Index: chrome/browser/ui/views/profiles/new_avatar_button.cc |
diff --git a/chrome/browser/ui/views/profiles/new_avatar_button.cc b/chrome/browser/ui/views/profiles/new_avatar_button.cc |
index 795ca239a216e99c1280e4eaff0747fdef293a11..24893dcdabb8d0b626dbd04169318a2be69b08a7 100644 |
--- a/chrome/browser/ui/views/profiles/new_avatar_button.cc |
+++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc |
@@ -12,16 +12,19 @@ |
#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/themes/theme_properties.h" |
#include "chrome/browser/ui/views/profiles/avatar_button_delegate.h" |
#include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
#include "chrome/grit/theme_resources.h" |
#include "components/signin/core/common/profile_management_switches.h" |
#include "ui/base/resource/resource_bundle.h" |
+#include "ui/base/theme_provider.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/animation/ink_drop_mask.h" |
#include "ui/views/border.h" |
#include "ui/views/controls/button/label_button_border.h" |
#include "ui/views/painter.h" |
@@ -32,6 +35,65 @@ |
namespace { |
+// Insets between view bounds and the filled region for |
+// AvatarButtonThemedBorder. |
+static constexpr gfx::InsetsF kFillInsets(1); |
+ |
+// Corner radius of the roundrect for AvatarButtonThemedBorder. |
+static constexpr float kCornerRadius = 1; |
+ |
+// This class draws the border (and background) of the avatar button for |
+// "themed" browser windows, i.e. OpaqueBrowserFrameView. Currently it's only |
+// used on Linux as the shape specifically matches the Linux caption buttons. |
+// TODO(estade): make this look nice on Windows and use it there as well. |
+class AvatarButtonThemedBorder : public views::Border { |
+ public: |
+ AvatarButtonThemedBorder() {} |
+ ~AvatarButtonThemedBorder() override {} |
+ |
+ void Paint(const views::View& view, gfx::Canvas* canvas) override { |
+ gfx::RectF fill_bounds(view.GetLocalBounds()); |
+ fill_bounds.Inset(kFillInsets); |
+ cc::PaintFlags fill_flags; |
+ fill_flags.setStyle(cc::PaintFlags::kFill_Style); |
+ fill_flags.setColor(view.GetThemeProvider()->GetColor( |
+ ThemeProperties::COLOR_BUTTON_BACKGROUND)); |
+ fill_flags.setAntiAlias(true); |
+ canvas->DrawRoundRect(fill_bounds, kCornerRadius, fill_flags); |
+ |
+ // Start with an outer dark stroke. |
+ cc::PaintFlags stroke_flags; |
+ stroke_flags.setStyle(cc::PaintFlags::kStroke_Style); |
+ stroke_flags.setColor(SkColorSetA(SK_ColorBLACK, 0x2B)); |
+ stroke_flags.setStrokeWidth(1); |
+ stroke_flags.setAntiAlias(true); |
+ gfx::RectF stroke_bounds(view.GetLocalBounds()); |
+ stroke_bounds.Inset(gfx::InsetsF(0.5f)); |
+ canvas->DrawRoundRect(stroke_bounds, kCornerRadius, stroke_flags); |
+ |
+ // There's a second, light stroke that matches the fill bounds. |
Peter Kasting
2017/04/27 02:13:18
I'm a little worried about the radii of the corner
|
+ stroke_bounds.Inset(kFillInsets); |
+ stroke_flags.setColor(SkColorSetA(SK_ColorWHITE, 0x3F)); |
+ canvas->DrawRoundRect(stroke_bounds, kCornerRadius, stroke_flags); |
+ } |
+ |
+ gfx::Insets GetInsets() const override { |
+ const int kLeftRightInset = 8; |
+ const int kTopInset = 2; |
+ const int kBottomInset = 4; |
+ return gfx::Insets(kTopInset, kLeftRightInset, kBottomInset, |
+ kLeftRightInset); |
+ } |
+ |
+ gfx::Size GetMinimumSize() const override { |
+ return gfx::Size(GetInsets().width(), GetInsets().height()); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(AvatarButtonThemedBorder); |
+}; |
+ |
+#if !defined(OS_LINUX) |
std::unique_ptr<views::Border> CreateBorder(const int normal_image_set[], |
const int hot_image_set[], |
const int pushed_image_set[]) { |
@@ -52,6 +114,7 @@ std::unique_ptr<views::Border> CreateBorder(const int normal_image_set[], |
return std::move(border); |
} |
+#endif |
} // namespace |
@@ -78,14 +141,21 @@ NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate, |
label()->font_list().DeriveWithHeightUpperBound(kDisplayFontHeight)); |
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
+ generic_avatar_ = |
+ rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_AVATAR).AsImageSkia(); |
+#if defined(OS_LINUX) |
+ DCHECK_EQ(AvatarButtonStyle::THEMED, button_style); |
+ SetBorder(base::MakeUnique<AvatarButtonThemedBorder>()); |
+ SetInkDropMode(InkDropMode::ON); |
+#else // !defined(OS_LINUX) |
if (button_style == AvatarButtonStyle::THEMED) { |
+ SetBorder(base::MakeUnique<AvatarButtonThemedBorder>()); |
+ SetInkDropMode(InkDropMode::ON); |
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); |
@@ -105,6 +175,7 @@ NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate, |
generic_avatar_ = |
*rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia(); |
} |
+#endif // !defined(OS_LINUX) |
g_browser_process->profile_manager()-> |
GetProfileAttributesStorage().AddObserver(this); |
@@ -130,6 +201,25 @@ void NewAvatarButton::OnMouseReleased(const ui::MouseEvent& event) { |
LabelButton::OnMouseReleased(event); |
} |
+SkColor NewAvatarButton::GetInkDropBaseColor() const { |
+ return SK_ColorWHITE; |
Evan Stade
2017/04/26 19:24:49
I stuck with white because the theme-colored backg
Peter Kasting
2017/04/27 02:13:18
Is the drop visible at all on a pure-white toolbar
|
+} |
+ |
+std::unique_ptr<views::InkDropMask> NewAvatarButton::CreateInkDropMask() const { |
+ return base::MakeUnique<views::RoundRectInkDropMask>(size(), kFillInsets, |
+ kCornerRadius); |
+} |
+ |
+void NewAvatarButton::NotifyClick(const ui::Event& event) { |
+ LabelButton::NotifyClick(event); |
+ |
+ if (ProfileChooserView::IsShowing() && ink_drop_mode() == InkDropMode::ON) { |
+ ProfileChooserView::GetCurrentBubbleWidget()->AddObserver(this); |
+ AnimateInkDrop(views::InkDropState::ACTIVATED, |
+ ui::LocatedEvent::FromIfValid(&event)); |
+ } |
+} |
+ |
void NewAvatarButton::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 |
@@ -171,6 +261,11 @@ void NewAvatarButton::OnProfileSupervisedUserIdChanged( |
Update(); |
} |
+void NewAvatarButton::OnWidgetClosing(views::Widget* widget) { |
+ if (ink_drop_mode() == InkDropMode::ON) |
+ AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); |
+} |
+ |
void NewAvatarButton::Update() { |
ProfileAttributesStorage& storage = |
g_browser_process->profile_manager()->GetProfileAttributesStorage(); |