Commit 8711c1c8 authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Fix caption buttons ink drop highlight issue

The ink drop highlight lingers behind when the window and the
caption buttons are growing as a result of maximizing the window.
Sometimes it even sticks in the wrong place forever until the mouse
is moved.

This CL fixes the issue by painting the hover highlight in such
a way that simulates the AutoHighlightMode::SHOW_ON_RIPPLE mode.
This guarantees the highlight is always painted at the center of
button.

BUG=840901

Change-Id: I6096fef6605c262ca81c8526fea029e7dc459179
Reviewed-on: https://chromium-review.googlesource.com/1053805Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557692}
parent 242f9d41
...@@ -23,10 +23,7 @@ namespace { ...@@ -23,10 +23,7 @@ namespace {
// Ink drop parameters. // Ink drop parameters.
constexpr float kInkDropVisibleOpacity = 0.06f; constexpr float kInkDropVisibleOpacity = 0.06f;
constexpr float kHighlightVisibleOpacity = 0.08f;
constexpr int kInkDropCornerRadius = 14; constexpr int kInkDropCornerRadius = 14;
constexpr gfx::Size kInkDropHighlightSize{2 * kInkDropCornerRadius,
2 * kInkDropCornerRadius};
// The duration of the crossfade animation when swapping the button's images. // The duration of the crossfade animation when swapping the button's images.
const int kSwapImagesAnimationDurationMs = 200; const int kSwapImagesAnimationDurationMs = 200;
...@@ -58,6 +55,8 @@ bool UseLightColor(FrameCaptionButton::ColorMode color_mode, ...@@ -58,6 +55,8 @@ bool UseLightColor(FrameCaptionButton::ColorMode color_mode,
// from the button size in order to achieve a circular inkdrop with a size // from the button size in order to achieve a circular inkdrop with a size
// equals to kInkDropHighlightSize. // equals to kInkDropHighlightSize.
gfx::Insets GetInkdropInsets(const gfx::Size& button_size) { gfx::Insets GetInkdropInsets(const gfx::Size& button_size) {
constexpr gfx::Size kInkDropHighlightSize{2 * kInkDropCornerRadius,
2 * kInkDropCornerRadius};
return gfx::Insets( return gfx::Insets(
(button_size.height() - kInkDropHighlightSize.height()) / 2, (button_size.height() - kInkDropHighlightSize.height()) / 2,
(button_size.width() - kInkDropHighlightSize.width()) / 2); (button_size.width() - kInkDropHighlightSize.width()) / 2);
...@@ -190,9 +189,8 @@ views::PaintInfo::ScaleType FrameCaptionButton::GetPaintScaleType() const { ...@@ -190,9 +189,8 @@ views::PaintInfo::ScaleType FrameCaptionButton::GetPaintScaleType() const {
std::unique_ptr<views::InkDrop> FrameCaptionButton::CreateInkDrop() { std::unique_ptr<views::InkDrop> FrameCaptionButton::CreateInkDrop() {
auto ink_drop = std::make_unique<views::InkDropImpl>(this, size()); auto ink_drop = std::make_unique<views::InkDropImpl>(this, size());
ink_drop->SetAutoHighlightMode( ink_drop->SetAutoHighlightMode(views::InkDropImpl::AutoHighlightMode::NONE);
views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); ink_drop->SetShowHighlightOnHover(false);
ink_drop->SetShowHighlightOnHover(true);
return ink_drop; return ink_drop;
} }
...@@ -203,16 +201,6 @@ std::unique_ptr<views::InkDropRipple> FrameCaptionButton::CreateInkDropRipple() ...@@ -203,16 +201,6 @@ std::unique_ptr<views::InkDropRipple> FrameCaptionButton::CreateInkDropRipple()
GetInkDropBaseColor(), ink_drop_visible_opacity()); GetInkDropBaseColor(), ink_drop_visible_opacity());
} }
std::unique_ptr<views::InkDropHighlight>
FrameCaptionButton::CreateInkDropHighlight() const {
auto highlight = std::make_unique<views::InkDropHighlight>(
kInkDropHighlightSize, kInkDropCornerRadius,
gfx::PointF(GetMirroredRect(GetContentsBounds()).CenterPoint()),
GetInkDropBaseColor());
highlight->set_visible_opacity(kHighlightVisibleOpacity);
return highlight;
}
std::unique_ptr<views::InkDropMask> FrameCaptionButton::CreateInkDropMask() std::unique_ptr<views::InkDropMask> FrameCaptionButton::CreateInkDropMask()
const { const {
return std::make_unique<views::RoundRectInkDropMask>( return std::make_unique<views::RoundRectInkDropMask>(
...@@ -236,6 +224,30 @@ void FrameCaptionButton::SetColorMode(ColorMode color_mode) { ...@@ -236,6 +224,30 @@ void FrameCaptionButton::SetColorMode(ColorMode color_mode) {
} }
void FrameCaptionButton::PaintButtonContents(gfx::Canvas* canvas) { void FrameCaptionButton::PaintButtonContents(gfx::Canvas* canvas) {
constexpr SkAlpha kHighlightVisibleOpacity = 0x14;
SkAlpha highlight_alpha = SK_AlphaTRANSPARENT;
if (hover_animation().is_animating()) {
highlight_alpha = hover_animation().CurrentValueBetween(
SK_AlphaTRANSPARENT, kHighlightVisibleOpacity);
} else if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
// Painting a circular highlight in both "hovered" and "pressed" states
// simulates and ink drop highlight mode of
// AutoHighlightMode::SHOW_ON_RIPPLE.
highlight_alpha = kHighlightVisibleOpacity;
}
if (highlight_alpha != SK_AlphaTRANSPARENT) {
// We paint the highlight manually here rather than relying on the ink drop
// highlight as it doesn't work well when the button size is changing while
// the window is moving as a result of the animation from normal to
// maximized state or vice versa. https://crbug.com/840901.
cc::PaintFlags flags;
flags.setColor(GetInkDropBaseColor());
flags.setAlpha(highlight_alpha);
const gfx::Point center(GetMirroredRect(GetContentsBounds()).CenterPoint());
canvas->DrawCircle(center, kInkDropCornerRadius, flags);
}
int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255); int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255);
int crossfade_icon_alpha = 0; int crossfade_icon_alpha = 0;
if (icon_alpha < static_cast<int>(kFadeOutRatio * 255)) if (icon_alpha < static_cast<int>(kFadeOutRatio * 255))
......
...@@ -62,8 +62,6 @@ class ASH_EXPORT FrameCaptionButton : public views::Button { ...@@ -62,8 +62,6 @@ class ASH_EXPORT FrameCaptionButton : public views::Button {
// views::InkDropHostView: // views::InkDropHostView:
std::unique_ptr<views::InkDrop> CreateInkDrop() override; std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override; std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
void SetBackgroundColor(SkColor background_color); void SetBackgroundColor(SkColor background_color);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment