#include "config.h"
#if ENABLE(SVG)
#include "SVGAElement.h"
#include "Attr.h"
#include "Attribute.h"
#include "Document.h"
#include "EventHandler.h"
#include "EventNames.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderTypes.h"
#include "HTMLAnchorElement.h"
#include "HTMLParserIdioms.h"
#include "KeyboardEvent.h"
#include "MouseEvent.h"
#include "NodeRenderingContext.h"
#include "PlatformMouseEvent.h"
#include "RenderSVGInline.h"
#include "RenderSVGText.h"
#include "RenderSVGTransformableContainer.h"
#include "ResourceRequest.h"
#include "SVGElementInstance.h"
#include "SVGNames.h"
#include "SVGSMILElement.h"
#include "XLinkNames.h"
namespace WebCore {
DEFINE_ANIMATED_STRING(SVGAElement, SVGNames::targetAttr, SVGTarget, svgTarget)
DEFINE_ANIMATED_STRING(SVGAElement, XLinkNames::hrefAttr, Href, href)
DEFINE_ANIMATED_BOOLEAN(SVGAElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGAElement)
REGISTER_LOCAL_ANIMATED_PROPERTY(svgTarget)
REGISTER_LOCAL_ANIMATED_PROPERTY(href)
REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledTransformableElement)
REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests)
END_REGISTER_ANIMATED_PROPERTIES
inline SVGAElement::SVGAElement(const QualifiedName& tagName, Document* document)
: SVGStyledTransformableElement(tagName, document)
{
ASSERT(hasTagName(SVGNames::aTag));
registerAnimatedPropertiesForSVGAElement();
}
PassRefPtr<SVGAElement> SVGAElement::create(const QualifiedName& tagName, Document* document)
{
return adoptRef(new SVGAElement(tagName, document));
}
String SVGAElement::title() const
{
const AtomicString& title = fastGetAttribute(XLinkNames::titleAttr);
if (!title.isEmpty())
return title;
return SVGStyledElement::title();
}
bool SVGAElement::isSupportedAttribute(const QualifiedName& attrName)
{
DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
if (supportedAttributes.isEmpty()) {
SVGURIReference::addSupportedAttributes(supportedAttributes);
SVGTests::addSupportedAttributes(supportedAttributes);
SVGLangSpace::addSupportedAttributes(supportedAttributes);
SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
supportedAttributes.add(SVGNames::targetAttr);
}
return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
}
void SVGAElement::parseAttribute(Attribute* attr)
{
if (!isSupportedAttribute(attr->name())) {
SVGStyledTransformableElement::parseAttribute(attr);
return;
}
if (attr->name() == SVGNames::targetAttr) {
setSVGTargetBaseValue(attr->value());
return;
}
if (SVGURIReference::parseAttribute(attr))
return;
if (SVGTests::parseAttribute(attr))
return;
if (SVGLangSpace::parseAttribute(attr))
return;
if (SVGExternalResourcesRequired::parseAttribute(attr))
return;
ASSERT_NOT_REACHED();
}
void SVGAElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (!isSupportedAttribute(attrName)) {
SVGStyledTransformableElement::svgAttributeChanged(attrName);
return;
}
SVGElementInstance::InvalidationGuard invalidationGuard(this);
if (SVGURIReference::isKnownAttribute(attrName)) {
bool wasLink = isLink();
setIsLink(!href().isNull());
if (wasLink != isLink())
setNeedsStyleRecalc();
}
}
RenderObject* SVGAElement::createRenderer(RenderArena* arena, RenderStyle*)
{
if (parentNode() && parentNode()->isSVGElement() && static_cast<SVGElement*>(parentNode())->isTextContent())
return new (arena) RenderSVGInline(this);
return new (arena) RenderSVGTransformableContainer(this);
}
void SVGAElement::defaultEventHandler(Event* event)
{
if (isLink()) {
if (focused() && isEnterKeyKeydownEvent(event)) {
event->setDefaultHandled();
dispatchSimulatedClick(event);
return;
}
if (isLinkClick(event)) {
String url = stripLeadingAndTrailingHTMLSpaces(href());
if (url[0] == '#') {
Element* targetElement = treeScope()->getElementById(url.substring(1));
if (SVGSMILElement::isSMILElement(targetElement)) {
static_cast<SVGSMILElement*>(targetElement)->beginByLinkActivation();
event->setDefaultHandled();
return;
}
if (targetElement && !targetElement->hasTagName(SVGNames::viewTag))
return;
}
String target = isMiddleMouseButtonEvent(event) ? "_blank" : this->target();
if (target.isEmpty())
target = (fastGetAttribute(XLinkNames::showAttr) == "new") ? "_blank" : "_self";
handleLinkClick(event, document(), url, target);
return;
}
}
SVGStyledTransformableElement::defaultEventHandler(event);
}
bool SVGAElement::supportsFocus() const
{
if (rendererIsEditable())
return SVGStyledTransformableElement::supportsFocus();
return true;
}
bool SVGAElement::isFocusable() const
{
if (renderer() && renderer()->absoluteClippedOverflowRect().isEmpty())
return false;
return SVGElement::isFocusable();
}
bool SVGAElement::isMouseFocusable() const
{
return false;
}
bool SVGAElement::isKeyboardFocusable(KeyboardEvent* event) const
{
if (!isFocusable())
return false;
if (!document()->frame())
return false;
return document()->frame()->eventHandler()->tabsToLinks(event);
}
bool SVGAElement::childShouldCreateRenderer(const NodeRenderingContext& childContext) const
{
if (childContext.node()->hasTagName(SVGNames::aTag))
return false;
if (parentNode() && parentNode()->isSVGElement())
return parentNode()->childShouldCreateRenderer(childContext);
return SVGElement::childShouldCreateRenderer(childContext);
}
void SVGAElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
if (changedByParser || !renderer())
return;
if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(renderer()))
textRenderer->invalidateTextPositioningElements();
}
}
#endif // ENABLE(SVG)