| 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" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 12 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
| 13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/geometry/vector2d.h" |
| 16 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
| 17 #include "ui/views/controls/button/label_button_border.h" | 18 #include "ui/views/controls/button/label_button_border.h" |
| 18 #include "ui/views/painter.h" | 19 #include "ui/views/painter.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], | 23 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], |
| 23 const int hot_image_set[], | 24 const int hot_image_set[], |
| 24 const int pushed_image_set[]) { | 25 const int pushed_image_set[]) { |
| 25 scoped_ptr<views::LabelButtonBorder> border( | 26 scoped_ptr<views::LabelButtonBorder> border( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // the active profile is Guest. | 177 // the active profile is Guest. |
| 177 bool use_generic_button = (!browser_->profile()->IsGuestSession() && | 178 bool use_generic_button = (!browser_->profile()->IsGuestSession() && |
| 178 cache.GetNumberOfProfiles() == 1 && | 179 cache.GetNumberOfProfiles() == 1 && |
| 179 cache.GetUserNameOfProfileAtIndex(0).empty()); | 180 cache.GetUserNameOfProfileAtIndex(0).empty()); |
| 180 | 181 |
| 181 SetText(use_generic_button ? base::string16() : | 182 SetText(use_generic_button ? base::string16() : |
| 182 profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 183 profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 183 | 184 |
| 184 // If the button has no text, clear the text shadows to make sure the | 185 // If the button has no text, clear the text shadows to make sure the |
| 185 // image is centered correctly. | 186 // image is centered correctly. |
| 186 SetTextShadows(use_generic_button ? gfx::ShadowValues() : gfx::ShadowValues( | 187 SetTextShadows( |
| 187 10, gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); | 188 use_generic_button |
| 189 ? gfx::ShadowValues() |
| 190 : gfx::ShadowValues( |
| 191 10, gfx::ShadowValue(gfx::Vector2d(), 1.0f, SK_ColorDKGRAY))); |
| 188 | 192 |
| 189 // 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. |
| 190 SetMinSize(gfx::Size()); | 194 SetMinSize(gfx::Size()); |
| 191 | 195 |
| 192 if (use_generic_button) { | 196 if (use_generic_button) { |
| 193 SetImage(views::Button::STATE_NORMAL, generic_avatar_); | 197 SetImage(views::Button::STATE_NORMAL, generic_avatar_); |
| 194 } else if (has_auth_error_) { | 198 } else if (has_auth_error_) { |
| 195 SetImage(views::Button::STATE_NORMAL, | 199 SetImage(views::Button::STATE_NORMAL, |
| 196 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 200 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 197 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia()); | 201 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia()); |
| 198 } else { | 202 } else { |
| 199 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); | 203 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); |
| 200 } | 204 } |
| 201 | 205 |
| 202 // 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 |
| 203 // the text and the possible authentication error icon. | 207 // the text and the possible authentication error icon. |
| 204 const int kDefaultImageTextSpacing = 5; | 208 const int kDefaultImageTextSpacing = 5; |
| 205 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); | 209 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); |
| 206 | 210 |
| 207 InvalidateLayout(); | 211 InvalidateLayout(); |
| 208 | 212 |
| 209 // 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 |
| 210 // frame needs to recalculate the button bounds and redraw it. | 214 // frame needs to recalculate the button bounds and redraw it. |
| 211 if (parent()) | 215 if (parent()) |
| 212 parent()->Layout(); | 216 parent()->Layout(); |
| 213 } | 217 } |
| OLD | NEW |