@@ -31,85 +31,20 @@ namespace flutter {
3131// / FlutterPlatformNodeDelegate to wrap each AXNode in order to provide
3232// / an accessibility tree in the native format.
3333// /
34- // / This class takes in a AccessibilityBridgeDelegate instance and is in charge
35- // / of its lifecycle. The delegate are used to handle the accessibility events
36- // / and actions.
34+ // / To use this class, one must subclass this class and provide their own
35+ // / implementation of FlutterPlatformNodeDelegate.
3736// /
38- // / To use this class, you must provide your own implementation of
39- // / FlutterPlatformNodeDelegate and AccessibilityBridgeDelegate .
37+ // / AccessibilityBridge must be created as a shared_ptr, since some methods
38+ // / acquires its weak_ptr .
4039class AccessibilityBridge
4140 : public std::enable_shared_from_this<AccessibilityBridge>,
4241 public FlutterPlatformNodeDelegate::OwnerBridge,
4342 private ui::AXTreeObserver {
4443 public:
45- // -----------------------------------------------------------------------------
46- // / Delegate to handle requests from the accessibility bridge. The requests
47- // / include sending accessibility event to native accessibility system,
48- // / routing accessibility action to the Flutter framework, and creating
49- // / platform specific FlutterPlatformNodeDelegate.
50- // /
51- // / The accessibility events are generated when accessibility tree changes.
52- // / These events must be sent to the native accessibility system through
53- // / the native API for the system to pick up the changes
54- // / (e.g. NSAccessibilityPostNotification in MacOS).
55- // /
56- // / The accessibility actions are generated by the native accessibility system
57- // / when users interacted with the assistive technologies. Those actions
58- // / needed to be sent to the Flutter framework.
59- // /
60- // / Each platform needs to implement the FlutterPlatformNodeDelegate and
61- // / returns its platform specific instance of FlutterPlatformNodeDelegate
62- // / in this delegate.
63- class AccessibilityBridgeDelegate {
64- public:
65- virtual ~AccessibilityBridgeDelegate () = default ;
66- // ---------------------------------------------------------------------------
67- // / @brief Handle accessibility events generated due to accessibility
68- // / tree changes. These events are generated in accessibility
69- // / bridge and needed to be sent to native accessibility system.
70- // / See ui::AXEventGenerator::Event for possible events.
71- // /
72- // / @param[in] targeted_event The object that contains both the
73- // / generated event and the event target.
74- virtual void OnAccessibilityEvent (
75- ui::AXEventGenerator::TargetedEvent targeted_event) = 0;
76-
77- // ---------------------------------------------------------------------------
78- // / @brief Dispatch accessibility action back to the Flutter framework.
79- // / These actions are generated in the native accessibility
80- // / system when users interact with the assistive technologies.
81- // / For example, a
82- // / FlutterSemanticsAction::kFlutterSemanticsActionTap is
83- // / fired when user click or touch the screen.
84- // /
85- // / @param[in] target The semantics node id of the action
86- // / target.
87- // / @param[in] action The generated flutter semantics action.
88- // / @param[in] data Additional data associated with the
89- // / action.
90- virtual void DispatchAccessibilityAction (AccessibilityNodeId target,
91- FlutterSemanticsAction action,
92- fml::MallocMapping data) = 0;
93-
94- // ---------------------------------------------------------------------------
95- // / @brief Creates a platform specific FlutterPlatformNodeDelegate.
96- // / Ownership passes to the caller. This method will be called
97- // / by accessibility bridge whenever a new AXNode is created in
98- // / AXTree. Each platform needs to implement this method in
99- // / order to inject its subclass into the accessibility bridge.
100- virtual std::shared_ptr<FlutterPlatformNodeDelegate>
101- CreateFlutterPlatformNodeDelegate () = 0 ;
102- };
103-
10444 // -----------------------------------------------------------------------------
10545 // / @brief Creates a new instance of a accessibility bridge.
106- // /
107- // / @param[in] user_data A custom pointer to the data of your
108- // / choice. This pointer can be retrieve later
109- // / through GetUserData().
110- explicit AccessibilityBridge (
111- std::unique_ptr<AccessibilityBridgeDelegate> delegate);
112- ~AccessibilityBridge ();
46+ AccessibilityBridge ();
47+ virtual ~AccessibilityBridge ();
11348
11449 // -----------------------------------------------------------------------------
11550 // / @brief The ID of the root node in the accessibility tree. In Flutter,
@@ -168,12 +103,39 @@ class AccessibilityBridge
168103 // / events in AccessibilityBridgeDelegate::OnAccessibilityEvent in
169104 // / case one may decide to handle an event differently based on
170105 // / all pending events.
171- const std::vector<ui::AXEventGenerator::TargetedEvent> GetPendingEvents ();
106+ const std::vector<ui::AXEventGenerator::TargetedEvent> GetPendingEvents ()
107+ const ;
108+
109+ protected:
110+ // ---------------------------------------------------------------------------
111+ // / @brief Handle accessibility events generated due to accessibility
112+ // / tree changes. These events are needed to be sent to native
113+ // / accessibility system. See ui::AXEventGenerator::Event for
114+ // / possible events.
115+ // /
116+ // / @param[in] targeted_event The object that contains both the
117+ // / generated event and the event target.
118+ virtual void OnAccessibilityEvent (
119+ ui::AXEventGenerator::TargetedEvent targeted_event) = 0;
120+
121+ // ---------------------------------------------------------------------------
122+ // / @brief Creates a platform specific FlutterPlatformNodeDelegate.
123+ // / Ownership passes to the caller. This method will be called
124+ // / whenever a new AXNode is created in AXTree. Each platform
125+ // / needs to implement this method in order to inject its
126+ // / subclass into the accessibility bridge.
127+ virtual std::shared_ptr<FlutterPlatformNodeDelegate>
128+ CreateFlutterPlatformNodeDelegate () = 0 ;
172129
173130 // ------------------------------------------------------------------------------
174- // / @brief Update the AccessibilityBridgeDelegate stored in the
175- // / accessibility bridge to a new one.
176- void UpdateDelegate (std::unique_ptr<AccessibilityBridgeDelegate> delegate);
131+ // / @brief Recreate all FlutterPlatformNodeDelegates.
132+ // /
133+ // / This can be useful for subclasses when updating some
134+ // / properties that are used by node delegates, such as views.
135+ // / Each node is recreated using
136+ // / CreateFlutterPlatformNodeDelegate, then initialized using
137+ // / AXNodes from their corresponding old one.
138+ void RecreateNodeDelegates ();
177139
178140 private:
179141 // See FlutterSemanticsNode in embedder.h
@@ -220,7 +182,6 @@ class AccessibilityBridge
220182 std::unordered_map<int32_t , SemanticsCustomAction>
221183 pending_semantics_custom_action_updates_;
222184 AccessibilityNodeId last_focused_id_ = ui::AXNode::kInvalidAXID ;
223- std::unique_ptr<AccessibilityBridgeDelegate> delegate_;
224185
225186 void InitAXTree (const ui::AXTreeUpdate& initial_state);
226187
@@ -295,11 +256,6 @@ class AccessibilityBridge
295256 gfx::NativeViewAccessible GetNativeAccessibleFromId (
296257 AccessibilityNodeId id) override ;
297258
298- // |FlutterPlatformNodeDelegate::OwnerBridge|
299- void DispatchAccessibilityAction (AccessibilityNodeId target,
300- FlutterSemanticsAction action,
301- fml::MallocMapping data) override ;
302-
303259 // |FlutterPlatformNodeDelegate::OwnerBridge|
304260 gfx::RectF RelativeToGlobalBounds (const ui::AXNode* node,
305261 bool & offscreen,
0 commit comments