Bug 1326407 Part 2 - Extract a function to compute inset radii. r=dbaron
authorTing-Yu Lin <tlin@mozilla.com>
Thu, 16 Feb 2017 10:51:48 +0800
changeset 343236 2b9a5fad30b78c77860a5418b8db96b56edab11b
parent 343235 ecc715f72d6112bd6a57a5b52603c3ca2683a003
child 343237 b0af1a8bdcaf6952ba6be848bf83248e6fb455c4
push id31372
push usercbook@mozilla.com
push dateThu, 16 Feb 2017 12:16:10 +0000
treeherdermozilla-central@2737f66ad6ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1326407
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1326407 Part 2 - Extract a function to compute inset radii. r=dbaron MozReview-Commit-ID: 3XbfW40AJCI
layout/base/ShapeUtils.cpp
layout/base/ShapeUtils.h
layout/svg/nsCSSClipPathInstance.cpp
--- a/layout/base/ShapeUtils.cpp
+++ b/layout/base/ShapeUtils.cpp
@@ -132,9 +132,21 @@ ShapeUtils::ComputeInsetRect(StyleBasicS
                  nsRuleNode::ComputeCoordPercentCalc(coords[3], aRefBox.width));
 
   nsRect insetRect(aRefBox);
   insetRect.Deflate(inset);
 
   return insetRect;
 }
 
+/* static */ bool
+ShapeUtils::ComputeInsetRadii(StyleBasicShape* const aBasicShape,
+                              const nsRect& aInsetRect,
+                              const nsRect& aRefBox,
+                              nscoord aRadii[8])
+{
+  const nsStyleCorners& radius = aBasicShape->GetRadius();
+  return nsIFrame::ComputeBorderRadii(radius, aInsetRect.Size(), aRefBox.Size(),
+                                      Sides(), aRadii);
+
+}
+
 } // namespace mozilla
--- a/layout/base/ShapeUtils.h
+++ b/layout/base/ShapeUtils.h
@@ -57,13 +57,24 @@ struct ShapeUtils final
     const nsPoint& aCenter, const nsRect& aRefBox);
 
   // Compute the rect for an inset.
   // @param aRefBox the reference box of the inset.
   // @return The inset rect in app units.
   static nsRect ComputeInsetRect(
     mozilla::StyleBasicShape* const aBasicShape,
     const nsRect& aRefBox);
+
+  // Compute the radii for an inset.
+  // @param aRefBox the reference box of the inset.
+  // @param aInsetRect the inset rect computed by ComputeInsetRect().
+  // @param aRadii the returned radii in app units.
+  // @return true if any of the radii is nonzero; false otherwise.
+  static bool ComputeInsetRadii(
+    mozilla::StyleBasicShape* const aBasicShape,
+    const nsRect& aInsetRect,
+    const nsRect& aRefBox,
+    nscoord aRadii[8]);
 };
 
 } // namespace mozilla
 
 #endif // mozilla_ShapeUtils_h
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -180,22 +180,20 @@ nsCSSClipPathInstance::CreateClipPathIns
 
   RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
 
   nscoord appUnitsPerDevPixel =
     mTargetFrame->PresContext()->AppUnitsPerDevPixel();
 
   nsRect insetRect = ShapeUtils::ComputeInsetRect(basicShape, aRefBox);
   const Rect insetRectPixels = NSRectToRect(insetRect, appUnitsPerDevPixel);
-  const nsStyleCorners& radius = basicShape->GetRadius();
-
   nscoord appUnitsRadii[8];
 
-  if (nsIFrame::ComputeBorderRadii(radius, insetRect.Size(), aRefBox.Size(),
-                                   Sides(), appUnitsRadii)) {
+  if (ShapeUtils::ComputeInsetRadii(basicShape, insetRect, aRefBox,
+                                    appUnitsRadii)) {
     RectCornerRadii corners;
     nsCSSRendering::ComputePixelRadii(appUnitsRadii,
                                       appUnitsPerDevPixel, &corners);
 
     AppendRoundedRectToPath(builder, insetRectPixels, corners, true);
   } else {
     AppendRectToPath(builder, insetRectPixels, true);
   }