Bug 687340 - Make dynamic changes to mask, clipPath and marker attributes work. r=roc

This commit is contained in:
Robert Longson 2011-09-19 13:59:52 +01:00
parent 848e923aa5
commit 31d473fc4f
11 changed files with 155 additions and 19 deletions

View File

@ -247,9 +247,7 @@ SVGAnimatedPreserveAspectRatio::SetBaseValueString(
}
#endif
// We don't need to call DidChange* here - we're only called by
// nsSVGElement::ParseAttribute under nsGenericElement::SetAttr,
// which takes care of notifying.
aSVGElement->DidChangePreserveAspectRatio(aDoSetAttr);
return NS_OK;
}

View File

@ -1213,14 +1213,6 @@ nsSVGSVGElement::GetLengthInfo()
NS_ARRAY_LENGTH(sLengthInfo));
}
void
nsSVGSVGElement::DidChangeEnum(PRUint8 aAttrEnum, PRBool aDoSetAttr)
{
nsSVGSVGElementBase::DidChangeEnum(aAttrEnum, aDoSetAttr);
InvalidateTransformNotifyFrame();
}
nsSVGElement::EnumAttributesInfo
nsSVGSVGElement::GetEnumInfo()
{

View File

@ -194,7 +194,6 @@ public:
// nsSVGElement specializations:
virtual gfxMatrix PrependLocalTransformTo(const gfxMatrix &aMatrix) const;
virtual void DidChangeLength(PRUint8 aAttrEnum, PRBool aDoSetAttr);
virtual void DidChangeEnum(PRUint8 aAttrEnum, PRBool aDoSetAttr);
virtual void DidChangeViewBox(PRBool aDoSetAttr);
virtual void DidChangePreserveAspectRatio(PRBool aDoSetAttr);

View File

@ -0,0 +1,37 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
class="reftest-wait"
onload="startTest()"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Testing that dynamic changes to the clipPathUnits are reflected in the clipPath</title>
<defs>
<clipPath id="clip1" clipPathUnits="objectBoundingBox">
<rect width=".1" height=".1"/>
</clipPath>
</defs>
<rect width="100%" height="100%" fill="lime"/>
<g transform="scale(1000)">
<rect x=".2" y=".2" width=".6" height=".6" fill="red" clip-path="url(#clip1)"/>
</g>
<script>
function startTest() {
document.addEventListener("MozReftestInvalidate", doTest, false);
// in case we're not gecko
setTimeout(doTest, 5000);
}
function doTest() {
var clip1 = document.getElementById("clip1");
clip1.setAttribute("clipPathUnits", "userSpaceOnUse");
document.documentElement.removeAttribute("class");
}
</script>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -6,9 +6,9 @@
<title>Testing that dynamic changes to the element for a given ID are reflected in marker</title>
<!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=309220 -->
<defs>
<marker id="x" style="overflow: visible;" orient="auto" markerUnits="strokeWidth">
<rect width="100%" height="100%" fill="lime"/>
</marker>
<marker id="x" style="overflow: visible;" orient="auto" markerUnits="strokeWidth">
<rect width="100%" height="100%" fill="lime"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="red"/>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="Windows-1252"?>
<!--
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"
onload="startTest()">
<title>Testing that dynamic changes to preserveAspectRatio are reflected in the marker</title>
<script>
<![CDATA[
function startTest() {
document.addEventListener("MozReftestInvalidate", doTest, false);
// in case we're not gecko
setTimeout(doTest, 5000);
}
function doTest() {
m = document.getElementById("m1");
m.preserveAspectRatio.baseVal.align =
SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE;
document.documentElement.removeAttribute("class");
}
]]>
</script>
<defs>
<marker id="m1" orient="auto" markerUnits="userSpaceOnUse"
preserveAspectRatio="xMidYMid slice" viewBox="0 0 30 40" markerWidth="60" markerHeight="30">
<rect width="30" height="40" fill="red"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="lime"/>
<line x1="30" x2="30" y1="10" y2="10" stroke="red" stroke-width="3" marker-end="url(#m1)"/>
<rect x="30" y="10" width="60" height="30" fill="lime"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="Windows-1252"?>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
class="reftest-wait"
onload="startTest()"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Testing that dynamic changes to mask attributes are reflected in the mask</title>
<defs>
<mask id="mask1" width="1" height="1">
<rect width="1" height="1" fill="white"/>
</mask>
</defs>
<rect width="100%" height="100%" fill="lime"/>
<g transform="scale(500)">
<rect x=".2" y=".2" width=".2" height=".2" fill="red" mask="url(#mask1)"/>
</g>
<script>
function startTest() {
document.addEventListener("MozReftestInvalidate", doTest, false);
// in case we're not gecko
setTimeout(doTest, 5000);
}
function doTest() {
var mask1 = document.getElementById("mask1");
mask1.maskUnits.baseVal = SVGUnitTypes.SVG_UNIT_TYPE_USERSPACEONUSE;
document.documentElement.removeAttribute("class");
}
</script>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -62,6 +62,7 @@ fails-if(Android) == dynamic-conditions-01.svg pass.svg # bug 652050
== dynamic-conditions-12.svg pass.svg
== dynamic-conditions-13.svg about:blank
== dynamic-clipPath-01.svg pass.svg
== dynamic-clipPath-02.svg pass.svg
== dynamic-feFlood-01.svg pass.svg
== dynamic-feImage-01.svg pass.svg
== dynamic-filter-contents-01a.svg dynamic-filter-contents-01-ref.svg
@ -72,6 +73,8 @@ fails-if(Android) == dynamic-conditions-01.svg pass.svg # bug 652050
== dynamic-link-style-01.svg pass.svg
== dynamic-marker-01.svg pass.svg
== dynamic-marker-02.svg dynamic-marker-02-ref.svg
== dynamic-marker-03.svg pass.svg
== dynamic-mask-01.svg pass.svg
== dynamic-mask-contents-01.svg pass.svg
== dynamic-pattern-01.svg pass.svg
== dynamic-pattern-02.svg pass.svg

View File

@ -280,10 +280,14 @@ nsSVGClipPathFrame::AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
if (aNameSpaceID == kNameSpaceID_None &&
aAttribute == nsGkAtoms::transform) {
nsSVGUtils::NotifyChildrenOfSVGChange(this,
nsISVGChildFrame::TRANSFORM_CHANGED);
if (aNameSpaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::transform) {
nsSVGUtils::NotifyChildrenOfSVGChange(this,
nsISVGChildFrame::TRANSFORM_CHANGED);
}
if (aAttribute == nsGkAtoms::clipPathUnits) {
nsSVGEffects::InvalidateRenderingObservers(this);
}
}
return nsSVGClipPathFrameBase::AttributeChanged(aNameSpaceID,

View File

@ -38,6 +38,7 @@
#include "nsSVGMaskFrame.h"
#include "nsSVGContainerFrame.h"
#include "nsSVGMaskElement.h"
#include "nsSVGEffects.h"
#include "nsIDOMSVGMatrix.h"
#include "gfxContext.h"
#include "gfxImageSurface.h"
@ -157,6 +158,25 @@ nsSVGMaskFrame::ComputeMaskAlpha(nsSVGRenderState *aContext,
return retval;
}
NS_IMETHODIMP
nsSVGMaskFrame::AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
if (aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::x ||
aAttribute == nsGkAtoms::y ||
aAttribute == nsGkAtoms::width ||
aAttribute == nsGkAtoms::height||
aAttribute == nsGkAtoms::maskUnits ||
aAttribute == nsGkAtoms::maskContentUnits)) {
nsSVGEffects::InvalidateRenderingObservers(this);
}
return nsSVGMaskFrameBase::AttributeChanged(aNameSpaceID,
aAttribute, aModType);
}
#ifdef DEBUG
NS_IMETHODIMP
nsSVGMaskFrame::Init(nsIContent* aContent,

View File

@ -64,6 +64,10 @@ public:
const gfxMatrix &aMatrix,
float aOpacity = 1.0f);
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType);
#ifdef DEBUG
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,