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.
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_
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"
12 class NewAvatarButton;
13 class OpaqueBrowserFrameViewLayoutDelegate;
20 // Calculates the position of the widgets in the opaque browser frame view.
22 // This is separated out for testing reasons. OpaqueBrowserFrameView has tight
23 // dependencies with Browser and classes that depend on Browser.
24 class OpaqueBrowserFrameViewLayout : public views::LayoutManager {
26 explicit OpaqueBrowserFrameViewLayout(
27 OpaqueBrowserFrameViewLayoutDelegate* delegate);
28 virtual ~OpaqueBrowserFrameViewLayout();
30 // Whether we should add the (minimize,maximize,close) buttons. Can be false
31 // on Windows 8 in metro mode.
32 static bool ShouldAddDefaultCaptionButtons();
34 // Configures the button ordering in the frame.
35 void SetButtonOrdering(
36 const std::vector<views::FrameButton>& leading_buttons,
37 const std::vector<views::FrameButton>& trailing_buttons);
39 gfx::Rect GetBoundsForTabStrip(
40 const gfx::Size& tabstrip_preferred_size,
41 int available_width) const;
43 gfx::Size GetMinimumSize(int available_width) const;
45 // Returns the bounds of the window required to display the content area at
46 // the specified bounds.
47 gfx::Rect GetWindowBoundsForClientBounds(
48 const gfx::Rect& client_bounds) const;
50 // Returns the thickness of the border that makes up the window frame edges.
51 // This does not include any client edge. If |restored| is true, acts as if
52 // the window is restored regardless of the real mode.
53 int FrameBorderThickness(bool restored) const;
55 // Returns the thickness of the entire nonclient left, right, and bottom
56 // borders, including both the window frame and any client edge.
57 int NonClientBorderThickness() const;
59 // Returns the height of the entire nonclient top border, including the window
60 // frame, any title area, and any connected client edge. If |restored| is
61 // true, acts as if the window is restored regardless of the real mode.
62 int NonClientTopBorderHeight(bool restored) const;
64 int GetTabStripInsetsTop(bool restored) const;
66 // Returns the y-coordinate of the caption buttons. If |restored| is true,
67 // acts as if the window is restored regardless of the real mode.
68 int CaptionButtonY(bool restored) const;
70 // Returns the thickness of the 3D edge along the bottom of the titlebar. If
71 // |restored| is true, acts as if the window is restored regardless of the
73 int TitlebarBottomThickness(bool restored) const;
75 // Returns the bounds of the titlebar icon (or where the icon would be if
77 gfx::Rect IconBounds() const;
79 // Returns the bounds of the client area for the specified view size.
80 gfx::Rect CalculateClientAreaBounds(int width, int height) const;
82 void set_extra_caption_y(int extra_caption_y) {
83 extra_caption_y_ = extra_caption_y;
86 void set_window_caption_spacing(int window_caption_spacing) {
87 window_caption_spacing_ = window_caption_spacing;
90 const gfx::Rect& client_view_bounds() const { return client_view_bounds_; }
93 // Whether a specific button should be inserted on the leading or trailing
95 enum ButtonAlignment {
100 // Layout various sub-components of this view.
101 void LayoutWindowControls(views::View* host);
102 void LayoutTitleBar(views::View* host);
104 void LayoutNewStyleAvatar(views::View* host);
106 void ConfigureButton(views::View* host,
107 views::FrameButton button_id,
108 ButtonAlignment align,
111 // Sets the visibility of all buttons associated with |button_id| to false.
112 void HideButton(views::FrameButton button_id);
114 // Adds a window caption button to either the leading or trailing side.
115 void SetBoundsForButton(views::View* host,
116 views::ImageButton* button,
117 ButtonAlignment align,
120 // Internal implementation of ViewAdded() and ViewRemoved().
121 void SetView(int id, views::View* view);
123 // Overriden from views::LayoutManager:
124 virtual void Layout(views::View* host) OVERRIDE;
125 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE;
126 virtual void ViewAdded(views::View* host, views::View* view) OVERRIDE;
127 virtual void ViewRemoved(views::View* host, views::View* view) OVERRIDE;
129 OpaqueBrowserFrameViewLayoutDelegate* delegate_;
131 // The layout rect of the avatar icon, if visible.
132 gfx::Rect avatar_bounds_;
134 // The bounds of the ClientView.
135 gfx::Rect client_view_bounds_;
137 // The layout of the window icon, if visible.
138 gfx::Rect window_icon_bounds_;
140 // How far from the leading/trailing edge of the view the next window control
142 int leading_button_start_;
143 int trailing_button_start_;
145 // The size of the window buttons, and the avatar menu item (if any). This
146 // does not count labels or other elements that should be counted in a
148 int minimum_size_for_buttons_;
150 // Whether any of the window control buttons were packed on the leading.
151 bool has_leading_buttons_;
152 bool has_trailing_buttons_;
154 // Extra offset from the top of the frame to the top of the window control
155 // buttons. Configurable based on platform and whether we are under test.
156 int extra_caption_y_;
158 // Extra offset between the individual window caption buttons.
159 int window_caption_spacing_;
162 views::ImageButton* minimize_button_;
163 views::ImageButton* maximize_button_;
164 views::ImageButton* restore_button_;
165 views::ImageButton* close_button_;
167 views::View* window_icon_;
168 views::Label* window_title_;
170 views::View* avatar_label_;
171 views::View* avatar_button_;
172 NewAvatarButton* new_avatar_button_;
174 std::vector<views::FrameButton> leading_buttons_;
175 std::vector<views::FrameButton> trailing_buttons_;
177 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayout);
180 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_