| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/profiles/profiles_state.h" | 8 #include "chrome/browser/profiles/profiles_state.h" |
| 9 #include "chrome/browser/ui/views/profiles/avatar_label.h" | |
| 10 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 9 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
| 11 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 10 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 12 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 13 #include "components/signin/core/common/profile_management_switches.h" | 12 #include "components/signin/core/common/profile_management_switches.h" |
| 14 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" |
| 15 #include "ui/views/controls/button/image_button.h" | 14 #include "ui/views/controls/button/image_button.h" |
| 16 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 17 | 16 |
| 17 #if defined(ENABLE_MANAGED_USERS) |
| 18 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" |
| 19 #endif |
| 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 // Besides the frame border, there's another 9 px of empty space atop the | 23 // Besides the frame border, there's another 9 px of empty space atop the |
| 21 // window in restored mode, to use to drag the window around. | 24 // window in restored mode, to use to drag the window around. |
| 22 const int kNonClientRestoredExtraThickness = 9; | 25 const int kNonClientRestoredExtraThickness = 9; |
| 23 | 26 |
| 24 // The titlebar never shrinks too short to show the caption button plus some | 27 // The titlebar never shrinks too short to show the caption button plus some |
| 25 // padding below it. | 28 // padding below it. |
| 26 const int kCaptionButtonHeightWithPadding = 19; | 29 const int kCaptionButtonHeightWithPadding = 19; |
| 27 | 30 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the | 48 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the |
| 46 // user). | 49 // user). |
| 47 const int kAvatarBottomSpacing = 2; | 50 const int kAvatarBottomSpacing = 2; |
| 48 | 51 |
| 49 // Space between the frame border and the edge of the avatar. | 52 // Space between the frame border and the edge of the avatar. |
| 50 const int kAvatarOuterSpacing = 2; | 53 const int kAvatarOuterSpacing = 2; |
| 51 | 54 |
| 52 // Space between the edge of the avatar and the tabstrip. | 55 // Space between the edge of the avatar and the tabstrip. |
| 53 const int kAvatarInnerSpacing = 4; | 56 const int kAvatarInnerSpacing = 4; |
| 54 | 57 |
| 58 #if defined(ENABLE_MANAGED_USERS) |
| 55 // Space between the trailing edge of the avatar label and the tabstrip. | 59 // Space between the trailing edge of the avatar label and the tabstrip. |
| 56 const int kAvatarLabelInnerSpacing = 10; | 60 const int kSupervisedUserAvatarLabelInnerSpacing = 10; |
| 61 #endif |
| 57 | 62 |
| 58 // How far the new avatar button is from the closest caption button. | 63 // How far the new avatar button is from the closest caption button. |
| 59 const int kNewAvatarButtonOffset = 5; | 64 const int kNewAvatarButtonOffset = 5; |
| 60 | 65 |
| 61 // When the title bar is in its normal two row mode (usually the case for | 66 // When the title bar is in its normal two row mode (usually the case for |
| 62 // restored windows), the New Tab button isn't at the same height as the caption | 67 // restored windows), the New Tab button isn't at the same height as the caption |
| 63 // buttons, but the space will look cluttered if it actually slides under them, | 68 // buttons, but the space will look cluttered if it actually slides under them, |
| 64 // so we stop it when the gap between the two is down to 5 px. | 69 // so we stop it when the gap between the two is down to 5 px. |
| 65 const int kNewTabCaptionNormalSpacing = 5; | 70 const int kNewTabCaptionNormalSpacing = 5; |
| 66 | 71 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 has_leading_buttons_(false), | 113 has_leading_buttons_(false), |
| 109 has_trailing_buttons_(false), | 114 has_trailing_buttons_(false), |
| 110 extra_caption_y_(kExtraCaption), | 115 extra_caption_y_(kExtraCaption), |
| 111 window_caption_spacing_(kCaptionButtonSpacing), | 116 window_caption_spacing_(kCaptionButtonSpacing), |
| 112 minimize_button_(NULL), | 117 minimize_button_(NULL), |
| 113 maximize_button_(NULL), | 118 maximize_button_(NULL), |
| 114 restore_button_(NULL), | 119 restore_button_(NULL), |
| 115 close_button_(NULL), | 120 close_button_(NULL), |
| 116 window_icon_(NULL), | 121 window_icon_(NULL), |
| 117 window_title_(NULL), | 122 window_title_(NULL), |
| 118 avatar_label_(NULL), | 123 #if defined(ENABLE_MANAGED_USERS) |
| 124 supervised_user_avatar_label_(NULL), |
| 125 #endif |
| 119 avatar_button_(NULL), | 126 avatar_button_(NULL), |
| 120 new_avatar_button_(NULL) { | 127 new_avatar_button_(NULL) { |
| 121 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); | 128 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); |
| 122 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); | 129 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); |
| 123 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); | 130 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); |
| 124 } | 131 } |
| 125 | 132 |
| 126 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} | 133 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} |
| 127 | 134 |
| 128 void OpaqueBrowserFrameViewLayout::SetButtonOrdering( | 135 void OpaqueBrowserFrameViewLayout::SetButtonOrdering( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 139 available_width -= leading_button_start_; | 146 available_width -= leading_button_start_; |
| 140 | 147 |
| 141 const int caption_spacing = NewTabCaptionSpacing(); | 148 const int caption_spacing = NewTabCaptionSpacing(); |
| 142 const int tabstrip_width = available_width - caption_spacing; | 149 const int tabstrip_width = available_width - caption_spacing; |
| 143 gfx::Rect bounds(leading_button_start_, GetTabStripInsetsTop(false), | 150 gfx::Rect bounds(leading_button_start_, GetTabStripInsetsTop(false), |
| 144 std::max(0, tabstrip_width), | 151 std::max(0, tabstrip_width), |
| 145 tabstrip_preferred_size.height()); | 152 tabstrip_preferred_size.height()); |
| 146 | 153 |
| 147 int leading_tabstrip_indent = kTabStripIndent; | 154 int leading_tabstrip_indent = kTabStripIndent; |
| 148 if (delegate_->ShouldShowAvatar() && !ShouldAvatarBeOnRight()) { | 155 if (delegate_->ShouldShowAvatar() && !ShouldAvatarBeOnRight()) { |
| 149 if (avatar_label_ && avatar_label_->bounds().width()) | 156 #if defined(ENABLE_MANAGED_USERS) |
| 150 leading_tabstrip_indent += kAvatarLabelInnerSpacing; | 157 if (supervised_user_avatar_label_ && |
| 158 supervised_user_avatar_label_->bounds().width()) |
| 159 leading_tabstrip_indent += kSupervisedUserAvatarLabelInnerSpacing; |
| 151 else | 160 else |
| 152 leading_tabstrip_indent += kAvatarInnerSpacing; | 161 leading_tabstrip_indent += kAvatarInnerSpacing; |
| 162 #else |
| 163 leading_tabstrip_indent += kAvatarInnerSpacing; |
| 164 #endif |
| 153 } | 165 } |
| 154 bounds.Inset(leading_tabstrip_indent, 0, 0, 0); | 166 bounds.Inset(leading_tabstrip_indent, 0, 0, 0); |
| 155 return bounds; | 167 return bounds; |
| 156 } | 168 } |
| 157 | 169 |
| 158 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize( | 170 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize( |
| 159 int available_width) const { | 171 int available_width) const { |
| 160 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize(); | 172 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize(); |
| 161 int border_thickness = NonClientBorderThickness(); | 173 int border_thickness = NonClientBorderThickness(); |
| 162 min_size.Enlarge(2 * border_thickness, | 174 min_size.Enlarge(2 * border_thickness, |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 avatar_bounds_.SetRect( | 437 avatar_bounds_.SetRect( |
| 426 avatar_x, | 438 avatar_x, |
| 427 avatar_y, | 439 avatar_y, |
| 428 incognito_icon.width(), | 440 incognito_icon.width(), |
| 429 delegate_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); | 441 delegate_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); |
| 430 if (avatar_button_) { | 442 if (avatar_button_) { |
| 431 avatar_button_->set_button_on_right(avatar_on_right); | 443 avatar_button_->set_button_on_right(avatar_on_right); |
| 432 avatar_button_->SetBoundsRect(avatar_bounds_); | 444 avatar_button_->SetBoundsRect(avatar_bounds_); |
| 433 | 445 |
| 434 int edge_offset; | 446 int edge_offset; |
| 435 if (avatar_label_) { | 447 #if defined(ENABLE_MANAGED_USERS) |
| 436 avatar_label_->SetLabelOnRight(avatar_on_right); | 448 if (supervised_user_avatar_label_) { |
| 449 supervised_user_avatar_label_->SetLabelOnRight(avatar_on_right); |
| 437 // Space between the bottom of the avatar and the bottom of the avatar | 450 // Space between the bottom of the avatar and the bottom of the avatar |
| 438 // label. | 451 // label. |
| 439 const int kAvatarLabelBottomSpacing = 3; | 452 const int kSupervisedUserAvatarLabelBottomSpacing = 3; |
| 440 gfx::Size label_size = avatar_label_->GetPreferredSize(); | 453 gfx::Size label_size = supervised_user_avatar_label_->GetPreferredSize(); |
| 441 // The outside edge of the avatar label should be just outside that of the | 454 // The outside edge of the avatar label should be just outside that of the |
| 442 // avatar menu button. | 455 // avatar menu button. |
| 443 int avatar_label_x = avatar_on_right ? | 456 int avatar_label_x = avatar_on_right ? |
| 444 (host->width() - trailing_button_start_ - label_size.width()) : | 457 (host->width() - trailing_button_start_ - label_size.width()) : |
| 445 leading_button_start_; | 458 leading_button_start_; |
| 446 gfx::Rect label_bounds( | 459 gfx::Rect label_bounds( |
| 447 avatar_label_x, | 460 avatar_label_x, |
| 448 avatar_bottom - kAvatarLabelBottomSpacing - label_size.height(), | 461 avatar_bottom - kSupervisedUserAvatarLabelBottomSpacing - |
| 462 label_size.height(), |
| 449 label_size.width(), | 463 label_size.width(), |
| 450 delegate_->ShouldShowAvatar() ? label_size.height() : 0); | 464 delegate_->ShouldShowAvatar() ? label_size.height() : 0); |
| 451 avatar_label_->SetBoundsRect(label_bounds); | 465 supervised_user_avatar_label_->SetBoundsRect(label_bounds); |
| 452 edge_offset = label_size.width(); | 466 edge_offset = label_size.width(); |
| 453 } else { | 467 } else { |
| 454 edge_offset = kAvatarOuterSpacing + incognito_icon.width(); | 468 edge_offset = kAvatarOuterSpacing + incognito_icon.width(); |
| 455 } | 469 } |
| 470 #else |
| 471 edge_offset = kAvatarOuterSpacing + incognito_icon.width(); |
| 472 #endif |
| 456 if (avatar_on_right) | 473 if (avatar_on_right) |
| 457 trailing_button_start_ += edge_offset; | 474 trailing_button_start_ += edge_offset; |
| 458 else | 475 else |
| 459 leading_button_start_ += edge_offset; | 476 leading_button_start_ += edge_offset; |
| 460 | 477 |
| 461 // We just add the avatar button size to the minimum size because clicking | 478 // We just add the avatar button size to the minimum size because clicking |
| 462 // the avatar label does the same thing as clicking the avatar button. | 479 // the avatar label does the same thing as clicking the avatar button. |
| 463 minimum_size_for_buttons_ += kAvatarOuterSpacing + incognito_icon.width(); | 480 minimum_size_for_buttons_ += kAvatarOuterSpacing + incognito_icon.width(); |
| 464 } | 481 } |
| 465 } | 482 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 case VIEW_ID_WINDOW_ICON: | 640 case VIEW_ID_WINDOW_ICON: |
| 624 window_icon_ = view; | 641 window_icon_ = view; |
| 625 break; | 642 break; |
| 626 case VIEW_ID_WINDOW_TITLE: | 643 case VIEW_ID_WINDOW_TITLE: |
| 627 if (view) { | 644 if (view) { |
| 628 DCHECK_EQ(std::string(views::Label::kViewClassName), | 645 DCHECK_EQ(std::string(views::Label::kViewClassName), |
| 629 view->GetClassName()); | 646 view->GetClassName()); |
| 630 } | 647 } |
| 631 window_title_ = static_cast<views::Label*>(view); | 648 window_title_ = static_cast<views::Label*>(view); |
| 632 break; | 649 break; |
| 633 case VIEW_ID_AVATAR_LABEL: | 650 #if defined(ENABLE_MANAGED_USERS) |
| 634 avatar_label_ = static_cast<AvatarLabel*>(view); | 651 case VIEW_ID_SUPERVISED_USER_AVATAR_LABEL: |
| 652 supervised_user_avatar_label_ = |
| 653 static_cast<SupervisedUserAvatarLabel*>(view); |
| 635 break; | 654 break; |
| 655 #endif |
| 636 case VIEW_ID_AVATAR_BUTTON: | 656 case VIEW_ID_AVATAR_BUTTON: |
| 637 if (view) { | 657 if (view) { |
| 638 DCHECK_EQ(std::string(AvatarMenuButton::kViewClassName), | 658 DCHECK_EQ(std::string(AvatarMenuButton::kViewClassName), |
| 639 view->GetClassName()); | 659 view->GetClassName()); |
| 640 } | 660 } |
| 641 avatar_button_ = static_cast<AvatarMenuButton*>(view); | 661 avatar_button_ = static_cast<AvatarMenuButton*>(view); |
| 642 break; | 662 break; |
| 643 case VIEW_ID_NEW_AVATAR_BUTTON: | 663 case VIEW_ID_NEW_AVATAR_BUTTON: |
| 644 new_avatar_button_ = view; | 664 new_avatar_button_ = view; |
| 645 break; | 665 break; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 | 708 |
| 689 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 709 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
| 690 views::View* view) { | 710 views::View* view) { |
| 691 SetView(view->id(), view); | 711 SetView(view->id(), view); |
| 692 } | 712 } |
| 693 | 713 |
| 694 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 714 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
| 695 views::View* view) { | 715 views::View* view) { |
| 696 SetView(view->id(), NULL); | 716 SetView(view->id(), NULL); |
| 697 } | 717 } |
| OLD | NEW |