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

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

Issue 2880033003: Apply MD style to Linux avatar buttons. (Closed)
Patch Set: rebase Created 3 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
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/avatar_button.h" 5 #include "chrome/browser/ui/views/profiles/avatar_button.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "chrome/app/vector_icons/vector_icons.h" 9 #include "chrome/app/vector_icons/vector_icons.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profiles_state.h" 12 #include "chrome/browser/profiles/profiles_state.h"
13 #include "chrome/browser/signin/signin_manager_factory.h" 13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/browser/themes/theme_properties.h"
14 #include "chrome/browser/themes/theme_service.h" 15 #include "chrome/browser/themes/theme_service.h"
15 #include "chrome/browser/themes/theme_service_factory.h" 16 #include "chrome/browser/themes/theme_service_factory.h"
17 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
16 #include "chrome/grit/theme_resources.h" 18 #include "chrome/grit/theme_resources.h"
17 #include "components/signin/core/browser/signin_manager.h" 19 #include "components/signin/core/browser/signin_manager.h"
18 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/base/theme_provider.h"
22 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/color_palette.h" 23 #include "ui/gfx/color_palette.h"
20 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
21 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 25 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
22 #include "ui/views/animation/ink_drop_impl.h" 26 #include "ui/views/animation/ink_drop_impl.h"
27 #include "ui/views/animation/ink_drop_mask.h"
23 #include "ui/views/controls/button/label_button_border.h" 28 #include "ui/views/controls/button/label_button_border.h"
24 29
25 #if defined(OS_WIN) 30 #if defined(OS_WIN)
26 #include "base/win/windows_version.h" 31 #include "base/win/windows_version.h"
27 #include "chrome/browser/ui/views/frame/minimize_button_metrics_win.h" 32 #include "chrome/browser/ui/views/frame/minimize_button_metrics_win.h"
28 #endif 33 #endif
29 34
30 namespace { 35 namespace {
31 36
32 constexpr int kLeftRightInset = 8; 37 constexpr gfx::Insets kBorderInsets(2, 8, 4, 8);
33 constexpr int kTopInset = 2;
34 constexpr int kBottomInset = 4;
35 38
36 // TODO(emx): Calculate width based on caption button [http://crbug.com/716365] 39 // TODO(emx): Calculate width based on caption button [http://crbug.com/716365]
37 constexpr int kMdButtonMinWidth = 46; 40 constexpr int kCondensibleButtonMinWidth = 46;
41 // TODO(emx): Should this be calculated based on average character width?
42 constexpr int kCondensibleButtonMaxWidth = 98;
38 43
39 std::unique_ptr<views::Border> CreateThemedBorder( 44 std::unique_ptr<views::Border> CreateThemedBorder(
40 const int normal_image_set[], 45 const int normal_image_set[],
41 const int hot_image_set[], 46 const int hot_image_set[],
42 const int pushed_image_set[]) { 47 const int pushed_image_set[]) {
43 std::unique_ptr<views::LabelButtonAssetBorder> border( 48 std::unique_ptr<views::LabelButtonAssetBorder> border(
44 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); 49 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON));
45 50
46 border->SetPainter(false, views::Button::STATE_NORMAL, 51 border->SetPainter(false, views::Button::STATE_NORMAL,
47 views::Painter::CreateImageGridPainter(normal_image_set)); 52 views::Painter::CreateImageGridPainter(normal_image_set));
48 border->SetPainter(false, views::Button::STATE_HOVERED, 53 border->SetPainter(false, views::Button::STATE_HOVERED,
49 views::Painter::CreateImageGridPainter(hot_image_set)); 54 views::Painter::CreateImageGridPainter(hot_image_set));
50 border->SetPainter(false, views::Button::STATE_PRESSED, 55 border->SetPainter(false, views::Button::STATE_PRESSED,
51 views::Painter::CreateImageGridPainter(pushed_image_set)); 56 views::Painter::CreateImageGridPainter(pushed_image_set));
52 57
53 border->set_insets( 58 border->set_insets(kBorderInsets);
54 gfx::Insets(kTopInset, kLeftRightInset, kBottomInset, kLeftRightInset));
55 59
56 return std::move(border); 60 return std::move(border);
57 } 61 }
58 62
59 std::unique_ptr<views::Border> CreateWin10NativeBorder() { 63 // This class draws the border (and background) of the avatar button for
60 return views::CreateEmptyBorder(kTopInset, kLeftRightInset, kBottomInset, 64 // "themed" browser windows, i.e. OpaqueBrowserFrameView. Currently it's only
61 kLeftRightInset); 65 // used on Linux as the shape specifically matches the Linux caption buttons.
62 } 66 // TODO(estade): make this look nice on Windows and use it there as well.
67 class AvatarButtonThemedBorder : public views::Border {
68 public:
69 AvatarButtonThemedBorder() {}
70 ~AvatarButtonThemedBorder() override {}
71
72 void Paint(const views::View& view, gfx::Canvas* canvas) override {
73 // Start with an outer dark stroke.
74 cc::PaintFlags stroke_flags;
75 stroke_flags.setStyle(cc::PaintFlags::kStroke_Style);
76 stroke_flags.setColor(SkColorSetA(SK_ColorBLACK, 0x2B));
77 stroke_flags.setStrokeWidth(kStrokeWidth);
78 stroke_flags.setAntiAlias(true);
79 gfx::RectF stroke_bounds(view.GetLocalBounds());
80 stroke_bounds.Inset(gfx::InsetsF(0.5f));
81 canvas->DrawRoundRect(stroke_bounds, kCornerRadius, stroke_flags);
82
83 // There's a second, light stroke that matches the fill bounds.
84 stroke_bounds.Inset(gfx::InsetsF(kStrokeWidth));
85 stroke_flags.setColor(SkColorSetA(SK_ColorWHITE, 0x3F));
86 canvas->DrawRoundRect(stroke_bounds, kCornerRadius, stroke_flags);
87 }
88
89 gfx::Insets GetInsets() const override {
90 return kBorderStrokeInsets + gfx::Insets(0, 6);
91 }
92
93 gfx::Size GetMinimumSize() const override {
94 return gfx::Size(GetInsets().width(), GetInsets().height());
95 }
96
97 static std::unique_ptr<views::InkDropMask> CreateInkDropMask(
98 const gfx::Size& size) {
99 return base::MakeUnique<views::RoundRectInkDropMask>(
100 size, kBorderStrokeInsets, kCornerRadius);
101 }
102
103 private:
104 static constexpr float kStrokeWidth = 1;
105
106 // Insets between view bounds and the interior of the strokes.
107 static constexpr gfx::Insets kBorderStrokeInsets{kStrokeWidth * 2};
108
109 // Corner radius of the roundrect.
110 static constexpr float kCornerRadius = 1;
111
112 DISALLOW_COPY_AND_ASSIGN(AvatarButtonThemedBorder);
113 };
114
115 constexpr float AvatarButtonThemedBorder::kStrokeWidth;
116 constexpr gfx::Insets AvatarButtonThemedBorder::kBorderStrokeInsets;
117 constexpr float AvatarButtonThemedBorder::kCornerRadius;
63 118
64 } // namespace 119 } // namespace
65 120
66 AvatarButton::AvatarButton(views::ButtonListener* listener, 121 AvatarButton::AvatarButton(views::ButtonListener* listener,
67 AvatarButtonStyle button_style, 122 AvatarButtonStyle button_style,
68 Profile* profile) 123 Profile* profile)
69 : LabelButton(listener, base::string16()), 124 : LabelButton(listener, base::string16()),
70 error_controller_(this, profile), 125 error_controller_(this, profile),
71 profile_(profile), 126 profile_(profile),
72 profile_observer_(this), 127 profile_observer_(this),
73 use_win10_native_button_(false) { 128 button_style_(button_style) {
74 set_notify_action(CustomButton::NOTIFY_ON_PRESS); 129 set_notify_action(CustomButton::NOTIFY_ON_PRESS);
75 set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | 130 set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
76 ui::EF_RIGHT_MOUSE_BUTTON); 131 ui::EF_RIGHT_MOUSE_BUTTON);
77 set_animate_on_state_change(false); 132 set_animate_on_state_change(false);
78 SetEnabledTextColors(SK_ColorWHITE); 133 SetEnabledTextColors(SK_ColorWHITE);
79 SetTextSubpixelRenderingEnabled(false); 134 SetTextSubpixelRenderingEnabled(false);
80 SetHorizontalAlignment(gfx::ALIGN_CENTER); 135 SetHorizontalAlignment(gfx::ALIGN_CENTER);
81 136
82 profile_observer_.Add( 137 profile_observer_.Add(
83 &g_browser_process->profile_manager()->GetProfileAttributesStorage()); 138 &g_browser_process->profile_manager()->GetProfileAttributesStorage());
84 139
85 // The largest text height that fits in the button. If the font list height 140 // The largest text height that fits in the button. If the font list height
86 // is larger than this, it will be shrunk to match it. 141 // is larger than this, it will be shrunk to match it.
87 // TODO(noms): Calculate this constant algorithmically from the button's size. 142 // TODO(noms): Calculate this constant algorithmically from the button's size.
88 const int kDisplayFontHeight = 16; 143 const int kDisplayFontHeight = 16;
89 SetFontList( 144 SetFontList(
90 label()->font_list().DeriveWithHeightUpperBound(kDisplayFontHeight)); 145 label()->font_list().DeriveWithHeightUpperBound(kDisplayFontHeight));
91 146
92 #if defined(OS_WIN) 147 bool apply_ink_drop = IsCondensible();
93 // TODO(estade): Use MD button in other cases, too [http://crbug.com/591586] 148 #if defined(OS_LINUX)
94 if ((base::win::GetVersion() >= base::win::VERSION_WIN10) && 149 DCHECK_EQ(AvatarButtonStyle::THEMED, button_style);
95 ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) { 150 apply_ink_drop = true;
96 DCHECK_EQ(AvatarButtonStyle::NATIVE, button_style); 151 #endif
97 use_win10_native_button_ = true;
98 }
99 #endif // defined(OS_WIN)
100 152
101 if (use_win10_native_button_) { 153 if (apply_ink_drop) {
102 constexpr int kMdButtonIconHeight = 16; 154 constexpr int kIconSize = 16;
103 constexpr SkColor kMdButtonIconColor = 155 constexpr SkColor kIconColor =
104 SkColorSetA(SK_ColorBLACK, static_cast<SkAlpha>(0.54 * 0xFF)); 156 SkColorSetA(SK_ColorBLACK, static_cast<SkAlpha>(0.54 * 0xFF));
105 generic_avatar_ = gfx::CreateVectorIcon( 157 generic_avatar_ =
106 kAccountCircleIcon, kMdButtonIconHeight, kMdButtonIconColor); 158 gfx::CreateVectorIcon(kAccountCircleIcon, kIconSize, kIconColor);
107 SetBorder(CreateWin10NativeBorder());
108 159
109 SetInkDropMode(InkDropMode::ON); 160 SetInkDropMode(InkDropMode::ON);
110 set_has_ink_drop_action_on_click(true); 161 set_has_ink_drop_action_on_click(true);
111 SetFocusPainter(nullptr); 162 SetFocusPainter(nullptr);
163 #if defined(OS_LINUX)
164 set_ink_drop_base_color(SK_ColorWHITE);
165 SetBorder(base::MakeUnique<AvatarButtonThemedBorder>());
166 #elif defined(OS_WIN)
167 DCHECK_EQ(AvatarButtonStyle::NATIVE, button_style);
112 set_ink_drop_base_color(SK_ColorBLACK); 168 set_ink_drop_base_color(SK_ColorBLACK);
169 SetBorder(views::CreateEmptyBorder(kBorderInsets));
170 #endif // defined(OS_WIN)
171 } else if (button_style == AvatarButtonStyle::THEMED) {
172 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
173 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
174 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
175 SetButtonAvatar(IDR_AVATAR_THEMED_BUTTON_AVATAR);
176 SetBorder(
177 CreateThemedBorder(kNormalImageSet, kHoverImageSet, kPressedImageSet));
178 #if defined(OS_WIN)
179 } else if (base::win::GetVersion() < base::win::VERSION_WIN8) {
180 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
181 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
182 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
183 SetButtonAvatar(IDR_AVATAR_GLASS_BUTTON_AVATAR);
184 SetBorder(
185 CreateThemedBorder(kNormalImageSet, kHoverImageSet, kPressedImageSet));
186 #endif
113 } else { 187 } else {
114 if (button_style == AvatarButtonStyle::THEMED) { 188 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
115 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); 189 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
116 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); 190 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
117 const int kPressedImageSet[] = 191 SetButtonAvatar(IDR_AVATAR_NATIVE_BUTTON_AVATAR);
118 IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); 192 SetBorder(
119 SetButtonAvatar(IDR_AVATAR_THEMED_BUTTON_AVATAR); 193 CreateThemedBorder(kNormalImageSet, kHoverImageSet, kPressedImageSet));
120 SetBorder(CreateThemedBorder(kNormalImageSet, kHoverImageSet,
121 kPressedImageSet));
122 #if defined(OS_WIN)
123 } else if (base::win::GetVersion() < base::win::VERSION_WIN8) {
124 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
125 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
126 const int kPressedImageSet[] =
127 IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
128 SetButtonAvatar(IDR_AVATAR_GLASS_BUTTON_AVATAR);
129 SetBorder(CreateThemedBorder(kNormalImageSet, kHoverImageSet,
130 kPressedImageSet));
131 #endif
132 } else {
133 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
134 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
135 const int kPressedImageSet[] =
136 IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
137 SetButtonAvatar(IDR_AVATAR_NATIVE_BUTTON_AVATAR);
138 SetBorder(CreateThemedBorder(kNormalImageSet, kHoverImageSet,
139 kPressedImageSet));
140 }
141 } 194 }
142 195
143 Update(); 196 Update();
144 SchedulePaint(); 197 SchedulePaint();
145 } 198 }
146 199
147 AvatarButton::~AvatarButton() {} 200 AvatarButton::~AvatarButton() {}
148 201
149 void AvatarButton::OnGestureEvent(ui::GestureEvent* event) { 202 void AvatarButton::OnGestureEvent(ui::GestureEvent* event) {
150 // TODO(wjmaclean): The check for ET_GESTURE_LONG_PRESS is done here since 203 // TODO(wjmaclean): The check for ET_GESTURE_LONG_PRESS is done here since
151 // no other UI button based on CustomButton appears to handle mouse 204 // no other UI button based on CustomButton appears to handle mouse
152 // right-click. If other cases are identified, it may make sense to move this 205 // right-click. If other cases are identified, it may make sense to move this
153 // check to CustomButton. 206 // check to CustomButton.
154 if (event->type() == ui::ET_GESTURE_LONG_PRESS) 207 if (event->type() == ui::ET_GESTURE_LONG_PRESS)
155 NotifyClick(*event); 208 NotifyClick(*event);
156 else 209 else
157 LabelButton::OnGestureEvent(event); 210 LabelButton::OnGestureEvent(event);
158 } 211 }
159 212
160 gfx::Size AvatarButton::GetMinimumSize() const { 213 gfx::Size AvatarButton::GetMinimumSize() const {
161 if (use_win10_native_button_) { 214 if (IsCondensible()) {
162 // Returns the size of the button when it is atop the tabstrip. Called by 215 // Returns the size of the button when it is atop the tabstrip. Called by
163 // GlassBrowserFrameView::LayoutProfileSwitcher(). 216 // GlassBrowserFrameView::LayoutProfileSwitcher().
164 // TODO(emx): Calculate the height based on the top of the new tab button. 217 // TODO(emx): Calculate the height based on the top of the new tab button.
165 return gfx::Size(kMdButtonMinWidth, 20); 218 return gfx::Size(kCondensibleButtonMinWidth, 20);
166 } 219 }
167 220
168 return LabelButton::GetMinimumSize(); 221 return LabelButton::GetMinimumSize();
169 } 222 }
170 223
171 gfx::Size AvatarButton::GetPreferredSize() const { 224 gfx::Size AvatarButton::GetPreferredSize() const {
172 gfx::Size size = LabelButton::GetPreferredSize(); 225 // TODO(estade): Calculate the height instead of hardcoding to 20 for the
226 // not-condensible case.
227 gfx::Size size(LabelButton::GetPreferredSize().width(), 20);
173 228
174 if (use_win10_native_button_) { 229 if (IsCondensible()) {
230 // Returns the normal size of the button (when it does not overlap the
231 // tabstrip).
232 size.set_width(std::min(std::max(size.width(), kCondensibleButtonMinWidth),
233 kCondensibleButtonMaxWidth));
175 #if defined(OS_WIN) 234 #if defined(OS_WIN)
176 // Returns the normal size of the button (when it does not overlap the
177 // tabstrip). Its height should match the caption button height.
178 // The minimum width is the caption button width and the maximum is fixed
179 // as per the spec in http://crbug.com/635699.
180 // TODO(emx): Should this be calculated based on average character width?
181 constexpr int kMdButtonMaxWidth = 98;
182 size.set_width(
183 std::min(std::max(size.width(), kMdButtonMinWidth), kMdButtonMaxWidth));
184 size.set_height(MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs()); 235 size.set_height(MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs());
185 #endif 236 #endif
186 } else {
187 size.set_height(20);
188 } 237 }
189 238
190 return size; 239 return size;
191 } 240 }
192 241
242 std::unique_ptr<views::InkDropMask> AvatarButton::CreateInkDropMask() const {
243 if (button_style_ == AvatarButtonStyle::THEMED)
244 return AvatarButtonThemedBorder::CreateInkDropMask(size());
245 return LabelButton::CreateInkDropMask();
246 }
247
193 std::unique_ptr<views::InkDropHighlight> AvatarButton::CreateInkDropHighlight() 248 std::unique_ptr<views::InkDropHighlight> AvatarButton::CreateInkDropHighlight()
194 const { 249 const {
195 auto center = gfx::RectF(GetLocalBounds()).CenterPoint(); 250 if (button_style_ == AvatarButtonStyle::THEMED)
251 return LabelButton::CreateInkDropHighlight();
252
196 auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>( 253 auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>(
197 size(), 0, center, GetInkDropBaseColor()); 254 size(), 0, gfx::RectF(GetLocalBounds()).CenterPoint(),
255 GetInkDropBaseColor());
198 constexpr float kInkDropHighlightOpacity = 0.08f; 256 constexpr float kInkDropHighlightOpacity = 0.08f;
199 ink_drop_highlight->set_visible_opacity(kInkDropHighlightOpacity); 257 ink_drop_highlight->set_visible_opacity(kInkDropHighlightOpacity);
200 return ink_drop_highlight; 258 return ink_drop_highlight;
201 } 259 }
202 260
261 void AvatarButton::NotifyClick(const ui::Event& event) {
262 LabelButton::NotifyClick(event);
263
264 views::Widget* bubble_widget = ProfileChooserView::GetCurrentBubbleWidget();
265 if (bubble_widget && !bubble_widget->HasObserver(this) &&
266 ink_drop_mode() == InkDropMode::ON) {
267 ProfileChooserView::GetCurrentBubbleWidget()->AddObserver(this);
bruthig 2017/05/16 17:33:48 nit: It is ok to call AnimaterInkDrop() even when
Evan Stade 2017/05/16 23:50:13 Done.
268 AnimateInkDrop(views::InkDropState::ACTIVATED,
269 ui::LocatedEvent::FromIfValid(&event));
270 }
271 }
272
203 bool AvatarButton::ShouldUseFloodFillInkDrop() const { 273 bool AvatarButton::ShouldUseFloodFillInkDrop() const {
204 return true; 274 return true;
205 } 275 }
206 276
207 void AvatarButton::OnAvatarErrorChanged() { 277 void AvatarButton::OnAvatarErrorChanged() {
208 Update(); 278 Update();
209 } 279 }
210 280
211 void AvatarButton::OnProfileAdded(const base::FilePath& profile_path) { 281 void AvatarButton::OnProfileAdded(const base::FilePath& profile_path) {
212 Update(); 282 Update();
(...skipping 13 matching lines...) Expand all
226 if (profile_->GetPath() == profile_path) 296 if (profile_->GetPath() == profile_path)
227 Update(); 297 Update();
228 } 298 }
229 299
230 void AvatarButton::OnProfileSupervisedUserIdChanged( 300 void AvatarButton::OnProfileSupervisedUserIdChanged(
231 const base::FilePath& profile_path) { 301 const base::FilePath& profile_path) {
232 if (profile_->GetPath() == profile_path) 302 if (profile_->GetPath() == profile_path)
233 Update(); 303 Update();
234 } 304 }
235 305
306 void AvatarButton::OnWidgetClosing(views::Widget* widget) {
307 if (ink_drop_mode() == InkDropMode::ON)
308 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr);
309 }
310
236 void AvatarButton::Update() { 311 void AvatarButton::Update() {
237 ProfileAttributesStorage& storage = 312 ProfileAttributesStorage& storage =
238 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 313 g_browser_process->profile_manager()->GetProfileAttributesStorage();
239 314
240 // If we have a single local profile, then use the generic avatar 315 // If we have a single local profile, then use the generic avatar
241 // button instead of the profile name. Never use the generic button if 316 // button instead of the profile name. Never use the generic button if
242 // the active profile is Guest. 317 // the active profile is Guest.
243 const bool use_generic_button = 318 const bool use_generic_button =
244 !profile_->IsGuestSession() && storage.GetNumberOfProfiles() == 1 && 319 !profile_->IsGuestSession() && storage.GetNumberOfProfiles() == 1 &&
245 !SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated(); 320 !SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated();
(...skipping 27 matching lines...) Expand all
273 const int kDefaultImageTextSpacing = 5; 348 const int kDefaultImageTextSpacing = 5;
274 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); 349 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing);
275 350
276 PreferredSizeChanged(); 351 PreferredSizeChanged();
277 } 352 }
278 353
279 void AvatarButton::SetButtonAvatar(int avatar_idr) { 354 void AvatarButton::SetButtonAvatar(int avatar_idr) {
280 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 355 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
281 generic_avatar_ = *rb->GetImageNamed(avatar_idr).ToImageSkia(); 356 generic_avatar_ = *rb->GetImageNamed(avatar_idr).ToImageSkia();
282 } 357 }
358
359 bool AvatarButton::IsCondensible() const {
360 #if defined(OS_WIN)
361 return (base::win::GetVersion() >= base::win::VERSION_WIN10) &&
362 ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme();
363 #else
364 return false;
365 #endif
366 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/avatar_button.h ('k') | chrome/browser/ui/views/profiles/profile_chooser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698