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::parseAttribute(const QualifiedName& name, const AtomicString& value)
82
SVGParsingError parseError = NoError;
84
if (!isSupportedAttribute(name))
85
SVGStyledElement::parseAttribute(name, value);
86
else if (name == SVGNames::xAttr)
87
setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
88
else if (name == SVGNames::yAttr)
89
setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
90
else if (name == SVGNames::widthAttr)
91
setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
92
else if (name == SVGNames::heightAttr)
93
setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
94
else if (name == SVGNames::resultAttr)
95
setResultBaseValue(value);
99
reportAttributeParsingError(parseError, name, value);
102
bool SVGFilterPrimitiveStandardAttributes::setFilterEffectAttribute(FilterEffect*, const QualifiedName&)
104
// When all filters support this method, it will be changed to a pure virtual method.
105
ASSERT_NOT_REACHED();
109
void SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(const QualifiedName& attrName)
111
if (!isSupportedAttribute(attrName)) {
112
SVGStyledElement::svgAttributeChanged(attrName);
116
SVGElementInstance::InvalidationGuard invalidationGuard(this);
120
void SVGFilterPrimitiveStandardAttributes::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
122
SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
124
if (!changedByParser)
128
void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(FilterEffect* filterEffect) const
130
ASSERT(filterEffect);
134
if (hasAttribute(SVGNames::xAttr))
135
filterEffect->setHasX(true);
136
if (hasAttribute(SVGNames::yAttr))
137
filterEffect->setHasY(true);
138
if (hasAttribute(SVGNames::widthAttr))
139
filterEffect->setHasWidth(true);
140
if (hasAttribute(SVGNames::heightAttr))
141
filterEffect->setHasHeight(true);
144
RenderObject* SVGFilterPrimitiveStandardAttributes::createRenderer(RenderArena* arena, RenderStyle*)
146
return new (arena) RenderSVGResourceFilterPrimitive(this);
149
bool SVGFilterPrimitiveStandardAttributes::rendererIsNeeded(const NodeRenderingContext& context)
151
if (parentNode() && (parentNode()->hasTagName(SVGNames::filterTag)))
152
return SVGStyledElement::rendererIsNeeded(context);
157
void invalidateFilterPrimitiveParent(SVGElement* element)
162
ContainerNode* parent = element->parentNode();
167
RenderObject* renderer = parent->renderer();
168
if (!renderer || !renderer->isSVGResourceFilterPrimitive())
171
RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer, false);
176
#endif // ENABLE(SVG)