AX: [Mac] Meter element should use AXValueDescription to descrbe the status of the...
authorn_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Oct 2016 16:48:41 +0000 (16:48 +0000)
committern_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Oct 2016 16:48:41 +0000 (16:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163610

Reviewed by Chris Fleizach.

Source/WebCore:

Exposed the goodness of the meter value in AXValueDescription.

Test: accessibility/mac/meter-gauge-value-description.html

* English.lproj/Localizable.strings:
* accessibility/AccessibilityProgressIndicator.cpp:
(WebCore::AccessibilityProgressIndicator::gaugeRegionValueDescription):
* accessibility/AccessibilityProgressIndicator.h:
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper valueDescriptionForMeter]):
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):
* platform/LocalizedStrings.cpp:
(WebCore::AXMeterGaugeRegionOptimumText):
(WebCore::AXMeterGaugeRegionSuboptimalText):
(WebCore::AXMeterGaugeRegionLessGoodText):
* platform/LocalizedStrings.h:

LayoutTests:

* accessibility/mac/meter-gauge-value-description-expected.txt: Added.
* accessibility/mac/meter-gauge-value-description.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@207540 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/accessibility/mac/meter-gauge-value-description-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/mac/meter-gauge-value-description.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/English.lproj/Localizable.strings
Source/WebCore/accessibility/AccessibilityProgressIndicator.cpp
Source/WebCore/accessibility/AccessibilityProgressIndicator.h
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
Source/WebCore/platform/LocalizedStrings.cpp
Source/WebCore/platform/LocalizedStrings.h

index 32b206d..360bdcb 100644 (file)
@@ -1,3 +1,13 @@
+2016-10-19  Nan Wang  <n_wang@apple.com>
+
+        AX: [Mac] Meter element should use AXValueDescription to descrbe the status of the value
+        https://bugs.webkit.org/show_bug.cgi?id=163610
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/mac/meter-gauge-value-description-expected.txt: Added.
+        * accessibility/mac/meter-gauge-value-description.html: Added.
+
 2016-10-19  Ryan Haddad  <ryanhaddad@apple.com>
 
         Marking WPT html/webappapis/animation-frames/callback-* tests as flaky on mac-wk1.
diff --git a/LayoutTests/accessibility/mac/meter-gauge-value-description-expected.txt b/LayoutTests/accessibility/mac/meter-gauge-value-description-expected.txt
new file mode 100644 (file)
index 0000000..c9ecffd
--- /dev/null
@@ -0,0 +1,15 @@
+    
+This tests the gauge value description for meter elements.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS meter1.valueDescription is 'AXValueDescription: '
+PASS meter2.valueDescription is 'AXValueDescription: suboptimal value'
+PASS meter3.valueDescription is 'AXValueDescription: optimal value'
+PASS meter4.valueDescription is 'AXValueDescription: critical value'
+PASS meter5.valueDescription is 'AXValueDescription: 50 hours, optimal value'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/mac/meter-gauge-value-description.html b/LayoutTests/accessibility/mac/meter-gauge-value-description.html
new file mode 100644 (file)
index 0000000..8b43d93
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body id="body">
+
+<meter id="meter" value="83.5"></meter>
+<meter id="meter2" value="5" optimum="50" min="0" max="100" low="10" high="80"></meter>
+<meter id="meter3" value="50" optimum="50" min="0" max="100" low="10" high="80"></meter>
+<meter id="meter4" value="90" optimum="20" min="0" max="100" low="50" high="80"></meter>
+<meter id="meter5" value="50" optimum="50" min="0" max="100" low="10" high="80">50 hours</meter>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests the gauge value description for meter elements.");
+
+    if (window.accessibilityController) {
+
+          // Test that we are not exposing the gauge value description if author 
+          // didn't specify low, high or optimum attribute.
+          var meter1 = accessibilityController.accessibleElementById("meter");
+          shouldBe("meter1.valueDescription", "'AXValueDescription: '");
+
+          var meter2 = accessibilityController.accessibleElementById("meter2");
+          shouldBe("meter2.valueDescription", "'AXValueDescription: suboptimal value'");
+          
+          var meter3 = accessibilityController.accessibleElementById("meter3");
+          shouldBe("meter3.valueDescription", "'AXValueDescription: optimal value'");
+          
+          var meter4 = accessibilityController.accessibleElementById("meter4");
+          shouldBe("meter4.valueDescription", "'AXValueDescription: critical value'");
+          
+          // Test meter with inner text.
+          var meter5 = accessibilityController.accessibleElementById("meter5");
+          shouldBe("meter5.valueDescription", "'AXValueDescription: 50 hours, optimal value'");
+    }
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index f8b45ca..b1cec89 100644 (file)
@@ -1,3 +1,27 @@
+2016-10-19  Nan Wang  <n_wang@apple.com>
+
+        AX: [Mac] Meter element should use AXValueDescription to descrbe the status of the value
+        https://bugs.webkit.org/show_bug.cgi?id=163610
+
+        Reviewed by Chris Fleizach.
+
+        Exposed the goodness of the meter value in AXValueDescription.
+
+        Test: accessibility/mac/meter-gauge-value-description.html
+
+        * English.lproj/Localizable.strings:
+        * accessibility/AccessibilityProgressIndicator.cpp:
+        (WebCore::AccessibilityProgressIndicator::gaugeRegionValueDescription):
+        * accessibility/AccessibilityProgressIndicator.h:
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper valueDescriptionForMeter]):
+        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):
+        * platform/LocalizedStrings.cpp:
+        (WebCore::AXMeterGaugeRegionOptimumText):
+        (WebCore::AXMeterGaugeRegionSuboptimalText):
+        (WebCore::AXMeterGaugeRegionLessGoodText):
+        * platform/LocalizedStrings.h:
+
 2016-10-19  Dave Hyatt  <hyatt@apple.com>
 
         [CSS Parser] Fix named color parsing
