KHtml

SVGCircleElement.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 "SVGCircleElement.h"
27 
28 #include "FloatPoint.h"
29 #include "RenderPath.h"
30 #include "SVGNames.h"
31 
32 namespace WebCore
33 {
34 
35 SVGCircleElement::SVGCircleElement(const QualifiedName &tagName, Document *doc)
36  : SVGStyledTransformableElement(tagName, doc)
37  , SVGTests()
38  , SVGLangSpace()
39  , SVGExternalResourcesRequired()
40  , m_cx(SVGLength(this, LengthModeWidth))
41  , m_cy(SVGLength(this, LengthModeHeight))
42  , m_r(SVGLength(this, LengthModeOther))
43 {
44 }
45 
46 SVGCircleElement::~SVGCircleElement()
47 {
48 }
49 
50 ANIMATED_PROPERTY_DEFINITIONS(SVGCircleElement, SVGLength, Length, length, Cx, cx, SVGNames::cxAttr, m_cx)
51 ANIMATED_PROPERTY_DEFINITIONS(SVGCircleElement, SVGLength, Length, length, Cy, cy, SVGNames::cyAttr, m_cy)
52 ANIMATED_PROPERTY_DEFINITIONS(SVGCircleElement, SVGLength, Length, length, R, r, SVGNames::rAttr, m_r)
53 
54 void SVGCircleElement::parseMappedAttribute(MappedAttribute *attr)
55 {
56  if (attr->name() == SVGNames::cxAttr) {
57  setCxBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
58  } else if (attr->name() == SVGNames::cyAttr) {
59  setCyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
60  } else if (attr->name() == SVGNames::rAttr) {
61  setRBaseValue(SVGLength(this, LengthModeOther, attr->value()));
62  if (r().value() < 0.0) {
63  document()->accessSVGExtensions()->reportError("A negative value for circle <r> is not allowed");
64  }
65  } else {
66  if (SVGTests::parseMappedAttribute(attr)) {
67  return;
68  }
69  if (SVGLangSpace::parseMappedAttribute(attr)) {
70  return;
71  }
72  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
73  return;
74  }
75  SVGStyledTransformableElement::parseMappedAttribute(attr);
76  }
77 }
78 
79 void SVGCircleElement::svgAttributeChanged(const QualifiedName &attrName)
80 {
81  SVGStyledTransformableElement::svgAttributeChanged(attrName);
82 
83  if (!renderer()) {
84  return;
85  }
86 
87  if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr ||
88  attrName == SVGNames::rAttr ||
89  SVGTests::isKnownAttribute(attrName) ||
90  SVGLangSpace::isKnownAttribute(attrName) ||
91  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
92  SVGStyledTransformableElement::isKnownAttribute(attrName)) {
93  renderer()->setNeedsLayout(true);
94  }
95 }
96 
97 Path SVGCircleElement::toPathData() const
98 {
99  return Path::createCircle(FloatPoint(cx().value(), cy().value()), r().value());
100 }
101 
102 bool SVGCircleElement::hasRelativeValues() const
103 {
104  return (cx().isRelative() || cy().isRelative() || r().isRelative());
105 }
106 
107 // KHTML ElementImpl pure virtual method
108 quint32 SVGCircleElement::id() const
109 {
110  return SVGNames::circleTag.id();
111 }
112 
113 }
114 
115 #endif // ENABLE(SVG)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.