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/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)); | |
Peter Kasting
2017/05/15 21:51:27
Nit: Where did this constant come from? Is it jus
Evan Stade
2017/05/15 22:25:16
They match the assets we use for the caption butto
Peter Kasting
2017/05/15 23:41:02
Maybe we should put a comment in saying "matches x
Evan Stade
2017/05/16 23:50:13
comment added
| |
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. | |
Peter Kasting
2017/05/15 21:51:27
I'm still concerned with computing these nested (s
Evan Stade
2017/05/15 22:25:15
Yea. Before you said you were worried about appear
Peter Kasting
2017/05/15 23:41:02
Interesting. I recall noticing similar artifacts
| |
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); | |
Peter Kasting
2017/05/15 21:51:27
Nit: Again, where does this 6 come from? Can it b
Evan Stade
2017/05/15 22:25:16
I don't believe so. It was hardcoded before and it
Peter Kasting
2017/05/15 23:41:02
I'm thinking the spacing should match what we comp
Evan Stade
2017/05/16 23:50:13
I guess we're sorta matching this[1]. Changed.
[1
| |
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; | |
Peter Kasting
2017/05/15 21:51:27
Nit: Does the compiler actually complain if you do
Evan Stade
2017/05/15 22:25:15
The code compiles but won't link. There is some di
Peter Kasting
2017/05/15 23:41:02
Yeah, by "compiler" I really meant "linker". Leav
| |
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 gfx::Size size = LabelButton::GetPreferredSize(); |
226 size.set_height(20); | |
Peter Kasting
2017/05/15 21:51:27
Nit: Simpler:
gfx::Size size(LabelButton::GetPr
Evan Stade
2017/05/15 22:25:16
Done.
| |
173 | 227 |
174 if (use_win10_native_button_) { | 228 if (IsCondensible()) { |
175 #if defined(OS_WIN) | |
176 // Returns the normal size of the button (when it does not overlap the | 229 // Returns the normal size of the button (when it does not overlap the |
177 // tabstrip). Its height should match the caption button height. | 230 // tabstrip). Its height should match the caption button height. |
Peter Kasting
2017/05/15 21:51:27
Nit: This second sentence should probably turn int
Evan Stade
2017/05/15 22:25:16
todo added
| |
178 // The minimum width is the caption button width and the maximum is fixed | 231 // The minimum width is the caption button width and the maximum is fixed |
179 // as per the spec in http://crbug.com/635699. | 232 // as per the spec in http://crbug.com/635699. |
Peter Kasting
2017/05/15 21:51:28
Nit: This thirds sentence, if it needs saying at a
Evan Stade
2017/05/15 22:25:16
removed
| |
180 // TODO(emx): Should this be calculated based on average character width? | 233 size.set_width(std::min(std::max(size.width(), kCondensibleButtonMinWidth), |
181 constexpr int kMdButtonMaxWidth = 98; | 234 kCondensibleButtonMaxWidth)); |
182 size.set_width( | 235 #if defined(OS_WIN) |
183 std::min(std::max(size.width(), kMdButtonMinWidth), kMdButtonMaxWidth)); | |
184 size.set_height(MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs()); | 236 size.set_height(MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs()); |
Peter Kasting
2017/05/15 21:51:28
Nit: This call shouldn't be inside IsCondensible()
Evan Stade
2017/05/15 22:25:15
I agree with this sentiment but changing that migh
| |
185 #endif | 237 #endif |
186 } else { | |
187 size.set_height(20); | |
188 } | 238 } |
189 | 239 |
190 return size; | 240 return size; |
191 } | 241 } |
192 | 242 |
243 std::unique_ptr<views::InkDropMask> AvatarButton::CreateInkDropMask() const { | |
244 if (button_style_ == AvatarButtonStyle::THEMED) | |
245 return AvatarButtonThemedBorder::CreateInkDropMask(size()); | |
246 return LabelButton::CreateInkDropMask(); | |
Peter Kasting
2017/05/15 21:51:28
Nit: Could have single return with ?:, up to you
Evan Stade
2017/05/15 22:25:16
Acknowledged.
| |
247 } | |
248 | |
193 std::unique_ptr<views::InkDropHighlight> AvatarButton::CreateInkDropHighlight() | 249 std::unique_ptr<views::InkDropHighlight> AvatarButton::CreateInkDropHighlight() |
194 const { | 250 const { |
195 auto center = gfx::RectF(GetLocalBounds()).CenterPoint(); | 251 if (button_style_ == AvatarButtonStyle::THEMED) |
252 return LabelButton::CreateInkDropHighlight(); | |
253 | |
196 auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>( | 254 auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>( |
197 size(), 0, center, GetInkDropBaseColor()); | 255 size(), 0, gfx::RectF(GetLocalBounds()).CenterPoint(), |
256 GetInkDropBaseColor()); | |
198 constexpr float kInkDropHighlightOpacity = 0.08f; | 257 constexpr float kInkDropHighlightOpacity = 0.08f; |
199 ink_drop_highlight->set_visible_opacity(kInkDropHighlightOpacity); | 258 ink_drop_highlight->set_visible_opacity(kInkDropHighlightOpacity); |
200 return ink_drop_highlight; | 259 return ink_drop_highlight; |
201 } | 260 } |
202 | 261 |
262 void AvatarButton::NotifyClick(const ui::Event& event) { | |
263 LabelButton::NotifyClick(event); | |
264 | |
265 views::Widget* bubble_widget = ProfileChooserView::GetCurrentBubbleWidget(); | |
266 if (bubble_widget && !bubble_widget->HasObserver(this) && | |
267 ink_drop_mode() == InkDropMode::ON) { | |
268 ProfileChooserView::GetCurrentBubbleWidget()->AddObserver(this); | |
269 AnimateInkDrop(views::InkDropState::ACTIVATED, | |
270 ui::LocatedEvent::FromIfValid(&event)); | |
271 } | |
272 } | |
273 | |
203 bool AvatarButton::ShouldUseFloodFillInkDrop() const { | 274 bool AvatarButton::ShouldUseFloodFillInkDrop() const { |
204 return true; | 275 return true; |
205 } | 276 } |
206 | 277 |
207 void AvatarButton::OnAvatarErrorChanged() { | 278 void AvatarButton::OnAvatarErrorChanged() { |
208 Update(); | 279 Update(); |
209 } | 280 } |
210 | 281 |
211 void AvatarButton::OnProfileAdded(const base::FilePath& profile_path) { | 282 void AvatarButton::OnProfileAdded(const base::FilePath& profile_path) { |
212 Update(); | 283 Update(); |
(...skipping 13 matching lines...) Expand all Loading... | |
226 if (profile_->GetPath() == profile_path) | 297 if (profile_->GetPath() == profile_path) |
227 Update(); | 298 Update(); |
228 } | 299 } |
229 | 300 |
230 void AvatarButton::OnProfileSupervisedUserIdChanged( | 301 void AvatarButton::OnProfileSupervisedUserIdChanged( |
231 const base::FilePath& profile_path) { | 302 const base::FilePath& profile_path) { |
232 if (profile_->GetPath() == profile_path) | 303 if (profile_->GetPath() == profile_path) |
233 Update(); | 304 Update(); |
234 } | 305 } |
235 | 306 |
307 void AvatarButton::OnWidgetClosing(views::Widget* widget) { | |
308 if (ink_drop_mode() == InkDropMode::ON) | |
309 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); | |
310 } | |
311 | |
236 void AvatarButton::Update() { | 312 void AvatarButton::Update() { |
237 ProfileAttributesStorage& storage = | 313 ProfileAttributesStorage& storage = |
238 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 314 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
239 | 315 |
240 // If we have a single local profile, then use the generic avatar | 316 // 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 | 317 // button instead of the profile name. Never use the generic button if |
242 // the active profile is Guest. | 318 // the active profile is Guest. |
243 const bool use_generic_button = | 319 const bool use_generic_button = |
244 !profile_->IsGuestSession() && storage.GetNumberOfProfiles() == 1 && | 320 !profile_->IsGuestSession() && storage.GetNumberOfProfiles() == 1 && |
245 !SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated(); | 321 !SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated(); |
(...skipping 27 matching lines...) Expand all Loading... | |
273 const int kDefaultImageTextSpacing = 5; | 349 const int kDefaultImageTextSpacing = 5; |
274 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); | 350 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); |
275 | 351 |
276 PreferredSizeChanged(); | 352 PreferredSizeChanged(); |
277 } | 353 } |
278 | 354 |
279 void AvatarButton::SetButtonAvatar(int avatar_idr) { | 355 void AvatarButton::SetButtonAvatar(int avatar_idr) { |
280 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 356 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
281 generic_avatar_ = *rb->GetImageNamed(avatar_idr).ToImageSkia(); | 357 generic_avatar_ = *rb->GetImageNamed(avatar_idr).ToImageSkia(); |
282 } | 358 } |
359 | |
360 bool AvatarButton::IsCondensible() const { | |
361 #if defined(OS_WIN) | |
Peter Kasting
2017/05/15 21:51:27
Nit: Can we preserve some kind of TODO here about
Evan Stade
2017/05/15 22:25:16
I considered that TODO to refer to the ink drop ef
Peter Kasting
2017/05/15 23:41:02
OK. For reference, we want the condensibility on
Evan Stade
2017/05/16 23:50:13
added comment
| |
362 return (base::win::GetVersion() >= base::win::VERSION_WIN10) && | |
363 ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme(); | |
364 #else | |
365 return false; | |
366 #endif | |
367 } | |
OLD | NEW |