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