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

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: Extract separate CLs, fix new avatar button 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..a22f32de832341465d3e4a754bc57b38c6af770b 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,27 +102,30 @@ 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) {
+ gfx::Rect rect = GetTextBounds();
+ rect.Offset(0, -3);
noms (inactive) 2014/05/16 13:37:04 This change gets my spider senses tingly. Does it
Roger Tawa OOO till Jul 10th 2014/05/16 19:43:49 Oops, I thought GetTextBounds() handled it, but do
canvas->DrawStringRectWithHalo(
text(),
gfx::FontList(),
@@ -127,9 +133,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,6 +151,22 @@ 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);
noms (inactive) 2014/05/16 13:37:04 Should you maybe just move the icon bit in the if
Roger Tawa OOO till Jul 10th 2014/05/16 19:43:49 Nope. In case there is no longer an error, I want
+ UpdateAvatarButtonAndRelayoutParent();
+}
+
void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
// We want the button to resize if the new text is shorter.
ClearMaxTextSize();
@@ -156,5 +175,6 @@ void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
// 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())
noms (inactive) 2014/05/16 13:37:04 Can parent() ever even return null?
Roger Tawa OOO till Jul 10th 2014/05/16 19:43:49 Yup, when called from OnErrorChanged() when this l
+ parent()->Layout();
}

Powered by Google App Engine
This is Rietveld 408576698