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

Unified Diff: chrome/browser/ui/views/profiles/avatar_button.cc

Issue 2851543002: Update avatar button to MD (part 1) (Closed)
Patch Set: Rebased on CL 2868293002 [Rename new_avatar_button.* to avatar_button] 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/profiles/avatar_button.cc
diff --git a/chrome/browser/ui/views/profiles/avatar_button.cc b/chrome/browser/ui/views/profiles/avatar_button.cc
index bf5b01f591a2b543e8b01af7197586037c480944..52ccf5ebe9bf782d8da036bb9c286359b98ba676 100644
--- a/chrome/browser/ui/views/profiles/avatar_button.cc
+++ b/chrome/browser/ui/views/profiles/avatar_button.cc
@@ -6,70 +6,82 @@
#include <utility>
-#include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
-#include "chrome/browser/ui/views/profiles/avatar_button_delegate.h"
-#include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/browser/themes/theme_service.h"
+#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/grit/theme_resources.h"
-#include "components/signin/core/common/profile_management_switches.h"
+#include "components/signin/core/browser/signin_manager.h"
#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
-#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/paint_vector_icon.h"
-#include "ui/vector_icons/vector_icons.h"
-#include "ui/views/border.h"
+#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
+#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/controls/button/label_button_border.h"
-#include "ui/views/painter.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
+#include "chrome/browser/ui/views/frame/minimize_button_metrics_win.h"
#endif
namespace {
-std::unique_ptr<views::Border> CreateBorder(const int normal_image_set[],
- const int hot_image_set[],
- const int pushed_image_set[]) {
+std::unique_ptr<views::Border> CreateThemedBorder(
+ const int normal_image_set[],
+ const int hot_image_set[],
+ const int pushed_image_set[]) {
std::unique_ptr<views::LabelButtonAssetBorder> border(
new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON));
+
border->SetPainter(false, views::Button::STATE_NORMAL,
- views::Painter::CreateImageGridPainter(normal_image_set));
+ views::Painter::CreateImageGridPainter(normal_image_set));
border->SetPainter(false, views::Button::STATE_HOVERED,
- views::Painter::CreateImageGridPainter(hot_image_set));
+ views::Painter::CreateImageGridPainter(hot_image_set));
border->SetPainter(false, views::Button::STATE_PRESSED,
- views::Painter::CreateImageGridPainter(pushed_image_set));
+ views::Painter::CreateImageGridPainter(pushed_image_set));
const int kLeftRightInset = 8;
const int kTopInset = 2;
const int kBottomInset = 4;
- border->set_insets(gfx::Insets(kTopInset, kLeftRightInset,
- kBottomInset, kLeftRightInset));
+ border->set_insets(
+ gfx::Insets(kTopInset, kLeftRightInset, kBottomInset, kLeftRightInset));
return std::move(border);
}
+std::unique_ptr<views::Border> CreateWin10NativeBorder() {
+ // These insets look OK at 100%, 125%, 150%, 175% and 200% scaling.
+ const int kLeftRightInset = 8;
+ const int kTopInset = 1;
+ const int kBottomInset = 3;
+ return views::CreateEmptyBorder(kTopInset, kLeftRightInset, kBottomInset,
+ kLeftRightInset);
+}
+
} // namespace
-NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate,
- AvatarButtonStyle button_style,
- Profile* profile)
- : LabelButton(delegate, base::string16()),
- delegate_(delegate),
+AvatarButton::AvatarButton(views::ButtonListener* listener,
+ AvatarButtonStyle button_style,
+ Profile* profile)
+ : LabelButton(listener, base::string16()),
error_controller_(this, profile),
profile_(profile),
- suppress_mouse_released_action_(false) {
- set_triggerable_event_flags(
- ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON);
+ profile_observer_(this),
+ use_win10_native_button_(false) {
+ set_notify_action(CustomButton::NOTIFY_ON_PRESS);
+ set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
+ ui::EF_RIGHT_MOUSE_BUTTON);
set_animate_on_state_change(false);
SetEnabledTextColors(SK_ColorWHITE);
SetTextSubpixelRenderingEnabled(false);
SetHorizontalAlignment(gfx::ALIGN_CENTER);
+ profile_observer_.Add(
+ &g_browser_process->profile_manager()->GetProfileAttributesStorage());
+
// The largest text height that fits in the button. If the font list height
// is larger than this, it will be shrunk to match it.
// TODO(noms): Calculate this constant algorithmically from the button's size.
@@ -77,60 +89,62 @@ NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate,
SetFontList(
label()->font_list().DeriveWithHeightUpperBound(kDisplayFontHeight));
- ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
- if (button_style == AvatarButtonStyle::THEMED) {
- const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
- const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
- const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
-
- SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
- generic_avatar_ =
- *rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_AVATAR).ToImageSkia();
#if defined(OS_WIN)
- } else if (base::win::GetVersion() < base::win::VERSION_WIN8) {
- const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
- const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
- const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
-
- SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
- generic_avatar_ =
- *rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_AVATAR).ToImageSkia();
-#endif
+ // TODO: use MD button in other cases, too [http://crbug.com/591586]
+ if ((base::win::GetVersion() >= base::win::VERSION_WIN10) &&
+ ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
+ DCHECK_EQ(AvatarButtonStyle::NATIVE, button_style);
+ use_win10_native_button_ = true;
+ }
+#endif // defined(OS_WIN)
+
+ if (use_win10_native_button_) {
+ constexpr int kMdButtonIconHeight = 16;
+ constexpr SkColor kMdButtonIconColor =
+ SkColorSetA(SK_ColorBLACK, 0.54 * 0xFF);
Peter Kasting 2017/05/11 01:03:43 Nit: static_cast second arg to SkAlpha
emx 2017/05/11 12:56:11 Done.
+ generic_avatar_ = gfx::CreateVectorIcon(
+ kAccountCircleIcon, kMdButtonIconHeight, kMdButtonIconColor);
+ SetBorder(CreateWin10NativeBorder());
+
+ SetInkDropMode(InkDropMode::ON);
+ set_has_ink_drop_action_on_click(true);
+ SetFocusPainter(nullptr);
+ set_ink_drop_base_color(SK_ColorBLACK);
} else {
- const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
- const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
- const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
-
- SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
- generic_avatar_ =
- *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia();
+ if (button_style == AvatarButtonStyle::THEMED) {
+ const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
+ const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
+ const int kPressedImageSet[] =
+ IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
+ SetButtonAvatar(IDR_AVATAR_THEMED_BUTTON_AVATAR);
+ SetBorder(CreateThemedBorder(kNormalImageSet, kHoverImageSet,
+ kPressedImageSet));
+#if defined(OS_WIN)
+ } else if (base::win::GetVersion() < base::win::VERSION_WIN8) {
+ const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
+ const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
+ const int kPressedImageSet[] =
+ IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
+ SetButtonAvatar(IDR_AVATAR_GLASS_BUTTON_AVATAR);
+ SetBorder(CreateThemedBorder(kNormalImageSet, kHoverImageSet,
+ kPressedImageSet));
+#endif
+ } else {
+ const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
+ const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
+ const int kPressedImageSet[] =
+ IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
+ SetButtonAvatar(IDR_AVATAR_NATIVE_BUTTON_AVATAR);
+ SetBorder(CreateThemedBorder(kNormalImageSet, kHoverImageSet,
+ kPressedImageSet));
+ }
}
- g_browser_process->profile_manager()->
- GetProfileAttributesStorage().AddObserver(this);
Update();
SchedulePaint();
}
-NewAvatarButton::~NewAvatarButton() {
- g_browser_process->profile_manager()->
- GetProfileAttributesStorage().RemoveObserver(this);
-}
-
-bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) {
- // Prevent the bubble from being re-shown if it's already showing.
- suppress_mouse_released_action_ = ProfileChooserView::IsShowing();
- return LabelButton::OnMousePressed(event);
-}
-
-void NewAvatarButton::OnMouseReleased(const ui::MouseEvent& event) {
- if (suppress_mouse_released_action_)
- suppress_mouse_released_action_ = false;
- else
- LabelButton::OnMouseReleased(event);
-}
-
-void NewAvatarButton::OnGestureEvent(ui::GestureEvent* event) {
+void AvatarButton::OnGestureEvent(ui::GestureEvent* event) {
// TODO(wjmaclean): The check for ET_GESTURE_LONG_PRESS is done here since
// no other UI button based on CustomButton appears to handle mouse
// right-click. If other cases are identified, it may make sense to move this
@@ -141,37 +155,83 @@ void NewAvatarButton::OnGestureEvent(ui::GestureEvent* event) {
LabelButton::OnGestureEvent(event);
}
-void NewAvatarButton::OnAvatarErrorChanged() {
+gfx::Size AvatarButton::GetMinimumSize() const {
+ if (use_win10_native_button_) {
+ // Returns the size of the button when it is atop the tabstrip. Called by
+ // GlassBrowserFrameView::LayoutProfileSwitcher().
+ return gfx::Size(MinimizeButtonMetrics::GetCaptionButtonWidthInDIPs(), 20);
Peter Kasting 2017/05/11 01:03:43 Nit: Ultimately we'll probably want to calculate t
emx 2017/05/11 12:56:11 Done.
+ }
+
+ return LabelButton::GetMinimumSize();
+}
+
+gfx::Size AvatarButton::GetPreferredSize() const {
+ gfx::Size size = LabelButton::GetPreferredSize();
+
+ if (use_win10_native_button_) {
+#if defined(OS_WIN)
+ // Returns the normal size of the button (when it does not overlap the
+ // tabstrip). Its height should match the caption button height.
+ // The minimum width is the caption button width and the maximum is fixed
+ // as per the spec in http://crbug.com/635699.
+ const int min_width = MinimizeButtonMetrics::GetCaptionButtonWidthInDIPs();
+ constexpr int kMdButtonMaxWidth = 98;
+ size.set_width(
+ std::min(std::max(size.width(), min_width), kMdButtonMaxWidth));
+ size.set_height(MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs());
+#endif
+ } else {
+ size.set_height(20);
Peter Kasting 2017/05/11 01:03:43 Nit: Should this 20 and the 20 in GetMinimumSize()
emx 2017/05/11 12:56:11 I've wondered that as well, but I don't think they
+ }
+
+ return size;
+}
+
+std::unique_ptr<views::InkDropHighlight> AvatarButton::CreateInkDropHighlight()
+ const {
+ auto center = gfx::RectF(GetLocalBounds()).CenterPoint();
+ auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>(
+ size(), 0, center, GetInkDropBaseColor());
+ // Opacity of the ink drop on hover
Peter Kasting 2017/05/11 01:03:43 Nit: Comment looks like it just restates the code,
emx 2017/05/11 12:56:11 Done.
+ constexpr float kInkDropHighlightOpacity = 0.08f;
+ ink_drop_highlight->set_visible_opacity(kInkDropHighlightOpacity);
+ return ink_drop_highlight;
+}
+
+bool AvatarButton::ShouldUseFloodFillInkDrop() const {
+ return true;
+}
+
+void AvatarButton::OnAvatarErrorChanged() {
Update();
}
-void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) {
+void AvatarButton::OnProfileAdded(const base::FilePath& profile_path) {
Update();
}
-void NewAvatarButton::OnProfileWasRemoved(
- const base::FilePath& profile_path,
- const base::string16& profile_name) {
+void AvatarButton::OnProfileWasRemoved(const base::FilePath& profile_path,
+ const base::string16& profile_name) {
// If deleting the active profile, don't bother updating the avatar
// button, as the browser window is being closed anyway.
if (profile_->GetPath() != profile_path)
Update();
}
-void NewAvatarButton::OnProfileNameChanged(
- const base::FilePath& profile_path,
- const base::string16& old_profile_name) {
+void AvatarButton::OnProfileNameChanged(
+ const base::FilePath& profile_path,
+ const base::string16& old_profile_name) {
if (profile_->GetPath() == profile_path)
Update();
}
-void NewAvatarButton::OnProfileSupervisedUserIdChanged(
- const base::FilePath& profile_path) {
+void AvatarButton::OnProfileSupervisedUserIdChanged(
+ const base::FilePath& profile_path) {
if (profile_->GetPath() == profile_path)
Update();
}
-void NewAvatarButton::Update() {
+void AvatarButton::Update() {
ProfileAttributesStorage& storage =
g_browser_process->profile_manager()->GetProfileAttributesStorage();
@@ -179,9 +239,8 @@ void NewAvatarButton::Update() {
// button instead of the profile name. Never use the generic button if
// the active profile is Guest.
const bool use_generic_button =
- !profile_->IsGuestSession() &&
- storage.GetNumberOfProfiles() == 1 &&
- !storage.GetAllProfilesAttributes().front()->IsAuthenticated();
+ !profile_->IsGuestSession() && storage.GetNumberOfProfiles() == 1 &&
+ !SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated();
SetText(use_generic_button
? base::string16()
@@ -213,5 +272,9 @@ void NewAvatarButton::Update() {
SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing);
PreferredSizeChanged();
- delegate_->ButtonPreferredSizeChanged();
+}
+
+void AvatarButton::SetButtonAvatar(int avatar_idr) {
+ ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
+ generic_avatar_ = *rb->GetImageNamed(avatar_idr).ToImageSkia();
}

Powered by Google App Engine
This is Rietveld 408576698