Title: [282938] branches/safari-612-branch
Revision
282938
Author
repst...@apple.com
Date
2021-09-22 22:14:11 -0700 (Wed, 22 Sep 2021)

Log Message

Cherry-pick r282369. rdar://problem/83429914

    AX: set insertion point to the end of a native text control does not work when passing a collapsed TextMarkerRange with both start and end equals to the end TextMarker for the element.
    https://bugs.webkit.org/show_bug.cgi?id=230166

    Reviewed by Chris Fleizach.

    Source/WebCore:

    Test: accessibility/mac/native-text-control-set-selected-textmarker-range.html

    Added a special case to AX object's setSelectedVisiblePositionRange for
    when the passed range is a collapsed range to the end of a native text
    control element's range.
    To accomplish this, it is necessary to compare for equality two
    VisiblePositions obtained from TextMarkers.
    In order to reconstruct the VisiblePositions from the TextMarkers in a
    way that equality is preserved, the AnchorType of the underlying
    Position needs to be added to the TextMarkerData.

    * accessibility/AXObjectCache.cpp:
    Added the AnchorType to the TextMarkerData struct.
    (WebCore::AXObjectCache::visiblePositionForTextMarkerData):
    (WebCore::AXObjectCache::textMarkerDataForVisiblePosition):
    * accessibility/AXObjectCache.h:
    * accessibility/AccessibilityRenderObject.cpp:
    (WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const):
    * accessibility/mac/AXObjectCacheMac.mm:
    Exposed textMarkerRangeFromMarkers.
    (WebCore::textMarkerRangeFromMarkers):
    * accessibility/mac/WebAccessibilityObjectWrapperMac.h:
    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
    Added the AXTextMarkerRangeForTextMarkers attribute which, unlike
    AXTextMarkerRangeForUnorderedTextMarkers, assumes that the range's start
    and end are ordered, and thus is more efficient.
    (-[WebAccessibilityObjectWrapper ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):

    Tools:

    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
    (WTR::AccessibilityUIElement::textMarkerRangeForMarkers):
    Use AXTextMarkerRangeForTextMarkers instead of
    AXTextMarkerRangeForUnorderedTextMarkers.

    LayoutTests:

    * accessibility/mac/bounds-for-range-expected.txt:
    Added AXTextMarkerRangeForTextMarkers attribute name.
    * accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt:
    * accessibility/mac/native-text-control-set-selected-textmarker-range.html:
    Expanded to include the test cases to move the insertion point to the
    beginning and end of the text cotnrol.
    * accessibility/text-marker/text-marker-previous-next-expected.txt:
    * accessibility/text-marker/text-marker-previous-next.html:
    Adjusted expected value to include linebreak character.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/LayoutTests/ChangeLog (282937 => 282938)


--- branches/safari-612-branch/LayoutTests/ChangeLog	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/LayoutTests/ChangeLog	2021-09-23 05:14:11 UTC (rev 282938)
@@ -1,5 +1,84 @@
 2021-09-22  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r282369. rdar://problem/83429914
+
+    AX: set insertion point to the end of a native text control does not work when passing a collapsed TextMarkerRange with both start and end equals to the end TextMarker for the element.
+    https://bugs.webkit.org/show_bug.cgi?id=230166
+    
+    Reviewed by Chris Fleizach.
+    
+    Source/WebCore:
+    
+    Test: accessibility/mac/native-text-control-set-selected-textmarker-range.html
+    
+    Added a special case to AX object's setSelectedVisiblePositionRange for
+    when the passed range is a collapsed range to the end of a native text
+    control element's range.
+    To accomplish this, it is necessary to compare for equality two
+    VisiblePositions obtained from TextMarkers.
+    In order to reconstruct the VisiblePositions from the TextMarkers in a
+    way that equality is preserved, the AnchorType of the underlying
+    Position needs to be added to the TextMarkerData.
+    
+    * accessibility/AXObjectCache.cpp:
+    Added the AnchorType to the TextMarkerData struct.
+    (WebCore::AXObjectCache::visiblePositionForTextMarkerData):
+    (WebCore::AXObjectCache::textMarkerDataForVisiblePosition):
+    * accessibility/AXObjectCache.h:
+    * accessibility/AccessibilityRenderObject.cpp:
+    (WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const):
+    * accessibility/mac/AXObjectCacheMac.mm:
+    Exposed textMarkerRangeFromMarkers.
+    (WebCore::textMarkerRangeFromMarkers):
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.h:
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+    Added the AXTextMarkerRangeForTextMarkers attribute which, unlike
+    AXTextMarkerRangeForUnorderedTextMarkers, assumes that the range's start
+    and end are ordered, and thus is more efficient.
+    (-[WebAccessibilityObjectWrapper ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
+    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+    
+    Tools:
+    
+    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+    (WTR::AccessibilityUIElement::textMarkerRangeForMarkers):
+    Use AXTextMarkerRangeForTextMarkers instead of
+    AXTextMarkerRangeForUnorderedTextMarkers.
+    
+    LayoutTests:
+    
+    * accessibility/mac/bounds-for-range-expected.txt:
+    Added AXTextMarkerRangeForTextMarkers attribute name.
+    * accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt:
+    * accessibility/mac/native-text-control-set-selected-textmarker-range.html:
+    Expanded to include the test cases to move the insertion point to the
+    beginning and end of the text cotnrol.
+    * accessibility/text-marker/text-marker-previous-next-expected.txt:
+    * accessibility/text-marker/text-marker-previous-next.html:
+    Adjusted expected value to include linebreak character.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282369 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-13  Andres Gonzalez  <andresg...@apple.com>
+
+            AX: set insertion point to the end of a native text control does not work when passing a collapsed TextMarkerRange with both start and end equals to the end TextMarker for the element.
+            https://bugs.webkit.org/show_bug.cgi?id=230166
+
+            Reviewed by Chris Fleizach.
+
+            * accessibility/mac/bounds-for-range-expected.txt:
+            Added AXTextMarkerRangeForTextMarkers attribute name.
+            * accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt:
+            * accessibility/mac/native-text-control-set-selected-textmarker-range.html:
+            Expanded to include the test cases to move the insertion point to the
+            beginning and end of the text cotnrol.
+            * accessibility/text-marker/text-marker-previous-next-expected.txt:
+            * accessibility/text-marker/text-marker-previous-next.html:
+            Adjusted expected value to include linebreak character.
+
+2021-09-22  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r281691. rdar://problem/83429796
 
     Make AXCoreObject::setSelectedVisiblePositionRange work in native text controls on MacOS.

Modified: branches/safari-612-branch/LayoutTests/accessibility/mac/bounds-for-range-expected.txt (282937 => 282938)


--- branches/safari-612-branch/LayoutTests/accessibility/mac/bounds-for-range-expected.txt	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/LayoutTests/accessibility/mac/bounds-for-range-expected.txt	2021-09-23 05:14:11 UTC (rev 282938)
@@ -39,6 +39,7 @@
 AXBoundsForTextMarkerRange
 AXAttributedStringForTextMarkerRange
 AXAttributedStringForTextMarkerRangeWithOptions
+AXTextMarkerRangeForTextMarkers
 AXTextMarkerRangeForUnorderedTextMarkers
 AXNextTextMarkerForTextMarker
 AXPreviousTextMarkerForTextMarker

Modified: branches/safari-612-branch/LayoutTests/accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt (282937 => 282938)


--- branches/safari-612-branch/LayoutTests/accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/LayoutTests/accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt	2021-09-23 05:14:11 UTC (rev 282938)
@@ -4,12 +4,17 @@
 
 
 selected text "This is a textarea."
+selected text "T"
 selected text "This is a "
 selected text " is a "
+PASS p.textMarkerRangeLength(selectedRange) is 0
 selected text "This is a text field."
+selected text "T"
 selected text "This is a "
 selected text " is a text"
+PASS p.textMarkerRangeLength(selectedRange) is 0
 PASS successfullyParsed is true
 
 TEST COMPLETE
 
+

Modified: branches/safari-612-branch/LayoutTests/accessibility/mac/native-text-control-set-selected-textmarker-range.html (282937 => 282938)


--- branches/safari-612-branch/LayoutTests/accessibility/mac/native-text-control-set-selected-textmarker-range.html	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/LayoutTests/accessibility/mac/native-text-control-set-selected-textmarker-range.html	2021-09-23 05:14:11 UTC (rev 282938)
@@ -7,7 +7,7 @@
 <body>
 
 <textarea id="textarea">This is a textarea.</textarea>
-
+<br/>
 <input type="text" id="textfield" value="This is a text field." />
 
 <script>
@@ -16,15 +16,15 @@
     if (window.accessibilityController) {
         window.jsTestIsAsync = true;
 
-        let elementID = "textarea";
+        // textarea.
+        var elementID = "textarea";
+        var p = accessibilityController.accessibleElementById(elementID);
+        var range = p.textMarkerRangeForElement(p);
 
-        let p = accessibilityController.accessibleElementById(elementID);
-        let range = p.textMarkerRangeForElement(p);
-
         setTimeout(async () => {
             // Select all text.
             p.setSelectedTextMarkerRange(range);
-            let selectedRange = null;
+            window.selectedRange = null;
             await waitFor(() => {
                 selectedRange = p.selectedTextMarkerRange();
                 return p.textMarkerRangeLength(selectedRange) == 19;
@@ -31,9 +31,22 @@
             });
             debug(`selected text "${p.stringForTextMarkerRange(selectedRange)}"`);
 
+            // Move the insertion point to the beginning of the field.
+            let start = p.startTextMarkerForTextMarkerRange(range);
+            let end = start;
+            range = p.textMarkerRangeForMarkers(start, end);
+            p.setSelectedTextMarkerRange(range);
+            await waitFor(() => {
+                selectedRange = p.selectedTextMarkerRange();
+                return p.textMarkerRangeLength(selectedRange) == 0;
+            });
+            let selectionStart = p.startTextMarkerForTextMarkerRange(selectedRange);
+            let selectionEnd = p.endTextMarkerForTextMarkerRange(selectedRange);
+            // Move selectionEnd one over so that we have a length 1 range and we can get the character at the insertion point.
+            selectionEnd = p.nextTextMarker(selectionEnd);
+            debug(`selected text "${p.stringForTextMarkerRange(p.textMarkerRangeForMarkers(selectionStart, selectionEnd))}"`);
+
             // Select the first 10 characters.
-            let start = p.startTextMarkerForTextMarkerRange(range);
-            end = start;
             for (let i = 0; i < 10; ++i)
                 end = p.nextTextMarker(end);
             range = p.textMarkerRangeForMarkers(start, end);
@@ -55,8 +68,21 @@
             });
             debug(`selected text "${p.stringForTextMarkerRange(selectedRange)}"`);
 
+            // Move the insertion point to the end of the field.
+            range = p.textMarkerRangeForElement(p);
+            end = p.endTextMarkerForTextMarkerRange(range);
+            start = end;
+            range = p.textMarkerRangeForMarkers(start, end);
+            p.setSelectedTextMarkerRange(range);
+            await waitFor(() => {
+                selectedRange = p.selectedTextMarkerRange();
+                return p.textMarkerRangeLength(selectedRange) == 0;
+            });
+            selectedRange = p.selectedTextMarkerRange();
+            shouldBe("p.textMarkerRangeLength(selectedRange)", "0");
+
+            // Input text field.
             elementID = "textfield";
-
             p = accessibilityController.accessibleElementById(elementID);
             range = p.textMarkerRangeForElement(p);
 
@@ -69,9 +95,22 @@
             });
             debug(`selected text "${p.stringForTextMarkerRange(selectedRange)}"`);
 
-            // Select the first 10 characters.
+            // Move the insertion point to the beginning of the field.
             start = p.startTextMarkerForTextMarkerRange(range);
             end = start;
+            range = p.textMarkerRangeForMarkers(start, end);
+            p.setSelectedTextMarkerRange(range);
+            await waitFor(() => {
+                selectedRange = p.selectedTextMarkerRange();
+                return p.textMarkerRangeLength(selectedRange) == 0;
+            });
+            selectionStart = p.startTextMarkerForTextMarkerRange(selectedRange);
+            selectionEnd = p.endTextMarkerForTextMarkerRange(selectedRange);
+            // Move selectionEnd one over so that we have a length 1 range and we can get the character at the insertion point.
+            selectionEnd = p.nextTextMarker(selectionEnd);
+            debug(`selected text "${p.stringForTextMarkerRange(p.textMarkerRangeForMarkers(selectionStart, selectionEnd))}"`);
+
+            // Select the first 10 characters.
             for (let i = 0; i < 10; ++i)
                 end = p.nextTextMarker(end);
             range = p.textMarkerRangeForMarkers(start, end);
@@ -95,6 +134,19 @@
             });
             debug(`selected text "${p.stringForTextMarkerRange(selectedRange)}"`);
 
