OLD | NEW |
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 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->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 // contents_split_ is a SingleSplitView, it will adjust cached views rects, |
| 404 // but will not resize these views yet. |
367 contents_split_->SetBounds(vertical_layout_rect_.x(), top, | 405 contents_split_->SetBounds(vertical_layout_rect_.x(), top, |
368 vertical_layout_rect_.width(), bottom - top); | 406 vertical_layout_rect_.width(), bottom - top); |
| 407 |
| 408 // As a SingleSplitView, sidebar_split should be resized upfront too |
| 409 // to let it adjust its own cached views rects. |
| 410 views::SingleSplitView* sidebar_split = browser_view_->sidebar_split_; |
| 411 if (sidebar_split) { |
| 412 DCHECK(sidebar_split == contents_split_->GetChildViewAt(0)); |
| 413 sidebar_split->SetBounds(contents_split_->leading_view_rect()); |
| 414 } |
| 415 |
| 416 // Layout resize corner and sidebar mini tabs and calculate reserved contents |
| 417 // rects here as all contents view bounds are determined, but not yet set |
| 418 // at this point, so contents will be laid out once at most. |
| 419 // TODO(alekseys): layout sidebar minitabs and adjust reserved rect |
| 420 // accordingly. |
| 421 gfx::Rect browser_reserved_rect; |
| 422 if (!browser_view_->frame_->GetWindow()->IsMaximized() && |
| 423 !browser_view_->frame_->GetWindow()->IsFullscreen()) { |
| 424 gfx::Size resize_corner_size = browser_view_->GetResizeCornerSize(); |
| 425 if (!resize_corner_size.IsEmpty()) { |
| 426 gfx::Rect bounds = browser_view_->GetLocalBounds(false); |
| 427 gfx::Point resize_corner_origin( |
| 428 bounds.right() - resize_corner_size.width(), |
| 429 bounds.bottom() - resize_corner_size.height()); |
| 430 browser_reserved_rect = |
| 431 gfx::Rect(resize_corner_origin, resize_corner_size); |
| 432 } |
| 433 } |
| 434 |
| 435 if (sidebar_split) { |
| 436 UpdateReservedContentsRect(browser_reserved_rect, |
| 437 browser_view_->contents_container_, |
| 438 sidebar_split->leading_view_rect()); |
| 439 UpdateReservedContentsRect(browser_reserved_rect, |
| 440 browser_view_->sidebar_container_, |
| 441 sidebar_split->trailing_view_rect()); |
| 442 } else { |
| 443 UpdateReservedContentsRect(browser_reserved_rect, |
| 444 browser_view_->contents_container_, |
| 445 contents_split_->leading_view_rect()); |
| 446 } |
| 447 UpdateReservedContentsRect(browser_reserved_rect, |
| 448 browser_view_->devtools_container_, |
| 449 contents_split_->trailing_view_rect()); |
| 450 |
| 451 // Now it's safe to actually resize all contents views in the hierarchy. |
| 452 contents_split_->ResizeViews(); |
| 453 if (sidebar_split) |
| 454 sidebar_split->ResizeViews(); |
369 } | 455 } |
370 | 456 |
371 int BrowserViewLayout::GetTopMarginForActiveContent() { | 457 int BrowserViewLayout::GetTopMarginForActiveContent() { |
372 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() || | 458 if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() || |
373 !active_bookmark_bar_->IsDetached()) { | 459 !active_bookmark_bar_->IsDetached()) { |
374 return 0; | 460 return 0; |
375 } | 461 } |
376 | 462 |
377 if (contents_split_->GetChildViewAt(1) && | 463 if (contents_split_->GetChildViewAt(1) && |
378 contents_split_->GetChildViewAt(1)->IsVisible()) | 464 contents_split_->GetChildViewAt(1)->IsVisible()) |
(...skipping 26 matching lines...) Expand all Loading... |
405 bottom -= height; | 491 bottom -= height; |
406 } | 492 } |
407 return bottom; | 493 return bottom; |
408 } | 494 } |
409 | 495 |
410 bool BrowserViewLayout::InfobarVisible() const { | 496 bool BrowserViewLayout::InfobarVisible() const { |
411 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 497 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
412 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 498 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
413 (infobar_container_->GetPreferredSize().height() != 0); | 499 (infobar_container_->GetPreferredSize().height() != 0); |
414 } | 500 } |
OLD | NEW |