Flutter Engine
The Flutter Engine
ax_tree_id_registry.cc
Go to the documentation of this file.
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
6
8#include "base/logging.h"
9
10namespace ui {
11
12// static
14 static AXTreeIDRegistry INSTANCE;
15 return INSTANCE;
16}
17
19 const AXTreeID& ax_tree_id) {
20 auto it = frame_to_ax_tree_id_map_.find(frame_id);
21 if (it != frame_to_ax_tree_id_map_.end()) {
23 return;
24 }
25
26 frame_to_ax_tree_id_map_[frame_id] = ax_tree_id;
27 ax_tree_to_frame_id_map_[ax_tree_id] = frame_id;
28}
29
31 const AXTreeID& ax_tree_id) {
32 auto it = ax_tree_to_frame_id_map_.find(ax_tree_id);
33 if (it != ax_tree_to_frame_id_map_.end())
34 return it->second;
35
36 return FrameID(-1, -1);
37}
38
40 auto it = frame_to_ax_tree_id_map_.find(frame_id);
41 if (it != frame_to_ax_tree_id_map_.end())
42 return it->second;
43
44 return ui::AXTreeIDUnknown();
45}
46
47AXTreeID AXTreeIDRegistry::GetOrCreateAXTreeID(AXActionHandlerBase* handler) {
48 for (auto it : id_to_action_handler_) {
49 if (it.second == handler)
50 return it.first;
51 }
52 AXTreeID new_id = AXTreeID::CreateNewAXTreeID();
53 SetAXTreeID(new_id, handler);
54 return new_id;
55}
56
58 auto it = id_to_action_handler_.find(ax_tree_id);
59 if (it == id_to_action_handler_.end())
60 return nullptr;
61 return it->second;
62}
63
64void AXTreeIDRegistry::SetAXTreeID(const ui::AXTreeID& id,
65 AXActionHandlerBase* action_handler) {
66 BASE_DCHECK(id_to_action_handler_.find(id) == id_to_action_handler_.end());
67 id_to_action_handler_[id] = action_handler;
68}
69
71 auto frame_it = ax_tree_to_frame_id_map_.find(ax_tree_id);
72 if (frame_it != ax_tree_to_frame_id_map_.end()) {
73 frame_to_ax_tree_id_map_.erase(frame_it->second);
74 ax_tree_to_frame_id_map_.erase(frame_it);
75 }
76
77 auto action_it = id_to_action_handler_.find(ax_tree_id);
78 if (action_it != id_to_action_handler_.end())
79 id_to_action_handler_.erase(action_it);
80}
81
82AXTreeIDRegistry::AXTreeIDRegistry() {}
83
85
86} // namespace ui
std::pair< int, int > FrameID
AXActionHandlerBase * GetActionHandler(AXTreeID ax_tree_id)
void RemoveAXTreeID(AXTreeID ax_tree_id)
static AXTreeIDRegistry & GetInstance()
AXTreeID GetAXTreeID(FrameID frame_id)
FrameID GetFrameID(const AXTreeID &ax_tree_id)
void SetFrameIDForAXTreeID(const FrameID &frame_id, const AXTreeID &ax_tree_id)
static AXTreeID CreateNewAXTreeID()
Definition: ax_tree_id.cc:47
const AXTreeID & AXTreeIDUnknown()
Definition: ax_tree_id.cc:103
const uintptr_t id
#define BASE_DCHECK(condition)
Definition: logging.h:63
#define BASE_UNREACHABLE()
Definition: logging.h:69