+            // Move the insertion point to the end of the field.
+            range = p.textMarkerRangeForElement(p);
+            end = p.endTextMarkerForTextMarkerRange(range);
+            start = end;
+            range = p.textMarkerRangeForMarkers(start, end);
+            p.setSelectedTextMarkerRange(range);
+            await waitFor(() => {
+                selectedRange = p.selectedTextMarkerRange();
+                return p.textMarkerRangeLength(selectedRange) == 0;
+            });
+            selectedRange = p.selectedTextMarkerRange();
+            shouldBe("p.textMarkerRangeLength(selectedRange)", "0");
+
             finishJSTest();
         }, 0);
     }

Modified: branches/safari-612-branch/LayoutTests/accessibility/text-marker/text-marker-previous-next.html (282937 => 282938)


--- branches/safari-612-branch/LayoutTests/accessibility/text-marker/text-marker-previous-next.html	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/LayoutTests/accessibility/text-marker/text-marker-previous-next.html	2021-09-23 05:14:11 UTC (rev 282938)
@@ -81,8 +81,11 @@
         previousMarker = result.previous;
         currentMarker = result.current;
         markerRange = text.textMarkerRangeForMarkers(previousMarker, currentMarker);
-        shouldBe("text.stringForTextMarkerRange(markerRange)", "'t'");
-        
+        if (accessibilityController.platformName == "mac")
+            shouldBe("text.stringForTextMarkerRange(markerRange)", "'t' + newline");
+        else
+            shouldBe("text.stringForTextMarkerRange(markerRange)", "'t'");
+
         // Check the case with replaced node
         var text2 = accessibilityController.accessibleElementById("text2");
         var textMarkerRange2 = text2.textMarkerRangeForElement(text2);
