Title: [244059] trunk
Revision
244059
Author
cfleiz...@apple.com
Date
2019-04-08 17:39:50 -0700 (Mon, 08 Apr 2019)

Log Message

AX: Support API: accessibilityReplaceRange:withText
https://bugs.webkit.org/show_bug.cgi?id=196636

Reviewed by Daniel Bates.

Source/WebCore:

Support this platform API on mac to provide a way to replace a range of editable text.

Test: accessibility/mac/replace-text-with-range.html

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::replaceTextInRange):
* accessibility/AccessibilityObject.h:
* accessibility/mac/AccessibilityObjectBase.mm:
(WebCore::PlainTextRange::PlainTextRange):
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper accessibilityReplaceRange:withText:]):

Tools:

* DumpRenderTree/AccessibilityUIElement.cpp:
(replaceTextInRangeCallback):
(AccessibilityUIElement::replaceTextInRange):
(AccessibilityUIElement::getJSClass):
* DumpRenderTree/AccessibilityUIElement.h:
* DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
(AccessibilityUIElement::replaceTextInRange):
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
(AccessibilityUIElement::replaceTextInRange):
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
* WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
* WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
(WTR::AccessibilityUIElement::replaceTextInRange):
* WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
(WTR::AccessibilityUIElement::replaceTextInRange):

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/accessibility/mac/replace-text-with-range-expected.txt (0 => 244059)


--- trunk/LayoutTests/accessibility/mac/replace-text-with-range-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/accessibility/mac/replace-text-with-range-expected.txt	2019-04-09 00:39:50 UTC (rev 244059)
@@ -0,0 +1,17 @@
+This tests that the replace with range API functions as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS contenteditable.replaceTextInRange("Blurb", 5, 5) is true
+PASS contenteditable.stringValue is 'AXValue: HelloBlurb'
+PASS contenteditable.replaceTextInRange("Blorg", 5, 5) is true
+PASS contenteditable.stringValue is 'AXValue: HelloBlorg'
+PASS text.replaceTextInRange("blurb", 6, 5) is true
+PASS text.stringValue is 'AXValue: Hello blurb'
+PASS textarea.replaceTextInRange("blurb", 6, 5) is true
+PASS textarea.stringValue is 'AXValue: Hello blurb'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/accessibility/mac/replace-text-with-range.html (0 => 244059)


--- trunk/LayoutTests/accessibility/mac/replace-text-with-range.html	                        (rev 0)
+++ trunk/LayoutTests/accessibility/mac/replace-text-with-range.html	2019-04-09 00:39:50 UTC (rev 244059)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body id="body">
+<div id="content">
+
+<div id="contenteditable" contenteditable="true" role="textbox">HelloWorld</div>
+<input type="text" id="text" value="Hello world">
+<textarea id="textarea">Hello world</textarea>
+</div>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests that the replace with range API functions as expected.");
+
+    if (window.accessibilityController) {
+        var contenteditable = accessibilityController.accessibleElementById("contenteditable");
+        shouldBeTrue('contenteditable.replaceTextInRange("Blurb", 5, 5)');
+        shouldBe("contenteditable.stringValue", "'AXValue: HelloBlurb'");
+
+        // now test what happens when a control has focus
+        document.getElementById("contenteditable").focus();
+        shouldBeTrue('contenteditable.replaceTextInRange("Blorg", 5, 5)');
+        shouldBe("contenteditable.stringValue", "'AXValue: HelloBlorg'");
+        document.getElementById("contenteditable").blur();
+
+        var text = accessibilityController.accessibleElementById("text");
+        shouldBeTrue('text.replaceTextInRange("blurb", 6, 5)');
+        shouldBe("text.stringValue", "'AXValue: Hello blurb'");
+
+        var textarea = accessibilityController.accessibleElementById("textarea");
+        shouldBeTrue('textarea.replaceTextInRange("blurb", 6, 5)');
+        shouldBe("textarea.stringValue", "'AXValue: Hello blurb'");
+
+        document.getElementById("content").style.visibility = "hidden";
+    }
+
+</script>
+
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (244058 => 244059)


