AX: Certain tags should identify their context to iOS API
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2018 17:52:15 +0000 (17:52 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2018 17:52:15 +0000 (17:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190622
<rdar://problem/45308194>

Reviewed by Zalan Bujtas.

Source/WebCore:

Convey the semantic meaning of <code> tag to the iOS API so VoiceOver can make use of it.

Tests: accessibility/ios-simulator/text-context-attributes.html

* accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(-[WebAccessibilityObjectWrapper accessibilityTextualContext]):
(AXAttributeStringSetStyle):

Tools:

* DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
(AccessibilityUIElement::stringAttributeValue):
* WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
(WTR::AccessibilityUIElement::stringAttributeValue):

LayoutTests:

* accessibility/ios-simulator/text-context-attributes.html: Added.
* accessibility/ios-simulator/text-context-attributes-expcted.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/accessibility/ios-simulator/text-context-attributes-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/ios-simulator/text-context-attributes.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm
Tools/ChangeLog
Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm
Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm

index 4410f20..ba61a31 100644 (file)
@@ -1,3 +1,14 @@
+2018-10-17  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: Certain tags should identify their context to iOS API
+        https://bugs.webkit.org/show_bug.cgi?id=190622
+        <rdar://problem/45308194>
+
+        Reviewed by Zalan Bujtas.
+
+        * accessibility/ios-simulator/text-context-attributes.html: Added.
+        * accessibility/ios-simulator/text-context-attributes-expcted.txt: Added.
+
 2018-10-17  Ali Juma  <ajuma@chromium.org>
 
         Flaky IntersectionObserver web platform tests involving style updates
diff --git a/LayoutTests/accessibility/ios-simulator/text-context-attributes-expected.txt b/LayoutTests/accessibility/ios-simulator/text-context-attributes-expected.txt
new file mode 100644 (file)
index 0000000..7826f3c
--- /dev/null
@@ -0,0 +1,17 @@
+code
+This test ensures that ios simulator exposes textual context attributes for elements correctly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+context value: UIAccessibilityTextualContextSourceCode
+Attributed string: code{
+    UIAccessibilityTextAttributeContext = UIAccessibilityTextualContextSourceCode;
+    UIAccessibilityTokenFontFamily = Courier;
+    UIAccessibilityTokenFontName = Courier;
+    UIAccessibilityTokenFontSize = 13;
+}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/ios-simulator/text-context-attributes.html b/LayoutTests/accessibility/ios-simulator/text-context-attributes.html
new file mode 100644 (file)
index 0000000..4258b17
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<body id="body">
+
+<code id="code">
+code
+</code>
+
+<p id="description"></p>
+<div id="console"></div>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+
+    description("This test ensures that ios simulator exposes textual context attributes for elements correctly.");
+
+    if (window.accessibilityController) {
+
+        var obj = accessibilityController.accessibleElementById("code");
+        debug("context value: " + obj.stringAttributeValue("AXTextualContext"));
+
+        var text = obj.attributedStringForElement();
+        debug("Attributed string: " + text);
+    }
+
+    successfullyParsed = true;
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
index 7df541b..4ca2304 100644 (file)
@@ -1,3 +1,19 @@
+2018-10-17  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: Certain tags should identify their context to iOS API
+        https://bugs.webkit.org/show_bug.cgi?id=190622
+        <rdar://problem/45308194>
+
+        Reviewed by Zalan Bujtas.
+
+        Convey the semantic meaning of <code> tag to the iOS API so VoiceOver can make use of it.
+
+        Tests: accessibility/ios-simulator/text-context-attributes.html
+
+        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+        (-[WebAccessibilityObjectWrapper accessibilityTextualContext]):
+        (AXAttributeStringSetStyle):
+
 2018-10-17  Youenn Fablet  <youenn@apple.com>
 
         Remove unused code from RealtimeOutgoingVideoSourceCocoa
index d4fce54..0383c6c 100644 (file)
@@ -118,6 +118,9 @@ static NSString * const UIAccessibilityTokenUnderline = @"UIAccessibilityTokenUn
 static NSString * const UIAccessibilityTokenLanguage = @"UIAccessibilityTokenLanguage";
 static NSString * const UIAccessibilityTokenAttachment = @"UIAccessibilityTokenAttachment";
 
+static NSString * const UIAccessibilityTextAttributeContext = @"UIAccessibilityTextAttributeContext";
+static NSString * const UIAccessibilityTextualContextSourceCode = @"UIAccessibilityTextualContextSourceCode";
+
 static AccessibilityObjectWrapper* AccessibilityUnignoredAncestor(AccessibilityObjectWrapper *wrapper)
 {
     while (wrapper && ![wrapper isAccessibilityElement]) {
@@ -1889,6 +1892,17 @@ static void appendStringToResult(NSMutableString *result, NSString *string)
     return m_object->isAttachment();
 }
 
+- (NSString *)accessibilityTextualContext
+{
+    if (![self _prepareAccessibilityCall])
+        return nil;
+
+    if (m_object->node() && m_object->node()->hasTagName(codeTag))
+        return UIAccessibilityTextualContextSourceCode;
+    
+    return nil;
+}
+
 - (void)_accessibilityActivate
 {
     if (![self _prepareAccessibilityCall])
@@ -2256,6 +2270,15 @@ static void AXAttributeStringSetStyle(NSMutableAttributedString* attrString, Ren
     auto decor = style.textDecorationsInEffect();
     if (decor & TextDecoration::Underline)
         AXAttributeStringSetNumber(attrString, UIAccessibilityTokenUnderline, @YES, range);
+
+    // Add code context if this node is within a <code> block.
+    AccessibilityObject* axObject = renderer->document().axObjectCache()->getOrCreate(renderer);
+    auto matchFunc = [] (const AccessibilityObject& object) {
+        return object.node() && object.node()->hasTagName(codeTag);
+    };
+    
+    if (const AccessibilityObject* parent = AccessibilityObject::matchedParent(*axObject, true, WTFMove(matchFunc)))
+        [attrString addAttribute:UIAccessibilityTextAttributeContext value:UIAccessibilityTextualContextSourceCode range:range];
 }
 
 static void AXAttributedStringAppendText(NSMutableAttributedString* attrString, Node* node, NSString *text)
index 27068b8..0eb761c 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-17  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: Certain tags should identify their context to iOS API
+        https://bugs.webkit.org/show_bug.cgi?id=190622
+        <rdar://problem/45308194>
+
+        Reviewed by Zalan Bujtas.
+
+        * DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
+        (AccessibilityUIElement::stringAttributeValue):
+        * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+        (WTR::AccessibilityUIElement::stringAttributeValue):
+
 2018-10-16  Sihui Liu  <sihui_liu@apple.com>
 
         Add a switch for Web SQL
index c94814b..8bd6f2f 100644 (file)
@@ -102,6 +102,7 @@ AccessibilityUIElement::~AccessibilityUIElement()
 - (NSArray *)accessibilityFindMatchingObjects:(NSDictionary *)parameters;
 - (NSArray *)accessibilitySpeechHint;
 - (BOOL)_accessibilityIsStrongPasswordField;
+- (NSString *)accessibilityTextualContext;
 
 // TextMarker related
 - (NSArray *)textMarkerRange;
@@ -701,6 +702,9 @@ JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(JSStringRe
     if (JSStringIsEqualToUTF8CString(attribute, "AXSortDirection"))
         return [[m_element accessibilitySortDirection] createJSStringRef];
     
+    if (JSStringIsEqualToUTF8CString(attribute, "AXTextualContext"))
+        return [[m_element accessibilityTextualContext] createJSStringRef];
+    
     return createEmptyJSString();
 }
 
index a6e1f86..9f8108a 100644 (file)
@@ -81,6 +81,7 @@ typedef void (*AXPostedNotificationCallback)(id element, NSString* notification,
 - (NSArray<NSString *> *)accessibilitySpeechHint;
 - (BOOL)_accessibilityIsStrongPasswordField;
 - (CGRect)accessibilityVisibleContentRect;
+- (NSString *)accessibilityTextualContext;
 
 // TextMarker related
 - (NSArray *)textMarkerRange;
@@ -367,6 +368,9 @@ JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(JSStringRe
         return [rectStr createJSStringRef];
     }
 
+    if (JSStringIsEqualToUTF8CString(attribute, "AXTextualContext"))
+        return [[m_element accessibilityTextualContext] createJSStringRef];
+    
     return createEmptyJSString();
 }