File indexing completed on 2024-04-28 11:39:10

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 "SVGCircleElement.h"
0027 
0028 #include "FloatPoint.h"
0029 #include "RenderPath.h"
0030 #include "SVGNames.h"
0031 
0032 namespace WebCore
0033 {
0034 
0035 SVGCircleElement::SVGCircleElement(const QualifiedName &tagName, Document *doc)
0036     : SVGStyledTransformableElement(tagName, doc)
0037     , SVGTests()
0038     , SVGLangSpace()
0039     , SVGExternalResourcesRequired()
0040     , m_cx(SVGLength(this, LengthModeWidth))
0041     , m_cy(SVGLength(this, LengthModeHeight))
0042     , m_r(SVGLength(this, LengthModeOther))
0043 {
0044 }
0045 
0046 SVGCircleElement::~SVGCircleElement()
0047 {
0048 }
0049 
0050 ANIMATED_PROPERTY_DEFINITIONS(SVGCircleElement, SVGLength, Length, length, Cx, cx, SVGNames::cxAttr, m_cx)
0051 ANIMATED_PROPERTY_DEFINITIONS(SVGCircleElement, SVGLength, Length, length, Cy, cy, SVGNames::cyAttr, m_cy)
0052 ANIMATED_PROPERTY_DEFINITIONS(SVGCircleElement, SVGLength, Length, length, R, r, SVGNames::rAttr, m_r)
0053 
0054 void SVGCircleElement::parseMappedAttribute(MappedAttribute *attr)
0055 {
0056     if (attr->name() == SVGNames::cxAttr) {
0057         setCxBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
0058     } else if (attr->name() == SVGNames::cyAttr) {
0059         setCyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
0060     } else if (attr->name() == SVGNames::rAttr) {
0061         setRBaseValue(SVGLength(this, LengthModeOther, attr->value()));
0062         if (r().value() < 0.0) {
0063             document()->accessSVGExtensions()->reportError("A negative value for circle <r> is not allowed");
0064         }
0065     } else {
0066         if (SVGTests::parseMappedAttribute(attr)) {
0067             return;
0068         }
0069         if (SVGLangSpace::parseMappedAttribute(attr)) {
0070             return;
0071         }
0072         if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
0073             return;
0074         }
0075         SVGStyledTransformableElement::parseMappedAttribute(attr);
0076     }
0077 }
0078 
0079 void SVGCircleElement::svgAttributeChanged(const QualifiedName &attrName)
0080 {
0081     SVGStyledTransformableElement::svgAttributeChanged(attrName);
0082 
0083     if (!renderer()) {
0084         return;
0085     }
0086 
0087     if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
0088             attrName == SVGNames::rAttr ||
0089             SVGTests::isKnownAttribute(attrName) ||
0090             SVGLangSpace::isKnownAttribute(attrName) ||
0091             SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
0092             SVGStyledTransformableElement::isKnownAttribute(attrName)) {
0093         renderer()->setNeedsLayout(true);
0094     }
0095 }
0096 
0097 Path SVGCircleElement::toPathData() const
0098 {
0099     return Path::createCircle(FloatPoint(cx().value(), cy().value()), r().value());
0100 }
0101 
0102 bool SVGCircleElement::hasRelativeValues() const
0103 {
0104     return (cx().isRelative() || cy().isRelative() || r().isRelative());
0105 }
0106 
0107 // KHTML ElementImpl pure virtual method
0108 quint32 SVGCircleElement::id() const
0109 {
0110     return SVGNames::circleTag.id();
0111 }
0112 
0113 }
0114 
0115 #endif // ENABLE(SVG)