Title: [250494] branches/safari-608-branch
Revision
250494
Author
alanc...@apple.com
Date
2019-09-29 18:56:32 -0700 (Sun, 29 Sep 2019)

Log Message

Cherry-pick r249893. rdar://problem/55825342

    Expose misspelling ranges for editable content to accessibility clients.
    https://bugs.webkit.org/show_bug.cgi?id=201752
    <rdar://problem/49556828>

    Patch by Andres Gonzalez <andresg...@apple.com> on 2019-09-16
    Reviewed by Chris Fleizach.

    Source/WebCore:

    Test: accessibility/misspelling-range.html

    Added [WebAccessibilityObjectWrapper misspellingTextMarkerRange] and
    underlying AccessibilityObject implementation to expose misspellings to
    accessibility clients that provide an alternative user interface to
    spell checking.
    * accessibility/AccessibilityObject.cpp:
    (WebCore::AccessibilityObject::getMisspellingRange const):
    * accessibility/AccessibilityObject.h:
    * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
    (-[WebAccessibilityObjectWrapper misspellingTextMarkerRange:direction:]):
    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
    (accessibilityMisspellingSearchCriteriaForParameterizedAttribute):
    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):

    Tools:

    Test code needed for LayoutTests/accessibility/misspelling-range.html.
    * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
    * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
    * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
    (WTR::AccessibilityUIElement::indexForTextMarker):
    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
    (WTR::misspellingSearchParameterizedAttributeForCriteria):
    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):

    LayoutTests:

    * accessibility/misspelling-range-expected.txt: Added.
    * accessibility/misspelling-range.html: Added.
    * platform/ios-simulator/TestExpectations:

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-608-branch/LayoutTests/ChangeLog (250493 => 250494)


--- branches/safari-608-branch/LayoutTests/ChangeLog	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/LayoutTests/ChangeLog	2019-09-30 01:56:32 UTC (rev 250494)
@@ -1,3 +1,63 @@
+2019-09-29  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r249893. rdar://problem/55825342
+
+    Expose misspelling ranges for editable content to accessibility clients.
+    https://bugs.webkit.org/show_bug.cgi?id=201752
+    <rdar://problem/49556828>
+    
+    Patch by Andres Gonzalez <andresg...@apple.com> on 2019-09-16
+    Reviewed by Chris Fleizach.
+    
+    Source/WebCore:
+    
+    Test: accessibility/misspelling-range.html
+    
+    Added [WebAccessibilityObjectWrapper misspellingTextMarkerRange] and
+    underlying AccessibilityObject implementation to expose misspellings to
+    accessibility clients that provide an alternative user interface to
+    spell checking.
+    * accessibility/AccessibilityObject.cpp:
+    (WebCore::AccessibilityObject::getMisspellingRange const):
+    * accessibility/AccessibilityObject.h:
+    * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+    (-[WebAccessibilityObjectWrapper misspellingTextMarkerRange:direction:]):
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+    (accessibilityMisspellingSearchCriteriaForParameterizedAttribute):
+    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+    
+    Tools:
+    
+    Test code needed for LayoutTests/accessibility/misspelling-range.html.
+    * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+    * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+    * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+    (WTR::AccessibilityUIElement::indexForTextMarker):
+    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+    (WTR::misspellingSearchParameterizedAttributeForCriteria):
+    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+    
+    LayoutTests:
+    
+    * accessibility/misspelling-range-expected.txt: Added.
+    * accessibility/misspelling-range.html: Added.
+    * platform/ios-simulator/TestExpectations:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-16  Andres Gonzalez  <andresg...@apple.com>
+
+            Expose misspelling ranges for editable content to accessibility clients.
+            https://bugs.webkit.org/show_bug.cgi?id=201752
+            <rdar://problem/49556828>
+
+            Reviewed by Chris Fleizach.
+
+            * accessibility/misspelling-range-expected.txt: Added.
+            * accessibility/misspelling-range.html: Added.
+            * platform/ios-simulator/TestExpectations:
+
 2019-09-29  Babak Shafiei  <bshaf...@apple.com>
 
         Apply patch. rdar://problem/55801087

Added: branches/safari-608-branch/LayoutTests/accessibility/misspelling-range-expected.txt (0 => 250494)


