OLD | NEW |
---|---|
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" |
(...skipping 12 matching lines...) Expand all Loading... | |
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. | 30 // Text padding within the button border. |
31 const int kLeftRightInset = 7; | 31 const int kLeftRightInset = 7; |
32 const int kTopBottomInset = 2; | 32 const int kTopBottomInset = 2; |
33 // The button in themed windows is slightly smaller, so it needs an extra | |
34 // bottom inset so that the text doesn't get rendered outside the borders. | |
35 const int kThemedWindowExtraBottomInset = 2; | |
36 // Target size of the warning icon. | |
msw
2014/06/19 04:10:18
Remove these unused consts.
noms (inactive)
2014/06/19 15:10:55
Done.
| |
37 const int kAuthErrorIconWidth = 13; | |
38 const int kAuthErrorIconHeight = 11; | |
33 | 39 |
34 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], | 40 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], |
35 const int hot_image_set[], | 41 const int hot_image_set[], |
36 const int pushed_image_set[]) { | 42 const int pushed_image_set[], |
43 bool is_themed_window) { | |
37 scoped_ptr<views::LabelButtonBorder> border( | 44 scoped_ptr<views::LabelButtonBorder> border( |
38 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); | 45 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); |
39 | |
40 border->SetPainter(false, views::Button::STATE_NORMAL, | 46 border->SetPainter(false, views::Button::STATE_NORMAL, |
41 views::Painter::CreateImageGridPainter(normal_image_set)); | 47 views::Painter::CreateImageGridPainter(normal_image_set)); |
42 border->SetPainter(false, views::Button::STATE_HOVERED, | 48 border->SetPainter(false, views::Button::STATE_HOVERED, |
43 views::Painter::CreateImageGridPainter(hot_image_set)); | 49 views::Painter::CreateImageGridPainter(hot_image_set)); |
44 border->SetPainter(false, views::Button::STATE_PRESSED, | 50 border->SetPainter(false, views::Button::STATE_PRESSED, |
45 views::Painter::CreateImageGridPainter(pushed_image_set)); | 51 views::Painter::CreateImageGridPainter(pushed_image_set)); |
46 | 52 int bottom_inset = is_themed_window ? |
47 border->set_insets(gfx::Insets(kTopBottomInset, kLeftRightInset, | 53 kTopBottomInset + kThemedWindowExtraBottomInset : kTopBottomInset; |
48 kTopBottomInset, kLeftRightInset)); | 54 int top_inset = is_themed_window ? |
55 kTopBottomInset - kThemedWindowExtraBottomInset : kTopBottomInset; | |
56 border->set_insets(gfx::Insets(top_inset, kLeftRightInset, | |
msw
2014/06/19 04:10:17
Ah, I'm sorry to put you out, but can you see if t
noms (inactive)
2014/06/19 15:10:55
Patched in your CL, and your insets look good. I'v
| |
57 bottom_inset, kLeftRightInset)); | |
49 | 58 |
50 return border.PassAs<views::Border>(); | 59 return border.PassAs<views::Border>(); |
51 } | 60 } |
52 | 61 |
53 base::string16 GetElidedText(const base::string16& original_text) { | 62 base::string16 GetElidedText(const base::string16& original_text) { |
54 // Maximum characters the button can be before the text will get elided. | 63 // Maximum characters the button can be before the text will get elided. |
55 const int kMaxCharactersToDisplay = 15; | 64 const int kMaxCharactersToDisplay = 15; |
56 const gfx::FontList font_list; | 65 const gfx::FontList font_list; |
57 return gfx::ElideText(original_text, font_list, | 66 return gfx::ElideText(original_text, font_list, |
58 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), | 67 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), |
(...skipping 29 matching lines...) Expand all Loading... | |
88 bool is_win8 = false; | 97 bool is_win8 = false; |
89 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
90 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; | 99 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; |
91 #endif | 100 #endif |
92 | 101 |
93 if (button_style == THEMED_BUTTON) { | 102 if (button_style == THEMED_BUTTON) { |
94 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | 103 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); |
95 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | 104 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); |
96 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | 105 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); |
97 | 106 |
98 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 107 SetBorder( |
108 CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet, true)); | |
99 set_menu_marker( | 109 set_menu_marker( |
100 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); | 110 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); |
101 } else if (is_win8) { | 111 } else if (is_win8) { |
102 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); | 112 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); |
103 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER); | 113 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER); |
104 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); | 114 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); |
105 | 115 |
106 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 116 SetBorder( |
117 CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet, false)); | |
107 set_menu_marker( | 118 set_menu_marker( |
108 rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia()); | 119 rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia()); |
109 } else { | 120 } else { |
110 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); | 121 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); |
111 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); | 122 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); |
112 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); | 123 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); |
113 | 124 |
114 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 125 SetBorder( |
126 CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet, false)); | |
115 set_menu_marker( | 127 set_menu_marker( |
116 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); | 128 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); |
117 } | 129 } |
118 | 130 |
119 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 131 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
120 | 132 |
121 // Subscribe to authentication error changes so that the avatar button | 133 // Subscribe to authentication error changes so that the avatar button |
122 // can update itself. Note that guest mode profiles won't have a token | 134 // can update itself. Note that guest mode profiles won't have a token |
123 // service. | 135 // service. |
124 SigninErrorController* error = | 136 SigninErrorController* error = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 UpdateAvatarButtonAndRelayoutParent(); | 168 UpdateAvatarButtonAndRelayoutParent(); |
157 } | 169 } |
158 | 170 |
159 void NewAvatarButton::OnErrorChanged() { | 171 void NewAvatarButton::OnErrorChanged() { |
160 gfx::ImageSkia icon; | 172 gfx::ImageSkia icon; |
161 | 173 |
162 // If there is an error, show an warning icon. | 174 // If there is an error, show an warning icon. |
163 const SigninErrorController* error = | 175 const SigninErrorController* error = |
164 profiles::GetSigninErrorController(browser_->profile()); | 176 profiles::GetSigninErrorController(browser_->profile()); |
165 if (error && error->HasError()) { | 177 if (error && error->HasError()) { |
166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 178 icon = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
167 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); | 179 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToImageSkia(); |
msw
2014/06/19 04:10:18
Did you mean to leave this as IDR_WARNING?
noms (inactive)
2014/06/19 15:10:55
Nope! IDR_WARNING was a placeholder while we were
| |
168 } | 180 } |
169 | 181 |
170 SetImage(views::Button::STATE_NORMAL, icon); | 182 SetImage(views::Button::STATE_NORMAL, icon); |
171 UpdateAvatarButtonAndRelayoutParent(); | 183 UpdateAvatarButtonAndRelayoutParent(); |
172 } | 184 } |
173 | 185 |
174 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { | 186 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { |
175 // We want the button to resize if the new text is shorter. | 187 // We want the button to resize if the new text is shorter. |
176 SetText(GetButtonText(browser_->profile())); | 188 SetText(GetButtonText(browser_->profile())); |
177 set_min_size(gfx::Size()); | 189 set_min_size(gfx::Size()); |
178 InvalidateLayout(); | 190 InvalidateLayout(); |
179 | 191 |
180 // Because the width of the button might have changed, the parent browser | 192 // Because the width of the button might have changed, the parent browser |
181 // frame needs to recalculate the button bounds and redraw it. | 193 // frame needs to recalculate the button bounds and redraw it. |
182 if (parent()) | 194 if (parent()) |
183 parent()->Layout(); | 195 parent()->Layout(); |
184 } | 196 } |
OLD | NEW |