Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile_attributes_entry.h" | |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/profiles/profiles_state.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 16 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
| 16 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 19 #include "ui/gfx/color_palette.h" | 20 #include "ui/gfx/color_palette.h" |
| 20 #include "ui/gfx/geometry/vector2d.h" | 21 #include "ui/gfx/geometry/vector2d.h" |
| 21 #include "ui/gfx/paint_vector_icon.h" | 22 #include "ui/gfx/paint_vector_icon.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 } else { | 94 } else { |
| 94 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); | 95 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); |
| 95 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER); | 96 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER); |
| 96 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED); | 97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED); |
| 97 | 98 |
| 98 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
| 99 generic_avatar_ = | 100 generic_avatar_ = |
| 100 *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia(); | 101 *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 104 g_browser_process->profile_manager()-> |
| 105 GetProfileAttributesStorage().AddObserver(this); | |
| 104 | 106 |
| 105 // Subscribe to authentication error changes so that the avatar button can | 107 // Subscribe to authentication error changes so that the avatar button can |
| 106 // update itself. Note that guest mode profiles won't have a token service. | 108 // update itself. Note that guest mode profiles won't have a token service. |
| 107 SigninErrorController* error = | 109 SigninErrorController* error = |
| 108 profiles::GetSigninErrorController(browser_->profile()); | 110 profiles::GetSigninErrorController(browser_->profile()); |
| 109 if (error) { | 111 if (error) { |
| 110 error->AddObserver(this); | 112 error->AddObserver(this); |
| 111 OnErrorChanged(); // This calls Update(). | 113 OnErrorChanged(); // This calls Update(). |
| 112 } else { | 114 } else { |
| 113 Update(); | 115 Update(); |
| 114 } | 116 } |
| 115 SchedulePaint(); | 117 SchedulePaint(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 NewAvatarButton::~NewAvatarButton() { | 120 NewAvatarButton::~NewAvatarButton() { |
| 119 g_browser_process->profile_manager()-> | 121 g_browser_process->profile_manager()-> |
| 120 GetProfileInfoCache().RemoveObserver(this); | 122 GetProfileAttributesStorage().RemoveObserver(this); |
| 121 SigninErrorController* error = | 123 SigninErrorController* error = |
| 122 profiles::GetSigninErrorController(browser_->profile()); | 124 profiles::GetSigninErrorController(browser_->profile()); |
| 123 if (error) | 125 if (error) |
| 124 error->RemoveObserver(this); | 126 error->RemoveObserver(this); |
| 125 } | 127 } |
| 126 | 128 |
| 127 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { | 129 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { |
| 128 // Prevent the bubble from being re-shown if it's already showing. | 130 // Prevent the bubble from being re-shown if it's already showing. |
| 129 suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); | 131 suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); |
| 130 return LabelButton::OnMousePressed(event); | 132 return LabelButton::OnMousePressed(event); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 void NewAvatarButton::OnErrorChanged() { | 179 void NewAvatarButton::OnErrorChanged() { |
| 178 // If there is an error, show an warning icon. | 180 // If there is an error, show an warning icon. |
| 179 const SigninErrorController* error = | 181 const SigninErrorController* error = |
| 180 profiles::GetSigninErrorController(browser_->profile()); | 182 profiles::GetSigninErrorController(browser_->profile()); |
| 181 has_auth_error_ = error && error->HasError(); | 183 has_auth_error_ = error && error->HasError(); |
| 182 | 184 |
| 183 Update(); | 185 Update(); |
| 184 } | 186 } |
| 185 | 187 |
| 186 void NewAvatarButton::Update() { | 188 void NewAvatarButton::Update() { |
| 187 const ProfileInfoCache& cache = | 189 ProfileAttributesStorage& storage = |
| 188 g_browser_process->profile_manager()->GetProfileInfoCache(); | 190 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 189 | 191 |
| 190 // If we have a single local profile, then use the generic avatar | 192 // If we have a single local profile, then use the generic avatar |
| 191 // button instead of the profile name. Never use the generic button if | 193 // button instead of the profile name. Never use the generic button if |
| 192 // the active profile is Guest. | 194 // the active profile is Guest. |
| 193 bool use_generic_button = (!browser_->profile()->IsGuestSession() && | 195 bool use_generic_button = (!browser_->profile()->IsGuestSession() && |
|
Peter Kasting
2016/02/16 20:49:54
Wrapping/indenting here is now strange
lwchkg
2016/02/17 17:09:31
I see. Let's see if the new version (the ! is wrap
Peter Kasting
2016/02/17 22:16:26
Yeah, looks much better.
| |
| 194 cache.GetNumberOfProfiles() == 1 && | 196 storage.GetNumberOfProfiles() == 1 && |
| 195 !cache.ProfileIsAuthenticatedAtIndex(0)); | 197 !(*storage.GetAllProfilesAttributes().begin())->IsAuthenticated()); |
|
lwchkg
2016/02/14 17:07:18
begin() will be changed to cbegin() in the next pa
Peter Kasting
2016/02/16 20:49:54
Nit: Just use front() instead:
!storage.Get
| |
| 196 | 198 |
| 197 SetText(use_generic_button ? base::string16() : | 199 SetText(use_generic_button ? base::string16() : |
| 198 profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 200 profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 199 | 201 |
| 200 // If the button has no text, clear the text shadows to make sure the | 202 // If the button has no text, clear the text shadows to make sure the |
| 201 // image is centered correctly. | 203 // image is centered correctly. |
| 202 SetTextShadows( | 204 SetTextShadows( |
| 203 use_generic_button | 205 use_generic_button |
| 204 ? gfx::ShadowValues() | 206 ? gfx::ShadowValues() |
| 205 : gfx::ShadowValues( | 207 : gfx::ShadowValues( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 218 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); | 220 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); |
| 219 } | 221 } |
| 220 | 222 |
| 221 // If we are not using the generic button, then reset the spacing between | 223 // If we are not using the generic button, then reset the spacing between |
| 222 // the text and the possible authentication error icon. | 224 // the text and the possible authentication error icon. |
| 223 const int kDefaultImageTextSpacing = 5; | 225 const int kDefaultImageTextSpacing = 5; |
| 224 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); | 226 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); |
| 225 | 227 |
| 226 PreferredSizeChanged(); | 228 PreferredSizeChanged(); |
| 227 } | 229 } |
| OLD | NEW |