AX: [iOS] add support to return the attributed string under the element
authorn_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2018 23:54:45 +0000 (23:54 +0000)
committern_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2018 23:54:45 +0000 (23:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188276
<rdar://problem/42872357>

Reviewed by Chris Fleizach.

Source/WebCore:

Provided a way on iOS to return the attributed string under the element for
better performance.

Test: accessibility/ios-simulator/attributed-string-for-element.html

* accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(-[WebAccessibilityObjectWrapper _stringFromStartMarker:toEndMarker:attributed:]):
(-[WebAccessibilityObjectWrapper _stringForRange:attributed:]):
(-[WebAccessibilityObjectWrapper attributedStringForElement]):

Tools:

* DumpRenderTree/AccessibilityUIElement.cpp:
(attributedStringForElementCallback):
(AccessibilityUIElement::getJSClass):
* DumpRenderTree/AccessibilityUIElement.h:
* DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
(AccessibilityUIElement::attributedStringForElement):
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
(WTR::AccessibilityUIElement::attributedStringForElement):
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
* WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
* WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
(WTR::AccessibilityUIElement::attributedStringForElement):

LayoutTests:

* accessibility/ios-simulator/attributed-string-for-element-expected.txt: Added.
* accessibility/ios-simulator/attributed-string-for-element.html: Added.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/accessibility/ios-simulator/attributed-string-for-element-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/ios-simulator/attributed-string-for-element.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm
Tools/ChangeLog
Tools/DumpRenderTree/AccessibilityUIElement.cpp
Tools/DumpRenderTree/AccessibilityUIElement.h
Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm
Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp
Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h
Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl
Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm

index c941428..a92b983 100644 (file)
@@ -1,3 +1,14 @@
+2018-08-02  Nan Wang  <n_wang@apple.com>
+
+        AX: [iOS] add support to return the attributed string under the element
+        https://bugs.webkit.org/show_bug.cgi?id=188276
+        <rdar://problem/42872357>
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/ios-simulator/attributed-string-for-element-expected.txt: Added.
+        * accessibility/ios-simulator/attributed-string-for-element.html: Added.
+
 2018-08-02  Tim Horton  <timothy_horton@apple.com>
 
         REGRESSION (r234488): Layout test fast/events/ios/keyboard-scrolling-repeat.html is timing out
diff --git a/LayoutTests/accessibility/ios-simulator/attributed-string-for-element-expected.txt b/LayoutTests/accessibility/ios-simulator/attributed-string-for-element-expected.txt
new file mode 100644 (file)
index 0000000..8c2851c
--- /dev/null
@@ -0,0 +1,29 @@
+hello world test bold
+This test ensures that attributed string under the element works
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Attributed string: hello {
+    UIAccessibilityTokenFontFamily = "Times New Roman";
+    UIAccessibilityTokenFontName = "Times New Roman";
+    UIAccessibilityTokenFontSize = 16;
+}world{
+    UIAccessibilityTokenBold = 1;
+    UIAccessibilityTokenFontFamily = "Times New Roman";
+    UIAccessibilityTokenFontName = "Times New Roman Bold";
+    UIAccessibilityTokenFontSize = 16;
+} test {
+    UIAccessibilityTokenFontFamily = "Times New Roman";
+    UIAccessibilityTokenFontName = "Times New Roman";
+    UIAccessibilityTokenFontSize = 16;
+}bold{
+    UIAccessibilityTokenBold = 1;
+    UIAccessibilityTokenFontFamily = "Times New Roman";
+    UIAccessibilityTokenFontName = "Times New Roman Bold";
+    UIAccessibilityTokenFontSize = 16;
+}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/ios-simulator/attributed-string-for-element.html b/LayoutTests/accessibility/ios-simulator/attributed-string-for-element.html
new file mode 100644 (file)
index 0000000..0805dc1
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<body id="body">
+
+<div id="content">
+hello <b>world</b> test <b>bold</b>
+</div>
+
+<p id="description"></p>
+<div id="console"></div>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+
+    description("This test ensures that attributed string under the element works");
+
+    if (window.accessibilityController) {
+
+        var obj = accessibilityController.accessibleElementById("content");
+        var text = obj.attributedStringForElement();
+        debug("Attributed string: " + text);
+    }
+
+    successfullyParsed = true;
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
index 363bbae..ebb52ac 100644 (file)
@@ -1,3 +1,21 @@
+2018-08-02  Nan Wang  <n_wang@apple.com>
+
+        AX: [iOS] add support to return the attributed string under the element
+        https://bugs.webkit.org/show_bug.cgi?id=188276
+        <rdar://problem/42872357>
+
+        Reviewed by Chris Fleizach.
+
+        Provided a way on iOS to return the attributed string under the element for 
+        better performance.
+
+        Test: accessibility/ios-simulator/attributed-string-for-element.html
+
+        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+        (-[WebAccessibilityObjectWrapper _stringFromStartMarker:toEndMarker:attributed:]):
+        (-[WebAccessibilityObjectWrapper _stringForRange:attributed:]):
+        (-[WebAccessibilityObjectWrapper attributedStringForElement]):
+
 2018-08-02  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][Floating] Remove redundant LayoutContext member variable.
