Commit 90199b9c authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

views: Modify HighlightPathGenerator::CircleHighlightPathGenerator.

Makes CircleHighlightPathGenerator use RoundedRect. Tested manually and
the highlights/ripples/focus rings look the same, minus the previous
extra renderpass.

Test: manual
Bug: 1042303
Change-Id: Ib2010b4b8ba9838bfee9f9d6eb696bb6fffb843f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037849
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738680}
parent cb6b0967
......@@ -54,12 +54,16 @@ void InstallRectHighlightPathGenerator(View* view) {
view, std::make_unique<RectHighlightPathGenerator>());
}
SkPath CircleHighlightPathGenerator::GetHighlightPath(const View* view) {
const SkRect rect = gfx::RectToSkRect(view->GetLocalBounds());
const SkScalar corner_radius =
SkScalarHalf(std::min(rect.width(), rect.height()));
return SkPath().addCircle(rect.centerX(), rect.centerY(), corner_radius);
base::Optional<HighlightPathGenerator::RoundRect>
CircleHighlightPathGenerator::GetRoundRect(const View* view) {
gfx::RectF bounds(view->GetLocalBounds());
const float corner_radius = std::min(bounds.width(), bounds.height()) / 2.f;
bounds.ClampToCenteredSize(
gfx::SizeF(corner_radius * 2.f, corner_radius * 2.f));
HighlightPathGenerator::RoundRect round_rect;
round_rect.bounds = bounds;
round_rect.corner_radius = corner_radius;
return base::make_optional(round_rect);
}
void InstallCircleHighlightPathGenerator(View* view) {
......@@ -82,25 +86,22 @@ void InstallPillHighlightPathGenerator(View* view) {
}
FixedSizeCircleHighlightPathGenerator::FixedSizeCircleHighlightPathGenerator(
int corner_radius)
: corner_radius_(corner_radius) {}
int radius)
: radius_(radius) {}
base::Optional<HighlightPathGenerator::RoundRect>
FixedSizeCircleHighlightPathGenerator::GetRoundRect(const View* view) {
gfx::RectF bounds(view->GetLocalBounds());
bounds.ClampToCenteredSize(
gfx::SizeF(corner_radius_ * 2, corner_radius_ * 2));
bounds.ClampToCenteredSize(gfx::SizeF(radius_ * 2, radius_ * 2));
HighlightPathGenerator::RoundRect round_rect;
round_rect.bounds = bounds;
round_rect.corner_radius = corner_radius_;
round_rect.corner_radius = radius_;
return base::make_optional(round_rect);
}
void InstallFixedSizeCircleHighlightPathGenerator(View* view,
int corner_radius) {
void InstallFixedSizeCircleHighlightPathGenerator(View* view, int radius) {
HighlightPathGenerator::Install(
view,
std::make_unique<FixedSizeCircleHighlightPathGenerator>(corner_radius));
view, std::make_unique<FixedSizeCircleHighlightPathGenerator>(radius));
}
} // namespace views
......@@ -73,7 +73,8 @@ class VIEWS_EXPORT CircleHighlightPathGenerator
delete;
// HighlightPathGenerator:
SkPath GetHighlightPath(const View* view) override;
base::Optional<HighlightPathGenerator::RoundRect> GetRoundRect(
const View* view) override;
};
void VIEWS_EXPORT InstallCircleHighlightPathGenerator(View* view);
......@@ -109,7 +110,7 @@ class VIEWS_EXPORT FixedSizeCircleHighlightPathGenerator
const View* view) override;
private:
const int corner_radius_;
const int radius_;
};
void VIEWS_EXPORT InstallFixedSizeCircleHighlightPathGenerator(View* view,
......
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