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

Side by Side Diff: chrome/browser/ui/views/profiles/new_avatar_button.cc

Issue 297143008: [Win] UI fixes for the new avatar button/bubble auth errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: msw nits Created 6 years, 6 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/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/win/windows_version.h" 8 #include "base/win/windows_version.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/profiles/profiles_state.h" 11 #include "chrome/browser/profiles/profiles_state.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "components/signin/core/browser/profile_oauth2_token_service.h" 14 #include "components/signin/core/browser/profile_oauth2_token_service.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
21 #include "ui/gfx/font_list.h" 21 #include "ui/gfx/font_list.h"
22 #include "ui/gfx/text_constants.h" 22 #include "ui/gfx/text_constants.h"
23 #include "ui/gfx/text_elider.h" 23 #include "ui/gfx/text_elider.h"
24 #include "ui/views/border.h" 24 #include "ui/views/border.h"
25 #include "ui/views/controls/button/label_button_border.h" 25 #include "ui/views/controls/button/label_button_border.h"
26 #include "ui/views/painter.h" 26 #include "ui/views/painter.h"
27 27
28 namespace { 28 namespace {
29 29
30 // Text padding within the button border.
31 const int kLeftRightInset = 7;
32 const int kTopBottomInset = 2;
33
34 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], 30 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[],
35 const int hot_image_set[], 31 const int hot_image_set[],
36 const int pushed_image_set[]) { 32 const int pushed_image_set[]) {
37 scoped_ptr<views::LabelButtonBorder> border( 33 scoped_ptr<views::LabelButtonBorder> border(
38 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); 34 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON));
39
40 border->SetPainter(false, views::Button::STATE_NORMAL, 35 border->SetPainter(false, views::Button::STATE_NORMAL,
41 views::Painter::CreateImageGridPainter(normal_image_set)); 36 views::Painter::CreateImageGridPainter(normal_image_set));
42 border->SetPainter(false, views::Button::STATE_HOVERED, 37 border->SetPainter(false, views::Button::STATE_HOVERED,
43 views::Painter::CreateImageGridPainter(hot_image_set)); 38 views::Painter::CreateImageGridPainter(hot_image_set));
44 border->SetPainter(false, views::Button::STATE_PRESSED, 39 border->SetPainter(false, views::Button::STATE_PRESSED,
45 views::Painter::CreateImageGridPainter(pushed_image_set)); 40 views::Painter::CreateImageGridPainter(pushed_image_set));
46 41
47 border->set_insets(gfx::Insets(kTopBottomInset, kLeftRightInset, 42 const int kLeftRightInset = 10;
48 kTopBottomInset, kLeftRightInset)); 43 const int kTopInset = 0;
44 const int kBottomInset = 4;
45 border->set_insets(gfx::Insets(kTopInset, kLeftRightInset,
46 kBottomInset, kLeftRightInset));
49 47
50 return border.PassAs<views::Border>(); 48 return border.PassAs<views::Border>();
51 } 49 }
52 50
53 base::string16 GetElidedText(const base::string16& original_text) { 51 base::string16 GetElidedText(const base::string16& original_text) {
54 // Maximum characters the button can be before the text will get elided. 52 // Maximum characters the button can be before the text will get elided.
55 const int kMaxCharactersToDisplay = 15; 53 const int kMaxCharactersToDisplay = 15;
56 const gfx::FontList font_list; 54 const gfx::FontList font_list;
57 return gfx::ElideText(original_text, font_list, 55 return gfx::ElideText(original_text, font_list,
58 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), 56 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay),
(...skipping 29 matching lines...) Expand all
88 bool is_win8 = false; 86 bool is_win8 = false;
89 #if defined(OS_WIN) 87 #if defined(OS_WIN)
90 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; 88 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8;
91 #endif 89 #endif
92 90
93 if (button_style == THEMED_BUTTON) { 91 if (button_style == THEMED_BUTTON) {
94 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); 92 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
95 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); 93 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
96 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); 94 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
97 95
98 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 96 SetBorder(
97 CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
msw 2014/06/19 16:04:19 Nit: revert these spacing changes.
noms (inactive) 2014/06/19 17:04:01 Done.
99 set_menu_marker( 98 set_menu_marker(
100 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); 99 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia());
101 } else if (is_win8) { 100 } else if (is_win8) {
102 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); 101 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL);
103 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER); 102 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER);
104 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); 103 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED);
105 104
106 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 105 SetBorder(
106 CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
107 set_menu_marker( 107 set_menu_marker(
108 rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia()); 108 rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia());
109 } else { 109 } else {
110 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); 110 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
111 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); 111 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
112 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); 112 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
113 113
114 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 114 SetBorder(
115 CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
115 set_menu_marker( 116 set_menu_marker(
116 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); 117 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
117 } 118 }
118 119
119 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); 120 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
120 121
121 // Subscribe to authentication error changes so that the avatar button 122 // Subscribe to authentication error changes so that the avatar button
122 // can update itself. Note that guest mode profiles won't have a token 123 // can update itself. Note that guest mode profiles won't have a token
123 // service. 124 // service.
124 SigninErrorController* error = 125 SigninErrorController* error =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 UpdateAvatarButtonAndRelayoutParent(); 157 UpdateAvatarButtonAndRelayoutParent();
157 } 158 }
158 159
159 void NewAvatarButton::OnErrorChanged() { 160 void NewAvatarButton::OnErrorChanged() {
160 gfx::ImageSkia icon; 161 gfx::ImageSkia icon;
161 162
162 // If there is an error, show an warning icon. 163 // If there is an error, show an warning icon.
163 const SigninErrorController* error = 164 const SigninErrorController* error =
164 profiles::GetSigninErrorController(browser_->profile()); 165 profiles::GetSigninErrorController(browser_->profile());
165 if (error && error->HasError()) { 166 if (error && error->HasError()) {
166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 167 icon = *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
167 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); 168 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia();
168 } 169 }
169 170
170 SetImage(views::Button::STATE_NORMAL, icon); 171 SetImage(views::Button::STATE_NORMAL, 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(GetButtonText(browser_->profile())); 177 SetText(GetButtonText(browser_->profile()));
177 set_min_size(gfx::Size()); 178 set_min_size(gfx::Size());
178 InvalidateLayout(); 179 InvalidateLayout();
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 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/glass_browser_frame_view.cc ('k') | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698