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

Use highlight paths for HoverButton

Removes the need for custom ink-drop highlights. This change (as tested
locally) should have no visual impact. It only reduces custom ink-drop
usage.

Bug: chromium:888204
Change-Id: Iefb2c6adf9f95a6d1265fb1dbd95ff0f0e7ecf97
Reviewed-on: https://chromium-review.googlesource.com/c/1279169Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599785}
parent 95887b53
......@@ -11,14 +11,13 @@
#include "chrome/browser/ui/views/chrome_typography.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_ripple.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/view_properties.h"
namespace {
......@@ -273,10 +272,6 @@ views::Button::KeyClickAction HoverButton::GetKeyClickActionForEvent(
return MenuButton::GetKeyClickActionForEvent(event);
}
void HoverButton::SetHighlightingView(views::View* highlighting_view) {
highlighting_view_ = highlighting_view;
}
void HoverButton::StateChanged(ButtonState old_state) {
MenuButton::StateChanged(old_state);
......@@ -289,40 +284,21 @@ void HoverButton::StateChanged(ButtonState old_state) {
}
}
bool HoverButton::ShouldUseFloodFillInkDrop() const {
return true;
}
SkColor HoverButton::GetInkDropBaseColor() const {
return views::style::GetColor(*this, views::style::CONTEXT_BUTTON,
STYLE_SECONDARY);
}
std::unique_ptr<views::InkDrop> HoverButton::CreateInkDrop() {
std::unique_ptr<views::InkDrop> ink_drop = LabelButton::CreateInkDrop();
std::unique_ptr<views::InkDrop> ink_drop =
CreateDefaultFloodFillInkDropImpl();
// Turn on highlighting when the button is focused only - hovering the button
// will request focus.
// Note that the setup done in Button::CreateInkDrop() needs to be repeated
// here to configure flood-fill ink drops from LabelButton.
ink_drop->SetShowHighlightOnFocus(true);
ink_drop->SetShowHighlightOnHover(false);
return ink_drop;
}
std::unique_ptr<views::InkDropHighlight> HoverButton::CreateInkDropHighlight()
const {
// HoverButtons are supposed to encompass the full width of their parent, so
// remove the rounded corners.
std::unique_ptr<views::InkDropHighlight> highlight(
new views::InkDropHighlight(
highlighting_view_->size(), 0,
gfx::RectF(GetMirroredRect(highlighting_view_->GetContentsBounds()))
.CenterPoint(),
GetInkDropBaseColor()));
highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size())));
return highlight;
}
void HoverButton::Layout() {
MenuButton::Layout();
......@@ -357,6 +333,12 @@ views::View* HoverButton::GetTooltipHandlerForPoint(const gfx::Point& point) {
}
void HoverButton::OnBoundsChanged(const gfx::Rect& previous_bounds) {
// HoverButtons use a rectangular highlight to encompass the full width of
// their parent.
auto path = std::make_unique<SkPath>();
path->addRect(RectToSkRect(GetLocalBounds()));
SetProperty(views::kHighlightPathKey, path.release());
if (title_) {
SetTooltipAndAccessibleName(this, title_, subtitle_, GetLocalBounds(),
taken_width_, auto_compute_tooltip_);
......
......@@ -86,11 +86,6 @@ class HoverButton : public views::MenuButton, public views::MenuButtonListener {
auto_compute_tooltip_ = auto_compute_tooltip;
}
// Sets the view to be highlighted when the button is hovered. If this
// function is not called, |this| will be used. This function can be used e.g.
// when siblings in the parent view have to be highlighted as well.
void SetHighlightingView(views::View* highlighting_view);
protected:
// views::MenuButtonListener:
void OnMenuButtonClicked(MenuButton* source,
......@@ -100,13 +95,10 @@ class HoverButton : public views::MenuButton, public views::MenuButtonListener {
// views::MenuButton:
KeyClickAction GetKeyClickActionForEvent(const ui::KeyEvent& event) override;
void StateChanged(ButtonState old_state) override;
bool ShouldUseFloodFillInkDrop() const override;
// views::InkDropHostView:
SkColor GetInkDropBaseColor() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
// views::View:
void Layout() override;
......@@ -136,9 +128,6 @@ class HoverButton : public views::MenuButton, public views::MenuButtonListener {
// from the |title_| and |subtitle_| text.
bool auto_compute_tooltip_ = true;
// View that gets highlighted when this button is hovered.
views::View* highlighting_view_ = this;
// Listener to be called when button is clicked.
views::ButtonListener* listener_;
......
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