forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathax_event_generator.h
183 lines (160 loc) · 6.49 KB
/
ax_event_generator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_ACCESSIBILITY_AX_EVENT_GENERATOR_H_
#define UI_ACCESSIBILITY_AX_EVENT_GENERATOR_H_
#include <map>
#include <set>
#include <vector>
#include "ui/accessibility/ax_export.h"
#include "ui/accessibility/ax_tree.h"
namespace ui {
// Subclass of AXTreeDelegate that automatically generates AXEvents to fire
// based on changes to an accessibility tree. Every platform
// tends to want different events, so this class lets each platform
// handle the events it wants and ignore the others.
class AX_EXPORT AXEventGenerator : public AXTreeDelegate {
public:
enum class Event : int32_t {
ACTIVE_DESCENDANT_CHANGED,
ALERT,
CHECKED_STATE_CHANGED,
CHILDREN_CHANGED,
COLLAPSED,
DESCRIPTION_CHANGED,
DOCUMENT_SELECTION_CHANGED,
DOCUMENT_TITLE_CHANGED,
EXPANDED,
INVALID_STATUS_CHANGED,
LIVE_REGION_CHANGED, // Fired on the root of a live region.
LIVE_REGION_CREATED,
LIVE_REGION_NODE_CHANGED, // Fired on a node within a live region.
LOAD_COMPLETE,
MENU_ITEM_SELECTED,
NAME_CHANGED,
OTHER_ATTRIBUTE_CHANGED,
ROLE_CHANGED,
ROW_COUNT_CHANGED,
SCROLL_POSITION_CHANGED,
SELECTED_CHANGED,
SELECTED_CHILDREN_CHANGED,
STATE_CHANGED,
VALUE_CHANGED,
};
struct TargetedEvent {
TargetedEvent(ui::AXNode* node, Event event);
ui::AXNode* node;
Event event;
};
class AX_EXPORT Iterator
: public std::iterator<std::input_iterator_tag, TargetedEvent> {
public:
Iterator(const std::map<AXNode*, std::set<Event>>& map,
const std::map<AXNode*, std::set<Event>>::const_iterator& head);
Iterator(const Iterator& other);
~Iterator();
bool operator!=(const Iterator& rhs) const;
Iterator& operator++();
TargetedEvent operator*() const;
private:
const std::map<AXNode*, std::set<Event>>& map_;
std::map<AXNode*, std::set<Event>>::const_iterator map_iter_;
std::set<Event>::const_iterator set_iter_;
};
// If you use this constructor, you must call SetTree
// before using this class.
AXEventGenerator();
// Automatically registers itself as the delegate of |tree| and
// clears it on desctruction. |tree| must be valid for the lifetime
// of this object.
explicit AXEventGenerator(AXTree* tree);
~AXEventGenerator() override;
// Clears this class as the delegate of the previous tree that was
// being monitored, if any, and starts monitoring |new_tree|, if not
// nullptr. Note that |new_tree| must be valid for the lifetime of
// this object or until you call SetTree again.
void SetTree(AXTree* new_tree);
// Null |tree_| without accessing it or destroying it.
void ReleaseTree();
Iterator begin() const {
return Iterator(tree_events_, tree_events_.begin());
}
Iterator end() const { return Iterator(tree_events_, tree_events_.end()); }
// Clear any previously added events.
void ClearEvents();
// This is called automatically based on changes to the tree observed
// by AXTreeDelegate, but you can also call it directly to add events
// and retrieve them later.
//
// Note that events are organized by node and then by event id to
// efficiently remove duplicates, so events won't be retrieved in the
// same order they were added.
void AddEvent(ui::AXNode* node, Event event);
protected:
// AXTreeDelegate overrides.
void OnNodeDataWillChange(AXTree* tree,
const AXNodeData& old_node_data,
const AXNodeData& new_node_data) override;
void OnRoleChanged(AXTree* tree,
AXNode* node,
AXRole old_role,
AXRole new_role) override;
void OnStateChanged(AXTree* tree,
AXNode* node,
AXState state,
bool new_value) override;
void OnStringAttributeChanged(AXTree* tree,
AXNode* node,
AXStringAttribute attr,
const std::string& old_value,
const std::string& new_value) override;
void OnIntAttributeChanged(AXTree* tree,
AXNode* node,
AXIntAttribute attr,
int32_t old_value,
int32_t new_value) override;
void OnFloatAttributeChanged(AXTree* tree,
AXNode* node,
AXFloatAttribute attr,
float old_value,
float new_value) override;
void OnBoolAttributeChanged(AXTree* tree,
AXNode* node,
AXBoolAttribute attr,
bool new_value) override;
void OnIntListAttributeChanged(
AXTree* tree,
AXNode* node,
AXIntListAttribute attr,
const std::vector<int32_t>& old_value,
const std::vector<int32_t>& new_value) override;
void OnStringListAttributeChanged(
AXTree* tree,
AXNode* node,
AXStringListAttribute attr,
const std::vector<std::string>& old_value,
const std::vector<std::string>& new_value) override;
void OnTreeDataChanged(AXTree* tree,
const ui::AXTreeData& old_data,
const ui::AXTreeData& new_data) override;
void OnNodeWillBeDeleted(AXTree* tree, AXNode* node) override;
void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node) override;
void OnNodeWillBeReparented(AXTree* tree, AXNode* node) override;
void OnSubtreeWillBeReparented(AXTree* tree, AXNode* node) override;
void OnNodeCreated(AXTree* tree, AXNode* node) override;
void OnNodeReparented(AXTree* tree, AXNode* node) override;
void OnNodeChanged(AXTree* tree, AXNode* node) override;
void OnAtomicUpdateFinished(AXTree* tree,
bool root_changed,
const std::vector<Change>& changes) override;
private:
void FireLiveRegionEvents(AXNode* node);
void FireActiveDescendantEvents();
AXTree* tree_ = nullptr; // Not owned.
std::map<AXNode*, std::set<Event>> tree_events_;
// Valid between the call to OnIntAttributeChanged and the call to
// OnAtomicUpdateFinished. List of nodes whose active descendant changed.
std::vector<AXNode*> active_descendant_changed_;
};
} // namespace ui
#endif // UI_ACCESSIBILITY_AX_EVENT_GENERATOR_H_