#include "config.h"
#if SVG_SUPPORT
#include "SVGElement.h"
#include "Attr.h"
#include "Document.h"
#include "EventListener.h"
#include "EventNames.h"
#include "HTMLNames.h"
#include "PlatformString.h"
#include "SVGDOMImplementation.h"
#include "SVGDocumentExtensions.h"
#include "SVGNames.h"
#include "SVGSVGElement.h"
#include "XMLNames.h"
#include "ksvg.h"
namespace WebCore {
using namespace HTMLNames;
using namespace EventNames;
SVGElement::SVGElement(const QualifiedName& tagName, Document* doc)
: StyledElement(tagName, doc)
, m_closed(false)
{
}
SVGElement::~SVGElement()
{
}
bool SVGElement::isSupported(StringImpl* feature, StringImpl* version) const
{
if (SVGDOMImplementation::instance()->hasFeature(feature, version))
return true;
return DOMImplementation::instance()->hasFeature(feature, version);
}
String SVGElement::id() const
{
return getAttribute(idAttr);
}
void SVGElement::setId(const String& value)
{
setAttribute(idAttr, value);
}
String SVGElement::xmlbase() const
{
return getAttribute(XMLNames::baseAttr);
}
void SVGElement::setXmlbase(const String& value)
{
setAttribute(XMLNames::baseAttr, value);
}
SVGSVGElement* SVGElement::ownerSVGElement() const
{
Node *n = parentNode();
while(n) {
if (n->nodeType() == ELEMENT_NODE && n->hasTagName(SVGNames::svgTag))
return static_cast<SVGSVGElement*>(n);
n = n->parentNode();
}
return 0;
}
SVGElement* SVGElement::viewportElement() const
{
Node *n = parentNode();
while (n) {
if (n->isElementNode() &&
(n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::imageTag) || n->hasTagName(SVGNames::symbolTag)))
return static_cast<SVGElement*>(n);
n = n->parentNode();
}
return 0;
}
AtomicString SVGElement::tryGetAttribute(const String& name, AtomicString defaultVal) const
{
if (hasAttribute(name))
return getAttribute(name);
return defaultVal;
}
AtomicString SVGElement::tryGetAttributeNS(const String& namespaceURI, const String& localName, AtomicString defaultVal) const
{
if (hasAttributeNS(namespaceURI, localName))
return getAttributeNS(namespaceURI, localName);
return defaultVal;
}
void SVGElement::addSVGEventListener(const AtomicString& eventType, const Attribute* attr)
{
Element::setHTMLEventListener(eventType, document()->accessSVGExtensions()->
createSVGEventListener(attr->localName().domString(), attr->value(), this));
}
void SVGElement::parseMappedAttribute(MappedAttribute *attr)
{
if (attr->name() == onclickAttr)
addSVGEventListener(clickEvent, attr);
else if (attr->name() == onmousedownAttr)
addSVGEventListener(mousedownEvent, attr);
else if (attr->name() == onmousemoveAttr)
addSVGEventListener(mousemoveEvent, attr);
else if (attr->name() == onmouseoutAttr)
addSVGEventListener(mouseoutEvent, attr);
else if (attr->name() == onmouseoverAttr)
addSVGEventListener(mouseoverEvent, attr);
else if (attr->name() == onmouseupAttr)
addSVGEventListener(mouseupEvent, attr);
else if (attr->name() == onfocusAttr)
addSVGEventListener(DOMFocusInEvent, attr);
else if (attr->name() == onblurAttr)
addSVGEventListener(DOMFocusOutEvent, attr);
else
StyledElement::parseMappedAttribute(attr);
}
bool SVGElement::childShouldCreateRenderer(Node *child) const
{
if (child->isSVGElement())
return static_cast<SVGElement*>(child)->isValid();
return false;
}
}
#endif // SVG_SUPPORT