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" |
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 Loading... |
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 Loading... |
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|'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 |
366 void BrowserViewLayout::LayoutTabContents(int top, int bottom) { | 398 void BrowserViewLayout::LayoutTabContents(int top, int bottom) { |
367 contents_split_->SetBounds(vertical_layout_rect_.x(), top, | 399 // The ultimate idea is to calcualte bounds and reserved areas for all |
368 vertical_layout_rect_.width(), bottom - top); | 400 // contents views first and then resize them all, so every view |
| 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); |
369 } | 474 } |
370 | 475 |
371 int BrowserViewLayout::GetTopMarginForActiveContent() { | 476 int BrowserViewLayout::GetTopMarginForActiveContent() { |
372 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() || | 477 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() || |
373 !active_bookmark_bar_->IsDetached()) { | 478 !active_bookmark_bar_->IsDetached()) { |
374 return 0; | 479 return 0; |
375 } | 480 } |
376 | 481 |
377 if (contents_split_->GetChildViewAt(1) && | 482 if (contents_split_->GetChildViewAt(1) && |
378 contents_split_->GetChildViewAt(1)->IsVisible()) | 483 contents_split_->GetChildViewAt(1)->IsVisible()) |
(...skipping 26 matching lines...) Expand all Loading... |
405 bottom -= height; | 510 bottom -= height; |
406 } | 511 } |
407 return bottom; | 512 return bottom; |
408 } | 513 } |
409 | 514 |
410 bool BrowserViewLayout::InfobarVisible() const { | 515 bool BrowserViewLayout::InfobarVisible() const { |
411 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 516 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
412 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 517 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
413 (infobar_container_->GetPreferredSize().height() != 0); | 518 (infobar_container_->GetPreferredSize().height() != 0); |
414 } | 519 } |
OLD | NEW |