• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SVGCircleElement.h"
27 
28 #include "FloatPoint.h"
29 #include "RenderPath.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 
33 namespace WebCore {
34 
SVGCircleElement(const QualifiedName & tagName,Document * doc)35 SVGCircleElement::SVGCircleElement(const QualifiedName& tagName, Document* doc)
36     : SVGStyledTransformableElement(tagName, doc)
37     , SVGTests()
38     , SVGLangSpace()
39     , SVGExternalResourcesRequired()
40     , m_cx(this, SVGNames::cxAttr, LengthModeWidth)
41     , m_cy(this, SVGNames::cyAttr, LengthModeHeight)
42     , m_r(this, SVGNames::rAttr, LengthModeOther)
43 {
44 }
45 
~SVGCircleElement()46 SVGCircleElement::~SVGCircleElement()
47 {
48 }
49 
parseMappedAttribute(MappedAttribute * attr)50 void SVGCircleElement::parseMappedAttribute(MappedAttribute* attr)
51 {
52     if (attr->name() == SVGNames::cxAttr)
53         setCxBaseValue(SVGLength(LengthModeWidth, attr->value()));
54     else if (attr->name() == SVGNames::cyAttr)
55         setCyBaseValue(SVGLength(LengthModeHeight, attr->value()));
56     else if (attr->name() == SVGNames::rAttr) {
57         setRBaseValue(SVGLength(LengthModeOther, attr->value()));
58         if (rBaseValue().value(this) < 0.0)
59             document()->accessSVGExtensions()->reportError("A negative value for circle <r> is not allowed");
60     } else {
61         if (SVGTests::parseMappedAttribute(attr))
62             return;
63         if (SVGLangSpace::parseMappedAttribute(attr))
64             return;
65         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
66             return;
67         SVGStyledTransformableElement::parseMappedAttribute(attr);
68     }
69 }
70 
svgAttributeChanged(const QualifiedName & attrName)71 void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName)
72 {
73     SVGStyledTransformableElement::svgAttributeChanged(attrName);
74 
75     if (!renderer())
76         return;
77 
78     if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
79         attrName == SVGNames::rAttr ||
80         SVGTests::isKnownAttribute(attrName) ||
81         SVGLangSpace::isKnownAttribute(attrName) ||
82         SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
83         SVGStyledTransformableElement::isKnownAttribute(attrName))
84         renderer()->setNeedsLayout(true);
85 }
86 
toPathData() const87 Path SVGCircleElement::toPathData() const
88 {
89     return Path::createCircle(FloatPoint(cx().value(this), cy().value(this)), r().value(this));
90 }
91 
hasRelativeValues() const92 bool SVGCircleElement::hasRelativeValues() const
93 {
94     return (cx().isRelative() || cy().isRelative() || r().isRelative());
95 }
96 
97 }
98 
99 #endif // ENABLE(SVG)
100