--- trunk/Source/WebCore/ChangeLog	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Source/WebCore/ChangeLog	2019-04-09 00:39:50 UTC (rev 244059)
@@ -1,3 +1,22 @@
+2019-04-08  Chris Fleizach  <cfleiz...@apple.com>
+
+        AX: Support API: accessibilityReplaceRange:withText
+        https://bugs.webkit.org/show_bug.cgi?id=196636
+
+        Reviewed by Daniel Bates.
+
+        Support this platform API on mac to provide a way to replace a range of editable text.
+
+        Test: accessibility/mac/replace-text-with-range.html
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::replaceTextInRange):
+        * accessibility/AccessibilityObject.h:
+        * accessibility/mac/AccessibilityObjectBase.mm:
+        (WebCore::PlainTextRange::PlainTextRange):
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper accessibilityReplaceRange:withText:]):
+
 2019-04-08  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS] Do not allow starting selection drags when selection views are not visible

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (244058 => 244059)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2019-04-09 00:39:50 UTC (rev 244059)
@@ -2274,7 +2274,35 @@
     auto event = Event::create(eventName, Event::CanBubble::Yes, Event::IsCancelable::Yes);
     return dispatchAccessibilityEvent(event);
 }
+    
+bool AccessibilityObject::replaceTextInRange(const String& replacementString, const PlainTextRange& range)
+{
+    if (!renderer() || !is<Element>(node()))
+        return false;
 
+    auto& element = downcast<Element>(*renderer()->node());
+
+    // We should use the editor's insertText to mimic typing into the field.
+    // Also only do this when the field is in editing mode.
+    auto& frame = renderer()->frame();
+    if (element.shouldUseInputMethod()) {
+        frame.selection().setSelectedRange(rangeForPlainTextRange(range).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
+        frame.editor().replaceSelectionWithText(replacementString, Editor::SelectReplacement::No, Editor::SmartReplace::No);
+        return true;
+    }
+    
+    if (is<HTMLInputElement>(element)) {
+        downcast<HTMLInputElement>(element).setRangeText(replacementString, range.start, range.length, "");
+        return true;
+    }
+    if (is<HTMLTextAreaElement>(element)) {
+        downcast<HTMLTextAreaElement>(element).setRangeText(replacementString, range.start, range.length, "");
+        return true;
+    }
+
+    return false;
+}
+    
 bool AccessibilityObject::dispatchAccessibleSetValueEvent(const String& value) const
 {
     if (!canSetValueAttribute())

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.h (244058 => 244059)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.h	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.h	2019-04-09 00:39:50 UTC (rev 244059)
@@ -297,6 +297,10 @@
         , length(l)
     { }
     
+#if PLATFORM(COCOA)
+    PlainTextRange(NSRange);
+#endif
+    
     bool isNull() const { return !start && !length; }
 };
 
@@ -701,6 +705,8 @@
     virtual void setSelectedText(const String&) { }
     virtual void setSelectedTextRange(const PlainTextRange&) { }
     virtual void setValue(const String&) { }
+    bool replaceTextInRange(const String&, const PlainTextRange&);
+
     virtual void setValue(float) { }
     virtual void setSelected(bool) { }
     virtual void setSelectedRows(AccessibilityChildrenVector&) { }

Modified: trunk/Source/WebCore/accessibility/mac/AccessibilityObjectBase.mm (244058 => 244059)


--- trunk/Source/WebCore/accessibility/mac/AccessibilityObjectBase.mm	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Source/WebCore/accessibility/mac/AccessibilityObjectBase.mm	2019-04-09 00:39:50 UTC (rev 244059)
@@ -32,6 +32,12 @@
 
 namespace WebCore {
 
+PlainTextRange::PlainTextRange(NSRange r)
+    : start(r.location)
+    , length(r.length)
+{
+}
+    
 String AccessibilityObject::speechHintAttributeValue() const
 {
     auto speak = speakAsProperty();

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (244058 => 244059)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2019-04-09 00:39:50 UTC (rev 244059)
@@ -3642,6 +3642,14 @@
         [self accessibilityScrollToVisible];
 }
 
+- (BOOL)accessibilityReplaceRange:(NSRange)range withText:(NSString *)string
+{
+    if (![self updateObjectBackingStore])
+        return NO;
+    
+    return m_object->replaceTextInRange(string, PlainTextRange(range));
+}
+
 IGNORE_WARNINGS_BEGIN("deprecated-implementations")
 - (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attributeName
 IGNORE_WARNINGS_END

Modified: trunk/Tools/ChangeLog (244058 => 244059)


--- trunk/Tools/ChangeLog	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/ChangeLog	2019-04-09 00:39:50 UTC (rev 244059)
@@ -1,3 +1,26 @@
+2019-04-08  Chris Fleizach  <cfleiz...@apple.com>
+
+        AX: Support API: accessibilityReplaceRange:withText
+        https://bugs.webkit.org/show_bug.cgi?id=196636
+
+        Reviewed by Daniel Bates.
+
+        * DumpRenderTree/AccessibilityUIElement.cpp:
+        (replaceTextInRangeCallback):
+        (AccessibilityUIElement::replaceTextInRange):
+        (AccessibilityUIElement::getJSClass):
+        * DumpRenderTree/AccessibilityUIElement.h:
+        * DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
+        (AccessibilityUIElement::replaceTextInRange):
+        * DumpRenderTree/mac/AccessibilityUIElementMac.mm:
+        (AccessibilityUIElement::replaceTextInRange):
+        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+        * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+        (WTR::AccessibilityUIElement::replaceTextInRange):
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+        (WTR::AccessibilityUIElement::replaceTextInRange):
+
 2019-04-08  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS] Do not allow starting selection drags when selection views are not visible

Modified: trunk/Tools/DumpRenderTree/AccessibilityUIElement.cpp (244058 => 244059)


--- trunk/Tools/DumpRenderTree/AccessibilityUIElement.cpp	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/DumpRenderTree/AccessibilityUIElement.cpp	2019-04-09 00:39:50 UTC (rev 244059)
@@ -806,6 +806,18 @@
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef replaceTextInRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    if (argumentCount < 3)
+        return JSValueMakeUndefined(context);
+
+    auto text = adopt(JSValueToStringCopy(context, arguments[0], exception));
+    int position = JSValueToNumber(context, arguments[1], exception);
+    int length = JSValueToNumber(context, arguments[2], exception);
+
+    return JSValueMakeBoolean(context, toAXElement(thisObject)->replaceTextInRange(text.get(), position, length));
+}
+
 static JSValueRef attributedStringForTextMarkerRangeContainsAttributeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     AccessibilityTextMarkerRange* markerRange = 0;
@@ -1609,6 +1621,11 @@
 {
 }
 
+void AccessibilityUIElement::replaceTextInRange(JSStringRef, int, int)
+{
+    return false;
+}
+
 int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange*)
 {
     return 0;
@@ -1931,6 +1948,7 @@
         { "textMarkerRangeForElement", textMarkerRangeForElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "selectedTextMarkerRange", selectedTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "resetSelectedTextMarkerRange", resetSelectedTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "replaceTextInRange", replaceTextInRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "attributedStringForTextMarkerRangeContainsAttribute", attributedStringForTextMarkerRangeContainsAttributeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "indexForTextMarker", indexForTextMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "isTextMarkerValid", isTextMarkerValidCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },

Modified: trunk/Tools/DumpRenderTree/AccessibilityUIElement.h (244058 => 244059)


--- trunk/Tools/DumpRenderTree/AccessibilityUIElement.h	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/DumpRenderTree/AccessibilityUIElement.h	2019-04-09 00:39:50 UTC (rev 244059)
@@ -277,7 +277,8 @@
     AccessibilityTextMarkerRange selectedTextMarkerRange();
     void resetSelectedTextMarkerRange();
     bool setSelectedVisibleTextRange(AccessibilityTextMarkerRange*);
-    
+    bool replaceTextInRange(JSStringRef, int position, int length);
+
     JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
     JSRetainPtr<JSStringRef> attributedStringForTextMarkerRange(AccessibilityTextMarkerRange*);
     JSRetainPtr<JSStringRef> attributedStringForTextMarkerRangeWithOptions(AccessibilityTextMarkerRange*, bool includeSpellCheck);

Modified: trunk/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm (244058 => 244059)


--- trunk/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm	2019-04-09 00:39:50 UTC (rev 244059)
@@ -477,6 +477,11 @@
     return nullptr;
 }
 
