2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
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.
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.
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.
24 #include "wtf/Platform.h"
27 #include "SVGRectElement.h"
29 #include "RenderPath.h"
30 #include "SVGLength.h"
35 SVGRectElement::SVGRectElement(const QualifiedName
& tagName
, Document
*doc
)
36 : SVGStyledTransformableElement(tagName
, doc
)
39 , SVGExternalResourcesRequired()
40 , m_x(this, LengthModeWidth
)
41 , m_y(this, LengthModeHeight
)
42 , m_width(this, LengthModeWidth
)
43 , m_height(this, LengthModeHeight
)
44 , m_rx(this, LengthModeWidth
)
45 , m_ry(this, LengthModeHeight
)
49 SVGRectElement::~SVGRectElement()
53 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement
, SVGLength
, Length
, length
, X
, x
, SVGNames::xAttr
, m_x
)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement
, SVGLength
, Length
, length
, Y
, y
, SVGNames::yAttr
, m_y
)
55 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement
, SVGLength
, Length
, length
, Width
, width
, SVGNames::widthAttr
, m_width
)
56 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement
, SVGLength
, Length
, length
, Height
, height
, SVGNames::heightAttr
, m_height
)
57 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement
, SVGLength
, Length
, length
, Rx
, rx
, SVGNames::rxAttr
, m_rx
)
58 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement
, SVGLength
, Length
, length
, Ry
, ry
, SVGNames::ryAttr
, m_ry
)
60 void SVGRectElement::parseMappedAttribute(MappedAttribute
* attr
)
62 kDebug() << "called with" << attr
->localName() << attr
->value() << endl
;
63 if (attr
->name() == SVGNames::xAttr
)
64 setXBaseValue(SVGLength(this, LengthModeWidth
, attr
->value()));
65 else if (attr
->name() == SVGNames::yAttr
)
66 setYBaseValue(SVGLength(this, LengthModeHeight
, attr
->value()));
67 else if (attr
->name() == SVGNames::rxAttr
) {
68 setRxBaseValue(SVGLength(this, LengthModeWidth
, attr
->value()));
69 if (rx().value() < 0.0)
70 document()->accessSVGExtensions()->reportError("A negative value for rect <rx> is not allowed");
71 } else if (attr
->name() == SVGNames::ryAttr
) {
72 setRyBaseValue(SVGLength(this, LengthModeHeight
, attr
->value()));
73 if (ry().value() < 0.0)
74 document()->accessSVGExtensions()->reportError("A negative value for rect <ry> is not allowed");
75 } else if (attr
->name() == SVGNames::widthAttr
) {
76 setWidthBaseValue(SVGLength(this, LengthModeWidth
, attr
->value()));
77 if (width().value() < 0.0)
78 document()->accessSVGExtensions()->reportError("A negative value for rect <width> is not allowed");
79 } else if (attr
->name() == SVGNames::heightAttr
) {
80 setHeightBaseValue(SVGLength(this, LengthModeHeight
, attr
->value()));
81 if (height().value() < 0.0)
82 document()->accessSVGExtensions()->reportError("A negative value for rect <height> is not allowed");
84 if (SVGTests::parseMappedAttribute(attr
))
86 if (SVGLangSpace::parseMappedAttribute(attr
))
88 if (SVGExternalResourcesRequired::parseMappedAttribute(attr
))
90 SVGStyledTransformableElement::parseMappedAttribute(attr
);
94 void SVGRectElement::svgAttributeChanged(const QualifiedName
& attrName
)
96 SVGStyledTransformableElement::svgAttributeChanged(attrName
);
101 if (attrName
== SVGNames::xAttr
|| attrName
== SVGNames::yAttr
||
102 attrName
== SVGNames::widthAttr
|| attrName
== SVGNames::heightAttr
||
103 attrName
== SVGNames::rxAttr
|| attrName
== SVGNames::ryAttr
||
104 SVGTests::isKnownAttribute(attrName
) ||
105 SVGLangSpace::isKnownAttribute(attrName
) ||
106 SVGExternalResourcesRequired::isKnownAttribute(attrName
) ||
107 SVGStyledTransformableElement::isKnownAttribute(attrName
))
108 renderer()->setNeedsLayout(true);
111 Path
SVGRectElement::toPathData() const
113 FloatRect
rect(x().value(), y().value(), width().value(), height().value());
115 bool hasRx
= hasAttribute(SVGNames::rxAttr
);
116 bool hasRy
= hasAttribute(SVGNames::ryAttr
);
117 if (hasRx
|| hasRy
) {
118 float _rx
= hasRx
? rx().value() : ry().value();
119 float _ry
= hasRy
? ry().value() : rx().value();
120 return Path::createRoundedRectangle(rect
, FloatSize(_rx
, _ry
));
123 return Path::createRectangle(rect
);
126 bool SVGRectElement::hasRelativeValues() const
128 return (x().isRelative() || width().isRelative() ||
129 y().isRelative() || height().isRelative() ||
130 rx().isRelative() || ry().isRelative());
133 // KHTML ElementImpl pure virtual method
134 quint32
SVGRectElement::id() const
136 return SVGNames::rectTag
.id();
139 DOMString
SVGRectElement::tagName() const
141 return SVGNames::rectTag
.tagName();
146 #endif // ENABLE(SVG)