#include "config.h"
#include "SVGAElement.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 "PlatformMouseEvent.h"
#include "RenderSVGInline.h"
#include "RenderSVGText.h"
#include "RenderSVGTransformableContainer.h"
#include "ResourceRequest.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(SVGGraphicsElement)
END_REGISTER_ANIMATED_PROPERTIES
inline SVGAElement::SVGAElement(const QualifiedName& tagName, Document& document)
: SVGGraphicsElement(tagName, document)
{
ASSERT(hasTagName(SVGNames::aTag));
registerAnimatedPropertiesForSVGAElement();
}
Ref<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 SVGElement::title();
}
void SVGAElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == SVGNames::targetAttr) {
setSVGTargetBaseValue(value);
return;
}
SVGGraphicsElement::parseAttribute(name, value);
SVGURIReference::parseAttribute(name, value);
SVGExternalResourcesRequired::parseAttribute(name, value);
}
void SVGAElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (SVGURIReference::isKnownAttribute(attrName)) {
bool wasLink = isLink();
setIsLink(!href().isNull() && !shouldProhibitLinks(this));
if (wasLink != isLink()) {
InstanceInvalidationGuard guard(*this);
setNeedsStyleRecalc();
}
}
SVGGraphicsElement::svgAttributeChanged(attrName);
}
RenderPtr<RenderElement> SVGAElement::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
{
if (parentNode() && parentNode()->isSVGElement() && downcast<SVGElement>(*parentNode()).isTextContent())
return createRenderer<RenderSVGInline>(*this, WTF::move(style));
return createRenderer<RenderSVGTransformableContainer>(*this, WTF::move(style));
}
void SVGAElement::defaultEventHandler(Event* event)
{
if (isLink()) {
if (focused() && isEnterKeyKeydownEvent(event)) {
event->setDefaultHandled();
dispatchSimulatedClick(event);
return;
}
if (MouseEvent::canTriggerActivationBehavior(*event)) {
String url = stripLeadingAndTrailingHTMLSpaces(href());
if (url[0] == '#') {
Element* targetElement = treeScope().getElementById(url.substringSharingImpl(1));
if (is<SVGSMILElement>(targetElement)) {
downcast<SVGSMILElement>(*targetElement).beginByLinkActivation();
event->setDefaultHandled();
return;
}
if (targetElement && !targetElement->hasTagName(SVGNames::viewTag))
return;
}
String target = this->target();
if (target.isEmpty() && fastGetAttribute(XLinkNames::showAttr) == "new")
target = "_blank";
event->setDefaultHandled();
Frame* frame = document().frame();
if (!frame)
return;
frame->loader().urlSelected(document().completeURL(url), target, event, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate());
return;
}
}
SVGGraphicsElement::defaultEventHandler(event);
}
short SVGAElement::tabIndex() const
{
return Element::tabIndex();
}
bool SVGAElement::supportsFocus() const
{
if (hasEditableStyle())
return SVGGraphicsElement::supportsFocus();
return isLink() || Element::supportsFocus();
}
bool SVGAElement::isFocusable() const
{
if (renderer() && renderer()->absoluteClippedOverflowRect().isEmpty())
return false;
return SVGElement::isFocusable();
}
bool SVGAElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name().localName() == XLinkNames::hrefAttr || SVGGraphicsElement::isURLAttribute(attribute);
}
bool SVGAElement::isMouseFocusable() const
{
if (isLink())
return Element::supportsFocus();
return SVGElement::isMouseFocusable();
}
bool SVGAElement::isKeyboardFocusable(KeyboardEvent* event) const
{
if (isFocusable() && Element::supportsFocus())
return SVGElement::isKeyboardFocusable(event);
if (isLink())
return document().frame()->eventHandler().tabsToLinks(event);
return SVGElement::isKeyboardFocusable(event);
}
bool SVGAElement::canStartSelection() const
{
if (!isLink())
return SVGElement::canStartSelection();
return hasEditableStyle();
}
bool SVGAElement::childShouldCreateRenderer(const Node& child) const
{
if (child.hasTagName(SVGNames::aTag))
return false;
if (parentElement() && parentElement()->isSVGElement())
return parentElement()->childShouldCreateRenderer(child);
return SVGElement::childShouldCreateRenderer(child);
}
bool SVGAElement::willRespondToMouseClickEvents()
{
return isLink() || SVGGraphicsElement::willRespondToMouseClickEvents();
}
}