Commit fa60a76a authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

views: Remove ink drop masks for views code.

Makes use of the clipping api for ink drop highlights/ripples.

ToggleButton: Ink-drop layers were always forwarded to the thumb view,
so the InkDropMask was unnecessary before.

FrameButton: InkDropMask relies a bit on the frame button internals, so
create a custom highlight path generator.

MediaButton: Used CircularMask which can be converted to a CircularPath.

Test: manual
Bug: 1056490
Change-Id: I16e4b853158136eee2ffba1a2de2b495437896f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310875Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790984}
parent 91436df9
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/canvas_painter.h" #include "ui/compositor/canvas_painter.h"
#include "ui/message_center/public/cpp/message_center_constants.h" #include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/animation/slide_out_controller.h" #include "ui/views/animation/slide_out_controller.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h" #include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -59,15 +59,12 @@ class MediaNotificationContainerImplView::DismissButton ...@@ -59,15 +59,12 @@ class MediaNotificationContainerImplView::DismissButton
explicit DismissButton(views::ButtonListener* listener) explicit DismissButton(views::ButtonListener* listener)
: views::ImageButton(listener) { : views::ImageButton(listener) {
views::ConfigureVectorImageButton(this); views::ConfigureVectorImageButton(this);
views::InstallFixedSizeCircleHighlightPathGenerator(
this, kDismissButtonBackgroundRadius);
} }
~DismissButton() override = default; ~DismissButton() override = default;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override {
return std::make_unique<views::CircleInkDropMask>(
size(), GetLocalBounds().CenterPoint(), kDismissButtonBackgroundRadius);
}
private: private:
DISALLOW_COPY_AND_ASSIGN(DismissButton); DISALLOW_COPY_AND_ASSIGN(DismissButton);
}; };
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/gfx/shadow_value.h" #include "ui/gfx/shadow_value.h"
#include "ui/gfx/skia_paint_util.h" #include "ui/gfx/skia_paint_util.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/animation/ink_drop_ripple.h" #include "ui/views/animation/ink_drop_ripple.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/highlight_path_generator.h" #include "ui/views/controls/highlight_path_generator.h"
...@@ -330,10 +329,6 @@ std::unique_ptr<InkDrop> ToggleButton::CreateInkDrop() { ...@@ -330,10 +329,6 @@ std::unique_ptr<InkDrop> ToggleButton::CreateInkDrop() {
return std::move(ink_drop); return std::move(ink_drop);
} }
std::unique_ptr<InkDropMask> ToggleButton::CreateInkDropMask() const {
return nullptr;
}
std::unique_ptr<InkDropRipple> ToggleButton::CreateInkDropRipple() const { std::unique_ptr<InkDropRipple> ToggleButton::CreateInkDropRipple() const {
gfx::Rect rect = thumb_view_->GetLocalBounds(); gfx::Rect rect = thumb_view_->GetLocalBounds();
rect.Inset(-ThumbView::GetShadowOutsets()); rect.Inset(-ThumbView::GetShadowOutsets());
......
...@@ -72,7 +72,6 @@ class VIEWS_EXPORT ToggleButton : public Button { ...@@ -72,7 +72,6 @@ class VIEWS_EXPORT ToggleButton : public Button {
void AddInkDropLayer(ui::Layer* ink_drop_layer) override; void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<InkDrop> CreateInkDrop() override; std::unique_ptr<InkDrop> CreateInkDrop() override;
std::unique_ptr<InkDropMask> CreateInkDropMask() const override;
std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
SkColor GetInkDropBaseColor() const override; SkColor GetInkDropBaseColor() const override;
......
...@@ -4,18 +4,24 @@ ...@@ -4,18 +4,24 @@
#include "ui/views/window/frame_caption_button.h" #include "ui/views/window/frame_caption_button.h"
#include <memory>
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/animation/throb_animation.h" #include "ui/gfx/animation/throb_animation.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/rrect_f.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h" #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_highlight.h" #include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h" #include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/animation/ink_drop_ripple.h" #include "ui/views/animation/ink_drop_ripple.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/window/caption_button_layout_constants.h" #include "ui/views/window/caption_button_layout_constants.h"
#include "ui/views/window/hit_test_utils.h" #include "ui/views/window/hit_test_utils.h"
...@@ -35,6 +41,29 @@ constexpr float kDisabledButtonAlphaRatio = 0.5f; ...@@ -35,6 +41,29 @@ constexpr float kDisabledButtonAlphaRatio = 0.5f;
} // namespace } // namespace
// Custom highlight path generator for clipping ink drops and drawing focus
// rings.
class FrameCaptionButton::HighlightPathGenerator
: public views::HighlightPathGenerator {
public:
explicit HighlightPathGenerator(FrameCaptionButton* frame_caption_button)
: frame_caption_button_(frame_caption_button) {}
HighlightPathGenerator(const HighlightPathGenerator&) = delete;
HighlightPathGenerator& operator=(const HighlightPathGenerator&) = delete;
~HighlightPathGenerator() override = default;
// views::HighlightPathGenerator:
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
gfx::Rect bounds = gfx::ToRoundedRect(rect);
bounds.Inset(frame_caption_button_->GetInkdropInsets(bounds.size()));
return gfx::RRectF(gfx::RectF(bounds),
frame_caption_button_->ink_drop_corner_radius());
}
private:
FrameCaptionButton* const frame_caption_button_;
};
// static // static
const char FrameCaptionButton::kViewClassName[] = "FrameCaptionButton"; const char FrameCaptionButton::kViewClassName[] = "FrameCaptionButton";
...@@ -58,6 +87,9 @@ FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener, ...@@ -58,6 +87,9 @@ FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener,
set_ink_drop_visible_opacity(kInkDropVisibleOpacity); set_ink_drop_visible_opacity(kInkDropVisibleOpacity);
UpdateInkDropBaseColor(); UpdateInkDropBaseColor();
views::HighlightPathGenerator::Install(
this, std::make_unique<HighlightPathGenerator>(this));
// Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left
// and snap right button icons should not be flipped. The other icons are // and snap right button icons should not be flipped. The other icons are
// horizontally symmetrical. // horizontally symmetrical.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/views/window/caption_button_types.h" #include "ui/views/window/caption_button_types.h"
...@@ -73,6 +74,7 @@ class VIEWS_EXPORT FrameCaptionButton : public views::Button { ...@@ -73,6 +74,7 @@ class VIEWS_EXPORT FrameCaptionButton : public views::Button {
void set_ink_drop_corner_radius(int ink_drop_corner_radius) { void set_ink_drop_corner_radius(int ink_drop_corner_radius) {
ink_drop_corner_radius_ = ink_drop_corner_radius; ink_drop_corner_radius_ = ink_drop_corner_radius;
} }
int ink_drop_corner_radius() const { return ink_drop_corner_radius_; }
CaptionButtonIcon icon() const { return icon_; } CaptionButtonIcon icon() const { return icon_; }
...@@ -87,6 +89,8 @@ class VIEWS_EXPORT FrameCaptionButton : public views::Button { ...@@ -87,6 +89,8 @@ class VIEWS_EXPORT FrameCaptionButton : public views::Button {
void PaintButtonContents(gfx::Canvas* canvas) override; void PaintButtonContents(gfx::Canvas* canvas) override;
private: private:
class HighlightPathGenerator;
// Determines what alpha to use for the icon based on animation and // Determines what alpha to use for the icon based on animation and
// active state. // active state.
int GetAlphaForIcon(int base_alpha) const; int GetAlphaForIcon(int base_alpha) const;
......
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