--- branches/safari-608-branch/LayoutTests/accessibility/misspelling-range-expected.txt	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/accessibility/misspelling-range-expected.txt	2019-09-30 01:56:32 UTC (rev 250494)
@@ -0,0 +1,29 @@
+wrods is misspelled aab lotsi nowadays. euep.
+This tests that misspelling ranges are properly retrieved in the fashion that a spell checker would.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+textMarkerRange start: 0
+textMarkerRange end: 45
+startRange start: 0
+startRange end: 0
+misspelling start: 0
+misspelling end: 5
+PASS text.stringForTextMarkerRange(misspellingRange) is 'wrods'
+misspelling start: 20
+misspelling end: 23
+PASS text.stringForTextMarkerRange(misspellingRange) is 'aab'
+misspelling start: 24
+misspelling end: 29
+PASS text.stringForTextMarkerRange(misspellingRange) is 'lotsi'
+misspelling start: 40
+misspelling end: 44
+PASS text.stringForTextMarkerRange(misspellingRange) is 'euep'
+misspelling start: 24
+misspelling end: 29
+PASS text.stringForTextMarkerRange(misspellingRange) is 'lotsi'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: branches/safari-608-branch/LayoutTests/accessibility/misspelling-range.html (0 => 250494)


--- branches/safari-608-branch/LayoutTests/accessibility/misspelling-range.html	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/accessibility/misspelling-range.html	2019-09-30 01:56:32 UTC (rev 250494)
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+<script>
+if (window.testRunner)
+   testRunner.dumpAsText();
+</script>
+</head>
+<body>
+
+<div contenteditable=true id="content" role="textbox">
+wrods is misspelled aab lotsi nowadays. euep.
+</div>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests that misspelling ranges are properly retrieved in the fashion that a spell checker would.");
+
+    if (window.accessibilityController) {
+        var content = document.getElementById("content");
+        content.focus();
+
+        var text = accessibilityController.focusedElement;
+
+        var textMarkerRange = text.textMarkerRangeForElement(text);
+        var startMarker = text.startTextMarkerForTextMarkerRange(textMarkerRange);
+        debug("textMarkerRange start: " + text.indexForTextMarker(startMarker));
+        var endMarker = text.endTextMarkerForTextMarkerRange(textMarkerRange);
+        debug("textMarkerRange end: " + text.indexForTextMarker(endMarker));
+
+        // Find the first misspelling, "wrods".
+        var startRange = text.textMarkerRangeForMarkers(startMarker, startMarker);
+        startMarker = text.startTextMarkerForTextMarkerRange(startRange);
+        debug("startRange start: " + text.indexForTextMarker(startMarker));
+        endMarker = text.endTextMarkerForTextMarkerRange(startRange);
+        debug("startRange end: " + text.indexForTextMarker(endMarker));
+
+        var misspellingRange = text.misspellingTextMarkerRange(startRange, true);
+        startMarker = text.startTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling start: " + text.indexForTextMarker(startMarker));
+        endMarker = text.endTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling end: " + text.indexForTextMarker(endMarker));
+        shouldBe("text.stringForTextMarkerRange(misspellingRange)", "'wrods'");
+
+        // Find the next one, "aab".
+        startRange = misspellingRange;
+        misspellingRange = text.misspellingTextMarkerRange(startRange, true);
+        startMarker = text.startTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling start: " + text.indexForTextMarker(startMarker));
+        endMarker = text.endTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling end: " + text.indexForTextMarker(endMarker));
+        shouldBe("text.stringForTextMarkerRange(misspellingRange)", "'aab'");
+
+        // Find the next one, "lotsi".
+        startRange = misspellingRange;
+        misspellingRange = text.misspellingTextMarkerRange(startRange, true);
+        startMarker = text.startTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling start: " + text.indexForTextMarker(startMarker));
+        endMarker = text.endTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling end: " + text.indexForTextMarker(endMarker));
+        shouldBe("text.stringForTextMarkerRange(misspellingRange)", "'lotsi'");
+
+        // Find the next one, "euep".
+        startRange = misspellingRange;
+        misspellingRange = text.misspellingTextMarkerRange(startRange, true);
+        startMarker = text.startTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling start: " + text.indexForTextMarker(startMarker));
+        endMarker = text.endTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling end: " + text.indexForTextMarker(endMarker));
+        shouldBe("text.stringForTextMarkerRange(misspellingRange)", "'euep'");
+
+        // Find the previous one, "lotsi".
+        startRange = misspellingRange;
+        misspellingRange = text.misspellingTextMarkerRange(startRange, false);
+        startMarker = text.startTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling start: " + text.indexForTextMarker(startMarker));
+        endMarker = text.endTextMarkerForTextMarkerRange(misspellingRange);
+        debug("misspelling end: " + text.indexForTextMarker(endMarker));
+        shouldBe("text.stringForTextMarkerRange(misspellingRange)", "'lotsi'");
+    }
+</script>
+
+<script src=""
+</body>
+</html>
+

