1 /*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24
25 #if ENABLE(SVG)
26 #include "SVGPolyElement.h"
27
28 #include "Document.h"
29 #include "FloatPoint.h"
30 #include "RenderPath.h"
31 #include "SVGAnimatedProperty.h"
32 #include "SVGNames.h"
33 #include "SVGParserUtilities.h"
34 #include "SVGPointList.h"
35
36 namespace WebCore {
37
SVGPolyElement(const QualifiedName & tagName,Document * doc)38 SVGPolyElement::SVGPolyElement(const QualifiedName& tagName, Document* doc)
39 : SVGStyledTransformableElement(tagName, doc)
40 , SVGTests()
41 , SVGLangSpace()
42 , SVGExternalResourcesRequired()
43 , SVGAnimatedPoints()
44 {
45 }
46
~SVGPolyElement()47 SVGPolyElement::~SVGPolyElement()
48 {
49 }
50
points() const51 SVGPointList* SVGPolyElement::points() const
52 {
53 if (!m_points)
54 m_points = SVGPointList::create(SVGNames::pointsAttr);
55
56 return m_points.get();
57 }
58
animatedPoints() const59 SVGPointList* SVGPolyElement::animatedPoints() const
60 {
61 // FIXME!
62 return 0;
63 }
64
parseMappedAttribute(MappedAttribute * attr)65 void SVGPolyElement::parseMappedAttribute(MappedAttribute* attr)
66 {
67 const AtomicString& value = attr->value();
68 if (attr->name() == SVGNames::pointsAttr) {
69 ExceptionCode ec = 0;
70 points()->clear(ec);
71
72 if (!pointsListFromSVGData(points(), value)) {
73 points()->clear(ec);
74 document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value + "\"");
75 }
76 } else {
77 if (SVGTests::parseMappedAttribute(attr))
78 return;
79 if (SVGLangSpace::parseMappedAttribute(attr))
80 return;
81 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
82 return;
83 SVGStyledTransformableElement::parseMappedAttribute(attr);
84 }
85 }
86
svgAttributeChanged(const QualifiedName & attrName)87 void SVGPolyElement::svgAttributeChanged(const QualifiedName& attrName)
88 {
89 SVGStyledTransformableElement::svgAttributeChanged(attrName);
90
91 if (!renderer())
92 return;
93
94 if (attrName == SVGNames::pointsAttr) {
95 setSynchronizedSVGAttributes(false);
96 renderer()->setNeedsLayout(true);
97 return;
98 }
99
100 if (SVGTests::isKnownAttribute(attrName) ||
101 SVGLangSpace::isKnownAttribute(attrName) ||
102 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
103 SVGStyledTransformableElement::isKnownAttribute(attrName))
104 renderer()->setNeedsLayout(true);
105 }
106
107 // Custom SVG<->XML synchronization logic, as SVGPoly*Element doesn't use animated
108 // properties for this, but a special solution: SVGAnimatedPoints inheritance.
updateAnimatedSVGAttribute(const String & name) const109 void SVGPolyElement::updateAnimatedSVGAttribute(const String& name) const
110 {
111 ASSERT(!m_areSVGAttributesValid);
112
113 if (m_synchronizingSVGAttributes)
114 return;
115
116 if (name == SVGNames::pointsAttr.localName()) {
117 m_synchronizingSVGAttributes = true;
118
119 synchronizeProperty<SVGPolyElement, SVGPointList*>(this, SVGNames::pointsAttr, m_points.get());
120 setSynchronizedSVGAttributes(true);
121 m_synchronizingSVGAttributes = false;
122 return;
123 }
124
125 SVGStyledTransformableElement::updateAnimatedSVGAttribute(name);
126 }
127
128 }
129
130 #endif // ENABLE(SVG)
131