SVGImageElement.cpp [plain text]
#include "config.h"
#if SVG_SUPPORT
#include "SVGImageElement.h"
#include "Attr.h"
#include "CSSPropertyNames.h"
#include "KCanvasRenderingStyle.h"
#include "RenderSVGImage.h"
#include "SVGAnimatedLength.h"
#include "SVGAnimatedPreserveAspectRatio.h"
#include "SVGAnimatedString.h"
#include "SVGDocument.h"
#include "SVGHelper.h"
#include "SVGNames.h"
#include "SVGSVGElement.h"
#include "XLinkNames.h"
#include <kcanvas/RenderSVGContainer.h>
#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/KCanvasImage.h>
#include <kcanvas/KCanvasPath.h>
#include <wtf/Assertions.h>
using namespace WebCore;
SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document *doc)
: SVGStyledTransformableElement(tagName, doc), SVGTests(), SVGLangSpace(), SVGExternalResourcesRequired(), SVGURIReference(), m_imageLoader(this)
{
}
SVGImageElement::~SVGImageElement()
{
}
SVGAnimatedLength *SVGImageElement::x() const
{
return lazy_create<SVGAnimatedLength>(m_x, this, LM_WIDTH, viewportElement());
}
SVGAnimatedLength *SVGImageElement::y() const
{
return lazy_create<SVGAnimatedLength>(m_y, this, LM_HEIGHT, viewportElement());
}
SVGAnimatedLength *SVGImageElement::width() const
{
return lazy_create<SVGAnimatedLength>(m_width, this, LM_WIDTH, viewportElement());
}
SVGAnimatedLength *SVGImageElement::height() const
{
return lazy_create<SVGAnimatedLength>(m_height, this, LM_HEIGHT, viewportElement());
}
SVGAnimatedPreserveAspectRatio *SVGImageElement::preserveAspectRatio() const
{
return lazy_create<SVGAnimatedPreserveAspectRatio>(m_preserveAspectRatio, this);
}
void SVGImageElement::parseMappedAttribute(MappedAttribute *attr)
{
const AtomicString& value = attr->value();
if (attr->name() == SVGNames::xAttr)
x()->baseVal()->setValueAsString(value.impl());
else if (attr->name() == SVGNames::yAttr)
y()->baseVal()->setValueAsString(value.impl());
else if (attr->name() == SVGNames::preserveAspectRatioAttr)
preserveAspectRatio()->baseVal()->parsePreserveAspectRatio(value.impl());
else if (attr->name() == SVGNames::widthAttr) {
width()->baseVal()->setValueAsString(value.impl());
addCSSProperty(attr, CSS_PROP_WIDTH, value);
} else if (attr->name() == SVGNames::heightAttr) {
height()->baseVal()->setValueAsString(value.impl());
addCSSProperty(attr, CSS_PROP_HEIGHT, value);
} else {
if (SVGTests::parseMappedAttribute(attr))
return;
if (SVGLangSpace::parseMappedAttribute(attr))
return;
if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
return;
if (SVGURIReference::parseMappedAttribute(attr)) {
if (attr->name().matches(XLinkNames::hrefAttr))
m_imageLoader.updateFromElement();
return;
}
SVGStyledTransformableElement::parseMappedAttribute(attr);
}
}
RenderObject *SVGImageElement::createRenderer(RenderArena *arena, RenderStyle *style)
{
return new (arena) RenderSVGImage(this);
}
void SVGImageElement::attach()
{
SVGStyledTransformableElement::attach();
if (RenderSVGImage* imageObj = static_cast<RenderSVGImage*>(renderer()))
imageObj->setCachedImage(m_imageLoader.image());
}
#endif // SVG_SUPPORT