| Flutter iOS Embedder |

accessibility_bridge.h
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 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_BRIDGE_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_BRIDGE_H_
7
8 #import <UIKit/UIKit.h>
9
10 #include <memory>
11 #include <unordered_map>
12 #include <unordered_set>
13 #include <vector>
14
15 #include "flutter/fml/macros.h"
16 #include "flutter/fml/memory/weak_ptr.h"
17 #include "flutter/lib/ui/semantics/custom_accessibility_action.h"
18 #include "flutter/lib/ui/semantics/semantics_node.h"
19 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
20 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
21 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
22 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
23 #import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h"
24 #import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_ios.h"
25
26 namespace flutter {
27 class PlatformViewIOS;
28
29 /**
30 * An accessibility instance is bound to one `FlutterViewController` and
31 * `FlutterView` instance.
32 *
33 * It helps populate the UIView's accessibilityElements property from Flutter's
34 * semantics nodes.
35 */
36 class AccessibilityBridge final : public AccessibilityBridgeIos {
37 public:
38 /** Delegate for handling iOS operations. */
39 class IosDelegate {
40 public:
41 virtual ~IosDelegate() = default;
42 /// Returns true when the FlutterViewController associated with the `view`
43 /// is presenting a modal view controller.
44 virtual bool IsFlutterViewControllerPresentingModalViewController(
45 FlutterViewController* view_controller) = 0;
46 virtual void PostAccessibilityNotification(UIAccessibilityNotifications notification,
47 id argument) = 0;
48 };
49
50 AccessibilityBridge(FlutterViewController* view_controller,
51 PlatformViewIOS* platform_view,
52 __weak FlutterPlatformViewsController* platform_views_controller,
53 std::unique_ptr<IosDelegate> ios_delegate = nullptr);
54 ~AccessibilityBridge();
55
56 void UpdateSemantics(flutter::SemanticsNodeUpdates nodes,
57 const flutter::CustomAccessibilityActionUpdates& actions);
58 void HandleEvent(NSDictionary<NSString*, id>* annotatedEvent);
59 void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action) override;
60 void DispatchSemanticsAction(int32_t id,
61 flutter::SemanticsAction action,
62 fml::MallocMapping args) override;
63 void AccessibilityObjectDidBecomeFocused(int32_t id) override;
64 void AccessibilityObjectDidLoseFocus(int32_t id) override;
65
66 UIView<UITextInput>* textInputView() override;
67
68 UIView* view() const override { return view_controller_.view; }
69
70 bool isVoiceOverRunning() const override { return view_controller_.isVoiceOverRunning; }
71
72 fml::WeakPtr<AccessibilityBridge> GetWeakPtr();
73
74 FlutterPlatformViewsController* GetPlatformViewsController() const override {
75 return platform_views_controller_;
76 };
77
78 void clearState();
79
80 private:
81 SemanticsObject* GetOrCreateObject(int32_t id, flutter::SemanticsNodeUpdates& updates);
82 SemanticsObject* FindNextFocusableIfNecessary();
83 // Finds the first focusable SemanticsObject rooted at the parent. This includes the parent itself
84 // if it is a focusable SemanticsObject.
85 //
86 // If the parent is nil, this function use the root SemanticsObject as the parent.
87 SemanticsObject* FindFirstFocusable(SemanticsObject* parent);
88 void VisitObjectsRecursivelyAndRemove(SemanticsObject* object,
89 NSMutableArray<NSNumber*>* doomed_uids);
90
91 __weak FlutterViewController* view_controller_;
92 PlatformViewIOS* platform_view_;
93 __weak FlutterPlatformViewsController* platform_views_controller_;
94 // If the this id is kSemanticObjectIdInvalid, it means either nothing has
95 // been focused or the focus is currently outside of the flutter application
96 // (i.e. the status bar or keyboard)
97 int32_t last_focused_semantics_object_id_;
98
99 NSMutableDictionary<NSNumber*, SemanticsObject*>* objects_;
100 FlutterBasicMessageChannel* accessibility_channel_;
101 int32_t previous_route_id_ = 0;
102 std::unordered_map<int32_t, flutter::CustomAccessibilityAction> actions_;
103 std::vector<int32_t> previous_routes_;
104 std::unique_ptr<IosDelegate> ios_delegate_;
105 fml::WeakPtrFactory<AccessibilityBridge> weak_factory_; // Must be the last member.
106 FML_DISALLOW_COPY_AND_ASSIGN(AccessibilityBridge);
107 };
108
109 } // namespace flutter
110
111 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_BRIDGE_H_
FlutterChannels.h
platform_view
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Definition: FlutterEnginePlatformViewTest.mm:68
FlutterTextInputPlugin.h
FlutterView.h
FlutterViewController_Internal.h
SemanticsObject.h
accessibility_bridge_ios.h
flutter::AccessibilityBridge::IosDelegate
Definition: accessibility_bridge.h:39
flutter::AccessibilityBridge::IosDelegate::PostAccessibilityNotification
virtual void PostAccessibilityNotification(UIAccessibilityNotifications notification, id argument)=0
flutter::AccessibilityBridge::IosDelegate::IsFlutterViewControllerPresentingModalViewController
virtual bool IsFlutterViewControllerPresentingModalViewController(FlutterViewController *view_controller)=0
flutter::AccessibilityBridge::IosDelegate::~IosDelegate
virtual ~IosDelegate()=default
flutter::AccessibilityBridge
Definition: accessibility_bridge.h:36
flutter::AccessibilityBridge::UpdateSemantics
void UpdateSemantics(flutter::SemanticsNodeUpdates nodes, const flutter::CustomAccessibilityActionUpdates &actions)
flutter::AccessibilityBridge::DispatchSemanticsAction
void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action) override
flutter::AccessibilityBridge::AccessibilityObjectDidLoseFocus
void AccessibilityObjectDidLoseFocus(int32_t id) override
flutter::AccessibilityBridge::GetPlatformViewsController
FlutterPlatformViewsController * GetPlatformViewsController() const override
Definition: accessibility_bridge.h:74
flutter::AccessibilityBridge::AccessibilityBridge
AccessibilityBridge(FlutterViewController *view_controller, PlatformViewIOS *platform_view, __weak FlutterPlatformViewsController *platform_views_controller, std::unique_ptr< IosDelegate > ios_delegate=nullptr)
flutter::AccessibilityBridge::~AccessibilityBridge
~AccessibilityBridge()
Definition: accessibility_bridge.cc:34
flutter::AccessibilityBridge::clearState
void clearState()
flutter::AccessibilityBridge::DispatchSemanticsAction
void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action, fml::MallocMapping args) override
flutter::AccessibilityBridge::isVoiceOverRunning
bool isVoiceOverRunning() const override
Definition: accessibility_bridge.h:70
flutter::AccessibilityBridge::HandleEvent
void HandleEvent(NSDictionary< NSString *, id > *annotatedEvent)
flutter::AccessibilityBridge::GetWeakPtr
fml::WeakPtr< AccessibilityBridge > GetWeakPtr()
flutter::AccessibilityBridge::textInputView
UIView< UITextInput > * textInputView() override
flutter::AccessibilityBridge::view
UIView * view() const override
Definition: accessibility_bridge.h:68
flutter::AccessibilityBridge::AccessibilityObjectDidBecomeFocused
void AccessibilityObjectDidBecomeFocused(int32_t id) override
flutter::AccessibilityBridgeIos
Interface that represents an accessibility bridge for iOS.
Definition: accessibility_bridge_ios.h:20
flutter::PlatformViewIOS
Definition: platform_view_ios.h:39
FlutterBasicMessageChannel
Definition: FlutterChannels.h:38
FlutterPlatformViewsController
Definition: FlutterPlatformViewsController.h:31
FlutterViewController
Definition: FlutterViewController.h:57
SemanticsObject
Definition: SemanticsObject.h:32
flutter
Definition: accessibility_bridge.h:26