Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/opaque_browser_frame_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profiles_state.h" | |
| 8 #include "chrome/browser/ui/views/new_avatar_button.h" | |
| 7 #include "ui/gfx/font.h" | 9 #include "ui/gfx/font.h" |
| 8 #include "ui/views/controls/button/image_button.h" | 10 #include "ui/views/controls/button/image_button.h" |
| 9 #include "ui/views/controls/label.h" | 11 #include "ui/views/controls/label.h" |
| 10 | 12 |
| 11 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
| 12 #include "win8/util/win8_util.h" | 14 #include "win8/util/win8_util.h" |
| 13 #endif // OS_WIN | 15 #endif // OS_WIN |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 42 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the | 44 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the |
| 43 // user). | 45 // user). |
| 44 const int kAvatarBottomSpacing = 2; | 46 const int kAvatarBottomSpacing = 2; |
| 45 | 47 |
| 46 // Space between the frame border and the left edge of the avatar. | 48 // Space between the frame border and the left edge of the avatar. |
| 47 const int kAvatarLeftSpacing = 2; | 49 const int kAvatarLeftSpacing = 2; |
| 48 | 50 |
| 49 // Space between the right edge of the avatar and the tabstrip. | 51 // Space between the right edge of the avatar and the tabstrip. |
| 50 const int kAvatarRightSpacing = -4; | 52 const int kAvatarRightSpacing = -4; |
| 51 | 53 |
| 54 // How far the new avatar button is from the closest caption button. | |
| 55 const int kNewAvatarButtonOffset = 5; | |
| 56 | |
| 52 // In restored mode, the New Tab button isn't at the same height as the caption | 57 // In restored mode, the New Tab button isn't at the same height as the caption |
| 53 // buttons, but the space will look cluttered if it actually slides under them, | 58 // buttons, but the space will look cluttered if it actually slides under them, |
| 54 // so we stop it when the gap between the two is down to 5 px. | 59 // so we stop it when the gap between the two is down to 5 px. |
| 55 const int kNewTabCaptionRestoredSpacing = 5; | 60 const int kNewTabCaptionRestoredSpacing = 5; |
| 56 | 61 |
| 57 // In maximized mode, where the New Tab button and the caption buttons are at | 62 // In maximized mode, where the New Tab button and the caption buttons are at |
| 58 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid | 63 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
| 59 // looking too cluttered. | 64 // looking too cluttered. |
| 60 const int kNewTabCaptionMaximizedSpacing = 16; | 65 const int kNewTabCaptionMaximizedSpacing = 16; |
| 61 | 66 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 has_trailing_buttons_(false), | 99 has_trailing_buttons_(false), |
| 95 extra_caption_y_(kExtraCaption), | 100 extra_caption_y_(kExtraCaption), |
| 96 window_caption_spacing_(kCaptionButtonSpacing), | 101 window_caption_spacing_(kCaptionButtonSpacing), |
| 97 minimize_button_(NULL), | 102 minimize_button_(NULL), |
| 98 maximize_button_(NULL), | 103 maximize_button_(NULL), |
| 99 restore_button_(NULL), | 104 restore_button_(NULL), |
| 100 close_button_(NULL), | 105 close_button_(NULL), |
| 101 window_icon_(NULL), | 106 window_icon_(NULL), |
| 102 window_title_(NULL), | 107 window_title_(NULL), |
| 103 avatar_label_(NULL), | 108 avatar_label_(NULL), |
| 104 avatar_button_(NULL) { | 109 avatar_button_(NULL), |
| 110 new_avatar_button_(NULL) { | |
| 105 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); | 111 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); |
| 106 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); | 112 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); |
| 107 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); | 113 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); |
| 108 } | 114 } |
| 109 | 115 |
| 110 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} | 116 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} |
| 111 | 117 |
| 112 // static | 118 // static |
| 113 bool OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons() { | 119 bool OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons() { |
| 114 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 window_icon_bounds_ = gfx::Rect(); | 354 window_icon_bounds_ = gfx::Rect(); |
| 349 } else { | 355 } else { |
| 350 // We set the icon bounds to a small rectangle in the top leading corner | 356 // We set the icon bounds to a small rectangle in the top leading corner |
| 351 // if there are no icons on the leading side. | 357 // if there are no icons on the leading side. |
| 352 window_icon_bounds_ = gfx::Rect( | 358 window_icon_bounds_ = gfx::Rect( |
| 353 frame_thickness + kIconLeftSpacing, frame_thickness, size, size); | 359 frame_thickness + kIconLeftSpacing, frame_thickness, size, size); |
| 354 } | 360 } |
| 355 } | 361 } |
| 356 } | 362 } |
| 357 | 363 |
| 364 void OpaqueBrowserFrameViewLayout::LayoutNewStyleAvatar(views::View* host) { | |
| 365 gfx::Size label_size = new_avatar_button_->GetPreferredSize(); | |
| 366 int button_size_with_offset = kNewAvatarButtonOffset + label_size.width(); | |
| 367 | |
| 368 int button_x; | |
| 369 int button_y = CaptionButtonY(false); | |
| 370 | |
| 371 button_x = host->width() - trailing_button_start_ - button_size_with_offset; | |
|
Elliot Glaysher
2013/10/09 17:43:50
move this so that it is int buton_x = host->width(
noms (inactive)
2013/10/09 18:17:52
Done.
| |
| 372 trailing_button_start_ += button_size_with_offset; | |
| 373 minimum_size_for_buttons_ += button_size_with_offset; | |
| 374 | |
| 375 new_avatar_button_->SetBounds( | |
| 376 button_x, | |
| 377 button_y, | |
| 378 label_size.width(), | |
| 379 button_y + kCaptionButtonHeightWithPadding); | |
| 380 } | |
| 381 | |
| 358 void OpaqueBrowserFrameViewLayout::LayoutAvatar() { | 382 void OpaqueBrowserFrameViewLayout::LayoutAvatar() { |
| 359 // Even though the avatar is used for both incognito and profiles we always | 383 // Even though the avatar is used for both incognito and profiles we always |
| 360 // use the incognito icon to layout the avatar button. The profile icon | 384 // use the incognito icon to layout the avatar button. The profile icon |
| 361 // can be customized so we can't depend on its size to perform layout. | 385 // can be customized so we can't depend on its size to perform layout. |
| 362 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); | 386 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); |
| 363 | 387 |
| 364 int avatar_bottom = GetTabStripInsetsTop(false) + | 388 int avatar_bottom = GetTabStripInsetsTop(false) + |
| 365 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; | 389 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; |
| 366 int avatar_restored_y = avatar_bottom - incognito_icon.height(); | 390 int avatar_restored_y = avatar_bottom - incognito_icon.height(); |
| 367 int avatar_y = delegate_->IsMaximized() ? | 391 int avatar_y = delegate_->IsMaximized() ? |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 view->GetClassName()); | 584 view->GetClassName()); |
| 561 } | 585 } |
| 562 window_title_ = static_cast<views::Label*>(view); | 586 window_title_ = static_cast<views::Label*>(view); |
| 563 break; | 587 break; |
| 564 case VIEW_ID_AVATAR_LABEL: | 588 case VIEW_ID_AVATAR_LABEL: |
| 565 avatar_label_ = view; | 589 avatar_label_ = view; |
| 566 break; | 590 break; |
| 567 case VIEW_ID_AVATAR_BUTTON: | 591 case VIEW_ID_AVATAR_BUTTON: |
| 568 avatar_button_ = view; | 592 avatar_button_ = view; |
| 569 break; | 593 break; |
| 594 case VIEW_ID_NEW_AVATAR_BUTTON: | |
| 595 new_avatar_button_ = static_cast<NewAvatarButton*>(view); | |
| 596 break; | |
| 570 default: | 597 default: |
| 571 NOTIMPLEMENTED() << "Unknown view id " << id; | 598 NOTIMPLEMENTED() << "Unknown view id " << id; |
| 572 break; | 599 break; |
| 573 } | 600 } |
| 574 } | 601 } |
| 575 | 602 |
| 576 /////////////////////////////////////////////////////////////////////////////// | 603 /////////////////////////////////////////////////////////////////////////////// |
| 577 // OpaqueBrowserFrameView, views::LayoutManager: | 604 // OpaqueBrowserFrameView, views::LayoutManager: |
| 578 | 605 |
| 579 void OpaqueBrowserFrameViewLayout::Layout(views::View* host) { | 606 void OpaqueBrowserFrameViewLayout::Layout(views::View* host) { |
| 580 // Reset all our data so that everything is invisible. | 607 // Reset all our data so that everything is invisible. |
| 581 int thickness = FrameBorderThickness(false); | 608 int thickness = FrameBorderThickness(false); |
| 582 leading_button_start_ = thickness; | 609 leading_button_start_ = thickness; |
| 583 trailing_button_start_ = thickness; | 610 trailing_button_start_ = thickness; |
| 584 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_; | 611 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_; |
| 585 has_leading_buttons_ = false; | 612 has_leading_buttons_ = false; |
| 586 has_trailing_buttons_ = false; | 613 has_trailing_buttons_ = false; |
| 587 | 614 |
| 588 LayoutWindowControls(host); | 615 LayoutWindowControls(host); |
| 589 LayoutTitleBar(host); | 616 LayoutTitleBar(host); |
| 590 | 617 |
| 591 // We now add a single pixel to the leading spacing. We do this because the | 618 // We now add a single pixel to the leading spacing. We do this because the |
| 592 // avatar and tab strip start one pixel inward compared to where things start | 619 // avatar and tab strip start one pixel inward compared to where things start |
| 593 // on the trailing side. | 620 // on the trailing side. |
| 594 leading_button_start_++; | 621 leading_button_start_++; |
| 595 | 622 |
| 596 LayoutAvatar(); | 623 if (delegate_->IsRegularOrGuestSession() && |
| 624 profiles::IsNewProfileManagementEnabled()) | |
| 625 LayoutNewStyleAvatar(host); | |
| 626 else | |
| 627 LayoutAvatar(); | |
| 597 | 628 |
| 598 client_view_bounds_ = CalculateClientAreaBounds( | 629 client_view_bounds_ = CalculateClientAreaBounds( |
| 599 host->width(), host->height()); | 630 host->width(), host->height()); |
| 600 } | 631 } |
| 601 | 632 |
| 602 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize(views::View* host) { | 633 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize(views::View* host) { |
| 603 // This is never used; NonClientView::GetPreferredSize() will be called | 634 // This is never used; NonClientView::GetPreferredSize() will be called |
| 604 // instead. | 635 // instead. |
| 605 NOTREACHED(); | 636 NOTREACHED(); |
| 606 return gfx::Size(); | 637 return gfx::Size(); |
| 607 } | 638 } |
| 608 | 639 |
| 609 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 640 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
| 610 views::View* view) { | 641 views::View* view) { |
| 611 SetView(view->id(), view); | 642 SetView(view->id(), view); |
| 612 } | 643 } |
| 613 | 644 |
| 614 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 645 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
| 615 views::View* view) { | 646 views::View* view) { |
| 616 SetView(view->id(), NULL); | 647 SetView(view->id(), NULL); |
| 617 } | 648 } |
| OLD | NEW |