blob: 077ccf5752b08b767a52fd2b853265c2f7aebb5c [file] [log] [blame]
dtsengad8ae0f2014-11-04 19:56:241// 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
dtsengbe423432017-02-22 14:05:435#ifndef UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_
6#define UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_
dtsengad8ae0f2014-11-04 19:56:247
8#include <map>
Dominic Mazzoni336bc0062018-09-23 16:46:439#include <string>
thestigcf9519fa2016-08-30 05:50:5410#include <utility>
dtsengad8ae0f2014-11-04 19:56:2411
avib7348942015-12-25 20:57:1012#include "base/macros.h"
dtsengbe423432017-02-22 14:05:4313#include "ui/accessibility/ax_export.h"
Dominic Mazzoni336bc0062018-09-23 16:46:4314#include "ui/accessibility/ax_tree_id.h"
avib7348942015-12-25 20:57:1015
olli.raula36aa8be2015-09-10 11:14:2216namespace base {
dtsengad8ae0f2014-11-04 19:56:2417template <typename T>
18struct DefaultSingletonTraits;
olli.raula36aa8be2015-09-10 11:14:2219} // namespace base
dtsengad8ae0f2014-11-04 19:56:2420
dtsengbe423432017-02-22 14:05:4321namespace ui {
dmazzoni1efe8792015-08-07 01:02:1522
dtseng32ea17362017-02-25 00:52:2723class 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.
dtsengbe423432017-02-22 14:05:4333class AX_EXPORT AXTreeIDRegistry {
dtsengad8ae0f2014-11-04 19:56:2434 public:
thestigcf9519fa2016-08-30 05:50:5435 using FrameID = std::pair<int, int>;
dtsengad8ae0f2014-11-04 19:56:2436
37 // Get the single instance of this class.
38 static AXTreeIDRegistry* GetInstance();
39
David Tsengefd9d9c2018-12-12 16:23:0040 // Gets the frame id based on an ax tree id.
41 FrameID GetFrameID(const AXTreeID& ax_tree_id);
dtsengad8ae0f2014-11-04 19:56:2442
David Tsengefd9d9c2018-12-12 16:23:0043 // 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.
dtseng32ea17362017-02-25 00:52:2747 AXHostDelegate* GetHostDelegate(AXTreeID ax_tree_id);
48
David Tsengefd9d9c2018-12-12 16:23:0049 // Removes an ax tree id, and its associated delegate and frame id (if it
50 // exists).
dtseng32ea17362017-02-25 00:52:2751 void RemoveAXTreeID(AXTreeID ax_tree_id);
dtsengbe423432017-02-22 14:05:4352
David Tsengefd9d9c2018-12-12 16:23:0053 // Associate a frame id with an ax tree id.
54 void SetFrameIDForAXTreeID(const FrameID& frame_id,
55 const AXTreeID& ax_tree_id);
56
dtsengad8ae0f2014-11-04 19:56:2457 private:
olli.raula36aa8be2015-09-10 11:14:2258 friend struct base::DefaultSingletonTraits<AXTreeIDRegistry>;
dtseng32ea17362017-02-25 00:52:2759 friend AXHostDelegate;
60
David Tsengefd9d9c2018-12-12 16:23:0061 // Get or create a ax tree id keyed on |delegate|.
dtseng32ea17362017-02-25 00:52:2762 AXTreeID GetOrCreateAXTreeID(AXHostDelegate* delegate);
dtsengad8ae0f2014-11-04 19:56:2463
64 AXTreeIDRegistry();
65 virtual ~AXTreeIDRegistry();
66
dtsengad8ae0f2014-11-04 19:56:2467 // 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
dtseng32ea17362017-02-25 00:52:2773 // Maps an id to its host delegate.
74 std::map<AXTreeID, AXHostDelegate*> id_to_host_delegate_;
75
dtsengad8ae0f2014-11-04 19:56:2476 DISALLOW_COPY_AND_ASSIGN(AXTreeIDRegistry);
77};
78
dtsengbe423432017-02-22 14:05:4379} // namespace ui
dmazzoni1efe8792015-08-07 01:02:1580
dtsengbe423432017-02-22 14:05:4381#endif // UI_ACCESSIBILITY_AX_TREE_ID_REGISTRY_H_