| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "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" | |
| 17 #include "chrome/browser/ui/views/tabs/side_tab_strip.h" | 16 #include "chrome/browser/ui/views/tabs/side_tab_strip.h" |
| 18 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 17 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 19 #include "chrome/browser/ui/views/toolbar_view.h" | 18 #include "chrome/browser/ui/views/toolbar_view.h" |
| 20 #include "gfx/scrollbar_size.h" | 19 #include "gfx/scrollbar_size.h" |
| 21 #include "views/controls/single_split_view.h" | |
| 22 #include "views/window/window.h" | 20 #include "views/window/window.h" |
| 23 | 21 |
| 24 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) |
| 25 #include "views/window/hit_test.h" | 23 #include "views/window/hit_test.h" |
| 26 #endif | 24 #endif |
| 27 | 25 |
| 28 namespace { | 26 namespace { |
| 29 | 27 |
| 30 // The visible height of the shadow above the tabs. Clicks in this area are | 28 // The visible height of the shadow above the tabs. Clicks in this area are |
| 31 // treated as clicks to the frame, rather than clicks to the tab. | 29 // treated as clicks to the frame, rather than clicks to the tab. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 active_bookmark_bar_ = NULL; | 200 active_bookmark_bar_ = NULL; |
| 203 tabstrip_ = NULL; | 201 tabstrip_ = NULL; |
| 204 browser_view_ = static_cast<BrowserView*>(host); | 202 browser_view_ = static_cast<BrowserView*>(host); |
| 205 } | 203 } |
| 206 | 204 |
| 207 void BrowserViewLayout::Uninstalled(views::View* host) {} | 205 void BrowserViewLayout::Uninstalled(views::View* host) {} |
| 208 | 206 |
| 209 void BrowserViewLayout::ViewAdded(views::View* host, views::View* view) { | 207 void BrowserViewLayout::ViewAdded(views::View* host, views::View* view) { |
| 210 switch (view->GetID()) { | 208 switch (view->GetID()) { |
| 211 case VIEW_ID_CONTENTS_SPLIT: { | 209 case VIEW_ID_CONTENTS_SPLIT: { |
| 212 contents_split_ = static_cast<views::SingleSplitView*>(view); | 210 contents_split_ = view; |
| 213 // We're installed as the LayoutManager before BrowserView creates the | 211 // We're installed as the LayoutManager before BrowserView creates the |
| 214 // contents, so we have to set contents_container_ here rather than in | 212 // contents, so we have to set contents_container_ here rather than |
| 215 // Installed. | 213 // Installed. |
| 216 contents_container_ = browser_view_->contents_; | 214 contents_container_ = browser_view_->contents_; |
| 217 break; | 215 break; |
| 218 } | 216 } |
| 219 case VIEW_ID_INFO_BAR_CONTAINER: | 217 case VIEW_ID_INFO_BAR_CONTAINER: |
| 220 infobar_container_ = view; | 218 infobar_container_ = view; |
| 221 break; | 219 break; |
| 222 case VIEW_ID_DOWNLOAD_SHELF: | 220 case VIEW_ID_DOWNLOAD_SHELF: |
| 223 download_shelf_ = static_cast<DownloadShelfView*>(view); | 221 download_shelf_ = static_cast<DownloadShelfView*>(view); |
| 224 break; | 222 break; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 356 |
| 359 int BrowserViewLayout::LayoutInfoBar(int top) { | 357 int BrowserViewLayout::LayoutInfoBar(int top) { |
| 360 bool visible = InfobarVisible(); | 358 bool visible = InfobarVisible(); |
| 361 int height = visible ? infobar_container_->GetPreferredSize().height() : 0; | 359 int height = visible ? infobar_container_->GetPreferredSize().height() : 0; |
| 362 infobar_container_->SetVisible(visible); | 360 infobar_container_->SetVisible(visible); |
| 363 infobar_container_->SetBounds(vertical_layout_rect_.x(), top, | 361 infobar_container_->SetBounds(vertical_layout_rect_.x(), top, |
| 364 vertical_layout_rect_.width(), height); | 362 vertical_layout_rect_.width(), height); |
| 365 return top + height; | 363 return top + height; |
| 366 } | 364 } |
| 367 | 365 |
| 368 // |browser_reserved_rect| is in browser_view_ coordinates. | |
| 369 // |future_source_bounds| is in |source|'s parent coordinates. | |
| 370 // |future_parent_offset| is required, since parent view is not moved yet. | |
| 371 // Note that |future_parent_offset| is relative to browser_view_, not to | |
| 372 // the parent view. | |
| 373 void BrowserViewLayout::UpdateReservedContentsRect( | |
| 374 const gfx::Rect& browser_reserved_rect, | |
| 375 TabContentsContainer* source, | |
| 376 const gfx::Rect& future_source_bounds, | |
| 377 const gfx::Point& future_parent_offset) { | |
| 378 gfx::Point resize_corner_origin(browser_reserved_rect.origin()); | |
| 379 // Convert |resize_corner_origin| from browser_view_ to source's parent | |
| 380 // coordinates. | |
| 381 views::View::ConvertPointToView(browser_view_, source->GetParent(), | |
| 382 &resize_corner_origin); | |
| 383 // Create |reserved_rect| in source's parent coordinates. | |
| 384 gfx::Rect reserved_rect(resize_corner_origin, browser_reserved_rect.size()); | |
| 385 // Apply source's parent future offset to it. | |
| 386 reserved_rect.Offset(-future_parent_offset.x(), -future_parent_offset.y()); | |
| 387 if (future_source_bounds.Intersects(reserved_rect)) { | |
| 388 // |source| is not properly positioned yet to use ConvertPointToView, | |
| 389 // so convert it into |source|'s coordinates manually. | |
| 390 reserved_rect.Offset(-future_source_bounds.x(), -future_source_bounds.y()); | |
| 391 } else { | |
| 392 reserved_rect = gfx::Rect(); | |
| 393 } | |
| 394 | |
| 395 source->SetReservedContentsRect(reserved_rect); | |
| 396 } | |
| 397 | |
| 398 void BrowserViewLayout::LayoutTabContents(int top, int bottom) { | 366 void BrowserViewLayout::LayoutTabContents(int top, int bottom) { |
| 399 // The ultimate idea is to calcualte bounds and reserved areas for all | 367 contents_split_->SetBounds(vertical_layout_rect_.x(), top, |
| 400 // contents views first and then resize them all, so every view | 368 vertical_layout_rect_.width(), bottom - top); |
| 401 // (and its contents) is resized and laid out only once. | |
| 402 | |
| 403 // The views hierarcy (see browser_view.h for more details): | |
| 404 // 1) Sidebar is not allowed: | |
| 405 // contents_split_ -> [contents_container_ | devtools] | |
| 406 // 2) Sidebar is allowed: | |
| 407 // contents_split_ -> | |
| 408 // [sidebar_split -> [contents_container_ | sidebar]] | devtools | |
| 409 | |
| 410 gfx::Rect sidebar_split_bounds; | |
| 411 gfx::Rect contents_bounds; | |
| 412 gfx::Rect sidebar_bounds; | |
| 413 gfx::Rect devtools_bounds; | |
| 414 | |
| 415 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(), top, | |
| 416 vertical_layout_rect_.width(), | |
| 417 std::max(0, bottom - top)); | |
| 418 contents_split_->CalculateChildrenBounds( | |
| 419 contents_split_bounds, &sidebar_split_bounds, &devtools_bounds); | |
| 420 gfx::Point contents_split_offset( | |
| 421 contents_split_bounds.x() - contents_split_->bounds().x(), | |
| 422 contents_split_bounds.y() - contents_split_->bounds().y()); | |
| 423 gfx::Point sidebar_split_offset(contents_split_offset); | |
| 424 sidebar_split_offset.Offset(sidebar_split_bounds.x(), | |
| 425 sidebar_split_bounds.y()); | |
| 426 | |
| 427 views::SingleSplitView* sidebar_split = browser_view_->sidebar_split_; | |
| 428 if (sidebar_split) { | |
| 429 DCHECK(sidebar_split == contents_split_->GetChildViewAt(0)); | |
| 430 sidebar_split->CalculateChildrenBounds( | |
| 431 sidebar_split_bounds, &contents_bounds, &sidebar_bounds); | |
| 432 } else { | |
| 433 contents_bounds = sidebar_split_bounds; | |
| 434 } | |
| 435 | |
| 436 // Layout resize corner, sidebar mini tabs and calculate reserved contents | |
| 437 // rects here as all contents view bounds are already determined, but not yet | |
| 438 // set at this point, so contents will be laid out once at most. | |
| 439 // TODO(alekseys): layout sidebar minitabs and adjust reserved rect | |
| 440 // accordingly. | |
| 441 gfx::Rect browser_reserved_rect; | |
| 442 if (!browser_view_->frame_->GetWindow()->IsMaximized() && | |
| 443 !browser_view_->frame_->GetWindow()->IsFullscreen()) { | |
| 444 gfx::Size resize_corner_size = browser_view_->GetResizeCornerSize(); | |
| 445 if (!resize_corner_size.IsEmpty()) { | |
| 446 gfx::Rect bounds = browser_view_->GetLocalBounds(false); | |
| 447 gfx::Point resize_corner_origin( | |
| 448 bounds.right() - resize_corner_size.width(), | |
| 449 bounds.bottom() - resize_corner_size.height()); | |
| 450 browser_reserved_rect = | |
| 451 gfx::Rect(resize_corner_origin, resize_corner_size); | |
| 452 } | |
| 453 } | |
| 454 | |
| 455 UpdateReservedContentsRect(browser_reserved_rect, | |
| 456 browser_view_->contents_container_, | |
| 457 contents_bounds, | |
| 458 sidebar_split_offset); | |
| 459 if (sidebar_split) { | |
| 460 UpdateReservedContentsRect(browser_reserved_rect, | |
| 461 browser_view_->sidebar_container_, | |
| 462 sidebar_bounds, | |
| 463 sidebar_split_offset); | |
| 464 } | |
| 465 UpdateReservedContentsRect(browser_reserved_rect, | |
| 466 browser_view_->devtools_container_, | |
| 467 devtools_bounds, | |
| 468 contents_split_offset); | |
| 469 | |
| 470 // Now it's safe to actually resize all contents views in the hierarchy. | |
| 471 contents_split_->SetBounds(contents_split_bounds); | |
| 472 if (sidebar_split) | |
| 473 sidebar_split->SetBounds(sidebar_split_bounds); | |
| 474 } | 369 } |
| 475 | 370 |
| 476 int BrowserViewLayout::GetTopMarginForActiveContent() { | 371 int BrowserViewLayout::GetTopMarginForActiveContent() { |
| 477 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() || | 372 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() || |
| 478 !active_bookmark_bar_->IsDetached()) { | 373 !active_bookmark_bar_->IsDetached()) { |
| 479 return 0; | 374 return 0; |
| 480 } | 375 } |
| 481 | 376 |
| 482 if (contents_split_->GetChildViewAt(1) && | 377 if (contents_split_->GetChildViewAt(1) && |
| 483 contents_split_->GetChildViewAt(1)->IsVisible()) | 378 contents_split_->GetChildViewAt(1)->IsVisible()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 510 bottom -= height; | 405 bottom -= height; |
| 511 } | 406 } |
| 512 return bottom; | 407 return bottom; |
| 513 } | 408 } |
| 514 | 409 |
| 515 bool BrowserViewLayout::InfobarVisible() const { | 410 bool BrowserViewLayout::InfobarVisible() const { |
| 516 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 411 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
| 517 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 412 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
| 518 (infobar_container_->GetPreferredSize().height() != 0); | 413 (infobar_container_->GetPreferredSize().height() != 0); |
| 519 } | 414 } |
| OLD | NEW |