AX: [ATK] Use WebCore Accessibility's AccessibilityText for AtkObject name and description
https://bugs.webkit.org/show_bug.cgi?id=157822
Reviewed by Chris Fleizach.
Source/WebCore:
Remove the old code which was overriding WebCore Accessibility and always use
AccessibilityText.
If the AccessibilityText's textSource is HelpText or SummaryText, it should be exposed
as the AtkObject description. If the textSource is TitleTagText and there is no other
text alternative, the value should also be exposed in this fashion. Note that AtkObject's
description property is equivalent to AXAPI's AXHelp property.
If the AccessibilityText's textSource is anything other than the above, the first
non-empty value should be exposed as the AtkObject name. Depending on the source of
the name content, AtkObject's name property can be the equivalent of AXAPI's AXTitle.
However, most of the time, AtkObject's name property is equivalent to AXAPI's
AXDescription property.
By making these changes, what WebKit exposes for ATK is now extremely similar to what
WebKit exposes on the Mac (modulo the property names) and also with what is defined in
the HTML Accessibility and Accessible Name and Description Computation API mappings specs.
Now that the exposure is correct, the Layout Tests needed to be adjusted accordingly because
asking for the "AXDescription" gives you the AXDescription on the Mac and the AtkObject
description in GNU/Linux. But as indicated above, what ATK calls a "description" is what
the Mac calls "help."
Ultimately our Layout Tests and/or our platform TestRunner API should be modified to deal
with these differences more gracefully. (Bug https://bugs.webkit.org/show_bug.cgi?id=157187
has been opened for that task.) In the meantime, the existing tests have been given platform
checks to ask for the right property on each platform. This was done in such a way as to not
require other (non-ATK) platforms change their current expectations files.
* accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
(webkitAccessibleGetName):
(webkitAccessibleGetDescription):
Tools:
Fix AccessibilityUIElement::helpText() so that it returns an empty string rather than
nullptr upon failure.
* WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp:
(WTR::AccessibilityUIElement::helpText):
LayoutTests:
Now that the exposure is correct, the Layout Tests needed to be adjusted accordingly because asking
for the "AXDescription" gives you the AXDescription on the Mac and the AtkObject description in
GNU/Linux. But what the Mac calls a "description" is what ATK calls a "name." What ATK calls a
"description" is what the Mac calls "help."
Ultimately our Layout Tests and/or our platform TestRunner API should be modified to deal with
with these differences more gracefully. (Bug https://bugs.webkit.org/show_bug.cgi?id=157187 has
been opened for that task.) In the meantime, the existing tests have been given platform checks
to ask for the right property on each platform. This was done in such a way as to not require
other (non-ATK) platforms change their current expectations files.
In addition to the above, three previously-failing tests were corrected and are now passing.
* accessibility/alt-tag-on-image-with-nonimage-role.html:
* accessibility/aria-help.html:
* accessibility/aria-label.html:
* accessibility/aria-labeled-with-hidden-node.html:
* accessibility/aria-labelledby-on-input.html:
* accessibility/aria-labelledby-overrides-aria-labeledby.html:
* accessibility/aria-labelledby-overrides-label.html:
* accessibility/aria-labelledby-stay-within.html:
* accessibility/aria-labelledby-with-descendants.html:
* accessibility/aria-namefrom-author.html:
* accessibility/aria-option-role.html:
* accessibility/canvas-description-and-role.html:
* accessibility/empty-image-with-title.html:
* accessibility/fieldset-element.html:
* accessibility/focusable-div.html:
* accessibility/gtk/no-notification-for-unrendered-iframe-children-expected.txt:
* accessibility/gtk/no-notification-for-unrendered-iframe-children.html:
* accessibility/gtk/title-and-alt-expected.txt:
* accessibility/gtk/title-and-alt.html:
* accessibility/help-text.html:
* accessibility/img-alt-tag-only-whitespace-expected.txt:
* accessibility/img-alt-tag-only-whitespace.html:
* accessibility/img-aria-button-alt-tag.html:
* accessibility/img-fallsback-to-title.html:
* accessibility/input-image-alt.html:
* accessibility/loading-iframe-sends-notification.html:
* accessibility/media-element.html:
* accessibility/radio-button-title-label.html:
* accessibility/self-referencing-aria-labelledby.html:
* accessibility/svg-bounds.html:
* platform/gtk/TestExpectations:
* platform/gtk/accessibility/alt-tag-on-image-with-nonimage-role-expected.txt: Added.
* platform/gtk/accessibility/aria-help-expected.txt:
* platform/gtk/accessibility/aria-hidden-negates-no-visibility-expected.txt: Added.
* platform/gtk/accessibility/aria-labeled-with-hidden-node-expected.txt: Added.
* platform/gtk/accessibility/aria-labelledby-on-input-expected.txt: Added.
* platform/gtk/accessibility/aria-labelledby-overrides-aria-label-expected.txt: Added.
* platform/gtk/accessibility/aria-labelledby-overrides-aria-labeledby-expected.txt: Added.
* platform/gtk/accessibility/aria-labelledby-overrides-label-expected.txt: Added.
* platform/gtk/accessibility/aria-labelledby-with-descendants-expected.txt: Added.
* platform/gtk/accessibility/aria-namefrom-author-expected.txt: Added.
* platform/gtk/accessibility/aria-option-role-expected.txt: Added.
* platform/gtk/accessibility/aria-switch-text-expected.txt:
* platform/gtk/accessibility/canvas-description-and-role-expected.txt: Added.
* platform/gtk/accessibility/empty-image-with-title-expected.txt: Added.
* platform/gtk/accessibility/fieldset-element-expected.txt: Added.
* platform/gtk/accessibility/focusable-div-expected.txt: Added.
* platform/gtk/accessibility/help-text-expected.txt: Added.
* platform/gtk/accessibility/image-link-expected.txt:
* platform/gtk/accessibility/image-map1-expected.txt:
* platform/gtk/accessibility/image-map2-expected.txt:
* platform/gtk/accessibility/image-with-alt-and-map-expected.txt:
* platform/gtk/accessibility/img-alt-tag-only-whitespace-expected.txt: Added.
* platform/gtk/accessibility/img-aria-button-alt-tag-expected.txt: Added.
* platform/gtk/accessibility/img-fallsback-to-title-expected.txt:
* platform/gtk/accessibility/input-image-alt-expected.txt: Added.
* platform/gtk/accessibility/media-element-expected.txt:
* platform/gtk/accessibility/radio-button-title-label-expected.txt:
* platform/gtk/accessibility/self-referencing-aria-labelledby-expected.txt: Added.
* platform/gtk/accessibility/svg-bounds-expected.txt: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@201072 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp b/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
index f8c1ff2..9daff56 100644
--- a/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
+++ b/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
@@ -111,67 +111,24 @@
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
- AccessibilityObject* coreObject = core(object);
- if (coreObject->isFieldset()) {
- AccessibilityObject* label = coreObject->titleUIElement();
- if (label) {
- AtkObject* atkObject = label->wrapper();
- if (ATK_IS_TEXT(atkObject))
- return atk_text_get_text(ATK_TEXT(atkObject), 0, -1);
- }
+ Vector<AccessibilityText> textOrder;
+ core(object)->accessibilityText(textOrder);
+
+ for (const auto& text : textOrder) {
+ // FIXME: This check is here because AccessibilityNodeObject::titleElementText()
+ // appends an empty String for the LabelByElementText source when there is a
+ // titleUIElement(). Removing this check makes some fieldsets lose their name.
+ if (text.text.isEmpty())
+ continue;
+
+ // WebCore Accessibility should provide us with the text alternative computation
+ // in the order defined by that spec. So take the first thing that our platform
+ // does not expose via the AtkObject description.
+ if (text.textSource != HelpText && text.textSource != SummaryText)
+ return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, text.text);
}
- if (coreObject->isControl()) {
- AccessibilityObject* label = coreObject->correspondingLabelForControlElement();
- if (label) {
- AtkObject* atkObject = label->wrapper();
- if (ATK_IS_TEXT(atkObject))
- return atk_text_get_text(ATK_TEXT(atkObject), 0, -1);
- }
-
- // Try text under the node.
- String textUnder = coreObject->textUnderElement();
- if (textUnder.length())
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, textUnder);
- }
-
- if (is<SVGElement>(coreObject->element())) {
- Vector<AccessibilityText> textOrder;
- coreObject->accessibilityText(textOrder);
-
- for (const auto& text : textOrder) {
- if (text.textSource != HelpText && text.textSource != SummaryText)
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, text.text);
- }
- // FIXME: This is to keep the next blocks from returning duplicate text.
- // This behavior should be extended to all elements; not just SVG.
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, "");
- }
-
- if (coreObject->isImage() || coreObject->isInputImage() || coreObject->isImageMap() || coreObject->isImageMapLink()) {
- Node* node = coreObject->node();
- if (is<HTMLElement>(node)) {
- // Get the attribute rather than altText String so as not to fall back on title.
- const AtomicString& alt = downcast<HTMLElement>(*node).getAttribute(HTMLNames::altAttr);
- if (!alt.isEmpty())
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, alt);
- }
- }
-
- // Fallback for the webArea object: just return the document's title.
- if (coreObject->isWebArea()) {
- Document* document = coreObject->document();
- if (document)
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, document->title());
- }
-
- // Nothing worked so far, try with the AccessibilityObject's
- // title() before going ahead with stringValue().
- String axTitle = accessibilityTitle(coreObject);
- if (!axTitle.isEmpty())
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, axTitle);
-
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, coreObject->stringValue());
+ return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, "");
}
static const gchar* webkitAccessibleGetDescription(AtkObject* object)
@@ -179,41 +136,26 @@
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
- AccessibilityObject* coreObject = core(object);
- Node* node = nullptr;
- if (coreObject->isAccessibilityRenderObject())
- node = coreObject->node();
+ Vector<AccessibilityText> textOrder;
+ core(object)->accessibilityText(textOrder);
- if (is<SVGElement>(node)) {
- Vector<AccessibilityText> textOrder;
- coreObject->accessibilityText(textOrder);
+ bool nameTextAvailable = false;
+ for (const auto& text : textOrder) {
+ // WebCore Accessibility should provide us with the text alternative computation
+ // in the order defined by that spec. So take the first thing that our platform
+ // does not expose via the AtkObject name.
+ if (text.textSource == HelpText || text.textSource == SummaryText)
+ return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, text.text);
- for (const auto& text : textOrder) {
- if (text.textSource == HelpText || text.textSource == SummaryText || text.textSource == TitleTagText)
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, text.text);
- }
- // FIXME: This is to keep the next blocks from returning duplicate text.
- // This behavior should be extended to all elements; not just SVG.
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, "");
+ // If there is no other text alternative, the title tag contents will have been
+ // used for the AtkObject name. We don't want to duplicate it here.
+ if (text.textSource == TitleTagText && nameTextAvailable)
+ return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, text.text);
+
+ nameTextAvailable = true;
}
- if (!is<HTMLElement>(node) || coreObject->ariaRoleAttribute() != UnknownRole || coreObject->isImage())
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, accessibilityDescription(coreObject));
-
- // atk_table_get_summary returns an AtkObject. We have no summary object, so expose summary here.
- if (coreObject->roleValue() == TableRole) {
- const AtomicString& summary = downcast<HTMLTableElement>(*node).summary();
- if (!summary.isEmpty())
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, summary);
- }
-
- // The title attribute should be reliably available as the object's descripton.
- // We do not want to fall back on other attributes in its absence. See bug 25524.
- String title = downcast<HTMLElement>(*node).title();
- if (!title.isEmpty())
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, title);
-
- return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, accessibilityDescription(coreObject));
+ return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, "");
}
static void removeAtkRelationByType(AtkRelationSet* relationSet, AtkRelationType relationType)