Modified: branches/safari-608-branch/LayoutTests/platform/ios-simulator/TestExpectations (250493 => 250494)


--- branches/safari-608-branch/LayoutTests/platform/ios-simulator/TestExpectations	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/LayoutTests/platform/ios-simulator/TestExpectations	2019-09-30 01:56:32 UTC (rev 250494)
@@ -4,6 +4,7 @@
 #
 
 accessibility/insert-newline.html [ Pass ]
+accessibility/misspelling-range.html [ Pass ]
 css3/font-variant-small-caps-synthesis-coverage.html [ ImageOnlyFailure ]
 fast/frames/sandboxed-iframe-close-top-noclose.html [ Failure ]
 fast/multicol/flexbox-rows.html [ Skip ]

Modified: branches/safari-608-branch/LayoutTests/platform/win/TestExpectations (250493 => 250494)


--- branches/safari-608-branch/LayoutTests/platform/win/TestExpectations	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/LayoutTests/platform/win/TestExpectations	2019-09-30 01:56:32 UTC (rev 250494)
@@ -1710,6 +1710,7 @@
 # Not implemented on Win
 accessibility/insert-newline.html [ Skip ]
 accessibility/media-with-aria-label.html [ Skip ]
+accessibility/misspelling-range.html [ Skip ]
 
 ################################################################################
 #######################   End Accessibility Issues   ###########################

Modified: branches/safari-608-branch/Source/WebCore/ChangeLog (250493 => 250494)


--- branches/safari-608-branch/Source/WebCore/ChangeLog	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Source/WebCore/ChangeLog	2019-09-30 01:56:32 UTC (rev 250494)
@@ -1,3 +1,74 @@
+2019-09-29  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r249893. rdar://problem/55825342
+
+    Expose misspelling ranges for editable content to accessibility clients.
+    https://bugs.webkit.org/show_bug.cgi?id=201752
+    <rdar://problem/49556828>
+    
+    Patch by Andres Gonzalez <andresg...@apple.com> on 2019-09-16
+    Reviewed by Chris Fleizach.
+    
+    Source/WebCore:
+    
+    Test: accessibility/misspelling-range.html
+    
+    Added [WebAccessibilityObjectWrapper misspellingTextMarkerRange] and
+    underlying AccessibilityObject implementation to expose misspellings to
+    accessibility clients that provide an alternative user interface to
+    spell checking.
+    * accessibility/AccessibilityObject.cpp:
+    (WebCore::AccessibilityObject::getMisspellingRange const):
+    * accessibility/AccessibilityObject.h:
+    * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+    (-[WebAccessibilityObjectWrapper misspellingTextMarkerRange:direction:]):
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+    (accessibilityMisspellingSearchCriteriaForParameterizedAttribute):
+    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+    
+    Tools:
+    
+    Test code needed for LayoutTests/accessibility/misspelling-range.html.
+    * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+    * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+    * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+    (WTR::AccessibilityUIElement::indexForTextMarker):
+    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+    (WTR::misspellingSearchParameterizedAttributeForCriteria):
+    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+    
+    LayoutTests:
+    
+    * accessibility/misspelling-range-expected.txt: Added.
+    * accessibility/misspelling-range.html: Added.
+    * platform/ios-simulator/TestExpectations:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-16  Andres Gonzalez  <andresg...@apple.com>
+
+            Expose misspelling ranges for editable content to accessibility clients.
+            https://bugs.webkit.org/show_bug.cgi?id=201752
+            <rdar://problem/49556828>
+
+            Reviewed by Chris Fleizach.
+
+            Test: accessibility/misspelling-range.html
+
+            Added [WebAccessibilityObjectWrapper misspellingTextMarkerRange] and
+            underlying AccessibilityObject implementation to expose misspellings to
+            accessibility clients that provide an alternative user interface to
+            spell checking.
+            * accessibility/AccessibilityObject.cpp:
+            (WebCore::AccessibilityObject::getMisspellingRange const):
+            * accessibility/AccessibilityObject.h:
+            * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+            (-[WebAccessibilityObjectWrapper misspellingTextMarkerRange:direction:]):
+            * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+            (accessibilityMisspellingSearchCriteriaForParameterizedAttribute):
+            (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+
 2019-09-27  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r250441. rdar://problem/55801089

Modified: branches/safari-608-branch/Source/WebCore/accessibility/AccessibilityObject.cpp (250493 => 250494)


--- branches/safari-608-branch/Source/WebCore/accessibility/AccessibilityObject.cpp	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Source/WebCore/accessibility/AccessibilityObject.cpp	2019-09-30 01:56:32 UTC (rev 250494)
@@ -463,6 +463,55 @@
     return isMisspelled;
 }
 
