Flutter Engine
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 SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_BRIDGE_H_
6 #define SHELL_PLATFORM_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/fml/platform/darwin/scoped_nsobject.h"
18 #include "flutter/lib/ui/semantics/custom_accessibility_action.h"
19 #include "flutter/lib/ui/semantics/semantics_node.h"
20 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
21 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
22 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
23 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
24 #import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h"
25 #import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_ios.h"
26 #include "third_party/skia/include/core/SkRect.h"
27 
28 namespace flutter {
29 class PlatformViewIOS;
30 
31 /**
32  * An accessibility instance is bound to one `FlutterViewController` and
33  * `FlutterView` instance.
34  *
35  * It helps populate the UIView's accessibilityElements property from Flutter's
36  * semantics nodes.
37  */
39  public:
40  /** Delegate for handling iOS operations. */
41  class IosDelegate {
42  public:
43  virtual ~IosDelegate() = default;
44  /// Returns true when the FlutterViewController associated with the `view`
45  /// is presenting a modal view controller.
47  FlutterViewController* view_controller) = 0;
48  virtual void PostAccessibilityNotification(UIAccessibilityNotifications notification,
49  id argument) = 0;
50  };
51 
53  PlatformViewIOS* platform_view,
54  FlutterPlatformViewsController* platform_views_controller,
55  std::unique_ptr<IosDelegate> ios_delegate = nullptr);
57 
60  void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action) override;
61  void DispatchSemanticsAction(int32_t id,
63  std::vector<uint8_t> args) override;
64  void AccessibilityObjectDidBecomeFocused(int32_t id) override;
65  void AccessibilityObjectDidLoseFocus(int32_t id) override;
66 
67  UIView<UITextInput>* textInputView() override;
68 
69  UIView* view() const override { return view_controller_.view; }
70 
72 
74  return platform_views_controller_;
75  };
76 
77  void clearState();
78 
79  private:
80  SemanticsObject* GetOrCreateObject(int32_t id, flutter::SemanticsNodeUpdates& updates);
81  SemanticsObject* FindFirstFocusable(SemanticsObject* object);
82  void VisitObjectsRecursivelyAndRemove(SemanticsObject* object,
83  NSMutableArray<NSNumber*>* doomed_uids);
84  void HandleEvent(NSDictionary<NSString*, id>* annotatedEvent);
85 
86  FlutterViewController* view_controller_;
87  PlatformViewIOS* platform_view_;
88  FlutterPlatformViewsController* platform_views_controller_;
89  // If the this id is kSemanticObjectIdInvalid, it means either nothing has
90  // been focused or the focus is currently outside of the flutter application
91  // (i.e. the status bar or keyboard)
92  int32_t last_focused_semantics_object_id_;
96  int32_t previous_route_id_;
97  std::unordered_map<int32_t, flutter::CustomAccessibilityAction> actions_;
98  std::vector<int32_t> previous_routes_;
99  std::unique_ptr<IosDelegate> ios_delegate_;
100 
102 };
103 
104 } // namespace flutter
105 
106 #endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_BRIDGE_H_
G_BEGIN_DECLS FlValue * args
FlutterPlatformViewsController * GetPlatformViewsController() const override
void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action) override
void AccessibilityObjectDidBecomeFocused(int32_t id) override
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
fml::WeakPtr< AccessibilityBridge > GetWeakPtr()
Interface that represents an accessibility bridge for iOS.
AccessibilityBridge(FlutterViewController *view_controller, PlatformViewIOS *platform_view, FlutterPlatformViewsController *platform_views_controller, std::unique_ptr< IosDelegate > ios_delegate=nullptr)
void AccessibilityObjectDidLoseFocus(int32_t id) override
SemanticsAction action
void UpdateSemantics(flutter::SemanticsNodeUpdates nodes, flutter::CustomAccessibilityActionUpdates actions)
UIView * view() const override
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
UIView< UITextInput > * textInputView() override
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
virtual void PostAccessibilityNotification(UIAccessibilityNotifications notification, id argument)=0
virtual bool IsFlutterViewControllerPresentingModalViewController(FlutterViewController *view_controller)=0