Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / svg / SVGEllipseElement.cpp
blob3946fb9ea410156325dd5e8faff98c83685f410c
1 /*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
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.
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.
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.
21 #include "config.h"
23 #if ENABLE(SVG)
24 #include "SVGEllipseElement.h"
26 #include "FloatPoint.h"
27 #include "MappedAttribute.h"
28 #include "RenderPath.h"
29 #include "SVGLength.h"
30 #include "SVGNames.h"
32 namespace WebCore {
34 SVGEllipseElement::SVGEllipseElement(const QualifiedName& tagName, Document* doc)
35 : SVGStyledTransformableElement(tagName, doc)
36 , SVGTests()
37 , SVGLangSpace()
38 , SVGExternalResourcesRequired()
39 , m_cx(this, SVGNames::cxAttr, LengthModeWidth)
40 , m_cy(this, SVGNames::cyAttr, LengthModeHeight)
41 , m_rx(this, SVGNames::rxAttr, LengthModeWidth)
42 , m_ry(this, SVGNames::ryAttr, LengthModeHeight)
43 , m_externalResourcesRequired(this, SVGNames::externalResourcesRequiredAttr, false)
47 SVGEllipseElement::~SVGEllipseElement()
51 void SVGEllipseElement::parseMappedAttribute(MappedAttribute* attr)
53 if (attr->name() == SVGNames::cxAttr)
54 setCxBaseValue(SVGLength(LengthModeWidth, attr->value()));
55 else if (attr->name() == SVGNames::cyAttr)
56 setCyBaseValue(SVGLength(LengthModeHeight, attr->value()));
57 else if (attr->name() == SVGNames::rxAttr) {
58 setRxBaseValue(SVGLength(LengthModeWidth, attr->value()));
59 if (rxBaseValue().value(this) < 0.0)
60 document()->accessSVGExtensions()->reportError("A negative value for ellipse <rx> is not allowed");
61 } else if (attr->name() == SVGNames::ryAttr) {
62 setRyBaseValue(SVGLength(LengthModeHeight, attr->value()));
63 if (ryBaseValue().value(this) < 0.0)
64 document()->accessSVGExtensions()->reportError("A negative value for ellipse <ry> is not allowed");
65 } else {
66 if (SVGTests::parseMappedAttribute(attr))
67 return;
68 if (SVGLangSpace::parseMappedAttribute(attr))
69 return;
70 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
71 return;
72 SVGStyledTransformableElement::parseMappedAttribute(attr);
76 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
78 SVGStyledTransformableElement::svgAttributeChanged(attrName);
80 if (!renderer())
81 return;
83 if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
84 attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
85 SVGTests::isKnownAttribute(attrName) ||
86 SVGLangSpace::isKnownAttribute(attrName) ||
87 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
88 SVGStyledTransformableElement::isKnownAttribute(attrName))
89 renderer()->setNeedsLayout(true);
92 Path SVGEllipseElement::toPathData() const
94 return Path::createEllipse(FloatPoint(cx().value(this), cy().value(this)),
95 rx().value(this), ry().value(this));
98 bool SVGEllipseElement::hasRelativeValues() const
100 return (cx().isRelative() || cy().isRelative() ||
101 rx().isRelative() || ry().isRelative());
106 #endif // ENABLE(SVG)