| OLD | NEW |
| 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_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/find_bar/find_bar.h" | 10 #include "chrome/browser/ui/find_bar/find_bar.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // BrowserViewLayout, public: | 106 // BrowserViewLayout, public: |
| 107 | 107 |
| 108 BrowserViewLayout::BrowserViewLayout() | 108 BrowserViewLayout::BrowserViewLayout() |
| 109 : browser_(NULL), | 109 : browser_(NULL), |
| 110 browser_view_(NULL), | 110 browser_view_(NULL), |
| 111 bookmark_bar_(NULL), | 111 bookmark_bar_(NULL), |
| 112 infobar_container_(NULL), | 112 infobar_container_(NULL), |
| 113 contents_split_(NULL), | 113 contents_split_(NULL), |
| 114 contents_container_(NULL), | 114 contents_container_(NULL), |
| 115 download_shelf_(NULL), | 115 download_shelf_(NULL), |
| 116 find_bar_y_(0), | |
| 117 ALLOW_THIS_IN_INITIALIZER_LIST( | 116 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 118 dialog_host_(new WebContentsModalDialogHostViews(this))), | 117 dialog_host_(new WebContentsModalDialogHostViews(this))), |
| 119 web_contents_modal_dialog_top_y_(-1) { | 118 web_contents_modal_dialog_top_y_(-1) { |
| 120 } | 119 } |
| 121 | 120 |
| 122 BrowserViewLayout::~BrowserViewLayout() { | 121 BrowserViewLayout::~BrowserViewLayout() { |
| 123 } | 122 } |
| 124 | 123 |
| 125 void BrowserViewLayout::Init(Browser* browser, | 124 void BrowserViewLayout::Init(Browser* browser, |
| 126 BrowserView* browser_view, | 125 BrowserView* browser_view, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 153 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); | 152 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); |
| 154 gfx::Size bookmark_bar_size; | 153 gfx::Size bookmark_bar_size; |
| 155 if (bookmark_bar_ && | 154 if (bookmark_bar_ && |
| 156 bookmark_bar_->visible() && | 155 bookmark_bar_->visible() && |
| 157 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { | 156 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { |
| 158 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); | 157 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); |
| 159 bookmark_bar_size.Enlarge(0, | 158 bookmark_bar_size.Enlarge(0, |
| 160 -(views::NonClientFrameView::kClientEdgeThickness + | 159 -(views::NonClientFrameView::kClientEdgeThickness + |
| 161 bookmark_bar_->GetToolbarOverlap(true))); | 160 bookmark_bar_->GetToolbarOverlap(true))); |
| 162 } | 161 } |
| 162 // TODO: Adjust the minimum height for the find bar. |
| 163 |
| 163 gfx::Size contents_size(contents_split_->GetMinimumSize()); | 164 gfx::Size contents_size(contents_split_->GetMinimumSize()); |
| 164 | 165 |
| 165 int min_height = tabstrip_size.height() + toolbar_size.height() + | 166 int min_height = tabstrip_size.height() + toolbar_size.height() + |
| 166 bookmark_bar_size.height() + contents_size.height(); | 167 bookmark_bar_size.height() + contents_size.height(); |
| 167 int widths[] = { | 168 int widths[] = { |
| 168 tabstrip_size.width() + tab_strip_insets.left + tab_strip_insets.right, | 169 tabstrip_size.width() + tab_strip_insets.left + tab_strip_insets.right, |
| 169 toolbar_size.width(), | 170 toolbar_size.width(), |
| 170 bookmark_bar_size.width(), | 171 bookmark_bar_size.width(), |
| 171 contents_size.width() }; | 172 contents_size.width() }; |
| 172 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); | 173 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); |
| 173 return gfx::Size(min_width, min_height); | 174 return gfx::Size(min_width, min_height); |
| 174 } | 175 } |
| 175 | 176 |
| 176 gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const { | 177 gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const { |
| 177 // This function returns the area the Find Bar can be laid out | 178 // This function returns the area the Find Bar can be laid out within. This |
| 178 // within. This basically implies the "user-perceived content | 179 // basically implies the "user-perceived content area" of the browser |
| 179 // area" of the browser window excluding the vertical | 180 // window excluding the vertical scrollbar. The "user-perceived content area" |
| 180 // scrollbar. This is not quite so straightforward as positioning | 181 // excludes the detached bookmark bar (in the New Tab case) and any infobars |
| 181 // based on the TabContentsContainer since the BookmarkBarView may | 182 // since they are not _visually_ connected to the Toolbar. |
| 182 // be visible but not persistent (in the New Tab case) and we | |
| 183 // position the Find Bar over the top of it in that case since the | |
| 184 // BookmarkBarView is not _visually_ connected to the Toolbar. | |
| 185 | 183 |
| 186 // First determine the bounding box of the content area in Widget | 184 // First determine the bounding box of the content area in Widget |
| 187 // coordinates. | 185 // coordinates. |
| 188 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( | 186 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( |
| 189 contents_container_->GetLocalBounds()); | 187 contents_container_->GetLocalBounds()); |
| 190 | 188 |
| 191 // Adjust the position and size of the bounding box by the find bar offset | 189 TopContainerView* top_container = browser_view_->top_container(); |
| 192 // calculated during the last Layout. | 190 gfx::Rect top_container_bounds = top_container->ConvertRectToWidget( |
| 193 int height_delta = find_bar_y_ - bounding_box.y(); | 191 top_container->GetLocalBounds()); |
| 194 bounding_box.set_y(find_bar_y_); | 192 |
| 193 // The find bar is positioned 1 pixel above the bottom of the top container so |
| 194 // that it occludes the border between the content area and the top container |
| 195 // and looks connected to the top container. |
| 196 int find_bar_y = top_container_bounds.bottom() - 1; |
| 197 |
| 198 // Grow the height of |bounding_box| by the height of any elements between |
| 199 // the top container and |contents_container_| such as the detached bookmark |
| 200 // bar and any infobars. |
| 201 int height_delta = bounding_box.y() - find_bar_y; |
| 202 bounding_box.set_y(find_bar_y); |
| 195 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta)); | 203 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta)); |
| 196 | 204 |
| 197 // Finally decrease the width of the bounding box by the width of | 205 // Finally decrease the width of the bounding box by the width of |
| 198 // the vertical scroll bar. | 206 // the vertical scroll bar. |
| 199 int scrollbar_width = gfx::scrollbar_size(); | 207 int scrollbar_width = gfx::scrollbar_size(); |
| 200 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); | 208 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); |
| 201 if (base::i18n::IsRTL()) | 209 if (base::i18n::IsRTL()) |
| 202 bounding_box.set_x(bounding_box.x() + scrollbar_width); | 210 bounding_box.set_x(bounding_box.x() + scrollbar_width); |
| 203 | 211 |
| 204 return bounding_box; | 212 return bounding_box; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 int height = toolbar_visible ? toolbar->GetPreferredSize().height() : 0; | 413 int height = toolbar_visible ? toolbar->GetPreferredSize().height() : 0; |
| 406 toolbar->SetVisible(toolbar_visible); | 414 toolbar->SetVisible(toolbar_visible); |
| 407 toolbar->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); | 415 toolbar->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); |
| 408 | 416 |
| 409 return y + height; | 417 return y + height; |
| 410 } | 418 } |
| 411 | 419 |
| 412 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { | 420 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { |
| 413 web_contents_modal_dialog_top_y_ = | 421 web_contents_modal_dialog_top_y_ = |
| 414 top + browser_view_->y() - kConstrainedWindowOverlap; | 422 top + browser_view_->y() - kConstrainedWindowOverlap; |
| 415 find_bar_y_ = top + browser_view_->y() - 1; | |
| 416 if (bookmark_bar_) { | 423 if (bookmark_bar_) { |
| 417 // If we're showing the Bookmark bar in detached style, then we | 424 // If we're showing the Bookmark bar in detached style, then we |
| 418 // need to show any Info bar _above_ the Bookmark bar, since the | 425 // need to show any Info bar _above_ the Bookmark bar, since the |
| 419 // Bookmark bar is styled to look like it's part of the page. | 426 // Bookmark bar is styled to look like it's part of the page. |
| 420 if (bookmark_bar_->IsDetached()) | 427 if (bookmark_bar_->IsDetached()) |
| 421 return LayoutBookmarkBar(LayoutInfoBar(top)); | 428 return LayoutBookmarkBar(LayoutInfoBar(top)); |
| 422 // Otherwise, Bookmark bar first, Info bar second. | 429 // Otherwise, Bookmark bar first, Info bar second. |
| 423 top = std::max(browser_view_->toolbar_->bounds().bottom(), | 430 top = std::max(browser_view_->toolbar_->bounds().bottom(), |
| 424 LayoutBookmarkBar(top)); | 431 LayoutBookmarkBar(top)); |
| 425 } | 432 } |
| 426 find_bar_y_ = top + browser_view_->y() - 1; | |
| 427 return LayoutInfoBar(top); | 433 return LayoutInfoBar(top); |
| 428 } | 434 } |
| 429 | 435 |
| 430 int BrowserViewLayout::LayoutBookmarkBar(int top) { | 436 int BrowserViewLayout::LayoutBookmarkBar(int top) { |
| 431 int y = top; | 437 int y = top; |
| 432 if (!browser_view_->IsBookmarkBarVisible()) { | 438 if (!browser_view_->IsBookmarkBarVisible()) { |
| 433 bookmark_bar_->SetVisible(false); | 439 bookmark_bar_->SetVisible(false); |
| 434 // TODO(jamescook): Don't change the bookmark bar height when it is | 440 // TODO(jamescook): Don't change the bookmark bar height when it is |
| 435 // invisible, so we can use its height for layout even in that state. | 441 // invisible, so we can use its height for layout even in that state. |
| 436 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0); | 442 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 return bottom; | 575 return bottom; |
| 570 } | 576 } |
| 571 | 577 |
| 572 bool BrowserViewLayout::InfobarVisible() const { | 578 bool BrowserViewLayout::InfobarVisible() const { |
| 573 // Cast to a views::View to access GetPreferredSize(). | 579 // Cast to a views::View to access GetPreferredSize(). |
| 574 views::View* infobar_container = infobar_container_; | 580 views::View* infobar_container = infobar_container_; |
| 575 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 581 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
| 576 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 582 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
| 577 (infobar_container->GetPreferredSize().height() != 0); | 583 (infobar_container->GetPreferredSize().height() != 0); |
| 578 } | 584 } |
| OLD | NEW |