| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_VIEWS_NON_CLIENT_VIEW_H_ | 5 #ifndef CHROME_VIEWS_NON_CLIENT_VIEW_H_ |
| 6 #define CHROME_VIEWS_NON_CLIENT_VIEW_H_ | 6 #define CHROME_VIEWS_NON_CLIENT_VIEW_H_ |
| 7 | 7 |
| 8 #include "base/task.h" |
| 8 #include "chrome/views/view.h" | 9 #include "chrome/views/view.h" |
| 9 #include "chrome/views/client_view.h" | 10 #include "chrome/views/client_view.h" |
| 10 | 11 |
| 11 namespace gfx { | 12 namespace gfx { |
| 12 class Path; | 13 class Path; |
| 13 } | 14 } |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 18 // NonClientView | 19 // NonClientFrameView |
| 19 // | 20 // |
| 20 // An object implementing the NonClientView interface is a View that provides | 21 // An object that subclasses NonClientFrameView is a View that renders and |
| 21 // the "non-client" areas of a window. This is the area that typically | 22 // responds to events within the frame portions of the non-client area of a |
| 22 // encompasses the window frame - title bar, sizing borders and window | 23 // window. This view does _not_ contain the ClientView, but rather is a sibling |
| 23 // controls. This interface provides methods that allow a specific | 24 // of it. |
| 24 // presentation to define non-client areas for windows hit testing, the shape | 25 class NonClientFrameView : public views::View { |
| 25 // of the window, and other window-related information. | |
| 26 // | |
| 27 class NonClientView : public View { | |
| 28 public: | 26 public: |
| 29 NonClientView(); | |
| 30 virtual ~NonClientView(); | |
| 31 | |
| 32 // Various edges of the frame border have a 1 px shadow along their edges; in | 27 // Various edges of the frame border have a 1 px shadow along their edges; in |
| 33 // a few cases we shift elements based on this amount for visual appeal. | 28 // a few cases we shift elements based on this amount for visual appeal. |
| 34 static const int kFrameShadowThickness; | 29 static const int kFrameShadowThickness; |
| 35 // In restored mode, we draw a 1 px edge around the content area inside the | 30 // In restored mode, we draw a 1 px edge around the content area inside the |
| 36 // frame border. | 31 // frame border. |
| 37 static const int kClientEdgeThickness; | 32 static const int kClientEdgeThickness; |
| 38 | 33 |
| 34 void DisableInactiveRendering(bool disable) { |
| 35 paint_as_active_ = disable; |
| 36 if (!paint_as_active_) |
| 37 SchedulePaint(); |
| 38 } |
| 39 |
| 40 // Returns the bounds (in this View's parent's coordinates) that the client |
| 41 // view should be laid out within. |
| 42 virtual gfx::Rect GetBoundsForClientView() const = 0; |
| 43 |
| 44 // Returns true if this FrameView should always use the custom frame, |
| 45 // regardless of the system settings. An example is the Constrained Window, |
| 46 // which is a child window and must always provide its own frame. |
| 47 virtual bool AlwaysUseCustomFrame() const { return false; } |
| 48 |
| 49 virtual gfx::Rect GetWindowBoundsForClientBounds( |
| 50 const gfx::Rect& client_bounds) const = 0; |
| 51 virtual gfx::Point GetSystemMenuPoint() const = 0; |
| 52 virtual int NonClientHitTest(const gfx::Point& point) = 0; |
| 53 virtual void GetWindowMask(const gfx::Size& size, |
| 54 gfx::Path* window_mask) = 0; |
| 55 virtual void EnableClose(bool enable) = 0; |
| 56 virtual void ResetWindowControls() = 0; |
| 57 |
| 58 protected: |
| 59 NonClientFrameView() : paint_as_active_(false) {} |
| 60 |
| 61 |
| 62 // Helper for non-client view implementations to determine which area of the |
| 63 // window border the specified |point| falls within. The other parameters are |
| 64 // the size of the sizing edges, and whether or not the window can be |
| 65 // resized. |
| 66 int GetHTComponentForFrame(const gfx::Point& point, |
| 67 int top_resize_border_height, |
| 68 int resize_border_thickness, |
| 69 int top_resize_corner_height, |
| 70 int resize_corner_width, |
| 71 bool can_resize); |
| 72 |
| 73 // Accessor for paint_as_active_. |
| 74 bool paint_as_active() const { return paint_as_active_; } |
| 75 |
| 76 private: |
| 77 // True when the non-client view should always be rendered as if the window |
| 78 // were active, regardless of whether or not the top level window actually |
| 79 // is active. |
| 80 bool paint_as_active_; |
| 81 }; |
| 82 |
| 83 //////////////////////////////////////////////////////////////////////////////// |
| 84 // NonClientView |
| 85 // |
| 86 // The NonClientView is the logical root of all Views contained within a |
| 87 // Window, except for the RootView which is its parent and of which it is the |
| 88 // sole child. The NonClientView has two children, the NonClientFrameView which |
| 89 // is responsible for painting and responding to events from the non-client |
| 90 // portions of the window, and the ClientView, which is responsible for the |
| 91 // same for the client area of the window: |
| 92 // |
| 93 // +- views::Window ------------------------------------+ |
| 94 // | +- views::RootView ------------------------------+ | |
| 95 // | | +- views::NonClientView ---------------------+ | | |
| 96 // | | | +- views::NonClientFrameView subclass ---+ | | | |
| 97 // | | | | | | | | |
| 98 // | | | | << all painting and event receiving >> | | | | |
| 99 // | | | | << of the non-client areas of a >> | | | | |
| 100 // | | | | << views::Window. >> | | | | |
| 101 // | | | | | | | | |
| 102 // | | | +----------------------------------------+ | | | |
| 103 // | | | +- views::ClientView or subclass --------+ | | | |
| 104 // | | | | | | | | |
| 105 // | | | | << all painting and event receiving >> | | | | |
| 106 // | | | | << of the client areas of a >> | | | | |
| 107 // | | | | << views::Window. >> | | | | |
| 108 // | | | | | | | | |
| 109 // | | | +----------------------------------------+ | | | |
| 110 // | | +--------------------------------------------+ | | |
| 111 // | +------------------------------------------------+ | |
| 112 // +----------------------------------------------------+ |
| 113 // |
| 114 // The NonClientFrameView and ClientView are siblings because due to theme |
| 115 // changes the NonClientFrameView may be replaced with different |
| 116 // implementations (e.g. during the switch from DWM/Aero-Glass to Vista Basic/ |
| 117 // Classic rendering). |
| 118 // |
| 119 class NonClientView : public View { |
| 120 public: |
| 121 explicit NonClientView(Window* frame); |
| 122 virtual ~NonClientView(); |
| 123 |
| 124 // Replaces the current NonClientFrameView (if any) with the specified one. |
| 125 void SetFrameView(NonClientFrameView* frame_view); |
| 126 |
| 39 // Returns true if the ClientView determines that the containing window can be | 127 // Returns true if the ClientView determines that the containing window can be |
| 40 // closed, false otherwise. | 128 // closed, false otherwise. |
| 41 bool CanClose() const; | 129 bool CanClose() const; |
| 42 | 130 |
| 43 // Called by the containing Window when it is closed. | 131 // Called by the containing Window when it is closed. |
| 44 void WindowClosing(); | 132 void WindowClosing(); |
| 45 | 133 |
| 134 // Called by the window when it receives a theme changed notification. Changes |
| 135 // the content of the NonClientView to match what is required for the current |
| 136 // system theme. |
| 137 void SystemThemeChanged(); |
| 138 |
| 139 // Changes the frame from native to custom depending on the value of |
| 140 // |use_native_frame|. |
| 141 void SetUseNativeFrame(bool use_native_frame); |
| 142 |
| 46 // Returns true if the native window frame should be used, false if the | 143 // Returns true if the native window frame should be used, false if the |
| 47 // NonClientView provides its own frame implementation. | 144 // NonClientView provides its own frame implementation. |
| 48 bool UseNativeFrame() const; | 145 bool UseNativeFrame() const; |
| 49 | 146 |
| 50 // Calculates the bounds of the client area of the window assuming the | 147 // Prevents the window from being rendered as deactivated when |disable| is |
| 51 // window is sized to |width| and |height|. | 148 // true, until called with |disable| false. Used when a sub-window is to be |
| 52 virtual gfx::Rect CalculateClientAreaBounds(int width, int height) const; | 149 // shown that shouldn't visually de-activate the window. |
| 150 // Subclasses can override this to perform additional actions when this value |
| 151 // changes. |
| 152 void DisableInactiveRendering(bool disable); |
| 53 | 153 |
| 54 // Calculates the size of window required to display a client area of the | 154 // Returns the bounds of the window required to display the content area at |
| 55 // specified width and height. | 155 // the specified bounds. |
| 56 virtual gfx::Size CalculateWindowSizeForClientSize(int width, | 156 gfx::Rect GetWindowBoundsForClientBounds(const gfx::Rect client_bounds) const; |
| 57 int height) const; | |
| 58 | 157 |
| 59 // Returns the point, in screen coordinates, where the system menu should | 158 // Returns the point, in screen coordinates, where the system menu should |
| 60 // be shown so it shows up anchored to the system menu icon. | 159 // be shown so it shows up anchored to the system menu icon. |
| 61 virtual gfx::Point GetSystemMenuPoint() const; | 160 gfx::Point GetSystemMenuPoint() const; |
| 62 | 161 |
| 63 // Determines the windows HT* code when the mouse cursor is at the | 162 // Determines the windows HT* code when the mouse cursor is at the |
| 64 // specified point, in window coordinates. | 163 // specified point, in window coordinates. |
| 65 virtual int NonClientHitTest(const gfx::Point& point); | 164 int NonClientHitTest(const gfx::Point& point); |
| 66 | 165 |
| 67 // Returns a mask to be used to clip the top level window for the given | 166 // Returns a mask to be used to clip the top level window for the given |
| 68 // size. This is used to create the non-rectangular window shape. | 167 // size. This is used to create the non-rectangular window shape. |
| 69 virtual void GetWindowMask(const gfx::Size& size, | 168 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask); |
| 70 gfx::Path* window_mask); | |
| 71 | 169 |
| 72 // Toggles the enable state for the Close button (and the Close menu item in | 170 // Toggles the enable state for the Close button (and the Close menu item in |
| 73 // the system menu). | 171 // the system menu). |
| 74 virtual void EnableClose(bool enable); | 172 void EnableClose(bool enable); |
| 75 | 173 |
| 76 // Tells the window controls as rendered by the NonClientView to reset | 174 // Tells the window controls as rendered by the NonClientView to reset |
| 77 // themselves to a normal state. This happens in situations where the | 175 // themselves to a normal state. This happens in situations where the |
| 78 // containing window does not receive a normal sequences of messages that | 176 // containing window does not receive a normal sequences of messages that |
| 79 // would lead to the controls returning to this normal state naturally, e.g. | 177 // would lead to the controls returning to this normal state naturally, e.g. |
| 80 // when the window is maximized, minimized or restored. | 178 // when the window is maximized, minimized or restored. |
| 81 virtual void ResetWindowControls(); | 179 void ResetWindowControls(); |
| 82 | |
| 83 // Prevents the non-client view from rendering as inactive when called with | |
| 84 // |disable| true, until called with false. | |
| 85 void set_paint_as_active(bool paint_as_active) { | |
| 86 paint_as_active_ = paint_as_active; | |
| 87 } | |
| 88 | 180 |
| 89 // Get/Set client_view property. | 181 // Get/Set client_view property. |
| 90 ClientView* client_view() const { return client_view_; } | 182 ClientView* client_view() const { return client_view_; } |
| 91 void set_client_view(ClientView* client_view) { | 183 void set_client_view(ClientView* client_view) { |
| 92 client_view_ = client_view; | 184 client_view_ = client_view; |
| 93 } | 185 } |
| 94 | 186 |
| 95 // NonClientView, View overrides: | 187 // NonClientView, View overrides: |
| 96 virtual gfx::Size GetPreferredSize(); | 188 virtual gfx::Size GetPreferredSize(); |
| 97 virtual void Layout(); | 189 virtual void Layout(); |
| 98 | 190 |
| 99 protected: | 191 protected: |
| 100 // NonClientView, View overrides: | 192 // NonClientView, View overrides: |
| 101 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); | 193 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); |
| 102 | 194 |
| 103 // Helper for non-client view implementations to determine which area of the | 195 private: |
| 104 // window border the specified |point| falls within. The other parameters are | 196 // The frame that hosts this NonClientView. |
| 105 // the size of the sizing edges, and whether or not the window can be | 197 Window* frame_; |
| 106 // resized. | |
| 107 int GetHTComponentForFrame(const gfx::Point& point, | |
| 108 int top_resize_border_height, | |
| 109 int resize_border_thickness, | |
| 110 int top_resize_corner_height, | |
| 111 int resize_corner_width, | |
| 112 bool can_resize); | |
| 113 | 198 |
| 114 // Accessor for paint_as_active_. | |
| 115 bool paint_as_active() const { return paint_as_active_; } | |
| 116 | |
| 117 private: | |
| 118 // A ClientView object or subclass, responsible for sizing the contents view | 199 // A ClientView object or subclass, responsible for sizing the contents view |
| 119 // of the window, hit testing and perhaps other tasks depending on the | 200 // of the window, hit testing and perhaps other tasks depending on the |
| 120 // implementation. | 201 // implementation. |
| 121 ClientView* client_view_; | 202 ClientView* client_view_; |
| 122 | 203 |
| 123 // True when the non-client view should always be rendered as if the window | 204 // The NonClientFrameView that renders the non-client portions of the window. |
| 124 // were active, regardless of whether or not the top level window actually | 205 // This object is not owned by the view hierarchy because it can be replaced |
| 125 // is active. | 206 // dynamically as the system settings change. |
| 126 bool paint_as_active_; | 207 scoped_ptr<NonClientFrameView> frame_view_; |
| 208 |
| 209 // Whether or not we should use the native frame. |
| 210 bool use_native_frame_; |
| 211 |
| 212 DISALLOW_COPY_AND_ASSIGN(NonClientView); |
| 127 }; | 213 }; |
| 128 | 214 |
| 129 } // namespace views | 215 } // namespace views |
| 130 | 216 |
| 131 #endif // #ifndef CHROME_VIEWS_NON_CLIENT_VIEW_H_ | 217 #endif // #ifndef CHROME_VIEWS_NON_CLIENT_VIEW_H_ |
| 132 | 218 |
| OLD | NEW |