Bug 823964 - Wrong bounds for scaled images. r=longsonr
authorJonathan Kew <jfkthame@gmail.com>
Sat, 22 Dec 2012 10:07:00 +0000
changeset 116856 4fa2400559e04e20c8c2ab7880f6727e4f226e0b
parent 116855 f1c7eade6c974813db71bcc451cc3dcbc50e440b
child 116857 79d9e21392276cdfc305241381fba7dfd6705a91
push id20185
push userlongsonr@gmail.com
push dateSat, 22 Dec 2012 10:06:54 +0000
treeherdermozilla-inbound@4fa2400559e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs823964
milestone20.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 823964 - Wrong bounds for scaled images. r=longsonr
content/svg/content/test/bbox-helper.svg
content/svg/content/test/bounds-helper.svg
content/svg/content/test/test_bbox.xhtml
content/svg/content/test/test_bounds.html
layout/svg/nsSVGImageFrame.cpp
--- a/content/svg/content/test/bbox-helper.svg
+++ b/content/svg/content/test/bbox-helper.svg
@@ -1,12 +1,13 @@
 <?xml version="1.0"?>
 <svg xmlns="http://www.w3.org/2000/svg">
   <g transform="scale(0.5)">
     <foreignObject id="fO" x="10" y="10" width="100" height="100"/>
+    <image id="i" x="10" y="10" width="100" height="100"/>
   </g>
   <text id="b" x="20" y="20">b</text>
   <text id="a" x="20" y="30">a</text>
   <text id="y" x="20" y="40">y</text>
   <text id="tspan">
     <tspan x="20" y="20">b</tspan>
   </text>
   <g id="v">
--- a/content/svg/content/test/bounds-helper.svg
+++ b/content/svg/content/test/bounds-helper.svg
@@ -16,15 +16,16 @@ text { font: 20px monospace; }
     <rect id="rect2" x="150" y="50" width="50" height="50" fill="yellow"/>
     <rect id="rect2a" x="150" y="50" width="50" height="50" fill="none" stroke-width="4" stroke="blue"/>
     <text id="text3" x="150" y="50" text-anchor="middle">abc</text>
   </g>
   <g transform="scale(2)">
     <rect id="rect3" x="25" y="80" width="50" height="50" fill="green"/>
     <rect id="rect3a" x="25" y="80" width="50" height="50" fill="none" stroke-width="4" stroke="blue"/>
     <rect id="rect3b" vector-effect="non-scaling-stroke" x="100" y="100" width="25" height="25" fill="orange" stroke-width="4" stroke="yellow"/>
+    <image id="i" x="10" y="10" width="100" height="100"/>
   </g>
   <g transform="scale(2) rotate(45 175 75)">
     <rect id="rect4" x="150" y="50" width="50" height="50" fill="yellow"/>
     <rect id="rect4a" x="150" y="50" width="50" height="50" fill="none" stroke-width="4" stroke="blue"/>
   </g>
 </g>
 </svg>
--- a/content/svg/content/test/test_bbox.xhtml
+++ b/content/svg/content/test/test_bbox.xhtml
@@ -43,16 +43,17 @@ function run()
   }
   function compareBBoxHeight(id1, id2) {
     var bbox1 = getBBox(id1);
     var bbox2 = getBBox(id2);
     is(bbox1.height, bbox2.height, id1 + ".getBBox().height");
   }
 
   checkBBox("fO", 10, 10, 100, 100);
+  checkBBox("i", 10, 10, 100, 100);
   compareBBoxHeight("a", "b");
   compareBBoxHeight("a", "y");
   compareBBox("b", "tspan");
   checkBBox("v", 95, 45, 10, 155);
   checkBBox("h", 195, 45, 105, 55);
   checkBBox("e", 95, 95, 10, 10);
   
   SimpleTest.finish();
--- a/content/svg/content/test/test_bounds.html
+++ b/content/svg/content/test/test_bounds.html
@@ -129,16 +129,23 @@ function runTest()
   var text2aBounds = doc.getElementById("text2a").getBoundingClientRect();
 
   isWithAbsTolerance(text1aBounds.left, 82, 1, "text1a.getBoundingClientRect().left");
   is(text1aBounds.width, text1Bounds.width + 4, "text1a.getBoundingClientRect().width");
 
   is(text2aBounds.left, text1aBounds.left + 100 - 3, "text2a.getBoundingClientRect().left");
   is(text2aBounds.width, text1aBounds.width + 6, "text2a.getBoundingClientRect().width");
 
+  var i = doc.getElementById("i");
+  var iBounds = i.getBoundingClientRect();
+  is(iBounds.left, 20, "i.getBoundingClientRect().left");
+  is(iBounds.top, 20, "i.getBoundingClientRect().top");
+  is(iBounds.width, 200, "i.getBoundingClientRect().width");
+  is(iBounds.height, 200, "i.getBoundingClientRect().height");
+
   SimpleTest.finish();
 }
 
 window.addEventListener("load", runTest, false);
 </script>
 </pre>
 </body>
 </html>
--- a/layout/svg/nsSVGImageFrame.cpp
+++ b/layout/svg/nsSVGImageFrame.cpp
@@ -480,18 +480,20 @@ nsSVGImageFrame::ReflowSVG()
   // overwhelming number of SVGs will never have this problem.
   // XXX Will Azure eventually save us from having to do this?
   gfxSize scaleFactors = GetCanvasTM(FOR_OUTERSVG_TM).ScaleFactors(true);
   bool applyScaling = fabs(scaleFactors.width) >= 1e-6 &&
                       fabs(scaleFactors.height) >= 1e-6;
   gfxMatrix scaling;
   if (applyScaling) {
     scaling.Scale(scaleFactors.width, scaleFactors.height);
-  } 
+  }
+  tmpCtx.Save();
   GeneratePath(&tmpCtx, scaling);
+  tmpCtx.Restore();
   gfxRect extent = tmpCtx.GetUserPathExtent();
   if (applyScaling) {
     extent.Scale(1 / scaleFactors.width, 1 / scaleFactors.height);
   }
 
   if (!extent.IsEmpty()) {
     mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent, 
               PresContext()->AppUnitsPerCSSPixel());