00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "config.h"
00025
00026 #if ENABLE(SVG)
00027 #include "SVGImageElement.h"
00028
00029 #include "CSSPropertyNames.h"
00030 #include "RenderSVGImage.h"
00031 #include "SVGDocument.h"
00032 #include "SVGLength.h"
00033 #include "SVGNames.h"
00034 #include "SVGPreserveAspectRatio.h"
00035 #include "SVGSVGElement.h"
00036 #include "XLinkNames.h"
00037
00038 namespace WebCore {
00039
00040 SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document* doc)
00041 : SVGStyledTransformableElement(tagName, doc)
00042 , SVGTests()
00043 , SVGLangSpace()
00044 , SVGExternalResourcesRequired()
00045 , SVGURIReference()
00046 , m_x(this, LengthModeWidth)
00047 , m_y(this, LengthModeHeight)
00048 , m_width(this, LengthModeWidth)
00049 , m_height(this, LengthModeHeight)
00050 , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
00051 , m_imageLoader(this)
00052 {
00053 }
00054
00055 SVGImageElement::~SVGImageElement()
00056 {
00057 }
00058
00059 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00060 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00061 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00062 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00063 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
00064
00065 void SVGImageElement::parseMappedAttribute(MappedAttribute *attr)
00066 {
00067 if (attr->name() == SVGNames::xAttr)
00068 setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00069 else if (attr->name() == SVGNames::yAttr)
00070 setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00071 else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
00072 const UChar* c = attr->value().characters();
00073 const UChar* end = c + attr->value().length();
00074 preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
00075 } else if (attr->name() == SVGNames::widthAttr) {
00076 setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00077 addCSSProperty(attr, CSSPropertyWidth, attr->value());
00078 if (width().value() < 0.0)
00079 document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed");
00080 } else if (attr->name() == SVGNames::heightAttr) {
00081 setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00082 addCSSProperty(attr, CSSPropertyHeight, attr->value());
00083 if (height().value() < 0.0)
00084 document()->accessSVGExtensions()->reportError("A negative value for image attribute <height> is not allowed");
00085 } else {
00086 if (SVGTests::parseMappedAttribute(attr))
00087 return;
00088 if (SVGLangSpace::parseMappedAttribute(attr))
00089 return;
00090 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
00091 return;
00092 if (SVGURIReference::parseMappedAttribute(attr))
00093 return;
00094 SVGStyledTransformableElement::parseMappedAttribute(attr);
00095 }
00096 }
00097
00098 void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName)
00099 {
00100 SVGStyledTransformableElement::svgAttributeChanged(attrName);
00101
00102 if (!renderer())
00103 return;
00104
00105 bool isURIAttribute = SVGURIReference::isKnownAttribute(attrName);
00106
00107 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
00108 attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
00109 SVGTests::isKnownAttribute(attrName) ||
00110 SVGLangSpace::isKnownAttribute(attrName) ||
00111 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
00112 isURIAttribute ||
00113 SVGStyledTransformableElement::isKnownAttribute(attrName)) {
00114 renderer()->setNeedsLayout(true);
00115
00116 if (isURIAttribute)
00117 m_imageLoader.updateFromElement();
00118 }
00119 }
00120
00121 bool SVGImageElement::hasRelativeValues() const
00122 {
00123 return (x().isRelative() || width().isRelative() ||
00124 y().isRelative() || height().isRelative());
00125 }
00126
00127 RenderObject* SVGImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
00128 {
00129 return new (arena) RenderSVGImage(this);
00130 }
00131
00132 bool SVGImageElement::haveLoadedRequiredResources()
00133 {
00134 return !externalResourcesRequiredBaseValue() || m_imageLoader.haveFiredLoadEvent();
00135 }
00136
00137 void SVGImageElement::attach()
00138 {
00139 SVGStyledTransformableElement::attach();
00140 m_imageLoader.updateFromElement();
00141 if (RenderSVGImage* imageObj = static_cast<RenderSVGImage*>(renderer()))
00142 imageObj->setCachedImage(m_imageLoader.image());
00143 }
00144
00145 void SVGImageElement::getSubresourceAttributeStrings(Vector<String>& urls) const
00146 {
00147 urls.append(href());
00148 }
00149
00150 }
00151
00152 #endif // ENABLE(SVG)