Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / views / window / non_client_view.h
blob762ccf1ba1a25ff22f31727152d8557e347ad958
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"
11 namespace gfx {
12 class Path;
15 namespace views {
17 class ClientView;
19 ////////////////////////////////////////////////////////////////////////////////
20 // NonClientFrameView
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
25 // of it.
26 class VIEWS_EXPORT NonClientFrameView : public View,
27 public ViewTargeterDelegate {
28 public:
29 // Internal class name.
30 static const char kViewClassName[];
32 enum {
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
38 // frame border.
39 kClientEdgeThickness = 1,
42 ~NonClientFrameView() override;
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
57 // resized.
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,
63 bool can_resize);
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.
75 // HTSYSMENU.
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;
84 // View:
85 void GetAccessibleState(ui::AXViewState* state) override;
86 const char* GetClassName() const override;
88 protected:
89 NonClientFrameView();
91 // ViewTargeterDelegate:
92 bool DoesIntersectRect(const View* target,
93 const gfx::Rect& rect) const override;
95 // View:
96 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
98 private:
99 // Prevents the non-client frame view from being rendered as inactive when
100 // true.
101 bool inactive_rendering_disabled_;
104 ////////////////////////////////////////////////////////////////////////////////
105 // NonClientView
107 // The NonClientView is the logical root of all Views contained within a
108 // Window, except for the RootView which is its parent and of which it is the
109 // sole child. The NonClientView has two children, the NonClientFrameView which
110 // is responsible for painting and responding to events from the non-client
111 // portions of the window, and the ClientView, which is responsible for the
112 // same for the client area of the window:
114 // +- views::Widget ------------------------------------+
115 // | +- views::RootView ------------------------------+ |
116 // | | +- views::NonClientView ---------------------+ | |
117 // | | | +- views::NonClientFrameView subclass ---+ | | |
118 // | | | | | | | |
119 // | | | | << all painting and event receiving >> | | | |
120 // | | | | << of the non-client areas of a >> | | | |
121 // | | | | << views::Widget. >> | | | |
122 // | | | | | | | |
123 // | | | +----------------------------------------+ | | |
124 // | | | +- views::ClientView or subclass --------+ | | |
125 // | | | | | | | |
126 // | | | | << all painting and event receiving >> | | | |
127 // | | | | << of the client areas of a >> | | | |
128 // | | | | << views::Widget. >> | | | |
129 // | | | | | | | |
130 // | | | +----------------------------------------+ | | |
131 // | | +--------------------------------------------+ | |
132 // | +------------------------------------------------+ |
133 // +----------------------------------------------------+
135 // The NonClientFrameView and ClientView are siblings because due to theme
136 // changes the NonClientFrameView may be replaced with different
137 // implementations (e.g. during the switch from DWM/Aero-Glass to Vista Basic/
138 // Classic rendering).
140 class VIEWS_EXPORT NonClientView : public View, public ViewTargeterDelegate {
141 public:
142 // Internal class name.
143 static const char kViewClassName[];
145 NonClientView();
146 ~NonClientView() override;
148 // Returns the current NonClientFrameView instance, or NULL if
149 // it does not exist.
150 NonClientFrameView* frame_view() const { return frame_view_.get(); }
152 // Replaces the current NonClientFrameView (if any) with the specified one.
153 void SetFrameView(NonClientFrameView* frame_view);
155 // Replaces the current |overlay_view_| (if any) with the specified one.
156 void SetOverlayView(View* view);
158 // Returns true if the ClientView determines that the containing window can be
159 // closed, false otherwise.
160 bool CanClose();
162 // Called by the containing Window when it is closed.
163 void WindowClosing();
165 // Replaces the frame view with a new one. Used when switching window theme
166 // or frame style.
167 void UpdateFrame();
169 // Prevents the window from being rendered as deactivated when |disable| is
170 // true, until called with |disable| false. Used when a sub-window is to be
171 // shown that shouldn't visually de-activate the window.
172 void SetInactiveRenderingDisabled(bool disable);
174 // Returns the bounds of the window required to display the content area at
175 // the specified bounds.
176 gfx::Rect GetWindowBoundsForClientBounds(const gfx::Rect client_bounds) const;
178 // Determines the windows HT* code when the mouse cursor is at the
179 // specified point, in window coordinates.
180 int NonClientHitTest(const gfx::Point& point);
182 // Returns a mask to be used to clip the top level window for the given
183 // size. This is used to create the non-rectangular window shape.
184 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
186 // Tells the window controls as rendered by the NonClientView to reset
187 // themselves to a normal state. This happens in situations where the
188 // containing window does not receive a normal sequences of messages that
189 // would lead to the controls returning to this normal state naturally, e.g.
190 // when the window is maximized, minimized or restored.
191 void ResetWindowControls();
193 // Tells the NonClientView to invalidate the NonClientFrameView's window icon.
194 void UpdateWindowIcon();
196 // Tells the NonClientView to invalidate the NonClientFrameView's window
197 // title.
198 void UpdateWindowTitle();
200 // Called when the size constraints of the window change.
201 void SizeConstraintsChanged();
203 // Get/Set client_view property.
204 ClientView* client_view() const { return client_view_; }
205 void set_client_view(ClientView* client_view) {
206 client_view_ = client_view;
209 // Layout just the frame view. This is necessary on Windows when non-client
210 // metrics such as the position of the window controls changes independently
211 // of a window resize message.
212 void LayoutFrameView();
214 // Set the accessible name of this view.
215 void SetAccessibleName(const base::string16& name);
217 // NonClientView, View overrides:
218 gfx::Size GetPreferredSize() const override;
219 gfx::Size GetMinimumSize() const override;
220 gfx::Size GetMaximumSize() const override;
221 void Layout() override;
222 void GetAccessibleState(ui::AXViewState* state) override;
223 const char* GetClassName() const override;
225 views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
227 protected:
228 // NonClientView, View overrides:
229 void ViewHierarchyChanged(
230 const ViewHierarchyChangedDetails& details) override;
232 private:
233 // ViewTargeterDelegate:
234 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
238 // implementation.
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.
248 View* overlay_view_;
250 // The accessible name of this view.
251 base::string16 accessible_name_;
253 DISALLOW_COPY_AND_ASSIGN(NonClientView);
256 } // namespace views
258 #endif // UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_