From 2487c4de1e92172fc586887026327571cf383cdd Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Sun, 12 Jun 2011 18:52:32 -0700 Subject: [PATCH] Remove notion of percentage intrinsic size: remove the single case that (incorrectly) sets percentage intrinsic sizes, and fix all of the tests that depend on our old incorrect behavior. (Bug 611099) r=dholbert Needed to help CSS 2.1 meet Proposed Recommendation entrance criteria. --- .../as-image/img-novb-height-all-1-ref.html | 10 ++-- .../as-image/img-novb-width-all-1-ref.html | 12 ++-- layout/reftests/svg/dynamic-rect-04.xhtml | 2 + .../dynamic--inline-resize-cb-height.xhtml | 4 +- .../dynamic--inline-resize-cb-width.xhtml | 4 +- .../dynamic--object--auto-auto--pct-px.html | 9 +-- .../inline--position-absolute--02.xhtml | 4 +- .../sizing/object--auto-auto--0-pct--ref.html | 2 +- .../svg/sizing/object--auto-auto--0-pct.html | 9 +-- .../sizing/object--auto-auto--pct-0--ref.html | 2 +- .../svg/sizing/object--auto-auto--pct-0.html | 10 ++-- layout/reftests/svg/sizing/reftest.list | 6 +- .../svg/svg-in-foreignObject-01.xhtml | 2 +- .../svg/svg-in-foreignObject-02.xhtml | 2 +- .../clipPath-html-06-extref.xhtml | 2 +- .../svg-integration/clipPath-html-06.xhtml | 2 +- .../conditions-outer-svg-01.xhtml | 2 +- .../conditions-outer-svg-02.xhtml | 2 +- .../dynamic-conditions-outer-svg-01.xhtml | 2 +- .../dynamic-conditions-outer-svg-02.xhtml | 2 +- .../dynamic-conditions-outer-svg-03.xhtml | 2 +- .../dynamic-conditions-outer-svg-04.xhtml | 2 +- layout/svg/base/src/nsSVGOuterSVGFrame.cpp | 60 ++++++++++++++----- .../htmlparser/tests/reftest/bug577418-1.html | 2 +- 24 files changed, 95 insertions(+), 61 deletions(-) diff --git a/layout/reftests/svg/as-image/img-novb-height-all-1-ref.html b/layout/reftests/svg/as-image/img-novb-height-all-1-ref.html index 51448fee174b..999ce5aa6358 100644 --- a/layout/reftests/svg/as-image/img-novb-height-all-1-ref.html +++ b/layout/reftests/svg/as-image/img-novb-height-all-1-ref.html @@ -18,15 +18,15 @@ // elements. // * FIRST TWO ROWS: has width=auto height=auto - // - Each renders w/ width = 10% * body_width = .1*600 = 60px - // - Synthesized viewBox has width = 10% * viewport_width = .1*60 = 6 + // - Each renders w/ width = 300px (default) + // - Synthesized viewBox has width = 10% * viewport_width = .1*300 = 30 // - & viewBox both get height=30px, from height attr - svgParams.viewBox = [0, 0, 6, 30], - appendSVGSubArrayWithParams(svgParams, "embed", "60px", "30px"); + svgParams.viewBox = [0, 0, 30, 30], + appendSVGSubArrayWithParams(svgParams, "embed", "300px", "30px"); // * SECOND TWO ROWS: has width=auto, height=20px // Calculations are as above, except now imposes height="20px". - appendSVGSubArrayWithParams(svgParams, "embed", "60px", "20px"); + appendSVGSubArrayWithParams(svgParams, "embed", "300px", "20px"); // * THIRD TWO ROWS: has width=30px height=auto // - now renders w/ width = 30px (imposed by width attr) diff --git a/layout/reftests/svg/as-image/img-novb-width-all-1-ref.html b/layout/reftests/svg/as-image/img-novb-width-all-1-ref.html index 35592f862854..9d99b4da67b0 100644 --- a/layout/reftests/svg/as-image/img-novb-width-all-1-ref.html +++ b/layout/reftests/svg/as-image/img-novb-width-all-1-ref.html @@ -18,11 +18,11 @@ // elements. // * FIRST TWO ROWS: has width=auto height=auto - // - Each renders w/ height = 20% * body_height = .2*600 = 120px - // - Synthesized viewBox has height = 20% * viewport_height = .2*120 = 24 + // - Each renders w/ height = 150px (default) + // - Synthesized viewBox has height = 20% * viewport_height = .2*150 = 30 // - & viewBox both get width=20px, from width attr - svgParams.viewBox = [0, 0, 20, 24], - appendSVGSubArrayWithParams(svgParams, "embed", "20px", "120px"); + svgParams.viewBox = [0, 0, 20, 30], + appendSVGSubArrayWithParams(svgParams, "embed", "20px", "150px"); // * SECOND TWO ROWS: has width=auto, height=20px // - now renders w/ height = 20px (imposed by height attr) @@ -34,8 +34,8 @@ // * THIRD TWO ROWS: has width=30px height=auto // Calculations are as with "FIRST TWO ROWS", except now imposes // width="30px". - svgParams.viewBox = [0, 0, 20, 24], - appendSVGSubArrayWithParams(svgParams, "embed", "30px", "120px"); + svgParams.viewBox = [0, 0, 20, 30], + appendSVGSubArrayWithParams(svgParams, "embed", "30px", "150px"); // * FOURTH TWO ROWS: has width=30px height=20px // Calculations are as with "SECOND TWO ROWS", except now imposes diff --git a/layout/reftests/svg/dynamic-rect-04.xhtml b/layout/reftests/svg/dynamic-rect-04.xhtml index 112e327aeeb7..a176065c5d59 100644 --- a/layout/reftests/svg/dynamic-rect-04.xhtml +++ b/layout/reftests/svg/dynamic-rect-04.xhtml @@ -14,6 +14,8 @@ function m() { svg.style.position = 'absolute'; svg.style.left = '0px'; svg.style.top = '0px'; + svg.style.width = '100%'; + svg.style.height = '100%'; document.body.appendChild(svg); var rect = document.createElementNS(SVG_NS, "rect"); diff --git a/layout/reftests/svg/sizing/dynamic--inline-resize-cb-height.xhtml b/layout/reftests/svg/sizing/dynamic--inline-resize-cb-height.xhtml index 4a914f4574a0..a2703bfedcd9 100644 --- a/layout/reftests/svg/sizing/dynamic--inline-resize-cb-height.xhtml +++ b/layout/reftests/svg/sizing/dynamic--inline-resize-cb-height.xhtml @@ -22,7 +22,7 @@ html, body, div { margin: 0; width: 100%; height: 100%; /* inline style override on the div below */ - background: red; + background: white; overflow: hidden; } @@ -44,7 +44,7 @@ document.addEventListener("MozReftestInvalidate", resize_div, false);
- +
diff --git a/layout/reftests/svg/sizing/dynamic--inline-resize-cb-width.xhtml b/layout/reftests/svg/sizing/dynamic--inline-resize-cb-width.xhtml index 237624fe24f3..8b62f2ff14bf 100644 --- a/layout/reftests/svg/sizing/dynamic--inline-resize-cb-width.xhtml +++ b/layout/reftests/svg/sizing/dynamic--inline-resize-cb-width.xhtml @@ -22,7 +22,7 @@ html, body, div { margin: 0; width: 100%; /* inline style override on the div below */ height: 100%; - background: red; + background: white; overflow: hidden; } @@ -44,7 +44,7 @@ document.addEventListener("MozReftestInvalidate", resize_div, false);
- +
diff --git a/layout/reftests/svg/sizing/dynamic--object--auto-auto--pct-px.html b/layout/reftests/svg/sizing/dynamic--object--auto-auto--pct-px.html index 6b9666076c3f..8879ebadb3b3 100644 --- a/layout/reftests/svg/sizing/dynamic--object--auto-auto--pct-px.html +++ b/layout/reftests/svg/sizing/dynamic--object--auto-auto--pct-px.html @@ -10,10 +10,11 @@ Test: width:auto; height:auto; width="49%" height="70px" diff --git a/layout/reftests/svg/sizing/object--auto-auto--0-pct.html b/layout/reftests/svg/sizing/object--auto-auto--0-pct.html index 8632a7f56d61..e6c3a35630c5 100644 --- a/layout/reftests/svg/sizing/object--auto-auto--0-pct.html +++ b/layout/reftests/svg/sizing/object--auto-auto--0-pct.html @@ -10,10 +10,11 @@ Test: width:auto; height:auto; width="0" height="49%" + diff --git a/layout/reftests/svg/svg-integration/conditions-outer-svg-02.xhtml b/layout/reftests/svg/svg-integration/conditions-outer-svg-02.xhtml index 0ade2d47830e..662c3f9436e6 100644 --- a/layout/reftests/svg/svg-integration/conditions-outer-svg-02.xhtml +++ b/layout/reftests/svg/svg-integration/conditions-outer-svg-02.xhtml @@ -8,7 +8,7 @@ Test that using elements from conditional-failing outer 'svg' elements works - + diff --git a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-01.xhtml b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-01.xhtml index 22192029a1d5..a2ff5b83df17 100644 --- a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-01.xhtml +++ b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-01.xhtml @@ -7,7 +7,7 @@ Test that conditional processing attributes on outer 'svg' elements are honored - + diff --git a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-02.xhtml b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-02.xhtml index 9e053e3ea5cf..85e4b3175b26 100644 --- a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-02.xhtml +++ b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-02.xhtml @@ -7,7 +7,7 @@ Test that conditional processing attributes on outer 'svg' elements are honored - + diff --git a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-03.xhtml b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-03.xhtml index 6ca2b96eee15..c3176e2af4d5 100644 --- a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-03.xhtml +++ b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-03.xhtml @@ -7,7 +7,7 @@ Test that conditional processing attributes on outer 'svg' elements are honored - + diff --git a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-04.xhtml b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-04.xhtml index c29aabdd356d..2d8e108051f5 100644 --- a/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-04.xhtml +++ b/layout/reftests/svg/svg-integration/dynamic-conditions-outer-svg-04.xhtml @@ -7,7 +7,7 @@ Test that conditional processing attributes on outer 'svg' elements are honored - + diff --git a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp index 9e31bbbc5921..ff75d673fef3 100644 --- a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp +++ b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp @@ -248,21 +248,13 @@ nsSVGOuterSVGFrame::GetIntrinsicSize() nsSVGLength2 &width = content->mLengthAttributes[nsSVGSVGElement::WIDTH]; nsSVGLength2 &height = content->mLengthAttributes[nsSVGSVGElement::HEIGHT]; - if (width.IsPercentage()) { - float val = width.GetAnimValInSpecifiedUnits() / 100.0f; - if (val < 0.0f) val = 0.0f; - intrinsicSize.width.SetPercentValue(val); - } else { + if (!width.IsPercentage()) { nscoord val = nsPresContext::CSSPixelsToAppUnits(width.GetAnimValue(content)); if (val < 0) val = 0; intrinsicSize.width.SetCoordValue(val); } - if (height.IsPercentage()) { - float val = height.GetAnimValInSpecifiedUnits() / 100.0f; - if (val < 0.0f) val = 0.0f; - intrinsicSize.height.SetPercentValue(val); - } else { + if (!height.IsPercentage()) { nscoord val = nsPresContext::CSSPixelsToAppUnits(height.GetAnimValue(content)); if (val < 0) val = 0; intrinsicSize.height.SetCoordValue(val); @@ -318,16 +310,52 @@ nsSVGOuterSVGFrame::ComputeSize(nsRenderingContext *aRenderingContext, { nsSVGSVGElement* content = static_cast(mContent); - if ((content->HasValidViewbox() || content->ShouldSynthesizeViewBox()) && - (IsRootOfImage() || IsRootOfReplacedElementSubDoc())) { - // The embedding element has done the replaced element sizing, using our - // intrinsic dimensions as necessary. We just need to fill the viewport. - return aCBSize; + IntrinsicSize intrinsicSize = GetIntrinsicSize(); + + if (!mContent->GetParent()) { + if (IsRootOfImage() || IsRootOfReplacedElementSubDoc()) { + // The embedding element has done the replaced element sizing, + // using our intrinsic dimensions as necessary. We just need to + // fill the viewport. + return aCBSize; + } else { + // We're the root of a browsing context, so we need to honor + // widths and heights in percentages. (GetIntrinsicSize() doesn't + // report these since there's no such thing as a percentage + // intrinsic size.) + nsSVGLength2 &width = + content->mLengthAttributes[nsSVGSVGElement::WIDTH]; + if (width.IsPercentage()) { + NS_ABORT_IF_FALSE(intrinsicSize.width.GetUnit() == eStyleUnit_None, + "GetIntrinsicSize should have reported no " + "intrinsic width"); + float val = width.GetAnimValInSpecifiedUnits() / 100.0f; + if (val < 0.0f) val = 0.0f; + intrinsicSize.width.SetCoordValue(val * aCBSize.width); + } + + nsSVGLength2 &height = + content->mLengthAttributes[nsSVGSVGElement::HEIGHT]; + NS_ABORT_IF_FALSE(aCBSize.height != NS_AUTOHEIGHT, + "root should not have auto-height containing block"); + if (height.IsPercentage()) { + NS_ABORT_IF_FALSE(intrinsicSize.height.GetUnit() == eStyleUnit_None, + "GetIntrinsicSize should have reported no " + "intrinsic height"); + float val = height.GetAnimValInSpecifiedUnits() / 100.0f; + if (val < 0.0f) val = 0.0f; + intrinsicSize.height.SetCoordValue(val * aCBSize.height); + } + NS_ABORT_IF_FALSE(intrinsicSize.height.GetUnit() == eStyleUnit_Coord && + intrinsicSize.width.GetUnit() == eStyleUnit_Coord, + "We should have just handled the only situation where" + "we lack an intrinsic height or width."); + } } return nsLayoutUtils::ComputeSizeWithIntrinsicDimensions( aRenderingContext, this, - GetIntrinsicSize(), GetIntrinsicRatio(), aCBSize, + intrinsicSize, GetIntrinsicRatio(), aCBSize, aMargin, aBorder, aPadding); } diff --git a/parser/htmlparser/tests/reftest/bug577418-1.html b/parser/htmlparser/tests/reftest/bug577418-1.html index 70af4e54a7fa..cfd53be0a882 100644 --- a/parser/htmlparser/tests/reftest/bug577418-1.html +++ b/parser/htmlparser/tests/reftest/bug577418-1.html @@ -1,7 +1,7 @@ - +