+bool AccessibilityUIElement::replaceTextInRange(JSStringRef, int, int)
+{
+    return false;
+}
+
 void AccessibilityUIElement::resetSelectedTextMarkerRange()
 {
 }

Modified: trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm (244058 => 244059)


--- trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm	2019-04-09 00:39:50 UTC (rev 244059)
@@ -70,6 +70,7 @@
 typedef void (*AXPostedNotificationCallback)(id element, NSString* notification, void* context);
 
 @interface NSObject (WebKitAccessibilityAdditions)
+- (BOOL)accessibilityReplaceRange:(NSRange)range withText:(NSString *)string;
 - (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
 - (NSUInteger)accessibilityIndexOfChild:(id)child;
 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute;
@@ -1633,6 +1634,14 @@
     END_AX_OBJC_EXCEPTIONS
 }
 
+bool AccessibilityUIElement::replaceTextInRange(JSStringRef string, int location, int length)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    return [m_element accessibilityReplaceRange:NSMakeRange(location, length) withText:[NSString stringWithJSStringRef:string]];
+    END_AX_OBJC_EXCEPTIONS
+    return false;
+}
+
 int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
 {
     BEGIN_AX_OBJC_EXCEPTIONS

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h (244058 => 244059)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h	2019-04-09 00:39:50 UTC (rev 244059)
@@ -279,6 +279,7 @@
     RefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
     RefPtr<AccessibilityTextMarkerRange> selectedTextMarkerRange();
     void resetSelectedTextMarkerRange();
+    bool replaceTextInRange(JSStringRef, int position, int length);
     RefPtr<AccessibilityTextMarker> startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
     RefPtr<AccessibilityTextMarker> endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
     RefPtr<AccessibilityTextMarker> endTextMarkerForBounds(int x, int y, int width, int height);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl (244058 => 244059)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl	2019-04-09 00:39:50 UTC (rev 244059)
@@ -205,6 +205,7 @@
     AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker startMarker, AccessibilityTextMarker endMarker);
     AccessibilityTextMarkerRange selectedTextMarkerRange();
     void resetSelectedTextMarkerRange();