index 50d9522..0e07835 100644 (file)
@@ -2514,26 +2514,11 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     return [WebAccessibilityTextMarker textMarkerWithCharacterOffset:characterOffset cache:cache];
 }
 
-- (id)_stringForRange:(NSRange)range attributed:(BOOL)attributed
+- (id)_stringFromStartMarker:(WebAccessibilityTextMarker*)startMarker toEndMarker:(WebAccessibilityTextMarker*)endMarker attributed:(BOOL)attributed
 {
-    if (![self _prepareAccessibilityCall])
+    if (!startMarker || !endMarker)
         return nil;
     
-    WebAccessibilityTextMarker* startMarker = [self textMarkerForPosition:range.location];
-    WebAccessibilityTextMarker* endMarker = [self textMarkerForPosition:NSMaxRange(range)];
-    
-    // Clients don't always know the exact range, rather than force them to compute it,
-    // allow clients to overshoot and use the max text marker range.
-    if (!startMarker || !endMarker) {
-        NSArray *markers = [self textMarkerRange];
-        if ([markers count] != 2)
-            return nil;
-        if (!startMarker)
-            startMarker = [markers objectAtIndex:0];
-        if (!endMarker)
-            endMarker = [markers objectAtIndex:1];
-    }
-    
     NSArray* array = [self arrayOfTextForTextMarkers:[NSArray arrayWithObjects:startMarker, endMarker, nil] attributed:attributed];
     Class returnClass = attributed ? [NSMutableAttributedString class] : [NSMutableString class];
     id returnValue = [[(NSString *)[returnClass alloc] init] autorelease];
@@ -2557,6 +2542,29 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     return returnValue;
 }
 
+- (id)_stringForRange:(NSRange)range attributed:(BOOL)attributed
+{
+    if (![self _prepareAccessibilityCall])
+        return nil;
+    
+    WebAccessibilityTextMarker* startMarker = [self textMarkerForPosition:range.location];
+    WebAccessibilityTextMarker* endMarker = [self textMarkerForPosition:NSMaxRange(range)];
+    
+    // Clients don't always know the exact range, rather than force them to compute it,
+    // allow clients to overshoot and use the max text marker range.
+    if (!startMarker || !endMarker) {
+        NSArray *markers = [self textMarkerRange];
+        if ([markers count] != 2)
+            return nil;
+        if (!startMarker)
+            startMarker = [markers objectAtIndex:0];
+        if (!endMarker)
+            endMarker = [markers objectAtIndex:1];
+    }
+    
+    return [self _stringFromStartMarker:startMarker toEndMarker:endMarker attributed:attributed];
+}
+
 
 // A convenience method for getting the text of a NSRange. Currently used only by DRT.
 - (NSString *)stringForRange:(NSRange)range
