|
| 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_ACCESSIBILITYBRIDGEMACDELEGATE_H_ |
| 6 | +#define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_ACCESSIBILITYBRIDGEMACDELEGATE_H_ |
| 7 | + |
| 8 | +#import <Cocoa/Cocoa.h> |
| 9 | + |
| 10 | +#include "flutter/shell/platform/common/accessibility_bridge.h" |
| 11 | + |
| 12 | +@class FlutterEngine; |
| 13 | + |
| 14 | +namespace flutter { |
| 15 | + |
| 16 | +//------------------------------------------------------------------------------ |
| 17 | +/// The macOS implementation of AccessibilityBridge::AccessibilityBridgeDelegate. |
| 18 | +/// This delegate is used to create AccessibilityBridge in the macOS embedding. |
| 19 | +class AccessibilityBridgeMacDelegate : public AccessibilityBridge::AccessibilityBridgeDelegate { |
| 20 | + public: |
| 21 | + //--------------------------------------------------------------------------- |
| 22 | + /// @brief Creates an AccessibilityBridgeMacDelegate. |
| 23 | + /// @param[in] flutterEngine The weak reference to the FlutterEngine. |
| 24 | + explicit AccessibilityBridgeMacDelegate(__weak FlutterEngine* flutter_engine); |
| 25 | + virtual ~AccessibilityBridgeMacDelegate() = default; |
| 26 | + |
| 27 | + // |AccessibilityBridge::AccessibilityBridgeDelegate| |
| 28 | + void OnAccessibilityEvent(ui::AXEventGenerator::TargetedEvent targeted_event) override; |
| 29 | + |
| 30 | + // |AccessibilityBridge::AccessibilityBridgeDelegate| |
| 31 | + void DispatchAccessibilityAction(AccessibilityNodeId target, |
| 32 | + FlutterSemanticsAction action, |
| 33 | + const std::vector<uint8_t>& data) override; |
| 34 | + |
| 35 | + // |AccessibilityBridge::AccessibilityBridgeDelegate| |
| 36 | + std::unique_ptr<FlutterPlatformNodeDelegate> CreateFlutterPlatformNodeDelegate() override; |
| 37 | + |
| 38 | + private: |
| 39 | + /// A wrapper structure to wraps macOS native accessibility events. |
| 40 | + struct NSAccessibilityEvent { |
| 41 | + NSAccessibilityNotificationName name; |
| 42 | + gfx::NativeViewAccessible target; |
| 43 | + NSDictionary* user_info; |
| 44 | + }; |
| 45 | + |
| 46 | + //--------------------------------------------------------------------------- |
| 47 | + /// @brief Posts the given event against the given node to the macOS |
| 48 | + /// accessibility notification system. |
| 49 | + /// @param[in] native_node The event target, must not be nil. |
| 50 | + /// @param[in] mac_notification The event name, must not be nil. |
| 51 | + void DispatchMacOSNotification(gfx::NativeViewAccessible native_node, |
| 52 | + NSAccessibilityNotificationName mac_notification); |
| 53 | + |
| 54 | + //--------------------------------------------------------------------------- |
| 55 | + /// @brief Posts the given event against the given node with the |
| 56 | + /// additional attributes to the macOS accessibility notification |
| 57 | + /// system. |
| 58 | + /// @param[in] native_node The event target, must not be nil. |
| 59 | + /// @param[in] mac_notification The event name, must not be nil. |
| 60 | + /// @param[in] user_info The additional attributes, must not be nil. |
| 61 | + void DispatchMacOSNotificationWithUserInfo(gfx::NativeViewAccessible native_node, |
| 62 | + NSAccessibilityNotificationName mac_notification, |
| 63 | + NSDictionary* user_info); |
| 64 | + |
| 65 | + //--------------------------------------------------------------------------- |
| 66 | + /// @brief Whether the given event is in current pending events. |
| 67 | + /// @param[in] event_type The event you would like to look up. |
| 68 | + bool HasPendingEvent(ui::AXEventGenerator::Event event) const; |
| 69 | + |
| 70 | + //--------------------------------------------------------------------------- |
| 71 | + /// @brief Converts the give ui::AXEventGenerator::Event into |
| 72 | + /// macOS native accessibility event[s] |
| 73 | + /// @param[in] event_type The original event type. |
| 74 | + /// @param[in] ax_node The original event target. |
| 75 | + std::vector<NSAccessibilityEvent> MacOSEventsFromAXEvent(ui::AXEventGenerator::Event event_type, |
| 76 | + const ui::AXNode& ax_node) const; |
| 77 | + |
| 78 | + __weak FlutterEngine* flutter_engine_; |
| 79 | +}; |
| 80 | + |
| 81 | +} // namespace flutter |
| 82 | + |
| 83 | +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_ACCESSIBILITYBRIDGEMACDELEGATE_H_ |
0 commit comments