Index: chrome/browser/ui/views/profiles/new_avatar_button.cc |
diff --git a/chrome/browser/ui/views/profiles/new_avatar_button.cc b/chrome/browser/ui/views/profiles/new_avatar_button.cc |
index 2e3647c1048c58ac38e75dc08ce4293267778971..ef9a22e881866175d7589541922576cff5190f85 100644 |
--- a/chrome/browser/ui/views/profiles/new_avatar_button.cc |
+++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc |
@@ -31,8 +31,8 @@ scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], |
border->SetPainter(false, views::Button::STATE_PRESSED, |
views::Painter::CreateImageGridPainter(pushed_image_set)); |
- const int kLeftRightInset = 10; |
- const int kTopInset = 0; |
+ const int kLeftRightInset = 8; |
+ const int kTopInset = 2; |
const int kBottomInset = 4; |
border->set_insets(gfx::Insets(kTopInset, kLeftRightInset, |
kBottomInset, kLeftRightInset)); |
@@ -42,16 +42,12 @@ scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], |
} // namespace |
-NewAvatarButton::NewAvatarButton( |
- views::ButtonListener* listener, |
- const base::string16& profile_name, |
- AvatarButtonStyle button_style, |
- Browser* browser) |
- : MenuButton(listener, |
- profiles::GetAvatarButtonTextForProfile(browser->profile()), |
- NULL, |
- true), |
+NewAvatarButton::NewAvatarButton(views::ButtonListener* listener, |
+ AvatarButtonStyle button_style, |
+ Browser* browser) |
+ : LabelButton(listener, base::string16()), |
browser_(browser), |
+ has_auth_error_(false), |
suppress_mouse_released_action_(false) { |
set_animate_on_state_change(false); |
SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); |
@@ -60,6 +56,7 @@ NewAvatarButton::NewAvatarButton( |
SetTextShadows(gfx::ShadowValues(10, |
gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); |
SetTextSubpixelRenderingEnabled(false); |
+ SetHorizontalAlignment(gfx::ALIGN_CENTER); |
// The largest text height that fits in the button. If the font list height |
// is larger than this, it will be shrunk to match it. |
@@ -74,8 +71,8 @@ NewAvatarButton::NewAvatarButton( |
const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); |
SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
- set_menu_marker( |
- rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); |
+ generic_avatar_ = |
+ *rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_AVATAR).ToImageSkia(); |
#if defined(OS_WIN) |
} else if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); |
@@ -83,8 +80,8 @@ NewAvatarButton::NewAvatarButton( |
const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); |
SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
- set_menu_marker( |
- rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia()); |
+ generic_avatar_ = |
+ *rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_AVATAR).ToImageSkia(); |
#endif |
} else { |
const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); |
@@ -92,8 +89,8 @@ NewAvatarButton::NewAvatarButton( |
const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); |
SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
- set_menu_marker( |
- rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); |
+ generic_avatar_ = |
+ *rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_AVATAR).ToImageSkia(); |
} |
g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
@@ -104,9 +101,11 @@ NewAvatarButton::NewAvatarButton( |
profiles::GetSigninErrorController(browser_->profile()); |
if (error) { |
error->AddObserver(this); |
+ // This calls UpdateAvatarButtonAndRelayoutParent(). |
OnErrorChanged(); |
+ } else { |
+ UpdateAvatarButtonAndRelayoutParent(); |
} |
- |
SchedulePaint(); |
} |
@@ -122,14 +121,14 @@ NewAvatarButton::~NewAvatarButton() { |
bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { |
// Prevent the bubble from being re-shown if it's already showing. |
suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); |
- return MenuButton::OnMousePressed(event); |
+ return LabelButton::OnMousePressed(event); |
} |
void NewAvatarButton::OnMouseReleased(const ui::MouseEvent& event) { |
if (suppress_mouse_released_action_) |
suppress_mouse_released_action_ = false; |
else |
- MenuButton::OnMouseReleased(event); |
+ LabelButton::OnMouseReleased(event); |
} |
void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { |
@@ -159,24 +158,45 @@ void NewAvatarButton::OnProfileSupervisedUserIdChanged( |
} |
void NewAvatarButton::OnErrorChanged() { |
- gfx::ImageSkia icon; |
- |
// If there is an error, show an warning icon. |
const SigninErrorController* error = |
profiles::GetSigninErrorController(browser_->profile()); |
- if (error && error->HasError()) { |
- icon = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
- IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia(); |
- } |
+ has_auth_error_ = error && error->HasError(); |
- SetImage(views::Button::STATE_NORMAL, icon); |
UpdateAvatarButtonAndRelayoutParent(); |
} |
void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { |
+ const ProfileInfoCache& cache = |
+ g_browser_process->profile_manager()->GetProfileInfoCache(); |
+ |
+ // If we have a single local profile, then use the generic avatar |
+ // button instead of the profile name. Never use the generic button if |
+ // the active profile is Guest. |
+ bool use_generic_button = (!browser_->profile()->IsGuestSession() && |
+ cache.GetNumberOfProfiles() == 1 && |
+ cache.GetUserNameOfProfileAtIndex(0).empty()); |
+ |
+ SetText(use_generic_button ? base::string16() : |
+ profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
// We want the button to resize if the new text is shorter. |
- SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
SetMinSize(gfx::Size()); |
+ |
+ if (use_generic_button) { |
+ SetImage(views::Button::STATE_NORMAL, generic_avatar_); |
+ } else if (has_auth_error_) { |
+ SetImage(views::Button::STATE_NORMAL, |
+ *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia()); |
+ } else { |
+ SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); |
+ } |
+ |
+ // If we are not using the generic button, then reset the spacing between |
+ // the text and the possible authentication error icon. |
+ const int kDefaultImageTextSpacing = 5; |
+ SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); |
+ |
InvalidateLayout(); |
// Because the width of the button might have changed, the parent browser |