@@ -2569,6 +2577,18 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     return [self _stringForRange:range attributed:YES];
 }
 
+- (NSAttributedString *)attributedStringForElement
+{
+    if (![self _prepareAccessibilityCall])
+        return nil;
+    
+    NSArray *markers = [self textMarkerRange];
+    if ([markers count] != 2)
+        return nil;
+    
+    return [self _stringFromStartMarker:markers.firstObject toEndMarker:markers.lastObject attributed:YES];
+}
+
 - (NSRange)_accessibilitySelectedTextRange
 {
     if (![self _prepareAccessibilityCall] || !m_object->isTextControl())
index 6f15cc5..faadf2f 100644 (file)
@@ -1,3 +1,24 @@
+2018-08-02  Nan Wang  <n_wang@apple.com>
+
+        AX: [iOS] add support to return the attributed string under the element
+        https://bugs.webkit.org/show_bug.cgi?id=188276
+        <rdar://problem/42872357>
+
+        Reviewed by Chris Fleizach.
+
+        * DumpRenderTree/AccessibilityUIElement.cpp:
+        (attributedStringForElementCallback):
+        (AccessibilityUIElement::getJSClass):
+        * DumpRenderTree/AccessibilityUIElement.h:
+        * DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
+        (AccessibilityUIElement::attributedStringForElement):
+        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
+        (WTR::AccessibilityUIElement::attributedStringForElement):
+        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+        * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+        (WTR::AccessibilityUIElement::attributedStringForElement):
+
 2018-08-02  Ryan Haddad  <ryanhaddad@apple.com>
 
         Skip API test DataInteractionTests.CustomActionSheetPopover on current SDKs.
index ea8ee9c..f66c133 100644 (file)
@@ -369,6 +369,12 @@ static JSValueRef fieldsetAncestorElementCallback(JSContextRef context, JSObject
     return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->fieldsetAncestorElement());
 }
 
+static JSValueRef attributedStringForElementCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    JSRetainPtr<JSStringRef> stringDescription(Adopt, toAXElement(thisObject)->attributedStringForElement());
+    return JSValueMakeString(context, stringDescription.get());
+}
+
 #endif
 
 static JSValueRef childAtIndexCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
@@ -1980,6 +1986,7 @@ JSClassRef AccessibilityUIElement::getJSClass()
         { "assistiveTechnologySimulatedFocus", assistiveTechnologySimulatedFocusCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "fieldsetAncestorElement", fieldsetAncestorElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "textMarkerRangeMatchesTextNearMarkers", textMarkerRangeMatchesTextNearMarkersCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "attributedStringForElement", attributedStringForElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
 #endif
         { 0, 0, 0 }
     };
index 7d4d1d4..634ce8a 100644 (file)
@@ -232,6 +232,7 @@ public:
     
     bool hasContainedByFieldsetTrait();
     AccessibilityUIElement fieldsetAncestorElement();
+    JSStringRef attributedStringForElement();
 #endif
 
 #if PLATFORM(GTK)
index ff5e486..bb6969e 100644 (file)
@@ -74,6 +74,7 @@ AccessibilityUIElement::~AccessibilityUIElement()
 - (NSString *)accessibilityPlaceholderValue;
 - (NSString *)stringForRange:(NSRange)range;
 - (NSAttributedString *)attributedStringForRange:(NSRange)range;
+- (NSAttributedString *)attributedStringForElement;
 - (NSArray *)elementsForRange:(NSRange)range;
 - (NSString *)selectionRangeString;
 - (CGPoint)accessibilityClickPoint;
@@ -393,6 +394,15 @@ JSStringRef AccessibilityUIElement::attributedStringForRange(unsigned location,
     return [stringWithAttrs createJSStringRef];
 }
 
