| Flutter macOS Embedder |

AccessibilityBridgeMac.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_MACOS_FRAMEWORK_SOURCE_ACCESSIBILITYBRIDGEMAC_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_ACCESSIBILITYBRIDGEMAC_H_
7
8 #import <Cocoa/Cocoa.h>
9
10 #include "flutter/fml/macros.h"
11 #include "flutter/shell/platform/common/accessibility_bridge.h"
12
13 @class FlutterEngine;
14 @class FlutterViewController;
15
16 namespace flutter {
17
18 //------------------------------------------------------------------------------
19 /// The macOS implementation of AccessibilityBridge.
20 ///
21 /// This interacts with macOS accessibility APIs, which includes routing
22 /// accessibility events fired from the framework to macOS, routing native
23 /// macOS accessibility events to the framework, and creating macOS-specific
24 /// FlutterPlatformNodeDelegate objects for each node in the semantics tree.
25 ///
26 /// AccessibilityBridgeMac must be created as a shared_ptr, since some methods
27 /// acquires its weak_ptr.
28 class AccessibilityBridgeMac : public AccessibilityBridge {
29 public:
30 //---------------------------------------------------------------------------
31 /// @brief Creates an AccessibilityBridgeMacDelegate.
32 /// @param[in] flutter_engine The weak reference to the FlutterEngine.
33 /// @param[in] view_controller The weak reference to the FlutterViewController.
34 explicit AccessibilityBridgeMac(__weak FlutterEngine* flutter_engine,
35 __weak FlutterViewController* view_controller);
36 virtual ~AccessibilityBridgeMac() = default;
37
38 // |FlutterPlatformNodeDelegate::OwnerBridge|
39 void DispatchAccessibilityAction(AccessibilityNodeId target,
40 FlutterSemanticsAction action,
41 fml::MallocMapping data) override;
42
43 protected:
44 // |AccessibilityBridge|
45 void OnAccessibilityEvent(ui::AXEventGenerator::TargetedEvent targeted_event) override;
46
47 // |AccessibilityBridge|
48 std::shared_ptr<FlutterPlatformNodeDelegate> CreateFlutterPlatformNodeDelegate() override;
49
50 private:
51 /// A wrapper structure to wraps macOS native accessibility events.
52 struct NSAccessibilityEvent {
53 NSAccessibilityNotificationName name;
54 gfx::NativeViewAccessible target;
55 NSDictionary* user_info;
56 };
57
58 //---------------------------------------------------------------------------
59 /// @brief Posts the given event against the given node to the macOS
60 /// accessibility notification system.
61 /// @param[in] native_node The event target, must not be nil.
62 /// @param[in] mac_notification The event name, must not be nil.
63 virtual void DispatchMacOSNotification(gfx::NativeViewAccessible native_node,
64 NSAccessibilityNotificationName mac_notification);
65
66 //---------------------------------------------------------------------------
67 /// @brief Posts the given event against the given node with the
68 /// additional attributes to the macOS accessibility notification
69 /// system.
70 /// @param[in] native_node The event target, must not be nil.
71 /// @param[in] mac_notification The event name, must not be nil.
72 /// @param[in] user_info The additional attributes, must not be nil.
73 void DispatchMacOSNotificationWithUserInfo(gfx::NativeViewAccessible native_node,
74 NSAccessibilityNotificationName mac_notification,
75 NSDictionary* user_info);
76
77 //---------------------------------------------------------------------------
78 /// @brief Whether the given event is in current pending events.
79 /// @param[in] event_type The event to look up.
80 bool HasPendingEvent(ui::AXEventGenerator::Event event) const;
81
82 //---------------------------------------------------------------------------
83 /// @brief Converts the give ui::AXEventGenerator::Event into
84 /// macOS native accessibility event[s]
85 /// @param[in] event_type The original event type.
86 /// @param[in] ax_node The original event target.
87 std::vector<NSAccessibilityEvent> MacOSEventsFromAXEvent(ui::AXEventGenerator::Event event_type,
88 const ui::AXNode& ax_node) const;
89
90 __weak FlutterEngine* flutter_engine_;
91 __weak FlutterViewController* view_controller_;
92
93 FML_DISALLOW_COPY_AND_ASSIGN(AccessibilityBridgeMac);
94 };
95
96 } // namespace flutter
97
98 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_ACCESSIBILITYBRIDGEMAC_H_
accessibility_bridge.h
flutter::AccessibilityBridge
Definition: accessibility_bridge.h:44
flutter::AccessibilityBridgeMac
Definition: AccessibilityBridgeMac.h:28
flutter::AccessibilityBridgeMac::AccessibilityBridgeMac
AccessibilityBridgeMac(__weak FlutterEngine *flutter_engine, __weak FlutterViewController *view_controller)
Creates an AccessibilityBridgeMacDelegate.
Definition: AccessibilityBridgeMac.mm:23
flutter::AccessibilityBridgeMac::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: AccessibilityBridgeMac.mm:27
flutter::AccessibilityBridgeMac::CreateFlutterPlatformNodeDelegate
std::shared_ptr< FlutterPlatformNodeDelegate > CreateFlutterPlatformNodeDelegate() override
Creates a platform specific FlutterPlatformNodeDelegate. Ownership passes to the caller....
Definition: AccessibilityBridgeMac.mm:345
flutter::AccessibilityBridgeMac::~AccessibilityBridgeMac
virtual ~AccessibilityBridgeMac()=default
flutter::AccessibilityBridgeMac::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: AccessibilityBridgeMac.mm:332
FlutterEngine
Definition: FlutterEngine.h:32
FlutterViewController
Definition: FlutterViewController.h:73
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::AccessibilityNodeId
ui::AXNode::AXID AccessibilityNodeId
Definition: flutter_platform_node_delegate.h:15