⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 244059 in webkit


Ignore:
Timestamp:
Apr 8, 2019, 5:39:50 PM (7 years ago)
Author:
Chris Fleizach
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):

Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r244056 r244059  
     12019-04-08  Chris Fleizach  <cfleizach@apple.com>
     2
     3        AX: Support API: accessibilityReplaceRange:withText
     4        https://bugs.webkit.org/show_bug.cgi?id=196636
     5
     6        Reviewed by Daniel Bates.
     7
     8        Support this platform API on mac to provide a way to replace a range of editable text.
     9
     10        Test: accessibility/mac/replace-text-with-range.html
     11
     12        * accessibility/AccessibilityObject.cpp:
     13        (WebCore::AccessibilityObject::replaceTextInRange):
     14        * accessibility/AccessibilityObject.h:
     15        * accessibility/mac/AccessibilityObjectBase.mm:
     16        (WebCore::PlainTextRange::PlainTextRange):
     17        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
     18        (-[WebAccessibilityObjectWrapper accessibilityReplaceRange:withText:]):
     19
    1202019-04-08  Wenson Hsieh  <wenson_hsieh@apple.com>
    221
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r243198 r244059  
    22752275    return dispatchAccessibilityEvent(event);
    22762276}
    2277 
     2277   
     2278bool AccessibilityObject::replaceTextInRange(const String& replacementString, const PlainTextRange& range)
     2279{
     2280    if (!renderer() || !is<Element>(node()))
     2281        return false;
     2282
     2283    auto& element = downcast<Element>(*renderer()->node());
     2284
     2285    // We should use the editor's insertText to mimic typing into the field.
     2286    // Also only do this when the field is in editing mode.
     2287    auto& frame = renderer()->frame();
     2288    if (element.shouldUseInputMethod()) {
     2289        frame.selection().setSelectedRange(rangeForPlainTextRange(range).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
     2290        frame.editor().replaceSelectionWithText(replacementString, Editor::SelectReplacement::No, Editor::SmartReplace::No);
     2291        return true;
     2292    }
     2293   
     2294    if (is<HTMLInputElement>(element)) {
     2295        downcast<HTMLInputElement>(element).setRangeText(replacementString, range.start, range.length, "");
     2296        return true;
     2297    }
     2298    if (is<HTMLTextAreaElement>(element)) {
     2299        downcast<HTMLTextAreaElement>(element).setRangeText(replacementString, range.start, range.length, "");
     2300        return true;
     2301    }
     2302
     2303    return false;
     2304}
     2305   
    22782306bool AccessibilityObject::dispatchAccessibleSetValueEvent(const String& value) const
    22792307{
  • trunk/Source/WebCore/accessibility/AccessibilityObject.h

    r243928 r244059  
    297297        , length(l)
    298298    { }
     299   
     300#if PLATFORM(COCOA)
     301    PlainTextRange(NSRange);
     302#endif
    299303   
    300304    bool isNull() const { return !start && !length; }
     
    702706    virtual void setSelectedTextRange(const PlainTextRange&) { }
    703707    virtual void setValue(const String&) { }
     708    bool replaceTextInRange(const String&, const PlainTextRange&);
     709
    704710    virtual void setValue(float) { }
    705711    virtual void setSelected(bool) { }
  • trunk/Source/WebCore/accessibility/mac/AccessibilityObjectBase.mm

    r241321 r244059  
    3333namespace WebCore {
    3434
     35PlainTextRange::PlainTextRange(NSRange r)
     36    : start(r.location)
     37    , length(r.length)
     38{
     39}
     40   
    3541String AccessibilityObject::speechHintAttributeValue() const
    3642{
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r242051 r244059  
    36433643}
    36443644
     3645- (BOOL)accessibilityReplaceRange:(NSRange)range withText:(NSString *)string
     3646{
     3647    if (![self updateObjectBackingStore])
     3648        return NO;
     3649   
     3650    return m_object->replaceTextInRange(string, PlainTextRange(range));
     3651}
     3652
    36453653IGNORE_WARNINGS_BEGIN("deprecated-implementations")
    36463654- (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attributeName
  • trunk/Tools/ChangeLog

    r244056 r244059  
     12019-04-08  Chris Fleizach  <cfleizach@apple.com>
     2
     3        AX: Support API: accessibilityReplaceRange:withText
     4        https://bugs.webkit.org/show_bug.cgi?id=196636
     5
     6        Reviewed by Daniel Bates.
     7
     8        * DumpRenderTree/AccessibilityUIElement.cpp:
     9        (replaceTextInRangeCallback):
     10        (AccessibilityUIElement::replaceTextInRange):
     11        (AccessibilityUIElement::getJSClass):
     12        * DumpRenderTree/AccessibilityUIElement.h:
     13        * DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
     14        (AccessibilityUIElement::replaceTextInRange):
     15        * DumpRenderTree/mac/AccessibilityUIElementMac.mm:
     16        (AccessibilityUIElement::replaceTextInRange):
     17        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
     18        * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
     19        * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
     20        (WTR::AccessibilityUIElement::replaceTextInRange):
     21        * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
     22        (WTR::AccessibilityUIElement::replaceTextInRange):
     23
    1242019-04-08  Wenson Hsieh  <wenson_hsieh@apple.com>
    225
  • trunk/Tools/DumpRenderTree/AccessibilityUIElement.cpp

    r237266 r244059  
    807807}
    808808
     809static JSValueRef replaceTextInRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     810{
     811    if (argumentCount < 3)
     812        return JSValueMakeUndefined(context);
     813
     814    auto text = adopt(JSValueToStringCopy(context, arguments[0], exception));
     815    int position = JSValueToNumber(context, arguments[1], exception);
     816    int length = JSValueToNumber(context, arguments[2], exception);
     817
     818    return JSValueMakeBoolean(context, toAXElement(thisObject)->replaceTextInRange(text.get(), position, length));
     819}
     820
    809821static JSValueRef attributedStringForTextMarkerRangeContainsAttributeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    810822{
     
    16081620void AccessibilityUIElement::resetSelectedTextMarkerRange()
    16091621{
     1622}
     1623
     1624void AccessibilityUIElement::replaceTextInRange(JSStringRef, int, int)
     1625{
     1626    return false;
    16101627}
    16111628
     
    19321949        { "selectedTextMarkerRange", selectedTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    19331950        { "resetSelectedTextMarkerRange", resetSelectedTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     1951        { "replaceTextInRange", replaceTextInRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    19341952        { "attributedStringForTextMarkerRangeContainsAttribute", attributedStringForTextMarkerRangeContainsAttributeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    19351953        { "indexForTextMarker", indexForTextMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  • trunk/Tools/DumpRenderTree/AccessibilityUIElement.h

    r237266 r244059  
    278278    void resetSelectedTextMarkerRange();
    279279    bool setSelectedVisibleTextRange(AccessibilityTextMarkerRange*);
    280    
     280    bool replaceTextInRange(JSStringRef, int position, int length);
     281
    281282    JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
    282283    JSRetainPtr<JSStringRef> attributedStringForTextMarkerRange(AccessibilityTextMarkerRange*);
  • trunk/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm

    r237266 r244059  
    478478}
    479479
     480bool AccessibilityUIElement::replaceTextInRange(JSStringRef, int, int)
     481{
     482    return false;
     483}
     484
    480485void AccessibilityUIElement::resetSelectedTextMarkerRange()
    481486{
  • trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm

    r240219 r244059  
    7171
    7272@interface NSObject (WebKitAccessibilityAdditions)
     73- (BOOL)accessibilityReplaceRange:(NSRange)range withText:(NSString *)string;
    7374- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
    7475- (NSUInteger)accessibilityIndexOfChild:(id)child;
     
    16341635}
    16351636
     1637bool AccessibilityUIElement::replaceTextInRange(JSStringRef string, int location, int length)
     1638{
     1639    BEGIN_AX_OBJC_EXCEPTIONS
     1640    return [m_element accessibilityReplaceRange:NSMakeRange(location, length) withText:[NSString stringWithJSStringRef:string]];
     1641    END_AX_OBJC_EXCEPTIONS
     1642    return false;
     1643}
     1644
    16361645int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
    16371646{
  • trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h

    r240219 r244059  
    280280    RefPtr<AccessibilityTextMarkerRange> selectedTextMarkerRange();
    281281    void resetSelectedTextMarkerRange();
     282    bool replaceTextInRange(JSStringRef, int position, int length);
    282283    RefPtr<AccessibilityTextMarker> startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
    283284    RefPtr<AccessibilityTextMarker> endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl

    r240219 r244059  
    206206    AccessibilityTextMarkerRange selectedTextMarkerRange();
    207207    void resetSelectedTextMarkerRange();
     208    boolean replaceTextInRange(DOMString string, long position, long length);
    208209    AccessibilityTextMarker startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange range);
    209210    AccessibilityTextMarker endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange range);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm

    r240710 r244059  
    11451145    return nullptr;
    11461146}
     1147   
     1148bool AccessibilityUIElement::replaceTextInRange(JSStringRef, int, int)
     1149{
     1150    return false;
     1151}
    11471152
    11481153RefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForPoint(int x, int y)
  • trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm

    r240219 r244059  
    7575
    7676@interface NSObject (WebKitAccessibilityAdditions)
     77- (BOOL)accessibilityReplaceRange:(NSRange)range withText:(NSString *)string;
    7778- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
    7879- (NSUInteger)accessibilityIndexOfChild:(id)child;
     
    18071808}
    18081809
     1810bool AccessibilityUIElement::replaceTextInRange(JSStringRef string, int location, int length)
     1811{
     1812    BEGIN_AX_OBJC_EXCEPTIONS
     1813    return [m_element accessibilityReplaceRange:NSMakeRange(location, length) withText:[NSString stringWithJSStringRef:string]];
     1814    END_AX_OBJC_EXCEPTIONS
     1815    return false;
     1816}
     1817   
    18091818RefPtr<AccessibilityTextMarker> AccessibilityUIElement::startTextMarkerForBounds(int x, int y, int width, int height)
    18101819{
Note: See TracChangeset for help on using the changeset viewer.