Title: [257052] trunk/Source/WebCore
Revision
257052
Author
[email protected]
Date
2020-02-20 06:06:25 -0800 (Thu, 20 Feb 2020)

Log Message

[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange] must run on the main thread.
https://bugs.webkit.org/show_bug.cgi?id=207958

Reviewed by Darin Adler.

Covered by existing tests.

[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange]
calls into TextIterator and Node, thus it must be dispatched to the
main thread.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (257051 => 257052)


--- trunk/Source/WebCore/ChangeLog	2020-02-20 13:06:36 UTC (rev 257051)
+++ trunk/Source/WebCore/ChangeLog	2020-02-20 14:06:25 UTC (rev 257052)
@@ -1,3 +1,19 @@
+2020-02-20  Andres Gonzalez  <[email protected]>
+
+        [WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange] must run on the main thread.
+        https://bugs.webkit.org/show_bug.cgi?id=207958
+
+        Reviewed by Darin Adler.
+
+        Covered by existing tests.
+
+        [WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange]
+        calls into TextIterator and Node, thus it must be dispatched to the
+        main thread.
+
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):
+
 2020-02-20  Carlos Garcia Campos  <[email protected]>
 
         [WPE] Use custom colors for text and listbox selection

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (257051 => 257052)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2020-02-20 13:06:36 UTC (rev 257051)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm	2020-02-20 14:06:25 UTC (rev 257052)
@@ -1277,46 +1277,49 @@
 
 - (NSAttributedString*)doAXAttributedStringForTextMarkerRange:(id)textMarkerRange spellCheck:(BOOL)spellCheck
 {
-    if (!self.axBackingObject)
-        return nil;
-    
-    RefPtr<Range> range = [self rangeForTextMarkerRange:textMarkerRange];
-    NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init];
-    TextIterator it(range.get());
-    while (!it.atEnd()) {
-        // locate the node and starting offset for this range
-        Node& node = it.range()->startContainer();
-        ASSERT(&node == &it.range()->endContainer());
-        int offset = it.range()->startOffset();
-        
-        // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
-        if (it.text().length()) {
-            // Add the text of the list marker item if necessary.
-            String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(it.range()->startPosition()));
-            if (!listMarkerText.isEmpty())
-                AXAttributedStringAppendText(attrString, &node, listMarkerText, spellCheck);
-            AXAttributedStringAppendText(attrString, &node, it.text(), spellCheck);
-        } else {
-            Node* replacedNode = node.traverseToChildAt(offset);
-            NSString *attachmentString = nsStringForReplacedNode(replacedNode);
-            if (attachmentString) {
-                NSRange attrStringRange = NSMakeRange([attrString length], [attachmentString length]);
-                
-                // append the placeholder string
-                [[attrString mutableString] appendString:attachmentString];
-                
-                // remove all inherited attributes
-                [attrString setAttributes:nil range:attrStringRange];
-                
-                // add the attachment attribute
-                AccessibilityObject* obj = replacedNode->renderer()->document().axObjectCache()->getOrCreate(replacedNode->renderer());
-                AXAttributeStringSetElement(attrString, NSAccessibilityAttachmentTextAttribute, obj, attrStringRange);
+    return Accessibility::retrieveValueFromMainThread<NSAttributedString *>([&textMarkerRange, &spellCheck, protectedSelf = RetainPtr<WebAccessibilityObjectWrapper>(self)] () -> NSAttributedString * {
+        auto* backingObject = protectedSelf.get().axBackingObject;
+        if (!backingObject)
+            return nil;
+
+        RefPtr<Range> range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
+        NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init];
+        TextIterator it(range.get());
+        while (!it.atEnd()) {
+            // locate the node and starting offset for this range
+            Node& node = it.range()->startContainer();
+            ASSERT(&node == &it.range()->endContainer());
+            int offset = it.range()->startOffset();
+
+            // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
+            if (it.text().length()) {
+                // Add the text of the list marker item if necessary.
+                String listMarkerText = AccessibilityObject::listMarkerTextForNodeAndPosition(&node, VisiblePosition(it.range()->startPosition()));
+                if (!listMarkerText.isEmpty())
+                    AXAttributedStringAppendText(attrString, &node, listMarkerText, spellCheck);
+                AXAttributedStringAppendText(attrString, &node, it.text(), spellCheck);
+            } else {
+                Node* replacedNode = node.traverseToChildAt(offset);
+                NSString *attachmentString = nsStringForReplacedNode(replacedNode);
+                if (attachmentString) {
+                    NSRange attrStringRange = NSMakeRange([attrString length], [attachmentString length]);
+
+                    // append the placeholder string
+                    [[attrString mutableString] appendString:attachmentString];
+
+                    // remove all inherited attributes
+                    [attrString setAttributes:nil range:attrStringRange];
+
+                    // add the attachment attribute
+                    AccessibilityObject* obj = replacedNode->renderer()->document().axObjectCache()->getOrCreate(replacedNode->renderer());
+                    AXAttributeStringSetElement(attrString, NSAccessibilityAttachmentTextAttribute, obj, attrStringRange);
+                }
             }
+            it.advance();
         }
-        it.advance();
-    }
 
-    return [attrString autorelease];
+        return [attrString autorelease];
+    });
 }
 
 static id textMarkerRangeFromVisiblePositions(AXObjectCache* cache, const VisiblePosition& startPosition, const VisiblePosition& endPosition)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to