Home | History | Annotate | Download | only in svg
      1 /*
      2     Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      3                   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 "Document.h"
     27 #include "FloatPoint.h"
     28 #include "MappedAttribute.h"
     29 #include "RenderPath.h"
     30 #include "SVGNames.h"
     31 #include "SVGParserUtilities.h"
     32 #include "SVGPointList.h"
     33 
     34 namespace WebCore {
     35 
     36 SVGPolyElement::SVGPolyElement(const QualifiedName& tagName, Document* doc)
     37     : SVGStyledTransformableElement(tagName, doc)
     38     , SVGTests()
     39     , SVGLangSpace()
     40     , SVGExternalResourcesRequired()
     41     , SVGAnimatedPoints()
     42 {
     43 }
     44 
     45 SVGPolyElement::~SVGPolyElement()
     46 {
     47 }
     48 
     49 SVGPointList* SVGPolyElement::points() const
     50 {
     51     if (!m_points)
     52         m_points = SVGPointList::create(SVGNames::pointsAttr);
     53 
     54     return m_points.get();
     55 }
     56 
     57 SVGPointList* SVGPolyElement::animatedPoints() const
     58 {
     59     // FIXME!
     60     return 0;
     61 }
     62 
     63 void SVGPolyElement::parseMappedAttribute(MappedAttribute* attr)
     64 {
     65     const AtomicString& value = attr->value();
     66     if (attr->name() == SVGNames::pointsAttr) {
     67         ExceptionCode ec = 0;
     68         points()->clear(ec);
     69 
     70         if (!pointsListFromSVGData(points(), value)) {
     71             points()->clear(ec);
     72             document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value + "\"");
     73         }
     74     } else {
     75         if (SVGTests::parseMappedAttribute(attr))
     76             return;
     77         if (SVGLangSpace::parseMappedAttribute(attr))
     78             return;
     79         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
     80             return;
     81         SVGStyledTransformableElement::parseMappedAttribute(attr);
     82     }
     83 }
     84 
     85 void SVGPolyElement::svgAttributeChanged(const QualifiedName& attrName)
     86 {
     87     SVGStyledTransformableElement::svgAttributeChanged(attrName);
     88 
     89     // The points property is not a regular SVGAnimatedProperty, still we use the same SVG<->XML DOM synchronization framework.
     90     if (attrName == SVGNames::pointsAttr)
     91         setSynchronizedSVGAttributes(false);
     92 
     93     if (!renderer())
     94         return;
     95 
     96     if (attrName == SVGNames::pointsAttr
     97         || SVGTests::isKnownAttribute(attrName)
     98         || SVGLangSpace::isKnownAttribute(attrName)
     99         || SVGExternalResourcesRequired::isKnownAttribute(attrName)
    100         || SVGStyledTransformableElement::isKnownAttribute(attrName))
    101         renderer()->setNeedsLayout(true);
    102 }
    103 
    104 void SVGPolyElement::synchronizeProperty(const QualifiedName& attrName)
    105 {
    106     SVGStyledTransformableElement::synchronizeProperty(attrName);
    107 
    108     if (attrName == anyQName()) {
    109         synchronizeExternalResourcesRequired();
    110         SVGAnimatedPropertySynchronizer<true>::synchronize(this, SVGNames::pointsAttr, points()->valueAsString());
    111         return;
    112     }
    113 
    114     if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
    115         synchronizeExternalResourcesRequired();
    116     else if (attrName == SVGNames::pointsAttr)
    117         SVGAnimatedPropertySynchronizer<true>::synchronize(this, attrName, points()->valueAsString());
    118 }
    119 
    120 }
    121 
    122 #endif // ENABLE(SVG)
    123