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

Add HighlightPathGenerator to color_picker_view.cc

Replaces OnBoundsChanged override for ColorPickerElementView.

Bug: chromium:1007546
Change-Id: Iefe2e8f035cfbe83778ebd05df562ca5aaf33c47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1859586
Auto-Submit: Peter Boström <pbos@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705975}
parent fedb1e34
......@@ -17,8 +17,29 @@
#include "ui/gfx/color_utils.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view_class_properties.h"
namespace {
class ColorPickerHighlightPathGenerator : public views::HighlightPathGenerator {
public:
ColorPickerHighlightPathGenerator() = default;
// views::HighlightPathGenerator:
SkPath GetHighlightPath(const views::View* view) override {
// Our highlight path should be slightly larger than the circle we paint.
gfx::RectF bounds(view->GetContentsBounds());
bounds.Inset(gfx::Insets(-2.0f));
const gfx::PointF center = bounds.CenterPoint();
return SkPath().addCircle(center.x(), center.y(), bounds.width() / 2.0f);
}
private:
DISALLOW_COPY_AND_ASSIGN(ColorPickerHighlightPathGenerator);
};
} // namespace
// Represents one of the colors the user can pick from. Displayed as a solid
// circle of the given color.
......@@ -38,6 +59,8 @@ class ColorPickerElementView : public views::Button,
SetAccessibleName(color_name);
SetFocusForPlatform();
SetInstallFocusRingOnFocus(true);
views::HighlightPathGenerator::Install(
this, std::make_unique<ColorPickerHighlightPathGenerator>());
SetBorder(
views::CreateEmptyBorder(ChromeLayoutProvider::Get()->GetInsetsMetric(
......@@ -89,19 +112,6 @@ class ColorPickerElementView : public views::Button,
int GetHeightForWidth(int width) const override { return width; }
void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
if (size() == previous_bounds.size())
return;
// Our highlight path should be slightly larger than the circle we paint.
gfx::RectF bounds(GetContentsBounds());
bounds.Inset(gfx::Insets(-2.0f));
const gfx::PointF center = bounds.CenterPoint();
SkPath path;
path.addCircle(center.x(), center.y(), bounds.width() / 2.0f);
SetProperty(views::kHighlightPathKey, std::move(path));
}
void PaintButtonContents(gfx::Canvas* canvas) override {
// Paint a colored circle surrounded by a bit of empty space.
......
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