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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 AvatarButtonStyle button_style, | 46 AvatarButtonStyle button_style, |
47 Browser* browser) | 47 Browser* browser) |
48 : LabelButton(listener, base::string16()), | 48 : LabelButton(listener, base::string16()), |
49 browser_(browser), | 49 browser_(browser), |
50 has_auth_error_(false), | 50 has_auth_error_(false), |
51 suppress_mouse_released_action_(false) { | 51 suppress_mouse_released_action_(false) { |
52 set_animate_on_state_change(false); | 52 set_animate_on_state_change(false); |
53 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); | 53 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); |
54 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); | 54 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); |
55 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); | 55 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); |
56 SetTextShadows(gfx::ShadowValues(10, | |
57 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); | |
58 SetTextSubpixelRenderingEnabled(false); | 56 SetTextSubpixelRenderingEnabled(false); |
59 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 57 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
60 | 58 |
61 // The largest text height that fits in the button. If the font list height | 59 // The largest text height that fits in the button. If the font list height |
62 // is larger than this, it will be shrunk to match it. | 60 // is larger than this, it will be shrunk to match it. |
63 // TODO(noms): Calculate this constant algorithmically. | 61 // TODO(noms): Calculate this constant algorithmically. |
64 const int kDisplayFontHeight = 15; | 62 const int kDisplayFontHeight = 15; |
65 SetFontList(GetFontList().DeriveWithHeightUpperBound(kDisplayFontHeight)); | 63 SetFontList(GetFontList().DeriveWithHeightUpperBound(kDisplayFontHeight)); |
66 | 64 |
67 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 65 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
68 if (button_style == THEMED_BUTTON) { | 66 if (button_style == THEMED_BUTTON) { |
69 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | 67 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); |
70 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | 68 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); |
71 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | 69 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); |
72 | 70 |
73 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 71 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
74 generic_avatar_ = | 72 generic_avatar_ = |
75 *rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_AVATAR).ToImageSkia(); | 73 *rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_AVATAR).ToImageSkia(); |
76 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
77 } else if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 75 } else if (base::win::GetVersion() >= base::win::VERSION_WIN8 || |
| 76 browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) { |
78 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); | 77 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); |
79 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER); | 78 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER); |
80 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); | 79 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); |
81 | 80 |
82 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 81 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
83 generic_avatar_ = | 82 generic_avatar_ = |
84 *rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_AVATAR).ToImageSkia(); | 83 *rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_AVATAR).ToImageSkia(); |
85 #endif | 84 #endif |
86 } else { | 85 } else { |
87 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); | 86 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 177 |
179 // If we have a single local profile, then use the generic avatar | 178 // If we have a single local profile, then use the generic avatar |
180 // button instead of the profile name. Never use the generic button if | 179 // button instead of the profile name. Never use the generic button if |
181 // the active profile is Guest. | 180 // the active profile is Guest. |
182 bool use_generic_button = (!browser_->profile()->IsGuestSession() && | 181 bool use_generic_button = (!browser_->profile()->IsGuestSession() && |
183 cache.GetNumberOfProfiles() == 1 && | 182 cache.GetNumberOfProfiles() == 1 && |
184 cache.GetUserNameOfProfileAtIndex(0).empty()); | 183 cache.GetUserNameOfProfileAtIndex(0).empty()); |
185 | 184 |
186 SetText(use_generic_button ? base::string16() : | 185 SetText(use_generic_button ? base::string16() : |
187 profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 186 profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 187 |
| 188 // If the button has no text, clear the text shadows to make sure the |
| 189 // image is centered correctly. |
| 190 SetTextShadows(use_generic_button ? gfx::ShadowValues() : gfx::ShadowValues( |
| 191 10, gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); |
| 192 |
188 // We want the button to resize if the new text is shorter. | 193 // We want the button to resize if the new text is shorter. |
189 SetMinSize(gfx::Size()); | 194 SetMinSize(gfx::Size()); |
190 | 195 |
191 if (use_generic_button) { | 196 if (use_generic_button) { |
192 SetImage(views::Button::STATE_NORMAL, generic_avatar_); | 197 SetImage(views::Button::STATE_NORMAL, generic_avatar_); |
193 } else if (has_auth_error_) { | 198 } else if (has_auth_error_) { |
194 SetImage(views::Button::STATE_NORMAL, | 199 SetImage(views::Button::STATE_NORMAL, |
195 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 200 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
196 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia()); | 201 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia()); |
197 } else { | 202 } else { |
198 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); | 203 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); |
199 } | 204 } |
200 | 205 |
201 // If we are not using the generic button, then reset the spacing between | 206 // If we are not using the generic button, then reset the spacing between |
202 // the text and the possible authentication error icon. | 207 // the text and the possible authentication error icon. |
203 const int kDefaultImageTextSpacing = 5; | 208 const int kDefaultImageTextSpacing = 5; |
204 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); | 209 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); |
205 | 210 |
206 InvalidateLayout(); | 211 InvalidateLayout(); |
207 | 212 |
208 // Because the width of the button might have changed, the parent browser | 213 // Because the width of the button might have changed, the parent browser |
209 // frame needs to recalculate the button bounds and redraw it. | 214 // frame needs to recalculate the button bounds and redraw it. |
210 if (parent()) | 215 if (parent()) |
211 parent()->Layout(); | 216 parent()->Layout(); |
212 } | 217 } |
OLD | NEW |