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" |
(...skipping 127 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), |
150 download_shelf_(NULL), | 149 download_shelf_(NULL), |
151 immersive_mode_controller_(NULL), | 150 immersive_mode_controller_(NULL), |
152 dialog_host_(new WebContentsModalDialogHostViews(this)), | 151 dialog_host_(new WebContentsModalDialogHostViews(this)), |
153 web_contents_modal_dialog_top_y_(-1) {} | 152 web_contents_modal_dialog_top_y_(-1) {} |
154 | 153 |
155 BrowserViewLayout::~BrowserViewLayout() { | 154 BrowserViewLayout::~BrowserViewLayout() { |
156 } | 155 } |
157 | 156 |
158 void BrowserViewLayout::Init( | 157 void BrowserViewLayout::Init( |
159 BrowserViewLayoutDelegate* delegate, | 158 BrowserViewLayoutDelegate* delegate, |
160 Browser* browser, | 159 Browser* browser, |
161 views::ClientView* browser_view, | 160 views::ClientView* browser_view, |
162 views::View* top_container, | 161 views::View* top_container, |
163 TabStrip* tab_strip, | 162 TabStrip* tab_strip, |
164 views::View* toolbar, | 163 views::View* toolbar, |
165 InfoBarContainerView* infobar_container, | 164 InfoBarContainerView* infobar_container, |
166 views::View* contents_split, | |
167 ContentsContainer* contents_container, | 165 ContentsContainer* contents_container, |
168 ImmersiveModeController* immersive_mode_controller) { | 166 ImmersiveModeController* immersive_mode_controller) { |
169 delegate_.reset(delegate); | 167 delegate_.reset(delegate); |
170 browser_ = browser; | 168 browser_ = browser; |
171 browser_view_ = browser_view; | 169 browser_view_ = browser_view; |
172 top_container_ = top_container; | 170 top_container_ = top_container; |
173 tab_strip_ = tab_strip; | 171 tab_strip_ = tab_strip; |
174 toolbar_ = toolbar; | 172 toolbar_ = toolbar; |
175 infobar_container_ = infobar_container; | 173 infobar_container_ = infobar_container; |
176 contents_split_ = contents_split; | |
177 contents_container_ = contents_container; | 174 contents_container_ = contents_container; |
178 immersive_mode_controller_ = immersive_mode_controller; | 175 immersive_mode_controller_ = immersive_mode_controller; |
179 } | 176 } |
180 | 177 |
181 WebContentsModalDialogHost* | 178 WebContentsModalDialogHost* |
182 BrowserViewLayout::GetWebContentsModalDialogHost() { | 179 BrowserViewLayout::GetWebContentsModalDialogHost() { |
183 return dialog_host_.get(); | 180 return dialog_host_.get(); |
184 } | 181 } |
185 | 182 |
186 gfx::Size BrowserViewLayout::GetMinimumSize() { | 183 gfx::Size BrowserViewLayout::GetMinimumSize() { |
187 gfx::Size tabstrip_size( | 184 gfx::Size tabstrip_size( |
188 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? | 185 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? |
189 tab_strip_->GetMinimumSize() : gfx::Size()); | 186 tab_strip_->GetMinimumSize() : gfx::Size()); |
190 gfx::Size toolbar_size( | 187 gfx::Size toolbar_size( |
191 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || | 188 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || |
192 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? | 189 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? |
193 toolbar_->GetMinimumSize() : gfx::Size()); | 190 toolbar_->GetMinimumSize() : gfx::Size()); |
194 if (tabstrip_size.height() && toolbar_size.height()) | 191 if (tabstrip_size.height() && toolbar_size.height()) |
195 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); | 192 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); |
196 gfx::Size bookmark_bar_size; | 193 gfx::Size bookmark_bar_size; |
197 if (bookmark_bar_ && | 194 if (bookmark_bar_ && |
198 bookmark_bar_->visible() && | 195 bookmark_bar_->visible() && |
199 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { | 196 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { |
200 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); | 197 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); |
201 bookmark_bar_size.Enlarge(0, -bookmark_bar_->GetToolbarOverlap()); | 198 bookmark_bar_size.Enlarge(0, -bookmark_bar_->GetToolbarOverlap()); |
202 } | 199 } |
203 // TODO: Adjust the minimum height for the find bar. | 200 // TODO: Adjust the minimum height for the find bar. |
204 | 201 |
205 gfx::Size contents_size(contents_split_->GetMinimumSize()); | 202 gfx::Size contents_size(contents_container_->GetMinimumSize()); |
206 | 203 |
207 int min_height = delegate_->GetTopInsetInBrowserView() + | 204 int min_height = delegate_->GetTopInsetInBrowserView() + |
208 tabstrip_size.height() + toolbar_size.height() + | 205 tabstrip_size.height() + toolbar_size.height() + |
209 bookmark_bar_size.height() + contents_size.height(); | 206 bookmark_bar_size.height() + contents_size.height(); |
210 int widths[] = { | 207 int widths[] = { |
211 tabstrip_size.width(), | 208 tabstrip_size.width(), |
212 toolbar_size.width(), | 209 toolbar_size.width(), |
213 bookmark_bar_size.width(), | 210 bookmark_bar_size.width(), |
214 contents_size.width() }; | 211 contents_size.width() }; |
215 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); | 212 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 356 |
360 // Top container requires updated toolbar and bookmark bar to compute bounds. | 357 // Top container requires updated toolbar and bookmark bar to compute bounds. |
361 UpdateTopContainerBounds(); | 358 UpdateTopContainerBounds(); |
362 | 359 |
363 int bottom = LayoutDownloadShelf(browser_view->height()); | 360 int bottom = LayoutDownloadShelf(browser_view->height()); |
364 // Treat a detached bookmark bar as if the web contents container is shifted | 361 // Treat a detached bookmark bar as if the web contents container is shifted |
365 // upwards and overlaps it. | 362 // upwards and overlaps it. |
366 int active_top_margin = GetContentsOffsetForBookmarkBar(); | 363 int active_top_margin = GetContentsOffsetForBookmarkBar(); |
367 contents_container_->SetActiveTopMargin(active_top_margin); | 364 contents_container_->SetActiveTopMargin(active_top_margin); |
368 top -= active_top_margin; | 365 top -= active_top_margin; |
369 LayoutContentsSplitView(top, bottom); | 366 LayoutContentsContainerView(top, bottom); |
370 | 367 |
371 // This must be done _after_ we lay out the WebContents since this | 368 // 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 | 369 // 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 | 370 // must be laid out within, and that code depends on the |
374 // TabContentsContainer's bounds being up to date. | 371 // TabContentsContainer's bounds being up to date. |
375 if (browser()->HasFindBarController()) { | 372 if (browser()->HasFindBarController()) { |
376 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( | 373 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( |
377 gfx::Rect(), true); | 374 gfx::Rect(), true); |
378 } | 375 } |
379 | 376 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 infobar_container_->SetVisible(InfobarVisible()); | 510 infobar_container_->SetVisible(InfobarVisible()); |
514 int height; | 511 int height; |
515 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); | 512 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); |
516 infobar_container_->SetBounds(vertical_layout_rect_.x(), | 513 infobar_container_->SetBounds(vertical_layout_rect_.x(), |
517 overlapped_top, | 514 overlapped_top, |
518 vertical_layout_rect_.width(), | 515 vertical_layout_rect_.width(), |
519 height); | 516 height); |
520 return overlapped_top + height; | 517 return overlapped_top + height; |
521 } | 518 } |
522 | 519 |
523 void BrowserViewLayout::LayoutContentsSplitView(int top, int bottom) { | 520 void BrowserViewLayout::LayoutContentsContainerView(int top, int bottom) { |
524 // |contents_split_| contains web page contents and devtools. | 521 // |contents_container_| contains web page contents and devtools. |
525 // See browser_view.h for details. | 522 // See browser_view.h for details. |
526 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(), | 523 gfx::Rect contents_container_bounds(vertical_layout_rect_.x(), |
527 top, | 524 top, |
528 vertical_layout_rect_.width(), | 525 vertical_layout_rect_.width(), |
529 std::max(0, bottom - top)); | 526 std::max(0, bottom - top)); |
530 contents_split_->SetBoundsRect(contents_split_bounds); | 527 contents_container_->SetBoundsRect(contents_container_bounds); |
531 } | 528 } |
532 | 529 |
533 void BrowserViewLayout::UpdateTopContainerBounds() { | 530 void BrowserViewLayout::UpdateTopContainerBounds() { |
534 gfx::Rect top_container_bounds(top_container_->GetPreferredSize()); | 531 gfx::Rect top_container_bounds(top_container_->GetPreferredSize()); |
535 | 532 |
536 // If the immersive mode controller is animating the top container, it may be | 533 // 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 | 534 // partly offscreen. The top container is positioned relative to the top of |
538 // the client view instead of relative to GetTopInsetInBrowserView() because | 535 // the client view instead of relative to GetTopInsetInBrowserView() because |
539 // the top container paints parts of the frame (title, window controls) during | 536 // the top container paints parts of the frame (title, window controls) during |
540 // an immersive reveal. | 537 // an immersive reveal. |
541 top_container_bounds.set_y( | 538 top_container_bounds.set_y( |
542 immersive_mode_controller_->GetTopContainerVerticalOffset( | 539 immersive_mode_controller_->GetTopContainerVerticalOffset( |
543 top_container_bounds.size())); | 540 top_container_bounds.size())); |
544 top_container_->SetBoundsRect(top_container_bounds); | 541 top_container_->SetBoundsRect(top_container_bounds); |
545 } | 542 } |
546 | 543 |
547 int BrowserViewLayout::GetContentsOffsetForBookmarkBar() { | 544 int BrowserViewLayout::GetContentsOffsetForBookmarkBar() { |
548 // If the bookmark bar is hidden or attached to the omnibox the web contents | 545 // 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. | 546 // will appear directly underneath it and does not need an offset. |
550 if (!bookmark_bar_ || | 547 if (!bookmark_bar_ || |
551 !delegate_->IsBookmarkBarVisible() || | 548 !delegate_->IsBookmarkBarVisible() || |
552 !bookmark_bar_->IsDetached()) { | 549 !bookmark_bar_->IsDetached()) { |
553 return 0; | 550 return 0; |
554 } | 551 } |
555 | 552 |
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. | 553 // Offset for the detached bookmark bar. |
561 return bookmark_bar_->height() - | 554 return bookmark_bar_->height() - |
562 bookmark_bar_->GetFullyDetachedToolbarOverlap(); | 555 bookmark_bar_->GetFullyDetachedToolbarOverlap(); |
563 } | 556 } |
564 | 557 |
565 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { | 558 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { |
566 if (delegate_->DownloadShelfNeedsLayout()) { | 559 if (delegate_->DownloadShelfNeedsLayout()) { |
567 bool visible = browser()->SupportsWindowFeature( | 560 bool visible = browser()->SupportsWindowFeature( |
568 Browser::FEATURE_DOWNLOADSHELF); | 561 Browser::FEATURE_DOWNLOADSHELF); |
569 DCHECK(download_shelf_); | 562 DCHECK(download_shelf_); |
570 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; | 563 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; |
571 download_shelf_->SetVisible(visible); | 564 download_shelf_->SetVisible(visible); |
572 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, | 565 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, |
573 vertical_layout_rect_.width(), height); | 566 vertical_layout_rect_.width(), height); |
574 download_shelf_->Layout(); | 567 download_shelf_->Layout(); |
575 bottom -= height; | 568 bottom -= height; |
576 } | 569 } |
577 return bottom; | 570 return bottom; |
578 } | 571 } |
579 | 572 |
580 bool BrowserViewLayout::InfobarVisible() const { | 573 bool BrowserViewLayout::InfobarVisible() const { |
581 // Cast to a views::View to access GetPreferredSize(). | 574 // Cast to a views::View to access GetPreferredSize(). |
582 views::View* infobar_container = infobar_container_; | 575 views::View* infobar_container = infobar_container_; |
583 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 576 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
584 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 577 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
585 (infobar_container->GetPreferredSize().height() != 0); | 578 (infobar_container->GetPreferredSize().height() != 0); |
586 } | 579 } |
OLD | NEW |