Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Unified Diff: third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp

Issue 2713193003: Added a quick heuristic to determine which objects are the target of in-page links and stop ignorin… (Closed)
Patch Set: Fixed Android test. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp
diff --git a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp
index e27a9b21a417919596fb3f24fb1126e28dc7d775..8b1f1edaeaa500df7ef422a9909ed7337bf4d37a 100644
--- a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp
+++ b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp
@@ -40,6 +40,7 @@
#include "core/frame/FrameView.h"
#include "core/html/HTMLAnchorElement.h"
#include "core/html/HTMLDListElement.h"
+#include "core/html/HTMLDivElement.h"
#include "core/html/HTMLFieldSetElement.h"
#include "core/html/HTMLFrameElementBase.h"
#include "core/html/HTMLImageElement.h"
@@ -461,12 +462,18 @@ AccessibilityRole AXNodeObject::nativeAccessibilityRoleIgnoringAria() const {
if (!getNode())
return UnknownRole;
- // HTMLAnchorElement sets isLink only when it has hrefAttr.
- // We assume that it is also LinkRole if it has event listners even though it
- // doesn't have hrefAttr.
- if (getNode()->isLink() || (isHTMLAnchorElement(*getNode()) && isClickable()))
+ // |HTMLAnchorElement| sets isLink only when it has hrefAttr.
+ if (getNode()->isLink())
return LinkRole;
+ if (isHTMLAnchorElement(*getNode())) {
+ // We assume that an anchor element is LinkRole if it has event listners
+ // even though it doesn't have hrefAttr.
+ if (isClickable())
+ return LinkRole;
+ return AnchorRole;
+ }
+
if (isHTMLButtonElement(*getNode()))
return buttonRoleType();
@@ -660,9 +667,8 @@ AccessibilityRole AXNodeObject::nativeAccessibilityRoleIgnoringAria() const {
if (isHTMLHRElement(*getNode()))
return SplitterRole;
- if (isFieldset()) {
+ if (isFieldset())
return GroupRole;
- }
return UnknownRole;
}
@@ -980,6 +986,28 @@ bool AXNodeObject::isLink() const {
return roleValue() == LinkRole;
}
+// It is not easily possible to find out if an element is the target of an
+// in-page link.
+// As a workaround, we check if the element is a sectioning element with an ID,
+// or an anchor with a name.
+bool AXNodeObject::isInPageLinkTarget() const {
+ if (!m_node || !m_node->isElementNode())
+ return false;
+ Element* element = toElement(m_node);
+ // We exclude elements that are in the shadow DOM.
+ if (element->containingShadowRoot())
+ return false;
+
+ if (isHTMLAnchorElement(element)) {
+ HTMLAnchorElement* htmlElement = toHTMLAnchorElement(element);
+ return htmlElement->hasName() || htmlElement->hasID();
+ }
+
+ if (element->hasID() && (isLandmarkRelated() || isHTMLDivElement(element)))
+ return true;
+ return false;
+}
+
bool AXNodeObject::isMenu() const {
return roleValue() == MenuRole;
}

Powered by Google App Engine
This is Rietveld 408576698