Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / views / window / non_client_view.h
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.
4
5 #ifndef UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
6 #define UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
7
8 #include "ui/views/view.h"
9 #include "ui/views/view_targeter_delegate.h"
10
11 namespace gfx {
12 class Path;
13 }
14
15 namespace views {
16
17 class ClientView;
18
19 ////////////////////////////////////////////////////////////////////////////////
20 // NonClientFrameView
21 //
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[];
31
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,
36
37     // In restored mode, we draw a 1 px edge around the content area inside the
38     // frame border.
39     kClientEdgeThickness = 1,
40   };
41
42   ~NonClientFrameView() override;
43
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);
49
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;
53
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);
64
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;
68
69   virtual gfx::Rect GetWindowBoundsForClientBounds(
70       const gfx::Rect& client_bounds) const = 0;
71
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;
83
84   // View:
85   void GetAccessibleState(ui::AXViewState* state) override;
86   const char* GetClassName() const override;
87
88  protected:
89   NonClientFrameView();
90
91   // ViewTargeterDelegate:
92   bool DoesIntersectRect(const View* target,
93                          const gfx::Rect& rect) const override;
94
95   // View:
96   void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
97
98  private:
99   // Prevents the non-client frame view from being rendered as inactive when
100   // true.
101   bool inactive_rendering_disabled_;
102 };
103
104 ////////////////////////////////////////////////////////////////////////////////
105 // NonClientView
106 //
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:
113 //
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 //  +----------------------------------------------------+
134 //
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).
139 //
140 class VIEWS_EXPORT NonClientView : public View, public ViewTargeterDelegate {
141  public:
142   // Internal class name.
143   static const char kViewClassName[];
144
145   NonClientView();
146   ~NonClientView() override;
147
148   // Returns the current NonClientFrameView instance, or NULL if
149   // it does not exist.
150   NonClientFrameView* frame_view() const { return frame_view_.get(); }
151
152   // Replaces the current NonClientFrameView (if any) with the specified one.
153   void SetFrameView(NonClientFrameView* frame_view);
154
155   // Replaces the current |overlay_view_| (if any) with the specified one.
156   void SetOverlayView(View* view);
157
158   // Returns true if the ClientView determines that the containing window can be
159   // closed, false otherwise.
160   bool CanClose();
161
162   // Called by the containing Window when it is closed.
163   void WindowClosing();
164
165   // Replaces the frame view with a new one. Used when switching window theme
166   // or frame style.
167   void UpdateFrame();
168
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);
173
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;
177
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);
181
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);
185
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();
192
193   // Tells the NonClientView to invalidate the NonClientFrameView's window icon.
194   void UpdateWindowIcon();
195
196   // Tells the NonClientView to invalidate the NonClientFrameView's window
197   // title.
198   void UpdateWindowTitle();
199
200   // Called when the size constraints of the window change.
201   void SizeConstraintsChanged();
202
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;
207   }
208
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();
213
214   // Set the accessible name of this view.
215   void SetAccessibleName(const base::string16& name);
216
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;
224
225   views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
226
227  protected:
228   // NonClientView, View overrides:
229   void ViewHierarchyChanged(
230       const ViewHierarchyChangedDetails& details) override;
231
232  private:
233   // ViewTargeterDelegate:
234   View* TargetForRect(View* root, const gfx::Rect& rect) override;
235
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_;
240
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_;
245
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_;
249
250   // The accessible name of this view.
251   base::string16 accessible_name_;
252
253   DISALLOW_COPY_AND_ASSIGN(NonClientView);
254 };
255
256 }  // namespace views
257
258 #endif  // UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_