Changeset 273227 in webkit


Ignore:
Timestamp:
Feb 21, 2021 6:13:13 PM (3 years ago)
Author:
Andres Gonzalez
Message:

Add [WebAccessibilityObjectWrapper textMarkerRangeForNSRange] to allow clients to efficiently get a TextMarkerRange from an NSRange.
https://bugs.webkit.org/show_bug.cgi?id=222154

Reviewed by Chris Fleizach and Darin Adler.

Source/WebCore:

Test: accessibility/mac/textmarker-range-for-range.html

Clients like VoiceOver often need the ability to convert a text range
into an accessibility TextMarkerRange.
This patch adds [WebAccessibilityObjectWrapper textMarkerRangeForNSRange]
to allow clients to efficiently perform this conversion.
This is the Mac implementation, iOS implementation is pending.

  • accessibility/AccessibilityObject.h:

(WebCore::AccessibilityObject::allowsTextRanges const):

  • accessibility/AccessibilityObjectInterface.h:
  • accessibility/isolatedtree/AXIsolatedObject.h:
  • accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:

(WebCore::AXIsolatedObject::textMarkerRangeForNSRange const):

  • accessibility/mac/AccessibilityObjectMac.mm:

(WebCore::AccessibilityObject::textMarkerRangeForNSRange const):

  • accessibility/mac/WebAccessibilityObjectWrapperMac.mm:

(-[WebAccessibilityObjectWrapper textMarkerRangeForNSRange:]):
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):

  • editing/Editing.cpp:

(WebCore::visiblePositionForIndexUsingCharacterIterator):
Only advance the CharacterIterator if not atEnd yet.

Tools:

  • WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:

(WTR::AccessibilityUIElement::textMarkerRangeForRange):

  • WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
  • WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
  • WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:

(WTR::AccessibilityUIElement::textMarkerRangeForRange):

LayoutTests:

  • accessibility/mac/textmarker-range-for-range-expected.txt: Added.
  • accessibility/mac/textmarker-range-for-range.html: Added.
