Bug 633337 - pattern viewBoxes not treated correctly. r=jwatt
authorRobert Longson <longsonr@gmail.com>
Sat, 09 Apr 2011 21:57:51 +0100
changeset 67797 4ff3dfaadd48709d3287b4a9104f3b4d9f5ccee1
parent 67796 c51a334e99d9b1d0ee31f072cce83568d97f39ef
child 67798 d90464774dfe407b5560830b58881d59ec486e72
push id19428
push usereakhgari@mozilla.com
push dateSun, 10 Apr 2011 19:11:44 +0000
treeherdermozilla-central@6eaee284fdb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs633337
milestone2.2a1pre
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 633337 - pattern viewBoxes not treated correctly. r=jwatt
layout/reftests/svg/viewBox-and-pattern-01.svg
layout/svg/base/src/nsSVGPatternFrame.cpp
--- a/layout/reftests/svg/viewBox-and-pattern-01.svg
+++ b/layout/reftests/svg/viewBox-and-pattern-01.svg
@@ -4,16 +4,16 @@
 -->
 <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
 
   <title>Testcase for elements referencing a viewBox pattern</title>
 
   <!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=519368 -->
 
   <defs>
-    <pattern id="test" patternUnits="userSpaceOnUse" x="10" y="10" width="20%" height="20%" viewBox="10 10 10 10">
+    <pattern id="test" patternUnits="userSpaceOnUse" x="10" y="10" width="20" height="20" viewBox="10 10 10 10">
       <rect x="10" y="10" width="10" height="10" fill="lime" />
     </pattern>
   </defs>
   <rect width="100%" height="100%" fill="lime" />
   <rect x="20" y="20" width="100" height="100" fill="red" />
   <rect x="20" y="20" width="100" height="100" fill="url(#test)" />
 </svg>
--- a/layout/svg/base/src/nsSVGPatternFrame.cpp
+++ b/layout/svg/base/src/nsSVGPatternFrame.cpp
@@ -580,52 +580,45 @@ nsSVGPatternFrame::ConstructCTM(const gf
   } else {
     if (targetContent->IsSVG()) {
       ctx = static_cast<nsSVGElement*>(targetContent)->GetCtx();
     }
     float scale = nsSVGUtils::MaxExpansion(callerCTM);
     tCTM.Scale(scale, scale);
   }
 
-  nsSVGPatternElement *patternElement =
-    static_cast<nsSVGPatternElement*>(mContent);
-  gfxMatrix tm;
   const nsSVGViewBoxRect viewBox = GetViewBox().GetAnimValue();
 
-  if (viewBox.height > 0.0f && viewBox.width > 0.0f) {
-    float viewportWidth, viewportHeight, refX, refY;
-    if (targetContent->IsSVG()) {
-      // If we're dealing with an SVG target only retrieve the context once.
-      // Calling the nsIFrame* variant of GetAnimValue would look it up on
-      // every call.
-      viewportWidth =
-        GetLengthValue(nsSVGPatternElement::WIDTH)->GetAnimValue(ctx);
-      viewportHeight =
-        GetLengthValue(nsSVGPatternElement::HEIGHT)->GetAnimValue(ctx);
-      refX = GetLengthValue(nsSVGPatternElement::X)->GetAnimValue(ctx);
-      refY = GetLengthValue(nsSVGPatternElement::Y)->GetAnimValue(ctx);
-    } else {
-      // No SVG target, call the nsIFrame* variant of GetAnimValue.
-      viewportWidth =
-        GetLengthValue(nsSVGPatternElement::WIDTH)->GetAnimValue(aTarget);
-      viewportHeight =
-        GetLengthValue(nsSVGPatternElement::HEIGHT)->GetAnimValue(aTarget);
-      refX = GetLengthValue(nsSVGPatternElement::X)->GetAnimValue(aTarget);
-      refY = GetLengthValue(nsSVGPatternElement::Y)->GetAnimValue(aTarget);
-    }
-    gfxMatrix viewBoxTM = nsSVGUtils::GetViewBoxTransform(patternElement,
-                                                          viewportWidth, viewportHeight,
-                                                          viewBox.x, viewBox.y,
-                                                          viewBox.width, viewBox.height,
-                                                          GetPreserveAspectRatio());
+  if (viewBox.height <= 0.0f && viewBox.width <= 0.0f) {
+    return tCTM;
+  }
 
-    gfxPoint ref = viewBoxTM.Transform(gfxPoint(refX, refY));
+  float viewportWidth, viewportHeight;
+  if (targetContent->IsSVG()) {
+    // If we're dealing with an SVG target only retrieve the context once.
+    // Calling the nsIFrame* variant of GetAnimValue would look it up on
+    // every call.
+    viewportWidth =
+      GetLengthValue(nsSVGPatternElement::WIDTH)->GetAnimValue(ctx);
+    viewportHeight =
+      GetLengthValue(nsSVGPatternElement::HEIGHT)->GetAnimValue(ctx);
+  } else {
+    // No SVG target, call the nsIFrame* variant of GetAnimValue.
+    viewportWidth =
+      GetLengthValue(nsSVGPatternElement::WIDTH)->GetAnimValue(aTarget);
+    viewportHeight =
+      GetLengthValue(nsSVGPatternElement::HEIGHT)->GetAnimValue(aTarget);
+  }
+  gfxMatrix tm = nsSVGUtils::GetViewBoxTransform(
+    static_cast<nsSVGPatternElement*>(mContent),
+    viewportWidth, viewportHeight,
+    viewBox.x, viewBox.y,
+    viewBox.width, viewBox.height,
+    GetPreserveAspectRatio());
 
-    tm = viewBoxTM * gfxMatrix().Translate(gfxPoint(-ref.x, -ref.y));
-  }
   return tm * tCTM;
 }
 
 gfxMatrix
 nsSVGPatternFrame::GetPatternMatrix(const gfxRect &bbox,
                                     const gfxRect &callerBBox,
                                     const gfxMatrix &callerCTM)
 {