+RefPtr<Range> AccessibilityObject::getMisspellingRange(RefPtr<Range> const& start, AccessibilitySearchDirection direction) const
+{
+    auto node = this->node();
+    if (!node)
+        return nullptr;
+
+    Frame* frame = node->document().frame();
+    if (!frame)
+        return nullptr;
+
+    if (!unifiedTextCheckerEnabled(frame))
+        return nullptr;
+
+    Editor& editor = frame->editor();
+
+    TextCheckerClient* textChecker = editor.textChecker();
+    if (!textChecker)
+        return nullptr;
+
+    Vector<TextCheckingResult> misspellings;
+    checkTextOfParagraph(*textChecker, stringValue(), TextCheckingType::Spelling, misspellings, frame->selection().selection());
+
+    // The returned misspellings are assumed to be ordered in the document
+    // logical order, which should be matched by Range::compareBoundaryPoints.
+    // So iterate forward or backwards depending on the desired search
+    // direction to find the closest misspelling in that direction.
+    if (direction == AccessibilitySearchDirection::Next) {
+        for (auto misspelling : misspellings) {
+            auto misspellingRange = editor.rangeForTextCheckingResult(misspelling);
+            if (!misspellingRange)
+                continue;
+
+            if (misspellingRange->compareBoundaryPoints(Range::END_TO_END, *start).releaseReturnValue() > 0)
+                return misspellingRange;
+        }
+    } else if (direction == AccessibilitySearchDirection::Previous) {
+        for (auto rit = misspellings.rbegin(); rit != misspellings.rend(); ++rit) {
+            auto misspellingRange = editor.rangeForTextCheckingResult(*rit);
+            if (!misspellingRange)
+                continue;
+
+            if (misspellingRange->compareBoundaryPoints(Range::START_TO_START, *start).releaseReturnValue() < 0)
+                return misspellingRange;
+        }
+    }
+
+    return nullptr;
+}
+
 unsigned AccessibilityObject::blockquoteLevel() const
 {
     unsigned level = 0;

Modified: branches/safari-608-branch/Source/WebCore/accessibility/AccessibilityObject.h (250493 => 250494)


--- branches/safari-608-branch/Source/WebCore/accessibility/AccessibilityObject.h	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Source/WebCore/accessibility/AccessibilityObject.h	2019-09-30 01:56:32 UTC (rev 250494)
@@ -485,6 +485,7 @@
     virtual bool hasBoldFont() const { return false; }
     virtual bool hasItalicFont() const { return false; }
     bool hasMisspelling() const;
+    RefPtr<Range> getMisspellingRange(RefPtr<Range> const& start, AccessibilitySearchDirection) const;
     virtual bool hasPlainText() const { return false; }
     virtual bool hasSameFont(RenderObject*) const { return false; }
     virtual bool hasSameFontColor(RenderObject*) const { return false; }

Modified: branches/safari-608-branch/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm (250493 => 250494)


--- branches/safari-608-branch/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm	2019-09-30 01:56:32 UTC (rev 250494)
@@ -2655,6 +2655,20 @@
     return [WebAccessibilityTextMarker textMarkerWithVisiblePosition:lineStart cache:m_object->axObjectCache()];
 }
 
