| 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/avatar_menu_bubble_view.h" | 5 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/profiles/avatar_menu_model.h" | 10 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 scaled_width = Round(src_width * scale); | 51 scaled_width = Round(src_width * scale); |
| 54 } | 52 } |
| 55 int x = dst_x + (dst_width - scaled_width) / 2; | 53 int x = dst_x + (dst_width - scaled_width) / 2; |
| 56 int y = dst_y + (dst_height - scaled_height) / 2; | 54 int y = dst_y + (dst_height - scaled_height) / 2; |
| 57 return gfx::Rect(x, y, scaled_width, scaled_height); | 55 return gfx::Rect(x, y, scaled_width, scaled_height); |
| 58 } | 56 } |
| 59 | 57 |
| 60 // Delegate to callback when the highlight state of a control changes. | 58 // Delegate to callback when the highlight state of a control changes. |
| 61 class HighlightDelegate { | 59 class HighlightDelegate { |
| 62 public: | 60 public: |
| 63 virtual ~HighlightDelegate() {} | |
| 64 virtual void OnHighlightStateChanged() = 0; | 61 virtual void OnHighlightStateChanged() = 0; |
| 65 }; | 62 }; |
| 66 | 63 |
| 67 // A custom Link control that forwards highlight state changes. We need to do | 64 // A custom Link control that forwards highlight state changes. We need to do |
| 68 // this to make sure that the ProfileItemView looks highlighted even when | 65 // this to make sure that the ProfileItemView looks highlighted even when |
| 69 // the mouse is over this link. | 66 // the mouse is over this link. |
| 70 class EditProfileLink : public views::Link { | 67 class EditProfileLink : public views::Link { |
| 71 public: | 68 public: |
| 72 explicit EditProfileLink(const string16& title, | 69 explicit EditProfileLink(const string16& title, |
| 73 HighlightDelegate* delegate) | 70 HighlightDelegate* delegate) |
| 74 : views::Link(title), | 71 : views::Link(UTF16ToWideHack(title)), |
| 75 delegate_(delegate), | 72 delegate_(delegate), |
| 76 state_(views::CustomButton::BS_NORMAL) { | 73 state_(views::CustomButton::BS_NORMAL) { |
| 77 } | 74 } |
| 78 | 75 |
| 79 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { | 76 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { |
| 80 views::Link::OnMouseEntered(event); | 77 views::Link::OnMouseEntered(event); |
| 81 state_ = views::CustomButton::BS_HOT; | 78 state_ = views::CustomButton::BS_HOT; |
| 82 delegate_->OnHighlightStateChanged(); | 79 delegate_->OnHighlightStateChanged(); |
| 83 } | 80 } |
| 84 | 81 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 SkBitmap profile_icon = item_.icon; | 114 SkBitmap profile_icon = item_.icon; |
| 118 if (item_.active) { | 115 if (item_.active) { |
| 119 SkBitmap badged_icon = GetBadgedIcon(profile_icon); | 116 SkBitmap badged_icon = GetBadgedIcon(profile_icon); |
| 120 image_view_->SetImage(&badged_icon); | 117 image_view_->SetImage(&badged_icon); |
| 121 } else { | 118 } else { |
| 122 image_view_->SetImage(&profile_icon); | 119 image_view_->SetImage(&profile_icon); |
| 123 } | 120 } |
| 124 AddChildView(image_view_); | 121 AddChildView(image_view_); |
| 125 | 122 |
| 126 // Add a label to show the profile name. | 123 // Add a label to show the profile name. |
| 127 name_label_ = new views::Label(item_.name); | 124 name_label_ = new views::Label(UTF16ToWideHack(item_.name)); |
| 128 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 125 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 129 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); | 126 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); |
| 130 int style = item_.active ? gfx::Font::BOLD : 0; | 127 int style = item_.active ? gfx::Font::BOLD : 0; |
| 131 const int kNameFontDelta = 1; | 128 const int kNameFontDelta = 1; |
| 132 name_label_->SetFont(base_font.DeriveFont(kNameFontDelta, style)); | 129 name_label_->SetFont(base_font.DeriveFont(kNameFontDelta, style)); |
| 133 name_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 130 name_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 134 AddChildView(name_label_); | 131 AddChildView(name_label_); |
| 135 | 132 |
| 136 // Add a label to show the sync state. | 133 // Add a label to show the sync state. |
| 137 sync_state_label_ = new views::Label(item_.sync_state); | 134 sync_state_label_ = new views::Label(UTF16ToWideHack(item_.sync_state)); |
| 138 const int kStateFontDelta = -1; | 135 const int kStateFontDelta = -1; |
| 139 sync_state_label_->SetFont(base_font.DeriveFont(kStateFontDelta)); | 136 sync_state_label_->SetFont(base_font.DeriveFont(kStateFontDelta)); |
| 140 sync_state_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 137 sync_state_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 141 sync_state_label_->SetEnabled(false); | 138 sync_state_label_->SetEnabled(false); |
| 142 AddChildView(sync_state_label_); | 139 AddChildView(sync_state_label_); |
| 143 | 140 |
| 144 // Add an edit profile link. | 141 // Add an edit profile link. |
| 145 edit_link_ = new EditProfileLink( | 142 edit_link_ = new EditProfileLink( |
| 146 l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this); | 143 l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this); |
| 147 edit_link_->set_listener(edit_profile_listener); | 144 edit_link_->set_listener(edit_profile_listener); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return canvas.ExtractBitmap(); | 240 return canvas.ExtractBitmap(); |
| 244 } | 241 } |
| 245 | 242 |
| 246 EditProfileLink* edit_link_; | 243 EditProfileLink* edit_link_; |
| 247 views::ImageView* image_view_; | 244 views::ImageView* image_view_; |
| 248 AvatarMenuModel::Item item_; | 245 AvatarMenuModel::Item item_; |
| 249 views::Label* name_label_; | 246 views::Label* name_label_; |
| 250 views::Label* sync_state_label_; | 247 views::Label* sync_state_label_; |
| 251 }; | 248 }; |
| 252 | 249 |
| 253 } // namespace | 250 } // namespace |
| 254 | 251 |
| 255 AvatarMenuBubbleView::AvatarMenuBubbleView(Browser* browser) | 252 AvatarMenuBubbleView::AvatarMenuBubbleView(Browser* browser) |
| 256 : add_profile_link_(NULL), | 253 : add_profile_link_(NULL), |
| 257 browser_(browser) { | 254 browser_(browser) { |
| 258 avatar_menu_model_.reset(new AvatarMenuModel( | 255 avatar_menu_model_.reset(new AvatarMenuModel( |
| 259 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 256 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
| 260 this, browser_)); | 257 this, browser_)); |
| 261 // Build the menu for the first time. | 258 // Build the menu for the first time. |
| 262 OnAvatarMenuModelChanged(avatar_menu_model_.get()); | 259 OnAvatarMenuModelChanged(avatar_menu_model_.get()); |
| 263 } | 260 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 ProfileItemView* item_view = new ProfileItemView(item, this, this); | 358 ProfileItemView* item_view = new ProfileItemView(item, this, this); |
| 362 item_view->SetAccessibleName(l10n_util::GetStringFUTF16( | 359 item_view->SetAccessibleName(l10n_util::GetStringFUTF16( |
| 363 IDS_PROFILES_SWITCH_TO_PROFILE_ACCESSIBLE_NAME, item.name)); | 360 IDS_PROFILES_SWITCH_TO_PROFILE_ACCESSIBLE_NAME, item.name)); |
| 364 AddChildView(item_view); | 361 AddChildView(item_view); |
| 365 item_views_.push_back(item_view); | 362 item_views_.push_back(item_view); |
| 366 } | 363 } |
| 367 | 364 |
| 368 separator_ = new views::Separator(); | 365 separator_ = new views::Separator(); |
| 369 AddChildView(separator_); | 366 AddChildView(separator_); |
| 370 | 367 |
| 371 add_profile_link_ = new views::Link( | 368 add_profile_link_ = new views::Link(UTF16ToWide( |
| 372 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); | 369 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK))); |
| 373 add_profile_link_->set_listener(this); | 370 add_profile_link_->set_listener(this); |
| 374 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 371 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 375 add_profile_link_->SetNormalColor(SkColorSetRGB(0, 0x79, 0xda)); | 372 add_profile_link_->SetNormalColor(SkColorSetRGB(0, 0x79, 0xda)); |
| 376 AddChildView(add_profile_link_); | 373 AddChildView(add_profile_link_); |
| 377 | 374 |
| 378 PreferredSizeChanged(); | 375 PreferredSizeChanged(); |
| 379 } | 376 } |
| OLD | NEW |