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 29 matching lines...) Expand all Loading... |
40 views::Painter::CreateImageGridPainter(hot_image_set)); | 40 views::Painter::CreateImageGridPainter(hot_image_set)); |
41 border->set_pushed_painter( | 41 border->set_pushed_painter( |
42 views::Painter::CreateImageGridPainter(pushed_image_set)); | 42 views::Painter::CreateImageGridPainter(pushed_image_set)); |
43 | 43 |
44 return border.PassAs<views::Border>(); | 44 return border.PassAs<views::Border>(); |
45 } | 45 } |
46 | 46 |
47 base::string16 GetElidedText(const base::string16& original_text) { | 47 base::string16 GetElidedText(const base::string16& original_text) { |
48 // Maximum characters the button can be before the text will get elided. | 48 // Maximum characters the button can be before the text will get elided. |
49 const int kMaxCharactersToDisplay = 15; | 49 const int kMaxCharactersToDisplay = 15; |
50 | |
51 const gfx::FontList font_list; | 50 const gfx::FontList font_list; |
52 return gfx::ElideText( | 51 return gfx::ElideText(original_text, font_list, |
53 original_text, | 52 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), |
54 font_list, | 53 gfx::ELIDE_TAIL); |
55 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), | |
56 gfx::ELIDE_AT_END); | |
57 } | 54 } |
58 | 55 |
59 base::string16 GetButtonText(Profile* profile) { | 56 base::string16 GetButtonText(Profile* profile) { |
60 base::string16 name = GetElidedText( | 57 base::string16 name = GetElidedText( |
61 profiles::GetAvatarNameForProfile(profile)); | 58 profiles::GetAvatarNameForProfile(profile)); |
62 if (profile->IsManaged()) | 59 if (profile->IsManaged()) |
63 name = l10n_util::GetStringFUTF16(IDS_MANAGED_USER_NEW_AVATAR_LABEL, name); | 60 name = l10n_util::GetStringFUTF16(IDS_MANAGED_USER_NEW_AVATAR_LABEL, name); |
64 return name; | 61 return name; |
65 } | 62 } |
66 | 63 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { | 180 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { |
184 // We want the button to resize if the new text is shorter. | 181 // We want the button to resize if the new text is shorter. |
185 SetText(GetButtonText(browser_->profile())); | 182 SetText(GetButtonText(browser_->profile())); |
186 ClearMaxTextSize(); | 183 ClearMaxTextSize(); |
187 | 184 |
188 // Because the width of the button might have changed, the parent browser | 185 // Because the width of the button might have changed, the parent browser |
189 // frame needs to recalculate the button bounds and redraw it. | 186 // frame needs to recalculate the button bounds and redraw it. |
190 if (parent()) | 187 if (parent()) |
191 parent()->Layout(); | 188 parent()->Layout(); |
192 } | 189 } |
OLD | NEW |