| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); | 97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); |
| 98 | 98 |
| 99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
| 100 set_menu_marker( | 100 set_menu_marker( |
| 101 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); | 101 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 104 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
| 105 | 105 |
| 106 // Subscribe to authentication error changes so that the avatar button | 106 // Subscribe to authentication error changes so that the avatar button |
| 107 // can update itself. | 107 // can update itself. Note that guest mode profiles won't have a token |
| 108 // service. |
| 108 SigninErrorController* error = | 109 SigninErrorController* error = |
| 109 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> | 110 profiles::GetSigninErrorController(browser_->profile()); |
| 110 signin_error_controller(); | 111 if (error) { |
| 111 error->AddObserver(this); | 112 error->AddObserver(this); |
| 112 OnErrorChanged(); | 113 OnErrorChanged(); |
| 114 } |
| 113 | 115 |
| 114 SchedulePaint(); | 116 SchedulePaint(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 NewAvatarButton::~NewAvatarButton() { | 119 NewAvatarButton::~NewAvatarButton() { |
| 118 g_browser_process->profile_manager()-> | 120 g_browser_process->profile_manager()-> |
| 119 GetProfileInfoCache().RemoveObserver(this); | 121 GetProfileInfoCache().RemoveObserver(this); |
| 120 SigninErrorController* error = | 122 SigninErrorController* error = |
| 121 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> | 123 profiles::GetSigninErrorController(browser_->profile()); |
| 122 signin_error_controller(); | 124 if (error) |
| 123 error->RemoveObserver(this); | 125 error->RemoveObserver(this); |
| 124 } | 126 } |
| 125 | 127 |
| 126 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) { | 128 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 127 // Get text bounds, and then adjust for the top and RTL languages. | 129 // Get text bounds, and then adjust for the top and RTL languages. |
| 128 gfx::Rect rect = GetTextBounds(); | 130 gfx::Rect rect = GetTextBounds(); |
| 129 rect.Offset(0, -rect.y()); | 131 rect.Offset(0, -rect.y()); |
| 130 if (rect.width() > 0) | 132 if (rect.width() > 0) |
| 131 rect.set_x(GetMirroredXForRect(rect)); | 133 rect.set_x(GetMirroredXForRect(rect)); |
| 132 | 134 |
| 133 canvas->DrawStringRectWithHalo( | 135 canvas->DrawStringRectWithHalo( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 152 void NewAvatarButton::OnProfileNameChanged( | 154 void NewAvatarButton::OnProfileNameChanged( |
| 153 const base::FilePath& profile_path, | 155 const base::FilePath& profile_path, |
| 154 const base::string16& old_profile_name) { | 156 const base::string16& old_profile_name) { |
| 155 UpdateAvatarButtonAndRelayoutParent(); | 157 UpdateAvatarButtonAndRelayoutParent(); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void NewAvatarButton::OnErrorChanged() { | 160 void NewAvatarButton::OnErrorChanged() { |
| 159 gfx::ImageSkia icon; | 161 gfx::ImageSkia icon; |
| 160 | 162 |
| 161 // If there is an error, show an warning icon. | 163 // If there is an error, show an warning icon. |
| 162 SigninErrorController* error = | 164 const SigninErrorController* error = |
| 163 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> | 165 profiles::GetSigninErrorController(browser_->profile()); |
| 164 signin_error_controller(); | 166 if (error && error->HasError()) { |
| 165 if (error->HasError()) { | |
| 166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 167 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 167 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); | 168 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 SetIcon(icon); | 171 SetIcon(icon); |
| 171 UpdateAvatarButtonAndRelayoutParent(); | 172 UpdateAvatarButtonAndRelayoutParent(); |
| 172 } | 173 } |
| 173 | 174 |
| 174 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { | 175 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { |
| 175 // We want the button to resize if the new text is shorter. | 176 // We want the button to resize if the new text is shorter. |
| 176 SetText(GetElidedText( | 177 SetText(GetElidedText( |
| 177 profiles::GetAvatarNameForProfile(browser_->profile()))); | 178 profiles::GetAvatarNameForProfile(browser_->profile()))); |
| 178 ClearMaxTextSize(); | 179 ClearMaxTextSize(); |
| 179 | 180 |
| 180 // Because the width of the button might have changed, the parent browser | 181 // Because the width of the button might have changed, the parent browser |
| 181 // frame needs to recalculate the button bounds and redraw it. | 182 // frame needs to recalculate the button bounds and redraw it. |
| 182 if (parent()) | 183 if (parent()) |
| 183 parent()->Layout(); | 184 parent()->Layout(); |
| 184 } | 185 } |
| OLD | NEW |