Fix for LayoutTests/accessibility/mac/search-text/search-text.html in IsolatedTree...
authorandresg_22@apple.com <andresg_22@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Mar 2020 22:50:30 +0000 (22:50 +0000)
committerandresg_22@apple.com <andresg_22@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Mar 2020 22:50:30 +0000 (22:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208434

Reviewed by Chris Fleizach.

Source/WebCore:

Covered by LayoutTests/accessibility/mac/search-text/search-text.html

- Updates IsolatedTree for AXSelectedTextChanged notifications.
- Exposes webAreaObject through the AXCoreObject interface.
- AXIsolatedObject implementation for hasApplePDFAnnotationAttribute,
webAreaObject and stringForRange.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::postTextStateChangeNotification):
(WebCore::AXObjectCache::updateIsolatedTree):
(WebCore::AXObjectCache::rootWebArea):
* accessibility/AXObjectCache.h:
* accessibility/AccessibilityObject.h:
* accessibility/AccessibilityObjectInterface.h:
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::isLoaded const):
(WebCore::AccessibilityRenderObject::accessKey const):
* accessibility/AccessibilityScrollView.h:
* accessibility/ios/AXObjectCacheIOS.mm:
(WebCore::AXObjectCache::postTextStateChangePlatformNotification):
(WebCore::AXObjectCache::postTextReplacementPlatformNotification):
(WebCore::AXObjectCache::postTextReplacementPlatformNotificationForTextControl):
* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::initializeAttributeData):
(WebCore::AXIsolatedObject::stringForRange const):
(WebCore::AXIsolatedObject::hasApplePDFAnnotationAttribute const): Deleted.
* accessibility/isolatedtree/AXIsolatedObject.h:
* accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::removeNode):
(WebCore::AXIsolatedTree::applyPendingChanges):
* accessibility/mac/AXObjectCacheMac.mm:
(WebCore::AXObjectCache::postTextStateChangePlatformNotification):
(WebCore::addTextMarkerFor):
(WebCore::textReplacementChangeDictionary):
(WebCore::postUserInfoForChanges):
(WebCore::AXObjectCache::postTextReplacementPlatformNotification):
(WebCore::AXObjectCache::postTextReplacementPlatformNotificationForTextControl):
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper textMarkerRangeFromVisiblePositions:endPosition:]):
(-[WebAccessibilityObjectWrapper associatedPluginParent]):
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):

Tools:

* WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
(WTR::AccessibilityController::AccessibilityController): Initializes m_useAXThread.
(WTR::AccessibilityController::rootElement): No need to set m_useAXThread here since it is initialize in the constructor.
* WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
(WTR::AccessibilityController::accessibleElementById): Same as above.

LayoutTests:

* accessibility/mac/aria-expanded-notifications.html:
With this change, we now get the FocusChanged notification when the
script sets focus to a tree item.

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

20 files changed:
LayoutTests/ChangeLog
LayoutTests/accessibility/mac/aria-expanded-notifications.html
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/AXObjectCache.h
Source/WebCore/accessibility/AccessibilityObject.h
Source/WebCore/accessibility/AccessibilityObjectInterface.h
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/AccessibilityScrollView.h
Source/WebCore/accessibility/ios/AXObjectCacheIOS.mm
Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp
Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h
Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp
Source/WebCore/accessibility/mac/AXObjectCacheMac.mm
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
Source/WebKit/WebProcess/WebPage/atk/WebKitWebPageAccessibilityObject.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp
Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.h
Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm

index 8f21e91..26a5a17 100644 (file)
@@ -1,3 +1,14 @@
+2020-03-02  Andres Gonzalez  <andresg_22@apple.com>
+
+        Fix for LayoutTests/accessibility/mac/search-text/search-text.html in IsolatedTree mode.
+        https://bugs.webkit.org/show_bug.cgi?id=208434
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/mac/aria-expanded-notifications.html:
+        With this change, we now get the FocusChanged notification when the
+        script sets focus to a tree item.
+
 2020-03-02  Jason Lawrence  <lawrence.j@apple.com>
 
         [ Mac wk2 ] tiled-drawing/scrolling/fast-scroll-div-latched-mainframe-with-handler.html is flaky failing.
