browser_view_layout.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/frame/browser_view_layout.h" 6 7#include "base/observer_list.h" 8#include "chrome/browser/profiles/profile.h" 9#include "chrome/browser/ui/browser.h" 10#include "chrome/browser/ui/browser_finder.h" 11#include "chrome/browser/ui/browser_window.h" 12#include "chrome/browser/ui/find_bar/find_bar.h" 13#include "chrome/browser/ui/find_bar/find_bar_controller.h" 14#include "chrome/browser/ui/search/search_model.h" 15#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 16#include "chrome/browser/ui/views/download/download_shelf_view.h" 17#include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" 18#include "chrome/browser/ui/views/frame/contents_layout_manager.h" 19#include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 20#include "chrome/browser/ui/views/frame/top_container_view.h" 21#include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" 22#include "chrome/browser/ui/views/infobars/infobar_container_view.h" 23#include "chrome/browser/ui/views/tabs/tab_strip.h" 24#include "components/web_modal/web_contents_modal_dialog_host.h" 25#include "ui/base/hit_test.h" 26#include "ui/gfx/point.h" 27#include "ui/gfx/scrollbar_size.h" 28#include "ui/gfx/size.h" 29#include "ui/views/controls/webview/webview.h" 30#include "ui/views/widget/widget.h" 31#include "ui/views/window/client_view.h" 32 33using views::View; 34using web_modal::WebContentsModalDialogHost; 35using web_modal::ModalDialogHostObserver; 36 37namespace { 38 39// The visible height of the shadow above the tabs. Clicks in this area are 40// treated as clicks to the frame, rather than clicks to the tab. 41const int kTabShadowSize = 2; 42// The number of pixels the metro switcher is offset from the right edge. 43const int kWindowSwitcherOffsetX = 7; 44// The number of pixels the constrained window should overlap the bottom 45// of the omnibox. 46const int kConstrainedWindowOverlap = 3; 47 48// Combines View::ConvertPointToTarget and View::HitTest for a given |point|. 49// Converts |point| from |src| to |dst| and hit tests it against |dst|. The 50// converted |point| can then be retrieved and used for additional tests. 51bool ConvertedHitTest(views::View* src, views::View* dst, gfx::Point* point) { 52 DCHECK(src); 53 DCHECK(dst); 54 DCHECK(point); 55 views::View::ConvertPointToTarget(src, dst, point); 56 return dst->HitTestPoint(*point); 57} 58 59} // namespace 60 61class BrowserViewLayout::WebContentsModalDialogHostViews 62 : public WebContentsModalDialogHost { 63 public: 64 explicit WebContentsModalDialogHostViews( 65 BrowserViewLayout* browser_view_layout) 66 : browser_view_layout_(browser_view_layout) { 67 } 68 69 virtual ~WebContentsModalDialogHostViews() { 70 FOR_EACH_OBSERVER(ModalDialogHostObserver, 71 observer_list_, 72 OnHostDestroying()); 73 } 74 75 void NotifyPositionRequiresUpdate() { 76 FOR_EACH_OBSERVER(ModalDialogHostObserver, 77 observer_list_, 78 OnPositionRequiresUpdate()); 79 } 80 81 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { 82 views::View* view = browser_view_layout_->delegate_->GetContentsWebView(); 83 gfx::Rect content_area = view->ConvertRectToWidget(view->GetLocalBounds()); 84 const int middle_x = content_area.x() + content_area.width() / 2; 85 const int top = browser_view_layout_->web_contents_modal_dialog_top_y_; 86 return gfx::Point(middle_x - size.width() / 2, top); 87 } 88 89 virtual gfx::Size GetMaximumDialogSize() OVERRIDE { 90 views::View* view = browser_view_layout_->delegate_->GetContentsWebView(); 91 gfx::Rect content_area = view->ConvertRectToWidget(view->GetLocalBounds()); 92 const int top = browser_view_layout_->web_contents_modal_dialog_top_y_; 93 return gfx::Size(content_area.width(), content_area.bottom() - top); 94 } 95 96 private: 97 virtual gfx::NativeView GetHostView() const OVERRIDE { 98 gfx::NativeWindow window = 99 browser_view_layout_->browser()->window()->GetNativeWindow(); 100 return views::Widget::GetWidgetForNativeWindow(window)->GetNativeView(); 101 } 102 103 // Add/remove observer. 104 virtual void AddObserver(ModalDialogHostObserver* observer) OVERRIDE { 105 observer_list_.AddObserver(observer); 106 } 107 virtual void RemoveObserver(ModalDialogHostObserver* observer) OVERRIDE { 108 observer_list_.RemoveObserver(observer); 109 } 110 111 BrowserViewLayout* const browser_view_layout_; 112 113 ObserverList<ModalDialogHostObserver> observer_list_; 114 115 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostViews); 116}; 117 118// static 119const int BrowserViewLayout::kToolbarTabStripVerticalOverlap = 3; 120 121//////////////////////////////////////////////////////////////////////////////// 122// BrowserViewLayout, public: 123 124BrowserViewLayout::BrowserViewLayout() 125 : browser_(NULL), 126 browser_view_(NULL), 127 top_container_(NULL), 128 tab_strip_(NULL), 129 toolbar_(NULL), 130 bookmark_bar_(NULL), 131 infobar_container_(NULL), 132 contents_container_(NULL), 133 contents_layout_manager_(NULL), 134 download_shelf_(NULL), 135 immersive_mode_controller_(NULL), 136 dialog_host_(new WebContentsModalDialogHostViews(this)), 137 web_contents_modal_dialog_top_y_(-1) {} 138 139BrowserViewLayout::~BrowserViewLayout() { 140} 141 142void BrowserViewLayout::Init( 143 BrowserViewLayoutDelegate* delegate, 144 Browser* browser, 145 views::ClientView* browser_view, 146 views::View* top_container, 147 TabStrip* tab_strip, 148 views::View* toolbar, 149 InfoBarContainerView* infobar_container, 150 views::View* contents_container, 151 ContentsLayoutManager* contents_layout_manager, 152 ImmersiveModeController* immersive_mode_controller) { 153 delegate_.reset(delegate); 154 browser_ = browser; 155 browser_view_ = browser_view; 156 top_container_ = top_container; 157 tab_strip_ = tab_strip; 158 toolbar_ = toolbar; 159 infobar_container_ = infobar_container; 160 contents_container_ = contents_container; 161 contents_layout_manager_ = contents_layout_manager; 162 immersive_mode_controller_ = immersive_mode_controller; 163} 164 165WebContentsModalDialogHost* 166 BrowserViewLayout::GetWebContentsModalDialogHost() { 167 return dialog_host_.get(); 168} 169 170gfx::Size BrowserViewLayout::GetMinimumSize() { 171 gfx::Size tabstrip_size( 172 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? 173 tab_strip_->GetMinimumSize() : gfx::Size()); 174 gfx::Size toolbar_size( 175 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || 176 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? 177 toolbar_->GetMinimumSize() : gfx::Size()); 178 if (tabstrip_size.height() && toolbar_size.height()) 179 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); 180 gfx::Size bookmark_bar_size; 181 if (bookmark_bar_ && 182 bookmark_bar_->visible() && 183 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { 184 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); 185 bookmark_bar_size.Enlarge(0, -bookmark_bar_->GetToolbarOverlap()); 186 } 187 gfx::Size infobar_container_size(infobar_container_->GetMinimumSize()); 188 // TODO: Adjust the minimum height for the find bar. 189 190 gfx::Size contents_size(contents_container_->GetMinimumSize()); 191 192 int min_height = delegate_->GetTopInsetInBrowserView() + 193 tabstrip_size.height() + toolbar_size.height() + 194 bookmark_bar_size.height() + infobar_container_size.height() + 195 contents_size.height(); 196 int widths[] = { 197 tabstrip_size.width(), 198 toolbar_size.width(), 199 bookmark_bar_size.width(), 200 infobar_container_size.width(), 201 contents_size.width() }; 202 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); 203 return gfx::Size(min_width, min_height); 204} 205 206gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const { 207 // This function returns the area the Find Bar can be laid out within. This 208 // basically implies the "user-perceived content area" of the browser 209 // window excluding the vertical scrollbar. The "user-perceived content area" 210 // excludes the detached bookmark bar (in the New Tab case) and any infobars 211 // since they are not _visually_ connected to the Toolbar. 212 213 // First determine the bounding box of the content area in Widget 214 // coordinates. 215 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( 216 contents_container_->GetLocalBounds()); 217 218 gfx::Rect top_container_bounds = top_container_->ConvertRectToWidget( 219 top_container_->GetLocalBounds()); 220 221 int find_bar_y = 0; 222 if (immersive_mode_controller_->IsEnabled() && 223 !immersive_mode_controller_->IsRevealed()) { 224 // Position the find bar exactly below the top container. In immersive 225 // fullscreen, when the top-of-window views are not revealed, only the 226 // miniature immersive style tab strip is visible. Do not overlap the 227 // find bar and the tab strip. 228 find_bar_y = top_container_bounds.bottom(); 229 } else { 230 // Position the find bar 1 pixel above the bottom of the top container 231 // so that it occludes the border between the content area and the top 232 // container and looks connected to the top container. 233 find_bar_y = top_container_bounds.bottom() - 1; 234 } 235 236 // Grow the height of |bounding_box| by the height of any elements between 237 // the top container and |contents_container_| such as the detached bookmark 238 // bar and any infobars. 239 int height_delta = bounding_box.y() - find_bar_y; 240 bounding_box.set_y(find_bar_y); 241 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta)); 242 243 // Finally decrease the width of the bounding box by the width of 244 // the vertical scroll bar. 245 int scrollbar_width = gfx::scrollbar_size(); 246 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); 247 if (base::i18n::IsRTL()) 248 bounding_box.set_x(bounding_box.x() + scrollbar_width); 249 250 return bounding_box; 251} 252 253int BrowserViewLayout::NonClientHitTest(const gfx::Point& point) { 254 // Since the TabStrip only renders in some parts of the top of the window, 255 // the un-obscured area is considered to be part of the non-client caption 256 // area of the window. So we need to treat hit-tests in these regions as 257 // hit-tests of the titlebar. 258 259 views::View* parent = browser_view_->parent(); 260 261 gfx::Point point_in_browser_view_coords(point); 262 views::View::ConvertPointToTarget( 263 parent, browser_view_, &point_in_browser_view_coords); 264 gfx::Point test_point(point); 265 266 // Determine if the TabStrip exists and is capable of being clicked on. We 267 // might be a popup window without a TabStrip. 268 if (delegate_->IsTabStripVisible()) { 269 // See if the mouse pointer is within the bounds of the TabStrip. 270 if (ConvertedHitTest(parent, tab_strip_, &test_point)) { 271 if (tab_strip_->IsPositionInWindowCaption(test_point)) 272 return HTCAPTION; 273 return HTCLIENT; 274 } 275 276 // The top few pixels of the TabStrip are a drop-shadow - as we're pretty 277 // starved of dragable area, let's give it to window dragging (this also 278 // makes sense visually). 279 views::Widget* widget = browser_view_->GetWidget(); 280 if (!(widget->IsMaximized() || widget->IsFullscreen()) && 281 (point_in_browser_view_coords.y() < 282 (tab_strip_->y() + kTabShadowSize))) { 283 // We return HTNOWHERE as this is a signal to our containing 284 // NonClientView that it should figure out what the correct hit-test 285 // code is given the mouse position... 286 return HTNOWHERE; 287 } 288 } 289 290 // If the point's y coordinate is below the top of the toolbar and otherwise 291 // within the bounds of this view, the point is considered to be within the 292 // client area. 293 gfx::Rect bv_bounds = browser_view_->bounds(); 294 bv_bounds.Offset(0, toolbar_->y()); 295 bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); 296 if (bv_bounds.Contains(point)) 297 return HTCLIENT; 298 299 // If the point is within the bounds of the window switcher button, the point 300 // is considered to be within the client area. 301 views::View* window_switcher_button = delegate_->GetWindowSwitcherButton(); 302 if (window_switcher_button && window_switcher_button->visible()) { 303 gfx::Point window_switcher_point(point_in_browser_view_coords); 304 views::View::ConvertPointToTarget(browser_view_, window_switcher_button, 305 &window_switcher_point); 306 if (window_switcher_button->HitTestPoint(window_switcher_point)) 307 return HTCLIENT; 308 } 309 310 // If the point's y coordinate is above the top of the toolbar, but neither 311 // over the tabstrip nor over the window switcher button (per previous 312 // checking in this function), then we consider it in the window caption 313 // (e.g. the area to the right of the tabstrip underneath the window 314 // controls). However, note that we DO NOT return HTCAPTION here, because 315 // when the window is maximized the window controls will fall into this 316 // space (since the BrowserView is sized to entire size of the window at that 317 // point), and the HTCAPTION value will cause the window controls not to work. 318 // So we return HTNOWHERE so that the caller will hit-test the window controls 319 // before finally falling back to HTCAPTION. 320 bv_bounds = browser_view_->bounds(); 321 bv_bounds.set_height(toolbar_->y()); 322 if (bv_bounds.Contains(point)) 323 return HTNOWHERE; 324 325 // If the point is somewhere else, delegate to the default implementation. 326 return browser_view_->views::ClientView::NonClientHitTest(point); 327} 328 329////////////////////////////////////////////////////////////////////////////// 330// BrowserViewLayout, views::LayoutManager implementation: 331 332void BrowserViewLayout::Layout(views::View* browser_view) { 333 vertical_layout_rect_ = browser_view->GetLocalBounds(); 334 int top = delegate_->GetTopInsetInBrowserView(); 335 top = LayoutTabStripRegion(top); 336 if (delegate_->IsTabStripVisible()) { 337 int x = tab_strip_->GetMirroredX() + 338 browser_view_->GetMirroredX() + 339 delegate_->GetThemeBackgroundXInset(); 340 int y = browser_view_->y() + delegate_->GetTopInsetInBrowserView(); 341 tab_strip_->SetBackgroundOffset(gfx::Point(x, y)); 342 } 343 top = LayoutToolbar(top); 344 345 top = LayoutBookmarkAndInfoBars(top, browser_view->y()); 346 347 // Top container requires updated toolbar and bookmark bar to compute bounds. 348 UpdateTopContainerBounds(); 349 350 int bottom = LayoutDownloadShelf(browser_view->height()); 351 // Treat a detached bookmark bar as if the web contents container is shifted 352 // upwards and overlaps it. 353 int active_top_margin = GetContentsOffsetForBookmarkBar(); 354 contents_layout_manager_->SetActiveTopMargin(active_top_margin); 355 top -= active_top_margin; 356 LayoutContentsContainerView(top, bottom); 357 358 // This must be done _after_ we lay out the WebContents since this 359 // code calls back into us to find the bounding box the find bar 360 // must be laid out within, and that code depends on the 361 // TabContentsContainer's bounds being up to date. 362 if (browser()->HasFindBarController()) { 363 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( 364 gfx::Rect(), true); 365 } 366 367 // Adjust the fullscreen exit bubble bounds for |top_container_|'s new bounds. 368 // This makes the fullscreen exit bubble look like it animates with 369 // |top_container_| in immersive fullscreen. 370 FullscreenExitBubbleViews* fullscreen_exit_bubble = 371 delegate_->GetFullscreenExitBubble(); 372 if (fullscreen_exit_bubble) 373 fullscreen_exit_bubble->RepositionIfVisible(); 374 375 // Adjust any hosted dialogs if the browser's dialog hosting bounds changed. 376 const gfx::Rect dialog_bounds(dialog_host_->GetDialogPosition(gfx::Size()), 377 dialog_host_->GetMaximumDialogSize()); 378 if (latest_dialog_bounds_ != dialog_bounds) { 379 latest_dialog_bounds_ = dialog_bounds; 380 dialog_host_->NotifyPositionRequiresUpdate(); 381 } 382} 383 384// Return the preferred size which is the size required to give each 385// children their respective preferred size. 386gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { 387 return gfx::Size(); 388} 389 390////////////////////////////////////////////////////////////////////////////// 391// BrowserViewLayout, private: 392 393int BrowserViewLayout::LayoutTabStripRegion(int top) { 394 if (!delegate_->IsTabStripVisible()) { 395 tab_strip_->SetVisible(false); 396 tab_strip_->SetBounds(0, 0, 0, 0); 397 return top; 398 } 399 // This retrieves the bounds for the tab strip based on whether or not we show 400 // anything to the left of it, like the incognito avatar. 401 gfx::Rect tabstrip_bounds(delegate_->GetBoundsForTabStripInBrowserView()); 402 403 tab_strip_->SetVisible(true); 404 tab_strip_->SetBoundsRect(tabstrip_bounds); 405 int bottom = tabstrip_bounds.bottom(); 406 407 // The metro window switcher sits at the far right edge of the tabstrip 408 // a |kWindowSwitcherOffsetX| pixels from the right edge. 409 // Only visible if there is more than one type of window to switch between. 410 // TODO(mad): update this code when more window types than just incognito 411 // and regular are available. 412 views::View* switcher_button = delegate_->GetWindowSwitcherButton(); 413 if (switcher_button) { 414 if (browser()->profile()->HasOffTheRecordProfile() && 415 chrome::FindBrowserWithProfile( 416 browser()->profile()->GetOriginalProfile(), 417 browser()->host_desktop_type()) != NULL) { 418 switcher_button->SetVisible(true); 419 int width = browser_view_->width(); 420 gfx::Size ps = switcher_button->GetPreferredSize(); 421 if (width > ps.width()) { 422 switcher_button->SetBounds(width - ps.width() - kWindowSwitcherOffsetX, 423 0, 424 ps.width(), 425 ps.height()); 426 } 427 } else { 428 // We hide the button if the incognito profile is not alive. 429 // Note that Layout() is not called to all browser windows automatically 430 // when a profile goes away but we rely in the metro_driver.dll to call 431 // ::SetWindowPos( , .. SWP_SHOWWINDOW) which causes this function to 432 // be called again. This works both in showing or hidding the button. 433 switcher_button->SetVisible(false); 434 } 435 } 436 437 return bottom; 438} 439 440int BrowserViewLayout::LayoutToolbar(int top) { 441 int browser_view_width = vertical_layout_rect_.width(); 442 bool toolbar_visible = delegate_->IsToolbarVisible(); 443 int y = top; 444 y -= (toolbar_visible && delegate_->IsTabStripVisible()) ? 445 kToolbarTabStripVerticalOverlap : 0; 446 int height = toolbar_visible ? toolbar_->GetPreferredSize().height() : 0; 447 toolbar_->SetVisible(toolbar_visible); 448 toolbar_->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); 449 450 return y + height; 451} 452 453int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top, int browser_view_y) { 454 web_contents_modal_dialog_top_y_ = 455 top + browser_view_y - kConstrainedWindowOverlap; 456 457 if (bookmark_bar_) { 458 // If we're showing the Bookmark bar in detached style, then we 459 // need to show any Info bar _above_ the Bookmark bar, since the 460 // Bookmark bar is styled to look like it's part of the page. 461 if (bookmark_bar_->IsDetached()) { 462 web_contents_modal_dialog_top_y_ = 463 top + browser_view_y - kConstrainedWindowOverlap; 464 return LayoutBookmarkBar(LayoutInfoBar(top)); 465 } 466 // Otherwise, Bookmark bar first, Info bar second. 467 top = std::max(toolbar_->bounds().bottom(), LayoutBookmarkBar(top)); 468 } 469 470 return LayoutInfoBar(top); 471} 472 473int BrowserViewLayout::LayoutBookmarkBar(int top) { 474 int y = top; 475 if (!delegate_->IsBookmarkBarVisible()) { 476 bookmark_bar_->SetVisible(false); 477 // TODO(jamescook): Don't change the bookmark bar height when it is 478 // invisible, so we can use its height for layout even in that state. 479 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0); 480 return y; 481 } 482 483 bookmark_bar_->set_infobar_visible(InfobarVisible()); 484 int bookmark_bar_height = bookmark_bar_->GetPreferredSize().height(); 485 y -= bookmark_bar_->GetToolbarOverlap(); 486 bookmark_bar_->SetBounds(vertical_layout_rect_.x(), 487 y, 488 vertical_layout_rect_.width(), 489 bookmark_bar_height); 490 // Set visibility after setting bounds, as the visibility update uses the 491 // bounds to determine if the mouse is hovering over a button. 492 bookmark_bar_->SetVisible(true); 493 return y + bookmark_bar_height; 494} 495 496int BrowserViewLayout::LayoutInfoBar(int top) { 497 // In immersive fullscreen, the infobar always starts near the top of the 498 // screen, just under the "light bar" rectangular stripes. 499 if (immersive_mode_controller_->IsEnabled()) { 500 top = browser_view_->y(); 501 if (!immersive_mode_controller_->ShouldHideTabIndicators()) 502 top += TabStrip::GetImmersiveHeight(); 503 } 504 // Raise the |infobar_container_| by its vertical overlap. 505 infobar_container_->SetVisible(InfobarVisible()); 506 int height; 507 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); 508 infobar_container_->SetBounds(vertical_layout_rect_.x(), 509 overlapped_top, 510 vertical_layout_rect_.width(), 511 height); 512 return overlapped_top + height; 513} 514 515void BrowserViewLayout::LayoutContentsContainerView(int top, int bottom) { 516 // |contents_container_| contains web page contents and devtools. 517 // See browser_view.h for details. 518 gfx::Rect contents_container_bounds(vertical_layout_rect_.x(), 519 top, 520 vertical_layout_rect_.width(), 521 std::max(0, bottom - top)); 522 contents_container_->SetBoundsRect(contents_container_bounds); 523} 524 525void BrowserViewLayout::UpdateTopContainerBounds() { 526 // Set the bounds of the top container view such that it is tall enough to 527 // fully show all of its children. In particular, the bottom of the bookmark 528 // bar can be above the bottom of the toolbar while the bookmark bar is 529 // animating. The top container view is positioned relative to the top of the 530 // client view instead of relative to GetTopInsetInBrowserView() because the 531 // top container view paints parts of the frame (title, window controls) 532 // during an immersive fullscreen reveal. 533 int height = 0; 534 for (int i = 0; i < top_container_->child_count(); ++i) { 535 views::View* child = top_container_->child_at(i); 536 if (!child->visible()) 537 continue; 538 int child_bottom = child->bounds().bottom(); 539 if (child_bottom > height) 540 height = child_bottom; 541 } 542 543 // Ensure that the top container view reaches the topmost view in the 544 // ClientView because the bounds of the top container view are used in 545 // layout and we assume that this is the case. 546 height = std::max(height, delegate_->GetTopInsetInBrowserView()); 547 548 gfx::Rect top_container_bounds(vertical_layout_rect_.width(), height); 549 550 // If the immersive mode controller is animating the top container, it may be 551 // partly offscreen. 552 top_container_bounds.set_y( 553 immersive_mode_controller_->GetTopContainerVerticalOffset( 554 top_container_bounds.size())); 555 top_container_->SetBoundsRect(top_container_bounds); 556} 557 558int BrowserViewLayout::GetContentsOffsetForBookmarkBar() { 559 // If the bookmark bar is hidden or attached to the omnibox the web contents 560 // will appear directly underneath it and does not need an offset. 561 if (!bookmark_bar_ || 562 !delegate_->IsBookmarkBarVisible() || 563 !bookmark_bar_->IsDetached()) { 564 return 0; 565 } 566 567 // Offset for the detached bookmark bar. 568 return bookmark_bar_->height() - 569 bookmark_bar_->GetFullyDetachedToolbarOverlap(); 570} 571 572int BrowserViewLayout::LayoutDownloadShelf(int bottom) { 573 if (delegate_->DownloadShelfNeedsLayout()) { 574 bool visible = browser()->SupportsWindowFeature( 575 Browser::FEATURE_DOWNLOADSHELF); 576 DCHECK(download_shelf_); 577 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; 578 download_shelf_->SetVisible(visible); 579 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, 580 vertical_layout_rect_.width(), height); 581 download_shelf_->Layout(); 582 bottom -= height; 583 } 584 return bottom; 585} 586 587bool BrowserViewLayout::InfobarVisible() const { 588 // Cast to a views::View to access GetPreferredSize(). 589 views::View* infobar_container = infobar_container_; 590 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. 591 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && 592 (infobar_container->GetPreferredSize().height() != 0); 593} 594