Bug 407495 - Make SVG documents with percentage width/height respond to page zoom. r=roc.

--HG--
extra : rebase_source : c4c139693bb5d3b9086f7571dc3363c1c8b27ed5
This commit is contained in:
Jonathan Watt 2012-05-03 17:05:24 +01:00
Родитель d9928f2c53
Коммит ee7eeea5af
15 изменённых файлов: 73 добавлений и 71 удалений

Просмотреть файл

@ -1,6 +1,6 @@
<!DOCTYPE HTML>
<html>
<body style="background:white; margin:0;">
<div style="width:210px; height:150px; background:#010101;"></div>
<div style="width:280px; height:200px; background:#010101;"></div>
</body>
</html>

Просмотреть файл

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1" reftest-zoom="1.5">
version="1.1" reftest-zoom="2"
width="50%" height="50%">
<!-- use an empty g to force filters.svg to load before onload -->
<use xlink:href="../filters.svg#empty" />
<foreignObject x="0" y="0" height="100%" width="100%">

До

Ширина:  |  Высота:  |  Размер: 519 B

После

Ширина:  |  Высота:  |  Размер: 547 B

Просмотреть файл

@ -1,5 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 20 20">
<image width="10" height="10" xlink:href="blueRect10x10.png"/>
</svg>

До

Ширина:  |  Высота:  |  Размер: 186 B

Просмотреть файл

@ -1,8 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 20 20"
reftest-zoom="1.5">
<title>Testcase to ensure that full-page-zoom doesn't actually zoom raster
images, when we have a viewBox applied.</title>
<image width="10" height="10" xlink:href="blueRect10x10.png"/>
</svg>

До

Ширина:  |  Высота:  |  Размер: 344 B

Просмотреть файл

@ -1,8 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 20 20"
reftest-zoom="0.5">
<title>Testcase to ensure that full-page-zoom doesn't actually zoom raster
images, when we have a viewBox applied.</title>
<image width="10" height="10" xlink:href="blueRect10x10.png"/>
</svg>

До

Ширина:  |  Высота:  |  Размер: 344 B

Просмотреть файл

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
reftest-zoom="1.5">
reftest-zoom="1.5" width="10" height="10">
<title>Testcase to ensure that full-page-zoom will zoom raster
images the right amount.</title>
<image width="10" height="10" xlink:href="blueRect10x10.png"/>

До

Ширина:  |  Высота:  |  Размер: 292 B

После

Ширина:  |  Высота:  |  Размер: 315 B

Просмотреть файл

@ -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

Просмотреть файл

@ -2,7 +2,10 @@
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" reftest-zoom="5">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
reftest-zoom="5"
width="20%" height="20%">
<title>test image-rendering: -moz-crisp-edges</title>
<defs>
<filter id="i" x="0%" y="0%" width="100%" height="100%">

До

Ширина:  |  Высота:  |  Размер: 497 B

После

Ширина:  |  Высота:  |  Размер: 537 B

Просмотреть файл

@ -2,7 +2,10 @@
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" reftest-zoom="5">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
reftest-zoom="5"
width="20%" height="20%">
<title>test image-rendering: -moz-crisp-edges</title>
<defs>
<filter id="i" x="0%" y="0%" width="100%" height="100%">

До

Ширина:  |  Высота:  |  Размер: 503 B

После

Ширина:  |  Высота:  |  Размер: 543 B

Просмотреть файл

@ -3,7 +3,8 @@
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg"
onload="startTest()" reftest-zoom="1.5" class="reftest-wait">
onload="startTest()" reftest-zoom="2" class="reftest-wait"
style="width:50%; height:50%;">
<title>Testcase for zoomed foreignObject</title>

До

Ширина:  |  Высота:  |  Размер: 1.0 KiB

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Просмотреть файл

@ -3,7 +3,8 @@
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg"
reftest-zoom="1.5" class="reftest-wait">
reftest-zoom="2" class="reftest-wait"
width="50%" height="50%">
<title>Test invalidation of zoomed SVG</title>

До

Ширина:  |  Высота:  |  Размер: 740 B

После

Ширина:  |  Высота:  |  Размер: 768 B

Просмотреть файл

@ -2,7 +2,8 @@
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" reftest-zoom="2">
<svg xmlns="http://www.w3.org/2000/svg" reftest-zoom="2"
width="50%" height="50%">
<title>Test stroke-dasharray with text and zooming</title>
<g fill="none" stroke-width="1" stroke="black" stroke-dasharray="10">
<text font-size="50" x="50" y="50">|</text>

До

Ширина:  |  Высота:  |  Размер: 371 B

После

Ширина:  |  Высота:  |  Размер: 401 B

Просмотреть файл

@ -1,6 +1,6 @@
<!DOCTYPE HTML>
<html>
<body style="background:white; margin:0;">
<div style="width:210px; height:150px; background:#010101;"></div>
<div style="width:280px; height:200px; background:#010101;"></div>
</body>
</html>

Просмотреть файл

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1" reftest-zoom="1.5">
version="1.1" reftest-zoom="2"
width="50%" height="50%">>
<!-- use an empty g to force filters.svg to load before onload -->
<use xlink:href="../filters.svg#empty" />
<foreignObject x="0" y="0" height="100%" width="100%">

До

Ширина:  |  Высота:  |  Размер: 520 B

После

Ширина:  |  Высота:  |  Размер: 549 B

Просмотреть файл

@ -313,54 +313,68 @@ nsSVGOuterSVGFrame::ComputeSize(nsRenderingContext *aRenderingContext,
nsSize aMargin, nsSize aBorder, nsSize aPadding,
PRUint32 aFlags)
{
nsSVGSVGElement* content = static_cast<nsSVGSVGElement*>(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<nsSVGSVGElement*>(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);
}