index 953e5a6..bd98ac1 100644 (file)
@@ -30,7 +30,9 @@
     var notifyName = 0;
     // The order of notifications should be Row Count, Row Collapsed, Row Count, Row Expanded
     function notifyCallback(element, notification) {  
-        if (notification == "AXLoadComplete" || notification == "AXLayoutComplete")
+        if (notification == "AXLoadComplete"
+            || notification == "AXLayoutComplete"
+            || notification == "AXFocusChanged")
             return;
         notifyName = notification;
         if (notifyCount == 0)
index eccc901..22b798f 100644 (file)
@@ -1,3 +1,53 @@
+2020-03-02  Andres Gonzalez  <andresg_22@apple.com>
+
+        Fix for LayoutTests/accessibility/mac/search-text/search-text.html in IsolatedTree mode.
+        https://bugs.webkit.org/show_bug.cgi?id=208434
+
+        Reviewed by Chris Fleizach.
+
+        Covered by LayoutTests/accessibility/mac/search-text/search-text.html
+
+        - Updates IsolatedTree for AXSelectedTextChanged notifications.
+        - Exposes webAreaObject through the AXCoreObject interface.
+        - AXIsolatedObject implementation for hasApplePDFAnnotationAttribute,
+        webAreaObject and stringForRange.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::postTextStateChangeNotification):
+        (WebCore::AXObjectCache::updateIsolatedTree):
+        (WebCore::AXObjectCache::rootWebArea):
+        * accessibility/AXObjectCache.h:
+        * accessibility/AccessibilityObject.h:
+        * accessibility/AccessibilityObjectInterface.h:
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::isLoaded const):
+        (WebCore::AccessibilityRenderObject::accessKey const):
+        * accessibility/AccessibilityScrollView.h:
+        * accessibility/ios/AXObjectCacheIOS.mm:
+        (WebCore::AXObjectCache::postTextStateChangePlatformNotification):
+        (WebCore::AXObjectCache::postTextReplacementPlatformNotification):
+        (WebCore::AXObjectCache::postTextReplacementPlatformNotificationForTextControl):
+        * accessibility/isolatedtree/AXIsolatedObject.cpp:
+        (WebCore::AXIsolatedObject::initializeAttributeData):
+        (WebCore::AXIsolatedObject::stringForRange const):
+        (WebCore::AXIsolatedObject::hasApplePDFAnnotationAttribute const): Deleted.
+        * accessibility/isolatedtree/AXIsolatedObject.h:
+        * accessibility/isolatedtree/AXIsolatedTree.cpp:
+        (WebCore::AXIsolatedTree::removeNode):
+        (WebCore::AXIsolatedTree::applyPendingChanges):
+        * accessibility/mac/AXObjectCacheMac.mm:
+        (WebCore::AXObjectCache::postTextStateChangePlatformNotification):
+        (WebCore::addTextMarkerFor):
+        (WebCore::textReplacementChangeDictionary):
+        (WebCore::postUserInfoForChanges):
+        (WebCore::AXObjectCache::postTextReplacementPlatformNotification):
+        (WebCore::AXObjectCache::postTextReplacementPlatformNotificationForTextControl):
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper textMarkerRangeFromVisiblePositions:endPosition:]):
+        (-[WebAccessibilityObjectWrapper associatedPluginParent]):
+        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):
+        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+
 2020-03-02  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Make Path::Path(const Path&) and Path::operator=(const Path&) cheap
index 3f18544..d374003 100644 (file)
@@ -1364,6 +1364,10 @@ void AXObjectCache::postTextStateChangeNotification(const Position& position, co
         }
     }
 
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    updateIsolatedTree(object, AXSelectedTextChanged);
+#endif
+
     postTextStateChangeNotification(object, intent, selection);
 #else
     postTextStateChangeNotification(node, intent, selection);
