00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "wtf/Platform.h"
00025
00026 #if ENABLE(SVG)
00027 #include "SVGRectElement.h"
00028
00029 #include "RenderPath.h"
00030 #include "SVGLength.h"
00031 #include "SVGNames.h"
00032
00033 namespace WebCore {
00034
00035 SVGRectElement::SVGRectElement(const QualifiedName& tagName, Document *doc)
00036 : SVGStyledTransformableElement(tagName, doc)
00037 , SVGTests()
00038 , SVGLangSpace()
00039 , SVGExternalResourcesRequired()
00040 , m_x(this, LengthModeWidth)
00041 , m_y(this, LengthModeHeight)
00042 , m_width(this, LengthModeWidth)
00043 , m_height(this, LengthModeHeight)
00044 , m_rx(this, LengthModeWidth)
00045 , m_ry(this, LengthModeHeight)
00046 {
00047 }
00048
00049 SVGRectElement::~SVGRectElement()
00050 {
00051 }
00052
00053 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00054 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00055 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00056 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00057 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Rx, rx, SVGNames::rxAttr, m_rx)
00058 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Ry, ry, SVGNames::ryAttr, m_ry)
00059
00060 void SVGRectElement::parseMappedAttribute(MappedAttribute* attr)
00061 {
00062 kDebug() << "called with" << attr->localName() << attr->value() << endl;
00063 if (attr->name() == SVGNames::xAttr)
00064 setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00065 else if (attr->name() == SVGNames::yAttr)
00066 setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00067 else if (attr->name() == SVGNames::rxAttr) {
00068 setRxBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00069 if (rx().value() < 0.0)
00070 document()->accessSVGExtensions()->reportError("A negative value for rect <rx> is not allowed");
00071 } else if (attr->name() == SVGNames::ryAttr) {
00072 setRyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00073 if (ry().value() < 0.0)
00074 document()->accessSVGExtensions()->reportError("A negative value for rect <ry> is not allowed");
00075 } else if (attr->name() == SVGNames::widthAttr) {
00076 setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00077 if (width().value() < 0.0)
00078 document()->accessSVGExtensions()->reportError("A negative value for rect <width> is not allowed");
00079 } else if (attr->name() == SVGNames::heightAttr) {
00080 setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00081 if (height().value() < 0.0)
00082 document()->accessSVGExtensions()->reportError("A negative value for rect <height> is not allowed");
00083 } else {
00084 if (SVGTests::parseMappedAttribute(attr))
00085 return;
00086 if (SVGLangSpace::parseMappedAttribute(attr))
00087 return;
00088 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
00089 return;
00090 SVGStyledTransformableElement::parseMappedAttribute(attr);
00091 }
00092 }
00093
00094 void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName)
00095 {
00096 SVGStyledTransformableElement::svgAttributeChanged(attrName);
00097
00098 if (!renderer())
00099 return;
00100
00101 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
00102 attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
00103 attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
00104 SVGTests::isKnownAttribute(attrName) ||
00105 SVGLangSpace::isKnownAttribute(attrName) ||
00106 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
00107 SVGStyledTransformableElement::isKnownAttribute(attrName))
00108 renderer()->setNeedsLayout(true);
00109 }
00110
00111 Path SVGRectElement::toPathData() const
00112 {
00113 FloatRect rect(x().value(), y().value(), width().value(), height().value());
00114
00115 bool hasRx = hasAttribute(SVGNames::rxAttr);
00116 bool hasRy = hasAttribute(SVGNames::ryAttr);
00117 if (hasRx || hasRy) {
00118 float _rx = hasRx ? rx().value() : ry().value();
00119 float _ry = hasRy ? ry().value() : rx().value();
00120 return Path::createRoundedRectangle(rect, FloatSize(_rx, _ry));
00121 }
00122
00123 return Path::createRectangle(rect);
00124 }
00125
00126 bool SVGRectElement::hasRelativeValues() const
00127 {
00128 return (x().isRelative() || width().isRelative() ||
00129 y().isRelative() || height().isRelative() ||
00130 rx().isRelative() || ry().isRelative());
00131 }
00132
00133
00134 quint32 SVGRectElement::id() const
00135 {
00136 return SVGNames::rectTag.id();
00137 }
00138
00139 }
00140
00141 #endif // ENABLE(SVG)