1 /* 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) kde.org> 4 * 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. 9 * 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. 14 * 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. 19 */ 20 21 #include "config.h" 22 23 #if ENABLE(SVG) 24 #include "SVGPolyElement.h" 25 26 #include "Attribute.h" 27 #include "Document.h" 28 #include "FloatPoint.h" 29 #include "RenderSVGPath.h" 30 #include "RenderSVGResource.h" 31 #include "SVGNames.h" 32 #include "SVGParserUtilities.h" 33 #include "SVGPointList.h" 34 35 namespace WebCore { 36 37 // Animated property definitions 38 DEFINE_ANIMATED_BOOLEAN(SVGPolyElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 39 40 SVGPolyElement::SVGPolyElement(const QualifiedName& tagName, Document* document) 41 : SVGStyledTransformableElement(tagName, document) 42 { 43 } 44 45 void SVGPolyElement::parseMappedAttribute(Attribute* attr) 46 { 47 const AtomicString& value = attr->value(); 48 if (attr->name() == SVGNames::pointsAttr) { 49 SVGPointList newList; 50 if (!pointsListFromSVGData(newList, value)) 51 document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value + "\""); 52 53 if (SVGAnimatedListPropertyTearOff<SVGPointList>* list = m_animatablePointsList.get()) 54 list->detachListWrappers(newList.size()); 55 56 m_points.value = newList; 57 } else { 58 if (SVGTests::parseMappedAttribute(attr)) 59 return; 60 if (SVGLangSpace::parseMappedAttribute(attr)) 61 return; 62 if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) 63 return; 64 SVGStyledTransformableElement::parseMappedAttribute(attr); 65 } 66 } 67 68 void SVGPolyElement::svgAttributeChanged(const QualifiedName& attrName) 69 { 70 SVGStyledTransformableElement::svgAttributeChanged(attrName); 71 72 if (SVGTests::handleAttributeChange(this, attrName)) 73 return; 74 75 RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); 76 if (!renderer) 77 return; 78 79 if (attrName == SVGNames::pointsAttr) { 80 renderer->setNeedsPathUpdate(); 81 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 82 return; 83 } 84 85 if (SVGLangSpace::isKnownAttribute(attrName) 86 || SVGExternalResourcesRequired::isKnownAttribute(attrName)) 87 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 88 } 89 90 void SVGPolyElement::synchronizeProperty(const QualifiedName& attrName) 91 { 92 SVGStyledTransformableElement::synchronizeProperty(attrName); 93 94 if (attrName == anyQName()) { 95 synchronizeExternalResourcesRequired(); 96 synchronizePoints(); 97 SVGTests::synchronizeProperties(this, attrName); 98 return; 99 } 100 101 if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) 102 synchronizeExternalResourcesRequired(); 103 else if (attrName == SVGNames::pointsAttr) 104 synchronizePoints(); 105 else if (SVGTests::isKnownAttribute(attrName)) 106 SVGTests::synchronizeProperties(this, attrName); 107 } 108 109 AttributeToPropertyTypeMap& SVGPolyElement::attributeToPropertyTypeMap() 110 { 111 DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ()); 112 return s_attributeToPropertyTypeMap; 113 } 114 115 void SVGPolyElement::fillAttributeToPropertyTypeMap() 116 { 117 AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap(); 118 119 SVGStyledTransformableElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap); 120 attributeToPropertyTypeMap.set(SVGNames::pointsAttr, AnimatedPoints); 121 } 122 123 void SVGPolyElement::synchronizePoints() 124 { 125 if (!m_points.shouldSynchronize) 126 return; 127 128 SVGAnimatedPropertySynchronizer<true>::synchronize(this, SVGNames::pointsAttr, m_points.value.valueAsString()); 129 } 130 131 SVGListPropertyTearOff<SVGPointList>* SVGPolyElement::points() 132 { 133 if (!m_animatablePointsList) { 134 m_points.shouldSynchronize = true; 135 m_animatablePointsList = SVGAnimatedProperty::lookupOrCreateWrapper<SVGAnimatedListPropertyTearOff<SVGPointList> , SVGPointList> 136 (this, SVGNames::pointsAttr, SVGNames::pointsAttr.localName(), m_points.value); 137 } 138 139 return static_cast<SVGListPropertyTearOff<SVGPointList>*>(m_animatablePointsList->baseVal()); 140 } 141 142 SVGListPropertyTearOff<SVGPointList>* SVGPolyElement::animatedPoints() 143 { 144 if (!m_animatablePointsList) { 145 m_points.shouldSynchronize = true; 146 m_animatablePointsList = SVGAnimatedProperty::lookupOrCreateWrapper<SVGAnimatedListPropertyTearOff<SVGPointList> , SVGPointList> 147 (this, SVGNames::pointsAttr, SVGNames::pointsAttr.localName(), m_points.value); 148 } 149 150 return static_cast<SVGListPropertyTearOff<SVGPointList>*>(m_animatablePointsList->animVal()); 151 } 152 153 } 154 155 #endif // ENABLE(SVG) 156