+- (NSArray *)misspellingTextMarkerRange:(NSArray *)startTextMarkerRange forward:(BOOL)forward
+{
+    if (![self _prepareAccessibilityCall])
+        return nil;
+
+    RefPtr<Range> startRange = [self rangeForTextMarkers:startTextMarkerRange];
+    if (!startRange)
+        return nil;
+
+    RefPtr<Range> misspellingRange = m_object->getMisspellingRange(startRange,
+        forward ? AccessibilitySearchDirection::Next : AccessibilitySearchDirection::Previous);
+    return [self textMarkersForRange:misspellingRange];
+}
+
 - (WebAccessibilityTextMarker *)nextMarkerForMarker:(WebAccessibilityTextMarker *)marker
 {
     if (![self _prepareAccessibilityCall])

Modified: branches/safari-608-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (250493 => 250494)


--- branches/safari-608-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2019-09-30 01:56:32 UTC (rev 250494)
@@ -323,6 +323,10 @@
 #define NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute @"AXLineTextMarkerRangeForTextMarker"
 #endif
 
+#ifndef NSAccessibilityMisspellingTextMarkerRangeParameterizedAttribute
+#define NSAccessibilityMisspellingTextMarkerRangeParameterizedAttribute @"AXMisspellingTextMarkerRange"
+#endif
+
 // Text selection
 #ifndef NSAccessibilitySelectTextActivity
 #define NSAccessibilitySelectTextActivity @"AXSelectTextActivity"
@@ -727,6 +731,21 @@
     return operation;
 }
 
+static std::pair<RefPtr<Range>, AccessibilitySearchDirection> accessibilityMisspellingSearchCriteriaForParameterizedAttribute(WebAccessibilityObjectWrapper *object, const NSDictionary *params)
+{
+    std::pair<RefPtr<Range>, AccessibilitySearchDirection> criteria;
+
+    criteria.first = [object rangeForTextMarkerRange:[params objectForKey:@"AXStartTextMarkerRange"]];
+
+    NSNumber *forward = [params objectForKey:NSAccessibilitySearchTextDirection];
+    if ([forward isKindOfClass:[NSNumber class]])
+        criteria.second = [forward boolValue] ? AccessibilitySearchDirection::Next : AccessibilitySearchDirection::Previous;
+    else
+        criteria.second = AccessibilitySearchDirection::Next;
+
+    return criteria;
+}
+
 #pragma mark Text Marker helpers
 
 static BOOL getBytesFromAXTextMarker(CFTypeRef textMarker, void* bytes, size_t length)
@@ -4206,7 +4225,7 @@
         m_object->findMatchingObjects(&criteria, results);
         return convertToNSArray(results);
     }
-    
+
     if ([attribute isEqualToString:NSAccessibilityEndTextMarkerForBoundsParameterizedAttribute]) {
         IntRect webCoreRect = [self screenToContents:enclosingIntRect(rect)];
         CharacterOffset characterOffset = cache->characterOffsetForBounds(webCoreRect, false);
@@ -4223,7 +4242,14 @@
         VisiblePositionRange visiblePositionRange = m_object->lineRangeForPosition(visiblePosition);
         return [self textMarkerRangeFromVisiblePositions:visiblePositionRange.start endPosition:visiblePositionRange.end];
     }
