Title: [253088] trunk
Revision
253088
Author
andresg...@apple.com
Date
2019-12-03 19:44:53 -0800 (Tue, 03 Dec 2019)

Log Message

Focus tracking support in the accessibility isolatedtree.
https://bugs.webkit.org/show_bug.cgi?id=204535

Reviewed by Chris Fleizach.

Source/WebCore:

The AXIsolatedTree focused object is now set during the tree generation.
It is updated on handleFocusedUIElementChanged.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::focusedImageMapUIElement):
(WebCore::AXObjectCache::focusedObject):
(WebCore::AXObjectCache::isolatedTreeFocusedObject):
(WebCore::AXObjectCache::setIsolatedTreeFocusedObject):
(WebCore::AXObjectCache::focusedUIElementForPage):
(WebCore::AXObjectCache::isolatedTreeRootObject):
(WebCore::AXObjectCache::handleFocusedUIElementChanged):
(WebCore::AXObjectCache::createIsolatedTreeHierarchy):
(WebCore::AXObjectCache::generateIsolatedTree):
* accessibility/AXObjectCache.h:
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::focusedUIElement const):

Source/WebKit:

* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKAccessibilityFocusedObject):

Tools:

FocusElement can run on the secondary AXThread.

* WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
(WTR::AccessibilityController::focusedElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (253087 => 253088)


--- trunk/Source/WebCore/ChangeLog	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Source/WebCore/ChangeLog	2019-12-04 03:44:53 UTC (rev 253088)
@@ -1,3 +1,27 @@
+2019-12-03  Andres Gonzalez  <andresg...@apple.com>
+
+        Focus tracking support in the accessibility isolatedtree.
+        https://bugs.webkit.org/show_bug.cgi?id=204535
+
+        Reviewed by Chris Fleizach.
+
+        The AXIsolatedTree focused object is now set during the tree generation.
+        It is updated on handleFocusedUIElementChanged.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::focusedImageMapUIElement):
+        (WebCore::AXObjectCache::focusedObject):
+        (WebCore::AXObjectCache::isolatedTreeFocusedObject):
+        (WebCore::AXObjectCache::setIsolatedTreeFocusedObject):
+        (WebCore::AXObjectCache::focusedUIElementForPage):
+        (WebCore::AXObjectCache::isolatedTreeRootObject):
+        (WebCore::AXObjectCache::handleFocusedUIElementChanged):
+        (WebCore::AXObjectCache::createIsolatedTreeHierarchy):
+        (WebCore::AXObjectCache::generateIsolatedTree):
+        * accessibility/AXObjectCache.h:
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::focusedUIElement const):
+
 2019-12-03  Ryosuke Niwa  <rn...@webkit.org>
 
         Use the event loop instead of DocumentEventQueue and WorkerEventQueue

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (253087 => 253088)


--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2019-12-04 03:44:53 UTC (rev 253088)
@@ -348,34 +348,88 @@
     
     return nullptr;
 }
