File indexing completed on 2024-04-28 15:24:40

0001 /*
0002     Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
0003                   2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
0004 
0005     This file is part of the KDE project
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #include "wtf/Platform.h"
0024 
0025 #if ENABLE(SVG)
0026 #include "SVGPolyElement.h"
0027 
0028 #include "Document.h"
0029 #include "FloatPoint.h"
0030 #include "RenderPath.h"
0031 #include "SVGNames.h"
0032 #include "SVGParserUtilities.h"
0033 #include "SVGPointList.h"
0034 
0035 namespace WebCore
0036 {
0037 
0038 SVGPolyElement::SVGPolyElement(const QualifiedName &tagName, Document *doc)
0039     : SVGStyledTransformableElement(tagName, doc)
0040     , SVGTests()
0041     , SVGLangSpace()
0042     , SVGExternalResourcesRequired()
0043     , SVGAnimatedPoints()
0044     , m_ignoreAttributeChanges(false)
0045 {
0046 }
0047 
0048 SVGPolyElement::~SVGPolyElement()
0049 {
0050 }
0051 
0052 SVGPointList *SVGPolyElement::points() const
0053 {
0054     if (!m_points) {
0055         m_points = SVGPointList::create(SVGNames::pointsAttr);
0056     }
0057 
0058     return m_points.get();
0059 }
0060 
0061 SVGPointList *SVGPolyElement::animatedPoints() const
0062 {
0063     // FIXME!
0064     return nullptr;
0065 }
0066 
0067 void SVGPolyElement::parseMappedAttribute(MappedAttribute *attr)
0068 {
0069     const AtomicString &value = attr->value();
0070     if (attr->name() == SVGNames::pointsAttr) {
0071         ExceptionCode ec = 0;
0072         points()->clear(ec);
0073 
0074         if (!pointsListFromSVGData(points(), value)) {
0075             points()->clear(ec);
0076             /*FIXME khtml document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value.string() + "\"");*/
0077         }
0078     } else {
0079         if (SVGTests::parseMappedAttribute(attr)) {
0080             return;
0081         }
0082         if (SVGLangSpace::parseMappedAttribute(attr)) {
0083             return;
0084         }
0085         if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
0086             return;
0087         }
0088         SVGStyledTransformableElement::parseMappedAttribute(attr);
0089     }
0090 }
0091 
0092 void SVGPolyElement::svgAttributeChanged(const QualifiedName &attrName)
0093 {
0094     if (m_ignoreAttributeChanges) {
0095         return;
0096     }
0097 
0098     SVGStyledTransformableElement::svgAttributeChanged(attrName);
0099 
0100     if (!renderer()) {
0101         return;
0102     }
0103 
0104     if (attrName == SVGNames::pointsAttr) {
0105         m_ignoreAttributeChanges = true;
0106         renderer()->setNeedsLayout(true);
0107 
0108         //ExceptionCode ec = 0;
0109 
0110         // Spec: Additionally, the 'points' attribute on the original element
0111         // accessed via the XML DOM (e.g., using the getAttribute() method call)
0112         // will reflect any changes made to points.
0113         // qCDebug(KHTML_LOG) << "fixme!!!!!!!!!";
0114         /*FIXME KHTML String _points;
0115         int len = points()->numberOfItems();
0116         for (int i = 0; i < len; ++i) {
0117             FloatPoint p = points()->getItem(i, ec);
0118             _points += String::format("%.6lg %.6lg ", p.x(), p.y());
0119         }
0120 
0121         if (RefPtr<Attr> attr = const_cast<SVGPolyElement*>(this)->getAttributeNode(SVGNames::pointsAttr.localName())) {
0122             ExceptionCode ec = 0;
0123             attr->setValue(_points, ec);
0124         }*/
0125 
0126         m_ignoreAttributeChanges = false;
0127         return;
0128     }
0129 
0130     if (SVGTests::isKnownAttribute(attrName) ||
0131             SVGLangSpace::isKnownAttribute(attrName) ||
0132             SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
0133             SVGStyledTransformableElement::isKnownAttribute(attrName)) {
0134         renderer()->setNeedsLayout(true);
0135     }
0136 }
0137 
0138 }
0139 
0140 #endif // ENABLE(SVG)