@@ -222,4 +225,4 @@
 
 <script src=""
 </body>
-</html>
\ No newline at end of file
+</html>

Added: branches/safari-612-branch/LayoutTests/platform/mac/accessibility/text-marker/text-marker-previous-next-expected.txt (0 => 282938)


--- branches/safari-612-branch/LayoutTests/platform/mac/accessibility/text-marker/text-marker-previous-next-expected.txt	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/platform/mac/accessibility/text-marker/text-marker-previous-next-expected.txt	2021-09-23 05:14:11 UTC (rev 282938)
@@ -0,0 +1,52 @@
+text
+
+text1
+c  d
+
+can't select
+abc de f
+😃😏
+
+a b
+
+audiofile
+
+This tests the next/previous text marker functions are implemented correctly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS text.textMarkerRangeLength(textMarkerRange) is 4
+PASS text.accessibilityElementForTextMarker(startMarker).isEqual(text) is true
+PASS text.accessibilityElementForTextMarker(endMarker).isEqual(text) is true
+PASS text.stringForTextMarkerRange(markerRange) is newline
+PASS text.stringForTextMarkerRange(markerRange) is 't'
+PASS text.stringForTextMarkerRange(markerRange) is newline
+PASS text.stringForTextMarkerRange(markerRange) is 't' + newline
+PASS text2.textMarkerRangeLength(textMarkerRange2) is 5
+Object string for range: c [ATTACHMENT] d
+PASS text2.stringForTextMarkerRange(markerRange) is 'd'
+PASS text2.stringForTextMarkerRange(markerRange) is '1'
+PASS text3.stringForTextMarkerRange(markerRange) is 'ect'
+PASS text3.stringForTextMarkerRange(markerRange) is 'sel'
+PASS !psw.accessibilityElementForTextMarker(start) is true
+PASS text2.accessibilityElementForTextMarker(currentMarker).isEqual(text3) is true
+PASS text2.accessibilityElementForTextMarker(currentMarker).isEqual(text2.childAtIndex(2)) is true
+PASS text.stringForTextMarkerRange(markerRange) is 'f'
+PASS text.stringForTextMarkerRange(markerRange) is 'a'
+PASS text.textMarkerRangeLength(emojiTextMarkerRange) is 4
+PASS text.stringForTextMarkerRange(text.textMarkerRangeForMarkers(result.previous, result.current)) is '😏'
+PASS text.stringForTextMarkerRange(text.textMarkerRangeForMarkers(result.previous, result.current)) is '😃'
+PASS text.textMarkerRangeLength(collapsedWhitespaceMarkerRange) is 3
+PASS text.stringForTextMarkerRange(text.textMarkerRangeForMarkers(result.previous, result.current)) is 'a'
+PASS text.stringForTextMarkerRange(text.textMarkerRangeForMarkers(result.previous, result.current)) is ' '
+PASS text.stringForTextMarkerRange(text.textMarkerRangeForMarkers(result.previous, result.current)) is 'b'
+PASS text.stringForTextMarkerRange(text.textMarkerRangeForMarkers(result.previous, result.current)) is ' '
+PASS text.stringForTextMarkerRange(text.textMarkerRangeForMarkers(result.previous, result.current)) is 'a'
+PASS text.stringForTextMarkerRange(textMarkerRange) is 'audiofile'
+PASS text.stringForTextMarkerRange(markerRange) is ''
+PASS text.stringForTextMarkerRange(markerRange) is ''
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (282937 => 282938)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2021-09-23 05:14:11 UTC (rev 282938)
@@ -1,5 +1,103 @@
 2021-09-22  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r282369. rdar://problem/83429914
