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"
9 #include "ui/views/view_targeter_delegate.h"
19 ////////////////////////////////////////////////////////////////////////////////
22 // An object that subclasses NonClientFrameView is a View that renders and
23 // responds to events within the frame portions of the non-client area of a
24 // window. This view does _not_ contain the ClientView, but rather is a sibling
26 class VIEWS_EXPORT NonClientFrameView
: public View
,
27 public ViewTargeterDelegate
{
29 // Internal class name.
30 static const char kViewClassName
[];
33 // Various edges of the frame border have a 1 px shadow along their edges;
34 // in a few cases we shift elements based on this amount for visual appeal.
35 kFrameShadowThickness
= 1,
37 // In restored mode, we draw a 1 px edge around the content area inside the
39 kClientEdgeThickness
= 1,
42 virtual ~NonClientFrameView();
44 // Sets whether the window should be rendered as active regardless of the
45 // actual active state. Used when bubbles become active to make their parent
46 // appear active. A value of true makes the window render as active always,
47 // false gives normal behavior.
48 void SetInactiveRenderingDisabled(bool disable
);
50 // Used to determine if the frame should be painted as active. Keyed off the
51 // window's actual active state and |inactive_rendering_disabled_|.
52 bool ShouldPaintAsActive() const;
54 // Helper for non-client view implementations to determine which area of the
55 // window border the specified |point| falls within. The other parameters are
56 // the size of the sizing edges, and whether or not the window can be
58 int GetHTComponentForFrame(const gfx::Point
& point
,
59 int top_resize_border_height
,
60 int resize_border_thickness
,
61 int top_resize_corner_height
,
62 int resize_corner_width
,
65 // Returns the bounds (in this View's parent's coordinates) that the client
66 // view should be laid out within.
67 virtual gfx::Rect
GetBoundsForClientView() const = 0;
69 virtual gfx::Rect
GetWindowBoundsForClientBounds(
70 const gfx::Rect
& client_bounds
) const = 0;
72 // This function must ask the ClientView to do a hittest. We don't do this in
73 // the parent NonClientView because that makes it more difficult to calculate
74 // hittests for regions that are partially obscured by the ClientView, e.g.
76 virtual int NonClientHitTest(const gfx::Point
& point
) = 0;
77 virtual void GetWindowMask(const gfx::Size
& size
,
78 gfx::Path
* window_mask
) = 0;
79 virtual void ResetWindowControls() = 0;
80 virtual void UpdateWindowIcon() = 0;
81 virtual void UpdateWindowTitle() = 0;
82 virtual void SizeConstraintsChanged() = 0;
85 virtual void GetAccessibleState(ui::AXViewState
* state
) OVERRIDE
;
86 virtual const char* GetClassName() const OVERRIDE
;
89 virtual void OnBoundsChanged(const gfx::Rect
& previous_bounds
) OVERRIDE
;
94 // ViewTargeterDelegate:
95 virtual bool DoesIntersectRect(const View
* target
,
96 const gfx::Rect
& rect
) const OVERRIDE
;
98 // Prevents the non-client frame view from being rendered as inactive when
100 bool inactive_rendering_disabled_
;
103 ////////////////////////////////////////////////////////////////////////////////
106 // The NonClientView is the logical root of all Views contained within a
107 // Window, except for the RootView which is its parent and of which it is the
108 // sole child. The NonClientView has two children, the NonClientFrameView which
109 // is responsible for painting and responding to events from the non-client
110 // portions of the window, and the ClientView, which is responsible for the
111 // same for the client area of the window:
113 // +- views::Widget ------------------------------------+
114 // | +- views::RootView ------------------------------+ |
115 // | | +- views::NonClientView ---------------------+ | |
116 // | | | +- views::NonClientFrameView subclass ---+ | | |
118 // | | | | << all painting and event receiving >> | | | |
119 // | | | | << of the non-client areas of a >> | | | |
120 // | | | | << views::Widget. >> | | | |
122 // | | | +----------------------------------------+ | | |
123 // | | | +- views::ClientView or subclass --------+ | | |
125 // | | | | << all painting and event receiving >> | | | |
126 // | | | | << of the client areas of a >> | | | |
127 // | | | | << views::Widget. >> | | | |
129 // | | | +----------------------------------------+ | | |
130 // | | +--------------------------------------------+ | |
131 // | +------------------------------------------------+ |
132 // +----------------------------------------------------+
134 // The NonClientFrameView and ClientView are siblings because due to theme
135 // changes the NonClientFrameView may be replaced with different
136 // implementations (e.g. during the switch from DWM/Aero-Glass to Vista Basic/
137 // Classic rendering).
139 class VIEWS_EXPORT NonClientView
: public View
, public ViewTargeterDelegate
{
141 // Internal class name.
142 static const char kViewClassName
[];
145 virtual ~NonClientView();
147 // Returns the current NonClientFrameView instance, or NULL if
148 // it does not exist.
149 NonClientFrameView
* frame_view() const { return frame_view_
.get(); }
151 // Replaces the current NonClientFrameView (if any) with the specified one.
152 void SetFrameView(NonClientFrameView
* frame_view
);
154 // Replaces the current |overlay_view_| (if any) with the specified one.
155 void SetOverlayView(View
* view
);
157 // Returns true if the ClientView determines that the containing window can be
158 // closed, false otherwise.
161 // Called by the containing Window when it is closed.
162 void WindowClosing();
164 // Replaces the frame view with a new one. Used when switching window theme
168 // Prevents the window from being rendered as deactivated when |disable| is
169 // true, until called with |disable| false. Used when a sub-window is to be
170 // shown that shouldn't visually de-activate the window.
171 void SetInactiveRenderingDisabled(bool disable
);
173 // Returns the bounds of the window required to display the content area at
174 // the specified bounds.
175 gfx::Rect
GetWindowBoundsForClientBounds(const gfx::Rect client_bounds
) const;
177 // Determines the windows HT* code when the mouse cursor is at the
178 // specified point, in window coordinates.
179 int NonClientHitTest(const gfx::Point
& point
);
181 // Returns a mask to be used to clip the top level window for the given
182 // size. This is used to create the non-rectangular window shape.
183 void GetWindowMask(const gfx::Size
& size
, gfx::Path
* window_mask
);
185 // Tells the window controls as rendered by the NonClientView to reset
186 // themselves to a normal state. This happens in situations where the
187 // containing window does not receive a normal sequences of messages that
188 // would lead to the controls returning to this normal state naturally, e.g.
189 // when the window is maximized, minimized or restored.
190 void ResetWindowControls();
192 // Tells the NonClientView to invalidate the NonClientFrameView's window icon.
193 void UpdateWindowIcon();
195 // Tells the NonClientView to invalidate the NonClientFrameView's window
197 void UpdateWindowTitle();
199 // Called when the size constraints of the window change.
200 void SizeConstraintsChanged();
202 // Get/Set client_view property.
203 ClientView
* client_view() const { return client_view_
; }
204 void set_client_view(ClientView
* client_view
) {
205 client_view_
= client_view
;
208 // Layout just the frame view. This is necessary on Windows when non-client
209 // metrics such as the position of the window controls changes independently
210 // of a window resize message.
211 void LayoutFrameView();
213 // Set the accessible name of this view.
214 void SetAccessibleName(const base::string16
& name
);
216 // NonClientView, View overrides:
217 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
218 virtual gfx::Size
GetMinimumSize() const OVERRIDE
;
219 virtual gfx::Size
GetMaximumSize() const OVERRIDE
;
220 virtual void Layout() OVERRIDE
;
221 virtual void GetAccessibleState(ui::AXViewState
* state
) OVERRIDE
;
222 virtual const char* GetClassName() const OVERRIDE
;
224 virtual views::View
* GetTooltipHandlerForPoint(
225 const gfx::Point
& point
) OVERRIDE
;
228 // NonClientView, View overrides:
229 virtual void ViewHierarchyChanged(
230 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
233 // ViewTargeterDelegate:
234 virtual View
* TargetForRect(View
* root
, const gfx::Rect
& rect
) OVERRIDE
;
236 // A ClientView object or subclass, responsible for sizing the contents view
237 // of the window, hit testing and perhaps other tasks depending on the
239 ClientView
* client_view_
;
241 // The NonClientFrameView that renders the non-client portions of the window.
242 // This object is not owned by the view hierarchy because it can be replaced
243 // dynamically as the system settings change.
244 scoped_ptr
<NonClientFrameView
> frame_view_
;
246 // The overlay view, when non-NULL and visible, takes up the entire widget and
247 // is placed on top of the ClientView and NonClientFrameView.
250 // The accessible name of this view.
251 base::string16 accessible_name_
;
253 DISALLOW_COPY_AND_ASSIGN(NonClientView
);
258 #endif // UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_