| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/avatar_menu_bubble_view.h" | 5 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // ProfileItemView ------------------------------------------------------------ | 213 // ProfileItemView ------------------------------------------------------------ |
| 214 | 214 |
| 215 // Control that shows information about a single profile. | 215 // Control that shows information about a single profile. |
| 216 class ProfileItemView : public views::CustomButton, | 216 class ProfileItemView : public views::CustomButton, |
| 217 public HighlightDelegate { | 217 public HighlightDelegate { |
| 218 public: | 218 public: |
| 219 ProfileItemView(const AvatarMenu::Item& item, | 219 ProfileItemView(const AvatarMenu::Item& item, |
| 220 AvatarMenuBubbleView* parent, | 220 AvatarMenuBubbleView* parent, |
| 221 AvatarMenu* menu); | 221 AvatarMenu* menu); |
| 222 | 222 |
| 223 virtual gfx::Size GetPreferredSize() OVERRIDE; | 223 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
| 224 virtual void Layout() OVERRIDE; | 224 virtual void Layout() OVERRIDE; |
| 225 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 225 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
| 226 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 226 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
| 227 virtual void OnFocus() OVERRIDE; | 227 virtual void OnFocus() OVERRIDE; |
| 228 virtual void OnBlur() OVERRIDE; | 228 virtual void OnBlur() OVERRIDE; |
| 229 | 229 |
| 230 virtual void OnHighlightStateChanged() OVERRIDE; | 230 virtual void OnHighlightStateChanged() OVERRIDE; |
| 231 virtual void OnFocusStateChanged(bool has_focus) OVERRIDE; | 231 virtual void OnFocusStateChanged(bool has_focus) OVERRIDE; |
| 232 | 232 |
| 233 const AvatarMenu::Item& item() const { return item_; } | 233 const AvatarMenu::Item& item() const { return item_; } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // Add an edit profile link. | 290 // Add an edit profile link. |
| 291 edit_link_ = new EditProfileLink( | 291 edit_link_ = new EditProfileLink( |
| 292 l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this); | 292 l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this); |
| 293 edit_link_->set_listener(parent); | 293 edit_link_->set_listener(parent); |
| 294 edit_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 294 edit_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 295 AddChildView(edit_link_); | 295 AddChildView(edit_link_); |
| 296 | 296 |
| 297 OnHighlightStateChanged(); | 297 OnHighlightStateChanged(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 gfx::Size ProfileItemView::GetPreferredSize() { | 300 gfx::Size ProfileItemView::GetPreferredSize() const { |
| 301 int text_width = std::max(name_label_->GetPreferredSize().width(), | 301 int text_width = std::max(name_label_->GetPreferredSize().width(), |
| 302 sync_state_label_->GetPreferredSize().width()); | 302 sync_state_label_->GetPreferredSize().width()); |
| 303 text_width = std::max(edit_link_->GetPreferredSize().width(), text_width); | 303 text_width = std::max(edit_link_->GetPreferredSize().width(), text_width); |
| 304 text_width = std::min(kMaxItemTextWidth, text_width); | 304 text_width = std::min(kMaxItemTextWidth, text_width); |
| 305 return gfx::Size(profiles::kAvatarIconWidth + kIconMarginX + text_width, | 305 return gfx::Size(profiles::kAvatarIconWidth + kIconMarginX + text_width, |
| 306 kItemHeight); | 306 kItemHeight); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void ProfileItemView::Layout() { | 309 void ProfileItemView::Layout() { |
| 310 // Profile icon. | 310 // Profile icon. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 avatar_menu_.reset(new AvatarMenu( | 530 avatar_menu_.reset(new AvatarMenu( |
| 531 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 531 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
| 532 this, | 532 this, |
| 533 browser_)); | 533 browser_)); |
| 534 avatar_menu_->RebuildMenu(); | 534 avatar_menu_->RebuildMenu(); |
| 535 } | 535 } |
| 536 | 536 |
| 537 AvatarMenuBubbleView::~AvatarMenuBubbleView() { | 537 AvatarMenuBubbleView::~AvatarMenuBubbleView() { |
| 538 } | 538 } |
| 539 | 539 |
| 540 gfx::Size AvatarMenuBubbleView::GetPreferredSize() { | 540 gfx::Size AvatarMenuBubbleView::GetPreferredSize() const { |
| 541 const int kBubbleViewMinWidth = 175; | 541 const int kBubbleViewMinWidth = 175; |
| 542 gfx::Size preferred_size(kBubbleViewMinWidth, 0); | 542 gfx::Size preferred_size(kBubbleViewMinWidth, 0); |
| 543 for (size_t i = 0; i < item_views_.size(); ++i) { | 543 for (size_t i = 0; i < item_views_.size(); ++i) { |
| 544 gfx::Size size = item_views_[i]->GetPreferredSize(); | 544 gfx::Size size = item_views_[i]->GetPreferredSize(); |
| 545 preferred_size.Enlarge(0, size.height() + kItemMarginY); | 545 preferred_size.Enlarge(0, size.height() + kItemMarginY); |
| 546 preferred_size.SetToMax(size); | 546 preferred_size.SetToMax(size); |
| 547 } | 547 } |
| 548 | 548 |
| 549 if (buttons_view_) { | 549 if (buttons_view_) { |
| 550 preferred_size.Enlarge( | 550 preferred_size.Enlarge( |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 693 |
| 694 for (size_t i = 0; i < item_views_.size(); ++i) { | 694 for (size_t i = 0; i < item_views_.size(); ++i) { |
| 695 ProfileItemView* item_view = item_views_[i]; | 695 ProfileItemView* item_view = item_views_[i]; |
| 696 if (source == item_view->edit_link()) { | 696 if (source == item_view->edit_link()) { |
| 697 avatar_menu_->EditProfile(i); | 697 avatar_menu_->EditProfile(i); |
| 698 return; | 698 return; |
| 699 } | 699 } |
| 700 } | 700 } |
| 701 } | 701 } |
| 702 | 702 |
| 703 gfx::Rect AvatarMenuBubbleView::GetAnchorRect() { | 703 gfx::Rect AvatarMenuBubbleView::GetAnchorRect() const { |
| 704 return anchor_rect_; | 704 return anchor_rect_; |
| 705 } | 705 } |
| 706 | 706 |
| 707 void AvatarMenuBubbleView::Init() { | 707 void AvatarMenuBubbleView::Init() { |
| 708 // Build the menu for the first time. | 708 // Build the menu for the first time. |
| 709 OnAvatarMenuChanged(avatar_menu_.get()); | 709 OnAvatarMenuChanged(avatar_menu_.get()); |
| 710 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE)); | 710 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE)); |
| 711 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE)); | 711 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE)); |
| 712 } | 712 } |
| 713 | 713 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 Layout(); | 803 Layout(); |
| 804 if (GetBubbleFrameView()) | 804 if (GetBubbleFrameView()) |
| 805 SizeToContents(); | 805 SizeToContents(); |
| 806 } | 806 } |
| 807 | 807 |
| 808 void AvatarMenuBubbleView::SetBackgroundColors() { | 808 void AvatarMenuBubbleView::SetBackgroundColors() { |
| 809 for (size_t i = 0; i < item_views_.size(); ++i) { | 809 for (size_t i = 0; i < item_views_.size(); ++i) { |
| 810 item_views_[i]->OnHighlightStateChanged(); | 810 item_views_[i]->OnHighlightStateChanged(); |
| 811 } | 811 } |
| 812 } | 812 } |
| OLD | NEW |