Adopt is/toHTMLAnchorElement for code cleanup

https://bugs.webkit.org/show_bug.cgi?id=117973

Reviewed by Andreas Kling.

To enhance readibility, this patch adopts is/toHTMLAnchorElement.
This also helps out to reduce duplicated use of static_cast.

Source/WebCore:

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::anchorElement):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::anchorElement):
(WebCore::AccessibilityRenderObject::internalLinkElement):
(WebCore::AccessibilityRenderObject::url):
(WebCore::AccessibilityRenderObject::stringValueForMSAA):
(WebCore::AccessibilityRenderObject::isLinked):
* css/CSSDefaultStyleSheets.cpp:
(WebCore::elementCanUseSimpleDefaultStyle):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* dom/Document.cpp:
(WebCore::Document::updateBaseURL):
* dom/TreeScope.cpp:
(WebCore::TreeScope::findAnchor):
* dom/VisitedLinkState.cpp:
(WebCore::linkHashForElement):
(WebCore::VisitedLinkState::determineLinkStateSlowCase):
* html/HTMLAnchorElement.h:
(WebCore::isHTMLAnchorElement):
(WebCore::toHTMLAnchorElement):
* page/DragController.cpp:
(WebCore::DragController::draggableElement):
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::absoluteLinkURL):
(WebCore::HitTestResult::isLiveLink):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::getTextDecorationColors):

Source/WebKit/blackberry:

