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

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

Issue 14589016: Unit test for BrowserViewLayout that does not depend on BrowserView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: BrowserViewLayout owns its delegate 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "chrome/browser/ui/views/frame/browser_view_layout.h" 5 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
6 6
7 #include "base/observer_list.h" 7 #include "base/observer_list.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h" 10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_window.h" 11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/find_bar/find_bar.h" 12 #include "chrome/browser/ui/find_bar/find_bar.h"
13 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 13 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
14 #include "chrome/browser/ui/search/search_model.h" 14 #include "chrome/browser/ui/search/search_model.h"
15 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 15 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
16 #include "chrome/browser/ui/views/download/download_shelf_view.h" 16 #include "chrome/browser/ui/views/download/download_shelf_view.h"
17 #include "chrome/browser/ui/views/frame/browser_frame.h" 17 #include "chrome/browser/ui/views/frame/browser_frame.h"
18 #include "chrome/browser/ui/views/frame/browser_view.h" 18 #include "chrome/browser/ui/views/frame/browser_view.h"
19 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
19 #include "chrome/browser/ui/views/frame/contents_container.h" 20 #include "chrome/browser/ui/views/frame/contents_container.h"
20 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 21 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
21 #include "chrome/browser/ui/views/frame/overlay_container.h" 22 #include "chrome/browser/ui/views/frame/overlay_container.h"
22 #include "chrome/browser/ui/views/frame/top_container_view.h" 23 #include "chrome/browser/ui/views/frame/top_container_view.h"
23 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" 24 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
24 #include "chrome/browser/ui/views/tabs/tab_strip.h" 25 #include "chrome/browser/ui/views/tabs/tab_strip.h"
25 #include "chrome/browser/ui/views/toolbar_view.h"
26 #include "chrome/browser/ui/web_contents_modal_dialog_host.h" 26 #include "chrome/browser/ui/web_contents_modal_dialog_host.h"
27 #include "ui/base/hit_test.h" 27 #include "ui/base/hit_test.h"
28 #include "ui/gfx/point.h" 28 #include "ui/gfx/point.h"
29 #include "ui/gfx/scrollbar_size.h" 29 #include "ui/gfx/scrollbar_size.h"
30 #include "ui/gfx/size.h" 30 #include "ui/gfx/size.h"
31 #include "ui/views/controls/single_split_view.h"
32 #include "ui/views/controls/webview/webview.h" 31 #include "ui/views/controls/webview/webview.h"
33 32
34 using views::View; 33 using views::View;
35 34
36 namespace { 35 namespace {
37 36
38 // The visible height of the shadow above the tabs. Clicks in this area are 37 // The visible height of the shadow above the tabs. Clicks in this area are
39 // treated as clicks to the frame, rather than clicks to the tab. 38 // treated as clicks to the frame, rather than clicks to the tab.
40 const int kTabShadowSize = 2; 39 const int kTabShadowSize = 2;
41 // The number of pixels the bookmark bar should overlap the spacer by if the 40 // The number of pixels the bookmark bar should overlap the spacer by if the
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostViews); 108 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostViews);
110 }; 109 };
111 110
112 // static 111 // static
113 const int BrowserViewLayout::kToolbarTabStripVerticalOverlap = 3; 112 const int BrowserViewLayout::kToolbarTabStripVerticalOverlap = 3;
114 113
115 //////////////////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////////////////
116 // BrowserViewLayout, public: 115 // BrowserViewLayout, public:
117 116
118 BrowserViewLayout::BrowserViewLayout() 117 BrowserViewLayout::BrowserViewLayout()
119 : browser_(NULL), 118 : delegate_(NULL),
119 browser_(NULL),
120 browser_view_(NULL), 120 browser_view_(NULL),
121 top_container_(NULL),
122 tab_strip_(NULL),
123 toolbar_(NULL),
121 bookmark_bar_(NULL), 124 bookmark_bar_(NULL),
122 infobar_container_(NULL), 125 infobar_container_(NULL),
123 contents_split_(NULL), 126 contents_split_(NULL),
124 contents_container_(NULL), 127 contents_container_(NULL),
125 overlay_container_(NULL), 128 overlay_container_(NULL),
129 window_switcher_button_(NULL),
126 download_shelf_(NULL), 130 download_shelf_(NULL),
131 immersive_mode_controller_(NULL),
127 dialog_host_(new WebContentsModalDialogHostViews(this)), 132 dialog_host_(new WebContentsModalDialogHostViews(this)),
128 web_contents_modal_dialog_top_y_(-1) { 133 web_contents_modal_dialog_top_y_(-1) {
129 } 134 }
130 135
131 BrowserViewLayout::~BrowserViewLayout() { 136 BrowserViewLayout::~BrowserViewLayout() {
132 } 137 }
133 138
134 void BrowserViewLayout::Init(Browser* browser, 139 void BrowserViewLayout::Init(
135 BrowserView* browser_view, 140 BrowserViewLayoutDelegate* delegate,
136 InfoBarContainerView* infobar_container, 141 Browser* browser,
137 views::SingleSplitView* contents_split, 142 BrowserView* browser_view,
138 ContentsContainer* contents_container, 143 views::View* top_container,
139 OverlayContainer* overlay_container) { 144 TabStrip* tab_strip,
145 views::View* toolbar,
146 InfoBarContainerView* infobar_container,
147 views::View* contents_split,
148 ContentsContainer* contents_container,
149 OverlayContainer* overlay_container,
150 ImmersiveModeController* immersive_mode_controller) {
151 delegate_.reset(delegate);
140 browser_ = browser; 152 browser_ = browser;
141 browser_view_ = browser_view; 153 browser_view_ = browser_view;
154 top_container_ = top_container;
155 tab_strip_ = tab_strip;
156 toolbar_ = toolbar;
142 infobar_container_ = infobar_container; 157 infobar_container_ = infobar_container;
143 contents_split_ = contents_split; 158 contents_split_ = contents_split;
144 contents_container_ = contents_container; 159 contents_container_ = contents_container;
145 overlay_container_ = overlay_container; 160 overlay_container_ = overlay_container;
161 immersive_mode_controller_ = immersive_mode_controller;
146 } 162 }
147 163
148 WebContentsModalDialogHost* 164 WebContentsModalDialogHost*
149 BrowserViewLayout::GetWebContentsModalDialogHost() { 165 BrowserViewLayout::GetWebContentsModalDialogHost() {
150 return dialog_host_.get(); 166 return dialog_host_.get();
151 } 167 }
152 168
153 gfx::Size BrowserViewLayout::GetMinimumSize() { 169 gfx::Size BrowserViewLayout::GetMinimumSize() {
154 gfx::Size tabstrip_size( 170 gfx::Size tabstrip_size(
155 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? 171 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ?
156 browser_view_->tabstrip_->GetMinimumSize() : gfx::Size()); 172 tab_strip_->GetMinimumSize() : gfx::Size());
157 BrowserNonClientFrameView::TabStripInsets tab_strip_insets( 173 BrowserNonClientFrameView::TabStripInsets tab_strip_insets(
158 browser_view_->frame()->GetTabStripInsets(false)); 174 browser_view_->frame()->GetTabStripInsets(false));
159 gfx::Size toolbar_size( 175 gfx::Size toolbar_size(
160 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || 176 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
161 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? 177 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ?
162 browser_view_->toolbar_->GetMinimumSize() : gfx::Size()); 178 toolbar_->GetMinimumSize() : gfx::Size());
163 if (tabstrip_size.height() && toolbar_size.height()) 179 if (tabstrip_size.height() && toolbar_size.height())
164 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); 180 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap);
165 gfx::Size bookmark_bar_size; 181 gfx::Size bookmark_bar_size;
166 if (bookmark_bar_ && 182 if (bookmark_bar_ &&
167 bookmark_bar_->visible() && 183 bookmark_bar_->visible() &&
168 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { 184 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) {
169 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); 185 bookmark_bar_size = bookmark_bar_->GetMinimumSize();
170 bookmark_bar_size.Enlarge(0, 186 bookmark_bar_size.Enlarge(0,
171 -(views::NonClientFrameView::kClientEdgeThickness + 187 -(views::NonClientFrameView::kClientEdgeThickness +
172 bookmark_bar_->GetToolbarOverlap(true))); 188 bookmark_bar_->GetToolbarOverlap(true)));
(...skipping 18 matching lines...) Expand all
191 // basically implies the "user-perceived content area" of the browser 207 // basically implies the "user-perceived content area" of the browser
192 // window excluding the vertical scrollbar. The "user-perceived content area" 208 // window excluding the vertical scrollbar. The "user-perceived content area"
193 // excludes the detached bookmark bar (in the New Tab case) and any infobars 209 // excludes the detached bookmark bar (in the New Tab case) and any infobars
194 // since they are not _visually_ connected to the Toolbar. 210 // since they are not _visually_ connected to the Toolbar.
195 211
196 // First determine the bounding box of the content area in Widget 212 // First determine the bounding box of the content area in Widget
197 // coordinates. 213 // coordinates.
198 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( 214 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget(
199 contents_container_->GetLocalBounds()); 215 contents_container_->GetLocalBounds());
200 216
201 TopContainerView* top_container = browser_view_->top_container(); 217 gfx::Rect top_container_bounds = top_container_->ConvertRectToWidget(
202 gfx::Rect top_container_bounds = top_container->ConvertRectToWidget( 218 top_container_->GetLocalBounds());
203 top_container->GetLocalBounds());
204 219
205 // The find bar is positioned 1 pixel above the bottom of the top container so 220 // The find bar is positioned 1 pixel above the bottom of the top container so
206 // that it occludes the border between the content area and the top container 221 // that it occludes the border between the content area and the top container
207 // and looks connected to the top container. 222 // and looks connected to the top container.
208 int find_bar_y = top_container_bounds.bottom() - 1; 223 int find_bar_y = top_container_bounds.bottom() - 1;
209 224
210 // Grow the height of |bounding_box| by the height of any elements between 225 // Grow the height of |bounding_box| by the height of any elements between
211 // the top container and |contents_container_| such as the detached bookmark 226 // the top container and |contents_container_| such as the detached bookmark
212 // bar and any infobars. 227 // bar and any infobars.
213 int height_delta = bounding_box.y() - find_bar_y; 228 int height_delta = bounding_box.y() - find_bar_y;
214 bounding_box.set_y(find_bar_y); 229 bounding_box.set_y(find_bar_y);
215 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta)); 230 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta));
216 231
217 // Finally decrease the width of the bounding box by the width of 232 // Finally decrease the width of the bounding box by the width of
218 // the vertical scroll bar. 233 // the vertical scroll bar.
219 int scrollbar_width = gfx::scrollbar_size(); 234 int scrollbar_width = gfx::scrollbar_size();
220 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); 235 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width));
221 if (base::i18n::IsRTL()) 236 if (base::i18n::IsRTL())
222 bounding_box.set_x(bounding_box.x() + scrollbar_width); 237 bounding_box.set_x(bounding_box.x() + scrollbar_width);
223 238
224 return bounding_box; 239 return bounding_box;
225 } 240 }
226 241
227 bool BrowserViewLayout::IsPositionInWindowCaption( 242 bool BrowserViewLayout::IsPositionInWindowCaption(
228 const gfx::Point& point) { 243 const gfx::Point& point) {
229 TabStrip* tabstrip = browser_view_->tabstrip_;
230 // Tab strip may transiently have no parent between the RemoveChildView() and 244 // Tab strip may transiently have no parent between the RemoveChildView() and
231 // AddChildView() caused by reparenting during an immersive mode reveal. 245 // AddChildView() caused by reparenting during an immersive mode reveal.
232 // During this window report that the point didn't hit a tab. 246 // During this window report that the point didn't hit a tab.
233 if (!tabstrip->parent()) 247 if (!tab_strip_->parent())
234 return true; 248 return true;
235 gfx::Point tabstrip_point(point); 249 gfx::Point tabstrip_point(point);
236 views::View::ConvertPointToTarget(browser_view_, tabstrip, &tabstrip_point); 250 views::View::ConvertPointToTarget(browser_view_, tab_strip_, &tabstrip_point);
237 return tabstrip->IsPositionInWindowCaption(tabstrip_point); 251 return tab_strip_->IsPositionInWindowCaption(tabstrip_point);
238 } 252 }
239 253
240 int BrowserViewLayout::NonClientHitTest( 254 int BrowserViewLayout::NonClientHitTest(
241 const gfx::Point& point) { 255 const gfx::Point& point) {
242 // Since the TabStrip only renders in some parts of the top of the window, 256 // Since the TabStrip only renders in some parts of the top of the window,
243 // the un-obscured area is considered to be part of the non-client caption 257 // the un-obscured area is considered to be part of the non-client caption
244 // area of the window. So we need to treat hit-tests in these regions as 258 // area of the window. So we need to treat hit-tests in these regions as
245 // hit-tests of the titlebar. 259 // hit-tests of the titlebar.
246 260
247 views::View* parent = browser_view_->parent(); 261 views::View* parent = browser_view_->parent();
248 262
249 gfx::Point point_in_browser_view_coords(point); 263 gfx::Point point_in_browser_view_coords(point);
250 views::View::ConvertPointToTarget( 264 views::View::ConvertPointToTarget(
251 parent, browser_view_, &point_in_browser_view_coords); 265 parent, browser_view_, &point_in_browser_view_coords);
252 gfx::Point test_point(point); 266 gfx::Point test_point(point);
253 267
254 // Determine if the TabStrip exists and is capable of being clicked on. We 268 // Determine if the TabStrip exists and is capable of being clicked on. We
255 // might be a popup window without a TabStrip. 269 // might be a popup window without a TabStrip.
256 if (browser_view_->IsTabStripVisible()) { 270 if (browser_view_->IsTabStripVisible()) {
257 // See if the mouse pointer is within the bounds of the TabStrip. 271 // See if the mouse pointer is within the bounds of the TabStrip.
258 if (ConvertedHitTest(parent, browser_view_->tabstrip_, &test_point)) { 272 if (ConvertedHitTest(parent, tab_strip_, &test_point)) {
259 if (browser_view_->tabstrip_->IsPositionInWindowCaption(test_point)) 273 if (tab_strip_->IsPositionInWindowCaption(test_point))
260 return HTCAPTION; 274 return HTCAPTION;
261 return HTCLIENT; 275 return HTCLIENT;
262 } 276 }
263 277
264 // The top few pixels of the TabStrip are a drop-shadow - as we're pretty 278 // The top few pixels of the TabStrip are a drop-shadow - as we're pretty
265 // starved of dragable area, let's give it to window dragging (this also 279 // starved of dragable area, let's give it to window dragging (this also
266 // makes sense visually). 280 // makes sense visually).
267 if (!browser_view_->IsMaximized() && 281 if (!browser_view_->IsMaximized() &&
268 (point_in_browser_view_coords.y() < 282 (point_in_browser_view_coords.y() <
269 (browser_view_->tabstrip_->y() + kTabShadowSize))) { 283 (tab_strip_->y() + kTabShadowSize))) {
270 // We return HTNOWHERE as this is a signal to our containing 284 // We return HTNOWHERE as this is a signal to our containing
271 // NonClientView that it should figure out what the correct hit-test 285 // NonClientView that it should figure out what the correct hit-test
272 // code is given the mouse position... 286 // code is given the mouse position...
273 return HTNOWHERE; 287 return HTNOWHERE;
274 } 288 }
275 } 289 }
276 290
277 // If the point's y coordinate is below the top of the toolbar and otherwise 291 // If the point's y coordinate is below the top of the toolbar and otherwise
278 // within the bounds of this view, the point is considered to be within the 292 // within the bounds of this view, the point is considered to be within the
279 // client area. 293 // client area.
280 gfx::Rect bv_bounds = browser_view_->bounds(); 294 gfx::Rect bv_bounds = browser_view_->bounds();
281 bv_bounds.Offset(0, browser_view_->toolbar_->y()); 295 bv_bounds.Offset(0, toolbar_->y());
282 bv_bounds.set_height(bv_bounds.height() - browser_view_->toolbar_->y()); 296 bv_bounds.set_height(bv_bounds.height() - toolbar_->y());
283 if (bv_bounds.Contains(point)) 297 if (bv_bounds.Contains(point))
284 return HTCLIENT; 298 return HTCLIENT;
285 299
286 // If the point's y coordinate is above the top of the toolbar, but not in 300 // If the point's y coordinate is above the top of the toolbar, but not in
287 // the tabstrip (per previous checking in this function), then we consider it 301 // the tabstrip (per previous checking in this function), then we consider it
288 // in the window caption (e.g. the area to the right of the tabstrip 302 // in the window caption (e.g. the area to the right of the tabstrip
289 // underneath the window controls). However, note that we DO NOT return 303 // underneath the window controls). However, note that we DO NOT return
290 // HTCAPTION here, because when the window is maximized the window controls 304 // HTCAPTION here, because when the window is maximized the window controls
291 // will fall into this space (since the BrowserView is sized to entire size 305 // will fall into this space (since the BrowserView is sized to entire size
292 // of the window at that point), and the HTCAPTION value will cause the 306 // of the window at that point), and the HTCAPTION value will cause the
293 // window controls not to work. So we return HTNOWHERE so that the caller 307 // window controls not to work. So we return HTNOWHERE so that the caller
294 // will hit-test the window controls before finally falling back to 308 // will hit-test the window controls before finally falling back to
295 // HTCAPTION. 309 // HTCAPTION.
296 bv_bounds = browser_view_->bounds(); 310 bv_bounds = browser_view_->bounds();
297 bv_bounds.set_height(browser_view_->toolbar_->y()); 311 bv_bounds.set_height(toolbar_->y());
298 if (bv_bounds.Contains(point)) 312 if (bv_bounds.Contains(point))
299 return HTNOWHERE; 313 return HTNOWHERE;
300 314
301 // If the point is somewhere else, delegate to the default implementation. 315 // If the point is somewhere else, delegate to the default implementation.
302 return browser_view_->views::ClientView::NonClientHitTest(point); 316 return browser_view_->views::ClientView::NonClientHitTest(point);
303 } 317 }
304 318
305 ////////////////////////////////////////////////////////////////////////////// 319 //////////////////////////////////////////////////////////////////////////////
306 // BrowserViewLayout, views::LayoutManager implementation: 320 // BrowserViewLayout, views::LayoutManager implementation:
307 321
308 void BrowserViewLayout::Layout(views::View* host) { 322 void BrowserViewLayout::Layout(views::View* browser_view) {
309 vertical_layout_rect_ = browser_view_->GetLocalBounds(); 323 vertical_layout_rect_ = browser_view->GetLocalBounds();
310 int top = LayoutTabStripRegion(); 324 int top = LayoutTabStripRegion(browser_view);
311 if (browser_view_->IsTabStripVisible()) { 325 if (delegate_->IsTabStripVisible()) {
312 int x = browser_view_->tabstrip_->GetMirroredX() + 326 int x = tab_strip_->GetMirroredX() +
313 browser_view_->GetMirroredX() + 327 browser_view_->GetMirroredX() +
314 browser_view_->frame()->GetThemeBackgroundXInset(); 328 browser_view_->frame()->GetThemeBackgroundXInset();
315 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x, 329 tab_strip_->SetBackgroundOffset(
316 browser_view_->frame()->GetTabStripInsets(false).top)); 330 gfx::Point(x, browser_view_->frame()->GetTabStripInsets(false).top));
317 } 331 }
318 top = LayoutToolbar(top); 332 top = LayoutToolbar(top);
319 333
334 web_contents_modal_dialog_top_y_ =
335 top + browser_view->y() - kConstrainedWindowOverlap;
336
320 // Overlay container requires updated toolbar bounds to determine its 337 // Overlay container requires updated toolbar bounds to determine its
321 // position, and needs to be laid out before: 338 // position, and needs to be laid out before:
322 // - GetTopMarginForActiveContent(), which calls GetInstantUIState() to check 339 // - GetTopMarginForActiveContent(), which calls GetInstantUIState() to check
323 // if overlay container is visible 340 // if overlay container is visible
324 // - LayoutInfoBar(): children of infobar container will layout and call 341 // - LayoutInfoBar(): children of infobar container will layout and call
325 // BrowserView::DrawInfoBarArrows(), which checks if overlay container is 342 // BrowserView::DrawInfoBarArrows(), which checks if overlay container is
326 // visible. 343 // visible.
327 LayoutOverlayContainer(); 344 LayoutOverlayContainer();
328 345
329 top = LayoutBookmarkAndInfoBars(top); 346 top = LayoutBookmarkAndInfoBars(top);
330 347
331 // Top container requires updated toolbar and bookmark bar to compute size. 348 // Top container requires updated toolbar and bookmark bar to compute size.
332 browser_view_->top_container_->SetSize( 349 top_container_->SetSize(top_container_->GetPreferredSize());
333 browser_view_->top_container_->GetPreferredSize());
334 350
335 int bottom = LayoutDownloadShelf(browser_view_->height()); 351 int bottom = LayoutDownloadShelf(browser_view->height());
336 // Treat a detached bookmark bar as if the web contents container is shifted 352 // Treat a detached bookmark bar as if the web contents container is shifted
337 // upwards and overlaps it. 353 // upwards and overlaps it.
338 top -= GetContentsOffsetForBookmarkBar(); 354 top -= GetContentsOffsetForBookmarkBar();
339 LayoutContentsSplitView(top, bottom); 355 LayoutContentsSplitView(top, bottom);
340 356
341 // Instant extended can put suggestions in a web view, which can require an 357 // Instant extended can put suggestions in a web view, which can require an
342 // offset to align with the omnibox. This offset must be recomputed after 358 // offset to align with the omnibox. This offset must be recomputed after
343 // split view layout to account for infobar heights. 359 // split view layout to account for infobar heights.
344 int active_top_margin = GetTopMarginForActiveContent(); 360 int active_top_margin = GetTopMarginForActiveContent();
345 if (contents_container_->SetActiveTopMargin(active_top_margin)) 361 if (contents_container_->SetActiveTopMargin(active_top_margin))
(...skipping 14 matching lines...) Expand all
360 376
361 // Return the preferred size which is the size required to give each 377 // Return the preferred size which is the size required to give each
362 // children their respective preferred size. 378 // children their respective preferred size.
363 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { 379 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) {
364 return gfx::Size(); 380 return gfx::Size();
365 } 381 }
366 382
367 ////////////////////////////////////////////////////////////////////////////// 383 //////////////////////////////////////////////////////////////////////////////
368 // BrowserViewLayout, private: 384 // BrowserViewLayout, private:
369 385
370 int BrowserViewLayout::LayoutTabStripRegion() { 386 int BrowserViewLayout::LayoutTabStripRegion(views::View* browser_view) {
371 TabStrip* tabstrip = browser_view_->tabstrip_; 387 if (!delegate_->IsTabStripVisible()) {
372 if (!browser_view_->IsTabStripVisible()) { 388 tab_strip_->SetVisible(false);
373 tabstrip->SetVisible(false); 389 tab_strip_->SetBounds(0, 0, 0, 0);
374 tabstrip->SetBounds(0, 0, 0, 0);
375 return 0; 390 return 0;
376 } 391 }
377 // This retrieves the bounds for the tab strip based on whether or not we show 392 // This retrieves the bounds for the tab strip based on whether or not we show
378 // anything to the left of it, like the incognito avatar. 393 // anything to the left of it, like the incognito avatar.
379 gfx::Rect tabstrip_bounds( 394 gfx::Rect tabstrip_bounds(delegate_->GetBoundsForTabStrip(tab_strip_));
380 browser_view_->frame()->GetBoundsForTabStrip(tabstrip));
381 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); 395 gfx::Point tabstrip_origin(tabstrip_bounds.origin());
382 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_, 396 views::View::ConvertPointToTarget(
383 &tabstrip_origin); 397 browser_view->parent(), browser_view, &tabstrip_origin);
384 tabstrip_bounds.set_origin(tabstrip_origin); 398 tabstrip_bounds.set_origin(tabstrip_origin);
385 399
386 tabstrip->SetVisible(true); 400 tab_strip_->SetVisible(true);
387 tabstrip->SetBoundsRect(tabstrip_bounds); 401 tab_strip_->SetBoundsRect(tabstrip_bounds);
388 int bottom = tabstrip_bounds.bottom(); 402 int bottom = tabstrip_bounds.bottom();
389 403
390 // The metro window switcher sits at the far right edge of the tabstrip 404 // The metro window switcher sits at the far right edge of the tabstrip
391 // a |kWindowSwitcherOffsetX| pixels from the right edge. 405 // a |kWindowSwitcherOffsetX| pixels from the right edge.
392 // Only visible if there is more than one type of window to switch between. 406 // Only visible if there is more than one type of window to switch between.
393 // TODO(mad): update this code when more window types than just incognito 407 // TODO(mad): update this code when more window types than just incognito
394 // and regular are available. 408 // and regular are available.
395 views::Button* switcher_button = browser_view_->window_switcher_button_; 409 views::View* switcher_button = window_switcher_button_;
396 if (switcher_button) { 410 if (switcher_button) {
397 if (browser()->profile()->HasOffTheRecordProfile() && 411 if (browser()->profile()->HasOffTheRecordProfile() &&
398 chrome::FindBrowserWithProfile( 412 chrome::FindBrowserWithProfile(
399 browser()->profile()->GetOriginalProfile(), 413 browser()->profile()->GetOriginalProfile(),
400 browser()->host_desktop_type()) != NULL) { 414 browser()->host_desktop_type()) != NULL) {
401 switcher_button->SetVisible(true); 415 switcher_button->SetVisible(true);
402 int width = browser_view_->width(); 416 int width = browser_view->width();
403 gfx::Size ps = switcher_button->GetPreferredSize(); 417 gfx::Size ps = switcher_button->GetPreferredSize();
404 if (width > ps.width()) { 418 if (width > ps.width()) {
405 switcher_button->SetBounds(width - ps.width() - kWindowSwitcherOffsetX, 419 switcher_button->SetBounds(width - ps.width() - kWindowSwitcherOffsetX,
406 0, 420 0,
407 ps.width(), 421 ps.width(),
408 ps.height()); 422 ps.height());
409 } 423 }
410 } else { 424 } else {
411 // We hide the button if the incognito profile is not alive. 425 // We hide the button if the incognito profile is not alive.
412 // Note that Layout() is not called to all browser windows automatically 426 // Note that Layout() is not called to all browser windows automatically
413 // when a profile goes away but we rely in the metro_driver.dll to call 427 // when a profile goes away but we rely in the metro_driver.dll to call
414 // ::SetWindowPos( , .. SWP_SHOWWINDOW) which causes this function to 428 // ::SetWindowPos( , .. SWP_SHOWWINDOW) which causes this function to
415 // be called again. This works both in showing or hidding the button. 429 // be called again. This works both in showing or hidding the button.
416 switcher_button->SetVisible(false); 430 switcher_button->SetVisible(false);
417 } 431 }
418 } 432 }
419 433
420 return bottom; 434 return bottom;
421 } 435 }
422 436
423 int BrowserViewLayout::LayoutToolbar(int top) { 437 int BrowserViewLayout::LayoutToolbar(int top) {
424 ToolbarView* toolbar = browser_view_->toolbar_;
425 int browser_view_width = vertical_layout_rect_.width(); 438 int browser_view_width = vertical_layout_rect_.width();
426 bool toolbar_visible = browser_view_->IsToolbarVisible(); 439 bool toolbar_visible = delegate_->IsToolbarVisible();
427 toolbar->location_bar()->SetLocationEntryFocusable(toolbar_visible);
428 int y = top; 440 int y = top;
429 y -= (toolbar_visible && browser_view_->IsTabStripVisible()) ? 441 y -= (toolbar_visible && delegate_->IsTabStripVisible()) ?
430 kToolbarTabStripVerticalOverlap : 0; 442 kToolbarTabStripVerticalOverlap : 0;
431 int height = toolbar_visible ? toolbar->GetPreferredSize().height() : 0; 443 int height = toolbar_visible ? toolbar_->GetPreferredSize().height() : 0;
432 toolbar->SetVisible(toolbar_visible); 444 toolbar_->SetVisible(toolbar_visible);
433 toolbar->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); 445 toolbar_->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height);
434 446
435 return y + height; 447 return y + height;
436 } 448 }
437 449
438 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { 450 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) {
439 if (bookmark_bar_) { 451 if (bookmark_bar_) {
440 // If we're showing the Bookmark bar in detached style, then we 452 // If we're showing the Bookmark bar in detached style, then we
441 // need to show any Info bar _above_ the Bookmark bar, since the 453 // need to show any Info bar _above_ the Bookmark bar, since the
442 // Bookmark bar is styled to look like it's part of the page. 454 // Bookmark bar is styled to look like it's part of the page.
443 if (bookmark_bar_->IsDetached()) 455 if (bookmark_bar_->IsDetached())
444 return LayoutBookmarkBar(LayoutInfoBar(top)); 456 return LayoutBookmarkBar(LayoutInfoBar(top));
445 // Otherwise, Bookmark bar first, Info bar second. 457 // Otherwise, Bookmark bar first, Info bar second.
446 top = std::max(browser_view_->toolbar_->bounds().bottom(), 458 top = std::max(toolbar_->bounds().bottom(), LayoutBookmarkBar(top));
447 LayoutBookmarkBar(top));
448 } 459 }
449 web_contents_modal_dialog_top_y_ =
450 top + browser_view_->y() - kConstrainedWindowOverlap;
451 return LayoutInfoBar(top); 460 return LayoutInfoBar(top);
452 } 461 }
453 462
454 int BrowserViewLayout::LayoutBookmarkBar(int top) { 463 int BrowserViewLayout::LayoutBookmarkBar(int top) {
455 int y = top; 464 int y = top;
456 if (!browser_view_->IsBookmarkBarVisible()) { 465 if (!delegate_->IsBookmarkBarVisible()) {
457 bookmark_bar_->SetVisible(false); 466 bookmark_bar_->SetVisible(false);
458 // TODO(jamescook): Don't change the bookmark bar height when it is 467 // TODO(jamescook): Don't change the bookmark bar height when it is
459 // invisible, so we can use its height for layout even in that state. 468 // invisible, so we can use its height for layout even in that state.
460 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0); 469 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0);
461 return y; 470 return y;
462 } 471 }
463 472
464 bookmark_bar_->set_infobar_visible(InfobarVisible()); 473 bookmark_bar_->set_infobar_visible(InfobarVisible());
465 int bookmark_bar_height = bookmark_bar_->GetPreferredSize().height(); 474 int bookmark_bar_height = bookmark_bar_->GetPreferredSize().height();
466 y -= views::NonClientFrameView::kClientEdgeThickness + 475 y -= views::NonClientFrameView::kClientEdgeThickness +
467 bookmark_bar_->GetToolbarOverlap(false); 476 bookmark_bar_->GetToolbarOverlap(false);
468 bookmark_bar_->SetVisible(true); 477 bookmark_bar_->SetVisible(true);
469 bookmark_bar_->SetBounds(vertical_layout_rect_.x(), y, 478 bookmark_bar_->SetBounds(vertical_layout_rect_.x(), y,
470 vertical_layout_rect_.width(), 479 vertical_layout_rect_.width(),
471 bookmark_bar_height); 480 bookmark_bar_height);
472 return y + bookmark_bar_height; 481 return y + bookmark_bar_height;
473 } 482 }
474 483
475 int BrowserViewLayout::LayoutInfoBar(int top) { 484 int BrowserViewLayout::LayoutInfoBar(int top) {
476 // In immersive fullscreen, the infobar always starts near the top of the 485 // In immersive fullscreen, the infobar always starts near the top of the
477 // screen, just under the "light bar" rectangular stripes. 486 // screen, just under the "light bar" rectangular stripes.
478 if (browser_view_->immersive_mode_controller_->IsEnabled()) { 487 if (immersive_mode_controller_->IsEnabled()) {
479 top = browser_view_->immersive_mode_controller_->ShouldHideTabIndicators() ? 488 top = immersive_mode_controller_->ShouldHideTabIndicators()
480 browser_view_->y() : 489 ? browser_view_->y()
481 browser_view_->y() + TabStrip::GetImmersiveHeight(); 490 : browser_view_->y() + TabStrip::GetImmersiveHeight();
482 } 491 }
483 InfoBarContainerView* infobar_container = browser_view_->infobar_container_; 492 // Raise the |infobar_container_| by its vertical overlap.
484 // Raise the |infobar_container| by its vertical overlap. 493 infobar_container_->SetVisible(InfobarVisible());
485 infobar_container->SetVisible(InfobarVisible());
486 int height; 494 int height;
487 int overlapped_top = top - infobar_container->GetVerticalOverlap(&height); 495 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height);
488 infobar_container->SetBounds(vertical_layout_rect_.x(), 496 infobar_container_->SetBounds(vertical_layout_rect_.x(),
489 overlapped_top, 497 overlapped_top,
490 vertical_layout_rect_.width(), 498 vertical_layout_rect_.width(),
491 height); 499 height);
492 return overlapped_top + height; 500 return overlapped_top + height;
493 } 501 }
494 502
495 void BrowserViewLayout::LayoutContentsSplitView(int top, int bottom) { 503 void BrowserViewLayout::LayoutContentsSplitView(int top, int bottom) {
496 // |contents_split_| contains web page contents and devtools. 504 // |contents_split_| contains web page contents and devtools.
497 // See browser_view.h for details. 505 // See browser_view.h for details.
498 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(), 506 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(),
499 top, 507 top,
500 vertical_layout_rect_.width(), 508 vertical_layout_rect_.width(),
501 std::max(0, bottom - top)); 509 std::max(0, bottom - top));
502 contents_split_->SetBoundsRect(contents_split_bounds); 510 contents_split_->SetBoundsRect(contents_split_bounds);
503 } 511 }
504 512
505 void BrowserViewLayout::LayoutOverlayContainer() { 513 void BrowserViewLayout::LayoutOverlayContainer() {
506 bool full_height = overlay_container_->IsOverlayFullHeight(); 514 bool full_height = overlay_container_->IsOverlayFullHeight();
507 int preferred_height = 0; 515 int preferred_height = 0;
508 if (!full_height) 516 if (!full_height)
509 preferred_height = overlay_container_->GetPreferredSize().height(); 517 preferred_height = overlay_container_->GetPreferredSize().height();
510 overlay_container_->SetVisible(full_height || preferred_height > 0); 518 overlay_container_->SetVisible(full_height || preferred_height > 0);
511 if (!overlay_container_->visible()) 519 if (!overlay_container_->visible())
512 return; 520 return;
513 ToolbarView* toolbar = browser_view_->toolbar_; 521 gfx::Point bottom_edge(0, toolbar_->bounds().bottom());
514 gfx::Point bottom_edge(0, toolbar->bounds().bottom());
515 views::View::ConvertPointToTarget( 522 views::View::ConvertPointToTarget(
516 toolbar->parent(), browser_view_, &bottom_edge); 523 toolbar_->parent(), browser_view_, &bottom_edge);
517 // Overlaps with the toolbar like the attached bookmark bar would, so as to 524 // Overlaps with the toolbar like the attached bookmark bar would, so as to
518 // completely obscure the attached bookmark bar if it were visible. 525 // completely obscure the attached bookmark bar if it were visible.
519 bottom_edge.Offset(0, 526 bottom_edge.Offset(0,
520 -(views::NonClientFrameView::kClientEdgeThickness + 527 -(views::NonClientFrameView::kClientEdgeThickness +
521 BookmarkBarView::kToolbarAttachedBookmarkBarOverlap)); 528 BookmarkBarView::kToolbarAttachedBookmarkBarOverlap));
522 gfx::Rect rect(vertical_layout_rect_); 529 gfx::Rect rect(vertical_layout_rect_);
523 rect.Inset(0, bottom_edge.y(), 0, 0); 530 rect.Inset(0, bottom_edge.y(), 0, 0);
524 if (!full_height && preferred_height < rect.height()) 531 if (!full_height && preferred_height < rect.height())
525 rect.set_height(preferred_height); 532 rect.set_height(preferred_height);
526 overlay_container_->SetBoundsRect(rect); 533 overlay_container_->SetBoundsRect(rect);
(...skipping 16 matching lines...) Expand all
543 return bookmark_bar_->height() - 550 return bookmark_bar_->height() -
544 views::NonClientFrameView::kClientEdgeThickness; 551 views::NonClientFrameView::kClientEdgeThickness;
545 } 552 }
546 553
547 int BrowserViewLayout::GetTopMarginForActiveContent() { 554 int BrowserViewLayout::GetTopMarginForActiveContent() {
548 // During an immersive reveal, if instant extended is showing suggestions 555 // During an immersive reveal, if instant extended is showing suggestions
549 // in the main active web view, ensure that active web view appears aligned 556 // in the main active web view, ensure that active web view appears aligned
550 // with the bottom of the omnibox. 557 // with the bottom of the omnibox.
551 InstantUIState instant_ui_state = GetInstantUIState(); 558 InstantUIState instant_ui_state = GetInstantUIState();
552 if (instant_ui_state == kInstantUIFullPageResults && 559 if (instant_ui_state == kInstantUIFullPageResults &&
553 browser_view_->immersive_mode_controller()->IsRevealed()) 560 immersive_mode_controller_->IsRevealed())
554 return GetTopMarginForImmersiveInstant(); 561 return GetTopMarginForImmersiveInstant();
555 562
556 // Usually we only use a margin if there's a detached bookmarks bar. 563 // Usually we only use a margin if there's a detached bookmarks bar.
557 return GetContentsOffsetForBookmarkBar(); 564 return GetContentsOffsetForBookmarkBar();
558 } 565 }
559 566
560 int BrowserViewLayout::GetTopMarginForImmersiveInstant() { 567 int BrowserViewLayout::GetTopMarginForImmersiveInstant() {
561 // Compute the position of the bottom edge of the top container views, 568 // Compute the position of the bottom edge of the top container views,
562 // expressed as an offset in the coordinates of |contents_container_|, 569 // expressed as an offset in the coordinates of |contents_container_|,
563 // because the offset will be applied in |contents_container_| layout. 570 // because the offset will be applied in |contents_container_| layout.
564 // NOTE: This requires contents_split_ layout to be complete, as the 571 // NOTE: This requires contents_split_ layout to be complete, as the
565 // coordinate system conversion depends on the contents_split_ origin. 572 // coordinate system conversion depends on the contents_split_ origin.
566 gfx::Point bottom_edge(0, browser_view_->top_container_->height()); 573 gfx::Point bottom_edge(0, top_container_->height());
567 views::View::ConvertPointToTarget(browser_view_->top_container_, 574 views::View::ConvertPointToTarget(top_container_,
568 contents_container_, 575 contents_container_,
569 &bottom_edge); 576 &bottom_edge);
570 return bottom_edge.y(); 577 return bottom_edge.y();
571 } 578 }
572 579
573 BrowserViewLayout::InstantUIState BrowserViewLayout::GetInstantUIState() { 580 BrowserViewLayout::InstantUIState BrowserViewLayout::GetInstantUIState() {
574 if (!browser()->search_model()->mode().is_search()) 581 if (!browser()->search_model()->mode().is_search())
575 return kInstantUINone; 582 return kInstantUINone;
576 583
577 // If the search suggestions are already being displayed in the overlay 584 // If the search suggestions are already being displayed in the overlay
578 // contents then return kInstantUIOverlay. 585 // contents then return kInstantUIOverlay.
579 if (overlay_container_->visible()) 586 if (overlay_container_->visible())
580 return kInstantUIOverlay; 587 return kInstantUIOverlay;
581 588
582 // Top bars stay visible until the results page notifies Chrome it is ready. 589 // Top bars stay visible until the results page notifies Chrome it is ready.
583 if (browser()->search_model()->top_bars_visible()) 590 if (browser()->search_model()->top_bars_visible())
584 return kInstantUINone; 591 return kInstantUINone;
585 592
586 return kInstantUIFullPageResults; 593 return kInstantUIFullPageResults;
587 } 594 }
588 595
589 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { 596 int BrowserViewLayout::LayoutDownloadShelf(int bottom) {
590 // Re-layout the shelf either if it is visible or if its close animation 597 if (delegate_->DownloadShelfNeedsLayout()) {
591 // is currently running.
592 if (browser_view_->IsDownloadShelfVisible() ||
593 (download_shelf_ && download_shelf_->IsClosing())) {
594 bool visible = browser()->SupportsWindowFeature( 598 bool visible = browser()->SupportsWindowFeature(
595 Browser::FEATURE_DOWNLOADSHELF); 599 Browser::FEATURE_DOWNLOADSHELF);
596 DCHECK(download_shelf_); 600 DCHECK(download_shelf_);
597 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; 601 int height = visible ? download_shelf_->GetPreferredSize().height() : 0;
598 download_shelf_->SetVisible(visible); 602 download_shelf_->SetVisible(visible);
599 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, 603 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height,
600 vertical_layout_rect_.width(), height); 604 vertical_layout_rect_.width(), height);
601 download_shelf_->Layout(); 605 download_shelf_->Layout();
602 bottom -= height; 606 bottom -= height;
603 } 607 }
604 return bottom; 608 return bottom;
605 } 609 }
606 610
607 bool BrowserViewLayout::InfobarVisible() const { 611 bool BrowserViewLayout::InfobarVisible() const {
608 // Cast to a views::View to access GetPreferredSize(). 612 // Cast to a views::View to access GetPreferredSize().
609 views::View* infobar_container = infobar_container_; 613 views::View* infobar_container = infobar_container_;
610 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. 614 // NOTE: Can't check if the size IsEmpty() since it's always 0-width.
611 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && 615 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) &&
612 (infobar_container->GetPreferredSize().height() != 0); 616 (infobar_container->GetPreferredSize().height() != 0);
613 } 617 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view_layout.h ('k') | chrome/browser/ui/views/frame/browser_view_layout_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698