+    boolean replaceTextInRange(DOMString string, long position, long length);
     AccessibilityTextMarker startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange range);
     AccessibilityTextMarker endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange range);
     AccessibilityTextMarker endTextMarkerForBounds(long x, long y, long width, long height);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm (244058 => 244059)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm	2019-04-09 00:39:50 UTC (rev 244059)
@@ -1144,6 +1144,11 @@
 {
     return nullptr;
 }
+    
+bool AccessibilityUIElement::replaceTextInRange(JSStringRef, int, int)
+{
+    return false;
+}
 
 RefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForPoint(int x, int y)
 {

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm (244058 => 244059)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2019-04-09 00:00:24 UTC (rev 244058)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2019-04-09 00:39:50 UTC (rev 244059)
@@ -74,6 +74,7 @@
 typedef void (*AXPostedNotificationCallback)(id element, NSString* notification, void* context);
 
 @interface NSObject (WebKitAccessibilityAdditions)
+- (BOOL)accessibilityReplaceRange:(NSRange)range withText:(NSString *)string;
 - (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
 - (NSUInteger)accessibilityIndexOfChild:(id)child;
 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute;
@@ -1806,6 +1807,14 @@
     return nullptr;
 }
 
+bool AccessibilityUIElement::replaceTextInRange(JSStringRef string, int location, int length)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    return [m_element accessibilityReplaceRange:NSMakeRange(location, length) withText:[NSString stringWithJSStringRef:string]];
+    END_AX_OBJC_EXCEPTIONS
+    return false;
+}
+    
 RefPtr<AccessibilityTextMarker> AccessibilityUIElement::startTextMarkerForBounds(int x, int y, int width, int height)
 {
     BEGIN_AX_OBJC_EXCEPTIONS
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to