dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
dtseng | be42343 | 2017-02-22 14:05:43 | [diff] [blame] | 5 | #ifndef UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ |
| 6 | #define UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 7 | |
| 8 | #include <map> |
Dominic Mazzoni | 336bc006 | 2018-09-23 16:46:43 | [diff] [blame] | 9 | #include <string> |
thestig | cf9519fa | 2016-08-30 05:50:54 | [diff] [blame] | 10 | #include <utility> |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 11 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 12 | #include "base/macros.h" |
dtseng | be42343 | 2017-02-22 14:05:43 | [diff] [blame] | 13 | #include "ui/accessibility/ax_export.h" |
Dominic Mazzoni | 336bc006 | 2018-09-23 16:46:43 | [diff] [blame] | 14 | #include "ui/accessibility/ax_tree_id.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 15 | |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 16 | namespace base { |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 17 | template <typename T> |
| 18 | struct DefaultSingletonTraits; |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 19 | } // namespace base |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 20 | |
dtseng | be42343 | 2017-02-22 14:05:43 | [diff] [blame] | 21 | namespace ui { |
dmazzoni | 1efe879 | 2015-08-07 01:02:15 | [diff] [blame] | 22 | |
dtseng | 32ea1736 | 2017-02-25 00:52:27 | [diff] [blame] | 23 | class AXHostDelegate; |
| 24 | |
| 25 | // This class generates and saves a runtime id for an accessibility tree. |
| 26 | // It provides a few distinct forms of generating an id: |
| 27 | // - from a frame id (which consists of a process and routing id) |
| 28 | // - from a backing |AXHostDelegate| object |
| 29 | // |
| 30 | // The first form allows underlying instances to change but refer to the same |
| 31 | // frame. |
| 32 | // The second form allows this registry to track the object for later retrieval. |
dtseng | be42343 | 2017-02-22 14:05:43 | [diff] [blame] | 33 | class AX_EXPORT AXTreeIDRegistry { |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 34 | public: |
thestig | cf9519fa | 2016-08-30 05:50:54 | [diff] [blame] | 35 | using FrameID = std::pair<int, int>; |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 36 | |
| 37 | // Get the single instance of this class. |
| 38 | static AXTreeIDRegistry* GetInstance(); |
| 39 | |
David Tseng | efd9d9c | 2018-12-12 16:23:00 | [diff] [blame^] | 40 | // Gets the frame id based on an ax tree id. |
| 41 | FrameID GetFrameID(const AXTreeID& ax_tree_id); |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 42 | |
David Tseng | efd9d9c | 2018-12-12 16:23:00 | [diff] [blame^] | 43 | // Gets an ax tree id from a frame id. |
| 44 | AXTreeID GetAXTreeID(FrameID frame_id); |
| 45 | |
| 46 | // Retrieve an |AXHostDelegate| based on an ax tree id. |
dtseng | 32ea1736 | 2017-02-25 00:52:27 | [diff] [blame] | 47 | AXHostDelegate* GetHostDelegate(AXTreeID ax_tree_id); |
| 48 | |
David Tseng | efd9d9c | 2018-12-12 16:23:00 | [diff] [blame^] | 49 | // Removes an ax tree id, and its associated delegate and frame id (if it |
| 50 | // exists). |
dtseng | 32ea1736 | 2017-02-25 00:52:27 | [diff] [blame] | 51 | void RemoveAXTreeID(AXTreeID ax_tree_id); |
dtseng | be42343 | 2017-02-22 14:05:43 | [diff] [blame] | 52 | |
David Tseng | efd9d9c | 2018-12-12 16:23:00 | [diff] [blame^] | 53 | // Associate a frame id with an ax tree id. |
| 54 | void SetFrameIDForAXTreeID(const FrameID& frame_id, |
| 55 | const AXTreeID& ax_tree_id); |
| 56 | |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 57 | private: |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 58 | friend struct base::DefaultSingletonTraits<AXTreeIDRegistry>; |
dtseng | 32ea1736 | 2017-02-25 00:52:27 | [diff] [blame] | 59 | friend AXHostDelegate; |
| 60 | |
David Tseng | efd9d9c | 2018-12-12 16:23:00 | [diff] [blame^] | 61 | // Get or create a ax tree id keyed on |delegate|. |
dtseng | 32ea1736 | 2017-02-25 00:52:27 | [diff] [blame] | 62 | AXTreeID GetOrCreateAXTreeID(AXHostDelegate* delegate); |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 63 | |
| 64 | AXTreeIDRegistry(); |
| 65 | virtual ~AXTreeIDRegistry(); |
| 66 | |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 67 | // Maps an accessibility tree to its frame via ids. |
| 68 | std::map<AXTreeID, FrameID> ax_tree_to_frame_id_map_; |
| 69 | |
| 70 | // Maps frames to an accessibility tree via ids. |
| 71 | std::map<FrameID, AXTreeID> frame_to_ax_tree_id_map_; |
| 72 | |
dtseng | 32ea1736 | 2017-02-25 00:52:27 | [diff] [blame] | 73 | // Maps an id to its host delegate. |
| 74 | std::map<AXTreeID, AXHostDelegate*> id_to_host_delegate_; |
| 75 | |
dtseng | ad8ae0f | 2014-11-04 19:56:24 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(AXTreeIDRegistry); |
| 77 | }; |
| 78 | |
dtseng | be42343 | 2017-02-22 14:05:43 | [diff] [blame] | 79 | } // namespace ui |
dmazzoni | 1efe879 | 2015-08-07 01:02:15 | [diff] [blame] | 80 | |
dtseng | be42343 | 2017-02-22 14:05:43 | [diff] [blame] | 81 | #endif // UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ |