SVGFilterPrimitiveStandardAttributes.cpp [plain text]
#include "config.h"
#if SVG_SUPPORT
#include "Attr.h"
#include <wtf/Assertions.h>
#include "ksvg.h"
#include "SVGNames.h"
#include "SVGFilterPrimitiveStandardAttributes.h"
#include "SVGAnimatedEnumeration.h"
#include "SVGAnimatedString.h"
#include "SVGAnimatedLength.h"
#include "SVGStyledElement.h"
#include "SVGFilterElement.h"
#include <kcanvas/KCanvasFilters.h>
using namespace WebCore;
SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document *doc)
: SVGStyledElement(tagName, doc)
{
}
SVGFilterPrimitiveStandardAttributes::~SVGFilterPrimitiveStandardAttributes()
{
}
SVGAnimatedLength *SVGFilterPrimitiveStandardAttributes::x() const
{
return lazy_create<SVGAnimatedLength>(m_x, this, LM_WIDTH);
}
SVGAnimatedLength *SVGFilterPrimitiveStandardAttributes::y() const
{
return lazy_create<SVGAnimatedLength>(m_y, this, LM_HEIGHT);
}
SVGAnimatedLength *SVGFilterPrimitiveStandardAttributes::width() const
{
if (!m_width) {
lazy_create<SVGAnimatedLength>(m_width, this, LM_WIDTH);
m_width->baseVal()->setValueAsString(String("100%").impl());
}
return m_width.get();
}
SVGAnimatedLength *SVGFilterPrimitiveStandardAttributes::height() const
{
if (!m_height) {
lazy_create<SVGAnimatedLength>(m_height, this, LM_HEIGHT);
m_height->baseVal()->setValueAsString(String("100%").impl());
}
return m_height.get();
}
SVGAnimatedString *SVGFilterPrimitiveStandardAttributes::result() const
{
return lazy_create<SVGAnimatedString>(m_result, this);
}
void SVGFilterPrimitiveStandardAttributes::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::widthAttr)
width()->baseVal()->setValueAsString(value.impl());
else if (attr->name() == SVGNames::heightAttr)
height()->baseVal()->setValueAsString(value.impl());
else if (attr->name() == SVGNames::resultAttr)
result()->setBaseVal(value.impl());
else
return SVGStyledElement::parseMappedAttribute(attr);
}
void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(KCanvasFilterEffect *filterEffect) const
{
ASSERT(filterEffect);
if (!filterEffect)
return;
bool bbox = false;
if(parentNode() && parentNode()->hasTagName(SVGNames::filterTag))
bbox = static_cast<SVGFilterElement *>(parentNode())->primitiveUnits()->baseVal() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
x()->baseVal()->setBboxRelative(bbox);
y()->baseVal()->setBboxRelative(bbox);
width()->baseVal()->setBboxRelative(bbox);
height()->baseVal()->setBboxRelative(bbox);
float _x = x()->baseVal()->value(), _y = y()->baseVal()->value();
float _width = width()->baseVal()->value(), _height = height()->baseVal()->value();
if(bbox)
filterEffect->setSubRegion(FloatRect(_x * 100.f, _y * 100.f, _width * 100.f, _height * 100.f));
else
filterEffect->setSubRegion(FloatRect(_x, _y, _width, _height));
filterEffect->setResult(String(result()->baseVal()).deprecatedString());
}
#endif // SVG_SUPPORT