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

Use highlight path for DownloadItemView

Moves color derivation to GetInkDropBaseColor() and removes ripple and
highlight overrides. This change also makes use of the newer FocusRing
class instead of using a FocusableBorder. FocusRing automatically
follows the highlight path and has a more consistent style with the rest
of the UI.

This change also removes an override of AddInkDropLayer which clipped
the layer to the view bounds. This is not required for this ink drop as
it only paints within the highlight path which is within the view
bounds.

Bug: chromium:888204
Change-Id: I7b388f1fe52aea6b14c32d27c0f39d5e2cff527e
Reviewed-on: https://chromium-review.googlesource.com/c/1279289Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599761}
parent e16fa738
...@@ -68,9 +68,9 @@ ...@@ -68,9 +68,9 @@
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h" #include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/button/md_text_button.h" #include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/focusable_border.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/mouse_constants.h" #include "ui/views/mouse_constants.h"
#include "ui/views/view_properties.h"
#include "ui/views/widget/root_view.h" #include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -94,20 +94,16 @@ constexpr base::TimeDelta kAccessibleAlertInterval = ...@@ -94,20 +94,16 @@ constexpr base::TimeDelta kAccessibleAlertInterval =
base::TimeDelta::FromSeconds(30); base::TimeDelta::FromSeconds(30);
// The separator is drawn as a border. It's one dp wide. // The separator is drawn as a border. It's one dp wide.
class SeparatorBorder : public views::FocusableBorder { class SeparatorBorder : public views::Border {
public: public:
explicit SeparatorBorder(SkColor separator_color) explicit SeparatorBorder(SkColor separator_color)
: separator_color_(separator_color) { : separator_color_(separator_color) {}
// Set the color used by FocusableBorder::Paint(), which could otherwise
// change when FocusableBorder relies on FocusRings instead.
SetColorId(ui::NativeTheme::kColorId_FocusedBorderColor);
}
~SeparatorBorder() override {} ~SeparatorBorder() override {}
void Paint(const views::View& view, gfx::Canvas* canvas) override { void Paint(const views::View& view, gfx::Canvas* canvas) override {
// The FocusRing replaces the separator border when we have focus.
if (view.HasFocus()) if (view.HasFocus())
return FocusableBorder::Paint(view, canvas); return;
int end_x = base::i18n::IsRTL() ? 0 : view.width() - 1; int end_x = base::i18n::IsRTL() ? 0 : view.width() - 1;
canvas->DrawLine(gfx::Point(end_x, kTopBottomPadding), canvas->DrawLine(gfx::Point(end_x, kTopBottomPadding),
gfx::Point(end_x, view.height() - kTopBottomPadding), gfx::Point(end_x, view.height() - kTopBottomPadding),
...@@ -169,6 +165,7 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download, ...@@ -169,6 +165,7 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download,
status_font_list_ = status_font_list_ =
rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2);
focus_ring_ = views::FocusRing::Install(this);
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
OnDownloadUpdated(); OnDownloadUpdated();
...@@ -329,6 +326,8 @@ void DownloadItemView::OnDownloadOpened() { ...@@ -329,6 +326,8 @@ void DownloadItemView::OnDownloadOpened() {
// In dangerous mode we have to layout our buttons. // In dangerous mode we have to layout our buttons.
void DownloadItemView::Layout() { void DownloadItemView::Layout() {
InkDropHostView::Layout();
UpdateColorsFromTheme(); UpdateColorsFromTheme();
if (IsShowingWarningDialog()) { if (IsShowingWarningDialog()) {
...@@ -355,6 +354,14 @@ void DownloadItemView::Layout() { ...@@ -355,6 +354,14 @@ void DownloadItemView::Layout() {
} }
} }
void DownloadItemView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
auto path = std::make_unique<SkPath>();
path->addRect(RectToSkRect(GetLocalBounds()));
SetProperty(views::kHighlightPathKey, path.release());
InkDropHostView::OnBoundsChanged(previous_bounds);
}
void DownloadItemView::UpdateDropdownButton() { void DownloadItemView::UpdateDropdownButton() {
views::SetImageFromVectorIcon( views::SetImageFromVectorIcon(
dropdown_button_, dropdown_button_,
...@@ -493,34 +500,10 @@ void DownloadItemView::OnThemeChanged() { ...@@ -493,34 +500,10 @@ void DownloadItemView::OnThemeChanged() {
UpdateDropdownButton(); UpdateDropdownButton();
} }
void DownloadItemView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
InkDropHostView::AddInkDropLayer(ink_drop_layer);
// The layer that's added to host the ink drop layer must mask to bounds
// so the hover effect is clipped while animating open.
layer()->SetMasksToBounds(true);
}
std::unique_ptr<views::InkDrop> DownloadItemView::CreateInkDrop() { std::unique_ptr<views::InkDrop> DownloadItemView::CreateInkDrop() {
return CreateDefaultFloodFillInkDropImpl(); return CreateDefaultFloodFillInkDropImpl();
} }
std::unique_ptr<views::InkDropRipple> DownloadItemView::CreateInkDropRipple()
const {
return std::make_unique<views::FloodFillInkDropRipple>(
size(), GetInkDropCenterBasedOnLastEvent(),
color_utils::DeriveDefaultIconColor(GetTextColor()),
ink_drop_visible_opacity());
}
std::unique_ptr<views::InkDropHighlight>
DownloadItemView::CreateInkDropHighlight() const {
gfx::Size size = GetPreferredSize();
return std::make_unique<views::InkDropHighlight>(
size, ink_drop_small_corner_radius(),
gfx::RectF(gfx::SizeF(size)).CenterPoint(),
color_utils::DeriveDefaultIconColor(GetTextColor()));
}
void DownloadItemView::OnInkDropCreated() { void DownloadItemView::OnInkDropCreated() {
ConfigureInkDrop(); ConfigureInkDrop();
} }
...@@ -873,6 +856,10 @@ void DownloadItemView::ConfigureInkDrop() { ...@@ -873,6 +856,10 @@ void DownloadItemView::ConfigureInkDrop() {
GetInkDrop()->SetShowHighlightOnHover(!IsShowingWarningDialog()); GetInkDrop()->SetShowHighlightOnHover(!IsShowingWarningDialog());
} }
SkColor DownloadItemView::GetInkDropBaseColor() const {
return color_utils::DeriveDefaultIconColor(GetTextColor());
}
void DownloadItemView::SetMode(Mode mode) { void DownloadItemView::SetMode(Mode mode) {
mode_ = mode; mode_ = mode;
ConfigureInkDrop(); ConfigureInkDrop();
......
...@@ -94,6 +94,7 @@ class DownloadItemView : public views::InkDropHostView, ...@@ -94,6 +94,7 @@ class DownloadItemView : public views::InkDropHostView,
// views::View: // views::View:
void Layout() override; void Layout() override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override; bool OnMouseDragged(const ui::MouseEvent& event) override;
...@@ -105,12 +106,9 @@ class DownloadItemView : public views::InkDropHostView, ...@@ -105,12 +106,9 @@ class DownloadItemView : public views::InkDropHostView,
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// view::InkDropHostView: // view::InkDropHostView:
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override; std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
void OnInkDropCreated() override; void OnInkDropCreated() override;
SkColor GetInkDropBaseColor() const override;
// ui::EventHandler: // ui::EventHandler:
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
...@@ -313,6 +311,9 @@ class DownloadItemView : public views::InkDropHostView, ...@@ -313,6 +311,9 @@ class DownloadItemView : public views::InkDropHostView,
// The download shelf that owns us. // The download shelf that owns us.
DownloadShelfView* shelf_; DownloadShelfView* shelf_;
// The focus ring for this Button.
std::unique_ptr<views::FocusRing> focus_ring_;
// Elements of our particular download // Elements of our particular download
base::string16 status_text_; base::string16 status_text_;
......
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