Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_view_layout.h
blob0f4eb35e1322a29570c9322651f74cde2979f4ab
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
6 #define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/views/layout/layout_manager.h"
15 class BookmarkBarView;
16 class Browser;
17 class BrowserViewLayoutDelegate;
18 class ContentsLayoutManager;
19 class ImmersiveModeController;
20 class InfoBarContainerView;
21 class TabContentsContainer;
22 class TabStrip;
24 namespace gfx {
25 class Point;
26 class Size;
29 namespace views {
30 class ClientView;
31 class SingleSplitView;
34 namespace web_modal {
35 class WebContentsModalDialogHost;
38 // The layout manager used in chrome browser.
39 class BrowserViewLayout : public views::LayoutManager {
40 public:
41 BrowserViewLayout();
42 ~BrowserViewLayout() override;
44 // Sets all the views to be managed. Takes ownership of |delegate|.
45 // |browser_view| may be null in tests.
46 void Init(BrowserViewLayoutDelegate* delegate,
47 Browser* browser,
48 views::ClientView* browser_view,
49 views::View* top_container,
50 TabStrip* tab_strip,
51 views::View* toolbar,
52 InfoBarContainerView* infobar_container,
53 views::View* contents_container,
54 ContentsLayoutManager* contents_layout_manager,
55 ImmersiveModeController* immersive_mode_controller);
57 // Sets or updates views that are not available when |this| is initialized.
58 void set_tab_strip(TabStrip* tab_strip) {
59 tab_strip_ = tab_strip;
61 void set_bookmark_bar(BookmarkBarView* bookmark_bar) {
62 bookmark_bar_ = bookmark_bar;
64 void set_download_shelf(views::View* download_shelf) {
65 download_shelf_ = download_shelf;
68 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost();
70 // Returns the minimum size of the browser view.
71 gfx::Size GetMinimumSize();
73 // Returns the bounding box, in widget coordinates, for the find bar.
74 gfx::Rect GetFindBarBoundingBox() const;
76 // Tests to see if the specified |point| (in nonclient view's coordinates)
77 // is within the views managed by the laymanager. Returns one of
78 // HitTestCompat enum defined in ui/base/hit_test.h.
79 // See also ClientView::NonClientHitTest.
80 int NonClientHitTest(const gfx::Point& point);
82 // views::LayoutManager overrides:
83 void Layout(views::View* host) override;
84 gfx::Size GetPreferredSize(const views::View* host) const override;
86 private:
87 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, BrowserViewLayout);
88 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, Layout);
89 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, LayoutDownloadShelf);
90 class WebContentsModalDialogHostViews;
92 Browser* browser() { return browser_; }
94 // Layout the following controls, starting at |top|, returns the coordinate
95 // of the bottom of the control, for laying out the next control.
96 int LayoutTabStripRegion(int top);
97 int LayoutToolbar(int top);
98 int LayoutBookmarkAndInfoBars(int top, int browser_view_y);
99 int LayoutBookmarkBar(int top);
100 int LayoutInfoBar(int top);
102 // Layout the |contents_container_| view between the coordinates |top| and
103 // |bottom|. See browser_view.h for details of the relationship between
104 // |contents_container_| and other views.
105 void LayoutContentsContainerView(int top, int bottom);
107 // Updates |top_container_|'s bounds. The new bounds depend on the size of
108 // the bookmark bar and the toolbar.
109 void UpdateTopContainerBounds();
111 // Returns the vertical offset for the web contents to account for a
112 // detached bookmarks bar.
113 int GetContentsOffsetForBookmarkBar();
115 // Returns the top margin to adjust the contents_container_ by. This is used
116 // to make the bookmark bar and contents_container_ overlap so that the
117 // preview contents hides the bookmark bar.
118 int GetTopMarginForActiveContent();
120 // Layout the Download Shelf, returns the coordinate of the top of the
121 // control, for laying out the previous control.
122 int LayoutDownloadShelf(int bottom);
124 // Returns true if an infobar is showing.
125 bool InfobarVisible() const;
127 // The delegate interface. May be a mock in tests.
128 scoped_ptr<BrowserViewLayoutDelegate> delegate_;
130 // The browser from the owning BrowserView.
131 Browser* browser_;
133 // The owning browser view.
134 views::ClientView* browser_view_;
136 // Child views that the layout manager manages.
137 // NOTE: If you add a view, try to add it as a views::View, which makes
138 // testing much easier.
139 views::View* top_container_;
140 TabStrip* tab_strip_;
141 views::View* toolbar_;
142 BookmarkBarView* bookmark_bar_;
143 InfoBarContainerView* infobar_container_;
144 views::View* contents_container_;
145 ContentsLayoutManager* contents_layout_manager_;
146 views::View* download_shelf_;
148 ImmersiveModeController* immersive_mode_controller_;
150 // The bounds within which the vertically-stacked contents of the BrowserView
151 // should be laid out within. This is just the local bounds of the
152 // BrowserView.
153 // TODO(jamescook): Remove this and just use browser_view_->GetLocalBounds().
154 gfx::Rect vertical_layout_rect_;
156 // The host for use in positioning the web contents modal dialog.
157 scoped_ptr<WebContentsModalDialogHostViews> dialog_host_;
159 // The latest dialog bounds applied during a layout pass.
160 gfx::Rect latest_dialog_bounds_;
162 // The distance the web contents modal dialog is from the top of the window,
163 // in pixels.
164 int web_contents_modal_dialog_top_y_;
166 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayout);
169 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_