This source file includes following definitions.
- m_svgTarget
- create
- title
- isSupportedAttribute
- parseAttribute
- svgAttributeChanged
- createRenderer
- defaultEventHandler
- supportsFocus
- isURLAttribute
- isMouseFocusable
- isKeyboardFocusable
- willRespondToMouseClickEvents
#include "config.h"
#include "core/svg/SVGAElement.h"
#include "SVGNames.h"
#include "XLinkNames.h"
#include "core/dom/Attr.h"
#include "core/dom/Attribute.h"
#include "core/dom/Document.h"
#include "core/events/KeyboardEvent.h"
#include "core/events/MouseEvent.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLAnchorElement.h"
#include "core/html/HTMLFormElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/loader/FrameLoadRequest.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/FrameLoaderTypes.h"
#include "core/page/Chrome.h"
#include "core/page/ChromeClient.h"
#include "core/page/Page.h"
#include "core/rendering/svg/RenderSVGInline.h"
#include "core/rendering/svg/RenderSVGText.h"
#include "core/rendering/svg/RenderSVGTransformableContainer.h"
#include "core/svg/SVGElementInstance.h"
#include "core/svg/animation/SVGSMILElement.h"
#include "platform/PlatformMouseEvent.h"
#include "platform/network/ResourceRequest.h"
namespace WebCore {
using namespace HTMLNames;
inline SVGAElement::SVGAElement(Document& document)
: SVGGraphicsElement(SVGNames::aTag, document)
, SVGURIReference(this)
, m_svgTarget(SVGAnimatedString::create(this, SVGNames::targetAttr, SVGString::create()))
{
ScriptWrappable::init(this);
addToPropertyMap(m_svgTarget);
}
PassRefPtr<SVGAElement> SVGAElement::create(Document& document)
{
return adoptRef(new SVGAElement(document));
}
String SVGAElement::title() const
{
const AtomicString& title = fastGetAttribute(XLinkNames::titleAttr);
if (!title.isEmpty())
return title;
return SVGElement::title();
}
bool SVGAElement::isSupportedAttribute(const QualifiedName& attrName)
{
DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
if (supportedAttributes.isEmpty()) {
SVGURIReference::addSupportedAttributes(supportedAttributes);
supportedAttributes.add(SVGNames::targetAttr);
}
return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
}
void SVGAElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (!isSupportedAttribute(name)) {
SVGGraphicsElement::parseAttribute(name, value);
return;
}
SVGParsingError parseError = NoError;
if (name == SVGNames::targetAttr) {
m_svgTarget->setBaseValueAsString(value, parseError);
} else if (SVGURIReference::parseAttribute(name, value, parseError)) {
} else {
ASSERT_NOT_REACHED();
}
reportAttributeParsingError(parseError, name, value);
}
void SVGAElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (!isSupportedAttribute(attrName)) {
SVGGraphicsElement::svgAttributeChanged(attrName);
return;
}
SVGElementInstance::InvalidationGuard invalidationGuard(this);
if (SVGURIReference::isKnownAttribute(attrName)) {
bool wasLink = isLink();
setIsLink(!hrefString().isNull());
if (wasLink != isLink())
setNeedsStyleRecalc(SubtreeStyleChange);
}
}
RenderObject* SVGAElement::createRenderer(RenderStyle*)
{
if (parentNode() && parentNode()->isSVGElement() && toSVGElement(parentNode())->isTextContent())
return new RenderSVGInline(this);
return new RenderSVGTransformableContainer(this);
}
void SVGAElement::defaultEventHandler(Event* event)
{
if (isLink()) {
if (focused() && isEnterKeyKeydownEvent(event)) {
event->setDefaultHandled();
dispatchSimulatedClick(event);
return;
}
if (isLinkClick(event)) {
String url = stripLeadingAndTrailingHTMLSpaces(hrefString());
if (url[0] == '#') {
Element* targetElement = treeScope().getElementById(AtomicString(url.substring(1)));
if (targetElement && isSVGSMILElement(*targetElement)) {
toSVGSMILElement(targetElement)->beginByLinkActivation();
event->setDefaultHandled();
return;
}
if (targetElement && !isSVGViewElement(*targetElement))
return;
}
AtomicString target(m_svgTarget->currentValue()->value());
if (target.isEmpty() && fastGetAttribute(XLinkNames::showAttr) == "new")
target = AtomicString("_blank", AtomicString::ConstructFromLiteral);
event->setDefaultHandled();
LocalFrame* frame = document().frame();
if (!frame)
return;
FrameLoadRequest frameRequest(&document(), ResourceRequest(document().completeURL(url)), target);
frameRequest.setTriggeringEvent(event);
frame->loader().load(frameRequest);
return;
}
}
SVGGraphicsElement::defaultEventHandler(event);
}
bool SVGAElement::supportsFocus() const
{
if (rendererIsEditable())
return SVGGraphicsElement::supportsFocus();
return true;
}
bool SVGAElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name().localName() == hrefAttr || SVGGraphicsElement::isURLAttribute(attribute);
}
bool SVGAElement::isMouseFocusable() const
{
return false;
}
bool SVGAElement::isKeyboardFocusable() const
{
if (!isFocusable())
return false;
if (Page* page = document().page())
return page->chrome().client().tabsToLinks();
return false;
}
bool SVGAElement::willRespondToMouseClickEvents()
{
return isLink() || SVGGraphicsElement::willRespondToMouseClickEvents();
}
}