Changeset 206581 in webkit


Ignore:
Timestamp:
Sep 29, 2016 8:13:00 AM (8 years ago)
Author:
n_wang@apple.com
Message:

AX: Meter: [Mac] Content in label element should be used as AXTitle or AXDescription
https://bugs.webkit.org/show_bug.cgi?id=162586

Reviewed by Chris Fleizach.

Source/WebCore:

Exposed the label element's text as AXDescription for meter elements.
Also refactored the code for fetching the label element's text and taken care of
the case where aria-label and aria-labelledby attributes are used on label elements.

Test: accessibility/mac/meter-with-label-element.html

  • accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::isLabelable):
(WebCore::AccessibilityNodeObject::textForLabelElement):
(WebCore::AccessibilityNodeObject::titleElementText):
(WebCore::AccessibilityNodeObject::title):
(WebCore::AccessibilityNodeObject::usesAltTagForTextComputation): Deleted.

  • accessibility/AccessibilityNodeObject.h:
  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::AccessibilityRenderObject::exposesTitleUIElement):

LayoutTests:

  • accessibility/mac/aria-label-on-label-element-expected.txt:
  • accessibility/mac/aria-label-on-label-element.html:
  • accessibility/mac/meter-with-label-element-expected.txt: Added.
  • accessibility/mac/meter-with-label-element.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r206576 r206581  
     12016-09-29  Nan Wang  <n_wang@apple.com>
     2
     3        AX: Meter: [Mac] Content in label element should be used as AXTitle or AXDescription
     4        https://bugs.webkit.org/show_bug.cgi?id=162586
     5
     6        Reviewed by Chris Fleizach.
     7
     8        * accessibility/mac/aria-label-on-label-element-expected.txt:
     9        * accessibility/mac/aria-label-on-label-element.html:
     10        * accessibility/mac/meter-with-label-element-expected.txt: Added.
     11        * accessibility/mac/meter-with-label-element.html: Added.
     12
    1132016-09-28  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/accessibility/mac/aria-label-on-label-element-expected.txt

    r200318 r206581  
    11Some text  Some other text   
     2aria
     3
     4labelledby
     5
     6Some text
    27This tests that the aria-label attribute works on element.
    38
     
    914PASS titleUIElement2.isEqual(accessibilityController.accessibleElementById('label2')) is true
    1015PASS input3.title is 'AXTitle: hidden aria label'
     16PASS input4.title is 'AXTitle: aria labelledby'
    1117PASS successfullyParsed is true
    1218
  • trunk/LayoutTests/accessibility/mac/aria-label-on-label-element.html

    r200318 r206581  
    1414<label id="label3" for="input3" hidden aria-label="hidden aria label">hidden text</label>
    1515<input id="input3" type="text">
     16
     17<p id="p1">aria</p>
     18<p id="p2">labelledby</p>
     19<label for="input4" aria-labelledby="p1 p2">Some text</label>
     20<input id="input4" type="text" size=20>
    1621
    1722<p id="description"></p>
     
    3843        var input3 = accessibilityController.accessibleElementById("input3");
    3944        shouldBe("input3.title", "'AXTitle: hidden aria label'");
     45       
     46        // aria-labelledby also works.
     47        var input4 = accessibilityController.accessibleElementById("input4");
     48        shouldBe("input4.title", "'AXTitle: aria labelledby'");
    4049    }
    4150
  • trunk/Source/WebCore/ChangeLog

    r206579 r206581  
     12016-09-29  Nan Wang  <n_wang@apple.com>
     2
     3        AX: Meter: [Mac] Content in label element should be used as AXTitle or AXDescription
     4        https://bugs.webkit.org/show_bug.cgi?id=162586
     5
     6        Reviewed by Chris Fleizach.
     7
     8        Exposed the label element's text as AXDescription for meter elements.
     9        Also refactored the code for fetching the label element's text and taken care of
     10        the case where aria-label and aria-labelledby attributes are used on label elements.
     11
     12        Test: accessibility/mac/meter-with-label-element.html
     13
     14        * accessibility/AccessibilityNodeObject.cpp:
     15        (WebCore::AccessibilityNodeObject::isLabelable):
     16        (WebCore::AccessibilityNodeObject::textForLabelElement):
     17        (WebCore::AccessibilityNodeObject::titleElementText):
     18        (WebCore::AccessibilityNodeObject::title):
     19        (WebCore::AccessibilityNodeObject::usesAltTagForTextComputation): Deleted.
     20        * accessibility/AccessibilityNodeObject.h:
     21        * accessibility/AccessibilityRenderObject.cpp:
     22        (WebCore::AccessibilityRenderObject::exposesTitleUIElement):
     23
    1242016-09-29  Romain Bellessort  <romain.bellessort@crf.canon.fr>
    225
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp

    r206391 r206581  
    12311231    return isImage() || isInputImage() || isNativeImage() || isCanvas() || (node() && node()->hasTagName(imgTag));
    12321232}
     1233
     1234bool AccessibilityNodeObject::isLabelable() const
     1235{
     1236    Node* node = this->node();
     1237    if (!node)
     1238        return false;
     1239   
     1240    return is<HTMLInputElement>(*node) || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || isControl() || isProgressIndicator() || isMeter();
     1241}
     1242
     1243String AccessibilityNodeObject::textForLabelElement(Element* element) const
     1244{
     1245    String result = String();
     1246    if (!is<HTMLLabelElement>(*element))
     1247        return result;
     1248   
     1249    HTMLLabelElement* label = downcast<HTMLLabelElement>(element);
     1250    // Check to see if there's aria-labelledby attribute on the label element.
     1251    if (AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label))
     1252        result = labelObject->ariaLabeledByAttribute();
     1253   
     1254    // Then check for aria-label attribute.
     1255    if (result.isEmpty())
     1256        result = label->attributeWithoutSynchronization(aria_labelAttr);
     1257   
     1258    return !result.isEmpty() ? result : label->innerText();
     1259}
    12331260   
    12341261void AccessibilityNodeObject::titleElementText(Vector<AccessibilityText>& textOrder) const
     
    12381265        return;
    12391266   
    1240     bool isInputTag = is<HTMLInputElement>(*node);
    1241     if (isInputTag || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || isControl() || isProgressIndicator()) {
     1267    if (isLabelable()) {
    12421268        if (HTMLLabelElement* label = labelForElement(downcast<Element>(node))) {
    12431269            AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label);
    1244             String innerText = label->innerText();
    1245            
    1246             const AtomicString& ariaLabel = label->attributeWithoutSynchronization(aria_labelAttr);
    1247             if (!ariaLabel.isEmpty())
    1248                 innerText = ariaLabel;
     1270            String innerText = textForLabelElement(label);
    12491271           
    12501272            // Only use the <label> text if there's no ARIA override.
    12511273            if (!innerText.isEmpty() && !ariaAccessibilityDescription())
    1252                 textOrder.append(AccessibilityText(innerText, LabelByElementText, labelObject));
     1274                textOrder.append(AccessibilityText(innerText, isMeter() ? AlternativeText : LabelByElementText, labelObject));
    12531275            return;
    12541276        }
     
    17111733    }
    17121734
    1713     if (isInputTag || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || isControl() || isProgressIndicator()) {
     1735    if (isLabelable()) {
    17141736        HTMLLabelElement* label = labelForElement(downcast<Element>(node));
    17151737        // Use the label text as the title if 1) the title element is NOT an exposed element and 2) there's no ARIA override.
    17161738        if (label && !exposesTitleUIElement() && !ariaAccessibilityDescription().length())
    1717             return label->innerText();
     1739            return textForLabelElement(label);
    17181740    }
    17191741
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h

    r201087 r206581  
    184184    // This returns true if it's focusable but it's not content editable and it's not a control or ARIA control.
    185185    bool isGenericFocusableElement() const;
     186    bool isLabelable() const;
    186187    HTMLLabelElement* labelForElement(Element*) const;
     188    String textForLabelElement(Element*) const;
    187189    String ariaAccessibilityDescription() const;
    188190    void ariaLabeledByElements(Vector<Element*>& elements) const;
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r205865 r206581  
    10581058        return false;
    10591059   
    1060     // When <label> element has aria-label on it, we shouldn't expose it as the titleUIElement,
    1061     // otherwise its inner text will be announced by a screenreader.
    1062     if (is<HTMLInputElement>(*this->node()) || AccessibilityObject::isARIAInput(ariaRoleAttribute())) {
     1060    // When <label> element has aria-label or aria-labelledby on it, we shouldn't expose it as the
     1061    // titleUIElement, otherwise its inner text will be announced by a screenreader.
     1062    if (isLabelable()) {
    10631063        if (HTMLLabelElement* label = labelForElement(downcast<Element>(node()))) {
    10641064            if (!label->attributeWithoutSynchronization(aria_labelAttr).isEmpty())
    10651065                return false;
     1066            if (AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label)) {
     1067                if (!labelObject->ariaLabeledByAttribute().isEmpty())
     1068                    return false;
     1069            }
    10661070        }
    10671071    }
Note: See TracChangeset for help on using the changeset viewer.