1 /*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24
25 #if ENABLE(SVG)
26 #include "SVGEllipseElement.h"
27
28 #include "FloatPoint.h"
29 #include "MappedAttribute.h"
30 #include "RenderPath.h"
31 #include "SVGLength.h"
32 #include "SVGNames.h"
33
34 namespace WebCore {
35
SVGEllipseElement(const QualifiedName & tagName,Document * doc)36 SVGEllipseElement::SVGEllipseElement(const QualifiedName& tagName, Document* doc)
37 : SVGStyledTransformableElement(tagName, doc)
38 , SVGTests()
39 , SVGLangSpace()
40 , SVGExternalResourcesRequired()
41 , m_cx(this, SVGNames::cxAttr, LengthModeWidth)
42 , m_cy(this, SVGNames::cyAttr, LengthModeHeight)
43 , m_rx(this, SVGNames::rxAttr, LengthModeWidth)
44 , m_ry(this, SVGNames::ryAttr, LengthModeHeight)
45 {
46 }
47
~SVGEllipseElement()48 SVGEllipseElement::~SVGEllipseElement()
49 {
50 }
51
parseMappedAttribute(MappedAttribute * attr)52 void SVGEllipseElement::parseMappedAttribute(MappedAttribute* attr)
53 {
54 if (attr->name() == SVGNames::cxAttr)
55 setCxBaseValue(SVGLength(LengthModeWidth, attr->value()));
56 else if (attr->name() == SVGNames::cyAttr)
57 setCyBaseValue(SVGLength(LengthModeHeight, attr->value()));
58 else if (attr->name() == SVGNames::rxAttr) {
59 setRxBaseValue(SVGLength(LengthModeWidth, attr->value()));
60 if (rxBaseValue().value(this) < 0.0)
61 document()->accessSVGExtensions()->reportError("A negative value for ellipse <rx> is not allowed");
62 } else if (attr->name() == SVGNames::ryAttr) {
63 setRyBaseValue(SVGLength(LengthModeHeight, attr->value()));
64 if (ryBaseValue().value(this) < 0.0)
65 document()->accessSVGExtensions()->reportError("A negative value for ellipse <ry> is not allowed");
66 } else {
67 if (SVGTests::parseMappedAttribute(attr))
68 return;
69 if (SVGLangSpace::parseMappedAttribute(attr))
70 return;
71 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
72 return;
73 SVGStyledTransformableElement::parseMappedAttribute(attr);
74 }
75 }
76
svgAttributeChanged(const QualifiedName & attrName)77 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
78 {
79 SVGStyledTransformableElement::svgAttributeChanged(attrName);
80
81 if (!renderer())
82 return;
83
84 if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
85 attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
86 SVGTests::isKnownAttribute(attrName) ||
87 SVGLangSpace::isKnownAttribute(attrName) ||
88 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
89 SVGStyledTransformableElement::isKnownAttribute(attrName))
90 renderer()->setNeedsLayout(true);
91 }
92
toPathData() const93 Path SVGEllipseElement::toPathData() const
94 {
95 return Path::createEllipse(FloatPoint(cx().value(this), cy().value(this)),
96 rx().value(this), ry().value(this));
97 }
98
hasRelativeValues() const99 bool SVGEllipseElement::hasRelativeValues() const
100 {
101 return (cx().isRelative() || cy().isRelative() ||
102 rx().isRelative() || ry().isRelative());
103 }
104
105 }
106
107 #endif // ENABLE(SVG)
108