KHtml

SVGEllipseElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006, 2007 Rob Buis <[email protected]>
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 "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGEllipseElement.h"
27 
28 #include "FloatPoint.h"
29 #include "RenderPath.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 
33 namespace WebCore
34 {
35 
36 SVGEllipseElement::SVGEllipseElement(const QualifiedName &tagName, Document *doc)
37  : SVGStyledTransformableElement(tagName, doc)
38  , SVGTests()
39  , SVGLangSpace()
40  , SVGExternalResourcesRequired()
41  , m_cx(this, LengthModeWidth)
42  , m_cy(this, LengthModeHeight)
43  , m_rx(this, LengthModeWidth)
44  , m_ry(this, LengthModeHeight)
45 {
46 }
47 
48 SVGEllipseElement::~SVGEllipseElement()
49 {
50 }
51 
52 ANIMATED_PROPERTY_DEFINITIONS(SVGEllipseElement, SVGLength, Length, length, Cx, cx, SVGNames::cxAttr, m_cx)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGEllipseElement, SVGLength, Length, length, Cy, cy, SVGNames::cyAttr, m_cy)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGEllipseElement, SVGLength, Length, length, Rx, rx, SVGNames::rxAttr, m_rx)
55 ANIMATED_PROPERTY_DEFINITIONS(SVGEllipseElement, SVGLength, Length, length, Ry, ry, SVGNames::ryAttr, m_ry)
56 
57 void SVGEllipseElement::parseMappedAttribute(MappedAttribute *attr)
58 {
59  if (attr->name() == SVGNames::cxAttr) {
60  setCxBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
61  } else if (attr->name() == SVGNames::cyAttr) {
62  setCyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
63  } else if (attr->name() == SVGNames::rxAttr) {
64  setRxBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
65  if (rx().value() < 0.0) {
66  document()->accessSVGExtensions()->reportError("A negative value for ellipse <rx> is not allowed");
67  }
68  } else if (attr->name() == SVGNames::ryAttr) {
69  setRyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
70  if (ry().value() < 0.0) {
71  document()->accessSVGExtensions()->reportError("A negative value for ellipse <ry> is not allowed");
72  }
73  } else {
74  if (SVGTests::parseMappedAttribute(attr)) {
75  return;
76  }
77  if (SVGLangSpace::parseMappedAttribute(attr)) {
78  return;
79  }
80  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
81  return;
82  }
83  SVGStyledTransformableElement::parseMappedAttribute(attr);
84  }
85 }
86 
87 void SVGEllipseElement::svgAttributeChanged(const QualifiedName &attrName)
88 {
89  SVGStyledTransformableElement::svgAttributeChanged(attrName);
90 
91  if (!renderer()) {
92  return;
93  }
94 
95  if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
96  attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
97  SVGTests::isKnownAttribute(attrName) ||
98  SVGLangSpace::isKnownAttribute(attrName) ||
99  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
100  SVGStyledTransformableElement::isKnownAttribute(attrName)) {
101  renderer()->setNeedsLayout(true);
102  }
103 }
104 
105 Path SVGEllipseElement::toPathData() const
106 {
107  return Path::createEllipse(FloatPoint(cx().value(), cy().value()),
108  rx().value(), ry().value());
109 }
110 
111 bool SVGEllipseElement::hasRelativeValues() const
112 {
113  return (cx().isRelative() || cy().isRelative() ||
114  rx().isRelative() || ry().isRelative());
115 }
116 
117 // KHTML ElementImpl pure virtual method
118 quint32 SVGEllipseElement::id() const
119 {
120  return SVGNames::ellipseTag.id();
121 }
122 
123 }
124 
125 #endif // ENABLE(SVG)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:48:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.