Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: chrome/browser/ui/views/frame/browser_view_layout.cc

Issue 5606012: Streamline the layout of the BrowserView's children TabContents views.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/frame/browser_view_layout.h" 5 #include "chrome/browser/views/frame/browser_view_layout.h"
6 6
7 #include "chrome/browser/sidebar/sidebar_manager.h" 7 #include "chrome/browser/sidebar/sidebar_manager.h"
8 #include "chrome/browser/ui/find_bar/find_bar.h" 8 #include "chrome/browser/ui/find_bar/find_bar.h"
9 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 9 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
10 #include "chrome/browser/ui/view_ids.h" 10 #include "chrome/browser/ui/view_ids.h"
11 #include "chrome/browser/ui/views/bookmark_bar_view.h" 11 #include "chrome/browser/ui/views/bookmark_bar_view.h"
12 #include "chrome/browser/ui/views/download_shelf_view.h" 12 #include "chrome/browser/ui/views/download_shelf_view.h"
13 #include "chrome/browser/ui/views/frame/browser_frame.h" 13 #include "chrome/browser/ui/views/frame/browser_frame.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/frame/contents_container.h" 15 #include "chrome/browser/ui/views/frame/contents_container.h"
16 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h"
16 #include "chrome/browser/ui/views/tabs/side_tab_strip.h" 17 #include "chrome/browser/ui/views/tabs/side_tab_strip.h"
17 #include "chrome/browser/ui/views/tabs/tab_strip.h" 18 #include "chrome/browser/ui/views/tabs/tab_strip.h"
18 #include "chrome/browser/ui/views/toolbar_view.h" 19 #include "chrome/browser/ui/views/toolbar_view.h"
19 #include "gfx/scrollbar_size.h" 20 #include "gfx/scrollbar_size.h"
21 #include "views/controls/single_split_view.h"
20 #include "views/window/window.h" 22 #include "views/window/window.h"
21 23
22 #if defined(OS_LINUX) 24 #if defined(OS_LINUX)
23 #include "views/window/hit_test.h" 25 #include "views/window/hit_test.h"
24 #endif 26 #endif
25 27
26 namespace { 28 namespace {
27 29
28 // The visible height of the shadow above the tabs. Clicks in this area are 30 // The visible height of the shadow above the tabs. Clicks in this area are
29 // treated as clicks to the frame, rather than clicks to the tab. 31 // treated as clicks to the frame, rather than clicks to the tab.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 active_bookmark_bar_ = NULL; 202 active_bookmark_bar_ = NULL;
201 tabstrip_ = NULL; 203 tabstrip_ = NULL;
202 browser_view_ = static_cast<BrowserView*>(host); 204 browser_view_ = static_cast<BrowserView*>(host);
203 } 205 }
204 206
205 void BrowserViewLayout::Uninstalled(views::View* host) {} 207 void BrowserViewLayout::Uninstalled(views::View* host) {}
206 208
207 void BrowserViewLayout::ViewAdded(views::View* host, views::View* view) { 209 void BrowserViewLayout::ViewAdded(views::View* host, views::View* view) {
208 switch (view->GetID()) { 210 switch (view->GetID()) {
209 case VIEW_ID_CONTENTS_SPLIT: { 211 case VIEW_ID_CONTENTS_SPLIT: {
210 contents_split_ = view; 212 contents_split_ = static_cast<views::SingleSplitView*>(view);
211 // We're installed as the LayoutManager before BrowserView creates the 213 // We're installed as the LayoutManager before BrowserView creates the
212 // contents, so we have to set contents_container_ here rather than 214 // contents, so we have to set contents_container_ here rather than in
213 // Installed. 215 // Installed.
214 contents_container_ = browser_view_->contents_; 216 contents_container_ = browser_view_->contents_;
215 break; 217 break;
216 } 218 }
217 case VIEW_ID_INFO_BAR_CONTAINER: 219 case VIEW_ID_INFO_BAR_CONTAINER:
218 infobar_container_ = view; 220 infobar_container_ = view;
219 break; 221 break;
220 case VIEW_ID_DOWNLOAD_SHELF: 222 case VIEW_ID_DOWNLOAD_SHELF:
221 download_shelf_ = static_cast<DownloadShelfView*>(view); 223 download_shelf_ = static_cast<DownloadShelfView*>(view);
222 break; 224 break;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 358
357 int BrowserViewLayout::LayoutInfoBar(int top) { 359 int BrowserViewLayout::LayoutInfoBar(int top) {
358 bool visible = InfobarVisible(); 360 bool visible = InfobarVisible();
359 int height = visible ? infobar_container_->GetPreferredSize().height() : 0; 361 int height = visible ? infobar_container_->GetPreferredSize().height() : 0;
360 infobar_container_->SetVisible(visible); 362 infobar_container_->SetVisible(visible);
361 infobar_container_->SetBounds(vertical_layout_rect_.x(), top, 363 infobar_container_->SetBounds(vertical_layout_rect_.x(), top,
362 vertical_layout_rect_.width(), height); 364 vertical_layout_rect_.width(), height);
363 return top + height; 365 return top + height;
364 } 366 }
365 367
368 // |browser_reserved_rect| is in browser_view_ coordinates.
369 // |future_source_bounds| is in source->GetParent() coordinates.
370 void BrowserViewLayout::UpdateReservedContentsRect(
371 const gfx::Rect& browser_reserved_rect, TabContentsContainer* source,
372 const gfx::Rect& future_source_bounds) {
373 gfx::Point resize_corner_origin(browser_reserved_rect.origin());
374 // Convert |resize_corner_origin| from browser_view_ to source->GetParent()
375 // coordinates.
376 views::View::ConvertPointToView(browser_view_, source->GetParent(),
377 &resize_corner_origin);
378 // Create |reserved_rect| in source->GetParent() coordinates.
379 gfx::Rect reserved_rect(resize_corner_origin, browser_reserved_rect.size());
380 if (future_source_bounds.Intersects(reserved_rect)) {
381 // |source| is not properly positioned yet to use ConvertPointToView,
382 // so convert it into |source|'s coordinates manually.
383 reserved_rect.Offset(-future_source_bounds.x(), -future_source_bounds.y());
384 } else {
385 reserved_rect = gfx::Rect();
386 }
387
388 source->SetReservedContentsRect(reserved_rect);
389 }
390
366 void BrowserViewLayout::LayoutTabContents(int top, int bottom) { 391 void BrowserViewLayout::LayoutTabContents(int top, int bottom) {
392 // The ultimate idea is to calcualte bounds and reserved areas for all
393 // contents views first and then resize them all, so every view
394 // (and its contents) is resized and laid out only once.
395
396 // The views hierarcy (see browser_view.h for more details):
397 // 1) Sidebar is not allowed:
398 // contents_split_ -> [contents_container_ | devtools]
399 // 2) Sidebar is allowed:
400 // contents_split_ ->
401 // [sidebar_split -> [contents_container_ | sidebar]] | devtools
402
403 gfx::Rect sidebar_split_bounds;
404 gfx::Rect contents_bounds;
405 gfx::Rect sidebar_bounds;
406 gfx::Rect devtools_bounds;
407
408 // contents_split_ is a SingleSplitView, it won't resize children views yet.
367 contents_split_->SetBounds(vertical_layout_rect_.x(), top, 409 contents_split_->SetBounds(vertical_layout_rect_.x(), top,
368 vertical_layout_rect_.width(), bottom - top); 410 vertical_layout_rect_.width(), bottom - top);
411 contents_split_->CalculateChildrenBounds(&sidebar_split_bounds,
412 &devtools_bounds);
413
414 // As a SingleSplitView, sidebar_split should be resized upfront too.
415 views::SingleSplitView* sidebar_split = browser_view_->sidebar_split_;
416 if (sidebar_split) {
417 DCHECK(sidebar_split == contents_split_->GetChildViewAt(0));
418 sidebar_split->SetBounds(sidebar_split_bounds);
419 sidebar_split->CalculateChildrenBounds(&contents_bounds, &sidebar_bounds);
420 } else {
421 contents_bounds = sidebar_split_bounds;
422 }
423
424 // Layout resize corner, sidebar mini tabs and calculate reserved contents
425 // rects here as all contents view bounds are already determined, but not yet
426 // set at this point, so contents will be laid out once at most.
427 // TODO(alekseys): layout sidebar minitabs and adjust reserved rect
428 // accordingly.
429 gfx::Rect browser_reserved_rect;
430 if (!browser_view_->frame_->GetWindow()->IsMaximized() &&
431 !browser_view_->frame_->GetWindow()->IsFullscreen()) {
432 gfx::Size resize_corner_size = browser_view_->GetResizeCornerSize();
433 if (!resize_corner_size.IsEmpty()) {
434 gfx::Rect bounds = browser_view_->GetLocalBounds(false);
435 gfx::Point resize_corner_origin(
436 bounds.right() - resize_corner_size.width(),
437 bounds.bottom() - resize_corner_size.height());
438 browser_reserved_rect =
439 gfx::Rect(resize_corner_origin, resize_corner_size);
440 }
441 }
442
443 UpdateReservedContentsRect(browser_reserved_rect,
444 browser_view_->contents_container_,
445 contents_bounds);
446 if (sidebar_split) {
447 UpdateReservedContentsRect(browser_reserved_rect,
448 browser_view_->sidebar_container_,
449 sidebar_bounds);
450 }
451 UpdateReservedContentsRect(browser_reserved_rect,
452 browser_view_->devtools_container_,
453 devtools_bounds);
454
455 // Now it's safe to actually resize all contents views in the hierarchy.
456 contents_split_->ResizeChildren(sidebar_split_bounds, devtools_bounds);
457 if (sidebar_split)
458 sidebar_split->ResizeChildren(contents_bounds, sidebar_bounds);
369 } 459 }
370 460
371 int BrowserViewLayout::GetTopMarginForActiveContent() { 461 int BrowserViewLayout::GetTopMarginForActiveContent() {
372 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() || 462 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() ||
373 !active_bookmark_bar_->IsDetached()) { 463 !active_bookmark_bar_->IsDetached()) {
374 return 0; 464 return 0;
375 } 465 }
376 466
377 if (contents_split_->GetChildViewAt(1) && 467 if (contents_split_->GetChildViewAt(1) &&
378 contents_split_->GetChildViewAt(1)->IsVisible()) 468 contents_split_->GetChildViewAt(1)->IsVisible())
(...skipping 26 matching lines...) Expand all
405 bottom -= height; 495 bottom -= height;
406 } 496 }
407 return bottom; 497 return bottom;
408 } 498 }
409 499
410 bool BrowserViewLayout::InfobarVisible() const { 500 bool BrowserViewLayout::InfobarVisible() const {
411 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. 501 // NOTE: Can't check if the size IsEmpty() since it's always 0-width.
412 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && 502 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) &&
413 (infobar_container_->GetPreferredSize().height() != 0); 503 (infobar_container_->GetPreferredSize().height() != 0);
414 } 504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698