* WebKitSupport/FatFingers.cpp:
(BlackBerry::WebKit::FatFingers::isElementClickable):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@151975 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 93f4f701
2013-06-25 Kangil Han <kangil.han@samsung.com>
Adopt is/toHTMLAnchorElement for code cleanup
https://bugs.webkit.org/show_bug.cgi?id=117973
Reviewed by Andreas Kling.
To enhance readibility, this patch adopts is/toHTMLAnchorElement.
This also helps out to reduce duplicated use of static_cast.
* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::anchorElement):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::anchorElement):
(WebCore::AccessibilityRenderObject::internalLinkElement):
(WebCore::AccessibilityRenderObject::url):
(WebCore::AccessibilityRenderObject::stringValueForMSAA):
(WebCore::AccessibilityRenderObject::isLinked):
* css/CSSDefaultStyleSheets.cpp:
(WebCore::elementCanUseSimpleDefaultStyle):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* dom/Document.cpp:
(WebCore::Document::updateBaseURL):
* dom/TreeScope.cpp:
(WebCore::TreeScope::findAnchor):
* dom/VisitedLinkState.cpp:
(WebCore::linkHashForElement):
(WebCore::VisitedLinkState::determineLinkStateSlowCase):
* html/HTMLAnchorElement.h:
(WebCore::isHTMLAnchorElement):
(WebCore::toHTMLAnchorElement):
* page/DragController.cpp:
(WebCore::DragController::draggableElement):
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::absoluteLinkURL):
(WebCore::HitTestResult::isLiveLink):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::getTextDecorationColors):
2013-06-25 Dean Jackson <dino@apple.com>
Don't snapshot plug-ins that come from the same host as the page
......@@ -920,7 +920,7 @@ Element* AccessibilityNodeObject::anchorElement() const
// search up the DOM tree for an anchor element
// NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
for ( ; node; node = node->parentNode()) {
if (node->hasTagName(aTag) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
if (isHTMLAnchorElement(node) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
return toElement(node);
}
......
......@@ -579,7 +579,7 @@ Element* AccessibilityRenderObject::anchorElement() const
// NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
Node* node = currRenderer->node();
for ( ; node; node = node->parentNode()) {
if (node->hasTagName(aTag) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
if (isHTMLAnchorElement(node) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
return toElement(node);
}
......@@ -888,9 +888,9 @@ AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
return 0;
// Right now, we do not support ARIA links as internal link elements
if (!element->hasTagName(aTag))
if (!isHTMLAnchorElement(element))
return 0;
HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(element);
HTMLAnchorElement* anchor = toHTMLAnchorElement(element);
KURL linkURL = anchor->href();
String fragmentIdentifier = linkURL.fragmentIdentifier();
......@@ -1459,8 +1459,8 @@ void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range
KURL AccessibilityRenderObject::url() const
{
if (isAnchor() && m_renderer->node()->hasTagName(aTag)) {
if (HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(anchorElement()))
if (isAnchor() && isHTMLAnchorElement(m_renderer->node())) {
if (HTMLAnchorElement* anchor = toHTMLAnchorElement(anchorElement()))
return anchor->href();
}
......@@ -3195,8 +3195,8 @@ String AccessibilityRenderObject::stringValueForMSAA() const
{
if (isLinkable(*this)) {
Element* anchor = anchorElement();
if (anchor && anchor->hasTagName(aTag))
return static_cast<HTMLAnchorElement*>(anchor)->href();
if (anchor && isHTMLAnchorElement(anchor))
return toHTMLAnchorElement(anchor)->href();
}
return stringValue();
......@@ -3208,10 +3208,10 @@ bool AccessibilityRenderObject::isLinked() const
return false;
Element* anchor = anchorElement();
if (!anchor || !anchor->hasTagName(aTag))
if (!anchor || !isHTMLAnchorElement(anchor))
return false;
return !static_cast<HTMLAnchorElement*>(anchor)->href().isEmpty();
return !toHTMLAnchorElement(anchor)->href().isEmpty();
}
bool AccessibilityRenderObject::hasBoldFont() const
......
......@@ -31,6 +31,7 @@
#include "Chrome.h"
#include "ChromeClient.h"
#include "HTMLAnchorElement.h"
#include "MediaQueryEvaluator.h"
#include "Page.h"
#include "RenderTheme.h"
......@@ -61,7 +62,7 @@ static const char* simpleUserAgentStyleSheet = "html,body,div{display:block}head
static inline bool elementCanUseSimpleDefaultStyle(Element* e)
{
return e->hasTagName(htmlTag) || e->hasTagName(headTag) || e->hasTagName(bodyTag) || e->hasTagName(divTag) || e->hasTagName(spanTag) || e->hasTagName(brTag) || e->hasTagName(aTag);
return e->hasTagName(htmlTag) || e->hasTagName(headTag) || e->hasTagName(bodyTag) || e->hasTagName(divTag) || e->hasTagName(spanTag) || e->hasTagName(brTag) || isHTMLAnchorElement(e);
}
static const MediaQueryEvaluator& screenEval()
......
......@@ -34,6 +34,7 @@
#include "FocusController.h"
#include "Frame.h"
#include "FrameSelection.h"
#include "HTMLAnchorElement.h"
#include "HTMLDocument.h"
#include "HTMLFrameElementBase.h"
#include "HTMLInputElement.h"
......@@ -629,7 +630,7 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context) const
case CSSSelector::PseudoHover:
// If we're in quirks mode, then hover should never match anchors with no
// href and *:hover should not match anything. This is important for sites like wsj.com.
if (m_strictParsing || context.isSubSelector || (selector->m_match == CSSSelector::Tag && selector->tagQName() != anyQName() && !element->hasTagName(aTag)) || element->isLink()) {
if (m_strictParsing || context.isSubSelector || (selector->m_match == CSSSelector::Tag && selector->tagQName() != anyQName() && !isHTMLAnchorElement(element)) || element->isLink()) {
if (m_mode == ResolvingStyle) {
if (context.elementStyle)
context.elementStyle->setAffectedByHover();
......@@ -643,7 +644,7 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context) const
case CSSSelector::PseudoActive:
// If we're in quirks mode, then :active should never match anchors with no
// href and *:active should not match anything.
if (m_strictParsing || context.isSubSelector || (selector->m_match == CSSSelector::Tag && selector->tagQName() != anyQName() && !element->hasTagName(aTag)) || element->isLink()) {
if (m_strictParsing || context.isSubSelector || (selector->m_match == CSSSelector::Tag && selector->tagQName() != anyQName() && !isHTMLAnchorElement(element)) || element->isLink()) {
if (m_mode == ResolvingStyle) {
if (context.elementStyle)
context.elementStyle->setAffectedByActive();
......
......@@ -2655,8 +2655,8 @@ void Document::updateBaseURL()
// Base URL change changes any relative visited links.
// FIXME: There are other URLs in the tree that would need to be re-evaluated on dynamic base URL change. Style should be invalidated too.
for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::next(element)) {
if (element->hasTagName(aTag))
static_cast<HTMLAnchorElement*>(element)->invalidateCachedVisitedLinkHash();
if (isHTMLAnchorElement(element))
toHTMLAnchorElement(element)->invalidateCachedVisitedLinkHash();
}
}
}
......
......@@ -343,8 +343,8 @@ Element* TreeScope::findAnchor(const String& name)
if (Element* element = getElementById(name))
return element;
for (Element* element = ElementTraversal::firstWithin(rootNode()); element; element = ElementTraversal::next(element)) {
if (element->hasTagName(aTag)) {
HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(element);
if (isHTMLAnchorElement(element)) {
HTMLAnchorElement* anchor = toHTMLAnchorElement(element);
if (rootNode()->document()->inQuirksMode()) {
// Quirks mode, case insensitive comparison of names.
if (equalIgnoringCase(anchor->name(), name))
......
......@@ -75,8 +75,8 @@ void VisitedLinkState::invalidateStyleForAllLinks()
inline static LinkHash linkHashForElement(Document* document, Element* element)
{
if (element->hasTagName(aTag))
return static_cast<HTMLAnchorElement*>(element)->visitedLinkHash();
if (isHTMLAnchorElement(element))
return toHTMLAnchorElement(element)->visitedLinkHash();
if (const AtomicString* attribute = linkAttribute(element))
return WebCore::visitedLinkHash(document->baseURL(), *attribute);
return 0;
......@@ -106,8 +106,8 @@ EInsideLink VisitedLinkState::determineLinkStateSlowCase(Element* element)
return InsideVisitedLink;
LinkHash hash;
if (element->hasTagName(aTag))
hash = static_cast<HTMLAnchorElement*>(element)->visitedLinkHash();
if (isHTMLAnchorElement(element))
hash = toHTMLAnchorElement(element)->visitedLinkHash();
else
hash = WebCore::visitedLinkHash(element->document()->baseURL(), *attribute);
......
......@@ -154,6 +154,17 @@ inline LinkHash HTMLAnchorElement::visitedLinkHash() const
return m_cachedVisitedLinkHash;
}
inline bool isHTMLAnchorElement(Node* node)
{
return node->hasTagName(HTMLNames::aTag);
}
inline HTMLAnchorElement* toHTMLAnchorElement(Node* node)
{
ASSERT_WITH_SECURITY_IMPLICATION(!node || isHTMLAnchorElement(node));
return static_cast<HTMLAnchorElement*>(node);
}
// Functions shared with the other anchor elements (i.e., SVG).
bool isEnterKeyKeydownEvent(Event*);
......
......@@ -666,8 +666,8 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
return toElement(node);
}
if ((m_dragSourceAction & DragSourceActionLink)
&& node->hasTagName(HTMLNames::aTag)
&& static_cast<HTMLAnchorElement*>(node)->isLiveLink()) {
&& isHTMLAnchorElement(node)
&& toHTMLAnchorElement(node)->isLiveLink()) {
state.type = static_cast<DragSourceAction>(state.type | DragSourceActionLink);
return toElement(node);
}
......
......@@ -510,7 +510,7 @@ KURL HitTestResult::absoluteLinkURL() const
return KURL();
AtomicString urlString;
if (m_innerURLElement->hasTagName(aTag) || m_innerURLElement->hasTagName(areaTag) || m_innerURLElement->hasTagName(linkTag))
if (isHTMLAnchorElement(m_innerURLElement.get()) || m_innerURLElement->hasTagName(areaTag) || m_innerURLElement->hasTagName(linkTag))
urlString = m_innerURLElement->getAttribute(hrefAttr);
#if ENABLE(SVG)
else if (m_innerURLElement->hasTagName(SVGNames::aTag))
......@@ -527,8 +527,8 @@ bool HitTestResult::isLiveLink() const
if (!(m_innerURLElement && m_innerURLElement->document()))
return false;
if (m_innerURLElement->hasTagName(aTag))
return static_cast<HTMLAnchorElement*>(m_innerURLElement.get())->isLiveLink();
if (isHTMLAnchorElement(m_innerURLElement.get()))
return toHTMLAnchorElement(m_innerURLElement.get())->isLiveLink();
#if ENABLE(SVG)
if (m_innerURLElement->hasTagName(SVGNames::aTag))
return m_innerURLElement->isLink();
......
......@@ -38,6 +38,7 @@
#include "FrameSelection.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLAnchorElement.h"
#include "HTMLElement.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
......@@ -2890,8 +2891,7 @@ void RenderObject::getTextDecorationColors(int decorations, Color& underline, Co
curr = curr->parent();
if (curr && curr->isAnonymousBlock() && toRenderBlock(curr)->continuation())
curr = toRenderBlock(curr)->continuation();
} while (curr && decorations && (!quirksMode || !curr->node() ||
(!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
} while (curr && decorations && (!quirksMode || !curr->node() || (!isHTMLAnchorElement(curr->node()) && !curr->node()->hasTagName(fontTag))));
// If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
if (decorations && curr) {
......
2013-06-25 Kangil Han <kangil.han@samsung.com>
Adopt is/toHTMLAnchorElement for code cleanup
https://bugs.webkit.org/show_bug.cgi?id=117973
Reviewed by Andreas Kling.
To enhance readibility, this patch adopts is/toHTMLAnchorElement.
This also helps out to reduce duplicated use of static_cast.
* WebKitSupport/FatFingers.cpp:
(BlackBerry::WebKit::FatFingers::isElementClickable):
2013-06-24 Kangil Han <kangil.han@samsung.com>
Adopt is/toHTMLFormElement for code cleanup
......
......@@ -93,7 +93,7 @@ bool FatFingers::isElementClickable(Element* element) const
if (element->webkitMatchesSelector("a[href],*:link,*:visited,*[role=button],button,input,select,label[for],area[href],textarea,embed,object", ec)
|| element->isMediaControlElement()
|| element->isContentEditable()
|| (element->hasTagName(HTMLNames::imgTag) && element->parentNode() && element->parentNode()->hasTagName(HTMLNames::aTag)))
|| (element->hasTagName(HTMLNames::imgTag) && element->parentNode() && isHTMLAnchorElement(element->parentNode())))
return true;
return hasMousePressListener(element)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment