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

Add CircleHighlightPathGenerator

Replaces kHighlightPathKey uses in FindBarButton, ProfileMenuViewBase
and BubbleFrameView.

Bug: chromium:1007546
Change-Id: Iec2a07ed28913d68bf8e835e9603ca4247eadaa7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835263Reviewed-by: default avatarTaylor Bergquist <tbergquist@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702249}
parent 796e89e8
......@@ -42,6 +42,7 @@
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
......@@ -52,23 +53,12 @@
// An ImageButton that has a centered circular highlight.
class FindBarView::FindBarButton : public views::ImageButton {
public:
using ImageButton::ImageButton;
protected:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
explicit FindBarButton(views::ButtonListener* listener)
: ImageButton(listener) {
views::InstallCircleHighlightPathGenerator(this);
}
};
void FindBarView::FindBarButton::OnBoundsChanged(
const gfx::Rect& previous_bounds) {
const gfx::Rect bounds = GetLocalBounds();
auto highlight_path = std::make_unique<SkPath>();
const gfx::Point center = bounds.CenterPoint();
const int radius = views::LayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, bounds.size());
highlight_path->addCircle(center.x(), center.y(), radius);
SetProperty(views::kHighlightPathKey, highlight_path.release());
}
class FindBarView::MatchCountLabel : public views::Label {
public:
MatchCountLabel() {}
......
......@@ -30,6 +30,7 @@
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h"
......@@ -166,10 +167,8 @@ std::unique_ptr<views::Button> CreateCircularImageButton(
button->SetBorder(views::CreateRoundedRectBorder(
kBorderThickness, kButtonRadius, GetDefaultSeparatorColor()));
}
// Set circular highlight path.
auto path = std::make_unique<SkPath>();
path->addCircle(kButtonRadius, kButtonRadius, kButtonRadius);
button->SetProperty(views::kHighlightPathKey, path.release());
InstallCircleHighlightPathGenerator(button.get());
return button;
}
......
......@@ -27,6 +27,7 @@
#include "ui/views/bubble/footnote_container_view.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/layout_provider.h"
......@@ -116,10 +117,7 @@ std::unique_ptr<Button> BubbleFrameView::CreateCloseButton(
close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE));
close_button->SizeToPreferredSize();
// Let the close button use a circular inkdrop shape.
auto highlight_path = std::make_unique<SkPath>();
highlight_path->addOval(gfx::RectToSkRect(gfx::Rect(close_button->size())));
close_button->SetProperty(kHighlightPathKey, highlight_path.release());
InstallCircleHighlightPathGenerator(close_button.get());
// Remove the close button from tab traversal on all platforms. Note this does
// not affect screen readers' ability to focus the close button. Keyboard
......
......@@ -4,6 +4,7 @@
#include "ui/views/controls/highlight_path_generator.h"
#include "third_party/skia/include/core/SkRect.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
......@@ -29,4 +30,18 @@ void InstallRectHighlightPathGenerator(View* view) {
view, std::make_unique<RectHighlightPathGenerator>());
}
SkPath CircleHighlightPathGenerator::GetHighlightPath(const View* view) {
const SkRect rect = gfx::RectToSkRect(view->GetLocalBounds());
const SkScalar radius = SkScalarHalf(std::min(rect.width(), rect.height()));
SkPath path;
path.addCircle(rect.centerX(), rect.centerY(), radius);
return path;
}
void InstallCircleHighlightPathGenerator(View* view) {
HighlightPathGenerator::Install(
view, std::make_unique<CircleHighlightPathGenerator>());
}
} // namespace views
......@@ -46,6 +46,22 @@ class VIEWS_EXPORT RectHighlightPathGenerator : public HighlightPathGenerator {
void VIEWS_EXPORT InstallRectHighlightPathGenerator(View* view);
// Sets a centered circular highlight path.
class VIEWS_EXPORT CircleHighlightPathGenerator
: public HighlightPathGenerator {
public:
CircleHighlightPathGenerator() = default;
CircleHighlightPathGenerator(const CircleHighlightPathGenerator&) = delete;
CircleHighlightPathGenerator& operator=(const CircleHighlightPathGenerator&) =
delete;
// HighlightPathGenerator:
SkPath GetHighlightPath(const View* view) override;
};
void VIEWS_EXPORT InstallCircleHighlightPathGenerator(View* view);
} // namespace views
#endif // UI_VIEWS_CONTROLS_HIGHLIGHT_PATH_GENERATOR_H_
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