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

Use HighlightPathGenerator in search results

Uses a pill-shape generator for SearchResultSuggestionChipView. This
replaces a custom InkDropMask for the same shape and overriding the
focus ring's path inside OnBoundsChanged.

Bug: chromium:1007546
Change-Id: I229ad7529ad4d593f32b39cfe3fda948332eb32d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1861046
Auto-Submit: Peter Boström <pbos@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705995}
parent 305eca2a
...@@ -22,11 +22,10 @@ ...@@ -22,11 +22,10 @@
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h" #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h" #include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/view_class_properties.h"
namespace ash { namespace ash {
...@@ -36,7 +35,6 @@ constexpr SkColor kBackgroundColor = SkColorSetA(gfx::kGoogleGrey100, 0x14); ...@@ -36,7 +35,6 @@ constexpr SkColor kBackgroundColor = SkColorSetA(gfx::kGoogleGrey100, 0x14);
constexpr SkColor kTextColor = gfx::kGoogleGrey100; constexpr SkColor kTextColor = gfx::kGoogleGrey100;
constexpr SkColor kRippleColor = SkColorSetA(gfx::kGoogleGrey100, 0x0F); constexpr SkColor kRippleColor = SkColorSetA(gfx::kGoogleGrey100, 0x0F);
constexpr SkColor kFocusRingColor = gfx::kGoogleBlue300; constexpr SkColor kFocusRingColor = gfx::kGoogleBlue300;
constexpr int kFocusRingCornerRadius = 16;
constexpr int kMaxTextWidth = 192; constexpr int kMaxTextWidth = 192;
constexpr int kBlurRadius = 5; constexpr int kBlurRadius = 5;
constexpr int kIconMarginDip = 8; constexpr int kIconMarginDip = 8;
...@@ -65,6 +63,7 @@ SearchResultSuggestionChipView::SearchResultSuggestionChipView( ...@@ -65,6 +63,7 @@ SearchResultSuggestionChipView::SearchResultSuggestionChipView(
focus_ring()->SetColor(kFocusRingColor); focus_ring()->SetColor(kFocusRingColor);
SetInkDropMode(InkDropMode::ON); SetInkDropMode(InkDropMode::ON);
views::InstallPillHighlightPathGenerator(this);
InitLayout(); InitLayout();
} }
...@@ -152,11 +151,6 @@ void SearchResultSuggestionChipView::OnBlur() { ...@@ -152,11 +151,6 @@ void SearchResultSuggestionChipView::OnBlur() {
SchedulePaint(); SchedulePaint();
} }
void SearchResultSuggestionChipView::OnBoundsChanged(
const gfx::Rect& previous_bounds) {
UpdateFocusRingPath();
}
bool SearchResultSuggestionChipView::OnKeyPressed(const ui::KeyEvent& event) { bool SearchResultSuggestionChipView::OnKeyPressed(const ui::KeyEvent& event) {
if (event.key_code() == ui::VKEY_SPACE) if (event.key_code() == ui::VKEY_SPACE)
return false; return false;
...@@ -173,12 +167,6 @@ SearchResultSuggestionChipView::CreateInkDrop() { ...@@ -173,12 +167,6 @@ SearchResultSuggestionChipView::CreateInkDrop() {
return std::move(ink_drop); return std::move(ink_drop);
} }
std::unique_ptr<views::InkDropMask>
SearchResultSuggestionChipView::CreateInkDropMask() const {
return std::make_unique<views::RoundRectInkDropMask>(size(), gfx::InsetsF(),
height() / 2);
}
std::unique_ptr<views::InkDropRipple> std::unique_ptr<views::InkDropRipple>
SearchResultSuggestionChipView::CreateInkDropRipple() const { SearchResultSuggestionChipView::CreateInkDropRipple() const {
const gfx::Point center = GetLocalBounds().CenterPoint(); const gfx::Point center = GetLocalBounds().CenterPoint();
...@@ -232,18 +220,6 @@ void SearchResultSuggestionChipView::UpdateSuggestionChipView() { ...@@ -232,18 +220,6 @@ void SearchResultSuggestionChipView::UpdateSuggestionChipView() {
SetAccessibleName(accessible_name); SetAccessibleName(accessible_name);
} }
void SearchResultSuggestionChipView::UpdateFocusRingPath() {
auto path = std::make_unique<SkPath>();
gfx::Rect bounds = GetLocalBounds();
// Insets ensure the focus ring will fit within the bounds of the chip once
// they are clipped to be rounded.
bounds.Inset(gfx::Insets(1));
path->addRoundRect(gfx::RectToSkRect(bounds), kFocusRingCornerRadius,
kFocusRingCornerRadius);
SetProperty(views::kHighlightPathKey, path.release());
}
void SearchResultSuggestionChipView::InitLayout() { void SearchResultSuggestionChipView::InitLayout() {
layout_manager_ = SetLayoutManager(std::make_unique<views::BoxLayout>( layout_manager_ = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, views::BoxLayout::Orientation::kHorizontal,
......
...@@ -15,7 +15,6 @@ namespace views { ...@@ -15,7 +15,6 @@ namespace views {
class BoxLayout; class BoxLayout;
class ImageView; class ImageView;
class InkDrop; class InkDrop;
class InkDropMask;
class InkDropRipple; class InkDropRipple;
class Label; class Label;
} // namespace views } // namespace views
...@@ -48,12 +47,10 @@ class APP_LIST_EXPORT SearchResultSuggestionChipView ...@@ -48,12 +47,10 @@ class APP_LIST_EXPORT SearchResultSuggestionChipView
void OnPaintBackground(gfx::Canvas* canvas) override; void OnPaintBackground(gfx::Canvas* canvas) override;
void OnFocus() override; void OnFocus() override;
void OnBlur() override; void OnBlur() override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
bool OnKeyPressed(const ui::KeyEvent& event) override; bool OnKeyPressed(const ui::KeyEvent& event) override;
// views::InkDropHost: // views::InkDropHost:
std::unique_ptr<views::InkDrop> CreateInkDrop() override; std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
// ui::LayerOwner: // ui::LayerOwner:
...@@ -68,9 +65,6 @@ class APP_LIST_EXPORT SearchResultSuggestionChipView ...@@ -68,9 +65,6 @@ class APP_LIST_EXPORT SearchResultSuggestionChipView
// Updates the suggestion chip view's title and icon. // Updates the suggestion chip view's title and icon.
void UpdateSuggestionChipView(); void UpdateSuggestionChipView();
// Updates the focus ring draw path based on the current bounds.
void UpdateFocusRingPath();
void InitLayout(); void InitLayout();
// Sets rounded corners for the layer with |corner_radius| to clip the chip. // Sets rounded corners for the layer with |corner_radius| to clip the chip.
......
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