Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/ui/views/avatar_menu_bubble_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698