-    
-AXCoreObject* AXObjectCache::focusedUIElementForPage(const Page* page)
+
+AXCoreObject* AXObjectCache::focusedObject(Document& document)
 {
-    if (!gAccessibilityEnabled)
-        return nullptr;
-
-    // get the focused node in the page
-    Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
-    Element* focusedElement = focusedDocument->focusedElement();
+    Element* focusedElement = document.focusedElement();
     if (is<HTMLAreaElement>(focusedElement))
         return focusedImageMapUIElement(downcast<HTMLAreaElement>(focusedElement));
 
-    AXCoreObject* obj = focusedDocument->axObjectCache()->getOrCreate(focusedElement ? static_cast<Node*>(focusedElement) : focusedDocument);
-    if (!obj)
+    auto* axObjectCache = document.axObjectCache();
+    if (!axObjectCache)
         return nullptr;
 
-    if (obj->shouldFocusActiveDescendant()) {
-        if (AXCoreObject* descendant = obj->activeDescendant())
-            obj = descendant;
+    AXCoreObject* focus = axObjectCache->getOrCreate(focusedElement ? focusedElement : static_cast<Node*>(&document));
+    if (!focus)
+        return nullptr;
+
+    if (focus->shouldFocusActiveDescendant()) {
+        if (auto* descendant = focus->activeDescendant())
+            focus = descendant;
     }
 
     // the HTML element, for example, is focusable but has an AX object that is ignored
-    if (obj->accessibilityIsIgnored())
-        obj = obj->parentObjectUnignored();
+    if (focus->accessibilityIsIgnored())
+        focus = focus->parentObjectUnignored();
 
-    return obj;
+    return focus;
 }
 
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+AXCoreObject* AXObjectCache::isolatedTreeFocusedObject(Document& document)
+{
+    auto pageID = document.pageID();
+    if (!pageID)
+        return nullptr;
+
+    auto tree = AXIsolatedTree::treeForPageID(*pageID);
+    if (!tree) {
+        tree = generateIsolatedTree(*pageID, document);
+        // Now that we have created our tree, initialize the secondary thread,
+        // so future requests come in on the other thread.
+        _AXUIElementUseSecondaryAXThread(true);
+    }
+
+    if (tree)
+        return tree->focusedUIElement().get();
+
+    // Should not get here, couldn't create the IsolatedTree.
+    ASSERT_NOT_REACHED();
+    return nullptr;
+}
+
+void AXObjectCache::setIsolatedTreeFocusedObject(Node* focusedNode)
+{
+    ASSERT(isMainThread());
+    auto* focus = getOrCreate(focusedNode);
+    auto pageID = m_document.pageID();
+    if (!pageID)
+        return;
+
+    if (auto tree = AXIsolatedTree::treeForPageID(*pageID))
+        tree->setFocusedNodeID(focus ? focus->objectID() : InvalidAXID);
+}
+#endif
+
+AXCoreObject* AXObjectCache::focusedUIElementForPage(const Page* page)
+{
+    ASSERT(isMainThread());
+    if (!gAccessibilityEnabled)
+        return nullptr;
+
+    // get the focused node in the page
+    Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
+    if (!focusedDocument)
+        return nullptr;
+
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    if (clientSupportsIsolatedTree())
+        return isolatedTreeFocusedObject(*focusedDocument);
+#endif
+
+    return focusedObject(*focusedDocument);
+}
+
 AccessibilityObject* AXObjectCache::get(Widget* widget)
 {
     if (!widget)
@@ -687,7 +741,7 @@
 
     auto tree = AXIsolatedTree::treeForPageID(*pageID);
     if (!tree && isMainThread()) {
-        tree = generateIsolatedTree(*pageID);
+        tree = generateIsolatedTree(*pageID, m_document);
         // Now that we have created our tree, initialize the secondary thread,
         // so future requests come in on the other thread.
         _AXUIElementUseSecondaryAXThread(true);
@@ -700,7 +754,7 @@
     }
 
     // Should not get here, couldn't create or update the IsolatedTree.
-    ASSERT(false);
+    ASSERT_NOT_REACHED();
     return nullptr;
 }
 #endif
@@ -1103,6 +1157,10 @@
     
 void AXObjectCache::handleFocusedUIElementChanged(Node* oldNode, Node* newNode)
 {
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    setIsolatedTreeFocusedObject(newNode);
+#endif
+
     handleMenuItemSelected(newNode);
     platformHandleFocusedUIElementChanged(oldNode, newNode);
 }
@@ -3006,7 +3064,7 @@
 }
     
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-Ref<AXIsolatedObject> AXObjectCache::createIsolatedTreeHierarchy(AXCoreObject& object, AXID parentID, AXIsolatedTree& tree, Vector<Ref<AXIsolatedObject>>& nodeChanges)
+Ref<AXIsolatedObject> AXObjectCache::createIsolatedTreeHierarchy(AXCoreObject& object, AXID parentID, AXObjectCache* axObjectCache, AXIsolatedTree& tree, Vector<Ref<AXIsolatedObject>>& nodeChanges)
 {
     auto isolatedTreeNode = AXIsolatedObject::create(object);
     nodeChanges.append(isolatedTreeNode.copyRef());
@@ -3013,17 +3071,17 @@
 
     isolatedTreeNode->setTreeIdentifier(tree.treeIdentifier());
     isolatedTreeNode->setParent(parentID);
-    attachWrapper(&isolatedTreeNode.get());
+    axObjectCache->attachWrapper(&isolatedTreeNode.get());
 
     for (const auto& child : object.children()) {
-        auto staticChild = createIsolatedTreeHierarchy(*child, isolatedTreeNode->objectID(), tree, nodeChanges);
+        auto staticChild = createIsolatedTreeHierarchy(*child, isolatedTreeNode->objectID(), axObjectCache, tree, nodeChanges);
         isolatedTreeNode->appendChild(staticChild->objectID());
     }
 
     return isolatedTreeNode;
 }
