| Flutter Windows Embedder |

accessibility_bridge_windows.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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
5 #include "flutter/shell/platform/windows/accessibility_bridge_windows.h"
6
7 #include "flutter/fml/logging.h"
8 #include "flutter/shell/platform/windows/flutter_platform_node_delegate_windows.h"
9 #include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h"
10
11 namespace flutter {
12
13 AccessibilityBridgeWindows::AccessibilityBridgeWindows(FlutterWindowsView* view)
14 : view_(view) {
15 FML_DCHECK(view_);
16 }
17
18 void AccessibilityBridgeWindows::OnAccessibilityEvent(
19 ui::AXEventGenerator::TargetedEvent targeted_event) {
20 ui::AXNode* ax_node = targeted_event.node;
21 ui::AXEventGenerator::Event event_type = targeted_event.event_params.event;
22
23 auto node_delegate =
24 GetFlutterPlatformNodeDelegateFromID(ax_node->id()).lock();
25 FML_DCHECK(node_delegate)
26 << "No FlutterPlatformNodeDelegate found for node ID " << ax_node->id();
27 std::shared_ptr<FlutterPlatformNodeDelegateWindows> win_delegate =
28 std::static_pointer_cast<FlutterPlatformNodeDelegateWindows>(
29 node_delegate);
30
31 switch (event_type) {
32 case ui::AXEventGenerator::Event::ALERT:
33 DispatchWinAccessibilityEvent(win_delegate, ax::mojom::Event::kAlert);
34 break;
35 case ui::AXEventGenerator::Event::CHECKED_STATE_CHANGED:
36 DispatchWinAccessibilityEvent(win_delegate,
37 ax::mojom::Event::kValueChanged);
38 break;
39 case ui::AXEventGenerator::Event::CHILDREN_CHANGED:
40 DispatchWinAccessibilityEvent(win_delegate,
41 ax::mojom::Event::kChildrenChanged);
42 break;
43 case ui::AXEventGenerator::Event::DOCUMENT_SELECTION_CHANGED: {
44 // An event indicating a change in document selection should be fired
45 // only for the focused node whose selection has changed. If a valid
46 // caret and selection exist in the app tree, they must both be within
47 // the focus node.
48 auto focus_delegate = GetFocusedNode().lock();
49 if (focus_delegate) {
50 win_delegate =
51 std::static_pointer_cast<FlutterPlatformNodeDelegateWindows>(
52 focus_delegate);
53 }
54 DispatchWinAccessibilityEvent(
55 win_delegate, ax::mojom::Event::kDocumentSelectionChanged);
56 break;
57 }
58 case ui::AXEventGenerator::Event::FOCUS_CHANGED:
59 DispatchWinAccessibilityEvent(win_delegate, ax::mojom::Event::kFocus);
60 SetFocus(win_delegate);
61 break;
62 case ui::AXEventGenerator::Event::IGNORED_CHANGED:
63 if (ax_node->IsIgnored()) {
64 DispatchWinAccessibilityEvent(win_delegate, ax::mojom::Event::kHide);
65 }
66 break;
67 case ui::AXEventGenerator::Event::IMAGE_ANNOTATION_CHANGED:
68 DispatchWinAccessibilityEvent(win_delegate,
69 ax::mojom::Event::kTextChanged);
70 break;
71 case ui::AXEventGenerator::Event::LIVE_REGION_CHANGED:
72 DispatchWinAccessibilityEvent(win_delegate,
73 ax::mojom::Event::kLiveRegionChanged);
74 break;
75 case ui::AXEventGenerator::Event::NAME_CHANGED:
76 DispatchWinAccessibilityEvent(win_delegate,
77 ax::mojom::Event::kTextChanged);
78 break;
79 case ui::AXEventGenerator::Event::SCROLL_HORIZONTAL_POSITION_CHANGED:
80 DispatchWinAccessibilityEvent(win_delegate,
81 ax::mojom::Event::kScrollPositionChanged);
82 break;
83 case ui::AXEventGenerator::Event::SCROLL_VERTICAL_POSITION_CHANGED:
84 DispatchWinAccessibilityEvent(win_delegate,
85 ax::mojom::Event::kScrollPositionChanged);
86 break;
87 case ui::AXEventGenerator::Event::SELECTED_CHANGED:
88 DispatchWinAccessibilityEvent(win_delegate,
89 ax::mojom::Event::kValueChanged);
90 break;
91 case ui::AXEventGenerator::Event::SELECTED_CHILDREN_CHANGED:
92 DispatchWinAccessibilityEvent(win_delegate,
93 ax::mojom::Event::kSelectedChildrenChanged);
94 break;
95 case ui::AXEventGenerator::Event::SUBTREE_CREATED:
96 DispatchWinAccessibilityEvent(win_delegate, ax::mojom::Event::kShow);
97 break;
98 case ui::AXEventGenerator::Event::VALUE_CHANGED:
99 DispatchWinAccessibilityEvent(win_delegate,
100 ax::mojom::Event::kValueChanged);
101 break;
102 case ui::AXEventGenerator::Event::WIN_IACCESSIBLE_STATE_CHANGED:
103 DispatchWinAccessibilityEvent(win_delegate,
104 ax::mojom::Event::kStateChanged);
105 break;
106 case ui::AXEventGenerator::Event::ACCESS_KEY_CHANGED:
107 case ui::AXEventGenerator::Event::ACTIVE_DESCENDANT_CHANGED:
108 case ui::AXEventGenerator::Event::ATK_TEXT_OBJECT_ATTRIBUTE_CHANGED:
109 case ui::AXEventGenerator::Event::ATOMIC_CHANGED:
110 case ui::AXEventGenerator::Event::AUTO_COMPLETE_CHANGED:
111 case ui::AXEventGenerator::Event::BUSY_CHANGED:
112 case ui::AXEventGenerator::Event::CLASS_NAME_CHANGED:
113 case ui::AXEventGenerator::Event::COLLAPSED:
114 case ui::AXEventGenerator::Event::CONTROLS_CHANGED:
115 case ui::AXEventGenerator::Event::DESCRIBED_BY_CHANGED:
116 case ui::AXEventGenerator::Event::DESCRIPTION_CHANGED:
117 case ui::AXEventGenerator::Event::DOCUMENT_TITLE_CHANGED:
118 case ui::AXEventGenerator::Event::DROPEFFECT_CHANGED:
119 case ui::AXEventGenerator::Event::ENABLED_CHANGED:
120 case ui::AXEventGenerator::Event::EXPANDED:
121 case ui::AXEventGenerator::Event::FLOW_FROM_CHANGED:
122 case ui::AXEventGenerator::Event::FLOW_TO_CHANGED:
123 case ui::AXEventGenerator::Event::GRABBED_CHANGED:
124 case ui::AXEventGenerator::Event::HASPOPUP_CHANGED:
125 case ui::AXEventGenerator::Event::HIERARCHICAL_LEVEL_CHANGED:
126 case ui::AXEventGenerator::Event::INVALID_STATUS_CHANGED:
127 case ui::AXEventGenerator::Event::KEY_SHORTCUTS_CHANGED:
128 case ui::AXEventGenerator::Event::LABELED_BY_CHANGED:
129 case ui::AXEventGenerator::Event::LANGUAGE_CHANGED:
130 case ui::AXEventGenerator::Event::LAYOUT_INVALIDATED:
131 case ui::AXEventGenerator::Event::LIVE_REGION_CREATED:
132 case ui::AXEventGenerator::Event::LIVE_REGION_NODE_CHANGED:
133 case ui::AXEventGenerator::Event::LIVE_RELEVANT_CHANGED:
134 case ui::AXEventGenerator::Event::LIVE_STATUS_CHANGED:
135 case ui::AXEventGenerator::Event::LOAD_COMPLETE:
136 case ui::AXEventGenerator::Event::LOAD_START:
137 case ui::AXEventGenerator::Event::MENU_ITEM_SELECTED:
138 case ui::AXEventGenerator::Event::MULTILINE_STATE_CHANGED:
139 case ui::AXEventGenerator::Event::MULTISELECTABLE_STATE_CHANGED:
140 case ui::AXEventGenerator::Event::OBJECT_ATTRIBUTE_CHANGED:
141 case ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED:
142 case ui::AXEventGenerator::Event::PLACEHOLDER_CHANGED:
143 case ui::AXEventGenerator::Event::PORTAL_ACTIVATED:
144 case ui::AXEventGenerator::Event::POSITION_IN_SET_CHANGED:
145 case ui::AXEventGenerator::Event::READONLY_CHANGED:
146 case ui::AXEventGenerator::Event::RELATED_NODE_CHANGED:
147 case ui::AXEventGenerator::Event::REQUIRED_STATE_CHANGED:
148 case ui::AXEventGenerator::Event::ROLE_CHANGED:
149 case ui::AXEventGenerator::Event::ROW_COUNT_CHANGED:
150 case ui::AXEventGenerator::Event::SET_SIZE_CHANGED:
151 case ui::AXEventGenerator::Event::SORT_CHANGED:
152 case ui::AXEventGenerator::Event::STATE_CHANGED:
153 case ui::AXEventGenerator::Event::TEXT_ATTRIBUTE_CHANGED:
154 case ui::AXEventGenerator::Event::VALUE_MAX_CHANGED:
155 case ui::AXEventGenerator::Event::VALUE_MIN_CHANGED:
156 case ui::AXEventGenerator::Event::VALUE_STEP_CHANGED:
157 // Unhandled event type.
158 break;
159 }
160 }
161
162 void AccessibilityBridgeWindows::DispatchAccessibilityAction(
163 AccessibilityNodeId target,
164 FlutterSemanticsAction action,
165 fml::MallocMapping data) {
166 view_->GetEngine()->DispatchSemanticsAction(view_->view_id(), target, action,
167 std::move(data));
168 }
169
170 std::shared_ptr<FlutterPlatformNodeDelegate>
171 AccessibilityBridgeWindows::CreateFlutterPlatformNodeDelegate() {
172 return std::make_shared<FlutterPlatformNodeDelegateWindows>(
173 shared_from_this(), view_);
174 }
175
176 void AccessibilityBridgeWindows::DispatchWinAccessibilityEvent(
177 std::shared_ptr<FlutterPlatformNodeDelegateWindows> node_delegate,
178 ax::mojom::Event event_type) {
179 node_delegate->DispatchWinAccessibilityEvent(event_type);
180 }
181
182 void AccessibilityBridgeWindows::SetFocus(
183 std::shared_ptr<FlutterPlatformNodeDelegateWindows> node_delegate) {
184 node_delegate->SetFocus();
185 }
186
187 gfx::NativeViewAccessible
188 AccessibilityBridgeWindows::GetChildOfAXFragmentRoot() {
189 ui::AXPlatformNodeDelegate* root_delegate = RootDelegate();
190 if (!root_delegate) {
191 return nullptr;
192 }
193
194 return root_delegate->GetNativeViewAccessible();
195 }
196
197 gfx::NativeViewAccessible
198 AccessibilityBridgeWindows::GetParentOfAXFragmentRoot() {
199 return nullptr;
200 }
201
202 bool AccessibilityBridgeWindows::IsAXFragmentRootAControlElement() {
203 return true;
204 }
205
206 std::weak_ptr<FlutterPlatformNodeDelegate>
207 AccessibilityBridgeWindows::GetFocusedNode() {
208 ui::AXNode::AXID focus_id = GetAXTreeData().sel_focus_object_id;
209 return GetFlutterPlatformNodeDelegateFromID(focus_id);
210 }
211
212 } // namespace flutter
accessibility_bridge_windows.h
node_delegate
std::shared_ptr< FlutterPlatformNodeDelegateWindows > node_delegate
Definition: accessibility_bridge_windows_unittests.cc:33
event_type
ax::mojom::Event event_type
Definition: accessibility_bridge_windows_unittests.cc:34
flutter::AccessibilityBridge::RootDelegate
ui::AXPlatformNodeDelegate * RootDelegate() const override
Definition: accessibility_bridge.cc:724
flutter::AccessibilityBridge::GetFlutterPlatformNodeDelegateFromID
std::weak_ptr< FlutterPlatformNodeDelegate > GetFlutterPlatformNodeDelegateFromID(AccessibilityNodeId id) const
Get the flutter platform node delegate with the given id from this accessibility bridge....
Definition: accessibility_bridge.cc:131
flutter::AccessibilityBridge::GetAXTreeData
const ui::AXTreeData & GetAXTreeData() const
Get the ax tree data from this accessibility bridge. The tree data contains information such as the i...
Definition: accessibility_bridge.cc:141
flutter::AccessibilityBridgeWindows::DispatchWinAccessibilityEvent
virtual void DispatchWinAccessibilityEvent(std::shared_ptr< FlutterPlatformNodeDelegateWindows > node_delegate, ax::mojom::Event event_type)
Definition: accessibility_bridge_windows.cc:176
flutter::AccessibilityBridgeWindows::GetFocusedNode
virtual std::weak_ptr< FlutterPlatformNodeDelegate > GetFocusedNode()
Definition: accessibility_bridge_windows.cc:207
flutter::AccessibilityBridgeWindows::CreateFlutterPlatformNodeDelegate
std::shared_ptr< FlutterPlatformNodeDelegate > CreateFlutterPlatformNodeDelegate() override
Creates a platform specific FlutterPlatformNodeDelegate. Ownership passes to the caller....
Definition: accessibility_bridge_windows.cc:171
flutter::AccessibilityBridgeWindows::DispatchAccessibilityAction
void DispatchAccessibilityAction(AccessibilityNodeId target, FlutterSemanticsAction action, fml::MallocMapping data) override
Dispatch accessibility action back to the Flutter framework. These actions are generated in the nativ...
Definition: accessibility_bridge_windows.cc:162
flutter::AccessibilityBridgeWindows::AccessibilityBridgeWindows
AccessibilityBridgeWindows(FlutterWindowsView *view)
Definition: accessibility_bridge_windows.cc:13
flutter::AccessibilityBridgeWindows::SetFocus
virtual void SetFocus(std::shared_ptr< FlutterPlatformNodeDelegateWindows > node_delegate)
Definition: accessibility_bridge_windows.cc:182
flutter::AccessibilityBridgeWindows::IsAXFragmentRootAControlElement
bool IsAXFragmentRootAControlElement() override
Definition: accessibility_bridge_windows.cc:202
flutter::AccessibilityBridgeWindows::GetChildOfAXFragmentRoot
gfx::NativeViewAccessible GetChildOfAXFragmentRoot() override
Definition: accessibility_bridge_windows.cc:188
flutter::AccessibilityBridgeWindows::GetParentOfAXFragmentRoot
gfx::NativeViewAccessible GetParentOfAXFragmentRoot() override
Definition: accessibility_bridge_windows.cc:198
flutter::AccessibilityBridgeWindows::OnAccessibilityEvent
void OnAccessibilityEvent(ui::AXEventGenerator::TargetedEvent targeted_event) override
Handle accessibility events generated due to accessibility tree changes. These events are needed to b...
Definition: accessibility_bridge_windows.cc:18
flutter::FlutterWindowsEngine::DispatchSemanticsAction
bool DispatchSemanticsAction(FlutterViewId view_id, uint64_t node_id, FlutterSemanticsAction action, fml::MallocMapping data)
Definition: flutter_windows_engine.cc:961
flutter::FlutterWindowsView
Definition: flutter_windows_view.h:34
flutter::FlutterWindowsView::GetEngine
FlutterWindowsEngine * GetEngine() const
Definition: flutter_windows_view.cc:782
flutter::FlutterWindowsView::view_id
FlutterViewId view_id() const
Definition: flutter_windows_view.cc:709
flutter_platform_node_delegate_windows.h
action
int action
Definition: keyboard_key_handler_unittests.cc:116
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::AccessibilityNodeId
ui::AXNode::AXID AccessibilityNodeId
Definition: flutter_platform_node_delegate.h:15