Changeset 253088 in webkit


Ignore:
Timestamp:
Dec 3, 2019 7:44:53 PM (4 years ago)
Author:
Andres Gonzalez
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):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r253086 r253088  
     12019-12-03  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Focus tracking support in the accessibility isolatedtree.
     4        https://bugs.webkit.org/show_bug.cgi?id=204535
     5
     6        Reviewed by Chris Fleizach.
     7
     8        The AXIsolatedTree focused object is now set during the tree generation.
     9        It is updated on handleFocusedUIElementChanged.
     10
     11        * accessibility/AXObjectCache.cpp:
     12        (WebCore::AXObjectCache::focusedImageMapUIElement):
     13        (WebCore::AXObjectCache::focusedObject):
     14        (WebCore::AXObjectCache::isolatedTreeFocusedObject):
     15        (WebCore::AXObjectCache::setIsolatedTreeFocusedObject):
     16        (WebCore::AXObjectCache::focusedUIElementForPage):
     17        (WebCore::AXObjectCache::isolatedTreeRootObject):
     18        (WebCore::AXObjectCache::handleFocusedUIElementChanged):
     19        (WebCore::AXObjectCache::createIsolatedTreeHierarchy):
     20        (WebCore::AXObjectCache::generateIsolatedTree):
     21        * accessibility/AXObjectCache.h:
     22        * accessibility/AccessibilityObject.cpp:
     23        (WebCore::AccessibilityObject::focusedUIElement const):
     24
    1252019-12-03  Ryosuke Niwa  <rniwa@webkit.org>
    226
  • trunk/Source/WebCore/accessibility/AXObjectCache.cpp

    r252609 r253088  
    349349    return nullptr;
    350350}
    351    
     351
     352AXCoreObject* AXObjectCache::focusedObject(Document& document)
     353{
     354    Element* focusedElement = document.focusedElement();
     355    if (is<HTMLAreaElement>(focusedElement))
     356        return focusedImageMapUIElement(downcast<HTMLAreaElement>(focusedElement));
     357
     358    auto* axObjectCache = document.axObjectCache();
     359    if (!axObjectCache)
     360        return nullptr;
     361
     362    AXCoreObject* focus = axObjectCache->getOrCreate(focusedElement ? focusedElement : static_cast<Node*>(&document));
     363    if (!focus)
     364        return nullptr;
     365
     366    if (focus->shouldFocusActiveDescendant()) {
     367        if (auto* descendant = focus->activeDescendant())
     368            focus = descendant;
     369    }
     370
     371    // the HTML element, for example, is focusable but has an AX object that is ignored
     372    if (focus->accessibilityIsIgnored())
     373        focus = focus->parentObjectUnignored();
     374
     375    return focus;
     376}
     377
     378#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
     379AXCoreObject* AXObjectCache::isolatedTreeFocusedObject(Document& document)
     380{
     381    auto pageID = document.pageID();
     382    if (!pageID)
     383        return nullptr;
     384
     385    auto tree = AXIsolatedTree::treeForPageID(*pageID);
     386    if (!tree) {
     387        tree = generateIsolatedTree(*pageID, document);
     388        // Now that we have created our tree, initialize the secondary thread,
     389        // so future requests come in on the other thread.
     390        _AXUIElementUseSecondaryAXThread(true);
     391    }
     392
     393    if (tree)
     394        return tree->focusedUIElement().get();
     395
     396    // Should not get here, couldn't create the IsolatedTree.
     397    ASSERT_NOT_REACHED();
     398    return nullptr;
     399}
     400
     401void AXObjectCache::setIsolatedTreeFocusedObject(Node* focusedNode)
     402{
     403    ASSERT(isMainThread());
     404    auto* focus = getOrCreate(focusedNode);
     405    auto pageID = m_document.pageID();
     406    if (!pageID)
     407        return;
     408
     409    if (auto tree = AXIsolatedTree::treeForPageID(*pageID))
     410        tree->setFocusedNodeID(focus ? focus->objectID() : InvalidAXID);
     411}
     412#endif
     413
    352414AXCoreObject* AXObjectCache::focusedUIElementForPage(const Page* page)
    353415{
     416    ASSERT(isMainThread());
    354417    if (!gAccessibilityEnabled)
    355418        return nullptr;
     
    357420    // get the focused node in the page
    358421    Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
    359     Element* focusedElement = focusedDocument->focusedElement();
    360     if (is<HTMLAreaElement>(focusedElement))
    361         return focusedImageMapUIElement(downcast<HTMLAreaElement>(focusedElement));
    362 
    363     AXCoreObject* obj = focusedDocument->axObjectCache()->getOrCreate(focusedElement ? static_cast<Node*>(focusedElement) : focusedDocument);
    364     if (!obj)
    365         return nullptr;
    366 
    367     if (obj->shouldFocusActiveDescendant()) {
    368         if (AXCoreObject* descendant = obj->activeDescendant())
    369             obj = descendant;
    370     }
    371 
    372     // the HTML element, for example, is focusable but has an AX object that is ignored
    373     if (obj->accessibilityIsIgnored())
    374         obj = obj->parentObjectUnignored();
    375 
    376     return obj;
     422    if (!focusedDocument)
     423        return nullptr;
     424
     425#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
     426    if (clientSupportsIsolatedTree())
     427        return isolatedTreeFocusedObject(*focusedDocument);
     428#endif
     429
     430    return focusedObject(*focusedDocument);
    377431}
    378432
     
    688742    auto tree = AXIsolatedTree::treeForPageID(*pageID);
    689743    if (!tree && isMainThread()) {
    690         tree = generateIsolatedTree(*pageID);
     744        tree = generateIsolatedTree(*pageID, m_document);
    691745        // Now that we have created our tree, initialize the secondary thread,
    692746        // so future requests come in on the other thread.
     
    701755
    702756    // Should not get here, couldn't create or update the IsolatedTree.
    703     ASSERT(false);
     757    ASSERT_NOT_REACHED();
    704758    return nullptr;
    705759}
     
    11041158void AXObjectCache::handleFocusedUIElementChanged(Node* oldNode, Node* newNode)
    11051159{
     1160#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
     1161    setIsolatedTreeFocusedObject(newNode);
     1162#endif
     1163
    11061164    handleMenuItemSelected(newNode);
    11071165    platformHandleFocusedUIElementChanged(oldNode, newNode);
     
    30073065   
    30083066#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
    3009 Ref<AXIsolatedObject> AXObjectCache::createIsolatedTreeHierarchy(AXCoreObject& object, AXID parentID, AXIsolatedTree& tree, Vector<Ref<AXIsolatedObject>>& nodeChanges)
     3067Ref<AXIsolatedObject> AXObjectCache::createIsolatedTreeHierarchy(AXCoreObject& object, AXID parentID, AXObjectCache* axObjectCache, AXIsolatedTree& tree, Vector<Ref<AXIsolatedObject>>& nodeChanges)
    30103068{
    30113069    auto isolatedTreeNode = AXIsolatedObject::create(object);
     
    30143072    isolatedTreeNode->setTreeIdentifier(tree.treeIdentifier());
    30153073    isolatedTreeNode->setParent(parentID);
    3016     attachWrapper(&isolatedTreeNode.get());
     3074    axObjectCache->attachWrapper(&isolatedTreeNode.get());
    30173075
    30183076    for (const auto& child : object.children()) {
    3019         auto staticChild = createIsolatedTreeHierarchy(*child, isolatedTreeNode->objectID(), tree, nodeChanges);
     3077        auto staticChild = createIsolatedTreeHierarchy(*child, isolatedTreeNode->objectID(), axObjectCache, tree, nodeChanges);
    30203078        isolatedTreeNode->appendChild(staticChild->objectID());
    30213079    }
     
    30233081    return isolatedTreeNode;
    30243082}
    3025    
    3026 Ref<AXIsolatedTree> AXObjectCache::generateIsolatedTree(PageIdentifier pageID)
     3083
     3084Ref<AXIsolatedTree> AXObjectCache::generateIsolatedTree(PageIdentifier pageID, Document& document)
    30273085{
    30283086    RELEASE_ASSERT(isMainThread());
     
    30313089    if (!tree)
    30323090        tree = AXIsolatedTree::createTreeForPageID(pageID);
    3033    
    3034     Vector<Ref<AXIsolatedObject>> nodeChanges;
    3035     AccessibilityObject* axRoot = getOrCreate(m_document.view());
    3036     auto isolatedRoot = createIsolatedTreeHierarchy(*axRoot, InvalidAXID, *tree, nodeChanges);
    3037     tree->setRoot(isolatedRoot);
    3038     tree->appendNodeChanges(nodeChanges);
     3091
     3092    // Set the root and focused objects in the isolated tree. For that, we need
     3093    // the root and the focused object in the AXObject tree.
     3094    auto* axObjectCache = document.axObjectCache();
     3095    if (!axObjectCache)
     3096        return makeRef(*tree);
     3097
     3098    auto* axRoot = axObjectCache->getOrCreate(document.view());
     3099    if (axRoot) {
     3100        Vector<Ref<AXIsolatedObject>> nodeChanges;
     3101        auto isolatedRoot = createIsolatedTreeHierarchy(*axRoot, InvalidAXID, axObjectCache, *tree, nodeChanges);
     3102        tree->setRoot(isolatedRoot);
     3103        tree->appendNodeChanges(nodeChanges);
     3104    }
     3105
     3106    auto* axFocus = axObjectCache->focusedObject(document);
     3107    if (axFocus)
     3108        tree->setFocusedNodeID(axFocus->objectID());
    30393109
    30403110    return makeRef(*tree);
  • trunk/Source/WebCore/accessibility/AXObjectCache.h

    r252609 r253088  
    196196private:
    197197    AXCoreObject* isolatedTreeRootObject();
    198     Ref<AXIsolatedTree> generateIsolatedTree(PageIdentifier);
    199     Ref<AXIsolatedObject> createIsolatedTreeHierarchy(AXCoreObject&, AXID, AXIsolatedTree&, Vector<Ref<AXIsolatedObject>>&);
     198    static AXCoreObject* isolatedTreeFocusedObject(Document&);
     199    void setIsolatedTreeFocusedObject(Node*);
     200    static Ref<AXIsolatedTree> generateIsolatedTree(PageIdentifier, Document&);
     201    static Ref<AXIsolatedObject> createIsolatedTreeHierarchy(AXCoreObject&, AXID, AXObjectCache*, AXIsolatedTree&, Vector<Ref<AXIsolatedObject>>&);
    200202#endif
    201203
     
    414416
    415417    static AccessibilityObject* focusedImageMapUIElement(HTMLAreaElement*);
     418    static AXCoreObject* focusedObject(Document&);
    416419
    417420    AXID getAXID(AccessibilityObject*);
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r252181 r253088  
    28682868{
    28692869    auto* page = this->page();
    2870     return page ? AXObjectCache::focusedUIElementForPage(page) : nullptr;
     2870    auto* axObjectCache = this->axObjectCache();
     2871    return page && axObjectCache ? axObjectCache->focusedUIElementForPage(page) : nullptr;
    28712872}
    28722873   
  • trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp

    r252182 r253088  
    107107RefPtr<AXIsolatedObject> AXIsolatedTree::focusedUIElement()
    108108{
     109    m_focusedNodeID = m_pendingFocusedNodeID;
    109110    return nodeForID(m_focusedNodeID);
    110111}
  • trunk/Source/WebKit/ChangeLog

    r253082 r253088  
     12019-12-03  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Focus tracking support in the accessibility isolatedtree.
     4        https://bugs.webkit.org/show_bug.cgi?id=204535
     5
     6        Reviewed by Chris Fleizach.
     7
     8        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
     9        (WKAccessibilityFocusedObject):
     10
    1112019-12-03  John Wilander  <wilander@apple.com>
    212
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp

    r252609 r253088  
    5959#include <WebCore/AccessibilityObjectInterface.h>
    6060#include <WebCore/ApplicationCacheStorage.h>
     61#include <WebCore/FocusController.h>
    6162#include <WebCore/Frame.h>
    6263#include <WebCore/Page.h>
     
    270271        return 0;
    271272
     273    auto* focusedDocument = page->focusController().focusedOrMainFrame().document();
     274    if (!focusedDocument)
     275        return 0;
     276
    272277    WebCore::AXObjectCache::enableAccessibility();
    273278
    274     WebCore::AXCoreObject* focusedObject = WebCore::AXObjectCache::focusedUIElementForPage(page);
     279    auto* axObjectCache = focusedDocument->axObjectCache();
     280    if (!axObjectCache)
     281        return 0;
     282
     283    auto* focusedObject = axObjectCache->focusedUIElementForPage(page);
    275284    if (!focusedObject)
    276285        return 0;
  • trunk/Tools/ChangeLog

    r253082 r253088  
     12019-12-03  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Focus tracking support in the accessibility isolatedtree.
     4        https://bugs.webkit.org/show_bug.cgi?id=204535
     5
     6        Reviewed by Chris Fleizach.
     7
     8        FocusElement can run on the secondary AXThread.
     9
     10        * WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
     11        (WTR::AccessibilityController::focusedElement):
     12
    1132019-12-03  John Wilander  <wilander@apple.com>
    214
  • trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp

    r252832 r253088  
    100100{
    101101    WKBundlePageRef page = InjectedBundle::singleton().page()->page();
    102     void* root = WKAccessibilityFocusedObject(page);
    103    
    104     return AccessibilityUIElement::create(static_cast<PlatformUIElement>(root));   
     102    PlatformUIElement focusedElement = static_cast<PlatformUIElement>(WKAccessibilityFocusedObject(page));
     103    return AccessibilityUIElement::create(focusedElement);
    105104}
    106105
Note: See TracChangeset for help on using the changeset viewer.