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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/app/vector_icons/vector_icons.h" | 10 #include "chrome/app/vector_icons/vector_icons.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profiles/profile_attributes_entry.h" | 12 #include "chrome/browser/profiles/profile_attributes_entry.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/profiles/profiles_state.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
15 #include "chrome/browser/signin/signin_manager_factory.h" | |
15 #include "chrome/browser/ui/views/profiles/avatar_button_delegate.h" | 16 #include "chrome/browser/ui/views/profiles/avatar_button_delegate.h" |
16 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 17 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
18 #include "chrome/browser/ui/views/tabs/tab_strip.h" | |
17 #include "chrome/grit/theme_resources.h" | 19 #include "chrome/grit/theme_resources.h" |
18 #include "components/signin/core/common/profile_management_switches.h" | 20 #include "components/signin/core/common/profile_management_switches.h" |
19 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/color_palette.h" | 23 #include "ui/gfx/color_palette.h" |
22 #include "ui/gfx/geometry/vector2d.h" | 24 #include "ui/gfx/geometry/vector2d.h" |
23 #include "ui/gfx/paint_vector_icon.h" | 25 #include "ui/gfx/paint_vector_icon.h" |
24 #include "ui/vector_icons/vector_icons.h" | 26 #include "ui/vector_icons/vector_icons.h" |
27 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | |
28 #include "ui/views/animation/ink_drop_impl.h" | |
25 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
26 #include "ui/views/controls/button/label_button_border.h" | 30 #include "ui/views/controls/button/label_button_border.h" |
27 #include "ui/views/painter.h" | 31 #include "ui/views/painter.h" |
28 | 32 |
29 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
30 #include "base/win/windows_version.h" | 34 #include "base/win/windows_version.h" |
31 #endif | 35 #endif |
32 | 36 |
37 // Minimum and maximum width of the MD button | |
38 const int kMdButtonMinWidth = 48; | |
39 const int kMdButtonMaxWidth = 96; | |
40 // Height of the non-MD (pre-Windows 10) button | |
41 const int kButtonNonMdHeight = 20; | |
42 // Height of the "cozy" MD button that ("tall" MD button height is computed) | |
43 const int kButtonMdCozyHeight = 22; | |
44 // Opacity of the ink drop on hover | |
45 const float kHighlightInkDropOpacity = 0.08f; | |
46 // Opacity of the ink drop on click, which is added to kHighlightInkDropOpacity | |
47 const float kRippleInkDropOpacity = 0.04f; | |
48 | |
33 namespace { | 49 namespace { |
34 | 50 |
35 std::unique_ptr<views::Border> CreateBorder(const int normal_image_set[], | 51 std::unique_ptr<views::Border> CreateBorder(const int normal_image_set[], |
36 const int hot_image_set[], | 52 const int hot_image_set[], |
37 const int pushed_image_set[]) { | 53 const int pushed_image_set[]) { |
38 std::unique_ptr<views::LabelButtonAssetBorder> border( | 54 std::unique_ptr<views::LabelButtonAssetBorder> border( |
39 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); | 55 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); |
40 border->SetPainter(false, views::Button::STATE_NORMAL, | 56 border->SetPainter(false, views::Button::STATE_NORMAL, |
41 views::Painter::CreateImageGridPainter(normal_image_set)); | 57 views::Painter::CreateImageGridPainter(normal_image_set)); |
42 border->SetPainter(false, views::Button::STATE_HOVERED, | 58 border->SetPainter(false, views::Button::STATE_HOVERED, |
43 views::Painter::CreateImageGridPainter(hot_image_set)); | 59 views::Painter::CreateImageGridPainter(hot_image_set)); |
44 border->SetPainter(false, views::Button::STATE_PRESSED, | 60 border->SetPainter(false, views::Button::STATE_PRESSED, |
45 views::Painter::CreateImageGridPainter(pushed_image_set)); | 61 views::Painter::CreateImageGridPainter(pushed_image_set)); |
46 | 62 |
47 const int kLeftRightInset = 8; | 63 const int kLeftRightInset = 8; |
48 const int kTopInset = 2; | 64 const int kTopInset = 2; |
49 const int kBottomInset = 4; | 65 const int kBottomInset = 4; |
50 border->set_insets(gfx::Insets(kTopInset, kLeftRightInset, | 66 border->set_insets( |
51 kBottomInset, kLeftRightInset)); | 67 gfx::Insets(kTopInset, kLeftRightInset, kBottomInset, kLeftRightInset)); |
52 | 68 |
53 return std::move(border); | 69 return std::move(border); |
54 } | 70 } |
55 | 71 |
56 } // namespace | 72 } // namespace |
57 | 73 |
58 NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate, | 74 AvatarButton::AvatarButton(AvatarButtonDelegate* delegate, Profile* profile) |
59 AvatarButtonStyle button_style, | 75 : MenuButton(base::string16(), delegate, false), |
60 Profile* profile) | |
61 : LabelButton(delegate, base::string16()), | |
62 delegate_(delegate), | 76 delegate_(delegate), |
63 error_controller_(this, profile), | 77 error_controller_(this, profile), |
64 profile_(profile), | 78 profile_(profile) { |
65 suppress_mouse_released_action_(false) { | 79 set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
66 set_triggerable_event_flags( | 80 set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
67 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 81 ui::EF_RIGHT_MOUSE_BUTTON); |
68 set_animate_on_state_change(false); | 82 set_animate_on_state_change(false); |
69 SetEnabledTextColors(SK_ColorWHITE); | 83 SetEnabledTextColors(SK_ColorWHITE); |
70 SetTextSubpixelRenderingEnabled(false); | 84 SetTextSubpixelRenderingEnabled(false); |
71 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 85 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
72 | 86 |
87 g_browser_process->profile_manager() | |
88 ->GetProfileAttributesStorage() | |
89 .AddObserver(this); | |
90 | |
73 // The largest text height that fits in the button. If the font list height | 91 // The largest text height that fits in the button. If the font list height |
74 // is larger than this, it will be shrunk to match it. | 92 // is larger than this, it will be shrunk to match it. |
75 // TODO(noms): Calculate this constant algorithmically from the button's size. | 93 // TODO(noms): Calculate this constant algorithmically from the button's size. |
76 const int kDisplayFontHeight = 16; | 94 const int kDisplayFontHeight = 16; |
77 SetFontList( | 95 SetFontList( |
78 label()->font_list().DeriveWithHeightUpperBound(kDisplayFontHeight)); | 96 label()->font_list().DeriveWithHeightUpperBound(kDisplayFontHeight)); |
79 | |
80 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
81 if (button_style == AvatarButtonStyle::THEMED) { | |
82 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | |
83 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | |
84 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | |
85 | |
86 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | |
87 generic_avatar_ = | |
88 *rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_AVATAR).ToImageSkia(); | |
89 #if defined(OS_WIN) | |
90 } else if (base::win::GetVersion() < base::win::VERSION_WIN8) { | |
91 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); | |
92 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); | |
93 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); | |
94 | |
95 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | |
96 generic_avatar_ = | |
97 *rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_AVATAR).ToImageSkia(); | |
98 #endif | |
99 } else { | |
100 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); | |
101 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER); | |
102 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED); | |
103 | |
104 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | |
105 generic_avatar_ = | |
106 *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia(); | |
107 } | |
108 | |
109 g_browser_process->profile_manager()-> | |
110 GetProfileAttributesStorage().AddObserver(this); | |
111 Update(); | |
112 SchedulePaint(); | |
113 } | 97 } |
114 | 98 |
115 NewAvatarButton::~NewAvatarButton() { | 99 AvatarButton::~AvatarButton() { |
116 g_browser_process->profile_manager()-> | 100 g_browser_process->profile_manager() |
117 GetProfileAttributesStorage().RemoveObserver(this); | 101 ->GetProfileAttributesStorage() |
102 .RemoveObserver(this); | |
118 } | 103 } |
119 | 104 |
120 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { | 105 bool AvatarButton::IsTriggerableEvent(const ui::Event& event) { |
121 // Prevent the bubble from being re-shown if it's already showing. | 106 return event.type() == ui::ET_GESTURE_LONG_PRESS || |
122 suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); | 107 MenuButton::IsTriggerableEvent(event); |
123 return LabelButton::OnMousePressed(event); | |
124 } | 108 } |
125 | 109 |
126 void NewAvatarButton::OnMouseReleased(const ui::MouseEvent& event) { | 110 void AvatarButton::OnAvatarErrorChanged() { |
127 if (suppress_mouse_released_action_) | |
128 suppress_mouse_released_action_ = false; | |
129 else | |
130 LabelButton::OnMouseReleased(event); | |
131 } | |
132 | |
133 void NewAvatarButton::OnGestureEvent(ui::GestureEvent* event) { | |
134 // TODO(wjmaclean): The check for ET_GESTURE_LONG_PRESS is done here since | |
135 // no other UI button based on CustomButton appears to handle mouse | |
136 // right-click. If other cases are identified, it may make sense to move this | |
137 // check to CustomButton. | |
138 if (event->type() == ui::ET_GESTURE_LONG_PRESS) | |
139 NotifyClick(*event); | |
140 else | |
141 LabelButton::OnGestureEvent(event); | |
142 } | |
143 | |
144 void NewAvatarButton::OnAvatarErrorChanged() { | |
145 Update(); | 111 Update(); |
146 } | 112 } |
147 | 113 |
148 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { | 114 void AvatarButton::OnProfileAdded(const base::FilePath& profile_path) { |
149 Update(); | 115 Update(); |
150 } | 116 } |
151 | 117 |
152 void NewAvatarButton::OnProfileWasRemoved( | 118 void AvatarButton::OnProfileWasRemoved(const base::FilePath& profile_path, |
153 const base::FilePath& profile_path, | 119 const base::string16& profile_name) { |
154 const base::string16& profile_name) { | |
155 // If deleting the active profile, don't bother updating the avatar | 120 // If deleting the active profile, don't bother updating the avatar |
156 // button, as the browser window is being closed anyway. | 121 // button, as the browser window is being closed anyway. |
157 if (profile_->GetPath() != profile_path) | 122 if (profile_->GetPath() != profile_path) |
158 Update(); | 123 Update(); |
159 } | 124 } |
160 | 125 |
161 void NewAvatarButton::OnProfileNameChanged( | 126 void AvatarButton::OnProfileNameChanged( |
162 const base::FilePath& profile_path, | 127 const base::FilePath& profile_path, |
163 const base::string16& old_profile_name) { | 128 const base::string16& old_profile_name) { |
164 if (profile_->GetPath() == profile_path) | 129 if (profile_->GetPath() == profile_path) |
165 Update(); | 130 Update(); |
166 } | 131 } |
167 | 132 |
168 void NewAvatarButton::OnProfileSupervisedUserIdChanged( | 133 void AvatarButton::OnProfileSupervisedUserIdChanged( |
169 const base::FilePath& profile_path) { | 134 const base::FilePath& profile_path) { |
170 if (profile_->GetPath() == profile_path) | 135 if (profile_->GetPath() == profile_path) |
171 Update(); | 136 Update(); |
172 } | 137 } |
173 | 138 |
174 void NewAvatarButton::Update() { | 139 void AvatarButton::Update() { |
175 ProfileAttributesStorage& storage = | 140 ProfileAttributesStorage& storage = |
176 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 141 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
177 | 142 |
178 // If we have a single local profile, then use the generic avatar | 143 // If we have a single local profile, then use the generic avatar |
179 // button instead of the profile name. Never use the generic button if | 144 // button instead of the profile name. Never use the generic button if |
180 // the active profile is Guest. | 145 // the active profile is Guest. |
146 | |
msarda
2017/04/21 09:43:28
Remove blank line.
emx
2017/04/24 16:23:10
Done.
| |
181 const bool use_generic_button = | 147 const bool use_generic_button = |
182 !profile_->IsGuestSession() && | 148 !profile_->IsGuestSession() && storage.GetNumberOfProfiles() == 1 && |
183 storage.GetNumberOfProfiles() == 1 && | 149 !SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated(); |
184 !storage.GetAllProfilesAttributes().front()->IsAuthenticated(); | |
185 | 150 |
151 UpdateButton(use_generic_button, profile_, &error_controller_); | |
152 | |
153 PreferredSizeChanged(); | |
154 delegate_->ButtonPreferredSizeChanged(); | |
155 } | |
156 | |
157 void AvatarButton::UpdateButton(bool use_generic_button, | |
158 Profile* profile, | |
159 AvatarButtonErrorController* error_controller) { | |
186 SetText(use_generic_button | 160 SetText(use_generic_button |
187 ? base::string16() | 161 ? base::string16() |
188 : profiles::GetAvatarButtonTextForProfile(profile_)); | 162 : profiles::GetAvatarButtonTextForProfile(profile)); |
189 | 163 |
190 // If the button has no text, clear the text shadows to make sure the | 164 // If the button has no text, clear the text shadows to make sure the |
191 // image is centered correctly. | 165 // image is centered correctly. |
192 SetTextShadows( | 166 SetTextShadows( |
193 use_generic_button | 167 use_generic_button |
194 ? gfx::ShadowValues() | 168 ? gfx::ShadowValues() |
195 : gfx::ShadowValues( | 169 : gfx::ShadowValues( |
196 10, gfx::ShadowValue(gfx::Vector2d(), 2.0f, SK_ColorDKGRAY))); | 170 10, gfx::ShadowValue(gfx::Vector2d(), 2.0f, SK_ColorDKGRAY))); |
197 | 171 |
198 // We want the button to resize if the new text is shorter. | 172 // We want the button to resize if the new text is shorter. |
199 SetMinSize(gfx::Size()); | 173 SetMinSize(gfx::Size()); |
200 | 174 |
201 if (use_generic_button) { | 175 if (use_generic_button) { |
202 SetImage(views::Button::STATE_NORMAL, generic_avatar_); | 176 SetImage(views::Button::STATE_NORMAL, generic_avatar_); |
203 } else if (error_controller_.HasAvatarError()) { | 177 } else if (error_controller->HasAvatarError()) { |
204 SetImage(views::Button::STATE_NORMAL, | 178 SetImage(views::Button::STATE_NORMAL, |
205 gfx::CreateVectorIcon(kSyncProblemIcon, 16, gfx::kGoogleRed700)); | 179 gfx::CreateVectorIcon(kSyncProblemIcon, 16, gfx::kGoogleRed700)); |
206 } else { | 180 } else { |
207 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); | 181 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); |
208 } | 182 } |
209 | 183 |
210 // If we are not using the generic button, then reset the spacing between | 184 // If we are not using the generic button, then reset the spacing between |
211 // the text and the possible authentication error icon. | 185 // the text and the possible authentication error icon. |
212 const int kDefaultImageTextSpacing = 5; | 186 const int kDefaultImageTextSpacing = 5; |
213 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); | 187 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); |
188 } | |
214 | 189 |
215 PreferredSizeChanged(); | 190 void AvatarButton::SetButtonAndBorder(const int button_idr, |
216 delegate_->ButtonPreferredSizeChanged(); | 191 const int normal_image_set[], |
192 const int hover_image_set[], | |
193 const int pressed_image_set[]) { | |
194 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
195 SetBorder(CreateBorder(normal_image_set, hover_image_set, pressed_image_set)); | |
196 generic_avatar_ = *rb->GetImageNamed(button_idr).ToImageSkia(); | |
217 } | 197 } |
198 | |
199 //----------------------------------------------------------------------- | |
200 //----------------------------------------------------------------------- | |
201 //----------------------------------------------------------------------- | |
202 | |
203 NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate, | |
204 AvatarButtonStyle button_style, | |
205 Profile* profile) | |
206 : AvatarButton(delegate, profile) { | |
207 if (button_style == AvatarButtonStyle::THEMED) { | |
208 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | |
209 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | |
210 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | |
211 SetButtonAndBorder(IDR_AVATAR_THEMED_BUTTON_AVATAR, kNormalImageSet, | |
212 kHoverImageSet, kPressedImageSet); | |
213 #if defined(OS_WIN) | |
214 } else if (base::win::GetVersion() < base::win::VERSION_WIN8) { | |
215 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); | |
216 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); | |
217 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); | |
218 SetButtonAndBorder(IDR_AVATAR_GLASS_BUTTON_AVATAR, kNormalImageSet, | |
219 kHoverImageSet, kPressedImageSet); | |
220 #endif | |
221 } else { | |
222 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); | |
223 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER); | |
224 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED); | |
225 SetButtonAndBorder(IDR_AVATAR_NATIVE_BUTTON_AVATAR, kNormalImageSet, | |
226 kHoverImageSet, kPressedImageSet); | |
227 } | |
228 | |
229 Update(); | |
230 SchedulePaint(); | |
231 } | |
232 | |
233 NewAvatarButton::~NewAvatarButton() {} | |
234 | |
235 gfx::Size NewAvatarButton::GetPreferredSize() const { | |
236 gfx::Size ps = views::MenuButton::GetPreferredSize(); | |
237 ps.set_height(kButtonNonMdHeight); | |
238 return ps; | |
239 } | |
240 | |
241 //----------------------------------------------------------------------- | |
242 //----------------------------------------------------------------------- | |
243 //----------------------------------------------------------------------- | |
244 | |
245 MaterialDesignAvatarButton::MaterialDesignAvatarButton( | |
246 AvatarButtonDelegate* delegate, | |
247 Profile* profile, | |
248 BrowserView* browser_view) | |
249 : AvatarButton(delegate, profile), browser_view_(browser_view) { | |
250 DCHECK(browser_view); | |
251 | |
252 // The MD button uses the same set of (completely transparent) borders | |
253 // for all 3 states - highlighting is provided by the ink drop. | |
254 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_MD_BUTTON_NORMAL); | |
255 SetButtonAndBorder(IDR_AVATAR_MD_BUTTON_AVATAR, kNormalImageSet, | |
256 kNormalImageSet, kNormalImageSet); | |
257 | |
258 Update(); | |
259 SchedulePaint(); | |
260 | |
261 SetInkDropMode(InkDropMode::ON); | |
262 set_has_ink_drop_action_on_click(true); | |
263 SetFocusPainter(nullptr); | |
264 set_ink_drop_base_color(SK_ColorBLACK); | |
265 set_ink_drop_visible_opacity(kRippleInkDropOpacity); | |
266 } | |
267 | |
268 MaterialDesignAvatarButton::~MaterialDesignAvatarButton() {} | |
269 | |
270 gfx::Size MaterialDesignAvatarButton::GetPreferredSize() const { | |
271 gfx::Size ps = views::MenuButton::GetPreferredSize(); | |
272 ps.set_width( | |
273 std::min(std::max(ps.width(), kMdButtonMinWidth), kMdButtonMaxWidth)); | |
274 ps.set_height(browser_view_->frame()->GetMinimizeButtonHeight()); | |
275 return ps; | |
276 } | |
277 | |
278 std::unique_ptr<views::InkDrop> MaterialDesignAvatarButton::CreateInkDrop() { | |
279 return CreateDefaultFloodFillInkDropImpl(); | |
280 } | |
281 | |
282 std::unique_ptr<views::InkDropHighlight> | |
283 MaterialDesignAvatarButton::CreateInkDropHighlight() const { | |
284 auto center = gfx::RectF(gfx::Rect(size())).CenterPoint(); | |
285 auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>( | |
286 size(), 0, center, GetInkDropBaseColor()); | |
287 ink_drop_highlight->set_visible_opacity(kHighlightInkDropOpacity); | |
288 return ink_drop_highlight; | |
289 } | |
290 | |
291 std::unique_ptr<views::InkDropRipple> | |
292 MaterialDesignAvatarButton::CreateInkDropRipple() const { | |
293 return base::MakeUnique<views::FloodFillInkDropRipple>( | |
294 size(), GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), | |
295 ink_drop_visible_opacity()); | |
296 } | |
297 | |
298 void MaterialDesignAvatarButton::UpdateButtonHeightForPosition( | |
299 const int button_x, | |
300 int* button_height) const { | |
301 TabStrip* tab_strip = browser_view_->tabstrip(); | |
302 if (!tab_strip) | |
303 return; | |
304 | |
305 // In RTL the new tab button is on the left, so it can never slide under the | |
306 // avatar button (which is still on the right). May as well use the space. | |
307 if (base::i18n::IsRTL()) | |
308 return; | |
309 | |
310 // Use the "cozy" button if the tabstrip can slide under it | |
311 if (tab_strip->max_x() >= button_x) { | |
312 *button_height = kButtonMdCozyHeight; | |
313 } | |
314 } | |
OLD | NEW |