1 | /* |
2 | * Copyright (C) 2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(ACCESSIBILITY_ISOLATED_TREE) |
29 | |
30 | #include "AXIsolatedTreeNode.h" |
31 | #include <wtf/HashMap.h> |
32 | #include <wtf/RefPtr.h> |
33 | #include <wtf/ThreadSafeRefCounted.h> |
34 | |
35 | namespace WebCore { |
36 | |
37 | class Page; |
38 | |
39 | class AXIsolatedTree : public ThreadSafeRefCounted<AXIsolatedTree>, public CanMakeWeakPtr<AXIsolatedTree> { |
40 | WTF_MAKE_NONCOPYABLE(AXIsolatedTree); WTF_MAKE_FAST_ALLOCATED; |
41 | |
42 | public: |
43 | static Ref<AXIsolatedTree> create(); |
44 | virtual ~AXIsolatedTree(); |
45 | |
46 | static Ref<AXIsolatedTree> createTreeForPageID(uint64_t pageID); |
47 | WEBCORE_EXPORT static Ref<AXIsolatedTree> initializePageTreeForID(uint64_t pageID, AXObjectCache&); |
48 | WEBCORE_EXPORT static RefPtr<AXIsolatedTree> treeForPageID(uint64_t pageID); |
49 | WEBCORE_EXPORT static RefPtr<AXIsolatedTree> treeForID(AXIsolatedTreeID); |
50 | |
51 | WEBCORE_EXPORT RefPtr<AXIsolatedTreeNode> rootNode(); |
52 | WEBCORE_EXPORT RefPtr<AXIsolatedTreeNode> focusedUIElement(); |
53 | RefPtr<AXIsolatedTreeNode> nodeForID(AXID) const; |
54 | static RefPtr<AXIsolatedTreeNode> nodeInTreeForID(AXIsolatedTreeID, AXID); |
55 | |
56 | // Call on main thread |
57 | void appendNodeChanges(Vector<Ref<AXIsolatedTreeNode>>&); |
58 | void removeNode(AXID); |
59 | |
60 | void setRootNodeID(AXID); |
61 | void setFocusedNodeID(AXID); |
62 | |
63 | // Call on AX thread |
64 | WEBCORE_EXPORT void applyPendingChanges(); |
65 | |
66 | WEBCORE_EXPORT void setInitialRequestInProgress(bool); |
67 | AXIsolatedTreeID treeIdentifier() const { return m_treeID; } |
68 | |
69 | private: |
70 | AXIsolatedTree(); |
71 | |
72 | static HashMap<AXIsolatedTreeID, Ref<AXIsolatedTree>>& treeIDCache(); |
73 | static HashMap<uint64_t, Ref<AXIsolatedTree>>& treePageCache(); |
74 | |
75 | // Only access on AX thread requesting data. |
76 | HashMap<AXID, Ref<AXIsolatedTreeNode>> m_readerThreadNodeMap; |
77 | |
78 | // Written to by main thread under lock, accessed and applied by AX thread. |
79 | Vector<Ref<AXIsolatedTreeNode>> m_pendingAppends; |
80 | Vector<AXID> m_pendingRemovals; |
81 | AXID m_pendingFocusedNodeID; |
82 | AXID m_pendingRootNodeID; |
83 | Lock m_changeLogLock; |
84 | |
85 | AXIsolatedTreeID m_treeID; |
86 | AXID m_rootNodeID { InvalidAXID }; |
87 | AXID m_focusedNodeID { InvalidAXID }; |
88 | bool m_initialRequestInProgress; |
89 | }; |
90 | |
91 | } // namespace WebCore |
92 | |
93 | #endif |
94 | |