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