-    
+
+    if ([attribute isEqualToString:NSAccessibilityMisspellingTextMarkerRangeParameterizedAttribute]) {
+        auto criteria = accessibilityMisspellingSearchCriteriaForParameterizedAttribute(self, dictionary);
+        if (auto misspellingRange = m_object->getMisspellingRange(criteria.first, criteria.second))
+            return [self textMarkerRangeFromRange:misspellingRange];
+        return nil;
+    }
+
     if ([attribute isEqualToString:NSAccessibilityTextMarkerIsValidParameterizedAttribute]) {
         VisiblePosition pos = [self visiblePositionForTextMarker:textMarker];
         return [NSNumber numberWithBool:!pos.isNull()];

Modified: branches/safari-608-branch/Tools/ChangeLog (250493 => 250494)


--- branches/safari-608-branch/Tools/ChangeLog	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/ChangeLog	2019-09-30 01:56:32 UTC (rev 250494)
@@ -1,3 +1,69 @@
+2019-09-29  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r249893. rdar://problem/55825342
+
+    Expose misspelling ranges for editable content to accessibility clients.
+    https://bugs.webkit.org/show_bug.cgi?id=201752
+    <rdar://problem/49556828>
+    
+    Patch by Andres Gonzalez <andresg...@apple.com> on 2019-09-16
+    Reviewed by Chris Fleizach.
+    
+    Source/WebCore:
+    
+    Test: accessibility/misspelling-range.html
+    
+    Added [WebAccessibilityObjectWrapper misspellingTextMarkerRange] and
+    underlying AccessibilityObject implementation to expose misspellings to
+    accessibility clients that provide an alternative user interface to
+    spell checking.
+    * accessibility/AccessibilityObject.cpp:
+    (WebCore::AccessibilityObject::getMisspellingRange const):
+    * accessibility/AccessibilityObject.h:
+    * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+    (-[WebAccessibilityObjectWrapper misspellingTextMarkerRange:direction:]):
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+    (accessibilityMisspellingSearchCriteriaForParameterizedAttribute):
+    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+    
+    Tools:
+    
+    Test code needed for LayoutTests/accessibility/misspelling-range.html.
+    * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+    * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+    * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+    (WTR::AccessibilityUIElement::indexForTextMarker):
+    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+    (WTR::misspellingSearchParameterizedAttributeForCriteria):
+    (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+    
+    LayoutTests:
+    
+    * accessibility/misspelling-range-expected.txt: Added.
+    * accessibility/misspelling-range.html: Added.
+    * platform/ios-simulator/TestExpectations:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-16  Andres Gonzalez  <andresg...@apple.com>
+
+            Expose misspelling ranges for editable content to accessibility clients.
+            https://bugs.webkit.org/show_bug.cgi?id=201752
+            <rdar://problem/49556828>
+
+            Reviewed by Chris Fleizach.
+
+            Test code needed for LayoutTests/accessibility/misspelling-range.html.
+            * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+            * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+            * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+            (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+            (WTR::AccessibilityUIElement::indexForTextMarker):
+            * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+            (WTR::misspellingSearchParameterizedAttributeForCriteria):
+            (WTR::AccessibilityUIElement::misspellingTextMarkerRange):
+
 2019-09-29  Babak Shafiei  <bshaf...@apple.com>
 
         Apply patch. rdar://problem/55801087

Modified: branches/safari-608-branch/Tools/DumpRenderTree/AccessibilityUIElement.cpp (250493 => 250494)


--- branches/safari-608-branch/Tools/DumpRenderTree/AccessibilityUIElement.cpp	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/DumpRenderTree/AccessibilityUIElement.cpp	2019-09-30 01:56:32 UTC (rev 250494)
@@ -804,6 +804,19 @@
     return AccessibilityTextMarkerRange::makeJSAccessibilityTextMarkerRange(context, toAXElement(thisObject)->lineTextMarkerRangeForTextMarker(textMarker));
 }
 
+static JSValueRef misspellingTextMarkerRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    AccessibilityTextMarkerRange* startRange = nullptr;
+    bool forward = true;
+
+    if (argumentCount >= 1)
+        startRange = toTextMarkerRange(JSValueToObject(context, arguments[0], exception));
+    if (argumentCount >= 2)
+        forward = JSValueToBoolean(context, arguments[1]);
+
+    return AccessibilityTextMarkerRange::makeJSAccessibilityTextMarkerRange(context, toAXElement(thisObject)->misspellingTextMarkerRange(startRange, forward));
+}
+
 static JSValueRef textMarkerRangeForElementCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     AccessibilityUIElement* uiElement = 0;
@@ -1639,6 +1652,11 @@
     return nullptr;
 }
 
