Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ | 5 #ifndef UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ |
| 6 #define UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ | 6 #define UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "ui/accessibility/ax_export.h" | 12 #include "ui/accessibility/ax_export.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 template <typename T> | 15 template <typename T> |
| 16 struct DefaultSingletonTraits; | 16 struct DefaultSingletonTraits; |
| 17 } // namespace base | 17 } // namespace base |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 // A class which generates a unique id. | 21 class AXHostDelegate; |
| 22 | |
| 23 // This class generates and saves a runtime id for an accessibility tree. | |
| 24 // It provides a few distinct forms of generating an id: | |
| 25 // - from a frame id (which consists of a process and routing id) | |
| 26 // - from a backing object | |
|
dmazzoni
2017/02/20 04:50:46
from a backing AXHostDelegate object
David Tseng
2017/02/21 19:09:05
Done.
| |
| 27 // | |
| 28 // The first form allows underlying instances to change but refer to the same | |
| 29 // frame. | |
| 30 // The second form allows this registry to track the object for later retrieval. | |
| 22 class AX_EXPORT AXTreeIDRegistry { | 31 class AX_EXPORT AXTreeIDRegistry { |
| 23 public: | 32 public: |
| 24 using FrameID = std::pair<int, int>; | 33 using FrameID = std::pair<int, int>; |
| 25 | 34 |
| 26 using AXTreeID = int; | 35 using AXTreeID = int; |
| 27 | 36 |
| 28 static const AXTreeID kNoAXTreeID; | 37 static const AXTreeID kNoAXTreeID; |
| 29 | 38 |
| 30 // Get the single instance of this class. | 39 // Get the single instance of this class. |
| 31 static AXTreeIDRegistry* GetInstance(); | 40 static AXTreeIDRegistry* GetInstance(); |
| 32 | 41 |
| 33 // Obtains a unique id given a |process_id| and |routing_id|. Placeholder | 42 // Methods for FrameID ax tree id generation, and retrieval. |
| 34 // for full implementation once out of process iframe accessibility finalizes. | |
| 35 AXTreeID GetOrCreateAXTreeID(int process_id, int routing_id); | 43 AXTreeID GetOrCreateAXTreeID(int process_id, int routing_id); |
| 36 FrameID GetFrameID(AXTreeID ax_tree_id); | 44 FrameID GetFrameID(AXTreeID ax_tree_id); |
| 45 | |
| 46 // Methods for AXHostDelegate ax tree id generation, and retrieval. | |
| 47 AXTreeID GetOrCreateAXTreeID(AXHostDelegate* delegate); | |
| 48 AXHostDelegate* GetHostDelegate(AXTreeID ax_tree_id); | |
| 49 void SetDesktopHostDelegate(AXHostDelegate* delegate); | |
| 50 | |
| 37 void RemoveAXTreeID(AXTreeID ax_tree_id); | 51 void RemoveAXTreeID(AXTreeID ax_tree_id); |
| 38 | 52 |
| 39 // Create an id not associated with any process. | |
| 40 int CreateID(); | |
| 41 | |
| 42 private: | 53 private: |
| 43 friend struct base::DefaultSingletonTraits<AXTreeIDRegistry>; | 54 friend struct base::DefaultSingletonTraits<AXTreeIDRegistry>; |
| 44 | 55 |
| 45 AXTreeIDRegistry(); | 56 AXTreeIDRegistry(); |
| 46 virtual ~AXTreeIDRegistry(); | 57 virtual ~AXTreeIDRegistry(); |
| 47 | 58 |
| 48 // Tracks the current unique ax frame id. | 59 // Tracks the current unique ax frame id. |
| 49 AXTreeID ax_tree_id_counter_; | 60 AXTreeID ax_tree_id_counter_; |
| 50 | 61 |
| 51 // Maps an accessibility tree to its frame via ids. | 62 // Maps an accessibility tree to its frame via ids. |
| 52 std::map<AXTreeID, FrameID> ax_tree_to_frame_id_map_; | 63 std::map<AXTreeID, FrameID> ax_tree_to_frame_id_map_; |
| 53 | 64 |
| 54 // Maps frames to an accessibility tree via ids. | 65 // Maps frames to an accessibility tree via ids. |
| 55 std::map<FrameID, AXTreeID> frame_to_ax_tree_id_map_; | 66 std::map<FrameID, AXTreeID> frame_to_ax_tree_id_map_; |
| 56 | 67 |
| 68 // Maps an id to its host delegate. | |
| 69 std::map<AXTreeID, AXHostDelegate*> id_to_host_delegate_; | |
| 70 | |
| 57 DISALLOW_COPY_AND_ASSIGN(AXTreeIDRegistry); | 71 DISALLOW_COPY_AND_ASSIGN(AXTreeIDRegistry); |
| 58 }; | 72 }; |
| 59 | 73 |
| 60 } // namespace ui | 74 } // namespace ui |
| 61 | 75 |
| 62 #endif // UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ | 76 #endif // UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_ |
| OLD | NEW |