Bug 1269174: Fix nsSVGViewBox::HasRect() to return false instead of using stale mBaseVal. r=longsonr

MozReview-Commit-ID: esNxaomT3D
This commit is contained in:
Daniel Holbert 2016-05-03 07:40:26 -07:00
parent 359203771f
commit 0892fa8f5a
6 changed files with 93 additions and 5 deletions

View File

@ -70,6 +70,23 @@ nsSVGViewBox::Init()
mAnimVal = nullptr;
}
bool
nsSVGViewBox::HasRect() const
{
// Check mAnimVal if we have one; otherwise, check mBaseVal if we have one;
// otherwise, just return false (we clearly do not have a rect).
const nsSVGViewBoxRect* rect = mAnimVal;
if (!rect) {
if (!mHasBaseVal) {
// no anim val, no base val --> no viewbox rect
return false;
}
rect = &mBaseVal;
}
return !rect->none && rect->width >= 0 && rect->height >= 0;
}
void
nsSVGViewBox::SetAnimValue(const nsSVGViewBoxRect& aRect,
nsSVGElement *aSVGElement)

View File

@ -52,11 +52,7 @@ public:
* string, or if any of the four rect values were too big to store in a
* float, or the width/height are negative.
*/
bool HasRect() const
{
const nsSVGViewBoxRect& rect = GetAnimValue();
return !rect.none && rect.width >= 0 && rect.height >= 0;
}
bool HasRect() const;
/**
* Returns true if the corresponding "viewBox" attribute either defined a

View File

@ -0,0 +1,24 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" class="reftest-wait"
id="target" viewBox="-50 -50 20 20"
preserveAspectRatio="none">
<script>
function doTest() {
var target = document.getElementById("target");
target.removeAttribute("viewBox");
document.documentElement.removeAttribute("class");
}
document.addEventListener("MozReftestInvalidate", doTest, false);
</script>
<!-- Lime background to match pass.svg -->
<rect height="100%" width="100%" fill="lime"/>
<!-- Offscreen red rect - the initial |viewBox| makes this visible,
but it shouldn't be visible after we remove that attribute: -->
<rect x="-50" y="-50" width="20" height="20" fill="red"/>
</svg>

After

Width:  |  Height:  |  Size: 821 B

View File

@ -0,0 +1,24 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" class="reftest-wait"
id="target" viewBox="-50 -50 20 20"
preserveAspectRatio="none">
<script>
function doTest() {
var target = document.getElementById("target");
target.setAttribute("viewBox", "");
document.documentElement.removeAttribute("class");
}
document.addEventListener("MozReftestInvalidate", doTest, false);
</script>
<!-- Lime background to match pass.svg -->
<rect height="100%" width="100%" fill="lime"/>
<!-- Offscreen red rect - the initial |viewBox| makes this visible,
but it shouldn't be visible after we clear that attribute: -->
<rect x="-50" y="-50" width="20" height="20" fill="red"/>
</svg>

After

Width:  |  Height:  |  Size: 821 B

View File

@ -0,0 +1,24 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" class="reftest-wait"
id="target" viewBox="-50 -50 20 20"
preserveAspectRatio="none">
<script>
function doTest() {
var target = document.getElementById("target");
target.setAttribute("viewBox", "bogus value");
document.documentElement.removeAttribute("class");
}
document.addEventListener("MozReftestInvalidate", doTest, false);
</script>
<!-- Lime background to match pass.svg -->
<rect height="100%" width="100%" fill="lime"/>
<!-- Offscreen red rect - the initial |viewBox| makes this visible,
but it shouldn't be visible after we tweak that attribute: -->
<rect x="-50" y="-50" width="20" height="20" fill="red"/>
</svg>

After

Width:  |  Height:  |  Size: 832 B

View File

@ -135,6 +135,9 @@ random-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) fuzzy-if(/^Windows\x20NT\x2
random == dynamic-use-nested-01a.svg dynamic-use-nested-01-ref.svg
random == dynamic-use-nested-01b.svg dynamic-use-nested-01-ref.svg
== dynamic-use-remove-width.svg dynamic-use-remove-width-ref.svg
== dynamic-viewBox-change-01.svg pass.svg
== dynamic-viewBox-change-02.svg pass.svg
== dynamic-viewBox-change-03.svg pass.svg
== fragmentIdentifier-01.xhtml pass.svg
== linked-filter-01.svg pass.svg
== linked-pattern-01.svg pass.svg