+AccessibilityTextMarkerRange AccessibilityUIElement::misspellingTextMarkerRange(AccessibilityTextMarkerRange*, bool)
+{
+    return nullptr;
+}
+
 AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement*)
 {
     return 0;
@@ -1986,6 +2004,7 @@
         { "addSelection", addSelectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "removeSelection", removeSelectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "lineTextMarkerRangeForTextMarker", lineTextMarkerRangeForTextMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "misspellingTextMarkerRange", misspellingTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "textMarkerRangeForElement", textMarkerRangeForElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "selectedTextMarkerRange", selectedTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "resetSelectedTextMarkerRange", resetSelectedTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },

Modified: branches/safari-608-branch/Tools/DumpRenderTree/AccessibilityUIElement.h (250493 => 250494)


--- branches/safari-608-branch/Tools/DumpRenderTree/AccessibilityUIElement.h	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/DumpRenderTree/AccessibilityUIElement.h	2019-09-30 01:56:32 UTC (rev 250494)
@@ -257,7 +257,8 @@
 
     // Text markers.
     AccessibilityTextMarkerRange lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
-    AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement*);    
+    AccessibilityTextMarkerRange misspellingTextMarkerRange(AccessibilityTextMarkerRange* start, bool forward);
+    AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement*);
     AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
     AccessibilityTextMarker startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
     AccessibilityTextMarker endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);

Modified: branches/safari-608-branch/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm (250493 => 250494)


--- branches/safari-608-branch/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm	2019-09-30 01:56:32 UTC (rev 250494)
@@ -118,6 +118,7 @@
 - (id)accessibilityObjectForTextMarker:(id)marker;
 - (id)lineStartMarkerForMarker:(id)marker;
 - (id)lineEndMarkerForMarker:(id)marker;
+- (NSArray *)misspellingTextMarkerRange:(NSArray *)startTextMarkerRange forward:(BOOL)forward;
 - (NSArray *)textMarkerRangeFromMarkers:(NSArray *)markers withText:(NSString *)text;
 @end
 
@@ -469,6 +470,12 @@
     return AccessibilityTextMarkerRange(textMarkerRange);
 }
 
+AccessibilityTextMarkerRange AccessibilityUIElement::misspellingTextMarkerRange(AccessibilityTextMarkerRange* startRange, bool forward)
+{
+    id misspellingRange = [m_element misspellingTextMarkerRange:(id)startRange->platformTextMarkerRange() forward:forward];
+    return AccessibilityTextMarkerRange(misspellingRange);
+}
+
 AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     id textMarkerRange = [element->platformUIElement() textMarkerRange];

Modified: branches/safari-608-branch/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm (250493 => 250494)


--- branches/safari-608-branch/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm	2019-09-30 01:56:32 UTC (rev 250494)
@@ -1673,6 +1673,19 @@
     return nullptr;
 }
 
+AccessibilityTextMarkerRange AccessibilityUIElement::misspellingTextMarkerRange(AccessibilityTextMarkerRange* start, bool forward)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
+    [parameters setObject:(__bridge id)start->platformTextMarkerRange() forKey:@"AXStartTextMarkerRange"];
+    [parameters setObject:[NSNumber numberWithBool:forward] forKey:@"AXSearchTextDirection"];
+    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXMisspellingTextMarkerRange" forParameter:parameters];
+    return AccessibilityTextMarkerRange((__bridge CFTypeRef)textMarkerRange);
+    END_AX_OBJC_EXCEPTIONS
+
+    return nullptr;
+}
+
 AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     BEGIN_AX_OBJC_EXCEPTIONS

Modified: branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp (250493 => 250494)


--- branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp	2019-09-30 01:56:32 UTC (rev 250494)
@@ -109,6 +109,7 @@
 RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::sentenceTextMarkerRangeForTextMarker(AccessibilityTextMarker*) { return nullptr; }
 RefPtr<AccessibilityTextMarker> AccessibilityUIElement::nextSentenceEndTextMarkerForTextMarker(AccessibilityTextMarker*) { return nullptr; }
 RefPtr<AccessibilityTextMarker> AccessibilityUIElement::previousSentenceStartTextMarkerForTextMarker(AccessibilityTextMarker*) { return nullptr; }
+RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::misspellingTextMarkerRange(AccessibilityTextMarkerRange*, bool) { return nullptr; }
 #endif
 
 } // namespace WTR

Modified: branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h (250493 => 250494)


--- branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h	2019-09-30 01:56:32 UTC (rev 250494)
@@ -278,6 +278,7 @@
     
     // Text markers.
     RefPtr<AccessibilityTextMarkerRange> lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
+    RefPtr<AccessibilityTextMarkerRange> misspellingTextMarkerRange(AccessibilityTextMarkerRange* start, bool forward);
     RefPtr<AccessibilityTextMarkerRange> textMarkerRangeForElement(AccessibilityUIElement*);
     RefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
     RefPtr<AccessibilityTextMarkerRange> selectedTextMarkerRange();

