2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
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.
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.
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.
24 #if ENABLE(SVG) && ENABLE(FILTERS)
25 #include "SVGFilterPrimitiveStandardAttributes.h"
27 #include "Attribute.h"
28 #include "FilterEffect.h"
29 #include "RenderSVGResourceFilterPrimitive.h"
30 #include "SVGElementInstance.h"
31 #include "SVGFilterBuilder.h"
32 #include "SVGLength.h"
34 #include "SVGStyledElement.h"
35 #include "SVGUnitTypes.h"
39 // Animated property definitions
40 DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::xAttr, X, x)
41 DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::yAttr, Y, y)
42 DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::widthAttr, Width, width)
43 DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::heightAttr, Height, height)
44 DEFINE_ANIMATED_STRING(SVGFilterPrimitiveStandardAttributes, SVGNames::resultAttr, Result, result)
46 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
47 REGISTER_LOCAL_ANIMATED_PROPERTY(x)
48 REGISTER_LOCAL_ANIMATED_PROPERTY(y)
49 REGISTER_LOCAL_ANIMATED_PROPERTY(width)
50 REGISTER_LOCAL_ANIMATED_PROPERTY(height)
51 REGISTER_LOCAL_ANIMATED_PROPERTY(result)
52 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledElement)
53 END_REGISTER_ANIMATED_PROPERTIES
55 SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document* document)
56 : SVGStyledElement(tagName, document)
57 , m_x(LengthModeWidth, "0%")
58 , m_y(LengthModeHeight, "0%")
59 , m_width(LengthModeWidth, "100%")
60 , m_height(LengthModeHeight, "100%")
62 // Spec: If the x/y attribute is not specified, the effect is as if a value of "0%" were specified.
63 // Spec: If the width/height attribute is not specified, the effect is as if a value of "100%" were specified.
64 registerAnimatedPropertiesForSVGFilterPrimitiveStandardAttributes();
67 bool SVGFilterPrimitiveStandardAttributes::isSupportedAttribute(const QualifiedName& attrName)
69 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
70 if (supportedAttributes.isEmpty()) {
71 supportedAttributes.add(SVGNames::xAttr);
72 supportedAttributes.add(SVGNames::yAttr);
73 supportedAttributes.add(SVGNames::widthAttr);
74 supportedAttributes.add(SVGNames::heightAttr);
75 supportedAttributes.add(SVGNames::resultAttr);
77 return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
80 void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(Attribute* attr)
82 SVGParsingError parseError = NoError;
83 const AtomicString& value = attr->value();
85 if (!isSupportedAttribute(attr->name()))
86 SVGStyledElement::parseMappedAttribute(attr);
87 else if (attr->name() == SVGNames::xAttr)
88 setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
89 else if (attr->name() == SVGNames::yAttr)
90 setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
91 else if (attr->name() == SVGNames::widthAttr)
92 setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
93 else if (attr->name() == SVGNames::heightAttr)
94 setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
95 else if (attr->name() == SVGNames::resultAttr)
96 setResultBaseValue(value);
100 reportAttributeParsingError(parseError, attr);
103 bool SVGFilterPrimitiveStandardAttributes::setFilterEffectAttribute(FilterEffect*, const QualifiedName&)
105 // When all filters support this method, it will be changed to a pure virtual method.
106 ASSERT_NOT_REACHED();
110 void SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(const QualifiedName& attrName)
112 if (!isSupportedAttribute(attrName)) {
113 SVGStyledElement::svgAttributeChanged(attrName);
117 SVGElementInstance::InvalidationGuard invalidationGuard(this);
121 void SVGFilterPrimitiveStandardAttributes::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
123 SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
125 if (!changedByParser)
129 void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(FilterEffect* filterEffect) const
131 ASSERT(filterEffect);
135 if (hasAttribute(SVGNames::xAttr))
136 filterEffect->setHasX(true);
137 if (hasAttribute(SVGNames::yAttr))
138 filterEffect->setHasY(true);
139 if (hasAttribute(SVGNames::widthAttr))
140 filterEffect->setHasWidth(true);
141 if (hasAttribute(SVGNames::heightAttr))
142 filterEffect->setHasHeight(true);
145 RenderObject* SVGFilterPrimitiveStandardAttributes::createRenderer(RenderArena* arena, RenderStyle*)
147 return new (arena) RenderSVGResourceFilterPrimitive(this);
150 bool SVGFilterPrimitiveStandardAttributes::rendererIsNeeded(const NodeRenderingContext& context)
152 if (parentNode() && (parentNode()->hasTagName(SVGNames::filterTag)))
153 return SVGStyledElement::rendererIsNeeded(context);
158 void invalidateFilterPrimitiveParent(SVGElement* element)
163 ContainerNode* parent = element->parentNode();
168 RenderObject* renderer = parent->renderer();
169 if (!renderer || !renderer->isSVGResourceFilterPrimitive())
172 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer, false);
177 #endif // ENABLE(SVG)