Index: third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
diff --git a/third_party/WebKit/Source/modules/accessibility/AXObject.cpp b/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
index 29df97c32bb74b82cf9dfc6b20efe48bf5c6dd3c..8d1544f17a006256c539ec3ecc7118684d18a19d 100644 |
--- a/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
+++ b/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
@@ -676,6 +676,20 @@ bool AXObject::isPresentationalChild() const |
return m_cachedIsPresentationalChild; |
} |
+// Simplify and whitespace, but preserve a single leading and trailing whitespace |
aboxhall
2015/11/30 19:20:19
First clause seems a little weird - can't tell if
dmazzoni
2015/12/01 08:52:39
Done.
|
+// character if it's present. |
+// static |
+String AXObject::collapseWhitespace(const String& str) |
+{ |
+ StringBuilder result; |
+ if (!str.isEmpty() && isHTMLSpace<UChar>(str[0])) |
+ result.append(' '); |
+ result.append(str.simplifyWhiteSpace(isHTMLSpace<UChar>)); |
+ if (!str.isEmpty() && isHTMLSpace<UChar>(str[str.length() - 1])) |
+ result.append(' '); |
+ return result.toString(); |
+} |
+ |
String AXObject::computedName() const |
{ |
AXNameFrom nameFrom; |
@@ -690,7 +704,7 @@ String AXObject::name(AXNameFrom& nameFrom, AXObject::AXObjectVector* nameObject |
String text = textAlternative(false, false, visited, nameFrom, &relatedObjects, nullptr); |
if (!node() || !isHTMLBRElement(node())) |
- text = text.simplifyWhiteSpace(isHTMLSpace<UChar>, WTF::DoNotStripWhiteSpace); |
+ text = collapseWhitespace(text); |
if (nameObjects) { |
nameObjects->clear(); |
@@ -716,6 +730,28 @@ String AXObject::recursiveTextAlternative(const AXObject& axObj, bool inAriaLabe |
return axObj.textAlternative(true, inAriaLabelledByTraversal, visited, tmpNameFrom, nullptr, nullptr); |
} |
+bool AXObject::isHiddenForTextAlternativeCalculation() const |
+{ |
+ if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "false")) |
+ return false; |
+ |
+ if (layoutObject()) |
+ return layoutObject()->style()->visibility() != VISIBLE; |
+ |
+ // This is an obscure corner case: if a node has no LayoutObject, that means it's not rendered, |
aboxhall
2015/11/30 19:20:19
Helpful comment, thanks!
|
+ // but we still may be exploring it as part of a text alternative calculation, for example if it |
+ // was explicitly referenced by aria-labelledby. So we need to explicitly call the style resolver |
+ // to check whether it's invisible or display:none, rather than relying on the style cached in the |
+ // LayoutObject. |
+ Document* doc = document(); |
+ if (doc && node() && node()->isElementNode()) { |
+ RefPtr<ComputedStyle> style = doc->ensureStyleResolver().styleForElement(toElement(node())); |
+ return style->display() == NONE || style->visibility() != VISIBLE; |
+ } |
+ |
+ return false; |
+} |
+ |
String AXObject::ariaTextAlternative(bool recursive, bool inAriaLabelledByTraversal, AXObjectSet& visited, AXNameFrom& nameFrom, AXRelatedObjectVector* relatedObjects, NameSources* nameSources, bool* foundTextAlternative) const |
{ |
String textAlternative; |
@@ -724,9 +760,8 @@ String AXObject::ariaTextAlternative(bool recursive, bool inAriaLabelledByTraver |
// Step 2A from: http://www.w3.org/TR/accname-aam-1.1 |
// If you change this logic, update AXNodeObject::nameFromLabelElement, too. |
- if (!recursive && layoutObject() |
- && layoutObject()->style()->visibility() != VISIBLE |
- && !equalIgnoringCase(getAttribute(aria_hiddenAttr), "false")) { |
+ if (!inAriaLabelledByTraversal && isHiddenForTextAlternativeCalculation()) { |
aboxhall
2015/11/30 19:20:19
This looks much better now.
|
+ *foundTextAlternative = true; |
return String(); |
} |