Commit b25e7445 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Add HighlightPathGenerator to TabCloseButton

Replaces OnBoundsChanged override which resulted in a lot of path
generation (per-tab + frame) while opening new tabs or resizing the
window.

Also removes a ::GetInkDropMask() override which just generated the same
path.

Bug: chromium:1007546
Change-Id: I0131f9a589c1525e2c0eacd61c9fcd9f6ac05948
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1861016
Auto-Submit: Peter Boström <pbos@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705972}
parent 2c27da07
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
#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/animation/ink_drop_mask.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"
#include "ui/views/view_class_properties.h"
#if defined(USE_AURA) #if defined(USE_AURA)
#include "ui/aura/env.h" #include "ui/aura/env.h"
...@@ -35,6 +35,25 @@ ...@@ -35,6 +35,25 @@
namespace { 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,
...@@ -55,6 +74,8 @@ TabCloseButton::TabCloseButton(views::ButtonListener* listener, ...@@ -55,6 +74,8 @@ TabCloseButton::TabCloseButton(views::ButtonListener* listener,
GetInkDrop()->SetHoverHighlightFadeDuration(base::TimeDelta()); GetInkDrop()->SetHoverHighlightFadeDuration(base::TimeDelta());
SetInstallFocusRingOnFocus(true); SetInstallFocusRingOnFocus(true);
views::HighlightPathGenerator::Install(
this, std::make_unique<TabCloseButtonHighlightPathGenerator>());
} }
TabCloseButton::~TabCloseButton() {} TabCloseButton::~TabCloseButton() {}
...@@ -120,25 +141,6 @@ gfx::Size TabCloseButton::CalculatePreferredSize() const { ...@@ -120,25 +141,6 @@ gfx::Size TabCloseButton::CalculatePreferredSize() const {
return size; return size;
} }
void TabCloseButton::OnBoundsChanged(const gfx::Rect& previous_bounds) {
ImageButton::OnBoundsChanged(previous_bounds);
auto path = std::make_unique<SkPath>();
const gfx::Rect bounds = GetContentsBounds();
const gfx::Point center = bounds.CenterPoint();
const int radius = views::LayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, bounds.size());
path->addCircle(center.x(), center.y(), radius);
SetProperty(views::kHighlightPathKey, path.release());
}
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,12 +44,10 @@ class TabCloseButton : public views::ImageButton, ...@@ -44,12 +44,10 @@ 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:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void PaintButtonContents(gfx::Canvas* canvas) override; void PaintButtonContents(gfx::Canvas* canvas) override;
private: private:
......
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