24#include "wtf/Platform.h"
29#include "RenderPath.h"
35SVGRectElement::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)
49SVGRectElement::~SVGRectElement()
53ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length,
X, x, SVGNames::xAttr, m_x)
54ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
55ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
56ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
57ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Rx, rx, SVGNames::rxAttr, m_rx)
58ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Ry, ry, SVGNames::ryAttr, m_ry)
60void 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);
94void 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);
111Path 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);
126bool SVGRectElement::hasRelativeValues()
const
128 return (x().isRelative() || width().isRelative() ||
129 y().isRelative() || height().isRelative() ||
130 rx().isRelative() || ry().isRelative());
134quint32 SVGRectElement::id()
const
136 return SVGNames::rectTag.id();