Location:
trunk
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r273214 r273227  
     12021-02-21  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Add [WebAccessibilityObjectWrapper textMarkerRangeForNSRange] to allow clients to efficiently get a TextMarkerRange from an NSRange.
     4        https://bugs.webkit.org/show_bug.cgi?id=222154
     5
     6        Reviewed by Chris Fleizach and Darin Adler.
     7
     8        * accessibility/mac/textmarker-range-for-range-expected.txt: Added.
     9        * accessibility/mac/textmarker-range-for-range.html: Added.
     10
    1112021-02-20  Chris Fleizach  <cfleizach@apple.com>
    212
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r273043 r273227  
    967967
    968968webkit.org/b/208477 accessibility/mac/text-marker-for-index.html [ Skip ]
     969accessibility/mac/textmarker-range-for-range.html [ Skip ]
    969970accessibility/mac/isolated-tree-mode-on-off.html [ Skip ]
    970971accessibility/aria-current-state-changed-notification.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r273225 r273227  
     12021-02-21  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Add [WebAccessibilityObjectWrapper textMarkerRangeForNSRange] to allow clients to efficiently get a TextMarkerRange from an NSRange.
     4        https://bugs.webkit.org/show_bug.cgi?id=222154
     5
     6        Reviewed by Chris Fleizach and Darin Adler.
     7
     8        Test: accessibility/mac/textmarker-range-for-range.html
     9
     10        Clients like VoiceOver often need the ability to convert a text range
     11        into an accessibility TextMarkerRange.
     12        This patch adds [WebAccessibilityObjectWrapper textMarkerRangeForNSRange]
     13        to allow clients to efficiently perform this conversion.
     14        This is the Mac implementation, iOS implementation is pending.
     15
     16        * accessibility/AccessibilityObject.h:
     17        (WebCore::AccessibilityObject::allowsTextRanges const):
     18        * accessibility/AccessibilityObjectInterface.h:
     19        * accessibility/isolatedtree/AXIsolatedObject.h:
     20        * accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
     21        (WebCore::AXIsolatedObject::textMarkerRangeForNSRange const):
     22        * accessibility/mac/AccessibilityObjectMac.mm:
     23        (WebCore::AccessibilityObject::textMarkerRangeForNSRange const):
     24        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
     25        (-[WebAccessibilityObjectWrapper textMarkerRangeForNSRange:]):
     26        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
     27        * editing/Editing.cpp:
     28        (WebCore::visiblePositionForIndexUsingCharacterIterator):
     29        Only advance the CharacterIterator if not atEnd yet.
     30
    1312021-02-21  Keith Miller  <keith_miller@apple.com>
    232
  • trunk/Source/WebCore/accessibility/AccessibilityObject.h

    r273214 r273227  
    541541
    542542    Optional<SimpleRange> rangeForPlainTextRange(const PlainTextRange&) const override;
     543#if PLATFORM(MAC)
     544    AXTextMarkerRangeRef textMarkerRangeForNSRange(const NSRange&) const override;
     545#endif
    543546
    544547    static String stringForVisiblePositionRange(const VisiblePositionRange&);
     
    825828
    826829#if !(ENABLE(ACCESSIBILITY) && USE(ATK))
    827 inline bool AccessibilityObject::allowsTextRanges() const { return isTextControl(); }
     830inline bool AccessibilityObject::allowsTextRanges() const { return true; }
    828831inline unsigned AccessibilityObject::getLengthForTextRange() const { return text().length(); }
    829832#endif
  • trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h

    r273214 r273227  
    5050typedef WebAccessibilityObjectWrapper AccessibilityObjectWrapper;
    5151typedef struct _NSRange NSRange;
     52typedef const struct __AXTextMarker* AXTextMarkerRef;
     53typedef const struct __AXTextMarkerRange* AXTextMarkerRangeRef;
    5254#elif USE(ATK)
    5355typedef struct _WebKitAccessible WebKitAccessible;
     
    12761278
    12771279    virtual Optional<SimpleRange> rangeForPlainTextRange(const PlainTextRange&) const = 0;
     1280#if PLATFORM(MAC)
     1281    // FIXME: make this a COCOA method.
     1282    virtual AXTextMarkerRangeRef textMarkerRangeForNSRange(const NSRange&) const = 0;
     1283#endif
    12781284
    12791285    virtual String stringForRange(const SimpleRange&) const = 0;
  • trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h

    r273214 r273227  
    404404    VisiblePositionRange lineRangeForPosition(const VisiblePosition&) const override;
    405405    Optional<SimpleRange> rangeForPlainTextRange(const PlainTextRange&) const override;
     406#if PLATFORM(MAC)
     407    AXTextMarkerRangeRef textMarkerRangeForNSRange(const NSRange&) const override;
     408#endif
    406409    String stringForRange(const SimpleRange&) const override;
    407410    IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const override;
  • trunk/Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm

    r265311 r273227  
    6060}
    6161
     62AXTextMarkerRangeRef AXIsolatedObject::textMarkerRangeForNSRange(const NSRange& range) const
     63{
     64    return Accessibility::retrieveValueFromMainThread<AXTextMarkerRangeRef>([&range, this] () -> AXTextMarkerRangeRef {
     65        auto* axObject = associatedAXObject();
     66        return axObject ? axObject->textMarkerRangeForNSRange(range) : nullptr;
     67    });
     68}
     69
    6270} // WebCore
    6371
  • trunk/Source/WebCore/accessibility/mac/AccessibilityObjectMac.mm

    r269833 r273227  
    279279
    280280    return String();
     281}
     282
     283AXTextMarkerRangeRef AccessibilityObject::textMarkerRangeForNSRange(const NSRange& range) const
     284{
     285    return textMarkerRangeFromVisiblePositions(axObjectCache(),
     286        visiblePositionForIndex(range.location),
     287        visiblePositionForIndex(range.location + range.length));
    281288}
    282289
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r273214 r273227  
    34793479}
    34803480
     3481- (AXTextMarkerRangeRef)textMarkerRangeForNSRange:(const NSRange&)range
     3482{
     3483    auto* backingObject = self.updateObjectBackingStore;
     3484    return backingObject ? backingObject->textMarkerRangeForNSRange(range) : nil;
     3485}
     3486
    34813487// FIXME: No reason for this to be a method instead of a function; can get document from range.
    34823488- (NSRange)_convertToNSRange:(const SimpleRange&)range
     
    40234029            if (!backingObject)
    40244030                return CGRectZero;
    4025             auto* cache = backingObject->axObjectCache();
    4026             if (!cache)
     4031
     4032            auto start = backingObject->visiblePositionForIndex(range.location);
     4033            auto end = backingObject->visiblePositionForIndex(range.location + range.length);
     4034            auto webRange = makeSimpleRange({ start, end });
     4035            if (!webRange)
    40274036                return CGRectZero;
    4028             CharacterOffset start = cache->characterOffsetForIndex(range.location, backingObject);
    4029             CharacterOffset end = cache->characterOffsetForIndex(range.location+range.length, backingObject);
    4030             auto range = cache->rangeForUnorderedCharacterOffsets(start, end);
    4031             if (!range)
    4032                 return CGRectZero;
    4033             auto bounds = FloatRect(backingObject->boundsForRange(*range));
     4037
     4038            auto bounds = FloatRect(backingObject->boundsForRange(*webRange));
    40344039            return [protectedSelf convertRectToSpace:bounds space:AccessibilityConversionSpace::Screen];
    40354040        });
  • trunk/Source/WebCore/editing/Editing.cpp

    r269253 r273227  
    11021102    auto range = makeRangeSelectingNodeContents(node);
    11031103    CharacterIterator it(range);
    1104     it.advance(index - 1);
     1104    if (!it.atEnd())
     1105        it.advance(index - 1);
    11051106
    11061107    if (!it.atEnd() && it.text().length() == 1 && it.text()[0] == '\n') {
  • trunk/Tools/ChangeLog

    r273214 r273227  
     12021-02-21  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Add [WebAccessibilityObjectWrapper textMarkerRangeForNSRange] to allow clients to efficiently get a TextMarkerRange from an NSRange.
     4        https://bugs.webkit.org/show_bug.cgi?id=222154
     5
     6        Reviewed by Chris Fleizach and Darin Adler.
     7
     8        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
     9        (WTR::AccessibilityUIElement::textMarkerRangeForRange):
     10        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
     11        * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
     12        * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
     13        (WTR::AccessibilityUIElement::textMarkerRangeForRange):
     14
    1152021-02-20  Chris Fleizach  <cfleizach@apple.com>
    216
  • trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp

    r273214 r273227  
    103103
    104104#if !PLATFORM(MAC) || !HAVE(ACCESSIBILITY)
     105RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForRange(unsigned, unsigned) { return nullptr; }
    105106RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::selectedTextMarkerRange() { return nullptr; }
    106107void AccessibilityUIElement::resetSelectedTextMarkerRange() { }
  • trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h

    r273214 r273227  
    304304    RefPtr<AccessibilityTextMarkerRange> textMarkerRangeForElement(AccessibilityUIElement*);
    305305    RefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
     306    RefPtr<AccessibilityTextMarkerRange> textMarkerRangeForRange(unsigned location, unsigned length);
    306307    RefPtr<AccessibilityTextMarkerRange> selectedTextMarkerRange();
    307308    void resetSelectedTextMarkerRange();
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl

    r273214 r273227  
    221221    AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement element);
    222222    AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker startMarker, AccessibilityTextMarker endMarker);
     223    AccessibilityTextMarkerRange textMarkerRangeForRange(unsigned long location, unsigned long length);
    223224    AccessibilityTextMarkerRange selectedTextMarkerRange();
    224225    undefined resetSelectedTextMarkerRange();
  • trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm

    r273214 r273227  
    8484- (BOOL)accessibilityReplaceRange:(NSRange)range withText:(NSString *)string;
    8585- (BOOL)accessibilityInsertText:(NSString *)text;
     86- (id)textMarkerRangeForNSRange:(const NSRange&)nsRange;
    8687- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
    8788- (NSUInteger)accessibilityIndexOfChild:(id)child;
     
    18221823    END_AX_OBJC_EXCEPTIONS
    18231824   
     1825    return nullptr;
     1826}
     1827
     1828RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForRange(unsigned location, unsigned length)
     1829{
     1830    BEGIN_AX_OBJC_EXCEPTIONS
     1831    return AccessibilityTextMarkerRange::create([m_element textMarkerRangeForNSRange:NSMakeRange(location, length)]);
     1832    END_AX_OBJC_EXCEPTIONS
     1833
    18241834    return nullptr;
    18251835}
Note: See TracChangeset for help on using the changeset viewer.