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

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