@@ -3139,6 +3143,7 @@ void AXObjectCache::updateIsolatedTree(AXCoreObject* object, AXNotification noti
     switch (notification) {
     case AXCheckedStateChanged:
     case AXChildrenChanged:
+    case AXSelectedTextChanged:
     case AXValueChanged: {
         tree->removeSubtree(object->objectID());
         auto* parent = object->parentObject();
@@ -3239,12 +3244,12 @@ bool isNodeAriaVisible(Node* node)
     return !requiresAriaHiddenFalse || ariaHiddenFalsePresent;
 }
 
-AccessibilityObject* AXObjectCache::rootWebArea()
+AXCoreObject* AXObjectCache::rootWebArea()
 {
     AXCoreObject* rootObject = this->rootObject();
     if (!rootObject || !rootObject->isAccessibilityScrollView())
         return nullptr;
-    return downcast<AccessibilityScrollView>(*rootObject).webAreaObject();
+    return rootObject->webAreaObject();
 }
 
 AXAttributeCacheEnabler::AXAttributeCacheEnabler(AXObjectCache* cache)
index bee9ba1..2987eae 100644 (file)
@@ -368,10 +368,10 @@ protected:
     void platformPerformDeferredCacheUpdate();
 
 #if PLATFORM(COCOA)
-    void postTextStateChangePlatformNotification(AccessibilityObject*, const AXTextStateChangeIntent&, const VisibleSelection&);
+    void postTextStateChangePlatformNotification(AXCoreObject*, const AXTextStateChangeIntent&, const VisibleSelection&);
     void postTextStateChangePlatformNotification(AccessibilityObject*, AXTextEditType, const String&, const VisiblePosition&);
-    void postTextReplacementPlatformNotificationForTextControl(AccessibilityObject*, const String& deletedText, const String& insertedText, HTMLTextFormControlElement&);
-    void postTextReplacementPlatformNotification(AccessibilityObject*, AXTextEditType, const String&, AXTextEditType, const String&, const VisiblePosition&);
+    void postTextReplacementPlatformNotificationForTextControl(AXCoreObject*, const String& deletedText, const String& insertedText, HTMLTextFormControlElement&);
+    void postTextReplacementPlatformNotification(AXCoreObject*, AXTextEditType, const String&, AXTextEditType, const String&, const VisiblePosition&);
 #else
     static AXTextChange textChangeForEditType(AXTextEditType);
     void nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned, const String&);
@@ -412,7 +412,7 @@ protected:
     bool shouldSkipBoundary(const CharacterOffset&, const CharacterOffset&);
 
 private:
-    AccessibilityObject* rootWebArea();
+    AXCoreObject* rootWebArea();
 
     static AccessibilityObject* focusedImageMapUIElement(HTMLAreaElement*);
     static AXCoreObject* focusedObject(Document&);
index a13309b..dc35aa9 100644 (file)
@@ -756,6 +756,7 @@ public:
     AccessibilityObject* highestEditableAncestor() override;
 
     const AccessibilityScrollView* ancestorAccessibilityScrollView(bool includeSelf) const override;
+    AccessibilityObject* webAreaObject() const override { return nullptr; }
 
     void clearIsIgnoredFromParentData() override { m_isIgnoredFromParentData = AccessibilityIsIgnoredFromParentData(); }
     void setIsIgnoredFromParentDataForChild(AXCoreObject*) override;
index 759e3f1..cafdd66 100644 (file)
@@ -1160,6 +1160,7 @@ public:
     virtual AXCoreObject* highestEditableAncestor() = 0;
 
     virtual const AccessibilityScrollView* ancestorAccessibilityScrollView(bool includeSelf) const = 0;
+    virtual AXCoreObject* webAreaObject() const = 0;
 
     virtual void setIsIgnoredFromParentData(AccessibilityIsIgnoredFromParentData&) = 0;
     virtual void clearIsIgnoredFromParentData() = 0;
index 1597e91..90da1a7 100644 (file)
@@ -1492,7 +1492,7 @@ bool AccessibilityRenderObject::computeAccessibilityIsIgnored() const
 
 bool AccessibilityRenderObject::isLoaded() const
 {
-    return !m_renderer->document().parser();
+    return m_renderer ? !m_renderer->document().parser() : false;
 }
 
 double AccessibilityRenderObject::estimatedLoadingProgress() const
@@ -1572,9 +1572,13 @@ String AccessibilityRenderObject::selectedText() const
 
 String AccessibilityRenderObject::accessKey() const
 {
+    if (!m_renderer)
+        return String();
+
     Node* node = m_renderer->node();
     if (!is<Element>(node))
-        return nullAtom();
+        return String();
+
     return downcast<Element>(*node).attributeWithoutSynchronization(accesskeyAttr);
 }
 
index 39b3faa..6f1999c 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     virtual ~AccessibilityScrollView();
 
-    AccessibilityObject* webAreaObject() const;
+    AccessibilityObject* webAreaObject() const override;
 
 private:
     explicit AccessibilityScrollView(ScrollView*);
@@ -71,7 +71,7 @@ private:
     LayoutRect elementRect() const override;
     AccessibilityObject* parentObject() const override;
     AccessibilityObject* parentObjectIfExists() const override;
-    
+
     AccessibilityObject* firstChild() const override { return webAreaObject(); }
     AccessibilityScrollbar* addChildScrollbar(Scrollbar*);
     void removeChildScrollbar(AccessibilityObject*);
index cc33a2b..902693d 100644 (file)
@@ -92,7 +92,7 @@ void AXObjectCache::postPlatformNotification(AXCoreObject* obj, AXNotification n
         [obj->wrapper() accessibilityPostedNotification:notificationString];
 }
 
-void AXObjectCache::postTextStateChangePlatformNotification(AccessibilityObject* object, const AXTextStateChangeIntent&, const VisibleSelection&)
+void AXObjectCache::postTextStateChangePlatformNotification(AXCoreObject* object, const AXTextStateChangeIntent&, const VisibleSelection&)
 {
     postPlatformNotification(object, AXSelectedTextChanged);
 }
@@ -102,12 +102,12 @@ void AXObjectCache::postTextStateChangePlatformNotification(AccessibilityObject*
     postPlatformNotification(object, AXValueChanged);
 }
 
-void AXObjectCache::postTextReplacementPlatformNotification(AccessibilityObject* object, AXTextEditType, const String&, AXTextEditType, const String&, const VisiblePosition&)
+void AXObjectCache::postTextReplacementPlatformNotification(AXCoreObject* object, AXTextEditType, const String&, AXTextEditType, const String&, const VisiblePosition&)
 {
     postPlatformNotification(object, AXValueChanged);
 }
 
-void AXObjectCache::postTextReplacementPlatformNotificationForTextControl(AccessibilityObject* object, const String&, const String&, HTMLTextFormControlElement&)
+void AXObjectCache::postTextReplacementPlatformNotificationForTextControl(AXCoreObject* object, const String&, const String&, HTMLTextFormControlElement&)
 {
     postPlatformNotification(object, AXValueChanged);
 }
index 8fc744d..c3bfa26 100644 (file)
@@ -59,6 +59,8 @@ void AXIsolatedObject::initializeAttributeData(AXCoreObject& object, bool isRoot
     setProperty(AXPropertyName::BoundingBoxRect, object.boundingBoxRect());
     setProperty(AXPropertyName::Description, object.descriptionAttributeValue().isolatedCopy());
     setProperty(AXPropertyName::ElementRect, object.elementRect());
+    setProperty(AXPropertyName::HasARIAValueNow, object.hasARIAValueNow());
+    setProperty(AXPropertyName::HasApplePDFAnnotationAttribute, object.hasApplePDFAnnotationAttribute());
     setProperty(AXPropertyName::HelpText, object.helpTextAttributeValue().isolatedCopy());
     setProperty(AXPropertyName::IsAccessibilityIgnored, object.accessibilityIsIgnored());
     setProperty(AXPropertyName::IsActiveDescendantOfFocusedContainer, object.isActiveDescendantOfFocusedContainer());
@@ -206,7 +208,6 @@ void AXIsolatedObject::initializeAttributeData(AXCoreObject& object, bool isRoot
     setProperty(AXPropertyName::HierarchicalLevel, object.hierarchicalLevel());
     setProperty(AXPropertyName::Language, object.language());
     setProperty(AXPropertyName::CanHaveSelectedChildren, object.canHaveSelectedChildren());
-    setProperty(AXPropertyName::HasARIAValueNow, object.hasARIAValueNow());
     setProperty(AXPropertyName::TagName, object.tagName().isolatedCopy());
     setProperty(AXPropertyName::SupportsLiveRegion, object.supportsLiveRegion());
     setProperty(AXPropertyName::IsInsideLiveRegion, object.isInsideLiveRegion());
@@ -378,6 +379,7 @@ void AXIsolatedObject::initializeAttributeData(AXCoreObject& object, bool isRoot
     }
     
     if (isRoot) {
+        setObjectProperty(AXPropertyName::WebArea, object.webAreaObject());
         setProperty(AXPropertyName::PreventKeyboardDOMEventDispatch, object.preventKeyboardDOMEventDispatch());
         setProperty(AXPropertyName::SessionID, object.sessionID());
         setProperty(AXPropertyName::DocumentURI, object.documentURI());
@@ -864,6 +866,15 @@ void AXIsolatedObject::updateBackingStore()
     }
 }
 
+String AXIsolatedObject::stringForRange(RefPtr<Range> range) const
+{
+    return Accessibility::retrieveValueFromMainThread<String>([&range, this] () -> String {
+        if (auto* object = associatedAXObject())
+            return object->stringForRange(range);
+        return String();
+    });
+}
+
 Vector<RefPtr<Range>> AXIsolatedObject::findTextRanges(AccessibilitySearchTextCriteria const& criteria) const
 {
     return Accessibility::retrieveValueFromMainThread<Vector<RefPtr<Range>>>([&criteria, this] () -> Vector<RefPtr<Range>> {
@@ -1870,12 +1881,6 @@ AccessibilityObjectInclusion AXIsolatedObject::accessibilityPlatformIncludesObje
     return AccessibilityObjectInclusion::DefaultBehavior;
 }
 
-bool AXIsolatedObject::hasApplePDFAnnotationAttribute() const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
 const AccessibilityScrollView* AXIsolatedObject::ancestorAccessibilityScrollView(bool) const
 {
     ASSERT_NOT_REACHED();
index 1371895..3476c79 100644 (file)
@@ -144,6 +144,7 @@ private:
         FileUploadButtonReturnsValueInTitle,
         FocusableAncestor,
         HasARIAValueNow,
+        HasApplePDFAnnotationAttribute,
         HasChildren,
         HasPopup,
         HeaderContainer,
@@ -328,6 +329,7 @@ private:
         VerticalScrollBar,
         VisibleChildren,
         VisibleRows,
+        WebArea,
     };
     
     typedef std::pair<AXID, AXID> AccessibilityIsolatedTreeMathMultiscriptPair;
@@ -643,7 +645,7 @@ private:
     VisiblePositionRange visiblePositionRangeForRange(const PlainTextRange&) const override { return VisiblePositionRange(); }
     VisiblePositionRange lineRangeForPosition(const VisiblePosition&) const override { return VisiblePositionRange(); }
     RefPtr<Range> rangeForPlainTextRange(const PlainTextRange&) const override { return nullptr; }
-    String stringForRange(RefPtr<Range>) const override { return String(); }
+    String stringForRange(RefPtr<Range>) const override;
     IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const override { return IntRect(); }
     IntRect boundsForRange(const RefPtr<Range>) const override { return IntRect(); }
     int lengthForVisiblePositionRange(const VisiblePositionRange&) const override { return 0; }
@@ -875,8 +877,9 @@ private:
     void overrideAttachmentParent(AXCoreObject* parent) override;
     bool accessibilityIgnoreAttachment() const override;
     AccessibilityObjectInclusion accessibilityPlatformIncludesObject() const override;
-    bool hasApplePDFAnnotationAttribute() const override;
+    bool hasApplePDFAnnotationAttribute() const override { return boolAttributeValue(AXPropertyName::HasApplePDFAnnotationAttribute); }
     const AccessibilityScrollView* ancestorAccessibilityScrollView(bool includeSelf) const override;
+    AXCoreObject* webAreaObject() const override { return objectAttributeValue(AXPropertyName::WebArea); }
     void setIsIgnoredFromParentData(AccessibilityIsIgnoredFromParentData&) override;
     void clearIsIgnoredFromParentData() override;
     void setIsIgnoredFromParentDataForChild(AXCoreObject*) override;
index e80cf43..0144e8d 100644 (file)
@@ -174,7 +174,6 @@ void AXIsolatedTree::setFocusedNodeID(AXID axID)
 void AXIsolatedTree::removeNode(AXID axID)
 {
     LockHolder locker { m_changeLogLock };
-    ASSERT(m_readerThreadNodeMap.contains(axID));
     m_pendingRemovals.append(axID);
 }
 
@@ -215,17 +214,24 @@ void AXIsolatedTree::applyPendingChanges()
     m_pendingRemovals.clear();
 
     for (const auto& item : m_pendingAppends) {
-        ASSERT(!m_readerThreadNodeMap.contains(item.m_isolatedObject->objectID())
-            || item.m_isolatedObject->objectID() == m_rootNodeID);
+        AXID axID = item.m_isolatedObject->objectID();
+
+        if (m_readerThreadNodeMap.get(axID) != &item.m_isolatedObject.get()) {
+            // The new IsolatedObject is a replacement for an existing object
+            // as the result of an update. Thus detach the existing one before
+            // adding the new one.
+            if (auto object = nodeForID(axID))
+                object->detach(AccessibilityDetachmentType::ElementDestroyed);
+            m_readerThreadNodeMap.remove(axID);
+        }
 
-        if (item.m_wrapper)
-            item.m_isolatedObject->attachPlatformWrapper(item.m_wrapper);
+        if (m_readerThreadNodeMap.add(axID, item.m_isolatedObject.get()) && item.m_wrapper)
+            m_readerThreadNodeMap.get(axID)->attachPlatformWrapper(item.m_wrapper);
 
-        m_readerThreadNodeMap.add(item.m_isolatedObject->objectID(), item.m_isolatedObject.get());
         // The reference count of the just added IsolatedObject must be 2
         // because it is referenced by m_readerThreadNodeMap and m_pendingAppends.
         // When m_pendingAppends is cleared, the object will be held only by m_readerThreadNodeMap.
-        ASSERT(m_readerThreadNodeMap.get(item.m_isolatedObject->objectID())->refCount() == 2);
+        ASSERT(m_readerThreadNodeMap.get(axID)->refCount() == 2);
     }
     m_pendingAppends.clear();
 }
index cbb8cd9..6229306 100644 (file)
@@ -364,7 +364,7 @@ void AXObjectCache::postPlatformNotification(AXCoreObject* obj, AXNotification n
     AXPostNotificationWithUserInfo(obj->wrapper(), macNotification, nil, skipSystemNotification);
 }
 
-void AXObjectCache::postTextStateChangePlatformNotification(AccessibilityObject* object, const AXTextStateChangeIntent& intent, const VisibleSelection& selection)
+void AXObjectCache::postTextStateChangePlatformNotification(AXCoreObject* object, const AXTextStateChangeIntent& intent, const VisibleSelection& selection)
 {
     if (!object)
         object = rootWebArea();
@@ -419,7 +419,7 @@ void AXObjectCache::postTextStateChangePlatformNotification(AccessibilityObject*
     [userInfo release];
 }
 
-static void addTextMarkerFor(NSMutableDictionary* change, AccessibilityObject& object, const VisiblePosition& position)
+static void addTextMarkerFor(NSMutableDictionary* change, AXCoreObject& object, const VisiblePosition& position)
 {
     if (position.isNull())
         return;
@@ -427,14 +427,14 @@ static void addTextMarkerFor(NSMutableDictionary* change, AccessibilityObject& o
         [change setObject:textMarker forKey:NSAccessibilityTextChangeValueStartMarker];
 }
 
-static void addTextMarkerFor(NSMutableDictionary* change, AccessibilityObject& object, HTMLTextFormControlElement& textControl)
+static void addTextMarkerFor(NSMutableDictionary* change, AXCoreObject& object, HTMLTextFormControlElement& textControl)
 {
     if (id textMarker = [object.wrapper() textMarkerForFirstPositionInTextControl:textControl])
         [change setObject:textMarker forKey:NSAccessibilityTextChangeValueStartMarker];
 }
 
 template <typename TextMarkerTargetType>
-static NSDictionary *textReplacementChangeDictionary(AccessibilityObject& object, AXTextEditType type, const String& string, TextMarkerTargetType& markerTarget)
+static NSDictionary *textReplacementChangeDictionary(AXCoreObject& object, AXTextEditType type, const String& string, TextMarkerTargetType& markerTarget)
 {
     NSString *text = (NSString *)string;
     NSUInteger length = [text length];
@@ -459,7 +459,7 @@ void AXObjectCache::postTextStateChangePlatformNotification(AccessibilityObject*
     postTextReplacementPlatformNotification(object, AXTextEditTypeUnknown, emptyString(), type, text, position);
 }
 
-static void postUserInfoForChanges(AccessibilityObject& rootWebArea, AccessibilityObject& object, NSMutableArray* changes)
+static void postUserInfoForChanges(AXCoreObject& rootWebArea, AXCoreObject& object, NSMutableArray* changes)
 {
     NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] initWithCapacity:4];
     [userInfo setObject:@(platformChangeTypeForWebCoreChangeType(AXTextStateChangeTypeEdit)) forKey:NSAccessibilityTextStateChangeTypeKey];
@@ -476,7 +476,7 @@ static void postUserInfoForChanges(AccessibilityObject& rootWebArea, Accessibili
     [userInfo release];
 }
 
-void AXObjectCache::postTextReplacementPlatformNotification(AccessibilityObject* object, AXTextEditType deletionType, const String& deletedText, AXTextEditType insertionType, const String& insertedText, const VisiblePosition& position)
+void AXObjectCache::postTextReplacementPlatformNotification(AXCoreObject* object, AXTextEditType deletionType, const String& deletedText, AXTextEditType insertionType, const String& insertedText, const VisiblePosition& position)
 {
     if (!object)
         object = rootWebArea();
@@ -493,7 +493,7 @@ void AXObjectCache::postTextReplacementPlatformNotification(AccessibilityObject*
     [changes release];
 }
 
-void AXObjectCache::postTextReplacementPlatformNotificationForTextControl(AccessibilityObject* object, const String& deletedText, const String& insertedText, HTMLTextFormControlElement& textControl)
+void AXObjectCache::postTextReplacementPlatformNotificationForTextControl(AXCoreObject* object, const String& deletedText, const String& insertedText, HTMLTextFormControlElement& textControl)
 {
     if (!object)
         object = rootWebArea();
index 2fbacf4..48325c8 100644 (file)
@@ -1334,7 +1334,11 @@ static id textMarkerRangeFromVisiblePositions(AXObjectCache* cache, const Visibl
 
 - (id)textMarkerRangeFromVisiblePositions:(const VisiblePosition&)startPosition endPosition:(const VisiblePosition&)endPosition
 {
-    return textMarkerRangeFromVisiblePositions(self.axBackingObject->axObjectCache(), startPosition, endPosition);
+    auto* backingObject = self.updateObjectBackingStore;
+    if (!backingObject)
+        return nil;
+
+    return textMarkerRangeFromVisiblePositions(backingObject->axObjectCache(), startPosition, endPosition);
 }
 
 ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
@@ -1955,17 +1959,18 @@ static NSMutableArray *convertStringsToNSArray(const Vector<String>& vector)
 - (id)associatedPluginParent
 {
     return Accessibility::retrieveAutoreleasedValueFromMainThread<id>([protectedSelf = RetainPtr<WebAccessibilityObjectWrapper>(self)] () -> RetainPtr<id> {
-        if (!protectedSelf.get().axBackingObject || !protectedSelf.get().axBackingObject->hasApplePDFAnnotationAttribute())
+        auto* backingObject = protectedSelf.get().axBackingObject;
+        if (!backingObject || !backingObject->hasApplePDFAnnotationAttribute())
             return nil;
-    
-        if (!protectedSelf.get().axBackingObject->document()->isPluginDocument())
+
+        if (!backingObject->document()->isPluginDocument())
             return nil;
-        
-        Widget* pluginWidget = static_cast<PluginDocument*>(protectedSelf.get().axBackingObject->document())->pluginWidget();
+
+        Widget* pluginWidget = static_cast<PluginDocument*>(backingObject->document())->pluginWidget();
         if (!pluginWidget || !pluginWidget->isPluginViewBase())
             return nil;
-        
-        return static_cast<PluginViewBase*>(pluginWidget)->accessibilityAssociatedPluginParentForElement(protectedSelf.get().axBackingObject->element());
+
+        return static_cast<PluginViewBase*>(pluginWidget)->accessibilityAssociatedPluginParentForElement(backingObject->element());
     });
 }
 
@@ -3071,7 +3076,7 @@ ALLOW_DEPRECATED_IMPLEMENTATIONS_END
     if ([attributeName isEqualToString:@"AXDRTSpeechAttribute"])
         return [self baseAccessibilitySpeechHint];
 
-    // Used by DRT to find an accessible node by its element id.
+    // Used by TestRunner and DRT AccessibilityController to find an accessible node by its element id.
     if ([attributeName isEqualToString:@"AXDRTElementIdAttribute"])
         return backingObject->identifierAttribute();
 
@@ -3987,8 +3992,11 @@ ALLOW_DEPRECATED_IMPLEMENTATIONS_END
     }
 
     if ([attribute isEqualToString:@"AXStringForTextMarkerRange"]) {
-        RefPtr<Range> range = [self rangeForTextMarkerRange:textMarkerRange];
-        return backingObject->stringForRange(range);
+        return Accessibility::retrieveValueFromMainThread<String>([&textMarkerRange, protectedSelf = RetainPtr<WebAccessibilityObjectWrapper>(self)] () -> String {
+            RefPtr<Range> range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
+            auto* backingObject = protectedSelf.get().axBackingObject;
+            return backingObject ? backingObject->stringForRange(range) : String();
+        });
     }
 
     if ([attribute isEqualToString:@"AXTextMarkerForPosition"]) {
index 091fb8f..44773b5 100644 (file)
@@ -55,10 +55,10 @@ static void coreRootObjectWrapperDetachedCallback(AtkObject* wrapper, const char
 
 static AccessibilityObjectWrapper* rootWebAreaWrapper(AXCoreObject& rootObject)
 {
-    if (!rootObject.isAccessibilityScrollView())
+    if (!rootObject.isScrollView())
         return nullptr;
 
-    if (auto* webAreaObject = downcast<AccessibilityScrollView>(rootObject).webAreaObject())
+    if (auto* webAreaObject = rootObject.webAreaObject())
         return webAreaObject->wrapper();
 
     return nullptr;
index b410511..faf0efc 100644 (file)
@@ -1,3 +1,16 @@
+2020-03-02  Andres Gonzalez  <andresg_22@apple.com>
+
+        Fix for LayoutTests/accessibility/mac/search-text/search-text.html in IsolatedTree mode.
+        https://bugs.webkit.org/show_bug.cgi?id=208434
+
+        Reviewed by Chris Fleizach.
+
+        * WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
+        (WTR::AccessibilityController::AccessibilityController): Initializes m_useAXThread.
+        (WTR::AccessibilityController::rootElement): No need to set m_useAXThread here since it is initialize in the constructor.
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
+        (WTR::AccessibilityController::accessibleElementById): Same as above.
+
 2020-03-02  John Wilander  <wilander@apple.com>
 
         ResourceLoadStatistics: Enable cookie blocking and the Storage Access API in ephemeral sessions
index 1242238..a30300f 100644 (file)
@@ -46,6 +46,9 @@ Ref<AccessibilityController> AccessibilityController::create()
 
 AccessibilityController::AccessibilityController()
 {
+#if PLATFORM(COCOA)
+    m_useAXThread = WKAccessibilityCanUseSecondaryAXThread(InjectedBundle::singleton().page()->page());
+#endif
 }
 
 AccessibilityController::~AccessibilityController()
@@ -78,11 +81,6 @@ Ref<AccessibilityUIElement> AccessibilityController::rootElement()
     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     PlatformUIElement root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page));
 
-    // Now that we have a root and the isolated tree is generated, set
-    // m_useAXThread to true for next request to be handled in the secondary thread.
-    if (WKAccessibilityCanUseSecondaryAXThread(InjectedBundle::singleton().page()->page()))
-        m_useAXThread = true;
-
     return AccessibilityUIElement::create(root);
 }
 
index cefaa43..ea4ca28 100644 (file)
@@ -96,11 +96,6 @@ private:
     // do not work for WebKitTestRunner since this is calling directly into
     // WebCore/accessibility via JavaScript without going through HIServices.
     // Thus to simulate the behavior of HIServices, AccessibilityController is spawning a secondary thread to service the JavaScript requests.
-    // The following flag allows to run the very first request in the main
-    // thread and all subsequent requests in the secondary thread. this is what
-    // the behavior would be if using HIServices.
-    // The first request has to be served in the main thread in order to build
-    // the AXIsolatedTree.
     bool m_useAXThread { false };
     BinarySemaphore m_semaphore;
 #endif
index e83ad67..61758cb 100644 (file)
@@ -103,11 +103,6 @@ RefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JS
         root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page));
     });
 
-    // Now that we have a root and the isolated tree is generated, set
-    // m_useAXThread to true for next request to be handled in the secondary thread.
-    if (WKAccessibilityCanUseSecondaryAXThread(InjectedBundle::singleton().page()->page()))
-        m_useAXThread = true;
-
     id result;
     executeOnAXThreadIfPossible([&root, &idAttribute, &result] {
         result = findAccessibleObjectById(root, [NSString stringWithJSStringRef:idAttribute]);