Modified: branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl (250493 => 250494)


--- branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl	2019-09-30 01:56:32 UTC (rev 250494)
@@ -206,7 +206,8 @@
 
     // Text markers.
     AccessibilityTextMarkerRange lineTextMarkerRangeForTextMarker(AccessibilityTextMarker textMarker);
-    AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement element);    
+    AccessibilityTextMarkerRange misspellingTextMarkerRange(AccessibilityTextMarkerRange start, boolean forward);
+    AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement element);
     AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker startMarker, AccessibilityTextMarker endMarker);
     AccessibilityTextMarkerRange selectedTextMarkerRange();
     void resetSelectedTextMarkerRange();

Modified: branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm (250493 => 250494)


--- branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm	2019-09-30 01:56:32 UTC (rev 250494)
@@ -97,11 +97,13 @@
 - (NSString *)stringForTextMarkers:(NSArray *)markers;
 - (id)startOrEndTextMarkerForTextMarkers:(NSArray*)textMarkers isStart:(BOOL)isStart;
 - (NSArray *)textMarkerRangeForMarkers:(NSArray *)textMarkers;
+- (NSInteger)positionForTextMarker:(id)marker;
 - (id)nextMarkerForMarker:(id)marker;
 - (id)previousMarkerForMarker:(id)marker;
 - (id)accessibilityObjectForTextMarker:(id)marker;
 - (id)lineStartMarkerForMarker:(id)marker;
 - (id)lineEndMarkerForMarker:(id)marker;
+- (NSArray *)misspellingTextMarkerRange:(NSArray *)startTextMarkerRange forward:(BOOL)forward;
 - (NSArray *)textMarkerRangeFromMarkers:(NSArray *)markers withText:(NSString *)text;
 - (BOOL)_accessibilityIsInTableCell;
 @end
@@ -1102,6 +1104,12 @@
     return AccessibilityTextMarkerRange::create(textMarkerRange);
 }
 
+RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::misspellingTextMarkerRange(AccessibilityTextMarkerRange* start, bool forward)
+{
+    id misspellingRange = [m_element misspellingTextMarkerRange:(id)start->platformTextMarkerRange() forward:forward];
+    return AccessibilityTextMarkerRange::create(misspellingRange);
+}
+
 RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     id textMarkerRange = [element->platformUIElement() textMarkerRange];
@@ -1205,7 +1213,7 @@
 
 int AccessibilityUIElement::indexForTextMarker(AccessibilityTextMarker* marker)
 {
-    return -1;
+    return [m_element positionForTextMarker:(__bridge id)marker->platformTextMarker()];
 }
 
 bool AccessibilityUIElement::isTextMarkerValid(AccessibilityTextMarker* textMarker)

Modified: branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm (250493 => 250494)


--- branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2019-09-29 23:50:52 UTC (rev 250493)
+++ branches/safari-608-branch/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2019-09-30 01:56:32 UTC (rev 250494)
@@ -324,6 +324,16 @@
     return parameterizedAttribute;
 }
 
+static NSDictionary *misspellingSearchParameterizedAttributeForCriteria(AccessibilityTextMarkerRange* start, bool forward)
+{
+    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
+
+    [parameters setObject:(__bridge id)start->platformTextMarkerRange() forKey:@"AXStartTextMarkerRange"];
+    [parameters setObject:[NSNumber numberWithBool:forward] forKey:@"AXSearchTextDirection"];
+
+    return parameters;
+}
+
 void AccessibilityUIElement::getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement> >& elementVector)
 {
     BEGIN_AX_OBJC_EXCEPTIONS
@@ -1753,6 +1763,17 @@
     return nullptr;
 }
 
+RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::misspellingTextMarkerRange(AccessibilityTextMarkerRange* start, bool forward)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    NSDictionary *parameters = misspellingSearchParameterizedAttributeForCriteria(start, forward);
+    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXMisspellingTextMarkerRange" forParameter:parameters];
+    return AccessibilityTextMarkerRange::create((__bridge CFTypeRef)textMarkerRange);
+    END_AX_OBJC_EXCEPTIONS
+
+    return nullptr;
+}
+
 RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     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