SVGStyledElement.cpp [plain text]
#include "config.h"
#if SVG_SUPPORT
#include "SVGStyledElement.h"
#include "Attr.h"
#include "Document.h"
#include "KCanvasCreator.h"
#include "KCanvasRenderingStyle.h"
#include "KRenderingDevice.h"
#include "PlatformString.h"
#include "RenderView.h"
#include "RenderPath.h"
#include "SVGAnimatedString.h"
#include "SVGDOMImplementation.h"
#include "SVGElement.h"
#include "SVGHelper.h"
#include "SVGMatrix.h"
#include "SVGNames.h"
#include "SVGRenderStyle.h"
#include "SVGSVGElement.h"
#include "ksvg.h"
#include "ksvgcssproperties.h"
#include <wtf/Assertions.h>
namespace WebCore {
int getPropertyID(const char* str, int len);
using namespace SVGNames;
SVGStyledElement::SVGStyledElement(const QualifiedName& tagName, Document* doc)
: SVGElement(tagName, doc)
, m_updateVectorial(false)
{
}
SVGStyledElement::~SVGStyledElement()
{
}
SVGAnimatedString* SVGStyledElement::className() const
{
return lazy_create(m_className, (SVGStyledElement*)0); }
RenderObject* SVGStyledElement::createRenderer(RenderArena* arena, RenderStyle* style)
{
RefPtr<KCanvasPath> pathData = toPathData();
if (!pathData)
return 0;
return renderingDevice()->createItem(arena, style, this, pathData.get());
}
void SVGStyledElement::parseMappedAttribute(MappedAttribute* attr)
{
const String& value = attr->value();
DeprecatedString qProp = attr->name().localName().deprecatedString();
int propId = getPropertyID(qProp.ascii(), qProp.length());
if (propId == 0)
propId = SVG::getSVGCSSPropertyID(qProp.ascii(), qProp.length());
if (propId > 0) {
addCSSProperty(attr, propId, value);
setChanged();
return;
}
SVGElement::parseMappedAttribute(attr);
}
void SVGStyledElement::notifyAttributeChange() const
{
if (!ownerDocument()->parsing()) {
const_cast<SVGStyledElement*>(this)->m_updateVectorial = true;
const_cast<SVGStyledElement*>(this)->updateCanvasItem();
}
}
void SVGStyledElement::attributeChanged(Attribute* attr, bool preserveDecls)
{
SVGElement::attributeChanged(attr, preserveDecls);
notifyAttributeChange();
}
RenderView* SVGStyledElement::view() const
{
return static_cast<RenderView*>(document()->renderer());
}
void SVGStyledElement::updateCanvasItem()
{
if (!m_updateVectorial || !renderer() || !renderer()->isRenderPath())
return;
RenderPath* renderPath = static_cast<RenderPath*>(renderer());
bool renderSection = false;
SVGElement* parentElement = svg_dynamic_cast(parentNode());
if (parentElement && parentElement->renderer() && parentElement->isStyled()
&& parentElement->childShouldCreateRenderer(this))
renderSection = true;
renderPath->setPath(toPathData());
if (renderSection)
renderPath->setNeedsLayout(true);
m_updateVectorial = false;
}
const SVGStyledElement* SVGStyledElement::pushAttributeContext(const SVGStyledElement*)
{
if (view())
static_cast<RenderPath*>(renderer())->setPath(toPathData());
return 0;
}
}
#endif // SVG_SUPPORT