+JSStringRef AccessibilityUIElement::attributedStringForElement()
+{
+    NSAttributedString *string = [m_element attributedStringForElement];
+    if (![string isKindOfClass:[NSAttributedString class]])
+        return nullptr;
+    
+    return [[string description] createJSStringRef];
+}
+
 bool AccessibilityUIElement::attributedStringRangeIsMisspelled(unsigned, unsigned)
 {
     return false;
index dc54747..e619555 100644 (file)
@@ -76,6 +76,7 @@ bool AccessibilityUIElement::isSearchField() const { return false; }
 bool AccessibilityUIElement::isTextArea() const { return false; }
 RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeMatchesTextNearMarkers(JSStringRef, AccessibilityTextMarker*, AccessibilityTextMarker*) { return nullptr; }
 bool AccessibilityUIElement::dismiss() { return false; }
+JSRetainPtr<JSStringRef> AccessibilityUIElement::attributedStringForElement() { return nullptr; }
 #endif
     
 // Unsupported methods on various platforms. As they're implemented on other platforms this list should be modified.
index cb9317a..b00c549 100644 (file)
@@ -248,6 +248,8 @@ public:
     bool setSelectedTextRange(unsigned location, unsigned length);
     JSRetainPtr<JSStringRef> stringForRange(unsigned location, unsigned length);
     JSRetainPtr<JSStringRef> attributedStringForRange(unsigned location, unsigned length);
+    JSRetainPtr<JSStringRef> attributedStringForElement();
+
     bool attributedStringRangeIsMisspelled(unsigned location, unsigned length);
     unsigned uiElementCountForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);
     RefPtr<AccessibilityUIElement> uiElementForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);
index 80462bd..7d5d69d 100644 (file)
@@ -177,6 +177,7 @@ interface AccessibilityUIElement {
     DOMString boundsForRange(unsigned long location, unsigned long length);
     DOMString stringForRange(unsigned long location, unsigned long length);
     DOMString attributedStringForRange(unsigned long location, unsigned long length);
+    DOMString attributedStringForElement();
     boolean attributedStringRangeIsMisspelled(unsigned long location, unsigned long length);
     [PassContext] unsigned long uiElementCountForSearchPredicate(AccessibilityUIElement startElement, boolean isDirectionNext, object searchKey, DOMString searchText, boolean visibleOnly, boolean immediateDescendantsOnly);
     [PassContext] AccessibilityUIElement uiElementForSearchPredicate(AccessibilityUIElement startElement, boolean isDirectionNext, object searchKey, DOMString searchText, boolean visibleOnly, boolean immediateDescendantsOnly);
index d67ee44..c5e5e6c 100644 (file)
@@ -52,6 +52,7 @@ typedef void (*AXPostedNotificationCallback)(id element, NSString* notification,
 - (NSString *)accessibilityPlaceholderValue;
 - (NSString *)stringForRange:(NSRange)range;
 - (NSAttributedString *)attributedStringForRange:(NSRange)range;
+- (NSAttributedString *)attributedStringForElement;
 - (NSArray *)elementsForRange:(NSRange)range;
 - (NSString *)selectionRangeString;
 - (CGPoint)accessibilityClickPoint;
@@ -661,6 +662,15 @@ JSRetainPtr<JSStringRef> AccessibilityUIElement::attributedStringForRange(unsign
     return [[stringForRange description] createJSStringRef];
 }
 
+JSRetainPtr<JSStringRef> AccessibilityUIElement::attributedStringForElement()
+{
+    NSAttributedString *string = [m_element attributedStringForElement];
+    if (![string isKindOfClass:[NSAttributedString class]])
+        return nullptr;
+    
+    return [[string description] createJSStringRef];
+}
+
 bool AccessibilityUIElement::attributedStringRangeIsMisspelled(unsigned location, unsigned length)
 {
     return false;