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