2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
24 #include "SVGPolyElement.h"
26 #include "Attribute.h"
28 #include "FloatPoint.h"
29 #include "RenderSVGPath.h"
30 #include "RenderSVGResource.h"
31 #include "SVGElementInstance.h"
33 #include "SVGParserUtilities.h"
34 #include "SVGPointList.h"
38 // Define custom animated property 'points'.
39 const SVGPropertyInfo* SVGPolyElement::pointsPropertyInfo()
41 static const SVGPropertyInfo* s_propertyInfo = 0;
42 if (!s_propertyInfo) {
43 s_propertyInfo = new SVGPropertyInfo(AnimatedPoints,
45 SVGNames::pointsAttr.localName(),
46 &SVGPolyElement::synchronizePoints,
47 &SVGPolyElement::lookupOrCreatePointsWrapper);
49 return s_propertyInfo;
52 // Animated property definitions
53 DEFINE_ANIMATED_BOOLEAN(SVGPolyElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
55 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGPolyElement)
56 REGISTER_LOCAL_ANIMATED_PROPERTY(points)
57 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
58 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledTransformableElement)
59 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests)
60 END_REGISTER_ANIMATED_PROPERTIES
62 SVGPolyElement::SVGPolyElement(const QualifiedName& tagName, Document* document)
63 : SVGStyledTransformableElement(tagName, document)
65 registerAnimatedPropertiesForSVGPolyElement();
68 bool SVGPolyElement::isSupportedAttribute(const QualifiedName& attrName)
70 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
71 if (supportedAttributes.isEmpty()) {
72 SVGTests::addSupportedAttributes(supportedAttributes);
73 SVGLangSpace::addSupportedAttributes(supportedAttributes);
74 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
75 supportedAttributes.add(SVGNames::pointsAttr);
77 return supportedAttributes.contains(attrName);
80 void SVGPolyElement::parseMappedAttribute(Attribute* attr)
82 if (!isSupportedAttribute(attr->name())) {
83 SVGStyledTransformableElement::parseMappedAttribute(attr);
87 const AtomicString& value = attr->value();
88 if (attr->name() == SVGNames::pointsAttr) {
90 if (!pointsListFromSVGData(newList, value))
91 document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value + "\"");
93 if (SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGPolyElement, SVGAnimatedListPropertyTearOff<SVGPointList>, true>(this, pointsPropertyInfo()))
94 static_cast<SVGAnimatedListPropertyTearOff<SVGPointList>*>(wrapper)->detachListWrappers(newList.size());
96 m_points.value = newList;
100 if (SVGTests::parseMappedAttribute(attr))
102 if (SVGLangSpace::parseMappedAttribute(attr))
104 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
107 ASSERT_NOT_REACHED();
110 void SVGPolyElement::svgAttributeChanged(const QualifiedName& attrName)
112 if (!isSupportedAttribute(attrName)) {
113 SVGStyledTransformableElement::svgAttributeChanged(attrName);
117 SVGElementInstance::InvalidationGuard invalidationGuard(this);
119 if (SVGTests::handleAttributeChange(this, attrName))
122 RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer());
126 if (attrName == SVGNames::pointsAttr) {
127 renderer->setNeedsPathUpdate();
128 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
132 if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
133 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
137 ASSERT_NOT_REACHED();
140 void SVGPolyElement::synchronizePoints(void* contextElement)
142 ASSERT(contextElement);
143 SVGPolyElement* ownerType = static_cast<SVGPolyElement*>(contextElement);
144 if (!ownerType->m_points.shouldSynchronize)
146 SVGAnimatedPropertySynchronizer<true>::synchronize(ownerType, pointsPropertyInfo()->attributeName, ownerType->m_points.value.valueAsString());
149 PassRefPtr<SVGAnimatedProperty> SVGPolyElement::lookupOrCreatePointsWrapper(void* contextElement)
151 ASSERT(contextElement);
152 SVGPolyElement* ownerType = static_cast<SVGPolyElement*>(contextElement);
153 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGPolyElement, SVGAnimatedListPropertyTearOff<SVGPointList>, SVGPointList, true>
154 (ownerType, pointsPropertyInfo(), ownerType->m_points.value);
157 SVGListPropertyTearOff<SVGPointList>* SVGPolyElement::points()
159 m_points.shouldSynchronize = true;
160 return static_cast<SVGListPropertyTearOff<SVGPointList>*>(static_pointer_cast<SVGAnimatedListPropertyTearOff<SVGPointList> >(lookupOrCreatePointsWrapper(this))->baseVal());
163 SVGListPropertyTearOff<SVGPointList>* SVGPolyElement::animatedPoints()
165 m_points.shouldSynchronize = true;
166 return static_cast<SVGListPropertyTearOff<SVGPointList>*>(static_pointer_cast<SVGAnimatedListPropertyTearOff<SVGPointList> >(lookupOrCreatePointsWrapper(this))->animVal());
171 #endif // ENABLE(SVG)