Blink roll 174234:174238
[chromium-blink-merge.git] / ui / views / window / non_client_view.h
blob4757aa49a9bedd75ecc8c001ffd081c05bee781c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
6 #define UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
8 #include "ui/views/view.h"
10 namespace gfx {
11 class Path;
14 namespace views {
16 class ClientView;
18 ////////////////////////////////////////////////////////////////////////////////
19 // NonClientFrameView
21 // An object that subclasses NonClientFrameView is a View that renders and
22 // responds to events within the frame portions of the non-client area of a
23 // window. This view does _not_ contain the ClientView, but rather is a sibling
24 // of it.
25 class VIEWS_EXPORT NonClientFrameView : public View {
26 public:
27 // Internal class name.
28 static const char kViewClassName[];
30 enum {
31 // Various edges of the frame border have a 1 px shadow along their edges;
32 // in a few cases we shift elements based on this amount for visual appeal.
33 kFrameShadowThickness = 1,
35 // In restored mode, we draw a 1 px edge around the content area inside the
36 // frame border.
37 kClientEdgeThickness = 1,
40 virtual ~NonClientFrameView();
42 // Sets whether the window should be rendered as active regardless of the
43 // actual active state. Used when bubbles become active to make their parent
44 // appear active. A value of true makes the window render as active always,
45 // false gives normal behavior.
46 void SetInactiveRenderingDisabled(bool disable);
48 // Used to determine if the frame should be painted as active. Keyed off the
49 // window's actual active state and |inactive_rendering_disabled_|.
50 bool ShouldPaintAsActive() const;
52 // Helper for non-client view implementations to determine which area of the
53 // window border the specified |point| falls within. The other parameters are
54 // the size of the sizing edges, and whether or not the window can be
55 // resized.
56 int GetHTComponentForFrame(const gfx::Point& point,
57 int top_resize_border_height,
58 int resize_border_thickness,
59 int top_resize_corner_height,
60 int resize_corner_width,
61 bool can_resize);
63 // Returns the bounds (in this View's parent's coordinates) that the client
64 // view should be laid out within.
65 virtual gfx::Rect GetBoundsForClientView() const = 0;
67 virtual gfx::Rect GetWindowBoundsForClientBounds(
68 const gfx::Rect& client_bounds) const = 0;
70 // This function must ask the ClientView to do a hittest. We don't do this in
71 // the parent NonClientView because that makes it more difficult to calculate
72 // hittests for regions that are partially obscured by the ClientView, e.g.
73 // HTSYSMENU.
74 virtual int NonClientHitTest(const gfx::Point& point) = 0;
75 virtual void GetWindowMask(const gfx::Size& size,
76 gfx::Path* window_mask) = 0;
77 virtual void ResetWindowControls() = 0;
78 virtual void UpdateWindowIcon() = 0;
79 virtual void UpdateWindowTitle() = 0;
81 // Overridden from View:
82 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
83 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
84 virtual const char* GetClassName() const OVERRIDE;
86 protected:
87 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
89 NonClientFrameView();
91 private:
92 // Prevents the non-client frame view from being rendered as inactive when
93 // true.
94 bool inactive_rendering_disabled_;
97 ////////////////////////////////////////////////////////////////////////////////
98 // NonClientView
100 // The NonClientView is the logical root of all Views contained within a
101 // Window, except for the RootView which is its parent and of which it is the
102 // sole child. The NonClientView has two children, the NonClientFrameView which
103 // is responsible for painting and responding to events from the non-client
104 // portions of the window, and the ClientView, which is responsible for the
105 // same for the client area of the window:
107 // +- views::Widget ------------------------------------+
108 // | +- views::RootView ------------------------------+ |
109 // | | +- views::NonClientView ---------------------+ | |
110 // | | | +- views::NonClientFrameView subclass ---+ | | |
111 // | | | | | | | |
112 // | | | | << all painting and event receiving >> | | | |
113 // | | | | << of the non-client areas of a >> | | | |
114 // | | | | << views::Widget. >> | | | |
115 // | | | | | | | |
116 // | | | +----------------------------------------+ | | |
117 // | | | +- views::ClientView or subclass --------+ | | |
118 // | | | | | | | |
119 // | | | | << all painting and event receiving >> | | | |
120 // | | | | << of the client areas of a >> | | | |
121 // | | | | << views::Widget. >> | | | |
122 // | | | | | | | |
123 // | | | +----------------------------------------+ | | |
124 // | | +--------------------------------------------+ | |
125 // | +------------------------------------------------+ |
126 // +----------------------------------------------------+
128 // The NonClientFrameView and ClientView are siblings because due to theme
129 // changes the NonClientFrameView may be replaced with different
130 // implementations (e.g. during the switch from DWM/Aero-Glass to Vista Basic/
131 // Classic rendering).
133 class VIEWS_EXPORT NonClientView : public View {
134 public:
135 // Internal class name.
136 static const char kViewClassName[];
138 NonClientView();
139 virtual ~NonClientView();
141 // Returns the current NonClientFrameView instance, or NULL if
142 // it does not exist.
143 NonClientFrameView* frame_view() const { return frame_view_.get(); }
145 // Replaces the current NonClientFrameView (if any) with the specified one.
146 void SetFrameView(NonClientFrameView* frame_view);
148 // Replaces the current |overlay_view_| (if any) with the specified one.
149 void SetOverlayView(View* view);
151 // Returns true if the ClientView determines that the containing window can be
152 // closed, false otherwise.
153 bool CanClose();
155 // Called by the containing Window when it is closed.
156 void WindowClosing();
158 // Replaces the frame view with a new one. Used when switching window theme
159 // or frame style.
160 void UpdateFrame();
162 // Prevents the window from being rendered as deactivated when |disable| is
163 // true, until called with |disable| false. Used when a sub-window is to be
164 // shown that shouldn't visually de-activate the window.
165 void SetInactiveRenderingDisabled(bool disable);
167 // Returns the bounds of the window required to display the content area at
168 // the specified bounds.
169 gfx::Rect GetWindowBoundsForClientBounds(const gfx::Rect client_bounds) const;
171 // Determines the windows HT* code when the mouse cursor is at the
172 // specified point, in window coordinates.
173 int NonClientHitTest(const gfx::Point& point);
175 // Returns a mask to be used to clip the top level window for the given
176 // size. This is used to create the non-rectangular window shape.
177 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
179 // Tells the window controls as rendered by the NonClientView to reset
180 // themselves to a normal state. This happens in situations where the
181 // containing window does not receive a normal sequences of messages that
182 // would lead to the controls returning to this normal state naturally, e.g.
183 // when the window is maximized, minimized or restored.
184 void ResetWindowControls();
186 // Tells the NonClientView to invalidate the NonClientFrameView's window icon.
187 void UpdateWindowIcon();
189 // Tells the NonClientView to invalidate the NonClientFrameView's window
190 // title.
191 void UpdateWindowTitle();
193 // Get/Set client_view property.
194 ClientView* client_view() const { return client_view_; }
195 void set_client_view(ClientView* client_view) {
196 client_view_ = client_view;
199 // Layout just the frame view. This is necessary on Windows when non-client
200 // metrics such as the position of the window controls changes independently
201 // of a window resize message.
202 void LayoutFrameView();
204 // Set the accessible name of this view.
205 void SetAccessibleName(const base::string16& name);
207 // NonClientView, View overrides:
208 virtual gfx::Size GetPreferredSize() OVERRIDE;
209 virtual gfx::Size GetMinimumSize() OVERRIDE;
210 virtual gfx::Size GetMaximumSize() OVERRIDE;
211 virtual void Layout() OVERRIDE;
212 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
213 virtual const char* GetClassName() const OVERRIDE;
215 virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE;
216 virtual views::View* GetTooltipHandlerForPoint(
217 const gfx::Point& point) OVERRIDE;
219 protected:
220 // NonClientView, View overrides:
221 virtual void ViewHierarchyChanged(
222 const ViewHierarchyChangedDetails& details) OVERRIDE;
224 private:
225 // A ClientView object or subclass, responsible for sizing the contents view
226 // of the window, hit testing and perhaps other tasks depending on the
227 // implementation.
228 ClientView* client_view_;
230 // The NonClientFrameView that renders the non-client portions of the window.
231 // This object is not owned by the view hierarchy because it can be replaced
232 // dynamically as the system settings change.
233 scoped_ptr<NonClientFrameView> frame_view_;
235 // The overlay view, when non-NULL and visible, takes up the entire widget and
236 // is placed on top of the ClientView and NonClientFrameView.
237 View* overlay_view_;
239 // The accessible name of this view.
240 base::string16 accessible_name_;
242 DISALLOW_COPY_AND_ASSIGN(NonClientView);
245 } // namespace views
247 #endif // UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_