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

views: Remove InkDropMask from tab close button.

Modify the highlight path generator to use a round rect override so
that the ink drop clipping code will pick it up. Tab close buttons use
the content bounds, all other usages use the local buttons + fixed
inset, so tweak the API to allow for this.

Test: manual
Bug: 1056490
Change-Id: I9815c50ba1f79b3a40284c628eafcf50bcd9ce58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2307694
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790197}
parent d2bd56ab
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
#include "ui/base/pointer/touch_ui_controller.h" #include "ui/base/pointer/touch_ui_controller.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/ink_drop.h" #include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/controls/highlight_path_generator.h" #include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/layout/layout_provider.h" #include "ui/views/layout/layout_provider.h"
#include "ui/views/rect_based_targeting_utils.h" #include "ui/views/rect_based_targeting_utils.h"
...@@ -36,24 +36,6 @@ namespace { ...@@ -36,24 +36,6 @@ namespace {
constexpr int kGlyphWidth = 16; constexpr int kGlyphWidth = 16;
constexpr int kTouchGlyphWidth = 24; constexpr int kTouchGlyphWidth = 24;
class TabCloseButtonHighlightPathGenerator
: public views::HighlightPathGenerator {
public:
TabCloseButtonHighlightPathGenerator() = default;
// views::HighlightPathGenerator:
SkPath GetHighlightPath(const views::View* view) override {
const gfx::Rect bounds = view->GetContentsBounds();
const gfx::Point center = bounds.CenterPoint();
const int radius = views::LayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, bounds.size());
return SkPath().addCircle(center.x(), center.y(), radius);
}
private:
DISALLOW_COPY_AND_ASSIGN(TabCloseButtonHighlightPathGenerator);
};
} // namespace } // namespace
TabCloseButton::TabCloseButton(views::ButtonListener* listener, TabCloseButton::TabCloseButton(views::ButtonListener* listener,
...@@ -74,8 +56,10 @@ TabCloseButton::TabCloseButton(views::ButtonListener* listener, ...@@ -74,8 +56,10 @@ TabCloseButton::TabCloseButton(views::ButtonListener* listener,
GetInkDrop()->SetHoverHighlightFadeDuration(base::TimeDelta()); GetInkDrop()->SetHoverHighlightFadeDuration(base::TimeDelta());
SetInstallFocusRingOnFocus(true); SetInstallFocusRingOnFocus(true);
views::HighlightPathGenerator::Install( auto highlight_path =
this, std::make_unique<TabCloseButtonHighlightPathGenerator>()); std::make_unique<views::CircleHighlightPathGenerator>(gfx::Insets());
highlight_path->set_use_contents_bounds(true);
views::HighlightPathGenerator::Install(this, std::move(highlight_path));
} }
TabCloseButton::~TabCloseButton() {} TabCloseButton::~TabCloseButton() {}
...@@ -141,14 +125,6 @@ gfx::Size TabCloseButton::CalculatePreferredSize() const { ...@@ -141,14 +125,6 @@ gfx::Size TabCloseButton::CalculatePreferredSize() const {
return size; return size;
} }
std::unique_ptr<views::InkDropMask> TabCloseButton::CreateInkDropMask() const {
const gfx::Rect bounds = GetContentsBounds();
const int radius = views::LayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, bounds.size());
return std::make_unique<views::CircleInkDropMask>(
size(), GetMirroredRect(bounds).CenterPoint(), radius);
}
void TabCloseButton::PaintButtonContents(gfx::Canvas* canvas) { void TabCloseButton::PaintButtonContents(gfx::Canvas* canvas) {
cc::PaintFlags flags; cc::PaintFlags flags;
constexpr float kStrokeWidth = 1.5f; constexpr float kStrokeWidth = 1.5f;
......
...@@ -44,7 +44,6 @@ class TabCloseButton : public views::ImageButton, ...@@ -44,7 +44,6 @@ class TabCloseButton : public views::ImageButton,
void OnMouseReleased(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override;
void OnMouseMoved(const ui::MouseEvent& event) override; void OnMouseMoved(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
protected: protected:
// views::ImageButton: // views::ImageButton:
......
...@@ -51,7 +51,8 @@ base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect( ...@@ -51,7 +51,8 @@ base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect(
base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect( base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect(
const View* view) { const View* view) {
gfx::Rect bounds(view->GetLocalBounds()); gfx::Rect bounds =
use_contents_bounds_ ? view->GetContentsBounds() : view->GetLocalBounds();
bounds.Inset(insets_); bounds.Inset(insets_);
return GetRoundRect(gfx::RectF(bounds)); return GetRoundRect(gfx::RectF(bounds));
} }
......
...@@ -50,8 +50,15 @@ class VIEWS_EXPORT HighlightPathGenerator { ...@@ -50,8 +50,15 @@ class VIEWS_EXPORT HighlightPathGenerator {
virtual base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect); virtual base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect);
base::Optional<gfx::RRectF> GetRoundRect(const View* view); base::Optional<gfx::RRectF> GetRoundRect(const View* view);
void set_use_contents_bounds(bool use_contents_bounds) {
use_contents_bounds_ = use_contents_bounds;
}
private: private:
const gfx::Insets insets_; const gfx::Insets insets_;
// When set uses the view's content bounds instead of its local bounds.
bool use_contents_bounds_ = false;
}; };
// Sets a highlight path that is empty. This is used for ink drops that want to // Sets a highlight path that is empty. This is used for ink drops that want to
......
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