Bug 1250773. Ignore viewBoxes with negative width/height. r=heycam
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 24 Feb 2016 17:29:14 +1300
changeset 321715 4894d75bf376b60766430de3b76106023bab4ac3
parent 321714 3329b93589df2613f87fb475eace4b30c1cd0af4
child 321716 a097eb2ace2276e8f34477cacb061a7360fdf4e5
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1250773
milestone47.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 1250773. Ignore viewBoxes with negative width/height. r=heycam MozReview-Commit-ID: Be5fxaDz85w
dom/svg/nsSVGViewBox.h
layout/reftests/svg/reftest.list
layout/reftests/svg/viewBox-invalid-02.svg
--- a/dom/svg/nsSVGViewBox.h
+++ b/dom/svg/nsSVGViewBox.h
@@ -42,34 +42,39 @@ struct nsSVGViewBoxRect
 class nsSVGViewBox
 {
 public:
 
   void Init();
 
   /**
    * Returns true if the corresponding "viewBox" attribute defined a rectangle
-   * with finite values. Returns false if the viewBox was set to an invalid
+   * with finite values and nonnegative width/height.
+   * Returns false if the viewBox was set to an invalid
    * string, or if any of the four rect values were too big to store in a
-   * float.
-   *
-   * This method does not check whether the width or height values are
-   * positive, so callers must check whether the viewBox rect is valid where
-   * necessary!
+   * float, or the width/height are negative.
    */
   bool HasRect() const
-    { return (mAnimVal && !mAnimVal->none) ||
-             (!mAnimVal && mHasBaseVal && !mBaseVal.none); }
+    {
+      const nsSVGViewBoxRect& rect = GetAnimValue();
+      return !rect.none && rect.width >= 0 && rect.height >= 0;
+    }
 
   /**
    * Returns true if the corresponding "viewBox" attribute either defined a
    * rectangle with finite values or the special "none" value.
    */
   bool IsExplicitlySet() const
-    { return mAnimVal || mHasBaseVal; }
+    {
+      if (mAnimVal || mHasBaseVal) {
+        const nsSVGViewBoxRect& rect = GetAnimValue();
+        return rect.none || (rect.width >= 0 && rect.height >= 0);
+      }
+      return false;
+    }
 
   const nsSVGViewBoxRect& GetBaseValue() const
     { return mBaseVal; }
   void SetBaseValue(const nsSVGViewBoxRect& aRect,
                     nsSVGElement *aSVGElement);
   const nsSVGViewBoxRect& GetAnimValue() const
     { return mAnimVal ? *mAnimVal : mBaseVal; }
   void SetAnimValue(const nsSVGViewBoxRect& aRect,
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -388,16 +388,17 @@ fuzzy-if(skiaContent,1,300) == tspan-xy-
 fuzzy-if(skiaContent,1,100) == tspan-xy-anchor-middle-01.svg tspan-xy-anchor-middle-ref.svg # bug 773482
 fuzzy-if(skiaContent,1,100) == tspan-xy-anchor-end-01.svg tspan-xy-anchor-end-ref.svg # bug 773482
 == userSpaceOnUse-and-pattern-01.svg userSpaceOnUse-and-pattern-01-ref.svg
 == viewBox-and-pattern-01.svg pass.svg
 == viewBox-and-pattern-02.svg pass.svg
 == viewBox-and-pattern-03.svg pass.svg
 == viewBox-and-pattern-04.svg pass.svg
 == viewBox-invalid-01.svg pass.svg
+== viewBox-invalid-02.svg pass.svg
 == viewBox-valid-01.svg pass.svg
 == viewBox-valid-02.xhtml pass.svg
 == viewport-percent-graphic-user-01.svg pass.svg
 == winding-01.svg pass.svg
 
 == svg-effects-area-unzoomed.xhtml svg-effects-area-unzoomed-ref.xhtml
 == svg-effects-area-zoomed-in.xhtml svg-effects-area-zoomed-in-ref.xhtml
 == svg-effects-area-zoomed-out.xhtml svg-effects-area-zoomed-out-ref.xhtml
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/viewBox-invalid-02.svg
@@ -0,0 +1,38 @@
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+     xmlns:xlink="http://www.w3.org/1999/xlink">
+  <title>Testing invalid values for |viewBox| attributes</title>
+  <defs>
+    <rect id="redRect"  fill="red"  height="10" width="10"/>
+    <rect id="limeRect" fill="lime" height="10" width="10"/>
+  </defs>
+  <rect fill="lime" height="100%" width="100%"/>
+
+  <g transform="translate(0, 0)">
+    <use xlink:href="#redRect"/>
+    <!-- negative width/height in viewBox should ignore entire attribute -->
+    <svg width="20" height="20" viewBox="0,0,0,-1">
+      <use xlink:href="#limeRect"/>
+    </svg>
+  </g>
+  <g transform="translate(20, 0)">
+    <use xlink:href="#redRect"/>
+    <!-- negative width/height in viewBox should ignore entire attribute -->
+    <svg width="20" height="20" viewBox="0,0,-1,0">
+      <use xlink:href="#limeRect"/>
+    </svg>
+  </g>
+  <g transform="translate(40, 0)">
+    <use xlink:href="#limeRect"/>
+    <!-- zero width/height in viewBox should render nothing -->
+    <svg width="20" height="20" viewBox="0,0,0,20">
+      <use xlink:href="#redRect"/>
+    </svg>
+  </g>
+  <g transform="translate(60, 0)">
+    <use xlink:href="#limeRect"/>
+    <!-- zero width/height in viewBox should render nothing -->
+    <svg width="20" height="20" viewBox="0,0,20,0">
+      <use xlink:href="#redRect"/>
+    </svg>
+  </g>
+</svg>