Bug 1294966 - Part 2. Return correct width/height of bbox of an svg element even if the size of it is empty. draft
authorcku <cku@mozilla.com>
Wed, 06 Sep 2017 20:18:10 +0800
changeset 660002 b1c7a279ad5a27bab34127e993d947aab7260944
parent 659968 10fa430bc0c572a0ce793f1b57ab07bd028741c7
child 660003 2d3f1c29389a543b95778b2d5e81c63ac4dd0f10
push id78273
push userbmo:cku@mozilla.com
push dateWed, 06 Sep 2017 14:43:42 +0000
bugs1294966
milestone57.0a1
Bug 1294966 - Part 2. Return correct width/height of bbox of an svg element even if the size of it is empty. MozReview-Commit-ID: JnycqLvgu6D
dom/svg/SVGImageElement.cpp
dom/svg/SVGRectElement.cpp
--- a/dom/svg/SVGImageElement.cpp
+++ b/dom/svg/SVGImageElement.cpp
@@ -248,17 +248,19 @@ SVGImageElement::GetGeometryBounds(Rect*
                                    const Matrix* aToNonScalingStrokeSpace)
 {
   Rect rect;
   GetAnimatedLengthValues(&rect.x, &rect.y, &rect.width,
                           &rect.height, nullptr);
 
   if (rect.IsEmpty()) {
     // Rendering of the element disabled
-    rect.SetEmpty(); // Make sure width/height are zero and not negative
+    // Make sure width/height are not negative
+    rect.x = rect.x >= 0 ? rect.x : 0;
+    rect.y = rect.y >= 0 ? rect.y : 0;
   }
 
   *aBounds = aToBoundsSpace.TransformBounds(rect);
   return true;
 }
 
 already_AddRefed<Path>
 SVGImageElement::BuildPath(PathBuilder* aBuilder)
--- a/dom/svg/SVGRectElement.cpp
+++ b/dom/svg/SVGRectElement.cpp
@@ -119,17 +119,19 @@ SVGRectElement::GetGeometryBounds(Rect* 
 {
   Rect rect;
   Float rx, ry;
   GetAnimatedLengthValues(&rect.x, &rect.y, &rect.width,
                           &rect.height, &rx, &ry, nullptr);
 
   if (rect.IsEmpty()) {
     // Rendering of the element disabled
-    rect.SetEmpty(); // Make sure width/height are zero and not negative
+    // Make sure width/height are not negative
+    rect.x = rect.x >= 0 ? rect.x : 0;
+    rect.y = rect.y >= 0 ? rect.y : 0;
     // We still want the x/y position from 'rect'
     *aBounds = aToBoundsSpace.TransformBounds(rect);
     return true;
   }
 
   if (!aToBoundsSpace.IsRectilinear()) {
     // We can't ignore the radii in this case if we want tight bounds
     rx = std::max(rx, 0.0f);