29#include "CSSPropertyNames.h"
30#include "RenderSVGImage.h"
40SVGImageElement::SVGImageElement(
const QualifiedName& tagName, Document* doc)
41 : SVGStyledTransformableElement(tagName, doc)
44 , SVGExternalResourcesRequired()
46 , m_x(this, LengthModeWidth)
47 , m_y(this, LengthModeHeight)
48 , m_width(this, LengthModeWidth)
49 , m_height(this, LengthModeHeight)
50 , m_preserveAspectRatio(SVGPreserveAspectRatio::
create())
55SVGImageElement::~SVGImageElement()
59ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length,
X, x, SVGNames::xAttr, m_x)
60ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
61ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
62ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
63ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
65void SVGImageElement::parseMappedAttribute(MappedAttribute *attr)
67 if (attr->name() == SVGNames::xAttr)
68 setXBaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
69 else if (attr->name() == SVGNames::yAttr)
70 setYBaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
71 else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
72 const UChar* c = attr->value().characters();
73 const UChar*
end = c + attr->value().length();
74 preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
75 }
else if (attr->name() == SVGNames::widthAttr) {
76 setWidthBaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
77 addCSSProperty(attr, CSSPropertyWidth, attr->value());
78 if (width().value() < 0.0)
79 document()->accessSVGExtensions()->reportError(
"A negative value for image attribute <width> is not allowed");
80 }
else if (attr->name() == SVGNames::heightAttr) {
81 setHeightBaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
82 addCSSProperty(attr, CSSPropertyHeight, attr->value());
83 if (height().value() < 0.0)
84 document()->accessSVGExtensions()->reportError(
"A negative value for image attribute <height> is not allowed");
86 if (SVGTests::parseMappedAttribute(attr))
88 if (SVGLangSpace::parseMappedAttribute(attr))
90 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
92 if (SVGURIReference::parseMappedAttribute(attr))
94 SVGStyledTransformableElement::parseMappedAttribute(attr);
98void SVGImageElement::svgAttributeChanged(
const QualifiedName& attrName)
100 SVGStyledTransformableElement::svgAttributeChanged(attrName);
105 bool isURIAttribute = SVGURIReference::isKnownAttribute(attrName);
107 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
108 attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
109 SVGTests::isKnownAttribute(attrName) ||
110 SVGLangSpace::isKnownAttribute(attrName) ||
111 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
113 SVGStyledTransformableElement::isKnownAttribute(attrName)) {
114 renderer()->setNeedsLayout(
true);
117 m_imageLoader.updateFromElement();
121bool SVGImageElement::hasRelativeValues()
const
123 return (x().isRelative() || width().isRelative() ||
124 y().isRelative() || height().isRelative());
127RenderObject* SVGImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
129 return new (arena) RenderSVGImage(
this);
132bool SVGImageElement::haveLoadedRequiredResources()
134 return !externalResourcesRequiredBaseValue() || m_imageLoader.haveFiredLoadEvent();
137void SVGImageElement::attach()
139 SVGStyledTransformableElement::attach();
140 m_imageLoader.updateFromElement();
141 if (RenderSVGImage* imageObj =
static_cast<RenderSVGImage*
>(renderer()))
142 imageObj->setCachedImage(m_imageLoader.image());
145void SVGImageElement::getSubresourceAttributeStrings(Vector<String>& urls)
const
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)