Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: chrome/browser/ui/views/profiles/new_avatar_button.cc

Issue 240453006: Fix sign-in error strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 239255a6cba156328d3ef3030d24ca5ba8292653..ec28c46d12f6bfd6ecc1366fa9ca58afb44a29c7 100644
--- a/chrome/browser/ui/views/profiles/new_avatar_button.cc
+++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc
@@ -8,7 +8,9 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/ui/browser.h"
+#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -64,6 +66,7 @@ NewAvatarButton::NewAvatarButton(
: MenuButton(listener, GetElidedText(profile_name), NULL, true),
browser_(browser) {
set_animate_on_state_change(false);
+ set_icon_placement(ICON_ON_RIGHT);
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
@@ -99,26 +102,33 @@ NewAvatarButton::NewAvatarButton(
}
g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
+
+ // Subscribe to authentication error changes so that the avatar button
+ // can update itself.
+ SigninErrorController* error =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
+ signin_error_controller();
+ error->AddObserver(this);
+ OnErrorChanged();
+
SchedulePaint();
}
NewAvatarButton::~NewAvatarButton() {
g_browser_process->profile_manager()->
GetProfileInfoCache().RemoveObserver(this);
+ SigninErrorController* error =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
+ signin_error_controller();
+ error->RemoveObserver(this);
}
-void NewAvatarButton::OnPaint(gfx::Canvas* canvas) {
- // From TextButton::PaintButton, draw everything but the text.
- OnPaintBackground(canvas);
- OnPaintBorder(canvas);
- views::Painter::PaintFocusPainter(this, canvas, focus_painter());
-
- gfx::Rect rect;
- // In RTL languages the marker gets drawn leftmost, so account for its offset.
- if (base::i18n::IsRTL())
- rect = gfx::Rect(-kInset, 0, size().width(), size().height());
- else
- rect = gfx::Rect(kInset, 0, size().width(), size().height());
+void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) {
+ // Get text bounds, and then adjust for the top and RTL languages.
+ gfx::Rect rect = GetTextBounds();
+ rect.Offset(0, -rect.y());
+ if (rect.width() > 0)
+ rect.set_x(GetMirroredXForRect(rect));
canvas->DrawStringRectWithHalo(
text(),
@@ -127,9 +137,6 @@ void NewAvatarButton::OnPaint(gfx::Canvas* canvas) {
SK_ColorDKGRAY,
rect,
gfx::Canvas::NO_SUBPIXEL_RENDERING);
-
- // From MenuButton::PaintButton, paint the marker
- PaintMenuMarker(canvas);
}
void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) {
@@ -148,13 +155,30 @@ void NewAvatarButton::OnProfileNameChanged(
UpdateAvatarButtonAndRelayoutParent();
}
+void NewAvatarButton::OnErrorChanged() {
+ gfx::ImageSkia icon;
+
+ // If there is an error, show an warning icon.
+ SigninErrorController* error =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
+ signin_error_controller();
+ if (error->HasError()) {
+ ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
+ icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia();
+ }
+
+ SetIcon(icon);
+ UpdateAvatarButtonAndRelayoutParent();
+}
+
void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
// We want the button to resize if the new text is shorter.
- ClearMaxTextSize();
SetText(GetElidedText(
profiles::GetAvatarNameForProfile(browser_->profile())));
+ ClearMaxTextSize();
// Because the width of the button might have changed, the parent browser
// frame needs to recalculate the button bounds and redraw it.
- parent()->Layout();
+ if (parent())
+ parent()->Layout();
}
« no previous file with comments | « chrome/browser/ui/views/profiles/new_avatar_button.h ('k') | chrome/browser/ui/views/profiles/profile_chooser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698