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) { ...@@ -54,12 +54,16 @@ void InstallRectHighlightPathGenerator(View* view) {
view, std::make_unique<RectHighlightPathGenerator>()); view, std::make_unique<RectHighlightPathGenerator>());
} }
SkPath CircleHighlightPathGenerator::GetHighlightPath(const View* view) { base::Optional<HighlightPathGenerator::RoundRect>
const SkRect rect = gfx::RectToSkRect(view->GetLocalBounds()); CircleHighlightPathGenerator::GetRoundRect(const View* view) {
const SkScalar corner_radius = gfx::RectF bounds(view->GetLocalBounds());
SkScalarHalf(std::min(rect.width(), rect.height())); const float corner_radius = std::min(bounds.width(), bounds.height()) / 2.f;
bounds.ClampToCenteredSize(
return SkPath().addCircle(rect.centerX(), rect.centerY(), corner_radius); 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) { void InstallCircleHighlightPathGenerator(View* view) {
...@@ -82,25 +86,22 @@ void InstallPillHighlightPathGenerator(View* view) { ...@@ -82,25 +86,22 @@ void InstallPillHighlightPathGenerator(View* view) {
} }
FixedSizeCircleHighlightPathGenerator::FixedSizeCircleHighlightPathGenerator( FixedSizeCircleHighlightPathGenerator::FixedSizeCircleHighlightPathGenerator(
int corner_radius) int radius)
: corner_radius_(corner_radius) {} : radius_(radius) {}
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<HighlightPathGenerator::RoundRect>
FixedSizeCircleHighlightPathGenerator::GetRoundRect(const View* view) { FixedSizeCircleHighlightPathGenerator::GetRoundRect(const View* view) {
gfx::RectF bounds(view->GetLocalBounds()); gfx::RectF bounds(view->GetLocalBounds());
bounds.ClampToCenteredSize( bounds.ClampToCenteredSize(gfx::SizeF(radius_ * 2, radius_ * 2));
gfx::SizeF(corner_radius_ * 2, corner_radius_ * 2));
HighlightPathGenerator::RoundRect round_rect; HighlightPathGenerator::RoundRect round_rect;
round_rect.bounds = bounds; round_rect.bounds = bounds;
round_rect.corner_radius = corner_radius_; round_rect.corner_radius = radius_;
return base::make_optional(round_rect); return base::make_optional(round_rect);
} }
void InstallFixedSizeCircleHighlightPathGenerator(View* view, void InstallFixedSizeCircleHighlightPathGenerator(View* view, int radius) {
int corner_radius) {
HighlightPathGenerator::Install( HighlightPathGenerator::Install(
view, view, std::make_unique<FixedSizeCircleHighlightPathGenerator>(radius));
std::make_unique<FixedSizeCircleHighlightPathGenerator>(corner_radius));
} }
} // namespace views } // namespace views
...@@ -73,7 +73,8 @@ class VIEWS_EXPORT CircleHighlightPathGenerator ...@@ -73,7 +73,8 @@ class VIEWS_EXPORT CircleHighlightPathGenerator
delete; delete;
// HighlightPathGenerator: // HighlightPathGenerator:
SkPath GetHighlightPath(const View* view) override; base::Optional<HighlightPathGenerator::RoundRect> GetRoundRect(
const View* view) override;
}; };
void VIEWS_EXPORT InstallCircleHighlightPathGenerator(View* view); void VIEWS_EXPORT InstallCircleHighlightPathGenerator(View* view);
...@@ -109,7 +110,7 @@ class VIEWS_EXPORT FixedSizeCircleHighlightPathGenerator ...@@ -109,7 +110,7 @@ class VIEWS_EXPORT FixedSizeCircleHighlightPathGenerator
const View* view) override; const View* view) override;
private: private:
const int corner_radius_; const int radius_;
}; };
void VIEWS_EXPORT InstallFixedSizeCircleHighlightPathGenerator(View* view, 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