Bug 620468 - Bail out earlier when computing CTM of an <svg> element with negative width/height attributes. r=longsonr

This commit is contained in:
Cameron McCormack 2012-02-19 22:17:12 +11:00
parent d2535ba994
commit b5e1f40811
3 changed files with 13 additions and 1 deletions

View File

@ -1001,6 +1001,10 @@ nsSVGSVGElement::GetViewBoxTransform() const
viewportHeight = mViewportHeight;
}
if (viewportWidth <= 0.0f || viewportHeight <= 0.0f) {
return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
}
nsSVGViewBoxRect viewBox;
if (mViewBox.IsValid()) {
viewBox = mViewBox.GetAnimValue();

View File

@ -17,6 +17,9 @@
<svg id="inner" x="30" y="40" width="100" height="100">
<g id="g1"/>
</svg>
<svg id="inner-2" viewBox="0 0 10 10" width="-10" height="10">
<g id="g5"/>
</svg>
<foreignObject id="fO" x="30" y="40" width="100" height="100" transform="translate(1, 1)">
<!-- current layout implementation ignores x="50" and y="60".
thus, I made getCTM and getScreenCTM do the same. -->

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -35,6 +35,7 @@ function runTest()
var g2 = doc.getElementById("g2");
var g3 = doc.getElementById("g3");
var g4 = doc.getElementById("g4");
var g5 = doc.getElementById("g5");
var sym = doc.getElementById("sym");
var symbolRect = doc.getElementById("symbolRect");
var fO = doc.getElementById("fO");
@ -61,9 +62,11 @@ function runTest()
// symbolRect.nearestViewportElement == sym
is((function(){try{return symbolRect.getCTM().e}catch(e){return e}})(), 70, "symbolRect.getCTM().e");
is((function(){try{return symbolRect.getCTM().f}catch(e){return e}})(), 80, "symbolRect.getCTM().f");
// fO.nearestViewportElement = <svg> with no 'id'
// fO.nearestViewportElement == <svg> with no 'id'
is((function(){try{return fO.getCTM().e}catch(e){return e}})(), 2, "fO.getCTM().e");
is((function(){try{return fO.getCTM().f}catch(e){return e}})(), 3, "fO.getCTM().f");
// g5.nearestViewportElement == inner-2
is((function(){try{return g5.getCTM()}catch(e){return e}})(), null, "g5.getCTM()");
/* Tests the consistency with farthestViewportElement
(code is from test_viewport.html) */
@ -90,6 +93,8 @@ function runTest()
// fO.farthestViewportElement == root
is((function(){try{return fO.getScreenCTM().e}catch(e){return e}})(), 16, "symbolRect.getScreenCTM().e");
is((function(){try{return fO.getScreenCTM().f}catch(e){return e}})(), 29, "symbolRect.getScreenCTM().f");
// g5.farthestViewportElement == root
is((function(){try{return g5.getScreenCTM()}catch(e){return e}})(), null, "g5.getScreenCTM()");
SimpleTest.finish();
}