-    
-Ref<AXIsolatedTree> AXObjectCache::generateIsolatedTree(PageIdentifier pageID)
+
+Ref<AXIsolatedTree> AXObjectCache::generateIsolatedTree(PageIdentifier pageID, Document& document)
 {
     RELEASE_ASSERT(isMainThread());
 
@@ -3030,13 +3088,25 @@
     auto tree = AXIsolatedTree::treeForPageID(pageID);
     if (!tree)
         tree = AXIsolatedTree::createTreeForPageID(pageID);
-    
-    Vector<Ref<AXIsolatedObject>> nodeChanges;
-    AccessibilityObject* axRoot = getOrCreate(m_document.view());
-    auto isolatedRoot = createIsolatedTreeHierarchy(*axRoot, InvalidAXID, *tree, nodeChanges);
-    tree->setRoot(isolatedRoot);
-    tree->appendNodeChanges(nodeChanges);
 
+    // Set the root and focused objects in the isolated tree. For that, we need
+    // the root and the focused object in the AXObject tree.
+    auto* axObjectCache = document.axObjectCache();
+    if (!axObjectCache)
+        return makeRef(*tree);
+
+    auto* axRoot = axObjectCache->getOrCreate(document.view());
+    if (axRoot) {
+        Vector<Ref<AXIsolatedObject>> nodeChanges;
+        auto isolatedRoot = createIsolatedTreeHierarchy(*axRoot, InvalidAXID, axObjectCache, *tree, nodeChanges);
+        tree->setRoot(isolatedRoot);
+        tree->appendNodeChanges(nodeChanges);
+    }
+
+    auto* axFocus = axObjectCache->focusedObject(document);
+    if (axFocus)
+        tree->setFocusedNodeID(axFocus->objectID());
+
     return makeRef(*tree);
 }
 #endif

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.h (253087 => 253088)


--- trunk/Source/WebCore/accessibility/AXObjectCache.h	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.h	2019-12-04 03:44:53 UTC (rev 253088)
@@ -195,8 +195,10 @@
     WEBCORE_EXPORT static bool clientSupportsIsolatedTree();
 private:
     AXCoreObject* isolatedTreeRootObject();
-    Ref<AXIsolatedTree> generateIsolatedTree(PageIdentifier);
-    Ref<AXIsolatedObject> createIsolatedTreeHierarchy(AXCoreObject&, AXID, AXIsolatedTree&, Vector<Ref<AXIsolatedObject>>&);
+    static AXCoreObject* isolatedTreeFocusedObject(Document&);
+    void setIsolatedTreeFocusedObject(Node*);
+    static Ref<AXIsolatedTree> generateIsolatedTree(PageIdentifier, Document&);
+    static Ref<AXIsolatedObject> createIsolatedTreeHierarchy(AXCoreObject&, AXID, AXObjectCache*, AXIsolatedTree&, Vector<Ref<AXIsolatedObject>>&);
 #endif
 
 public:
@@ -413,6 +415,7 @@
     AccessibilityObject* rootWebArea();
 
     static AccessibilityObject* focusedImageMapUIElement(HTMLAreaElement*);
