• 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 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 "SVGEllipseElement.h"
25 
26 #include "FloatPoint.h"
27 #include "MappedAttribute.h"
28 #include "RenderPath.h"
29 #include "SVGLength.h"
30 #include "SVGNames.h"
31 
32 namespace WebCore {
33 
SVGEllipseElement(const QualifiedName & tagName,Document * doc)34 SVGEllipseElement::SVGEllipseElement(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_rx(LengthModeWidth)
42     , m_ry(LengthModeHeight)
43 {
44 }
45 
~SVGEllipseElement()46 SVGEllipseElement::~SVGEllipseElement()
47 {
48 }
49 
parseMappedAttribute(MappedAttribute * attr)50 void SVGEllipseElement::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::rxAttr) {
57         setRxBaseValue(SVGLength(LengthModeWidth, attr->value()));
58         if (rxBaseValue().value(this) < 0.0)
59             document()->accessSVGExtensions()->reportError("A negative value for ellipse <rx> is not allowed");
60     } else if (attr->name() == SVGNames::ryAttr) {
61         setRyBaseValue(SVGLength(LengthModeHeight, attr->value()));
62         if (ryBaseValue().value(this) < 0.0)
63             document()->accessSVGExtensions()->reportError("A negative value for ellipse <ry> is not allowed");
64     } else {
65         if (SVGTests::parseMappedAttribute(attr))
66             return;
67         if (SVGLangSpace::parseMappedAttribute(attr))
68             return;
69         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
70             return;
71         SVGStyledTransformableElement::parseMappedAttribute(attr);
72     }
73 }
74 
svgAttributeChanged(const QualifiedName & attrName)75 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
76 {
77     SVGStyledTransformableElement::svgAttributeChanged(attrName);
78 
79     if (!renderer())
80         return;
81 
82     if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
83         attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
84         SVGTests::isKnownAttribute(attrName) ||
85         SVGLangSpace::isKnownAttribute(attrName) ||
86         SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
87         SVGStyledTransformableElement::isKnownAttribute(attrName))
88         renderer()->setNeedsLayout(true);
89 }
90 
synchronizeProperty(const QualifiedName & attrName)91 void SVGEllipseElement::synchronizeProperty(const QualifiedName& attrName)
92 {
93     SVGStyledTransformableElement::synchronizeProperty(attrName);
94 
95     if (attrName == anyQName()) {
96         synchronizeCx();
97         synchronizeCy();
98         synchronizeRx();
99         synchronizeRy();
100         synchronizeExternalResourcesRequired();
101         return;
102     }
103 
104     if (attrName == SVGNames::cxAttr)
105         synchronizeCx();
106     else if (attrName == SVGNames::cyAttr)
107         synchronizeCy();
108     else if (attrName == SVGNames::rxAttr)
109         synchronizeRx();
110     else if (attrName == SVGNames::ryAttr)
111         synchronizeRy();
112     else if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
113         synchronizeExternalResourcesRequired();
114 }
115 
toPathData() const116 Path SVGEllipseElement::toPathData() const
117 {
118     return Path::createEllipse(FloatPoint(cx().value(this), cy().value(this)),
119                                           rx().value(this), ry().value(this));
120 }
121 
hasRelativeValues() const122 bool SVGEllipseElement::hasRelativeValues() const
123 {
124     return (cx().isRelative() || cy().isRelative() ||
125             rx().isRelative() || ry().isRelative());
126 }
127 
128 }
129 
130 #endif // ENABLE(SVG)
131