browser_view_layout.h revision 868fa2fe829687343ffae624259930155e16dbd8
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. 4 5#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_ 6#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_ 7 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/rect.h" 13#include "ui/views/layout/layout_manager.h" 14 15class BookmarkBarView; 16class Browser; 17class BrowserView; 18class BrowserViewLayoutDelegate; 19class ContentsContainer; 20class ImmersiveModeController; 21class InfoBarContainerView; 22class OverlayContainer; 23class TabContentsContainer; 24class TabStrip; 25 26namespace gfx { 27class Point; 28class Size; 29} 30 31namespace views { 32class SingleSplitView; 33} 34 35namespace web_modal { 36class WebContentsModalDialogHost; 37} 38 39// The layout manager used in chrome browser. 40class BrowserViewLayout : public views::LayoutManager { 41 public: 42 // The vertical overlap between the TabStrip and the Toolbar. 43 static const int kToolbarTabStripVerticalOverlap; 44 45 BrowserViewLayout(); 46 virtual ~BrowserViewLayout(); 47 48 // Sets all the views to be managed. Takes ownership of |delegate|. 49 // |browser_view| may be NULL in tests. 50 void Init(BrowserViewLayoutDelegate* delegate, 51 Browser* browser, 52 BrowserView* browser_view, 53 views::View* top_container, 54 TabStrip* tab_strip, 55 views::View* toolbar, 56 InfoBarContainerView* infobar_container, 57 views::View* contents_split, 58 ContentsContainer* contents_container, 59 OverlayContainer* overlay_container, 60 ImmersiveModeController* immersive_mode_controller); 61 62 // Sets or updates views that are not available when |this| is initialized. 63 void set_tab_strip(TabStrip* tab_strip) { 64 tab_strip_ = tab_strip; 65 } 66 void set_bookmark_bar(BookmarkBarView* bookmark_bar) { 67 bookmark_bar_ = bookmark_bar; 68 } 69 void set_download_shelf(views::View* download_shelf) { 70 download_shelf_ = download_shelf; 71 } 72 73 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost(); 74 75 // Returns the minimum size of the browser view. 76 gfx::Size GetMinimumSize(); 77 78 // Returns the bounding box, in widget coordinates, for the find bar. 79 gfx::Rect GetFindBarBoundingBox() const; 80 81 // Returns true if the specified point(BrowserView coordinates) is in 82 // in the window caption area of the browser window. 83 bool IsPositionInWindowCaption(const gfx::Point& point); 84 85 // Tests to see if the specified |point| (in nonclient view's coordinates) 86 // is within the views managed by the laymanager. Returns one of 87 // HitTestCompat enum defined in ui/base/hit_test.h. 88 // See also ClientView::NonClientHitTest. 89 int NonClientHitTest(const gfx::Point& point); 90 91 // views::LayoutManager overrides: 92 virtual void Layout(views::View* host) OVERRIDE; 93 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE; 94 95 private: 96 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, BrowserViewLayout); 97 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, Layout); 98 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, LayoutDownloadShelf); 99 class WebContentsModalDialogHostViews; 100 101 enum InstantUIState { 102 // No instant suggestions are being shown. 103 kInstantUINone, 104 // Instant suggestions are displayed in a overlay overlapping the tab 105 // contents. 106 kInstantUIOverlay, 107 // Instant suggestions are displayed in the main tab contents. 108 kInstantUIFullPageResults, 109 }; 110 111 Browser* browser() { return browser_; } 112 113 // Layout the tab strip region, returns the coordinate of the bottom of the 114 // TabStrip, for laying out subsequent controls. 115 int LayoutTabStripRegion(views::View* browser_view); 116 117 // Layout the following controls, starting at |top|, returns the coordinate 118 // of the bottom of the control, for laying out the next control. 119 int LayoutToolbar(int top); 120 int LayoutBookmarkAndInfoBars(int top, int browser_view_y); 121 int LayoutBookmarkBar(int top); 122 int LayoutInfoBar(int top); 123 124 // Layout the |contents_split_| view between the coordinates |top| and 125 // |bottom|. See browser_view.h for details of the relationship between 126 // |contents_split_| and other views. 127 void LayoutContentsSplitView(int top, int bottom); 128 129 // Layout the |overlay_container_| view below the toolbar. 130 void LayoutOverlayContainer(); 131 132 // Updates |top_container_|'s bounds. The new bounds depend on the size of 133 // the bookmark bar and the toolbar. 134 void UpdateTopContainerBounds(); 135 136 // Returns the vertical offset for the web contents to account for a 137 // detached bookmarks bar. 138 int GetContentsOffsetForBookmarkBar(); 139 140 // Returns the top margin to adjust the contents_container_ by. This is used 141 // to make the bookmark bar and contents_container_ overlap so that the 142 // preview contents hides the bookmark bar. 143 int GetTopMarginForActiveContent(); 144 145 // Returns the top margin for the active or overlay web view in 146 // |contents_container_| for an immersive fullscreen reveal while instant 147 // extended is providing suggestions. 148 int GetTopMarginForImmersiveInstant(); 149 150 // Returns the state of instant extended suggestions. 151 InstantUIState GetInstantUIState(); 152 153 // Layout the Download Shelf, returns the coordinate of the top of the 154 // control, for laying out the previous control. 155 int LayoutDownloadShelf(int bottom); 156 157 // Returns true if an infobar is showing. 158 bool InfobarVisible() const; 159 160 // The delegate interface. May be a mock in tests. 161 scoped_ptr<BrowserViewLayoutDelegate> delegate_; 162 163 // The browser from the owning BrowserView. 164 Browser* browser_; 165 166 // The owning BrowserView. May be NULL in tests. 167 // TODO(jamescook): Remove this, use the views::View passed in to Layout(). 168 BrowserView* browser_view_; 169 170 // Child views that the layout manager manages. 171 // NOTE: If you add a view, try to add it as a views::View, which makes 172 // testing much easier. 173 views::View* top_container_; 174 TabStrip* tab_strip_; 175 views::View* toolbar_; 176 BookmarkBarView* bookmark_bar_; 177 InfoBarContainerView* infobar_container_; 178 views::View* contents_split_; 179 ContentsContainer* contents_container_; 180 OverlayContainer* overlay_container_; 181 views::View* download_shelf_; 182 183 ImmersiveModeController* immersive_mode_controller_; 184 185 // The bounds within which the vertically-stacked contents of the BrowserView 186 // should be laid out within. This is just the local bounds of the 187 // BrowserView. 188 // TODO(jamescook): Remove this and just use browser_view_->GetLocalBounds(). 189 gfx::Rect vertical_layout_rect_; 190 191 // The host for use in positioning the web contents modal dialog. 192 scoped_ptr<WebContentsModalDialogHostViews> dialog_host_; 193 194 // The distance the web contents modal dialog is from the top of the window, 195 // in pixels. 196 int web_contents_modal_dialog_top_y_; 197 198 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayout); 199}; 200 201#endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_ 202