| 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.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_view_layout_delegate.h" | 17 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" |
| 18 #include "chrome/browser/ui/views/frame/contents_container.h" | 18 #include "chrome/browser/ui/views/frame/contents_layout_manager.h" |
| 19 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 19 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
| 20 #include "chrome/browser/ui/views/frame/top_container_view.h" | 20 #include "chrome/browser/ui/views/frame/top_container_view.h" |
| 21 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" | 21 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" |
| 22 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 22 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
| 23 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 23 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 24 #include "components/web_modal/web_contents_modal_dialog_host.h" | 24 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 25 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
| 26 #include "ui/gfx/point.h" | 26 #include "ui/gfx/point.h" |
| 27 #include "ui/gfx/scrollbar_size.h" | 27 #include "ui/gfx/scrollbar_size.h" |
| 28 #include "ui/gfx/size.h" | 28 #include "ui/gfx/size.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 gfx::NativeWindow native_window = | 83 gfx::NativeWindow native_window = |
| 84 browser_view_layout_->browser()->window()->GetNativeWindow(); | 84 browser_view_layout_->browser()->window()->GetNativeWindow(); |
| 85 return views::Widget::GetWidgetForNativeWindow(native_window)-> | 85 return views::Widget::GetWidgetForNativeWindow(native_window)-> |
| 86 GetNativeView(); | 86 GetNativeView(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Center horizontally over the content area, with the top overlapping the | 89 // Center horizontally over the content area, with the top overlapping the |
| 90 // browser chrome. | 90 // browser chrome. |
| 91 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { | 91 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { |
| 92 int top_y = browser_view_layout_->web_contents_modal_dialog_top_y_; | 92 int top_y = browser_view_layout_->web_contents_modal_dialog_top_y_; |
| 93 ContentsContainer* contents_container = | 93 views::View* contents_container = |
| 94 browser_view_layout_->contents_container_; | 94 browser_view_layout_->contents_container_; |
| 95 gfx::Rect contents_container_bounds_in_widget = | 95 gfx::Rect contents_container_bounds_in_widget = |
| 96 contents_container->ConvertRectToWidget( | 96 contents_container->ConvertRectToWidget( |
| 97 contents_container->GetLocalBounds()); | 97 contents_container->GetLocalBounds()); |
| 98 int middle_x = contents_container_bounds_in_widget.x() + | 98 int middle_x = contents_container_bounds_in_widget.x() + |
| 99 contents_container_bounds_in_widget.width() / 2; | 99 contents_container_bounds_in_widget.width() / 2; |
| 100 return gfx::Point(middle_x - size.width() / 2, top_y); | 100 return gfx::Point(middle_x - size.width() / 2, top_y); |
| 101 } | 101 } |
| 102 | 102 |
| 103 virtual gfx::Size GetMaximumDialogSize() OVERRIDE { | 103 virtual gfx::Size GetMaximumDialogSize() OVERRIDE { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // BrowserViewLayout, public: | 138 // BrowserViewLayout, public: |
| 139 | 139 |
| 140 BrowserViewLayout::BrowserViewLayout() | 140 BrowserViewLayout::BrowserViewLayout() |
| 141 : browser_(NULL), | 141 : browser_(NULL), |
| 142 browser_view_(NULL), | 142 browser_view_(NULL), |
| 143 top_container_(NULL), | 143 top_container_(NULL), |
| 144 tab_strip_(NULL), | 144 tab_strip_(NULL), |
| 145 toolbar_(NULL), | 145 toolbar_(NULL), |
| 146 bookmark_bar_(NULL), | 146 bookmark_bar_(NULL), |
| 147 infobar_container_(NULL), | 147 infobar_container_(NULL), |
| 148 contents_split_(NULL), | |
| 149 contents_container_(NULL), | 148 contents_container_(NULL), |
| 149 contents_layout_manager_(NULL), |
| 150 download_shelf_(NULL), | 150 download_shelf_(NULL), |
| 151 immersive_mode_controller_(NULL), | 151 immersive_mode_controller_(NULL), |
| 152 dialog_host_(new WebContentsModalDialogHostViews(this)), | 152 dialog_host_(new WebContentsModalDialogHostViews(this)), |
| 153 web_contents_modal_dialog_top_y_(-1) {} | 153 web_contents_modal_dialog_top_y_(-1) {} |
| 154 | 154 |
| 155 BrowserViewLayout::~BrowserViewLayout() { | 155 BrowserViewLayout::~BrowserViewLayout() { |
| 156 } | 156 } |
| 157 | 157 |
| 158 void BrowserViewLayout::Init( | 158 void BrowserViewLayout::Init( |
| 159 BrowserViewLayoutDelegate* delegate, | 159 BrowserViewLayoutDelegate* delegate, |
| 160 Browser* browser, | 160 Browser* browser, |
| 161 views::ClientView* browser_view, | 161 views::ClientView* browser_view, |
| 162 views::View* top_container, | 162 views::View* top_container, |
| 163 TabStrip* tab_strip, | 163 TabStrip* tab_strip, |
| 164 views::View* toolbar, | 164 views::View* toolbar, |
| 165 InfoBarContainerView* infobar_container, | 165 InfoBarContainerView* infobar_container, |
| 166 views::View* contents_split, | 166 views::View* contents_container, |
| 167 ContentsContainer* contents_container, | 167 ContentsLayoutManager* contents_layout_manager, |
| 168 ImmersiveModeController* immersive_mode_controller) { | 168 ImmersiveModeController* immersive_mode_controller) { |
| 169 delegate_.reset(delegate); | 169 delegate_.reset(delegate); |
| 170 browser_ = browser; | 170 browser_ = browser; |
| 171 browser_view_ = browser_view; | 171 browser_view_ = browser_view; |
| 172 top_container_ = top_container; | 172 top_container_ = top_container; |
| 173 tab_strip_ = tab_strip; | 173 tab_strip_ = tab_strip; |
| 174 toolbar_ = toolbar; | 174 toolbar_ = toolbar; |
| 175 infobar_container_ = infobar_container; | 175 infobar_container_ = infobar_container; |
| 176 contents_split_ = contents_split; | |
| 177 contents_container_ = contents_container; | 176 contents_container_ = contents_container; |
| 177 contents_layout_manager_ = contents_layout_manager; |
| 178 immersive_mode_controller_ = immersive_mode_controller; | 178 immersive_mode_controller_ = immersive_mode_controller; |
| 179 } | 179 } |
| 180 | 180 |
| 181 WebContentsModalDialogHost* | 181 WebContentsModalDialogHost* |
| 182 BrowserViewLayout::GetWebContentsModalDialogHost() { | 182 BrowserViewLayout::GetWebContentsModalDialogHost() { |
| 183 return dialog_host_.get(); | 183 return dialog_host_.get(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 gfx::Size BrowserViewLayout::GetMinimumSize() { | 186 gfx::Size BrowserViewLayout::GetMinimumSize() { |
| 187 gfx::Size tabstrip_size( | 187 gfx::Size tabstrip_size( |
| 188 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? | 188 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? |
| 189 tab_strip_->GetMinimumSize() : gfx::Size()); | 189 tab_strip_->GetMinimumSize() : gfx::Size()); |
| 190 gfx::Size toolbar_size( | 190 gfx::Size toolbar_size( |
| 191 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || | 191 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || |
| 192 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? | 192 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? |
| 193 toolbar_->GetMinimumSize() : gfx::Size()); | 193 toolbar_->GetMinimumSize() : gfx::Size()); |
| 194 if (tabstrip_size.height() && toolbar_size.height()) | 194 if (tabstrip_size.height() && toolbar_size.height()) |
| 195 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); | 195 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); |
| 196 gfx::Size bookmark_bar_size; | 196 gfx::Size bookmark_bar_size; |
| 197 if (bookmark_bar_ && | 197 if (bookmark_bar_ && |
| 198 bookmark_bar_->visible() && | 198 bookmark_bar_->visible() && |
| 199 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { | 199 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { |
| 200 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); | 200 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); |
| 201 bookmark_bar_size.Enlarge(0, -bookmark_bar_->GetToolbarOverlap()); | 201 bookmark_bar_size.Enlarge(0, -bookmark_bar_->GetToolbarOverlap()); |
| 202 } | 202 } |
| 203 // TODO: Adjust the minimum height for the find bar. | 203 // TODO: Adjust the minimum height for the find bar. |
| 204 | 204 |
| 205 gfx::Size contents_size(contents_split_->GetMinimumSize()); | 205 gfx::Size contents_size(contents_container_->GetMinimumSize()); |
| 206 | 206 |
| 207 int min_height = delegate_->GetTopInsetInBrowserView() + | 207 int min_height = delegate_->GetTopInsetInBrowserView() + |
| 208 tabstrip_size.height() + toolbar_size.height() + | 208 tabstrip_size.height() + toolbar_size.height() + |
| 209 bookmark_bar_size.height() + contents_size.height(); | 209 bookmark_bar_size.height() + contents_size.height(); |
| 210 int widths[] = { | 210 int widths[] = { |
| 211 tabstrip_size.width(), | 211 tabstrip_size.width(), |
| 212 toolbar_size.width(), | 212 toolbar_size.width(), |
| 213 bookmark_bar_size.width(), | 213 bookmark_bar_size.width(), |
| 214 contents_size.width() }; | 214 contents_size.width() }; |
| 215 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); | 215 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 top = LayoutBookmarkAndInfoBars(top, browser_view->y()); | 358 top = LayoutBookmarkAndInfoBars(top, browser_view->y()); |
| 359 | 359 |
| 360 // Top container requires updated toolbar and bookmark bar to compute bounds. | 360 // Top container requires updated toolbar and bookmark bar to compute bounds. |
| 361 UpdateTopContainerBounds(); | 361 UpdateTopContainerBounds(); |
| 362 | 362 |
| 363 int bottom = LayoutDownloadShelf(browser_view->height()); | 363 int bottom = LayoutDownloadShelf(browser_view->height()); |
| 364 // Treat a detached bookmark bar as if the web contents container is shifted | 364 // Treat a detached bookmark bar as if the web contents container is shifted |
| 365 // upwards and overlaps it. | 365 // upwards and overlaps it. |
| 366 int active_top_margin = GetContentsOffsetForBookmarkBar(); | 366 int active_top_margin = GetContentsOffsetForBookmarkBar(); |
| 367 contents_container_->SetActiveTopMargin(active_top_margin); | 367 contents_layout_manager_->SetActiveTopMargin(active_top_margin); |
| 368 top -= active_top_margin; | 368 top -= active_top_margin; |
| 369 LayoutContentsSplitView(top, bottom); | 369 LayoutContentsContainerView(top, bottom); |
| 370 | 370 |
| 371 // This must be done _after_ we lay out the WebContents since this | 371 // This must be done _after_ we lay out the WebContents since this |
| 372 // code calls back into us to find the bounding box the find bar | 372 // code calls back into us to find the bounding box the find bar |
| 373 // must be laid out within, and that code depends on the | 373 // must be laid out within, and that code depends on the |
| 374 // TabContentsContainer's bounds being up to date. | 374 // TabContentsContainer's bounds being up to date. |
| 375 if (browser()->HasFindBarController()) { | 375 if (browser()->HasFindBarController()) { |
| 376 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( | 376 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( |
| 377 gfx::Rect(), true); | 377 gfx::Rect(), true); |
| 378 } | 378 } |
| 379 | 379 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 infobar_container_->SetVisible(InfobarVisible()); | 513 infobar_container_->SetVisible(InfobarVisible()); |
| 514 int height; | 514 int height; |
| 515 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); | 515 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); |
| 516 infobar_container_->SetBounds(vertical_layout_rect_.x(), | 516 infobar_container_->SetBounds(vertical_layout_rect_.x(), |
| 517 overlapped_top, | 517 overlapped_top, |
| 518 vertical_layout_rect_.width(), | 518 vertical_layout_rect_.width(), |
| 519 height); | 519 height); |
| 520 return overlapped_top + height; | 520 return overlapped_top + height; |
| 521 } | 521 } |
| 522 | 522 |
| 523 void BrowserViewLayout::LayoutContentsSplitView(int top, int bottom) { | 523 void BrowserViewLayout::LayoutContentsContainerView(int top, int bottom) { |
| 524 // |contents_split_| contains web page contents and devtools. | 524 // |contents_container_| contains web page contents and devtools. |
| 525 // See browser_view.h for details. | 525 // See browser_view.h for details. |
| 526 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(), | 526 gfx::Rect contents_container_bounds(vertical_layout_rect_.x(), |
| 527 top, | 527 top, |
| 528 vertical_layout_rect_.width(), | 528 vertical_layout_rect_.width(), |
| 529 std::max(0, bottom - top)); | 529 std::max(0, bottom - top)); |
| 530 contents_split_->SetBoundsRect(contents_split_bounds); | 530 contents_container_->SetBoundsRect(contents_container_bounds); |
| 531 } | 531 } |
| 532 | 532 |
| 533 void BrowserViewLayout::UpdateTopContainerBounds() { | 533 void BrowserViewLayout::UpdateTopContainerBounds() { |
| 534 gfx::Rect top_container_bounds(top_container_->GetPreferredSize()); | 534 gfx::Rect top_container_bounds(top_container_->GetPreferredSize()); |
| 535 | 535 |
| 536 // If the immersive mode controller is animating the top container, it may be | 536 // If the immersive mode controller is animating the top container, it may be |
| 537 // partly offscreen. The top container is positioned relative to the top of | 537 // partly offscreen. The top container is positioned relative to the top of |
| 538 // the client view instead of relative to GetTopInsetInBrowserView() because | 538 // the client view instead of relative to GetTopInsetInBrowserView() because |
| 539 // the top container paints parts of the frame (title, window controls) during | 539 // the top container paints parts of the frame (title, window controls) during |
| 540 // an immersive reveal. | 540 // an immersive reveal. |
| 541 top_container_bounds.set_y( | 541 top_container_bounds.set_y( |
| 542 immersive_mode_controller_->GetTopContainerVerticalOffset( | 542 immersive_mode_controller_->GetTopContainerVerticalOffset( |
| 543 top_container_bounds.size())); | 543 top_container_bounds.size())); |
| 544 top_container_->SetBoundsRect(top_container_bounds); | 544 top_container_->SetBoundsRect(top_container_bounds); |
| 545 } | 545 } |
| 546 | 546 |
| 547 int BrowserViewLayout::GetContentsOffsetForBookmarkBar() { | 547 int BrowserViewLayout::GetContentsOffsetForBookmarkBar() { |
| 548 // If the bookmark bar is hidden or attached to the omnibox the web contents | 548 // If the bookmark bar is hidden or attached to the omnibox the web contents |
| 549 // will appear directly underneath it and does not need an offset. | 549 // will appear directly underneath it and does not need an offset. |
| 550 if (!bookmark_bar_ || | 550 if (!bookmark_bar_ || |
| 551 !delegate_->IsBookmarkBarVisible() || | 551 !delegate_->IsBookmarkBarVisible() || |
| 552 !bookmark_bar_->IsDetached()) { | 552 !bookmark_bar_->IsDetached()) { |
| 553 return 0; | 553 return 0; |
| 554 } | 554 } |
| 555 | 555 |
| 556 // Dev tools. | |
| 557 if (contents_split_->child_at(1) && contents_split_->child_at(1)->visible()) | |
| 558 return 0; | |
| 559 | |
| 560 // Offset for the detached bookmark bar. | 556 // Offset for the detached bookmark bar. |
| 561 return bookmark_bar_->height() - | 557 return bookmark_bar_->height() - |
| 562 bookmark_bar_->GetFullyDetachedToolbarOverlap(); | 558 bookmark_bar_->GetFullyDetachedToolbarOverlap(); |
| 563 } | 559 } |
| 564 | 560 |
| 565 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { | 561 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { |
| 566 if (delegate_->DownloadShelfNeedsLayout()) { | 562 if (delegate_->DownloadShelfNeedsLayout()) { |
| 567 bool visible = browser()->SupportsWindowFeature( | 563 bool visible = browser()->SupportsWindowFeature( |
| 568 Browser::FEATURE_DOWNLOADSHELF); | 564 Browser::FEATURE_DOWNLOADSHELF); |
| 569 DCHECK(download_shelf_); | 565 DCHECK(download_shelf_); |
| 570 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; | 566 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; |
| 571 download_shelf_->SetVisible(visible); | 567 download_shelf_->SetVisible(visible); |
| 572 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, | 568 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, |
| 573 vertical_layout_rect_.width(), height); | 569 vertical_layout_rect_.width(), height); |
| 574 download_shelf_->Layout(); | 570 download_shelf_->Layout(); |
| 575 bottom -= height; | 571 bottom -= height; |
| 576 } | 572 } |
| 577 return bottom; | 573 return bottom; |
| 578 } | 574 } |
| 579 | 575 |
| 580 bool BrowserViewLayout::InfobarVisible() const { | 576 bool BrowserViewLayout::InfobarVisible() const { |
| 581 // Cast to a views::View to access GetPreferredSize(). | 577 // Cast to a views::View to access GetPreferredSize(). |
| 582 views::View* infobar_container = infobar_container_; | 578 views::View* infobar_container = infobar_container_; |
| 583 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 579 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
| 584 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 580 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
| 585 (infobar_container->GetPreferredSize().height() != 0); | 581 (infobar_container->GetPreferredSize().height() != 0); |
| 586 } | 582 } |
| OLD | NEW |