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

Side by Side Diff: chrome/browser/ui/views/profiles/new_avatar_button.cc

Issue 381953002: New avatar button: Consolidate text elision between Mac and Win/Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use TruncateString Created 6 years, 5 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 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/new_avatar_button.h" 5 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/win/windows_version.h" 8 #include "base/win/windows_version.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
(...skipping 30 matching lines...) Expand all
41 41
42 const int kLeftRightInset = 10; 42 const int kLeftRightInset = 10;
43 const int kTopInset = 0; 43 const int kTopInset = 0;
44 const int kBottomInset = 4; 44 const int kBottomInset = 4;
45 border->set_insets(gfx::Insets(kTopInset, kLeftRightInset, 45 border->set_insets(gfx::Insets(kTopInset, kLeftRightInset,
46 kBottomInset, kLeftRightInset)); 46 kBottomInset, kLeftRightInset));
47 47
48 return border.PassAs<views::Border>(); 48 return border.PassAs<views::Border>();
49 } 49 }
50 50
51 base::string16 GetElidedText(const base::string16& original_text) {
52 // Maximum characters the button can be before the text will get elided.
53 const int kMaxCharactersToDisplay = 15;
54 const gfx::FontList font_list;
55 return gfx::ElideText(original_text, font_list,
56 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay),
57 gfx::ELIDE_TAIL);
58 }
59
60 base::string16 GetButtonText(Profile* profile) {
61 base::string16 name = GetElidedText(profiles::GetAvatarNameForProfile(
62 profile->GetPath()));
63 if (profile->IsSupervised())
64 name = l10n_util::GetStringFUTF16(IDS_SUPERVISED_USER_NEW_AVATAR_LABEL,
65 name);
66 return name;
67 }
68
69 } // namespace 51 } // namespace
70 52
71 NewAvatarButton::NewAvatarButton( 53 NewAvatarButton::NewAvatarButton(
72 views::ButtonListener* listener, 54 views::ButtonListener* listener,
73 const base::string16& profile_name, 55 const base::string16& profile_name,
74 AvatarButtonStyle button_style, 56 AvatarButtonStyle button_style,
75 Browser* browser) 57 Browser* browser)
76 : MenuButton(listener, GetButtonText(browser->profile()), NULL, true), 58 : MenuButton(listener,
59 profiles::GetAvatarButtonTextForProfile(browser->profile()),
60 NULL,
61 true),
77 browser_(browser) { 62 browser_(browser) {
78 set_animate_on_state_change(false); 63 set_animate_on_state_change(false);
79 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); 64 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE);
80 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); 65 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE);
81 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); 66 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE);
82 SetTextShadows(gfx::ShadowValues(10, 67 SetTextShadows(gfx::ShadowValues(10,
83 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); 68 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY)));
84 SetTextSubpixelRenderingEnabled(false); 69 SetTextSubpixelRenderingEnabled(false);
85 70
86 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 71 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 icon = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( 151 icon = *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
167 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia(); 152 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia();
168 } 153 }
169 154
170 SetImage(views::Button::STATE_NORMAL, icon); 155 SetImage(views::Button::STATE_NORMAL, icon);
171 UpdateAvatarButtonAndRelayoutParent(); 156 UpdateAvatarButtonAndRelayoutParent();
172 } 157 }
173 158
174 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { 159 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
175 // We want the button to resize if the new text is shorter. 160 // We want the button to resize if the new text is shorter.
176 SetText(GetButtonText(browser_->profile())); 161 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile()));
177 set_min_size(gfx::Size()); 162 set_min_size(gfx::Size());
178 InvalidateLayout(); 163 InvalidateLayout();
179 164
180 // Because the width of the button might have changed, the parent browser 165 // Because the width of the button might have changed, the parent browser
181 // frame needs to recalculate the button bounds and redraw it. 166 // frame needs to recalculate the button bounds and redraw it.
182 if (parent()) 167 if (parent())
183 parent()->Layout(); 168 parent()->Layout();
184 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698