Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Side by Side Diff: chrome/browser/ui/views/frame/browser_view_layout.h

Issue 14589016: Unit test for BrowserViewLayout that does not depend on BrowserView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: layout works thru toolbar Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
6 #define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_ 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 #include "ui/views/layout/layout_manager.h" 13 #include "ui/views/layout/layout_manager.h"
14 14
15 class BookmarkBarView; 15 class BookmarkBarView;
16 class Browser; 16 class Browser;
17 class BrowserView; 17 class BrowserView;
18 class ContentsContainer; 18 class ContentsContainer;
19 class DownloadShelfView; 19 class ImmersiveModeController;
20 class InfoBarContainerView; 20 class InfoBarContainerView;
21 class OverlayContainer; 21 class OverlayContainer;
22 class TabContentsContainer; 22 class TabContentsContainer;
23 class TabStrip; 23 class TabStrip;
24 class ToolbarView; 24 class TopContainerView;
25 class WebContentsModalDialogHost; 25 class WebContentsModalDialogHost;
26 26
27 namespace gfx { 27 namespace gfx {
28 class Point; 28 class Point;
29 class Size; 29 class Size;
30 } 30 }
31 31
32 namespace views { 32 namespace views {
33 class SingleSplitView; 33 class SingleSplitView;
34 } 34 }
35 35
36 // Delegate class to allow BrowserViewLayout to be decoupled from BrowserView
37 // for testing. Not a nested class so it can be forward declared.
38 class BrowserViewLayoutDelegate {
sky 2013/05/15 00:37:22 put in its own header.
James Cook 2013/05/15 16:45:39 Done.
39 public:
40 virtual ~BrowserViewLayoutDelegate() {}
sky 2013/05/15 00:37:22 nit: make protected as BrowserViewLayout doesn't o
James Cook 2013/05/15 16:45:39 I don't understand this suggestion. BrowserView ow
sky 2013/05/15 17:24:52 Makes ownership simpler. BrowserView has and owns
41
42 virtual bool IsTabStripVisible() const = 0;
43 virtual gfx::Rect GetBoundsForTabStrip(views::View* tab_strip) const = 0;
44 virtual bool IsToolbarVisible() const = 0;
45 virtual bool IsBookmarkBarVisible() const = 0;
46 virtual bool DownloadShelfNeedsLayout() const = 0;
47 };
48
36 // The layout manager used in chrome browser. 49 // The layout manager used in chrome browser.
37 class BrowserViewLayout : public views::LayoutManager { 50 class BrowserViewLayout : public views::LayoutManager {
38 public: 51 public:
39 // The vertical overlap between the TabStrip and the Toolbar. 52 // The vertical overlap between the TabStrip and the Toolbar.
40 static const int kToolbarTabStripVerticalOverlap; 53 static const int kToolbarTabStripVerticalOverlap;
41 54
42 BrowserViewLayout(); 55 BrowserViewLayout();
43 virtual ~BrowserViewLayout(); 56 virtual ~BrowserViewLayout();
44 57
45 // Sets all the views to be managed. Tests may inject stubs or NULL. 58 // Sets all the views to be managed. Tests may inject stubs or NULL.
59 // Does not take ownership.
46 void Init(Browser* browser, 60 void Init(Browser* browser,
61 BrowserViewLayoutDelegate* delegate,
47 BrowserView* browser_view, 62 BrowserView* browser_view,
63 views::View* top_container,
64 TabStrip* tab_strip,
65 views::View* toolbar,
48 InfoBarContainerView* infobar_container, 66 InfoBarContainerView* infobar_container,
49 views::SingleSplitView* contents_split, 67 views::View* contents_split,
50 ContentsContainer* contents_container, 68 ContentsContainer* contents_container,
51 OverlayContainer* overlay_container); 69 OverlayContainer* overlay_container,
70 ImmersiveModeController* immersive_mode_controller);
52 71
53 // Sets or updates views that are not available when |this| is initialized. 72 // Sets or updates views that are not available when |this| is initialized.
73 void set_window_switcher_button(views::View* button) {
74 window_switcher_button_ = button;
75 }
76 void set_tab_strip(TabStrip* tab_strip) {
77 tab_strip_ = tab_strip;
78 }
54 void set_bookmark_bar(BookmarkBarView* bookmark_bar) { 79 void set_bookmark_bar(BookmarkBarView* bookmark_bar) {
55 bookmark_bar_ = bookmark_bar; 80 bookmark_bar_ = bookmark_bar;
56 } 81 }
57 void set_download_shelf(DownloadShelfView* download_shelf) { 82 void set_download_shelf(views::View* download_shelf) {
58 download_shelf_ = download_shelf; 83 download_shelf_ = download_shelf;
59 } 84 }
60 85
61 WebContentsModalDialogHost* GetWebContentsModalDialogHost(); 86 WebContentsModalDialogHost* GetWebContentsModalDialogHost();
62 87
63 // Returns the minimum size of the browser view. 88 // Returns the minimum size of the browser view.
64 gfx::Size GetMinimumSize(); 89 gfx::Size GetMinimumSize();
65 90
66 // Returns the bounding box, in widget coordinates, for the find bar. 91 // Returns the bounding box, in widget coordinates, for the find bar.
67 gfx::Rect GetFindBarBoundingBox() const; 92 gfx::Rect GetFindBarBoundingBox() const;
68 93
69 // Returns true if the specified point(BrowserView coordinates) is in 94 // Returns true if the specified point(BrowserView coordinates) is in
70 // in the window caption area of the browser window. 95 // in the window caption area of the browser window.
71 bool IsPositionInWindowCaption(const gfx::Point& point); 96 bool IsPositionInWindowCaption(const gfx::Point& point);
72 97
73 // Tests to see if the specified |point| (in nonclient view's coordinates) 98 // Tests to see if the specified |point| (in nonclient view's coordinates)
74 // is within the views managed by the laymanager. Returns one of 99 // is within the views managed by the laymanager. Returns one of
75 // HitTestCompat enum defined in ui/base/hit_test.h. 100 // HitTestCompat enum defined in ui/base/hit_test.h.
76 // See also ClientView::NonClientHitTest. 101 // See also ClientView::NonClientHitTest.
77 int NonClientHitTest(const gfx::Point& point); 102 int NonClientHitTest(const gfx::Point& point);
78 103
79 // views::LayoutManager overrides: 104 // views::LayoutManager overrides:
80 virtual void Layout(views::View* host) OVERRIDE; 105 virtual void Layout(views::View* host) OVERRIDE;
81 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE; 106 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE;
82 107
83 private: 108 private:
84 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, BrowserViewLayout); 109 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, BrowserViewLayout);
85 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, Layout); 110 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, Layout);
111 FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, LayoutDownloadShelf);
86 class WebContentsModalDialogHostViews; 112 class WebContentsModalDialogHostViews;
87 113
88 enum InstantUIState { 114 enum InstantUIState {
89 // No instant suggestions are being shown. 115 // No instant suggestions are being shown.
90 kInstantUINone, 116 kInstantUINone,
91 // Instant suggestions are displayed in a overlay overlapping the tab 117 // Instant suggestions are displayed in a overlay overlapping the tab
92 // contents. 118 // contents.
93 kInstantUIOverlay, 119 kInstantUIOverlay,
94 // Instant suggestions are displayed in the main tab contents. 120 // Instant suggestions are displayed in the main tab contents.
95 kInstantUIFullPageResults, 121 kInstantUIFullPageResults,
96 }; 122 };
97 123
98 Browser* browser() { return browser_; } 124 Browser* browser() { return browser_; }
99 125
100 // Layout the tab strip region, returns the coordinate of the bottom of the 126 // Layout the tab strip region, returns the coordinate of the bottom of the
101 // TabStrip, for laying out subsequent controls. 127 // TabStrip, for laying out subsequent controls.
102 int LayoutTabStripRegion(); 128 int LayoutTabStripRegion(views::View* browser_view);
103 129
104 // Layout the following controls, starting at |top|, returns the coordinate 130 // Layout the following controls, starting at |top|, returns the coordinate
105 // of the bottom of the control, for laying out the next control. 131 // of the bottom of the control, for laying out the next control.
106 int LayoutToolbar(int top); 132 int LayoutToolbar(int top);
107 int LayoutBookmarkAndInfoBars(int top); 133 int LayoutBookmarkAndInfoBars(int top);
108 int LayoutBookmarkBar(int top); 134 int LayoutBookmarkBar(int top);
109 int LayoutInfoBar(int top); 135 int LayoutInfoBar(int top);
110 136
111 // Layout the |contents_split_| view between the coordinates |top| and 137 // Layout the |contents_split_| view between the coordinates |top| and
112 // |bottom|. See browser_view.h for details of the relationship between 138 // |bottom|. See browser_view.h for details of the relationship between
(...skipping 23 matching lines...) Expand all
136 // Layout the Download Shelf, returns the coordinate of the top of the 162 // Layout the Download Shelf, returns the coordinate of the top of the
137 // control, for laying out the previous control. 163 // control, for laying out the previous control.
138 int LayoutDownloadShelf(int bottom); 164 int LayoutDownloadShelf(int bottom);
139 165
140 // Returns true if an infobar is showing. 166 // Returns true if an infobar is showing.
141 bool InfobarVisible() const; 167 bool InfobarVisible() const;
142 168
143 // The browser from the owning BrowserView. 169 // The browser from the owning BrowserView.
144 Browser* browser_; 170 Browser* browser_;
145 171
172 // The delegate interface. May be a mock in tests.
173 BrowserViewLayoutDelegate* delegate_;
174
146 // The owning BrowserView. May be NULL in tests. 175 // The owning BrowserView. May be NULL in tests.
176 // TODO(jamescook): Remove this, use the views::View passed in to Layout().
147 BrowserView* browser_view_; 177 BrowserView* browser_view_;
148 178
149 // Child views that the layout manager manages. 179 // Child views that the layout manager manages.
180 // NOTE: If you add a view, try to add it as a views::View, which makes
181 // testing much easier.
182 views::View* top_container_;
183 TabStrip* tab_strip_;
184 views::View* toolbar_;
150 BookmarkBarView* bookmark_bar_; 185 BookmarkBarView* bookmark_bar_;
151 InfoBarContainerView* infobar_container_; 186 InfoBarContainerView* infobar_container_;
152 views::SingleSplitView* contents_split_; 187 views::View* contents_split_;
153 ContentsContainer* contents_container_; 188 ContentsContainer* contents_container_;
154 OverlayContainer* overlay_container_; 189 OverlayContainer* overlay_container_;
155 DownloadShelfView* download_shelf_; 190 views::View* window_switcher_button_;
191 views::View* download_shelf_;
192
193 ImmersiveModeController* immersive_mode_controller_;
156 194
157 // The bounds within which the vertically-stacked contents of the BrowserView 195 // 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 196 // should be laid out within. This is just the local bounds of the
159 // BrowserView. 197 // BrowserView.
160 // TODO(jamescook): Remove this and just use browser_view_->GetLocalBounds(). 198 // TODO(jamescook): Remove this and just use browser_view_->GetLocalBounds().
161 gfx::Rect vertical_layout_rect_; 199 gfx::Rect vertical_layout_rect_;
162 200
163 // The host for use in positioning the web contents modal dialog. 201 // The host for use in positioning the web contents modal dialog.
164 scoped_ptr<WebContentsModalDialogHostViews> dialog_host_; 202 scoped_ptr<WebContentsModalDialogHostViews> dialog_host_;
165 203
166 // The distance the web contents modal dialog is from the top of the window, 204 // The distance the web contents modal dialog is from the top of the window,
167 // in pixels. 205 // in pixels.
168 int web_contents_modal_dialog_top_y_; 206 int web_contents_modal_dialog_top_y_;
169 207
170 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayout); 208 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayout);
171 }; 209 };
172 210
173 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_ 211 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.cc ('k') | chrome/browser/ui/views/frame/browser_view_layout.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698