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 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.
9
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.
14
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.
19*/
20
21#include "config.h"
22
23#if ENABLE(SVG)
24#include "SVGCircleElement.h"
25
26#include "FloatPoint.h"
27#include "MappedAttribute.h"
28#include "RenderPath.h"
29#include "SVGLength.h"
30#include "SVGNames.h"
31
32namespace WebCore {
33
34SVGCircleElement::SVGCircleElement(const QualifiedName& tagName, Document* doc)
35    : SVGStyledTransformableElement(tagName, doc)
36    , SVGTests()
37    , SVGLangSpace()
38    , SVGExternalResourcesRequired()
39    , m_cx(LengthModeWidth)
40    , m_cy(LengthModeHeight)
41    , m_r(LengthModeOther)
42{
43}
44
45SVGCircleElement::~SVGCircleElement()
46{
47}
48
49void SVGCircleElement::parseMappedAttribute(MappedAttribute* attr)
50{
51    if (attr->name() == SVGNames::cxAttr)
52        setCxBaseValue(SVGLength(LengthModeWidth, attr->value()));
53    else if (attr->name() == SVGNames::cyAttr)
54        setCyBaseValue(SVGLength(LengthModeHeight, attr->value()));
55    else if (attr->name() == SVGNames::rAttr) {
56        setRBaseValue(SVGLength(LengthModeOther, attr->value()));
57        if (rBaseValue().value(this) < 0.0)
58            document()->accessSVGExtensions()->reportError("A negative value for circle <r> is not allowed");
59    } else {
60        if (SVGTests::parseMappedAttribute(attr))
61            return;
62        if (SVGLangSpace::parseMappedAttribute(attr))
63            return;
64        if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
65            return;
66        SVGStyledTransformableElement::parseMappedAttribute(attr);
67    }
68}
69
70void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName)
71{
72    SVGStyledTransformableElement::svgAttributeChanged(attrName);
73
74    if (!renderer())
75        return;
76
77    if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
78        attrName == SVGNames::rAttr ||
79        SVGTests::isKnownAttribute(attrName) ||
80        SVGLangSpace::isKnownAttribute(attrName) ||
81        SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
82        SVGStyledTransformableElement::isKnownAttribute(attrName))
83        renderer()->setNeedsLayout(true);
84}
85
86void SVGCircleElement::synchronizeProperty(const QualifiedName& attrName)
87{
88    SVGStyledTransformableElement::synchronizeProperty(attrName);
89
90    if (attrName == anyQName()) {
91        synchronizeCx();
92        synchronizeCy();
93        synchronizeR();
94        synchronizeExternalResourcesRequired();
95        return;
96    }
97
98    if (attrName == SVGNames::cxAttr)
99        synchronizeCx();
100    else if (attrName == SVGNames::cyAttr)
101        synchronizeCy();
102    else if (attrName == SVGNames::rAttr)
103        synchronizeR();
104    else if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
105        synchronizeExternalResourcesRequired();
106}
107
108Path SVGCircleElement::toPathData() const
109{
110    return Path::createCircle(FloatPoint(cx().value(this), cy().value(this)), r().value(this));
111}
112
113bool SVGCircleElement::hasRelativeValues() const
114{
115    return (cx().isRelative() || cy().isRelative() || r().isRelative());
116}
117
118}
119
120#endif // ENABLE(SVG)
121