1 /*
2 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 2009 Dirk Schulze <krit@webkit.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20 */
21
22 #include "config.h"
23
24 #if ENABLE(SVG) && ENABLE(FILTERS)
25 #include "SVGFilterPrimitiveStandardAttributes.h"
26
27 #include "FilterEffect.h"
28 #include "MappedAttribute.h"
29 #include "SVGLength.h"
30 #include "SVGNames.h"
31 #include "SVGStyledElement.h"
32 #include "SVGUnitTypes.h"
33
34 namespace WebCore {
35
SVGFilterPrimitiveStandardAttributes(const QualifiedName & tagName,Document * doc)36 SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document* doc)
37 : SVGStyledElement(tagName, doc)
38 , m_x(LengthModeWidth, "0%")
39 , m_y(LengthModeHeight, "0%")
40 , m_width(LengthModeWidth, "100%")
41 , m_height(LengthModeHeight, "100%")
42 {
43 // Spec: If the x/y attribute is not specified, the effect is as if a value of "0%" were specified.
44 // Spec: If the width/height attribute is not specified, the effect is as if a value of "100%" were specified.
45 }
46
~SVGFilterPrimitiveStandardAttributes()47 SVGFilterPrimitiveStandardAttributes::~SVGFilterPrimitiveStandardAttributes()
48 {
49 }
50
parseMappedAttribute(MappedAttribute * attr)51 void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(MappedAttribute* attr)
52 {
53 const AtomicString& value = attr->value();
54 if (attr->name() == SVGNames::xAttr)
55 setXBaseValue(SVGLength(LengthModeWidth, value));
56 else if (attr->name() == SVGNames::yAttr)
57 setYBaseValue(SVGLength(LengthModeHeight, value));
58 else if (attr->name() == SVGNames::widthAttr)
59 setWidthBaseValue(SVGLength(LengthModeWidth, value));
60 else if (attr->name() == SVGNames::heightAttr)
61 setHeightBaseValue(SVGLength(LengthModeHeight, value));
62 else if (attr->name() == SVGNames::resultAttr)
63 setResultBaseValue(value);
64 else
65 return SVGStyledElement::parseMappedAttribute(attr);
66 }
67
synchronizeProperty(const QualifiedName & attrName)68 void SVGFilterPrimitiveStandardAttributes::synchronizeProperty(const QualifiedName& attrName)
69 {
70 SVGStyledElement::synchronizeProperty(attrName);
71
72 if (attrName == anyQName()) {
73 synchronizeX();
74 synchronizeY();
75 synchronizeWidth();
76 synchronizeHeight();
77 synchronizeResult();
78 return;
79 }
80
81 if (attrName == SVGNames::xAttr)
82 synchronizeX();
83 else if (attrName == SVGNames::yAttr)
84 synchronizeY();
85 else if (attrName == SVGNames::widthAttr)
86 synchronizeWidth();
87 else if (attrName == SVGNames::heightAttr)
88 synchronizeHeight();
89 else if (attrName == SVGNames::resultAttr)
90 synchronizeResult();
91 }
92
setStandardAttributes(SVGResourceFilter * resourceFilter,FilterEffect * filterEffect) const93 void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(SVGResourceFilter* resourceFilter, FilterEffect* filterEffect) const
94 {
95 ASSERT(filterEffect);
96 if (!filterEffect)
97 return;
98
99 ASSERT(resourceFilter);
100
101 if (this->hasAttribute(SVGNames::xAttr))
102 filterEffect->setHasX(true);
103 if (this->hasAttribute(SVGNames::yAttr))
104 filterEffect->setHasY(true);
105 if (this->hasAttribute(SVGNames::widthAttr))
106 filterEffect->setHasWidth(true);
107 if (this->hasAttribute(SVGNames::heightAttr))
108 filterEffect->setHasHeight(true);
109
110 FloatRect effectBBox;
111 if (resourceFilter->effectBoundingBoxMode())
112 effectBBox = FloatRect(x().valueAsPercentage(),
113 y().valueAsPercentage(),
114 width().valueAsPercentage(),
115 height().valueAsPercentage());
116 else
117 effectBBox = FloatRect(x().value(this),
118 y().value(this),
119 width().value(this),
120 height().value(this));
121
122 filterEffect->setEffectBoundaries(effectBBox);
123 }
124
125 }
126
127 #endif // ENABLE(SVG)
128