Bug 1326406 Part 2 - Extract the computation of ellipse radii as ComputeEllipseRadii().
MozReview-Commit-ID: LPdvg66adHQ
--- a/layout/base/ShapeUtils.cpp
+++ b/layout/base/ShapeUtils.cpp
@@ -72,9 +72,37 @@ ShapeUtils::ComputeCircleRadius(StyleBas
SVGContentUtils::ComputeNormalizedHypotenuse(aRefBox.width,
aRefBox.height);
r = nsRuleNode::ComputeCoordPercentCalc(coords[0],
NSToCoordRound(referenceLength));
}
return r;
}
+nsSize
+ShapeUtils::ComputeEllipseRadii(StyleBasicShape* const aBasicShape,
+ const nsPoint& aCenter,
+ const nsRect& aRefBox)
+{
+ const nsTArray<nsStyleCoord>& coords = aBasicShape->Coordinates();
+ MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments");
+ nsSize radii;
+
+ if (coords[0].GetUnit() == eStyleUnit_Enumerated) {
+ const StyleShapeRadius radiusX = coords[0].GetEnumValue<StyleShapeRadius>();
+ radii.width = ComputeShapeRadius(radiusX, aCenter.x, aRefBox.x,
+ aRefBox.XMost());
+ } else {
+ radii.width = nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.width);
+ }
+
+ if (coords[1].GetUnit() == eStyleUnit_Enumerated) {
+ const StyleShapeRadius radiusY = coords[1].GetEnumValue<StyleShapeRadius>();
+ radii.height = ComputeShapeRadius(radiusY, aCenter.y, aRefBox.y,
+ aRefBox.YMost());
+ } else {
+ radii.height = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height);
+ }
+
+ return radii;
+}
+
} // namespace mozilla
--- a/layout/base/ShapeUtils.h
+++ b/layout/base/ShapeUtils.h
@@ -43,13 +43,22 @@ struct ShapeUtils final
// Compute the radius for a circle.
// @param aCenter the center of the circle.
// @param aRefBox the reference box of the circle.
// @return The length of the radius in app units.
static nscoord ComputeCircleRadius(
mozilla::StyleBasicShape* const aBasicShape,
const nsPoint& aCenter, const nsRect& aRefBox);
+
+ // Compute the radii for an ellipse.
+ // @param aCenter the center of the ellipse.
+ // @param aRefBox the reference box of the ellipse.
+ // @return The radii of the ellipse in app units. The width and height
+ // represent the x-axis and y-axis radii of the ellipse.
+ static nsSize ComputeEllipseRadii(
+ mozilla::StyleBasicShape* const aBasicShape,
+ const nsPoint& aCenter, const nsRect& aRefBox);
};
} // namespace mozilla
#endif // mozilla_ShapeUtils_h
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -130,42 +130,22 @@ nsCSSClipPathInstance::CreateClipPathEll
const nsRect& aRefBox)
{
StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
nsPoint center =
ShapeUtils::ComputeCircleOrEllipseCenter(basicShape, aRefBox);
-
- const nsTArray<nsStyleCoord>& coords = basicShape->Coordinates();
- MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments");
- nscoord rx = 0, ry = 0;
- if (coords[0].GetUnit() == eStyleUnit_Enumerated) {
- rx = ShapeUtils::ComputeShapeRadius(coords[0].GetEnumValue<StyleShapeRadius>(),
- center.x,
- aRefBox.x,
- aRefBox.x + aRefBox.width);
- } else {
- rx = nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.width);
- }
- if (coords[1].GetUnit() == eStyleUnit_Enumerated) {
- ry = ShapeUtils::ComputeShapeRadius(coords[1].GetEnumValue<StyleShapeRadius>(),
- center.y,
- aRefBox.y,
- aRefBox.y + aRefBox.height);
- } else {
- ry = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height);
- }
-
+ nsSize radii = ShapeUtils::ComputeEllipseRadii(basicShape, center, aRefBox);
nscoord appUnitsPerDevPixel =
mTargetFrame->PresContext()->AppUnitsPerDevPixel();
EllipseToBezier(builder.get(),
Point(center.x, center.y) / appUnitsPerDevPixel,
- Size(rx, ry) / appUnitsPerDevPixel);
+ Size(radii.width, radii.height) / appUnitsPerDevPixel);
builder->Close();
return builder->Finish();
}
already_AddRefed<Path>
nsCSSClipPathInstance::CreateClipPathPolygon(DrawTarget* aDrawTarget,
const nsRect& aRefBox)
{