Flutter Engine
 
Loading...
Searching...
No Matches
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"
25
26namespace flutter {
27class 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 */
36class AccessibilityBridge final : public AccessibilityBridgeIos {
37 public:
38 /** Delegate for handling iOS operations. */
40 public:
41 virtual ~IosDelegate() = default;
42 /// Returns true when the FlutterViewController associated with the `view`
43 /// is presenting a modal view controller.
45 FlutterViewController* view_controller) = 0;
46 virtual void PostAccessibilityNotification(UIAccessibilityNotifications notification,
47 id argument) = 0;
48 };
49
52 __weak FlutterPlatformViewsController* platform_views_controller,
53 std::unique_ptr<IosDelegate> ios_delegate = nullptr);
55
58 void HandleEvent(NSDictionary<NSString*, id>* annotatedEvent);
60 void DispatchSemanticsAction(int32_t id,
62 fml::MallocMapping args) override;
63 void AccessibilityObjectDidBecomeFocused(int32_t id) override;
64 void AccessibilityObjectDidLoseFocus(int32_t id) override;
65 NSString* GetDefaultLocale() override { return view_controller_.applicationLocale; }
66
67 UIView<UITextInput>* textInputView() override;
68
69 UIView* view() const override { return view_controller_.view; }
70
71 bool isVoiceOverRunning() const override { return view_controller_.isVoiceOverRunning; }
72
74
76 return platform_views_controller_;
77 };
78
79 void clearState();
80
81 private:
82 SemanticsObject* GetOrCreateObject(int32_t id, flutter::SemanticsNodeUpdates& updates);
83 SemanticsObject* FindNextFocusableIfNecessary();
84 // Finds the first focusable SemanticsObject rooted at the parent. This includes the parent itself
85 // if it is a focusable SemanticsObject.
86 //
87 // If the parent is nil, this function use the root SemanticsObject as the parent.
88 SemanticsObject* FindFirstFocusable(SemanticsObject* parent);
89 void VisitObjectsRecursivelyAndRemove(SemanticsObject* object,
90 NSMutableArray<NSNumber*>* doomed_uids);
91
92 __weak FlutterViewController* view_controller_;
93 PlatformViewIOS* platform_view_;
94 __weak FlutterPlatformViewsController* platform_views_controller_;
95
96 // If the this id is kSemanticObjectIdInvalid, it means either nothing has
97 // been focused or the focus is currently outside of the flutter application
98 // (i.e. the status bar or keyboard)
99 static constexpr int32_t kSemanticObjectIdInvalid = -1;
100 int32_t last_focused_semantics_object_id_ = kSemanticObjectIdInvalid;
101
102 NSMutableDictionary<NSNumber*, SemanticsObject*>* objects_;
103 FlutterBasicMessageChannel* accessibility_channel_;
104 int32_t previous_route_id_ = 0;
105 std::unordered_map<int32_t, flutter::CustomAccessibilityAction> actions_;
106 std::vector<int32_t> previous_routes_;
107 std::unique_ptr<IosDelegate> ios_delegate_;
108 fml::WeakPtrFactory<AccessibilityBridge> weak_factory_; // Must be the last member.
110};
111
112} // namespace flutter
113
114#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_BRIDGE_H_
std::unique_ptr< flutter::PlatformViewIOS > platform_view
virtual void PostAccessibilityNotification(UIAccessibilityNotifications notification, id argument)=0
virtual bool IsFlutterViewControllerPresentingModalViewController(FlutterViewController *view_controller)=0
void UpdateSemantics(flutter::SemanticsNodeUpdates nodes, const flutter::CustomAccessibilityActionUpdates &actions)
UIView * view() const override
void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action) override
UIView< UITextInput > * textInputView() override
void AccessibilityObjectDidLoseFocus(int32_t id) override
NSString * GetDefaultLocale() override
AccessibilityBridge(FlutterViewController *view_controller, PlatformViewIOS *platform_view, __weak FlutterPlatformViewsController *platform_views_controller, std::unique_ptr< IosDelegate > ios_delegate=nullptr)
void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action, fml::MallocMapping args) override
bool isVoiceOverRunning() const override
void HandleEvent(NSDictionary< NSString *, id > *annotatedEvent)
fml::WeakPtr< AccessibilityBridge > GetWeakPtr()
FlutterPlatformViewsController * GetPlatformViewsController() const override
void AccessibilityObjectDidBecomeFocused(int32_t id) override
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates