summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLAnchorElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/html/HTMLAnchorElement.cpp')
-rw-r--r--Source/WebCore/html/HTMLAnchorElement.cpp97
1 files changed, 47 insertions, 50 deletions
diff --git a/Source/WebCore/html/HTMLAnchorElement.cpp b/Source/WebCore/html/HTMLAnchorElement.cpp
index 5bd7e58b4..053e57f7f 100644
--- a/Source/WebCore/html/HTMLAnchorElement.cpp
+++ b/Source/WebCore/html/HTMLAnchorElement.cpp
@@ -24,8 +24,8 @@
#include "config.h"
#include "HTMLAnchorElement.h"
+#include "Attribute.h"
#include "DNS.h"
-#include "ElementIterator.h"
#include "EventHandler.h"
#include "EventNames.h"
#include "Frame.h"
@@ -33,14 +33,12 @@
#include "FrameLoaderClient.h"
#include "FrameLoaderTypes.h"
#include "FrameSelection.h"
-#include "HTMLCanvasElement.h"
#include "HTMLImageElement.h"
#include "HTMLParserIdioms.h"
#include "KeyboardEvent.h"
#include "MouseEvent.h"
#include "PingLoader.h"
#include "PlatformMouseEvent.h"
-#include "RelList.h"
#include "RenderImage.h"
#include "ResourceRequest.h"
#include "SVGImage.h"
@@ -62,14 +60,14 @@ HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& doc
{
}
-Ref<HTMLAnchorElement> HTMLAnchorElement::create(Document& document)
+PassRefPtr<HTMLAnchorElement> HTMLAnchorElement::create(Document& document)
{
- return adoptRef(*new HTMLAnchorElement(aTag, document));
+ return adoptRef(new HTMLAnchorElement(aTag, document));
}
-Ref<HTMLAnchorElement> HTMLAnchorElement::create(const QualifiedName& tagName, Document& document)
+PassRefPtr<HTMLAnchorElement> HTMLAnchorElement::create(const QualifiedName& tagName, Document& document)
{
- return adoptRef(*new HTMLAnchorElement(tagName, document));
+ return adoptRef(new HTMLAnchorElement(tagName, document));
}
HTMLAnchorElement::~HTMLAnchorElement()
@@ -144,7 +142,7 @@ bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const
if (!document().frame()->eventHandler().tabsToLinks(event))
return false;
- if (!renderer() && ancestorsOfType<HTMLCanvasElement>(*this).first())
+ if (isInCanvasSubtree())
return true;
return hasNonEmptyBox(renderBoxModelObject());
@@ -152,26 +150,25 @@ bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const
static void appendServerMapMousePosition(StringBuilder& url, Event* event)
{
- ASSERT(event);
- if (!is<MouseEvent>(*event))
+ if (!event->isMouseEvent())
return;
ASSERT(event->target());
Node* target = event->target()->toNode();
ASSERT(target);
- if (!is<HTMLImageElement>(*target))
+ if (!isHTMLImageElement(target))
return;
- HTMLImageElement& imageElement = downcast<HTMLImageElement>(*target);
- if (!imageElement.isServerMap())
+ HTMLImageElement* imageElement = toHTMLImageElement(target);
+ if (!imageElement || !imageElement->isServerMap())
return;
- if (!is<RenderImage>(imageElement.renderer()))
+ if (!imageElement->renderer() || !imageElement->renderer()->isRenderImage())
return;
- auto& renderer = downcast<RenderImage>(*imageElement.renderer());
+ RenderImage* renderer = toRenderImage(imageElement->renderer());
// FIXME: This should probably pass true for useTransforms.
- FloatPoint absolutePosition = renderer.absoluteToLocal(FloatPoint(downcast<MouseEvent>(*event).pageX(), downcast<MouseEvent>(*event).pageY()));
+ FloatPoint absolutePosition = renderer->absoluteToLocal(FloatPoint(static_cast<MouseEvent*>(event)->pageX(), static_cast<MouseEvent*>(event)->pageY()));
int x = absolutePosition.x();
int y = absolutePosition.y();
url.append('?');
@@ -189,7 +186,7 @@ void HTMLAnchorElement::defaultEventHandler(Event* event)
return;
}
- if (MouseEvent::canTriggerActivationBehavior(*event) && treatLinkAsLiveForEventType(eventType(event))) {
+ if (isLinkClick(event) && treatLinkAsLiveForEventType(eventType(event))) {
handleClick(event);
return;
}
@@ -197,9 +194,9 @@ void HTMLAnchorElement::defaultEventHandler(Event* event)
if (hasEditableStyle()) {
// This keeps track of the editable block that the selection was in (if it was in one) just before the link was clicked
// for the LiveWhenNotFocused editable link behavior
- if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(*event) && downcast<MouseEvent>(*event).button() != RightButton && document().frame()) {
- setRootEditableElementForSelectionOnMouseDown(document().frame()->selection().selection().rootEditableElement());
- m_wasShiftKeyDownOnMouseDown = downcast<MouseEvent>(*event).shiftKey();
+ if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() != RightButton && document().frame()) {
+ setRootEditableElementForSelectionOnMouseDown(document().frame()->selection().rootEditableElement());
+ m_wasShiftKeyDownOnMouseDown = static_cast<MouseEvent*>(event)->shiftKey();
} else if (event->type() == eventNames().mouseoverEvent) {
// These are cleared on mouseover and not mouseout because their values are needed for drag events,
// but drag events happen after mouse out events.
@@ -231,7 +228,7 @@ void HTMLAnchorElement::setActive(bool down, bool pause)
// Don't set the link to be active if the current selection is in the same editable block as
// this link
case EditableLinkLiveWhenNotFocused:
- if (down && document().frame() && document().frame()->selection().selection().rootEditableElement() == rootEditableElement())
+ if (down && document().frame() && document().frame()->selection().rootEditableElement() == rootEditableElement())
return;
break;
@@ -250,7 +247,7 @@ void HTMLAnchorElement::parseAttribute(const QualifiedName& name, const AtomicSt
bool wasLink = isLink();
setIsLink(!value.isNull() && !shouldProhibitLinks(this));
if (wasLink != isLink())
- setNeedsStyleRecalc();
+ didAffectSelector(AffectedSelectorLink | AffectedSelectorVisited | AffectedSelectorEnabled);
if (isLink()) {
String parsedURL = stripLeadingAndTrailingHTMLSpaces(value);
if (document().isDNSPrefetchEnabled()) {
@@ -261,12 +258,8 @@ void HTMLAnchorElement::parseAttribute(const QualifiedName& name, const AtomicSt
invalidateCachedVisitedLinkHash();
} else if (name == nameAttr || name == titleAttr) {
// Do nothing.
- } else if (name == relAttr) {
- if (SpaceSplitString::spaceSplitStringContainsValue(value, "noreferrer", true))
- m_linkRelations |= RelationNoReferrer;
- if (m_relList)
- m_relList->updateRelAttribute(value);
- }
+ } else if (name == relAttr)
+ setRel(value);
else
HTMLElement::parseAttribute(name, value);
}
@@ -283,6 +276,7 @@ bool HTMLAnchorElement::isURLAttribute(const Attribute& attribute) const
bool HTMLAnchorElement::canStartSelection() const
{
+ // FIXME: We probably want this same behavior in SVGAElement too
if (!isLink())
return HTMLElement::canStartSelection();
return hasEditableStyle();
@@ -291,7 +285,7 @@ bool HTMLAnchorElement::canStartSelection() const
bool HTMLAnchorElement::draggable() const
{
// Should be draggable if we have an href attribute.
- const AtomicString& value = fastGetAttribute(draggableAttr);
+ const AtomicString& value = getAttribute(draggableAttr);
if (equalIgnoringCase(value, "true"))
return true;
if (equalIgnoringCase(value, "false"))
@@ -314,11 +308,10 @@ bool HTMLAnchorElement::hasRel(uint32_t relation) const
return m_linkRelations & relation;
}
-DOMTokenList& HTMLAnchorElement::relList()
+void HTMLAnchorElement::setRel(const String& value)
{
- if (!m_relList)
- m_relList = std::make_unique<RelList>(*this);
- return *m_relList;
+ if (SpaceSplitString::spaceSplitStringContainsValue(value, "noreferrer", true))
+ m_linkRelations |= RelationNoReferrer;
}
const AtomicString& HTMLAnchorElement::name() const
@@ -487,7 +480,8 @@ String HTMLAnchorElement::search() const
String HTMLAnchorElement::origin() const
{
- return SecurityOrigin::create(href()).get().toString();
+ RefPtr<SecurityOrigin> origin = SecurityOrigin::create(href());
+ return origin->toString();
}
void HTMLAnchorElement::setSearch(const String& value)
@@ -502,12 +496,7 @@ void HTMLAnchorElement::setSearch(const String& value)
String HTMLAnchorElement::text()
{
- return textContent();
-}
-
-void HTMLAnchorElement::setText(const String& text, ExceptionCode& ec)
-{
- setTextContent(text, ec);
+ return innerText();
}
String HTMLAnchorElement::toString() const
@@ -522,12 +511,12 @@ bool HTMLAnchorElement::isLiveLink() const
void HTMLAnchorElement::sendPings(const URL& destinationURL)
{
- if (!fastHasAttribute(pingAttr) || !document().settings() || !document().settings()->hyperlinkAuditingEnabled())
+ if (!hasAttribute(pingAttr) || !document().settings() || !document().settings()->hyperlinkAuditingEnabled())
return;
- SpaceSplitString pingURLs(fastGetAttribute(pingAttr), false);
+ SpaceSplitString pingURLs(getAttribute(pingAttr), false);
for (unsigned i = 0; i < pingURLs.size(); i++)
- PingLoader::sendPing(*document().frame(), document().completeURL(pingURLs[i]), destinationURL);
+ PingLoader::sendPing(document().frame(), document().completeURL(pingURLs[i]), destinationURL);
}
void HTMLAnchorElement::handleClick(Event* event)
@@ -558,18 +547,16 @@ void HTMLAnchorElement::handleClick(Event* event)
frame->loader().client().startDownload(request, fastGetAttribute(downloadAttr));
} else
#endif
-
- frame->loader().urlSelected(kurl, target(), event, LockHistory::No, LockBackForwardList::No, hasRel(RelationNoReferrer) ? NeverSendReferrer : MaybeSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate());
+ frame->loader().urlSelected(kurl, target(), event, false, false, hasRel(RelationNoReferrer) ? NeverSendReferrer : MaybeSendReferrer);
sendPings(kurl);
}
HTMLAnchorElement::EventType HTMLAnchorElement::eventType(Event* event)
{
- ASSERT(event);
- if (!is<MouseEvent>(*event))
+ if (!event->isMouseEvent())
return NonMouseEvent;
- return downcast<MouseEvent>(*event).shiftKey() ? MouseEventWithShiftKey : MouseEventWithoutShiftKey;
+ return static_cast<MouseEvent*>(event)->shiftKey() ? MouseEventWithShiftKey : MouseEventWithoutShiftKey;
}
bool HTMLAnchorElement::treatLinkAsLiveForEventType(EventType eventType) const
@@ -604,12 +591,22 @@ bool HTMLAnchorElement::treatLinkAsLiveForEventType(EventType eventType) const
bool isEnterKeyKeydownEvent(Event* event)
{
- return event->type() == eventNames().keydownEvent && is<KeyboardEvent>(*event) && downcast<KeyboardEvent>(*event).keyIdentifier() == "Enter";
+ return event->type() == eventNames().keydownEvent && event->isKeyboardEvent() && static_cast<KeyboardEvent*>(event)->keyIdentifier() == "Enter";
+}
+
+bool isLinkClick(Event* event)
+{
+ return event->type() == eventNames().clickEvent && (!event->isMouseEvent() || static_cast<MouseEvent*>(event)->button() != RightButton);
}
bool shouldProhibitLinks(Element* element)
{
+#if ENABLE(SVG)
return isInSVGImage(element);
+#else
+ UNUSED_PARAM(element);
+ return false;
+#endif
}
bool HTMLAnchorElement::willRespondToMouseClickEvents()
@@ -621,7 +618,7 @@ typedef HashMap<const HTMLAnchorElement*, RefPtr<Element>> RootEditableElementMa
static RootEditableElementMap& rootEditableElementMap()
{
- DEPRECATED_DEFINE_STATIC_LOCAL(RootEditableElementMap, map, ());
+ DEFINE_STATIC_LOCAL(RootEditableElementMap, map, ());
return map;
}