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

Reland "views: Remove InkDropMask from tab close button."

This is a reland of d939a1e1.

Keeps the ink drop clip and ring path generators separate, as the ring
handles RTL implicitly, but the clip do not.

Original change's description:
> 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: Peter Boström <pbos@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#790197}

Bug: 1056490
Change-Id: I85d9bb217ec3659fa5244e9280ac237a26323192
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2308874
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790940}
parent 903291d4
...@@ -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,
...@@ -73,9 +55,24 @@ TabCloseButton::TabCloseButton(views::ButtonListener* listener, ...@@ -73,9 +55,24 @@ TabCloseButton::TabCloseButton(views::ButtonListener* listener,
SetAnimationDuration(base::TimeDelta()); SetAnimationDuration(base::TimeDelta());
GetInkDrop()->SetHoverHighlightFadeDuration(base::TimeDelta()); GetInkDrop()->SetHoverHighlightFadeDuration(base::TimeDelta());
// The ink drop highlight path is the same as the focus ring highlight path,
// but needs to be explicitly mirrored for RTL.
// TODO(http://crbug.com/1056490): Make ink drops in RTL work the same way as
// focus rings.
auto ink_drop_highlight_path =
std::make_unique<views::CircleHighlightPathGenerator>(gfx::Insets());
ink_drop_highlight_path->set_use_contents_bounds(true);
ink_drop_highlight_path->set_use_mirrored_rect(true);
views::HighlightPathGenerator::Install(this,
std::move(ink_drop_highlight_path));
SetInstallFocusRingOnFocus(true); SetInstallFocusRingOnFocus(true);
views::HighlightPathGenerator::Install( // TODO(http://crbug.com/1056490): Once this bug is solved and explicit
this, std::make_unique<TabCloseButtonHighlightPathGenerator>()); // mirroring for ink drops is not needed, we can combine these two.
auto ring_highlight_path =
std::make_unique<views::CircleHighlightPathGenerator>(gfx::Insets());
ring_highlight_path->set_use_contents_bounds(true);
focus_ring()->SetPathGenerator(std::move(ring_highlight_path));
} }
TabCloseButton::~TabCloseButton() {} TabCloseButton::~TabCloseButton() {}
...@@ -141,14 +138,6 @@ gfx::Size TabCloseButton::CalculatePreferredSize() const { ...@@ -141,14 +138,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,8 +51,11 @@ base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect( ...@@ -51,8 +51,11 @@ 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_);
if (use_mirrored_rect_)
bounds = view->GetMirroredRect(bounds);
return GetRoundRect(gfx::RectF(bounds)); return GetRoundRect(gfx::RectF(bounds));
} }
......
...@@ -50,8 +50,27 @@ class VIEWS_EXPORT HighlightPathGenerator { ...@@ -50,8 +50,27 @@ 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;
}
void set_use_mirrored_rect(bool use_mirrored_rect) {
use_mirrored_rect_ = use_mirrored_rect;
}
private: private:
const gfx::Insets insets_; const gfx::Insets insets_;
// When set uses the view's content bounds instead of its local bounds.
// TODO(http://crbug.com/1056490): Investigate removing this and seeing if all
// ink drops / focus rings should use the content bounds.
bool use_contents_bounds_ = false;
// When set uses the mirror rect in RTL. This should not be needed for focus
// rings paths as they handle RTL themselves.
// TODO(http://crbug.com/1056490): Investigate moving FocusRing RTL to this
// class and removing this bool.
bool use_mirrored_rect_ = 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