From ee7eeea5afa25096dff4403887a5def25e24d0c5 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Thu, 3 May 2012 17:05:24 +0100 Subject: [PATCH] Bug 407495 - Make SVG documents with percentage width/height respond to page zoom. r=roc. --HG-- extra : rebase_source : c4c139693bb5d3b9086f7571dc3363c1c8b27ed5 --- layout/reftests/ogg-video/zoomed-1-ref.html | 2 +- layout/reftests/ogg-video/zoomed-1.xhtml | 3 +- .../reftests/svg/image/image-zoom-01-ref.svg | 5 -- layout/reftests/svg/image/image-zoom-01a.svg | 8 -- layout/reftests/svg/image/image-zoom-01b.svg | 8 -- layout/reftests/svg/image/image-zoom-02.svg | 2 +- layout/reftests/svg/image/reftest.list | 2 - .../svg/moz-only/feImage-zoom-01a.svg | 5 +- .../svg/moz-only/feImage-zoom-01b.svg | 5 +- .../svg/moz-only/foreignObject-zoom-01.svg | 3 +- .../svg/moz-only/zoom-invalidation-01.svg | 3 +- .../svg/stroke-dasharray-and-text-01.svg | 3 +- layout/reftests/webm-video/zoomed-1-ref.html | 2 +- layout/reftests/webm-video/zoomed-1.xhtml | 3 +- layout/svg/base/src/nsSVGOuterSVGFrame.cpp | 90 +++++++++++-------- 15 files changed, 73 insertions(+), 71 deletions(-) delete mode 100644 layout/reftests/svg/image/image-zoom-01-ref.svg delete mode 100644 layout/reftests/svg/image/image-zoom-01a.svg delete mode 100644 layout/reftests/svg/image/image-zoom-01b.svg diff --git a/layout/reftests/ogg-video/zoomed-1-ref.html b/layout/reftests/ogg-video/zoomed-1-ref.html index 12236f829701..01929db7e769 100644 --- a/layout/reftests/ogg-video/zoomed-1-ref.html +++ b/layout/reftests/ogg-video/zoomed-1-ref.html @@ -1,6 +1,6 @@ -
+
diff --git a/layout/reftests/ogg-video/zoomed-1.xhtml b/layout/reftests/ogg-video/zoomed-1.xhtml index b6da6ddb293c..e68e1290f419 100644 --- a/layout/reftests/ogg-video/zoomed-1.xhtml +++ b/layout/reftests/ogg-video/zoomed-1.xhtml @@ -1,7 +1,8 @@ + version="1.1" reftest-zoom="2" + width="50%" height="50%"> diff --git a/layout/reftests/svg/image/image-zoom-01-ref.svg b/layout/reftests/svg/image/image-zoom-01-ref.svg deleted file mode 100644 index 49451529c02d..000000000000 --- a/layout/reftests/svg/image/image-zoom-01-ref.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/layout/reftests/svg/image/image-zoom-01a.svg b/layout/reftests/svg/image/image-zoom-01a.svg deleted file mode 100644 index b77712a138e8..000000000000 --- a/layout/reftests/svg/image/image-zoom-01a.svg +++ /dev/null @@ -1,8 +0,0 @@ - - Testcase to ensure that full-page-zoom doesn't actually zoom raster - images, when we have a viewBox applied. - - diff --git a/layout/reftests/svg/image/image-zoom-01b.svg b/layout/reftests/svg/image/image-zoom-01b.svg deleted file mode 100644 index 7aff01d2bb43..000000000000 --- a/layout/reftests/svg/image/image-zoom-01b.svg +++ /dev/null @@ -1,8 +0,0 @@ - - Testcase to ensure that full-page-zoom doesn't actually zoom raster - images, when we have a viewBox applied. - - diff --git a/layout/reftests/svg/image/image-zoom-02.svg b/layout/reftests/svg/image/image-zoom-02.svg index 6caf046558f3..f426dfca2adf 100644 --- a/layout/reftests/svg/image/image-zoom-02.svg +++ b/layout/reftests/svg/image/image-zoom-02.svg @@ -1,6 +1,6 @@ + reftest-zoom="1.5" width="10" height="10"> Testcase to ensure that full-page-zoom will zoom raster images the right amount. diff --git a/layout/reftests/svg/image/reftest.list b/layout/reftests/svg/image/reftest.list index 2c6b706a4b79..f0342f8d91c9 100644 --- a/layout/reftests/svg/image/reftest.list +++ b/layout/reftests/svg/image/reftest.list @@ -15,8 +15,6 @@ == image-x-01.svg image-x-01-ref.svg == image-xy-01.svg image-xy-01-ref.svg == image-y-01.svg image-y-01-ref.svg -== image-zoom-01a.svg image-zoom-01-ref.svg -== image-zoom-01b.svg image-zoom-01-ref.svg == image-zoom-02.svg image-zoom-02-ref.svg == imported-image-01.svg imported-image-ref.svg == imported-image-02.svg imported-image-ref.svg diff --git a/layout/reftests/svg/moz-only/feImage-zoom-01a.svg b/layout/reftests/svg/moz-only/feImage-zoom-01a.svg index 3b63c5bdc018..3b2ea655ff56 100644 --- a/layout/reftests/svg/moz-only/feImage-zoom-01a.svg +++ b/layout/reftests/svg/moz-only/feImage-zoom-01a.svg @@ -2,7 +2,10 @@ Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ --> - + test image-rendering: -moz-crisp-edges diff --git a/layout/reftests/svg/moz-only/feImage-zoom-01b.svg b/layout/reftests/svg/moz-only/feImage-zoom-01b.svg index af1871d6d267..c8be9ea6b578 100644 --- a/layout/reftests/svg/moz-only/feImage-zoom-01b.svg +++ b/layout/reftests/svg/moz-only/feImage-zoom-01b.svg @@ -2,7 +2,10 @@ Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ --> - + test image-rendering: -moz-crisp-edges diff --git a/layout/reftests/svg/moz-only/foreignObject-zoom-01.svg b/layout/reftests/svg/moz-only/foreignObject-zoom-01.svg index 20c4f199950d..42250464a988 100644 --- a/layout/reftests/svg/moz-only/foreignObject-zoom-01.svg +++ b/layout/reftests/svg/moz-only/foreignObject-zoom-01.svg @@ -3,7 +3,8 @@ http://creativecommons.org/publicdomain/zero/1.0/ --> + onload="startTest()" reftest-zoom="2" class="reftest-wait" + style="width:50%; height:50%;"> Testcase for zoomed foreignObject diff --git a/layout/reftests/svg/moz-only/zoom-invalidation-01.svg b/layout/reftests/svg/moz-only/zoom-invalidation-01.svg index 42fad444d38c..e8270968b101 100644 --- a/layout/reftests/svg/moz-only/zoom-invalidation-01.svg +++ b/layout/reftests/svg/moz-only/zoom-invalidation-01.svg @@ -3,7 +3,8 @@ http://creativecommons.org/publicdomain/zero/1.0/ --> + reftest-zoom="2" class="reftest-wait" + width="50%" height="50%"> Test invalidation of zoomed SVG diff --git a/layout/reftests/svg/stroke-dasharray-and-text-01.svg b/layout/reftests/svg/stroke-dasharray-and-text-01.svg index eb6a3bfeef8b..b890d397f60e 100644 --- a/layout/reftests/svg/stroke-dasharray-and-text-01.svg +++ b/layout/reftests/svg/stroke-dasharray-and-text-01.svg @@ -2,7 +2,8 @@ Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ --> - + Test stroke-dasharray with text and zooming | diff --git a/layout/reftests/webm-video/zoomed-1-ref.html b/layout/reftests/webm-video/zoomed-1-ref.html index 12236f829701..01929db7e769 100644 --- a/layout/reftests/webm-video/zoomed-1-ref.html +++ b/layout/reftests/webm-video/zoomed-1-ref.html @@ -1,6 +1,6 @@ -
+
diff --git a/layout/reftests/webm-video/zoomed-1.xhtml b/layout/reftests/webm-video/zoomed-1.xhtml index 5a09706b9474..fde4a1aaed1f 100644 --- a/layout/reftests/webm-video/zoomed-1.xhtml +++ b/layout/reftests/webm-video/zoomed-1.xhtml @@ -1,7 +1,8 @@ + version="1.1" reftest-zoom="2" + width="50%" height="50%">> diff --git a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp index 37f7164506cb..51e5c620ca8f 100644 --- a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp +++ b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp @@ -313,54 +313,68 @@ nsSVGOuterSVGFrame::ComputeSize(nsRenderingContext *aRenderingContext, nsSize aMargin, nsSize aBorder, nsSize aPadding, PRUint32 aFlags) { - nsSVGSVGElement* content = static_cast(mContent); + if (IsRootOfImage() || IsRootOfReplacedElementSubDoc()) { + // The embedding element has sized itself using the CSS replaced element + // sizing rules, using our intrinsic dimensions as necessary. The SVG spec + // says that the width and height of embedded SVG is overridden by the + // width and height of the embedding element, so we just need to size to + // the viewport that the embedding element has established for us. + return aCBSize; + } + nsSize cbSize = 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); - } + // We're the root of the outermost browsing context, so we need to scale + // cbSize by the full-zoom so that SVGs with percentage width/height zoom: - nsSVGLength2 &height = - content->mLengthAttributes[nsSVGSVGElement::HEIGHT]; - NS_ASSERTION(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."); + NS_ASSERTION(aCBSize.width != NS_AUTOHEIGHT && + aCBSize.height != NS_AUTOHEIGHT, + "root should not have auto-width/height containing block"); + cbSize.width *= PresContext()->GetFullZoom(); + cbSize.height *= PresContext()->GetFullZoom(); + + // We also need to honour the width and height attributes' default values + // of 100% when we're the root of a browsing context. (GetIntrinsicSize() + // doesn't report these since there's no such thing as a percentage + // intrinsic size. Also note that explicit percentage values are mapped + // into style, so the following isn't for them.) + + nsSVGSVGElement* content = static_cast(mContent); + + 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 * cbSize.width); } + + nsSVGLength2 &height = + content->mLengthAttributes[nsSVGSVGElement::HEIGHT]; + NS_ASSERTION(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 * cbSize.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, - intrinsicSize, GetIntrinsicRatio(), aCBSize, + intrinsicSize, GetIntrinsicRatio(), cbSize, aMargin, aBorder, aPadding); }