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 3 // found in the LICENSE file. 4 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_ 7 8 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" 9 #include "ui/views/layout/layout_manager.h" 10 #include "ui/views/window/frame_buttons.h" 11 12 class AvatarMenuButton; 13 class NewAvatarButton; 14 class OpaqueBrowserFrameViewLayoutDelegate; 15 16 namespace views { 17 class ImageButton; 18 class Label; 19 } 20 21 // Calculates the position of the widgets in the opaque browser frame view. 22 // 23 // This is separated out for testing reasons. OpaqueBrowserFrameView has tight 24 // dependencies with Browser and classes that depend on Browser. 25 class OpaqueBrowserFrameViewLayout : public views::LayoutManager { 26 public: 27 explicit OpaqueBrowserFrameViewLayout( 28 OpaqueBrowserFrameViewLayoutDelegate* delegate); 29 virtual ~OpaqueBrowserFrameViewLayout(); 30 31 // Whether we should add the (minimize,maximize,close) buttons. This should be 32 // true if the buttons could be shown at any time in this session (see 33 // OpaqueBrowserFrameViewLayoutDelegate::ShouldShowCaptionButtons for whether 34 // they are currently visible). 35 static bool ShouldAddDefaultCaptionButtons(); 36 37 // Configures the button ordering in the frame. 38 void SetButtonOrdering( 39 const std::vector<views::FrameButton>& leading_buttons, 40 const std::vector<views::FrameButton>& trailing_buttons); 41 42 gfx::Rect GetBoundsForTabStrip( 43 const gfx::Size& tabstrip_preferred_size, 44 int available_width) const; 45 46 gfx::Size GetMinimumSize(int available_width) const; 47 48 // Returns the bounds of the window required to display the content area at 49 // the specified bounds. 50 gfx::Rect GetWindowBoundsForClientBounds( 51 const gfx::Rect& client_bounds) const; 52 53 // Returns the thickness of the border that makes up the window frame edges. 54 // This does not include any client edge. If |restored| is true, acts as if 55 // the window is restored regardless of the real mode. 56 int FrameBorderThickness(bool restored) const; 57 58 // Returns the thickness of the entire nonclient left, right, and bottom 59 // borders, including both the window frame and any client edge. 60 int NonClientBorderThickness() const; 61 62 // Returns the height of the entire nonclient top border, including the window 63 // frame, any title area, and any connected client edge. If |restored| is 64 // true, acts as if the window is restored regardless of the real mode. 65 int NonClientTopBorderHeight(bool restored) const; 66 67 int GetTabStripInsetsTop(bool restored) const; 68 69 // Returns the y-coordinate of the caption buttons. If |restored| is true, 70 // acts as if the window is restored regardless of the real mode. 71 int CaptionButtonY(bool restored) const; 72 73 // Returns the thickness of the 3D edge along the bottom of the titlebar. If 74 // |restored| is true, acts as if the window is restored regardless of the 75 // real mode. 76 int TitlebarBottomThickness(bool restored) const; 77 78 // Returns the bounds of the titlebar icon (or where the icon would be if 79 // there was one). 80 gfx::Rect IconBounds() const; 81 82 // Returns the bounds of the client area for the specified view size. 83 gfx::Rect CalculateClientAreaBounds(int width, int height) const; 84 set_extra_caption_y(int extra_caption_y)85 void set_extra_caption_y(int extra_caption_y) { 86 extra_caption_y_ = extra_caption_y; 87 } 88 set_window_caption_spacing(int window_caption_spacing)89 void set_window_caption_spacing(int window_caption_spacing) { 90 window_caption_spacing_ = window_caption_spacing; 91 } 92 client_view_bounds()93 const gfx::Rect& client_view_bounds() const { return client_view_bounds_; } 94 95 private: 96 // Whether a specific button should be inserted on the leading or trailing 97 // side. 98 enum ButtonAlignment { 99 ALIGN_LEADING, 100 ALIGN_TRAILING 101 }; 102 103 // Determines whether the avatar should be shown on the right side of the tab 104 // strip (instead of the usual left). 105 bool ShouldAvatarBeOnRight() const; 106 107 // Layout various sub-components of this view. 108 void LayoutWindowControls(views::View* host); 109 void LayoutTitleBar(views::View* host); 110 void LayoutAvatar(views::View* host); 111 void LayoutNewStyleAvatar(views::View* host); 112 113 void ConfigureButton(views::View* host, 114 views::FrameButton button_id, 115 ButtonAlignment align, 116 int caption_y); 117 118 // Sets the visibility of all buttons associated with |button_id| to false. 119 void HideButton(views::FrameButton button_id); 120 121 // Adds a window caption button to either the leading or trailing side. 122 void SetBoundsForButton(views::View* host, 123 views::ImageButton* button, 124 ButtonAlignment align, 125 int caption_y); 126 127 // Internal implementation of ViewAdded() and ViewRemoved(). 128 void SetView(int id, views::View* view); 129 130 // Overriden from views::LayoutManager: 131 virtual void Layout(views::View* host) OVERRIDE; 132 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE; 133 virtual void ViewAdded(views::View* host, views::View* view) OVERRIDE; 134 virtual void ViewRemoved(views::View* host, views::View* view) OVERRIDE; 135 136 OpaqueBrowserFrameViewLayoutDelegate* delegate_; 137 138 // The layout rect of the avatar icon, if visible. 139 gfx::Rect avatar_bounds_; 140 141 // The bounds of the ClientView. 142 gfx::Rect client_view_bounds_; 143 144 // The layout of the window icon, if visible. 145 gfx::Rect window_icon_bounds_; 146 147 // How far from the leading/trailing edge of the view the next window control 148 // should be placed. 149 int leading_button_start_; 150 int trailing_button_start_; 151 152 // The size of the window buttons, and the avatar menu item (if any). This 153 // does not count labels or other elements that should be counted in a 154 // minimal frame. 155 int minimum_size_for_buttons_; 156 157 // Whether any of the window control buttons were packed on the leading. 158 bool has_leading_buttons_; 159 bool has_trailing_buttons_; 160 161 // Extra offset from the top of the frame to the top of the window control 162 // buttons. Configurable based on platform and whether we are under test. 163 int extra_caption_y_; 164 165 // Extra offset between the individual window caption buttons. 166 int window_caption_spacing_; 167 168 // Window controls. 169 views::ImageButton* minimize_button_; 170 views::ImageButton* maximize_button_; 171 views::ImageButton* restore_button_; 172 views::ImageButton* close_button_; 173 174 views::View* window_icon_; 175 views::Label* window_title_; 176 177 views::View* avatar_label_; 178 AvatarMenuButton* avatar_button_; 179 views::View* new_avatar_button_; 180 181 std::vector<views::FrameButton> leading_buttons_; 182 std::vector<views::FrameButton> trailing_buttons_; 183 184 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayout); 185 }; 186 187 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ 188