Bug 1717877 - Handle degenerate ratio and negative size attributes for intrinsic size calculation of SVG outer frames. r=emilio

Based on https://github.com/w3c/csswg-drafts/issues/6286, we fall back to the
viewport rect if
1. width/height is a degenerate ratio, or
2. width or height is a negative number.

Differential Revision: https://phabricator.services.mozilla.com/D118666
This commit is contained in:
Boris Chiou 2021-06-24 20:27:31 +00:00
Родитель 7c9cce86f8
Коммит 519e7347ed
4 изменённых файлов: 47 добавлений и 4 удалений

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

@ -253,7 +253,7 @@ AspectRatio SVGOuterSVGFrame::GetIntrinsicRatio() const {
// We only have an intrinsic size/ratio if our width and height attributes
// are both specified and set to non-percentage values, or we have a viewBox
// rect: http://www.w3.org/TR/SVGMobile12/coords.html#IntrinsicSizing
// rect: https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS
// Unfortunately we have to return the ratio as two nscoords whereas what
// we have are two floats. Using app units allows for some floating point
// values to work but really small or large numbers will fail.
@ -263,10 +263,17 @@ AspectRatio SVGOuterSVGFrame::GetIntrinsicRatio() const {
content->mLengthAttributes[SVGSVGElement::ATTR_WIDTH];
const SVGAnimatedLength& height =
content->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
if (!width.IsPercentage() && !height.IsPercentage()) {
return AspectRatio::FromSize(width.GetAnimValue(content),
height.GetAnimValue(content));
// Use width/height ratio only if
// 1. it's not a degenerate ratio, and
// 2. width and height are non-negative numbers.
// Otherwise, we use the viewbox rect.
// https://github.com/w3c/csswg-drafts/issues/6286
const float w = width.GetAnimValue(content);
const float h = height.GetAnimValue(content);
if (w > 0.0f && h > 0.0f) {
return AspectRatio::FromSize(w, h);
}
}
SVGViewElement* viewElement = content->GetCurrentViewElement();

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

@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>Outer SVG intrinsic size with degenerate ratio</title>
<link rel="author" title="Mozilla" href="https://www.mozilla.org/">
<link rel="help" href="https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#degenerate-ratio">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/6286">
<link rel="match" href="../../css/reference/ref-filled-green-100px-square.xht">
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<img style="width: 100px; background: green;"
src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='0' height='50px' viewBox='0 0 1 1'></svg>">

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

@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>Outer SVG intrinsic size with an negative size attribute</title>
<link rel="author" title="Mozilla" href="https://www.mozilla.org/">
<link rel="help" href="https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#degenerate-ratio">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/6286">
<link rel="match" href="../../css/reference/ref-filled-green-100px-square.xht">
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<img style="width: 100px; background: green;"
src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='-1px' height='50px' viewBox='0 0 1 1'></svg>">

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

@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>Outer SVG intrinsic size with negative size attributes</title>
<link rel="author" title="Mozilla" href="https://www.mozilla.org/">
<link rel="help" href="https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#degenerate-ratio">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/6286">
<link rel="match" href="../../css/reference/ref-filled-green-100px-square.xht">
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<img style="width: 100px; background: green;"
src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='-1px' height='-50px' viewBox='0 0 1 1'></svg>">