+    static AXCoreObject* focusedObject(Document&);
 
     AXID getAXID(AccessibilityObject*);
 

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (253087 => 253088)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2019-12-04 03:44:53 UTC (rev 253088)
@@ -2867,7 +2867,8 @@
 AXCoreObject* AccessibilityObject::focusedUIElement() const
 {
     auto* page = this->page();
-    return page ? AXObjectCache::focusedUIElementForPage(page) : nullptr;
+    auto* axObjectCache = this->axObjectCache();
+    return page && axObjectCache ? axObjectCache->focusedUIElementForPage(page) : nullptr;
 }
     
 AccessibilitySortDirection AccessibilityObject::sortDirection() const

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp (253087 => 253088)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp	2019-12-04 03:44:53 UTC (rev 253088)
@@ -106,6 +106,7 @@
 
 RefPtr<AXIsolatedObject> AXIsolatedTree::focusedUIElement()
 {
+    m_focusedNodeID = m_pendingFocusedNodeID;
     return nodeForID(m_focusedNodeID);
 }
     

Modified: trunk/Source/WebKit/ChangeLog (253087 => 253088)


--- trunk/Source/WebKit/ChangeLog	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Source/WebKit/ChangeLog	2019-12-04 03:44:53 UTC (rev 253088)
@@ -1,3 +1,13 @@
+2019-12-03  Andres Gonzalez  <andresg...@apple.com>
+
+        Focus tracking support in the accessibility isolatedtree.
+        https://bugs.webkit.org/show_bug.cgi?id=204535
+
+        Reviewed by Chris Fleizach.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+        (WKAccessibilityFocusedObject):
+
 2019-12-03  John Wilander  <wilan...@apple.com>
 
         Resource Load Statistics (experimental): Delete non-cookie website data after 7 days of no user interaction

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp (253087 => 253088)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2019-12-04 03:44:53 UTC (rev 253088)
@@ -58,6 +58,7 @@
 #include <WebCore/AXObjectCache.h>
 #include <WebCore/AccessibilityObjectInterface.h>
 #include <WebCore/ApplicationCacheStorage.h>
+#include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageOverlay.h>
@@ -269,9 +270,17 @@
     if (!page)
         return 0;
 
+    auto* focusedDocument = page->focusController().focusedOrMainFrame().document();
+    if (!focusedDocument)
+        return 0;
+
     WebCore::AXObjectCache::enableAccessibility();
 
-    WebCore::AXCoreObject* focusedObject = WebCore::AXObjectCache::focusedUIElementForPage(page);
+    auto* axObjectCache = focusedDocument->axObjectCache();
+    if (!axObjectCache)
+        return 0;
+
+    auto* focusedObject = axObjectCache->focusedUIElementForPage(page);
     if (!focusedObject)
         return 0;
     

Modified: trunk/Tools/ChangeLog (253087 => 253088)


--- trunk/Tools/ChangeLog	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Tools/ChangeLog	2019-12-04 03:44:53 UTC (rev 253088)
@@ -1,3 +1,15 @@
+2019-12-03  Andres Gonzalez  <andresg...@apple.com>
+
+        Focus tracking support in the accessibility isolatedtree.
+        https://bugs.webkit.org/show_bug.cgi?id=204535
+
+        Reviewed by Chris Fleizach.
+
+        FocusElement can run on the secondary AXThread.
+
+        * WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
+        (WTR::AccessibilityController::focusedElement):
+
 2019-12-03  John Wilander  <wilan...@apple.com>
 
         Resource Load Statistics (experimental): Delete non-cookie website data after 7 days of no user interaction

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp (253087 => 253088)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp	2019-12-04 03:31:32 UTC (rev 253087)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp	2019-12-04 03:44:53 UTC (rev 253088)
@@ -99,9 +99,8 @@
 Ref<AccessibilityUIElement> AccessibilityController::focusedElement()
 {
     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
-    void* root = WKAccessibilityFocusedObject(page);
-    
-    return AccessibilityUIElement::create(static_cast<PlatformUIElement>(root));    
+    PlatformUIElement focusedElement = static_cast<PlatformUIElement>(WKAccessibilityFocusedObject(page));
+    return AccessibilityUIElement::create(focusedElement);
 }
 
 void AccessibilityController::execute(Function<void()>&& function)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to