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/new_avatar_button.h" | 5 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" |
6 | 6 |
7 #include "base/win/windows_version.h" | 7 #include "base/win/windows_version.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/profiles/profiles_state.h" | 10 #include "chrome/browser/profiles/profiles_state.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 const int kMaxCharactersToDisplay = 15; | 47 const int kMaxCharactersToDisplay = 15; |
48 | 48 |
49 const gfx::FontList font_list; | 49 const gfx::FontList font_list; |
50 return gfx::ElideText( | 50 return gfx::ElideText( |
51 original_text, | 51 original_text, |
52 font_list, | 52 font_list, |
53 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), | 53 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), |
54 gfx::ELIDE_AT_END); | 54 gfx::ELIDE_AT_END); |
55 } | 55 } |
56 | 56 |
57 base::string16 GetButtonText(Profile* profile) { | |
58 base::string16 name = GetElidedText( | |
59 profiles::GetAvatarNameForProfile(profile)); | |
60 if (profile->IsManaged()) { | |
61 base::string16 label( | |
62 l10n_util::GetStringUTF16(IDS_MANAGED_USER_NEW_AVATAR_LABEL)); | |
63 if (base::i18n::IsRTL()) | |
64 name = label + base::char16(' ') + name; | |
msw
2014/05/21 17:20:25
Appending the strings like this is incorrect, even
Marc Treib
2014/05/26 09:17:53
Ah yes, I was kinda expecting a comment here ;-)
S
| |
65 else | |
66 name = name + base::char16(' ') + label; | |
67 } | |
68 return name; | |
69 } | |
70 | |
57 } // namespace | 71 } // namespace |
58 | 72 |
59 NewAvatarButton::NewAvatarButton( | 73 NewAvatarButton::NewAvatarButton( |
60 views::ButtonListener* listener, | 74 views::ButtonListener* listener, |
61 const base::string16& profile_name, | 75 const base::string16& profile_name, |
62 AvatarButtonStyle button_style, | 76 AvatarButtonStyle button_style, |
63 Browser* browser) | 77 Browser* browser) |
64 : MenuButton(listener, GetElidedText(profile_name), NULL, true), | 78 : MenuButton(listener, GetButtonText(browser->profile()), NULL, true), |
Marc Treib
2014/05/21 16:19:55
@noms: Is there any reason why this didn't use pro
noms (inactive)
2014/05/21 17:00:57
None that I can see. I think GetAvatarNameForProfi
| |
65 browser_(browser) { | 79 browser_(browser) { |
66 set_animate_on_state_change(false); | 80 set_animate_on_state_change(false); |
67 | 81 |
68 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 82 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
69 | 83 |
70 bool is_win8 = false; | 84 bool is_win8 = false; |
71 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
72 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; | 86 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; |
73 #endif | 87 #endif |
74 | 88 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 158 |
145 void NewAvatarButton::OnProfileNameChanged( | 159 void NewAvatarButton::OnProfileNameChanged( |
146 const base::FilePath& profile_path, | 160 const base::FilePath& profile_path, |
147 const base::string16& old_profile_name) { | 161 const base::string16& old_profile_name) { |
148 UpdateAvatarButtonAndRelayoutParent(); | 162 UpdateAvatarButtonAndRelayoutParent(); |
149 } | 163 } |
150 | 164 |
151 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { | 165 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { |
152 // We want the button to resize if the new text is shorter. | 166 // We want the button to resize if the new text is shorter. |
153 ClearMaxTextSize(); | 167 ClearMaxTextSize(); |
154 SetText(GetElidedText( | 168 SetText(GetButtonText(browser_->profile())); |
155 profiles::GetAvatarNameForProfile(browser_->profile()))); | |
156 | 169 |
157 // Because the width of the button might have changed, the parent browser | 170 // Because the width of the button might have changed, the parent browser |
158 // frame needs to recalculate the button bounds and redraw it. | 171 // frame needs to recalculate the button bounds and redraw it. |
159 parent()->Layout(); | 172 parent()->Layout(); |
160 } | 173 } |
OLD | NEW |