index bd44cb5..f70a73c 100644 (file)
 /* HTTP result code string */
 "length required" = "length required";
 
+/* The less good value description for a meter element */
+"less good" = "critical value";
+
 /* accessibility role description for link */
 "link" = "link";
 
 /* accessibility role description for an output element */
 "output" = "output";
 
+/* The optimum value description for a meter element */
+"optimum" = "optimal value";
+
 /* HTTP result code string */
 "partial content" = "partial content";
 
 /* accessibility help text for hide closed captions button */
 "stop displaying closed captions" = "stop displaying closed captions";
 
+/* The suboptimal value description for a meter element */
+"suboptimal" = "suboptimal value";
+
 /* HTTP result code string */
 "success" = "success";
 
index 1948539..c14177c 100644 (file)
@@ -26,6 +26,7 @@
 #include "HTMLMeterElement.h"
 #include "HTMLNames.h"
 #include "HTMLProgressElement.h"
+#include "LocalizedStrings.h"
 #include "RenderMeter.h"
 #include "RenderObject.h"
 #include "RenderProgress.h"
@@ -167,6 +168,32 @@ HTMLMeterElement* AccessibilityProgressIndicator::meterElement() const
 
     return downcast<RenderMeter>(*m_renderer).meterElement();
 }
+
+String AccessibilityProgressIndicator::gaugeRegionValueDescription() const
+{
+#if PLATFORM(COCOA)
+    if (!m_renderer || !m_renderer->isMeter())
+        return String();
+    
+    // Only expose this when the author has explicitly specified the following attributes.
+    if (!hasAttribute(lowAttr) && !hasAttribute(highAttr) && !hasAttribute(optimumAttr))
+        return String();
+    
+    if (HTMLMeterElement* element = meterElement()) {
+        switch (element->gaugeRegion()) {
+        case HTMLMeterElement::GaugeRegionOptimum:
+            return AXMeterGaugeRegionOptimumText();
+        case HTMLMeterElement::GaugeRegionSuboptimal:
+            return AXMeterGaugeRegionSuboptimalText();
+        case HTMLMeterElement::GaugeRegionEvenLessGood:
+            return AXMeterGaugeRegionLessGoodText();
+        default:
+            break;
+        }
+    }
+#endif
+    return String();
+}
 #endif
 
 Element* AccessibilityProgressIndicator::element() const
index 2831e5a..d8f600d 100644 (file)
@@ -38,6 +38,7 @@ public:
     static Ref<AccessibilityProgressIndicator> create(RenderProgress*);
 #if ENABLE(METER_ELEMENT)
     static Ref<AccessibilityProgressIndicator> create(RenderMeter*);
+    String gaugeRegionValueDescription() const;
 #endif
     Element* element() const override;
 
@@ -65,4 +66,6 @@ private:
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_ACCESSIBILITY(AccessibilityProgressIndicator, isProgressIndicator())
+
 #endif // AccessibilityProgressIndicator_h
index 0903e2c..875501b 100644 (file)
@@ -36,6 +36,7 @@
 #import "AccessibilityLabel.h"
 #import "AccessibilityList.h"
 #import "AccessibilityListBox.h"
+#import "AccessibilityProgressIndicator.h"
 #import "AccessibilityRenderObject.h"
 #import "AccessibilityScrollView.h"
 #import "AccessibilitySpinButton.h"
@@ -76,7 +77,7 @@
 #import "WebCoreSystemInterface.h"
 #import "htmlediting.h"
 #import <wtf/ObjcRuntimeExtras.h>
-#if ENABLE(TREE_DEBUGGING)
+#if ENABLE(TREE_DEBUGGING) || ENABLE(METER_ELEMENT)
 #import <wtf/text/StringBuilder.h>
 #endif
 
@@ -2602,6 +2603,29 @@ static NSString* roleValueToNSString(AccessibilityRole value)
     return [self remoteAccessibilityParentObject];
 }
 
+- (NSString *)valueDescriptionForMeter
+{
+    if (!m_object)
+        return nil;
+    
+    String valueDescription = m_object->valueDescription();
+#if ENABLE(METER_ELEMENT)
+    if (!is<AccessibilityProgressIndicator>(m_object))
+        return valueDescription;
+    auto &meter = downcast<AccessibilityProgressIndicator>(*m_object);
+    String gaugeRegionValue = meter.gaugeRegionValueDescription();
+    if (!gaugeRegionValue.isEmpty()) {
+        StringBuilder builder;
+        builder.append(valueDescription);
+        if (builder.length())
+            builder.appendLiteral(", ");
+        builder.append(gaugeRegionValue);
+        return builder.toString();
+    }
+#endif
+    return valueDescription;
+}
+
 // FIXME: split up this function in a better way.
 // suggestions: Use a hash table that maps attribute names to function calls,
 // or maybe pointers to member functions
@@ -3199,8 +3223,11 @@ static NSString* roleValueToNSString(AccessibilityRole value)
         return nil;
     }
     
-    if ([attributeName isEqualToString:NSAccessibilityValueDescriptionAttribute])
+    if ([attributeName isEqualToString:NSAccessibilityValueDescriptionAttribute]) {
+        if (m_object->isMeter())
+            return [self valueDescriptionForMeter];
         return m_object->valueDescription();
+    }
     
     if ([attributeName isEqualToString:NSAccessibilityOrientationAttribute]) {
         AccessibilityOrientation elementOrientation = m_object->orientation();
index aaa00f4..f7875b0 100644 (file)
@@ -781,6 +781,22 @@ String AXHorizontalRuleDescriptionText()
     return WEB_UI_STRING("separator", "accessibility role description for a horizontal rule [<hr>]");
 }
     
+#if ENABLE(METER_ELEMENT)
+String AXMeterGaugeRegionOptimumText()
+{
+    return WEB_UI_STRING("optimum", "The optimum value description for a meter element.");
+}
+
+String AXMeterGaugeRegionSuboptimalText()
+{
+    return WEB_UI_STRING("suboptimal", "The suboptimal value description for a meter element.");
+}
+
+String AXMeterGaugeRegionLessGoodText()
+{
+    return WEB_UI_STRING("less good", "The less good value description for a meter element.");
+}
+#endif // ENABLE(METER_ELEMENT)
 #endif // PLATFORM(COCOA)
 
 String missingPluginText()
index 8eb9f19..5fefe8a 100644 (file)
@@ -196,6 +196,11 @@ namespace WebCore {
 #if PLATFORM(COCOA)
     String AXARIAContentGroupText(const String& ariaType);
     String AXHorizontalRuleDescriptionText();
+#if ENABLE(METER_ELEMENT)
+    String AXMeterGaugeRegionOptimumText();
+    String AXMeterGaugeRegionSuboptimalText();
+    String AXMeterGaugeRegionLessGoodText();
+#endif
 #endif
     
     String AXAutoFillCredentialsLabel();