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