OSDN Git Service

Merge Webkit at r70949: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / svg / SVGPolyElement.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@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 SVGPolyElement::SVGPolyElement(const QualifiedName& tagName, Document* document)
38     : SVGStyledTransformableElement(tagName, document)
39 {
40 }
41
42 SVGPointList* SVGPolyElement::points() const
43 {
44     if (!m_points)
45         m_points = SVGPointList::create(SVGNames::pointsAttr);
46
47     return m_points.get();
48 }
49
50 SVGPointList* SVGPolyElement::animatedPoints() const
51 {
52     // FIXME!
53     return 0;
54 }
55
56 void SVGPolyElement::parseMappedAttribute(Attribute* attr)
57 {
58     const AtomicString& value = attr->value();
59     if (attr->name() == SVGNames::pointsAttr) {
60         ExceptionCode ec = 0;
61         points()->clear(ec);
62
63         if (!pointsListFromSVGData(points(), value))
64             document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value + "\"");
65     } else {
66         if (SVGTests::parseMappedAttribute(attr))
67             return;
68         if (SVGLangSpace::parseMappedAttribute(attr))
69             return;
70         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
71             return;
72         SVGStyledTransformableElement::parseMappedAttribute(attr);
73     }
74 }
75
76 void SVGPolyElement::svgAttributeChanged(const QualifiedName& attrName)
77 {
78     SVGStyledTransformableElement::svgAttributeChanged(attrName);
79
80     // The points property is not a regular SVGAnimatedProperty, still we use the same SVG<->XML DOM synchronization framework.
81     if (attrName == SVGNames::pointsAttr)
82         invalidateSVGAttributes();
83
84     RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer());
85     if (!renderer)
86         return;
87
88     if (SVGStyledTransformableElement::isKnownAttribute(attrName)) {
89         renderer->setNeedsTransformUpdate();
90         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
91         return;
92     }
93
94     if (attrName == SVGNames::pointsAttr) {
95         renderer->setNeedsPathUpdate();
96         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
97         return;
98     }
99
100     if (SVGTests::isKnownAttribute(attrName)
101         || SVGLangSpace::isKnownAttribute(attrName)
102         || SVGExternalResourcesRequired::isKnownAttribute(attrName))
103         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
104 }
105
106 void SVGPolyElement::synchronizeProperty(const QualifiedName& attrName)
107 {
108     SVGStyledTransformableElement::synchronizeProperty(attrName);
109
110     if (attrName == anyQName()) {
111         synchronizeExternalResourcesRequired();
112         SVGAnimatedPropertySynchronizer<true>::synchronize(this, SVGNames::pointsAttr, points()->valueAsString());
113         return;
114     }
115
116     if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
117         synchronizeExternalResourcesRequired();
118     else if (attrName == SVGNames::pointsAttr)
119         SVGAnimatedPropertySynchronizer<true>::synchronize(this, attrName, points()->valueAsString());
120 }
121
122 }
123
124 #endif // ENABLE(SVG)