+
+    AX: set insertion point to the end of a native text control does not work when passing a collapsed TextMarkerRange with both start and end equals to the end TextMarker for the element.
+    https://bugs.webkit.org/show_bug.cgi?id=230166
+    
+    Reviewed by Chris Fleizach.
+    
+    Source/WebCore:
+    
+    Test: accessibility/mac/native-text-control-set-selected-textmarker-range.html
+    
+    Added a special case to AX object's setSelectedVisiblePositionRange for
+    when the passed range is a collapsed range to the end of a native text
+    control element's range.
+    To accomplish this, it is necessary to compare for equality two
+    VisiblePositions obtained from TextMarkers.
+    In order to reconstruct the VisiblePositions from the TextMarkers in a
+    way that equality is preserved, the AnchorType of the underlying
+    Position needs to be added to the TextMarkerData.
+    
+    * accessibility/AXObjectCache.cpp:
+    Added the AnchorType to the TextMarkerData struct.
+    (WebCore::AXObjectCache::visiblePositionForTextMarkerData):
+    (WebCore::AXObjectCache::textMarkerDataForVisiblePosition):
+    * accessibility/AXObjectCache.h:
+    * accessibility/AccessibilityRenderObject.cpp:
+    (WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const):
+    * accessibility/mac/AXObjectCacheMac.mm:
+    Exposed textMarkerRangeFromMarkers.
+    (WebCore::textMarkerRangeFromMarkers):
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.h:
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+    Added the AXTextMarkerRangeForTextMarkers attribute which, unlike
+    AXTextMarkerRangeForUnorderedTextMarkers, assumes that the range's start
+    and end are ordered, and thus is more efficient.
+    (-[WebAccessibilityObjectWrapper ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
+    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+    
+    Tools:
+    
+    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+    (WTR::AccessibilityUIElement::textMarkerRangeForMarkers):
+    Use AXTextMarkerRangeForTextMarkers instead of
+    AXTextMarkerRangeForUnorderedTextMarkers.
+    
+    LayoutTests:
+    
+    * accessibility/mac/bounds-for-range-expected.txt:
+    Added AXTextMarkerRangeForTextMarkers attribute name.
+    * accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt:
+    * accessibility/mac/native-text-control-set-selected-textmarker-range.html:
+    Expanded to include the test cases to move the insertion point to the
+    beginning and end of the text cotnrol.
+    * accessibility/text-marker/text-marker-previous-next-expected.txt:
+    * accessibility/text-marker/text-marker-previous-next.html:
+    Adjusted expected value to include linebreak character.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282369 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-13  Andres Gonzalez  <andresg...@apple.com>
+
+            AX: set insertion point to the end of a native text control does not work when passing a collapsed TextMarkerRange with both start and end equals to the end TextMarker for the element.
+            https://bugs.webkit.org/show_bug.cgi?id=230166
+
+            Reviewed by Chris Fleizach.
+
+            Test: accessibility/mac/native-text-control-set-selected-textmarker-range.html
+
+            Added a special case to AX object's setSelectedVisiblePositionRange for
+            when the passed range is a collapsed range to the end of a native text
+            control element's range.
+            To accomplish this, it is necessary to compare for equality two
+            VisiblePositions obtained from TextMarkers.
+            In order to reconstruct the VisiblePositions from the TextMarkers in a
+            way that equality is preserved, the AnchorType of the underlying
+            Position needs to be added to the TextMarkerData.
+
+            * accessibility/AXObjectCache.cpp:
+            Added the AnchorType to the TextMarkerData struct.
+            (WebCore::AXObjectCache::visiblePositionForTextMarkerData):
+            (WebCore::AXObjectCache::textMarkerDataForVisiblePosition):
+            * accessibility/AXObjectCache.h:
+            * accessibility/AccessibilityRenderObject.cpp:
+            (WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const):
+            * accessibility/mac/AXObjectCacheMac.mm:
+            Exposed textMarkerRangeFromMarkers.
+            (WebCore::textMarkerRangeFromMarkers):
+            * accessibility/mac/WebAccessibilityObjectWrapperMac.h:
+            * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+            Added the AXTextMarkerRangeForTextMarkers attribute which, unlike
+            AXTextMarkerRangeForUnorderedTextMarkers, assumes that the range's start
+            and end are ordered, and thus is more efficient.
+            (-[WebAccessibilityObjectWrapper ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
+            (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+
+2021-09-22  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r281847. rdar://problem/83429949
 
     visualWordPosition should operate on a clean tree

Modified: branches/safari-612-branch/Source/WebCore/accessibility/AXObjectCache.cpp (282937 => 282938)


--- branches/safari-612-branch/Source/WebCore/accessibility/AXObjectCache.cpp	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Source/WebCore/accessibility/AXObjectCache.cpp	2021-09-23 05:14:11 UTC (rev 282938)
@@ -1911,7 +1911,7 @@
         || textMarkerData.node->isPseudoElement())
         return { };
 
-    auto visiblePosition = VisiblePosition(makeContainerOffsetPosition(textMarkerData.node, textMarkerData.offset), textMarkerData.affinity);
+    auto visiblePosition = VisiblePosition({ textMarkerData.node, textMarkerData.offset, textMarkerData.anchorType }, textMarkerData.affinity);
     auto deepPosition = visiblePosition.deepEquivalent();
     if (deepPosition.isNull())
         return { };
@@ -2495,7 +2495,7 @@
         return std::nullopt;
 
     Position deepPos = visiblePos.deepEquivalent();
-    Node* domNode = deepPos.deprecatedNode();
+    Node* domNode = deepPos.anchorNode();
     ASSERT(domNode);
     if (!domNode)
         return std::nullopt;
@@ -2526,6 +2526,7 @@
     textMarkerData.axID = obj.get()->objectID();
     textMarkerData.node = domNode;
     textMarkerData.offset = deepPos.deprecatedEditingOffset();
+    textMarkerData.anchorType = deepPos.anchorType();
     textMarkerData.affinity = visiblePos.affinity();
 
     textMarkerData.characterOffset = characterOffset.offset;

Modified: branches/safari-612-branch/Source/WebCore/accessibility/AXObjectCache.h (282937 => 282938)


--- branches/safari-612-branch/Source/WebCore/accessibility/AXObjectCache.h	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Source/WebCore/accessibility/AXObjectCache.h	2021-09-23 05:14:11 UTC (rev 282938)
@@ -60,12 +60,15 @@
 
 struct TextMarkerData {
     AXID axID { 0 };
+
     Node* node { nullptr };
-    int offset { 0 };
+    unsigned offset { 0 };
+    Position::AnchorType anchorType { Position::PositionIsOffsetInAnchor };
+    Affinity affinity { Affinity::Downstream };
+
     int characterStartIndex { 0 };
     int characterOffset { 0 };
     bool ignored { false };
-    Affinity affinity { Affinity::Downstream };
 };
 
 struct CharacterOffset {

Modified: branches/safari-612-branch/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (282937 => 282938)


--- branches/safari-612-branch/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2021-09-23 05:14:11 UTC (rev 282938)
@@ -2320,10 +2320,16 @@
         if (range.start.deepEquivalent().anchorNode() == range.end.deepEquivalent().anchorNode()
             && range.start.deepEquivalent().anchorNode() == textControl) {
             if (auto innerText = textControl->innerTextElement()) {
+                auto textControlRange = makeVisiblePositionRange(AXObjectCache::rangeForNodeContents(*textControl));
                 auto innerRange = makeVisiblePositionRange(AXObjectCache::rangeForNodeContents(*innerText));
-                if (range.start < innerRange.start)
+
+                if (range.start.equals(textControlRange.end))
+                    start = textControl->value().length();
+                else if (range.start <= innerRange.start)
                     start = 0;
-                if (range.end >= innerRange.end)
+
+                if (range.end >= innerRange.end
+                    || range.end.equals(textControlRange.end))
                     end = textControl->value().length();
             }
         }

Modified: branches/safari-612-branch/Source/WebCore/accessibility/mac/AXObjectCacheMac.mm (282937 => 282938)


--- branches/safari-612-branch/Source/WebCore/accessibility/mac/AXObjectCacheMac.mm	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Source/WebCore/accessibility/mac/AXObjectCacheMac.mm	2021-09-23 05:14:11 UTC (rev 282938)
@@ -612,7 +612,7 @@
     return adoptCF(AXTextMarkerRangeCreate(kCFAllocatorDefault, startMarker, endMarker));
 }
 
-static RetainPtr<AXTextMarkerRangeRef> textMarkerRangeFromMarkers(AXTextMarkerRef textMarker1, AXTextMarkerRef textMarker2)
+RetainPtr<AXTextMarkerRangeRef> textMarkerRangeFromMarkers(AXTextMarkerRef textMarker1, AXTextMarkerRef textMarker2)
 {
     if (!textMarker1 || !textMarker2)
         return nil;

Modified: branches/safari-612-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.h (282937 => 282938)


--- branches/safari-612-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.h	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.h	2021-09-23 05:14:11 UTC (rev 282938)
@@ -65,6 +65,7 @@
 // TextMarker and TextMarkerRange public funcstions.
 // FIXME: TextMarker and TextMarkerRange should become classes on their own right, wrapping the system objects.
 
+RetainPtr<AXTextMarkerRangeRef> textMarkerRangeFromMarkers(AXTextMarkerRef, AXTextMarkerRef);
 AccessibilityObject* accessibilityObjectForTextMarker(AXObjectCache*, AXTextMarkerRef);
 
 // TextMarker <-> VisiblePosition conversion.

Modified: branches/safari-612-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (282937 => 282938)


--- branches/safari-612-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2021-09-23 05:14:11 UTC (rev 282938)
@@ -3050,6 +3050,7 @@
             @"AXBoundsForTextMarkerRange",
             @"AXAttributedStringForTextMarkerRange",
             @"AXAttributedStringForTextMarkerRangeWithOptions",
+            @"AXTextMarkerRangeForTextMarkers",
             @"AXTextMarkerRangeForUnorderedTextMarkers",
             @"AXNextTextMarkerForTextMarker",
             @"AXPreviousTextMarkerForTextMarker",
@@ -4086,11 +4087,20 @@
         return nil;
     }
 
-    if ([attribute isEqualToString:@"AXTextMarkerRangeForUnorderedTextMarkers"]) {
-        if ([array count] < 2)
+    if ([attribute isEqualToString:@"AXTextMarkerRangeForTextMarkers"]) {
+        if (array.count < 2
+            || !AXObjectIsTextMarker([array objectAtIndex:0])
+            || !AXObjectIsTextMarker([array objectAtIndex:1]))
             return nil;
+        return Accessibility::retrieveAutoreleasedValueFromMainThread<id>([&array] () -> RetainPtr<id> {
+            return (id)textMarkerRangeFromMarkers((AXTextMarkerRef)[array objectAtIndex:0], (AXTextMarkerRef)[array objectAtIndex:1]).get();
+        });
+    }
 
-        if (!AXObjectIsTextMarker([array objectAtIndex:0]) || !AXObjectIsTextMarker([array objectAtIndex:0]))
+    if ([attribute isEqualToString:@"AXTextMarkerRangeForUnorderedTextMarkers"]) {
+        if (array.count < 2
+            || !AXObjectIsTextMarker([array objectAtIndex:0])
+            || !AXObjectIsTextMarker([array objectAtIndex:1]))
             return nil;
 
         AXTextMarkerRef textMarker1 = (AXTextMarkerRef)[array objectAtIndex:0];

Modified: branches/safari-612-branch/Tools/ChangeLog (282937 => 282938)


--- branches/safari-612-branch/Tools/ChangeLog	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Tools/ChangeLog	2021-09-23 05:14:11 UTC (rev 282938)
@@ -1,5 +1,79 @@
 2021-09-22  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r282369. rdar://problem/83429914
+
+    AX: set insertion point to the end of a native text control does not work when passing a collapsed TextMarkerRange with both start and end equals to the end TextMarker for the element.
+    https://bugs.webkit.org/show_bug.cgi?id=230166
+    
+    Reviewed by Chris Fleizach.
+    
+    Source/WebCore:
+    
+    Test: accessibility/mac/native-text-control-set-selected-textmarker-range.html
+    
+    Added a special case to AX object's setSelectedVisiblePositionRange for
+    when the passed range is a collapsed range to the end of a native text
+    control element's range.
+    To accomplish this, it is necessary to compare for equality two
+    VisiblePositions obtained from TextMarkers.
+    In order to reconstruct the VisiblePositions from the TextMarkers in a
+    way that equality is preserved, the AnchorType of the underlying
+    Position needs to be added to the TextMarkerData.
+    
+    * accessibility/AXObjectCache.cpp:
+    Added the AnchorType to the TextMarkerData struct.
+    (WebCore::AXObjectCache::visiblePositionForTextMarkerData):
+    (WebCore::AXObjectCache::textMarkerDataForVisiblePosition):
+    * accessibility/AXObjectCache.h:
+    * accessibility/AccessibilityRenderObject.cpp:
+    (WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const):
+    * accessibility/mac/AXObjectCacheMac.mm:
+    Exposed textMarkerRangeFromMarkers.
+    (WebCore::textMarkerRangeFromMarkers):
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.h:
+    * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+    Added the AXTextMarkerRangeForTextMarkers attribute which, unlike
+    AXTextMarkerRangeForUnorderedTextMarkers, assumes that the range's start
+    and end are ordered, and thus is more efficient.
+    (-[WebAccessibilityObjectWrapper ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
+    (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+    
+    Tools:
+    
+    * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+    (WTR::AccessibilityUIElement::textMarkerRangeForMarkers):
+    Use AXTextMarkerRangeForTextMarkers instead of
+    AXTextMarkerRangeForUnorderedTextMarkers.
+    
+    LayoutTests:
+    
+    * accessibility/mac/bounds-for-range-expected.txt:
+    Added AXTextMarkerRangeForTextMarkers attribute name.
+    * accessibility/mac/native-text-control-set-selected-textmarker-range-expected.txt:
+    * accessibility/mac/native-text-control-set-selected-textmarker-range.html:
+    Expanded to include the test cases to move the insertion point to the
+    beginning and end of the text cotnrol.
+    * accessibility/text-marker/text-marker-previous-next-expected.txt:
+    * accessibility/text-marker/text-marker-previous-next.html:
+    Adjusted expected value to include linebreak character.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282369 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-13  Andres Gonzalez  <andresg...@apple.com>
+
+            AX: set insertion point to the end of a native text control does not work when passing a collapsed TextMarkerRange with both start and end equals to the end TextMarker for the element.
+            https://bugs.webkit.org/show_bug.cgi?id=230166
+
+            Reviewed by Chris Fleizach.
+
+            * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+            (WTR::AccessibilityUIElement::textMarkerRangeForMarkers):
+            Use AXTextMarkerRangeForTextMarkers instead of
+            AXTextMarkerRangeForUnorderedTextMarkers.
+
+2021-09-22  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r282034. rdar://problem/83429808
 
     Safari’s Privacy Report window is completely blank

Modified: branches/safari-612-branch/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm (282937 => 282938)


--- branches/safari-612-branch/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm	2021-09-23 05:14:11 UTC (rev 282938)
@@ -1850,11 +1850,11 @@
 AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
 {
     BEGIN_AX_OBJC_EXCEPTIONS
-    NSArray* textMarkers = @[startMarker->platformTextMarker(), endMarker->platformTextMarker()];
-    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForUnorderedTextMarkers" forParameter:textMarkers];
+    NSArray *textMarkers = @[startMarker->platformTextMarker(), endMarker->platformTextMarker()];
+    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForTextMarkers" forParameter:textMarkers];
     return AccessibilityTextMarkerRange(textMarkerRange);
     END_AX_OBJC_EXCEPTIONS
-    
+
     return nullptr;
 }
 

Modified: branches/safari-612-branch/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm (282937 => 282938)


--- branches/safari-612-branch/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2021-09-23 05:14:06 UTC (rev 282937)
+++ branches/safari-612-branch/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2021-09-23 05:14:11 UTC (rev 282938)
@@ -1882,16 +1882,11 @@
 RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
 {
     BEGIN_AX_OBJC_EXCEPTIONS
-    id startPlatformMarker = startMarker->platformTextMarker();
-    id endPlatformMarker = endMarker->platformTextMarker();
-    if (!startPlatformMarker || !endPlatformMarker)
-        return nullptr;
-
-    NSArray* textMarkers = @[startPlatformMarker, endPlatformMarker];
-    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForUnorderedTextMarkers" forParameter:textMarkers];
+    NSArray *textMarkers = @[startMarker->platformTextMarker(), endMarker->platformTextMarker()];
+    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForTextMarkers" forParameter:textMarkers];
     return AccessibilityTextMarkerRange::create(textMarkerRange);
     END_AX_OBJC_EXCEPTIONS
-    
+
     return nullptr;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to