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

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

Issue 298813002: views: Move MenuButton from TextButton to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable DragDirectlyToSecondWindow. 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/win/windows_version.h" 8 #include "base/win/windows_version.h"
8 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/profiles/profiles_state.h" 11 #include "chrome/browser/profiles/profiles_state.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "components/signin/core/browser/profile_oauth2_token_service.h" 14 #include "components/signin/core/browser/profile_oauth2_token_service.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
20 #include "ui/gfx/font_list.h" 21 #include "ui/gfx/font_list.h"
22 #include "ui/gfx/text_constants.h"
21 #include "ui/gfx/text_elider.h" 23 #include "ui/gfx/text_elider.h"
22 #include "ui/views/border.h" 24 #include "ui/views/border.h"
25 #include "ui/views/controls/button/label_button_border.h"
23 #include "ui/views/painter.h" 26 #include "ui/views/painter.h"
24 27
25 namespace { 28 namespace {
26 29
27 // Text padding within the button border. 30 // Text padding within the button border.
28 const int kInset = 10; 31 const int kLeftRightInset = 7;
32 const int kTopBottomInset = 2;
29 33
30 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], 34 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[],
31 const int hot_image_set[], 35 const int hot_image_set[],
32 const int pushed_image_set[]) { 36 const int pushed_image_set[]) {
33 scoped_ptr<views::TextButtonDefaultBorder> border( 37 scoped_ptr<views::LabelButtonBorder> border(
34 new views::TextButtonDefaultBorder()); 38 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON));
35 39
36 border->SetInsets(gfx::Insets(kInset, kInset, kInset, kInset)); 40 border->SetPainter(false, views::Button::STATE_NORMAL,
37 border->set_normal_painter(
38 views::Painter::CreateImageGridPainter(normal_image_set)); 41 views::Painter::CreateImageGridPainter(normal_image_set));
39 border->set_hot_painter( 42 border->SetPainter(false, views::Button::STATE_HOVERED,
40 views::Painter::CreateImageGridPainter(hot_image_set)); 43 views::Painter::CreateImageGridPainter(hot_image_set));
41 border->set_pushed_painter( 44 border->SetPainter(false, views::Button::STATE_PRESSED,
42 views::Painter::CreateImageGridPainter(pushed_image_set)); 45 views::Painter::CreateImageGridPainter(pushed_image_set));
43 46
47 border->set_insets(gfx::Insets(kTopBottomInset, kLeftRightInset,
48 kTopBottomInset, kLeftRightInset));
49
44 return border.PassAs<views::Border>(); 50 return border.PassAs<views::Border>();
45 } 51 }
46 52
47 base::string16 GetElidedText(const base::string16& original_text) { 53 base::string16 GetElidedText(const base::string16& original_text) {
48 // Maximum characters the button can be before the text will get elided. 54 // Maximum characters the button can be before the text will get elided.
49 const int kMaxCharactersToDisplay = 15; 55 const int kMaxCharactersToDisplay = 15;
50 const gfx::FontList font_list; 56 const gfx::FontList font_list;
51 return gfx::ElideText(original_text, font_list, 57 return gfx::ElideText(original_text, font_list,
52 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), 58 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay),
53 gfx::ELIDE_TAIL); 59 gfx::ELIDE_TAIL);
(...skipping 10 matching lines...) Expand all
64 } // namespace 70 } // namespace
65 71
66 NewAvatarButton::NewAvatarButton( 72 NewAvatarButton::NewAvatarButton(
67 views::ButtonListener* listener, 73 views::ButtonListener* listener,
68 const base::string16& profile_name, 74 const base::string16& profile_name,
69 AvatarButtonStyle button_style, 75 AvatarButtonStyle button_style,
70 Browser* browser) 76 Browser* browser)
71 : MenuButton(listener, GetButtonText(browser->profile()), NULL, true), 77 : MenuButton(listener, GetButtonText(browser->profile()), NULL, true),
72 browser_(browser) { 78 browser_(browser) {
73 set_animate_on_state_change(false); 79 set_animate_on_state_change(false);
74 set_icon_placement(ICON_ON_RIGHT); 80 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE);
81 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE);
82 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE);
83 SetHaloColor(SK_ColorDKGRAY);
84 SetHorizontalAlignment(gfx::ALIGN_RIGHT);
75 85
76 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 86 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
77 87
78 bool is_win8 = false; 88 bool is_win8 = false;
79 #if defined(OS_WIN) 89 #if defined(OS_WIN)
80 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; 90 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8;
81 #endif 91 #endif
82 92
83 if (button_style == THEMED_BUTTON) { 93 if (button_style == THEMED_BUTTON) {
84 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); 94 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 133
124 NewAvatarButton::~NewAvatarButton() { 134 NewAvatarButton::~NewAvatarButton() {
125 g_browser_process->profile_manager()-> 135 g_browser_process->profile_manager()->
126 GetProfileInfoCache().RemoveObserver(this); 136 GetProfileInfoCache().RemoveObserver(this);
127 SigninErrorController* error = 137 SigninErrorController* error =
128 profiles::GetSigninErrorController(browser_->profile()); 138 profiles::GetSigninErrorController(browser_->profile());
129 if (error) 139 if (error)
130 error->RemoveObserver(this); 140 error->RemoveObserver(this);
131 } 141 }
132 142
133 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) {
134 // Get text bounds, and then adjust for the top and RTL languages.
135 gfx::Rect rect = GetTextBounds();
136 rect.Offset(0, -rect.y());
137 if (rect.width() > 0)
138 rect.set_x(GetMirroredXForRect(rect));
139
140 canvas->DrawStringRectWithHalo(
141 text(),
142 gfx::FontList(),
143 SK_ColorWHITE,
144 SK_ColorDKGRAY,
145 rect,
146 gfx::Canvas::NO_SUBPIXEL_RENDERING);
147 }
148
149 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { 143 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) {
150 UpdateAvatarButtonAndRelayoutParent(); 144 UpdateAvatarButtonAndRelayoutParent();
151 } 145 }
152 146
153 void NewAvatarButton::OnProfileWasRemoved( 147 void NewAvatarButton::OnProfileWasRemoved(
154 const base::FilePath& profile_path, 148 const base::FilePath& profile_path,
155 const base::string16& profile_name) { 149 const base::string16& profile_name) {
156 UpdateAvatarButtonAndRelayoutParent(); 150 UpdateAvatarButtonAndRelayoutParent();
157 } 151 }
158 152
159 void NewAvatarButton::OnProfileNameChanged( 153 void NewAvatarButton::OnProfileNameChanged(
160 const base::FilePath& profile_path, 154 const base::FilePath& profile_path,
161 const base::string16& old_profile_name) { 155 const base::string16& old_profile_name) {
162 UpdateAvatarButtonAndRelayoutParent(); 156 UpdateAvatarButtonAndRelayoutParent();
163 } 157 }
164 158
165 void NewAvatarButton::OnErrorChanged() { 159 void NewAvatarButton::OnErrorChanged() {
166 gfx::ImageSkia icon; 160 gfx::ImageSkia icon;
167 161
168 // If there is an error, show an warning icon. 162 // If there is an error, show an warning icon.
169 const SigninErrorController* error = 163 const SigninErrorController* error =
170 profiles::GetSigninErrorController(browser_->profile()); 164 profiles::GetSigninErrorController(browser_->profile());
171 if (error && error->HasError()) { 165 if (error && error->HasError()) {
172 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
173 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); 167 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia();
174 } 168 }
175 169
176 SetIcon(icon); 170 SetImage(views::Button::STATE_NORMAL, icon);
177 UpdateAvatarButtonAndRelayoutParent(); 171 UpdateAvatarButtonAndRelayoutParent();
178 } 172 }
179 173
180 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { 174 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
181 // We want the button to resize if the new text is shorter. 175 // We want the button to resize if the new text is shorter.
182 SetText(GetButtonText(browser_->profile())); 176 SetText(GetButtonText(browser_->profile()));
183 ClearMaxTextSize(); 177 set_min_size(gfx::Size());
178 InvalidateLayout();
184 179
185 // Because the width of the button might have changed, the parent browser 180 // Because the width of the button might have changed, the parent browser
186 // frame needs to recalculate the button bounds and redraw it. 181 // frame needs to recalculate the button bounds and redraw it.
187 if (parent()) 182 if (parent())
188 parent()->Layout(); 183 parent()->Layout();
189 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698