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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "components/signin/core/browser/profile_oauth2_token_service.h"
12 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/color_utils.h" 19 #include "ui/gfx/color_utils.h"
18 #include "ui/gfx/font_list.h" 20 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/text_elider.h" 21 #include "ui/gfx/text_elider.h"
20 #include "ui/views/border.h" 22 #include "ui/views/border.h"
21 #include "ui/views/painter.h" 23 #include "ui/views/painter.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } // namespace 59 } // namespace
58 60
59 NewAvatarButton::NewAvatarButton( 61 NewAvatarButton::NewAvatarButton(
60 views::ButtonListener* listener, 62 views::ButtonListener* listener,
61 const base::string16& profile_name, 63 const base::string16& profile_name,
62 AvatarButtonStyle button_style, 64 AvatarButtonStyle button_style,
63 Browser* browser) 65 Browser* browser)
64 : MenuButton(listener, GetElidedText(profile_name), NULL, true), 66 : MenuButton(listener, GetElidedText(profile_name), NULL, true),
65 browser_(browser) { 67 browser_(browser) {
66 set_animate_on_state_change(false); 68 set_animate_on_state_change(false);
69 set_icon_placement(ICON_ON_RIGHT);
67 70
68 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 71 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
69 72
70 bool is_win8 = false; 73 bool is_win8 = false;
71 #if defined(OS_WIN) 74 #if defined(OS_WIN)
72 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; 75 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8;
73 #endif 76 #endif
74 77
75 if (button_style == THEMED_BUTTON) { 78 if (button_style == THEMED_BUTTON) {
76 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); 79 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
(...skipping 15 matching lines...) Expand all
92 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); 95 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
93 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); 96 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
94 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); 97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
95 98
96 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
97 set_menu_marker( 100 set_menu_marker(
98 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); 101 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
99 } 102 }
100 103
101 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); 104 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
105
106 // Subscribe to authentication error changes so that the avatar button
107 // can update itself.
108 SigninErrorController* error =
109 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
110 signin_error_controller();
111 error->AddObserver(this);
112 OnErrorChanged();
113
102 SchedulePaint(); 114 SchedulePaint();
103 } 115 }
104 116
105 NewAvatarButton::~NewAvatarButton() { 117 NewAvatarButton::~NewAvatarButton() {
106 g_browser_process->profile_manager()-> 118 g_browser_process->profile_manager()->
107 GetProfileInfoCache().RemoveObserver(this); 119 GetProfileInfoCache().RemoveObserver(this);
120 SigninErrorController* error =
121 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
122 signin_error_controller();
123 error->RemoveObserver(this);
108 } 124 }
109 125
110 void NewAvatarButton::OnPaint(gfx::Canvas* canvas) { 126 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) {
111 // From TextButton::PaintButton, draw everything but the text. 127 gfx::Rect rect = GetTextBounds();
112 OnPaintBackground(canvas); 128 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
113 OnPaintBorder(canvas);
114 views::Painter::PaintFocusPainter(this, canvas, focus_painter());
115
116 gfx::Rect rect;
117 // In RTL languages the marker gets drawn leftmost, so account for its offset.
118 if (base::i18n::IsRTL())
119 rect = gfx::Rect(-kInset, 0, size().width(), size().height());
120 else
121 rect = gfx::Rect(kInset, 0, size().width(), size().height());
122
123 canvas->DrawStringRectWithHalo( 129 canvas->DrawStringRectWithHalo(
124 text(), 130 text(),
125 gfx::FontList(), 131 gfx::FontList(),
126 SK_ColorWHITE, 132 SK_ColorWHITE,
127 SK_ColorDKGRAY, 133 SK_ColorDKGRAY,
128 rect, 134 rect,
129 gfx::Canvas::NO_SUBPIXEL_RENDERING); 135 gfx::Canvas::NO_SUBPIXEL_RENDERING);
130
131 // From MenuButton::PaintButton, paint the marker
132 PaintMenuMarker(canvas);
133 } 136 }
134 137
135 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { 138 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) {
136 UpdateAvatarButtonAndRelayoutParent(); 139 UpdateAvatarButtonAndRelayoutParent();
137 } 140 }
138 141
139 void NewAvatarButton::OnProfileWasRemoved( 142 void NewAvatarButton::OnProfileWasRemoved(
140 const base::FilePath& profile_path, 143 const base::FilePath& profile_path,
141 const base::string16& profile_name) { 144 const base::string16& profile_name) {
142 UpdateAvatarButtonAndRelayoutParent(); 145 UpdateAvatarButtonAndRelayoutParent();
143 } 146 }
144 147
145 void NewAvatarButton::OnProfileNameChanged( 148 void NewAvatarButton::OnProfileNameChanged(
146 const base::FilePath& profile_path, 149 const base::FilePath& profile_path,
147 const base::string16& old_profile_name) { 150 const base::string16& old_profile_name) {
148 UpdateAvatarButtonAndRelayoutParent(); 151 UpdateAvatarButtonAndRelayoutParent();
149 } 152 }
150 153
154 void NewAvatarButton::OnErrorChanged() {
155 gfx::ImageSkia icon;
156
157 // If there is an error, show an warning icon.
158 SigninErrorController* error =
159 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
160 signin_error_controller();
161 if (error->HasError()) {
162 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
163 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia();
164 }
165
166 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
167 UpdateAvatarButtonAndRelayoutParent();
168 }
169
151 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { 170 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
152 // We want the button to resize if the new text is shorter. 171 // We want the button to resize if the new text is shorter.
153 ClearMaxTextSize(); 172 ClearMaxTextSize();
154 SetText(GetElidedText( 173 SetText(GetElidedText(
155 profiles::GetAvatarNameForProfile(browser_->profile()))); 174 profiles::GetAvatarNameForProfile(browser_->profile())));
156 175
157 // Because the width of the button might have changed, the parent browser 176 // Because the width of the button might have changed, the parent browser
158 // frame needs to recalculate the button bounds and redraw it. 177 // frame needs to recalculate the button bounds and redraw it.
159 parent()->Layout(); 178 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
179 parent()->Layout();
160 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698