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

Unify ink-drop style to flood fill with masks.

This change makes flood fill the default ink-drop style. Square InkDrops
are currently bugs in the browser that are kind-of hidden by InkDrop
masks.

It makes use of the same path that FocusRing uses for masks to make sure
that the InkDrop and FocusRing are in sync by default. These mismatch
bugs keep popping up, especially on Mac, as testers verify new parts of
the UI.

Follow-up changes will be to reduce the number of classes that override
CreateInkDrop methods and make sure that they explicitly request a
SquareInkDrop when they want it.

Bug: chromium:888204, chromium:907833, chromium:915284

Change-Id: I681b93d6f5bdfe7f78421ebc8f2fbd522fb6eee4
Reviewed-on: https://chromium-review.googlesource.com/c/1367186
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarMohsen Izadi <mohsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619533}
parent eae570f9
...@@ -500,10 +500,6 @@ void DownloadItemView::OnThemeChanged() { ...@@ -500,10 +500,6 @@ void DownloadItemView::OnThemeChanged() {
UpdateDropdownButton(); UpdateDropdownButton();
} }
std::unique_ptr<views::InkDrop> DownloadItemView::CreateInkDrop() {
return CreateDefaultFloodFillInkDropImpl();
}
void DownloadItemView::OnInkDropCreated() { void DownloadItemView::OnInkDropCreated() {
ConfigureInkDrop(); ConfigureInkDrop();
} }
......
...@@ -106,7 +106,6 @@ class DownloadItemView : public views::InkDropHostView, ...@@ -106,7 +106,6 @@ class DownloadItemView : public views::InkDropHostView,
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// view::InkDropHostView: // view::InkDropHostView:
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
void OnInkDropCreated() override; void OnInkDropCreated() override;
SkColor GetInkDropBaseColor() const override; SkColor GetInkDropBaseColor() const override;
......
...@@ -289,8 +289,7 @@ SkColor HoverButton::GetInkDropBaseColor() const { ...@@ -289,8 +289,7 @@ SkColor HoverButton::GetInkDropBaseColor() const {
} }
std::unique_ptr<views::InkDrop> HoverButton::CreateInkDrop() { std::unique_ptr<views::InkDrop> HoverButton::CreateInkDrop() {
std::unique_ptr<views::InkDrop> ink_drop = std::unique_ptr<views::InkDrop> ink_drop = MenuButton::CreateInkDrop();
CreateDefaultFloodFillInkDropImpl();
// Turn on highlighting when the button is focused only - hovering the button // Turn on highlighting when the button is focused only - hovering the button
// will request focus. // will request focus.
ink_drop->SetShowHighlightOnFocus(true); ink_drop->SetShowHighlightOnFocus(true);
......
...@@ -270,10 +270,6 @@ int BrowserAppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { ...@@ -270,10 +270,6 @@ int BrowserAppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) {
return ui::DragDropTypes::DRAG_MOVE; return ui::DragDropTypes::DRAG_MOVE;
} }
std::unique_ptr<views::InkDrop> BrowserAppMenuButton::CreateInkDrop() {
return CreateToolbarInkDrop(this);
}
std::unique_ptr<views::InkDropHighlight> std::unique_ptr<views::InkDropHighlight>
BrowserAppMenuButton::CreateInkDropHighlight() const { BrowserAppMenuButton::CreateInkDropHighlight() const {
return CreateToolbarInkDropHighlight(this); return CreateToolbarInkDropHighlight(this);
......
...@@ -75,7 +75,6 @@ class BrowserAppMenuButton : public AppMenuButton, ...@@ -75,7 +75,6 @@ class BrowserAppMenuButton : public AppMenuButton,
int OnDragUpdated(const ui::DropTargetEvent& event) override; int OnDragUpdated(const ui::DropTargetEvent& event) override;
void OnDragExited() override; void OnDragExited() override;
int OnPerformDrop(const ui::DropTargetEvent& event) override; int OnPerformDrop(const ui::DropTargetEvent& event) override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override; const override;
SkColor GetInkDropBaseColor() const override; SkColor GetInkDropBaseColor() const override;
......
...@@ -120,14 +120,9 @@ SkColor ToolbarActionView::GetInkDropBaseColor() const { ...@@ -120,14 +120,9 @@ SkColor ToolbarActionView::GetInkDropBaseColor() const {
return GetToolbarInkDropBaseColor(this); return GetToolbarInkDropBaseColor(this);
} }
bool ToolbarActionView::ShouldUseFloodFillInkDrop() const {
return delegate_->ShownInsideMenu();
}
std::unique_ptr<views::InkDrop> ToolbarActionView::CreateInkDrop() { std::unique_ptr<views::InkDrop> ToolbarActionView::CreateInkDrop() {
auto ink_drop = CreateToolbarInkDrop(this); auto ink_drop = MenuButton::CreateInkDrop();
ink_drop->SetShowHighlightOnHover(!delegate_->ShownInsideMenu()); ink_drop->SetShowHighlightOnHover(!delegate_->ShownInsideMenu());
ink_drop->SetShowHighlightOnFocus(!focus_ring());
return ink_drop; return ink_drop;
} }
......
...@@ -70,7 +70,6 @@ class ToolbarActionView : public views::MenuButton, ...@@ -70,7 +70,6 @@ class ToolbarActionView : public views::MenuButton,
const override; const override;
bool IsTriggerableEvent(const ui::Event& event) override; bool IsTriggerableEvent(const ui::Event& event) override;
SkColor GetInkDropBaseColor() const override; SkColor GetInkDropBaseColor() const override;
bool ShouldUseFloodFillInkDrop() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override; std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override; const override;
......
...@@ -225,10 +225,6 @@ void ToolbarButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -225,10 +225,6 @@ void ToolbarButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetDefaultActionVerb(ax::mojom::DefaultActionVerb::kPress); node_data->SetDefaultActionVerb(ax::mojom::DefaultActionVerb::kPress);
} }
std::unique_ptr<views::InkDrop> ToolbarButton::CreateInkDrop() {
return CreateToolbarInkDrop(this);
}
std::unique_ptr<views::InkDropHighlight> ToolbarButton::CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> ToolbarButton::CreateInkDropHighlight()
const { const {
return CreateToolbarInkDropHighlight(this); return CreateToolbarInkDropHighlight(this);
......
...@@ -77,7 +77,6 @@ class ToolbarButton : public views::LabelButton, ...@@ -77,7 +77,6 @@ class ToolbarButton : public views::LabelButton,
void OnMouseExited(const ui::MouseEvent& event) override; void OnMouseExited(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override; const override;
SkColor GetInkDropBaseColor() const override; SkColor GetInkDropBaseColor() const override;
......
...@@ -52,17 +52,6 @@ void SetToolbarButtonHighlightPath(views::View* host_view, ...@@ -52,17 +52,6 @@ void SetToolbarButtonHighlightPath(views::View* host_view,
host_view->SetProperty(views::kHighlightPathKey, path.release()); host_view->SetProperty(views::kHighlightPathKey, path.release());
} }
std::unique_ptr<views::InkDrop> CreateToolbarInkDrop(
views::InkDropHostView* host_view) {
auto ink_drop =
std::make_unique<views::InkDropImpl>(host_view, host_view->size());
ink_drop->SetAutoHighlightMode(
views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE);
ink_drop->SetShowHighlightOnHover(true);
ink_drop->SetShowHighlightOnFocus(!views::PlatformStyle::kPreferFocusRings);
return ink_drop;
}
std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight( std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
const views::InkDropHostView* host_view) { const views::InkDropHostView* host_view) {
constexpr float kToolbarInkDropHighlightVisibleOpacity = 0.08f; constexpr float kToolbarInkDropHighlightVisibleOpacity = 0.08f;
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
namespace views { namespace views {
class InkDrop;
class InkDropHighlight; class InkDropHighlight;
class InkDropHostView; class InkDropHostView;
class View; class View;
...@@ -30,11 +29,6 @@ gfx::Insets GetToolbarInkDropInsets(const views::View* host_view, ...@@ -30,11 +29,6 @@ gfx::Insets GetToolbarInkDropInsets(const views::View* host_view,
void SetToolbarButtonHighlightPath(views::View* host_view, void SetToolbarButtonHighlightPath(views::View* host_view,
const gfx::Insets& margin_insets); const gfx::Insets& margin_insets);
// Creates an ink drop that shows a highlight on hover that is kept and combined
// with the ripple when the ripple is shown.
std::unique_ptr<views::InkDrop> CreateToolbarInkDrop(
views::InkDropHostView* host_view);
// Creates the default inkdrop highlight but using the toolbar visible opacity. // Creates the default inkdrop highlight but using the toolbar visible opacity.
std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight( std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
const views::InkDropHostView* host_view); const views::InkDropHostView* host_view);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/views/animation/ink_drop_mask.h" #include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/animation/ink_drop_stub.h" #include "ui/views/animation/ink_drop_stub.h"
#include "ui/views/animation/square_ink_drop_ripple.h" #include "ui/views/animation/square_ink_drop_ripple.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/style/platform_style.h" #include "ui/views/style/platform_style.h"
#include "ui/views/view_properties.h" #include "ui/views/view_properties.h"
...@@ -146,32 +147,20 @@ void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { ...@@ -146,32 +147,20 @@ void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
} }
std::unique_ptr<InkDrop> InkDropHostView::CreateInkDrop() { std::unique_ptr<InkDrop> InkDropHostView::CreateInkDrop() {
return CreateDefaultInkDropImpl(); return CreateDefaultFloodFillInkDropImpl();
} }
std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const {
if (GetProperty(kHighlightPathKey)) { return std::make_unique<views::FloodFillInkDropRipple>(
return std::make_unique<views::FloodFillInkDropRipple>( size(), gfx::Insets(), GetInkDropCenterBasedOnLastEvent(),
size(), gfx::Insets(), GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), ink_drop_visible_opacity());
GetInkDropBaseColor(), ink_drop_visible_opacity());
}
return CreateDefaultInkDropRipple(
GetMirroredRect(GetContentsBounds()).CenterPoint());
} }
std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
const { const {
std::unique_ptr<InkDropHighlight> highlight; auto highlight = std::make_unique<views::InkDropHighlight>(
size(), 0, gfx::RectF(GetMirroredRect(GetLocalBounds())).CenterPoint(),
if (GetProperty(kHighlightPathKey)) { GetInkDropBaseColor());
highlight = std::make_unique<views::InkDropHighlight>(
size(), 0, gfx::RectF(GetMirroredRect(GetLocalBounds())).CenterPoint(),
GetInkDropBaseColor());
} else {
highlight = CreateDefaultInkDropHighlight(
gfx::RectF(GetMirroredRect(GetContentsBounds())).CenterPoint());
}
// TODO(pbos): Once |ink_drop_highlight_opacity_| is either always set or // TODO(pbos): Once |ink_drop_highlight_opacity_| is either always set or
// callers are using the default InkDropHighlight value then make this a // callers are using the default InkDropHighlight value then make this a
// constructor argument to InkDropHighlight. // constructor argument to InkDropHighlight.
...@@ -182,10 +171,8 @@ std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() ...@@ -182,10 +171,8 @@ std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
} }
std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const { std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const {
if (SkPath* highlight_path = GetProperty(kHighlightPathKey)) return std::make_unique<views::PathInkDropMask>(size(),
return std::make_unique<views::PathInkDropMask>(size(), *highlight_path); GetHighlightPath(this));
return nullptr;
} }
SkColor InkDropHostView::GetInkDropBaseColor() const { SkColor InkDropHostView::GetInkDropBaseColor() const {
...@@ -259,7 +246,7 @@ std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() { ...@@ -259,7 +246,7 @@ std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() {
std::unique_ptr<InkDropImpl> std::unique_ptr<InkDropImpl>
InkDropHostView::CreateDefaultFloodFillInkDropImpl() { InkDropHostView::CreateDefaultFloodFillInkDropImpl() {
std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); auto ink_drop = std::make_unique<InkDropImpl>(this, size());
ink_drop->SetAutoHighlightMode( ink_drop->SetAutoHighlightMode(
views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE);
return ink_drop; return ink_drop;
...@@ -268,6 +255,12 @@ InkDropHostView::CreateDefaultFloodFillInkDropImpl() { ...@@ -268,6 +255,12 @@ InkDropHostView::CreateDefaultFloodFillInkDropImpl() {
std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple(
const gfx::Point& center_point, const gfx::Point& center_point,
const gfx::Size& size) const { const gfx::Size& size) const {
return CreateSquareInkDropRipple(center_point, size);
}
std::unique_ptr<InkDropRipple> InkDropHostView::CreateSquareInkDropRipple(
const gfx::Point& center_point,
const gfx::Size& size) const {
auto ripple = std::make_unique<SquareInkDropRipple>( auto ripple = std::make_unique<SquareInkDropRipple>(
CalculateLargeInkDropSize(size), ink_drop_large_corner_radius_, size, CalculateLargeInkDropSize(size), ink_drop_large_corner_radius_, size,
ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor(), ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor(),
...@@ -278,6 +271,12 @@ std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( ...@@ -278,6 +271,12 @@ std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple(
std::unique_ptr<InkDropHighlight> std::unique_ptr<InkDropHighlight>
InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point, InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point,
const gfx::Size& size) const { const gfx::Size& size) const {
return CreateSquareInkDropHighlight(center_point, size);
}
std::unique_ptr<InkDropHighlight> InkDropHostView::CreateSquareInkDropHighlight(
const gfx::PointF& center_point,
const gfx::Size& size) const {
auto highlight = std::make_unique<InkDropHighlight>( auto highlight = std::make_unique<InkDropHighlight>(
size, ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor()); size, ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor());
highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size))); highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size)));
......
...@@ -134,26 +134,38 @@ class VIEWS_EXPORT InkDropHostView : public View { ...@@ -134,26 +134,38 @@ class VIEWS_EXPORT InkDropHostView : public View {
void OnFocus() override; void OnFocus() override;
void OnBlur() override; void OnBlur() override;
// Returns an InkDropImpl with default configuration. The base implementation // Returns an InkDropImpl suitable for use with a square ink drop.
// of CreateInkDrop() delegates to this function. // TODO(pbos): Rename to CreateDefaultSquareInkDropImpl.
std::unique_ptr<InkDropImpl> CreateDefaultInkDropImpl(); std::unique_ptr<InkDropImpl> CreateDefaultInkDropImpl();
// Returns an InkDropImpl configured to work well with a flood-fill ink drop // Returns an InkDropImpl configured to work well with a flood-fill ink drop
// ripple. // ripple.
std::unique_ptr<InkDropImpl> CreateDefaultFloodFillInkDropImpl(); std::unique_ptr<InkDropImpl> CreateDefaultFloodFillInkDropImpl();
// Returns the default InkDropRipple centered on |center_point|. // TODO(pbos): Migrate uses to CreateSquareInkDropRipple which this calls
// directly.
std::unique_ptr<InkDropRipple> CreateDefaultInkDropRipple( std::unique_ptr<InkDropRipple> CreateDefaultInkDropRipple(
const gfx::Point& center_point, const gfx::Point& center_point,
const gfx::Size& size = gfx::Size(kDefaultInkDropSize, const gfx::Size& size = gfx::Size(kDefaultInkDropSize,
kDefaultInkDropSize)) const; kDefaultInkDropSize)) const;
// Returns the default InkDropHighlight centered on |center_point|. // Creates a SquareInkDropRipple centered on |center_point|.
std::unique_ptr<InkDropRipple> CreateSquareInkDropRipple(
const gfx::Point& center_point,
const gfx::Size& size) const;
// TODO(pbos): Migrate uses to CreateSquareInkDropHighlight which this calls
// directly.
std::unique_ptr<InkDropHighlight> CreateDefaultInkDropHighlight( std::unique_ptr<InkDropHighlight> CreateDefaultInkDropHighlight(
const gfx::PointF& center_point, const gfx::PointF& center_point,
const gfx::Size& size = gfx::Size(kDefaultInkDropSize, const gfx::Size& size = gfx::Size(kDefaultInkDropSize,
kDefaultInkDropSize)) const; kDefaultInkDropSize)) const;
// Creates a InkDropHighlight centered on |center_point|.
std::unique_ptr<InkDropHighlight> CreateSquareInkDropHighlight(
const gfx::PointF& center_point,
const gfx::Size& size) const;
// Returns true if an ink drop instance has been created. // Returns true if an ink drop instance has been created.
bool HasInkDrop() const; bool HasInkDrop() const;
......
...@@ -621,10 +621,6 @@ void InkDropImpl::SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode) { ...@@ -621,10 +621,6 @@ void InkDropImpl::SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode) {
SetHighlightState(highlight_state_factory_->CreateStartState()); SetHighlightState(highlight_state_factory_->CreateStartState());
} }
void InkDropImpl::SetAutoHighlightModeForPlatform() {
SetAutoHighlightMode(AutoHighlightMode::HIDE_ON_RIPPLE);
}
void InkDropImpl::HostSizeChanged(const gfx::Size& new_size) { void InkDropImpl::HostSizeChanged(const gfx::Size& new_size) {
// |root_layer_| should fill the entire host because it affects the clipping // |root_layer_| should fill the entire host because it affects the clipping
// when a mask layer is applied to it. This will not affect clipping if no // when a mask layer is applied to it. This will not affect clipping if no
......
...@@ -60,13 +60,10 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop, ...@@ -60,13 +60,10 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
// This method is intended as a configuration option to be used after // This method is intended as a configuration option to be used after
// construction. Behavior is undefined if |this| has already handled any // construction. Behavior is undefined if |this| has already handled any
// InkDrop inherited functions. // InkDrop inherited functions.
// TODO(pbos): Move along with AutoHighlightMode to views::InkDrop so users
// can configure inkdrops created by parent classes.
void SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode); void SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode);
// Sets the AutoHighlightMode as per the platform. Platforms that show ripples
// will be set to HIDE_ON_RIPPLE, and platforms that don't show ripples are
// set to SHOW_ON_RIPPLE highlight behavior.
void SetAutoHighlightModeForPlatform();
const base::Optional<int>& hover_highlight_fade_duration_ms() const { const base::Optional<int>& hover_highlight_fade_duration_ms() const {
return hover_highlight_fade_duration_ms_; return hover_highlight_fade_duration_ms_;
} }
......
...@@ -492,10 +492,9 @@ void Button::RemovedFromWidget() { ...@@ -492,10 +492,9 @@ void Button::RemovedFromWidget() {
} }
std::unique_ptr<InkDrop> Button::CreateInkDrop() { std::unique_ptr<InkDrop> Button::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); std::unique_ptr<InkDrop> ink_drop = InkDropHostView::CreateInkDrop();
ink_drop->SetShowHighlightOnFocus(!focus_ring_); ink_drop->SetShowHighlightOnFocus(!focus_ring_);
ink_drop->SetAutoHighlightModeForPlatform(); return ink_drop;
return std::move(ink_drop);
} }
SkColor Button::GetInkDropBaseColor() const { SkColor Button::GetInkDropBaseColor() const {
......
...@@ -107,7 +107,6 @@ void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) { ...@@ -107,7 +107,6 @@ void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) {
} }
std::unique_ptr<InkDrop> Checkbox::CreateInkDrop() { std::unique_ptr<InkDrop> Checkbox::CreateInkDrop() {
// Completely removes the highlight.
std::unique_ptr<InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); std::unique_ptr<InkDropImpl> ink_drop = CreateDefaultInkDropImpl();
ink_drop->SetShowHighlightOnHover(false); ink_drop->SetShowHighlightOnHover(false);
ink_drop->SetAutoHighlightMode(InkDropImpl::AutoHighlightMode::NONE); ink_drop->SetAutoHighlightMode(InkDropImpl::AutoHighlightMode::NONE);
...@@ -116,8 +115,8 @@ std::unique_ptr<InkDrop> Checkbox::CreateInkDrop() { ...@@ -116,8 +115,8 @@ std::unique_ptr<InkDrop> Checkbox::CreateInkDrop() {
std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const { std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const {
// The "small" size is 21dp, the large size is 1.33 * 21dp = 28dp. // The "small" size is 21dp, the large size is 1.33 * 21dp = 28dp.
return CreateDefaultInkDropRipple(image()->GetMirroredBounds().CenterPoint(), return CreateSquareInkDropRipple(image()->GetMirroredBounds().CenterPoint(),
gfx::Size(21, 21)); gfx::Size(21, 21));
} }
SkColor Checkbox::GetInkDropBaseColor() const { SkColor Checkbox::GetInkDropBaseColor() const {
......
...@@ -18,11 +18,7 @@ ...@@ -18,11 +18,7 @@
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/geometry/vector2d.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop.h" #include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/square_ink_drop_ripple.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/button/label_button_border.h" #include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/button/label_button_label.h" #include "ui/views/controls/button/label_button_label.h"
...@@ -342,10 +338,6 @@ gfx::Rect LabelButton::GetChildAreaBounds() { ...@@ -342,10 +338,6 @@ gfx::Rect LabelButton::GetChildAreaBounds() {
return GetLocalBounds(); return GetLocalBounds();
} }
bool LabelButton::ShouldUseFloodFillInkDrop() const {
return !GetText().empty();
}
void LabelButton::OnFocus() { void LabelButton::OnFocus() {
Button::OnFocus(); Button::OnFocus();
// Typically the border renders differently when focused. // Typically the border renders differently when focused.
...@@ -382,39 +374,6 @@ void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { ...@@ -382,39 +374,6 @@ void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); ink_drop_container_->RemoveInkDropLayer(ink_drop_layer);
} }
std::unique_ptr<InkDrop> LabelButton::CreateInkDrop() {
return ShouldUseFloodFillInkDrop() ? CreateDefaultFloodFillInkDropImpl()
: Button::CreateInkDrop();
}
std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const {
// Views that use a highlight path use the base style and do not need the
// overrides in this file.
if (GetProperty(views::kHighlightPathKey))
return InkDropHostView::CreateInkDropRipple();
return ShouldUseFloodFillInkDrop()
? std::make_unique<views::FloodFillInkDropRipple>(
size(), GetInkDropCenterBasedOnLastEvent(),
GetInkDropBaseColor(), ink_drop_visible_opacity())
: CreateDefaultInkDropRipple(
image()->GetMirroredBounds().CenterPoint());
}
std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight()
const {
// Views that use a highlight path use the base style and do not need the
// overrides in this file.
if (GetProperty(views::kHighlightPathKey))
return InkDropHostView::CreateInkDropHighlight();
return ShouldUseFloodFillInkDrop()
? std::make_unique<views::InkDropHighlight>(
size(), ink_drop_small_corner_radius(),
gfx::RectF(GetLocalBounds()).CenterPoint(),
GetInkDropBaseColor())
: CreateDefaultInkDropHighlight(
gfx::RectF(image()->GetMirroredBounds()).CenterPoint());
}
void LabelButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { void LabelButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
if (is_default()) if (is_default())
node_data->AddState(ax::mojom::State::kDefault); node_data->AddState(ax::mojom::State::kDefault);
......
...@@ -95,9 +95,6 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate { ...@@ -95,9 +95,6 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
void EnableCanvasFlippingForRTLUI(bool flip) override; void EnableCanvasFlippingForRTLUI(bool flip) override;
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<InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
protected: protected:
...@@ -115,10 +112,6 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate { ...@@ -115,10 +112,6 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
// these bounds if they need room to do manual painting. // these bounds if they need room to do manual painting.
virtual gfx::Rect GetChildAreaBounds(); virtual gfx::Rect GetChildAreaBounds();
// Returns true if the CreateInkDrop*() methods should create flood fill ink
// drop components.
virtual bool ShouldUseFloodFillInkDrop() const;
// View: // View:
void OnFocus() override; void OnFocus() override;
void OnBlur() override; void OnBlur() override;
......
...@@ -99,18 +99,6 @@ SkColor MdTextButton::GetInkDropBaseColor() const { ...@@ -99,18 +99,6 @@ SkColor MdTextButton::GetInkDropBaseColor() const {
return color_utils::DeriveDefaultIconColor(label()->enabled_color()); return color_utils::DeriveDefaultIconColor(label()->enabled_color());
} }
std::unique_ptr<InkDrop> MdTextButton::CreateInkDrop() {
return CreateDefaultFloodFillInkDropImpl();
}
std::unique_ptr<views::InkDropRipple> MdTextButton::CreateInkDropRipple()
const {
return std::unique_ptr<views::InkDropRipple>(
new views::FloodFillInkDropRipple(
size(), GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
ink_drop_visible_opacity()));
}
void MdTextButton::StateChanged(ButtonState old_state) { void MdTextButton::StateChanged(ButtonState old_state) {
LabelButton::StateChanged(old_state); LabelButton::StateChanged(old_state);
UpdateColors(); UpdateColors();
......
...@@ -41,8 +41,6 @@ class VIEWS_EXPORT MdTextButton : public LabelButton { ...@@ -41,8 +41,6 @@ class VIEWS_EXPORT MdTextButton : public LabelButton {
// LabelButton: // LabelButton:
void OnNativeThemeChanged(const ui::NativeTheme* theme) override; void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
std::unique_ptr<InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override; const override;
SkColor GetInkDropBaseColor() const override; SkColor GetInkDropBaseColor() const override;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "ui/views/style/platform_style.h" #include "ui/views/style/platform_style.h"
#include "ui/views/view_properties.h" #include "ui/views/view_properties.h"
namespace views {
namespace { namespace {
ui::NativeTheme::ColorId ColorIdForValidity(bool valid) { ui::NativeTheme::ColorId ColorIdForValidity(bool valid) {
...@@ -16,9 +18,12 @@ ui::NativeTheme::ColorId ColorIdForValidity(bool valid) { ...@@ -16,9 +18,12 @@ ui::NativeTheme::ColorId ColorIdForValidity(bool valid) {
: ui::NativeTheme::kColorId_AlertSeverityHigh; : ui::NativeTheme::kColorId_AlertSeverityHigh;
} }
} // namespace double GetCornerRadius() {
double thickness = PlatformStyle::kFocusHaloThickness / 2.f;
return FocusableBorder::kCornerRadiusDp + thickness;
}
namespace views { } // namespace
const char FocusRing::kViewClassName[] = "FocusRing"; const char FocusRing::kViewClassName[] = "FocusRing";
...@@ -83,13 +88,8 @@ void FocusRing::OnPaint(gfx::Canvas* canvas) { ...@@ -83,13 +88,8 @@ void FocusRing::OnPaint(gfx::Canvas* canvas) {
paint.setStrokeWidth(PlatformStyle::kFocusHaloThickness); paint.setStrokeWidth(PlatformStyle::kFocusHaloThickness);
SkPath path = path_; SkPath path = path_;
if (path.isEmpty()) {
SkPath* highlight_path = parent()->GetProperty(kHighlightPathKey);
if (highlight_path)
path = *highlight_path;
}
if (path.isEmpty()) if (path.isEmpty())
path.addRect(RectToSkRect(parent()->GetLocalBounds())); path = GetHighlightPath(parent());
DCHECK(IsPathUseable(path)); DCHECK(IsPathUseable(path));
SkRect bounds; SkRect bounds;
...@@ -130,8 +130,7 @@ FocusRing::~FocusRing() { ...@@ -130,8 +130,7 @@ FocusRing::~FocusRing() {
} }
SkRRect FocusRing::RingRectFromPathRect(const SkRect& rect) const { SkRRect FocusRing::RingRectFromPathRect(const SkRect& rect) const {
double thickness = PlatformStyle::kFocusHaloThickness / 2.f; const double corner_radius = GetCornerRadius();
double corner_radius = FocusableBorder::kCornerRadiusDp + thickness;
return RingRectFromPathRect( return RingRectFromPathRect(
SkRRect::MakeRectXY(rect, corner_radius, corner_radius)); SkRRect::MakeRectXY(rect, corner_radius, corner_radius));
} }
...@@ -153,4 +152,16 @@ SkRRect FocusRing::RingRectFromPathRect(const SkRRect& rrect) const { ...@@ -153,4 +152,16 @@ SkRRect FocusRing::RingRectFromPathRect(const SkRRect& rrect) const {
return skr; return skr;
} }
SkPath GetHighlightPath(const View* view) {
SkPath* highlight_path = view->GetProperty(kHighlightPathKey);
if (highlight_path)
return *highlight_path;
const double corner_radius = GetCornerRadius();
SkPath path;
path.addRRect(SkRRect::MakeRectXY(RectToSkRect(view->GetLocalBounds()),
corner_radius, corner_radius));
return path;
}
} // namespace views } // namespace views
...@@ -116,6 +116,8 @@ class VIEWS_EXPORT FocusRing : public View, public ViewObserver { ...@@ -116,6 +116,8 @@ class VIEWS_EXPORT FocusRing : public View, public ViewObserver {
DISALLOW_COPY_AND_ASSIGN(FocusRing); DISALLOW_COPY_AND_ASSIGN(FocusRing);
}; };
VIEWS_EXPORT SkPath GetHighlightPath(const View* view);
} // views } // views
#endif // UI_VIEWS_CONTROLS_FOCUS_RING_H_ #endif // UI_VIEWS_CONTROLS_FOCUS_RING_H_
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