| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 void NotifyPositionRequiresUpdate() { | 75 void NotifyPositionRequiresUpdate() { |
| 76 FOR_EACH_OBSERVER(ModalDialogHostObserver, | 76 FOR_EACH_OBSERVER(ModalDialogHostObserver, |
| 77 observer_list_, | 77 observer_list_, |
| 78 OnPositionRequiresUpdate()); | 78 OnPositionRequiresUpdate()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Center horizontally over the content area, with the top overlapping the | 81 // Center horizontally over the content area, with the top overlapping the |
| 82 // browser chrome. | 82 // browser chrome. |
| 83 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { | 83 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { |
| 84 int top_y = browser_view_layout_->web_contents_modal_dialog_top_y_; | 84 int top_y = browser_view_layout_->web_contents_modal_dialog_top_y_; |
| 85 ContentsContainer* contents_container = | 85 views::View* contents_container = |
| 86 browser_view_layout_->contents_container_; | 86 browser_view_layout_->contents_container_; |
| 87 gfx::Rect contents_container_bounds_in_widget = | 87 gfx::Rect contents_container_bounds_in_widget = |
| 88 contents_container->ConvertRectToWidget( | 88 contents_container->ConvertRectToWidget( |
| 89 contents_container->GetLocalBounds()); | 89 contents_container->GetLocalBounds()); |
| 90 int middle_x = contents_container_bounds_in_widget.x() + | 90 int middle_x = contents_container_bounds_in_widget.x() + |
| 91 contents_container_bounds_in_widget.width() / 2; | 91 contents_container_bounds_in_widget.width() / 2; |
| 92 return gfx::Point(middle_x - size.width() / 2, top_y); | 92 return gfx::Point(middle_x - size.width() / 2, top_y); |
| 93 } | 93 } |
| 94 | 94 |
| 95 private: | 95 private: |
| (...skipping 42 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 gfx::Size infobar_container_size(infobar_container_->GetMinimumSize()); | 203 gfx::Size infobar_container_size(infobar_container_->GetMinimumSize()); |
| 204 // TODO: Adjust the minimum height for the find bar. | 204 // TODO: Adjust the minimum height for the find bar. |
| 205 | 205 |
| 206 gfx::Size contents_size(contents_split_->GetMinimumSize()); | 206 gfx::Size contents_size(contents_container_->GetMinimumSize()); |
| 207 | 207 |
| 208 int min_height = delegate_->GetTopInsetInBrowserView() + | 208 int min_height = delegate_->GetTopInsetInBrowserView() + |
| 209 tabstrip_size.height() + toolbar_size.height() + | 209 tabstrip_size.height() + toolbar_size.height() + |
| 210 bookmark_bar_size.height() + infobar_container_size.height() + | 210 bookmark_bar_size.height() + infobar_container_size.height() + |
| 211 contents_size.height(); | 211 contents_size.height(); |
| 212 int widths[] = { | 212 int widths[] = { |
| 213 tabstrip_size.width(), | 213 tabstrip_size.width(), |
| 214 toolbar_size.width(), | 214 toolbar_size.width(), |
| 215 bookmark_bar_size.width(), | 215 bookmark_bar_size.width(), |
| 216 infobar_container_size.width(), | 216 infobar_container_size.width(), |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 top = LayoutBookmarkAndInfoBars(top, browser_view->y()); | 361 top = LayoutBookmarkAndInfoBars(top, browser_view->y()); |
| 362 | 362 |
| 363 // Top container requires updated toolbar and bookmark bar to compute bounds. | 363 // Top container requires updated toolbar and bookmark bar to compute bounds. |
| 364 UpdateTopContainerBounds(); | 364 UpdateTopContainerBounds(); |
| 365 | 365 |
| 366 int bottom = LayoutDownloadShelf(browser_view->height()); | 366 int bottom = LayoutDownloadShelf(browser_view->height()); |
| 367 // Treat a detached bookmark bar as if the web contents container is shifted | 367 // Treat a detached bookmark bar as if the web contents container is shifted |
| 368 // upwards and overlaps it. | 368 // upwards and overlaps it. |
| 369 int active_top_margin = GetContentsOffsetForBookmarkBar(); | 369 int active_top_margin = GetContentsOffsetForBookmarkBar(); |
| 370 contents_container_->SetActiveTopMargin(active_top_margin); | 370 contents_layout_manager_->SetActiveTopMargin(active_top_margin); |
| 371 top -= active_top_margin; | 371 top -= active_top_margin; |
| 372 LayoutContentsSplitView(top, bottom); | 372 LayoutContentsContainerView(top, bottom); |
| 373 | 373 |
| 374 // This must be done _after_ we lay out the WebContents since this | 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 | 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 | 376 // must be laid out within, and that code depends on the |
| 377 // TabContentsContainer's bounds being up to date. | 377 // TabContentsContainer's bounds being up to date. |
| 378 if (browser()->HasFindBarController()) { | 378 if (browser()->HasFindBarController()) { |
| 379 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( | 379 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( |
| 380 gfx::Rect(), true); | 380 gfx::Rect(), true); |
| 381 } | 381 } |
| 382 | 382 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 infobar_container_->SetVisible(InfobarVisible()); | 519 infobar_container_->SetVisible(InfobarVisible()); |
| 520 int height; | 520 int height; |
| 521 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); | 521 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); |
| 522 infobar_container_->SetBounds(vertical_layout_rect_.x(), | 522 infobar_container_->SetBounds(vertical_layout_rect_.x(), |
| 523 overlapped_top, | 523 overlapped_top, |
| 524 vertical_layout_rect_.width(), | 524 vertical_layout_rect_.width(), |
| 525 height); | 525 height); |
| 526 return overlapped_top + height; | 526 return overlapped_top + height; |
| 527 } | 527 } |
| 528 | 528 |
| 529 void BrowserViewLayout::LayoutContentsSplitView(int top, int bottom) { | 529 void BrowserViewLayout::LayoutContentsContainerView(int top, int bottom) { |
| 530 // |contents_split_| contains web page contents and devtools. | 530 // |contents_container_| contains web page contents and devtools. |
| 531 // See browser_view.h for details. | 531 // See browser_view.h for details. |
| 532 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(), | 532 gfx::Rect contents_container_bounds(vertical_layout_rect_.x(), |
| 533 top, | 533 top, |
| 534 vertical_layout_rect_.width(), | 534 vertical_layout_rect_.width(), |
| 535 std::max(0, bottom - top)); | 535 std::max(0, bottom - top)); |
| 536 contents_split_->SetBoundsRect(contents_split_bounds); | 536 contents_container_->SetBoundsRect(contents_container_bounds); |
| 537 } | 537 } |
| 538 | 538 |
| 539 void BrowserViewLayout::UpdateTopContainerBounds() { | 539 void BrowserViewLayout::UpdateTopContainerBounds() { |
| 540 gfx::Rect top_container_bounds(top_container_->GetPreferredSize()); | 540 gfx::Rect top_container_bounds(top_container_->GetPreferredSize()); |
| 541 | 541 |
| 542 // If the immersive mode controller is animating the top container, it may be | 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 | 543 // partly offscreen. The top container is positioned relative to the top of |
| 544 // the client view instead of relative to GetTopInsetInBrowserView() because | 544 // the client view instead of relative to GetTopInsetInBrowserView() because |
| 545 // the top container paints parts of the frame (title, window controls) during | 545 // the top container paints parts of the frame (title, window controls) during |
| 546 // an immersive reveal. | 546 // an immersive reveal. |
| 547 top_container_bounds.set_y( | 547 top_container_bounds.set_y( |
| 548 immersive_mode_controller_->GetTopContainerVerticalOffset( | 548 immersive_mode_controller_->GetTopContainerVerticalOffset( |
| 549 top_container_bounds.size())); | 549 top_container_bounds.size())); |
| 550 top_container_->SetBoundsRect(top_container_bounds); | 550 top_container_->SetBoundsRect(top_container_bounds); |
| 551 } | 551 } |
| 552 | 552 |
| 553 int BrowserViewLayout::GetContentsOffsetForBookmarkBar() { | 553 int BrowserViewLayout::GetContentsOffsetForBookmarkBar() { |
| 554 // If the bookmark bar is hidden or attached to the omnibox the web contents | 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. | 555 // will appear directly underneath it and does not need an offset. |
| 556 if (!bookmark_bar_ || | 556 if (!bookmark_bar_ || |
| 557 !delegate_->IsBookmarkBarVisible() || | 557 !delegate_->IsBookmarkBarVisible() || |
| 558 !bookmark_bar_->IsDetached()) { | 558 !bookmark_bar_->IsDetached()) { |
| 559 return 0; | 559 return 0; |
| 560 } | 560 } |
| 561 | 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. | 562 // Offset for the detached bookmark bar. |
| 567 return bookmark_bar_->height() - | 563 return bookmark_bar_->height() - |
| 568 bookmark_bar_->GetFullyDetachedToolbarOverlap(); | 564 bookmark_bar_->GetFullyDetachedToolbarOverlap(); |
| 569 } | 565 } |
| 570 | 566 |
| 571 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { | 567 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { |
| 572 if (delegate_->DownloadShelfNeedsLayout()) { | 568 if (delegate_->DownloadShelfNeedsLayout()) { |
| 573 bool visible = browser()->SupportsWindowFeature( | 569 bool visible = browser()->SupportsWindowFeature( |
| 574 Browser::FEATURE_DOWNLOADSHELF); | 570 Browser::FEATURE_DOWNLOADSHELF); |
| 575 DCHECK(download_shelf_); | 571 DCHECK(download_shelf_); |
| 576 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; | 572 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; |
| 577 download_shelf_->SetVisible(visible); | 573 download_shelf_->SetVisible(visible); |
| 578 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, | 574 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, |
| 579 vertical_layout_rect_.width(), height); | 575 vertical_layout_rect_.width(), height); |
| 580 download_shelf_->Layout(); | 576 download_shelf_->Layout(); |
| 581 bottom -= height; | 577 bottom -= height; |
| 582 } | 578 } |
| 583 return bottom; | 579 return bottom; |
| 584 } | 580 } |
| 585 | 581 |
| 586 bool BrowserViewLayout::InfobarVisible() const { | 582 bool BrowserViewLayout::InfobarVisible() const { |
| 587 // Cast to a views::View to access GetPreferredSize(). | 583 // Cast to a views::View to access GetPreferredSize(). |
| 588 views::View* infobar_container = infobar_container_; | 584 views::View* infobar_container = infobar_container_; |
| 589 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 585 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
| 590 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 586 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
| 591 (infobar_container->GetPreferredSize().height() != 0); | 587 (infobar_container->GetPreferredSize().height() != 0); |
| 592 } | 588 } |
| OLD | NEW |