• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   virtual ~NonClientFrameView();
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   virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
86   virtual const char* GetClassName() const OVERRIDE;
87 
88  protected:
89   virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
90 
91   NonClientFrameView();
92 
93  private:
94   // ViewTargeterDelegate:
95   virtual bool DoesIntersectRect(const View* target,
96                                  const gfx::Rect& rect) const OVERRIDE;
97 
98   // Prevents the non-client frame view from being rendered as inactive when
99   // true.
100   bool inactive_rendering_disabled_;
101 };
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 // NonClientView
105 //
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:
112 //
113 //  +- views::Widget ------------------------------------+
114 //  | +- views::RootView ------------------------------+ |
115 //  | | +- views::NonClientView ---------------------+ | |
116 //  | | | +- views::NonClientFrameView subclass ---+ | | |
117 //  | | | |                                        | | | |
118 //  | | | | << all painting and event receiving >> | | | |
119 //  | | | | << of the non-client areas of a     >> | | | |
120 //  | | | | << views::Widget.                   >> | | | |
121 //  | | | |                                        | | | |
122 //  | | | +----------------------------------------+ | | |
123 //  | | | +- views::ClientView or subclass --------+ | | |
124 //  | | | |                                        | | | |
125 //  | | | | << all painting and event receiving >> | | | |
126 //  | | | | << of the client areas of a         >> | | | |
127 //  | | | | << views::Widget.                   >> | | | |
128 //  | | | |                                        | | | |
129 //  | | | +----------------------------------------+ | | |
130 //  | | +--------------------------------------------+ | |
131 //  | +------------------------------------------------+ |
132 //  +----------------------------------------------------+
133 //
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).
138 //
139 class VIEWS_EXPORT NonClientView : public View, public ViewTargeterDelegate {
140  public:
141   // Internal class name.
142   static const char kViewClassName[];
143 
144   NonClientView();
145   virtual ~NonClientView();
146 
147   // Returns the current NonClientFrameView instance, or NULL if
148   // it does not exist.
frame_view()149   NonClientFrameView* frame_view() const { return frame_view_.get(); }
150 
151   // Replaces the current NonClientFrameView (if any) with the specified one.
152   void SetFrameView(NonClientFrameView* frame_view);
153 
154   // Replaces the current |overlay_view_| (if any) with the specified one.
155   void SetOverlayView(View* view);
156 
157   // Returns true if the ClientView determines that the containing window can be
158   // closed, false otherwise.
159   bool CanClose();
160 
161   // Called by the containing Window when it is closed.
162   void WindowClosing();
163 
164   // Replaces the frame view with a new one. Used when switching window theme
165   // or frame style.
166   void UpdateFrame();
167 
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);
172 
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;
176 
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);
180 
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);
184 
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();
191 
192   // Tells the NonClientView to invalidate the NonClientFrameView's window icon.
193   void UpdateWindowIcon();
194 
195   // Tells the NonClientView to invalidate the NonClientFrameView's window
196   // title.
197   void UpdateWindowTitle();
198 
199   // Called when the size constraints of the window change.
200   void SizeConstraintsChanged();
201 
202   // Get/Set client_view property.
client_view()203   ClientView* client_view() const { return client_view_; }
set_client_view(ClientView * client_view)204   void set_client_view(ClientView* client_view) {
205     client_view_ = client_view;
206   }
207 
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();
212 
213   // Set the accessible name of this view.
214   void SetAccessibleName(const base::string16& name);
215 
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;
223 
224   virtual views::View* GetTooltipHandlerForPoint(
225       const gfx::Point& point) OVERRIDE;
226 
227  protected:
228   // NonClientView, View overrides:
229   virtual void ViewHierarchyChanged(
230       const ViewHierarchyChangedDetails& details) OVERRIDE;
231 
232  private:
233   // ViewTargeterDelegate:
234   virtual 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_
259