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

Use highlight path for InkDropMask and FocusRing

Introduces a kHighlightPathKey property to views and uses it as a
default for FocusRing and CreateInkDropMask in InkDropHostView. If no
highlight path is added this fall backs to prior behavior, which allows
introducing this change in parts.

This highlight path is added to the bookmarks-bar buttons and the dialog
close button. CreateInkDropMask and installing the focus ring is removed
from the prior.

Bug: chromium:861975, chromium:888204
Change-Id: I7eb682efe82caea7e8088d7277733698967d0234
Reviewed-on: https://chromium-review.googlesource.com/1239715Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593783}
parent 6b9706d9
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
#include "ui/views/metrics.h" #include "ui/views/metrics.h"
#include "ui/views/style/platform_style.h" #include "ui/views/style/platform_style.h"
#include "ui/views/view_constants.h" #include "ui/views/view_constants.h"
#include "ui/views/view_properties.h"
#include "ui/views/widget/tooltip_manager.h" #include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h" #include "ui/views/window/non_client_view.h"
...@@ -167,17 +168,15 @@ int GetInkDropCornerRadius(const views::View* host_view) { ...@@ -167,17 +168,15 @@ int GetInkDropCornerRadius(const views::View* host_view) {
views::EMPHASIS_MAXIMUM, host_view->size()); views::EMPHASIS_MAXIMUM, host_view->size());
} }
// Create a SkPath matching the bookmark inkdrops to be used for the focus ring. // Returns a gfx::Path for bookmark inkdrops and focus rings.
// TODO(pbos): Consolidate inkdrop effects, highlights and ripples along with std::unique_ptr<gfx::Path> CreateBookmarkHighlightPath(
// focus rings so that they are derived from the same actual SkPath or other views::InkDropHostView* host_view) {
// shared primitive.
SkPath CreateBookmarkFocusRingPath(views::InkDropHostView* host_view) {
gfx::Rect rect(host_view->size()); gfx::Rect rect(host_view->size());
rect.Inset(GetInkDropInsets()); rect.Inset(GetInkDropInsets());
SkPath path; auto path = std::make_unique<gfx::Path>();
const int radius = GetInkDropCornerRadius(host_view); const int radius = GetInkDropCornerRadius(host_view);
path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); path->addRoundRect(gfx::RectToSkRect(rect), radius, radius);
return path; return path;
} }
...@@ -196,12 +195,6 @@ std::unique_ptr<views::InkDropRipple> CreateBookmarkButtonInkDropRipple( ...@@ -196,12 +195,6 @@ std::unique_ptr<views::InkDropRipple> CreateBookmarkButtonInkDropRipple(
host_view->ink_drop_visible_opacity()); host_view->ink_drop_visible_opacity());
} }
std::unique_ptr<views::InkDropMask> CreateBookmarkButtonInkDropMask(
const views::InkDropHostView* host_view) {
return std::make_unique<views::RoundRectInkDropMask>(
host_view->size(), GetInkDropInsets(), GetInkDropCornerRadius(host_view));
}
std::unique_ptr<views::InkDropHighlight> CreateBookmarkButtonInkDropHighlight( std::unique_ptr<views::InkDropHighlight> CreateBookmarkButtonInkDropHighlight(
const views::InkDropHostView* host_view) { const views::InkDropHostView* host_view) {
std::unique_ptr<views::InkDropHighlight> highlight( std::unique_ptr<views::InkDropHighlight> highlight(
...@@ -260,8 +253,8 @@ class BookmarkButtonBase : public views::LabelButton { ...@@ -260,8 +253,8 @@ class BookmarkButtonBase : public views::LabelButton {
// LabelButton: // LabelButton:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override { void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
if (focus_ring()) SetProperty(views::kHighlightPathKey,
focus_ring()->SetPath(CreateBookmarkFocusRingPath(this)); CreateBookmarkHighlightPath(this).release());
LabelButton::OnBoundsChanged(previous_bounds); LabelButton::OnBoundsChanged(previous_bounds);
} }
...@@ -279,10 +272,6 @@ class BookmarkButtonBase : public views::LabelButton { ...@@ -279,10 +272,6 @@ class BookmarkButtonBase : public views::LabelButton {
return CreateBookmarkButtonInkDropHighlight(this); return CreateBookmarkButtonInkDropHighlight(this);
} }
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override {
return CreateBookmarkButtonInkDropMask(this);
}
std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder()
const override { const override {
return CreateBookmarkButtonBorder(); return CreateBookmarkButtonBorder();
...@@ -388,8 +377,8 @@ class BookmarkMenuButtonBase : public views::MenuButton { ...@@ -388,8 +377,8 @@ class BookmarkMenuButtonBase : public views::MenuButton {
// MenuButton: // MenuButton:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override { void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
if (focus_ring()) SetProperty(views::kHighlightPathKey,
focus_ring()->SetPath(CreateBookmarkFocusRingPath(this)); CreateBookmarkHighlightPath(this).release());
MenuButton::OnBoundsChanged(previous_bounds); MenuButton::OnBoundsChanged(previous_bounds);
} }
...@@ -407,10 +396,6 @@ class BookmarkMenuButtonBase : public views::MenuButton { ...@@ -407,10 +396,6 @@ class BookmarkMenuButtonBase : public views::MenuButton {
return CreateBookmarkButtonInkDropHighlight(this); return CreateBookmarkButtonInkDropHighlight(this);
} }
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override {
return CreateBookmarkButtonInkDropMask(this);
}
std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder()
const override { const override {
return CreateBookmarkButtonBorder(); return CreateBookmarkButtonBorder();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#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/style/platform_style.h" #include "ui/views/style/platform_style.h"
#include "ui/views/view_properties.h"
namespace views { namespace views {
namespace { namespace {
...@@ -170,6 +171,9 @@ std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() ...@@ -170,6 +171,9 @@ std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
} }
std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const { std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const {
if (gfx::Path* highlight_path = GetProperty(kHighlightPathKey))
return std::make_unique<views::PathInkDropMask>(size(), *highlight_path);
return nullptr; return nullptr;
} }
......
...@@ -75,4 +75,20 @@ void CircleInkDropMask::OnPaintLayer(const ui::PaintContext& context) { ...@@ -75,4 +75,20 @@ void CircleInkDropMask::OnPaintLayer(const ui::PaintContext& context) {
recorder.canvas()->DrawCircle(mask_center_, mask_radius_, flags); recorder.canvas()->DrawCircle(mask_center_, mask_radius_, flags);
} }
// PathInkDropMask
PathInkDropMask::PathInkDropMask(const gfx::Size& layer_size,
const gfx::Path& path)
: InkDropMask(layer_size), path_(path) {}
void PathInkDropMask::OnPaintLayer(const ui::PaintContext& context) {
cc::PaintFlags flags;
flags.setAlpha(255);
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setAntiAlias(true);
ui::PaintRecorder recorder(context, layer()->size());
recorder.canvas()->DrawPath(path_, flags);
}
} // namespace views } // namespace views
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ui/gfx/geometry/insets_f.h" #include "ui/gfx/geometry/insets_f.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/path.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
namespace views { namespace views {
...@@ -33,7 +34,7 @@ class VIEWS_EXPORT InkDropMask : public ui::LayerDelegate { ...@@ -33,7 +34,7 @@ class VIEWS_EXPORT InkDropMask : public ui::LayerDelegate {
explicit InkDropMask(const gfx::Size& layer_size); explicit InkDropMask(const gfx::Size& layer_size);
private: private:
// Overriden from ui::LayerDelegate: // ui::LayerDelegate:
void OnDeviceScaleFactorChanged(float old_device_scale_factor, void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override; float new_device_scale_factor) override;
...@@ -50,7 +51,7 @@ class VIEWS_EXPORT RoundRectInkDropMask : public InkDropMask { ...@@ -50,7 +51,7 @@ class VIEWS_EXPORT RoundRectInkDropMask : public InkDropMask {
float corner_radius); float corner_radius);
private: private:
// Overriden from InkDropMask: // InkDropMask:
void OnPaintLayer(const ui::PaintContext& context) override; void OnPaintLayer(const ui::PaintContext& context) override;
gfx::InsetsF mask_insets_; gfx::InsetsF mask_insets_;
...@@ -67,7 +68,7 @@ class VIEWS_EXPORT CircleInkDropMask : public InkDropMask { ...@@ -67,7 +68,7 @@ class VIEWS_EXPORT CircleInkDropMask : public InkDropMask {
int mask_radius); int mask_radius);
private: private:
// Overriden from InkDropMask: // InkDropMask:
void OnPaintLayer(const ui::PaintContext& context) override; void OnPaintLayer(const ui::PaintContext& context) override;
gfx::Point mask_center_; gfx::Point mask_center_;
...@@ -76,6 +77,20 @@ class VIEWS_EXPORT CircleInkDropMask : public InkDropMask { ...@@ -76,6 +77,20 @@ class VIEWS_EXPORT CircleInkDropMask : public InkDropMask {
DISALLOW_COPY_AND_ASSIGN(CircleInkDropMask); DISALLOW_COPY_AND_ASSIGN(CircleInkDropMask);
}; };
// An ink-drop mask that paints a specified path.
class VIEWS_EXPORT PathInkDropMask : public InkDropMask {
public:
PathInkDropMask(const gfx::Size& layer_size, const gfx::Path& path);
private:
// InkDropMask:
void OnPaintLayer(const ui::PaintContext& context) override;
gfx::Path path_;
DISALLOW_COPY_AND_ASSIGN(PathInkDropMask);
};
} // namespace views } // namespace views
#endif // UI_VIEWS_ANIMATION_INK_DROP_MASK_H_ #endif // UI_VIEWS_ANIMATION_INK_DROP_MASK_H_
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "ui/views/layout/layout_provider.h" #include "ui/views/layout/layout_provider.h"
#include "ui/views/paint_info.h" #include "ui/views/paint_info.h"
#include "ui/views/resources/grit/views_resources.h" #include "ui/views/resources/grit/views_resources.h"
#include "ui/views/view_properties.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
#include "ui/views/window/client_view.h" #include "ui/views/window/client_view.h"
...@@ -132,6 +133,11 @@ Button* BubbleFrameView::CreateCloseButton(ButtonListener* listener) { ...@@ -132,6 +133,11 @@ Button* BubbleFrameView::CreateCloseButton(ButtonListener* listener) {
close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE));
close_button->SizeToPreferredSize(); close_button->SizeToPreferredSize();
// Let the close button use a circular inkdrop shape.
auto highlight_path = std::make_unique<gfx::Path>();
highlight_path->addOval(gfx::RectToSkRect(gfx::Rect(close_button->size())));
close_button->SetProperty(kHighlightPathKey, highlight_path.release());
// Remove the close button from tab traversal on all platforms. Note this does // Remove the close button from tab traversal on all platforms. Note this does
// not affect screen readers' ability to focus the close button. Keyboard // not affect screen readers' ability to focus the close button. Keyboard
// access to the close button when not using a screen reader is done via the // access to the close button when not using a screen reader is done via the
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/views/controls/focusable_border.h" #include "ui/views/controls/focusable_border.h"
#include "ui/views/style/platform_style.h" #include "ui/views/style/platform_style.h"
#include "ui/views/view_properties.h"
namespace { namespace {
...@@ -79,6 +80,11 @@ void FocusRing::OnPaint(gfx::Canvas* canvas) { ...@@ -79,6 +80,11 @@ void FocusRing::OnPaint(gfx::Canvas* canvas) {
paint.setStrokeWidth(PlatformStyle::kFocusHaloThickness); paint.setStrokeWidth(PlatformStyle::kFocusHaloThickness);
SkPath path = path_; SkPath path = path_;
if (path.isEmpty()) {
gfx::Path* highlight_path = parent()->GetProperty(kHighlightPathKey);
if (highlight_path)
path = *highlight_path;
}
if (path.isEmpty()) if (path.isEmpty())
path.addRect(RectToSkRect(parent()->GetLocalBounds())); path.addRect(RectToSkRect(parent()->GetLocalBounds()));
......
...@@ -58,6 +58,7 @@ class VIEWS_EXPORT FocusRing : public View, public ViewObserver { ...@@ -58,6 +58,7 @@ class VIEWS_EXPORT FocusRing : public View, public ViewObserver {
// view's coordinate system, *not* in the FocusRing's coordinate system. Note // view's coordinate system, *not* in the FocusRing's coordinate system. Note
// that this path will not be mirrored in RTL, so your View's computation of // that this path will not be mirrored in RTL, so your View's computation of
// it should take RTL into account. // it should take RTL into account.
// TODO(pbos): Replace calls with setting kHighlightPathKey on the parent.
void SetPath(const SkPath& path); void SetPath(const SkPath& path);
// Sets whether the FocusRing should show an invalid state for the View it // Sets whether the FocusRing should show an invalid state for the View it
......
...@@ -20,6 +20,8 @@ DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, gfx::Insets*); ...@@ -20,6 +20,8 @@ DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, gfx::Insets*);
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT,
views::BubbleDialogDelegateView*); views::BubbleDialogDelegateView*);
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, gfx::Path*);
namespace views { namespace views {
DEFINE_UI_CLASS_PROPERTY_KEY(int, kHitTestComponentKey, HTNOWHERE); DEFINE_UI_CLASS_PROPERTY_KEY(int, kHitTestComponentKey, HTNOWHERE);
...@@ -27,5 +29,6 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Insets, kMarginsKey, nullptr); ...@@ -27,5 +29,6 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Insets, kMarginsKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(views::BubbleDialogDelegateView*, DEFINE_UI_CLASS_PROPERTY_KEY(views::BubbleDialogDelegateView*,
kAnchoredDialogKey, kAnchoredDialogKey,
nullptr); nullptr);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Path, kHighlightPathKey, nullptr);
} // namespace views } // namespace views
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace gfx { namespace gfx {
class Insets; class Insets;
class Path;
} // namespace gfx } // namespace gfx
namespace views { namespace views {
...@@ -30,6 +31,12 @@ VIEWS_EXPORT extern const ui::ClassProperty<gfx::Insets*>* const kMarginsKey; ...@@ -30,6 +31,12 @@ VIEWS_EXPORT extern const ui::ClassProperty<gfx::Insets*>* const kMarginsKey;
VIEWS_EXPORT extern const ui::ClassProperty<BubbleDialogDelegateView*>* const VIEWS_EXPORT extern const ui::ClassProperty<BubbleDialogDelegateView*>* const
kAnchoredDialogKey; kAnchoredDialogKey;
// A property to store a highlight path related to the view. This is nominally
// used by the default inkdrop and focus ring that are both used to highlight
// the view in different ways.
VIEWS_EXPORT extern const ui::ClassProperty<gfx::Path*>* const
kHighlightPathKey;
} // namespace views } // namespace views
// Declaring the template specialization here to make sure that the // Declaring the template specialization here to make sure that the
......
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