| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" | 8 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" |
| 9 #include "ui/views/layout/layout_manager.h" | 9 #include "ui/views/layout/layout_manager.h" |
| 10 | 10 |
| 11 class OpaqueBrowserFrameViewLayoutDelegate; | 11 class OpaqueBrowserFrameViewLayoutDelegate; |
| 12 | 12 |
| 13 namespace views { | 13 namespace views { |
| 14 class ImageButton; | 14 class ImageButton; |
| 15 class Label; | 15 class Label; |
| 16 } | 16 } |
| 17 | 17 |
| 18 // Calculates the position of the widgets in the opaque browser frame view. | 18 // Calculates the position of the widgets in the opaque browser frame view. |
| 19 // | 19 // |
| 20 // This is separated out for testing reasons. OpaqueBrowserFrameView has tight | 20 // This is separated out for testing reasons. OpaqueBrowserFrameView has tight |
| 21 // dependencies with Browser and classes that depend on Browser. | 21 // dependencies with Browser and classes that depend on Browser. |
| 22 class OpaqueBrowserFrameViewLayout : public views::LayoutManager { | 22 class OpaqueBrowserFrameViewLayout : public views::LayoutManager { |
| 23 public: | 23 public: |
| 24 enum ButtonID { |
| 25 BUTTON_MINIMIZE, |
| 26 BUTTON_MAXIMIZE, |
| 27 BUTTON_CLOSE |
| 28 }; |
| 29 |
| 24 explicit OpaqueBrowserFrameViewLayout( | 30 explicit OpaqueBrowserFrameViewLayout( |
| 25 OpaqueBrowserFrameViewLayoutDelegate* delegate); | 31 OpaqueBrowserFrameViewLayoutDelegate* delegate); |
| 26 virtual ~OpaqueBrowserFrameViewLayout(); | 32 virtual ~OpaqueBrowserFrameViewLayout(); |
| 27 | 33 |
| 28 // Whether we should add the (minimize,maximize,close) buttons. Can be false | 34 // Whether we should add the (minimize,maximize,close) buttons. Can be false |
| 29 // on Windows 8 in metro mode. | 35 // on Windows 8 in metro mode. |
| 30 static bool ShouldAddDefaultCaptionButtons(); | 36 static bool ShouldAddDefaultCaptionButtons(); |
| 31 | 37 |
| 32 gfx::Rect GetBoundsForTabStrip( | 38 gfx::Rect GetBoundsForTabStrip( |
| 33 const gfx::Size& tabstrip_preferred_size, | 39 const gfx::Size& tabstrip_preferred_size, |
| 34 int available_width) const; | 40 int available_width) const; |
| 35 gfx::Rect GetBoundsForTabStripAndAvatarArea( | |
| 36 const gfx::Size& tabstrip_preferred_size, | |
| 37 int available_width) const; | |
| 38 | 41 |
| 39 gfx::Size GetMinimumSize(int available_width) const; | 42 gfx::Size GetMinimumSize(int available_width) const; |
| 40 | 43 |
| 41 // Returns the bounds of the window required to display the content area at | 44 // Returns the bounds of the window required to display the content area at |
| 42 // the specified bounds. | 45 // the specified bounds. |
| 43 gfx::Rect GetWindowBoundsForClientBounds( | 46 gfx::Rect GetWindowBoundsForClientBounds( |
| 44 const gfx::Rect& client_bounds) const; | 47 const gfx::Rect& client_bounds) const; |
| 45 | 48 |
| 46 // Returns the thickness of the border that makes up the window frame edges. | 49 // Returns the thickness of the border that makes up the window frame edges. |
| 47 // This does not include any client edge. If |restored| is true, acts as if | 50 // This does not include any client edge. If |restored| is true, acts as if |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 // Returns the bounds of the titlebar icon (or where the icon would be if | 74 // Returns the bounds of the titlebar icon (or where the icon would be if |
| 72 // there was one). | 75 // there was one). |
| 73 gfx::Rect IconBounds() const; | 76 gfx::Rect IconBounds() const; |
| 74 | 77 |
| 75 // Returns the bounds of the client area for the specified view size. | 78 // Returns the bounds of the client area for the specified view size. |
| 76 gfx::Rect CalculateClientAreaBounds(int width, int height) const; | 79 gfx::Rect CalculateClientAreaBounds(int width, int height) const; |
| 77 | 80 |
| 78 const gfx::Rect& client_view_bounds() const { return client_view_bounds_; } | 81 const gfx::Rect& client_view_bounds() const { return client_view_bounds_; } |
| 79 | 82 |
| 80 private: | 83 private: |
| 84 // Whether a specific button should be inserted on the leading or trailing |
| 85 // side. |
| 86 enum ButtonAlignment { |
| 87 ALIGN_LEADING, |
| 88 ALIGN_TRAILING |
| 89 }; |
| 90 |
| 81 // Layout various sub-components of this view. | 91 // Layout various sub-components of this view. |
| 82 void LayoutWindowControls(views::View* host); | 92 void LayoutWindowControls(views::View* host); |
| 83 void LayoutTitleBar(); | 93 void LayoutTitleBar(views::View* host); |
| 84 void LayoutAvatar(); | 94 void LayoutAvatar(); |
| 85 | 95 |
| 96 void ConfigureButton(views::View* host, |
| 97 ButtonID button_id, |
| 98 ButtonAlignment align, |
| 99 int caption_y); |
| 100 |
| 101 // Sets the visibility of all buttons associated with |button_id| to false. |
| 102 void HideButton(ButtonID button_id); |
| 103 |
| 104 // Adds a window caption button to either the leading or trailing side. |
| 105 void SetBoundsForButton(views::View* host, |
| 106 views::ImageButton* button, |
| 107 ButtonAlignment align, |
| 108 int caption_y); |
| 109 |
| 86 // Internal implementation of ViewAdded() and ViewRemoved(). | 110 // Internal implementation of ViewAdded() and ViewRemoved(). |
| 87 void SetView(int id, views::View* view); | 111 void SetView(int id, views::View* view); |
| 88 | 112 |
| 89 // Overriden from views::LayoutManager: | 113 // Overriden from views::LayoutManager: |
| 90 virtual void Layout(views::View* host) OVERRIDE; | 114 virtual void Layout(views::View* host) OVERRIDE; |
| 91 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE; | 115 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE; |
| 92 virtual void ViewAdded(views::View* host, views::View* view) OVERRIDE; | 116 virtual void ViewAdded(views::View* host, views::View* view) OVERRIDE; |
| 93 virtual void ViewRemoved(views::View* host, views::View* view) OVERRIDE; | 117 virtual void ViewRemoved(views::View* host, views::View* view) OVERRIDE; |
| 94 | 118 |
| 95 OpaqueBrowserFrameViewLayoutDelegate* delegate_; | 119 OpaqueBrowserFrameViewLayoutDelegate* delegate_; |
| 96 | 120 |
| 97 // The layout rect of the avatar icon, if visible. | 121 // The layout rect of the avatar icon, if visible. |
| 98 gfx::Rect avatar_bounds_; | 122 gfx::Rect avatar_bounds_; |
| 99 | 123 |
| 100 // The bounds of the ClientView. | 124 // The bounds of the ClientView. |
| 101 gfx::Rect client_view_bounds_; | 125 gfx::Rect client_view_bounds_; |
| 102 | 126 |
| 127 // The layout of the window icon, if visible. |
| 128 gfx::Rect window_icon_bounds_; |
| 129 |
| 130 // How far from the leading/trailing edge of the view the next window control |
| 131 // should be placed. |
| 132 int leading_button_start_; |
| 133 int trailing_button_start_; |
| 134 |
| 135 // The size of the window buttons, and the avatar menu item (if any). This |
| 136 // does not count labels or other elements that should be counted in a |
| 137 // minimal frame. |
| 138 int minimum_size_for_buttons_; |
| 139 |
| 140 // Whether any of the window control buttons were packed on the leading. |
| 141 bool has_leading_buttons_; |
| 142 bool has_trailing_buttons_; |
| 143 |
| 103 // Window controls. | 144 // Window controls. |
| 104 views::ImageButton* minimize_button_; | 145 views::ImageButton* minimize_button_; |
| 105 views::ImageButton* maximize_button_; | 146 views::ImageButton* maximize_button_; |
| 106 views::ImageButton* restore_button_; | 147 views::ImageButton* restore_button_; |
| 107 views::ImageButton* close_button_; | 148 views::ImageButton* close_button_; |
| 108 | 149 |
| 109 views::View* window_icon_; | 150 views::View* window_icon_; |
| 110 views::Label* window_title_; | 151 views::Label* window_title_; |
| 111 | 152 |
| 112 views::View* avatar_label_; | 153 views::View* avatar_label_; |
| 113 views::View* avatar_button_; | 154 views::View* avatar_button_; |
| 114 | 155 |
| 156 std::vector<ButtonID> leading_buttons_; |
| 157 std::vector<ButtonID> trailing_buttons_; |
| 158 |
| 115 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayout); | 159 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayout); |
| 116 }; | 160 }; |
| 117 | 161 |
| 118 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ | 162 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ |
| OLD | NEW |