8 #include <Carbon/Carbon.h>
9 #import <objc/message.h>
11 #include "flutter/common/constants.h"
12 #include "flutter/shell/platform/embedder/embedder.h"
24 #pragma mark - Static types and data.
32 static constexpr int32_t kMousePointerDeviceId = 0;
33 static constexpr int32_t kPointerPanZoomDeviceId = 1;
38 static constexpr
double kTrackpadTouchInertiaCancelWindowMs = 0.050;
71 bool flutter_state_is_added =
false;
76 bool flutter_state_is_down =
false;
85 bool has_pending_exit =
false;
90 bool flutter_state_is_pan_zoom_started =
false;
95 NSEventPhase pan_gesture_phase = NSEventPhaseNone;
100 NSEventPhase scale_gesture_phase = NSEventPhaseNone;
105 NSEventPhase rotate_gesture_phase = NSEventPhaseNone;
110 NSTimeInterval last_scroll_momentum_changed_time = 0;
115 void GestureReset() {
120 flutter_state_is_pan_zoom_started =
false;
121 pan_gesture_phase = NSEventPhaseNone;
122 scale_gesture_phase = NSEventPhaseNone;
123 rotate_gesture_phase = NSEventPhaseNone;
130 flutter_state_is_added =
false;
131 flutter_state_is_down =
false;
132 has_pending_exit =
false;
139 #pragma mark - Private interface declaration.
156 - (void)setBackgroundColor:(NSColor*)color;
168 @property(nonatomic) NSTrackingArea* trackingArea;
173 @property(nonatomic) MouseState mouseState;
178 @property(nonatomic)
id keyUpMonitor;
189 @property(nonatomic) NSData* keyboardLayoutData;
194 - (BOOL)launchEngine;
200 - (void)configureTrackingArea;
205 - (void)initializeKeyboard;
212 - (void)dispatchMouseEvent:(nonnull NSEvent*)event;
217 - (void)dispatchGestureEvent:(nonnull NSEvent*)event;
222 - (void)dispatchMouseEvent:(nonnull NSEvent*)event phase:(FlutterPointerPhase)phase;
230 - (void)onKeyboardLayoutChanged;
234 #pragma mark - FlutterViewWrapper implementation.
243 CFDictionaryRef userInfo) {
245 if (controller != nil) {
246 [controller onKeyboardLayoutChanged];
255 - (instancetype)initWithFlutterView:(
FlutterView*)view
257 self = [
super initWithFrame:NSZeroRect];
261 view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
262 [
self addSubview:view];
267 - (void)setBackgroundColor:(NSColor*)color {
268 [_flutterView setBackgroundColor:color];
271 - (BOOL)performKeyEquivalent:(NSEvent*)event {
278 if (
self.window.firstResponder != _flutterView || [
_controller isDispatchingKeyEvent:event]) {
279 return [
super performKeyEquivalent:event];
281 [_flutterView keyDown:event];
285 - (NSArray*)accessibilityChildren {
286 return @[ _flutterView ];
291 - (void)mouseDown:(NSEvent*)event {
292 if (@available(macOS 13.3.1, *)) {
293 [
super mouseDown:event];
305 [
self.nextResponder mouseDown:event];
311 - (void)mouseUp:(NSEvent*)event {
312 if (@available(macOS 13.3.1, *)) {
313 [
super mouseUp:event];
325 [
self.nextResponder mouseUp:event];
331 #pragma mark - FlutterViewController implementation.
337 std::shared_ptr<flutter::AccessibilityBridgeMac>
_bridge;
344 @synthesize viewIdentifier = _viewIdentifier;
345 @dynamic accessibilityBridge;
353 project:controller->_project
354 allowHeadlessExecution:NO];
356 NSCAssert(controller.
engine == nil,
357 @"The FlutterViewController is unexpectedly attached to "
358 @"engine %@ before initialization.",
360 [engine addViewController:controller];
361 NSCAssert(controller.
engine != nil,
362 @"The FlutterViewController unexpectedly stays unattached after initialization. "
363 @"In unit tests, this is likely because either the FlutterViewController or "
364 @"the FlutterEngine is mocked. Please subclass these classes instead.",
366 controller->_mouseTrackingMode = kFlutterMouseTrackingModeInKeyWindow;
368 [controller initializeKeyboard];
369 [controller notifySemanticsEnabledChanged];
371 CFNotificationCenterRef cfCenter = CFNotificationCenterGetDistributedCenter();
374 kTISNotifySelectedKeyboardInputSourceChanged, NULL,
375 CFNotificationSuspensionBehaviorDeliverImmediately);
378 - (instancetype)initWithCoder:(NSCoder*)coder {
379 self = [
super initWithCoder:coder];
380 NSAssert(
self,
@"Super init cannot be nil");
382 CommonInit(
self, nil);
386 - (instancetype)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {
387 self = [
super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
388 NSAssert(
self,
@"Super init cannot be nil");
390 CommonInit(
self, nil);
395 self = [
super initWithNibName:nil bundle:nil];
396 NSAssert(
self,
@"Super init cannot be nil");
399 CommonInit(
self, nil);
404 nibName:(nullable NSString*)nibName
405 bundle:(nullable NSBundle*)nibBundle {
406 NSAssert(engine != nil,
@"Engine is required");
408 self = [
super initWithNibName:nibName bundle:nibBundle];
410 CommonInit(
self, engine);
416 - (BOOL)isDispatchingKeyEvent:(NSEvent*)event {
417 return [_keyboardManager isDispatchingKeyEvent:event];
422 id<MTLDevice> device = _engine.renderer.device;
423 id<MTLCommandQueue> commandQueue = _engine.renderer.commandQueue;
424 if (!device || !commandQueue) {
425 NSLog(
@"Unable to create FlutterView; no MTLDevice or MTLCommandQueue available.");
428 flutterView = [
self createFlutterViewWithMTLDevice:device commandQueue:commandQueue];
429 if (_backgroundColor != nil) {
434 self.view = wrapperView;
435 _flutterView = flutterView;
438 - (void)viewDidLoad {
439 [
self configureTrackingArea];
440 [
self.view setAllowedTouchTypes:NSTouchTypeMaskIndirect];
441 [
self.view setWantsRestingTouches:YES];
442 [_engine viewControllerViewDidLoad:self];
445 - (void)viewWillAppear {
446 [
super viewWillAppear];
447 if (!_engine.running) {
450 [
self listenForMetaModifiedKeyUpEvents];
453 - (void)viewWillDisappear {
456 [NSEvent removeMonitor:_keyUpMonitor];
461 if ([
self attached]) {
462 [_engine removeViewController:self];
464 CFNotificationCenterRef cfCenter = CFNotificationCenterGetDistributedCenter();
465 CFNotificationCenterRemoveEveryObserver(cfCenter, (__bridge
void*)
self);
468 #pragma mark - Public methods
470 - (void)setMouseTrackingMode:(FlutterMouseTrackingMode)mode {
471 if (_mouseTrackingMode == mode) {
474 _mouseTrackingMode = mode;
475 [
self configureTrackingArea];
478 - (void)setBackgroundColor:(NSColor*)color {
479 _backgroundColor = color;
480 [_flutterView setBackgroundColor:_backgroundColor];
484 NSAssert([
self attached],
@"This view controller is not attached.");
485 return _viewIdentifier;
488 - (void)onPreEngineRestart {
489 [
self initializeKeyboard];
492 - (void)notifySemanticsEnabledChanged {
493 BOOL mySemanticsEnabled = !!
_bridge;
494 BOOL newSemanticsEnabled = _engine.semanticsEnabled;
495 if (newSemanticsEnabled == mySemanticsEnabled) {
498 if (newSemanticsEnabled) {
499 _bridge = [
self createAccessibilityBridgeWithEngine:_engine];
502 _flutterView.accessibilityChildren = nil;
505 NSAssert(newSemanticsEnabled == !!
_bridge,
@"Failed to update semantics for the view.");
508 - (std::weak_ptr<flutter::AccessibilityBridgeMac>)accessibilityBridge {
515 NSAssert(_engine == nil,
@"Already attached to an engine %@.", _engine);
517 _viewIdentifier = viewIdentifier;
519 [_threadSynchronizer registerView:_viewIdentifier];
522 - (void)detachFromEngine {
523 NSAssert(_engine != nil,
@"Not attached to any engine.");
524 [_threadSynchronizer deregisterView:_viewIdentifier];
530 return _engine != nil;
533 - (void)updateSemantics:(const FlutterSemanticsUpdate2*)update {
536 if (!_engine.semanticsEnabled) {
539 for (
size_t i = 0; i < update->node_count; i++) {
540 const FlutterSemanticsNode2* node = update->nodes[i];
541 _bridge->AddFlutterSemanticsNodeUpdate(*node);
544 for (
size_t i = 0; i < update->custom_action_count; i++) {
545 const FlutterSemanticsCustomAction2* action = update->custom_actions[i];
546 _bridge->AddFlutterSemanticsCustomActionUpdate(*action);
552 if (!
self.viewLoaded) {
556 auto root =
_bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
558 if ([
self.flutterView.accessibilityChildren count] == 0) {
559 NSAccessibilityElement* native_root = root->GetNativeViewAccessible();
560 self.flutterView.accessibilityChildren = @[ native_root ];
563 self.flutterView.accessibilityChildren = nil;
567 #pragma mark - Private methods
569 - (BOOL)launchEngine {
570 if (![_engine runWithEntrypoint:nil]) {
580 - (void)listenForMetaModifiedKeyUpEvents {
581 if (_keyUpMonitor != nil) {
587 _keyUpMonitor = [NSEvent
588 addLocalMonitorForEventsMatchingMask:NSEventMaskKeyUp
589 handler:^NSEvent*(NSEvent* event) {
592 NSResponder* firstResponder = [[event window] firstResponder];
593 if (weakSelf.viewLoaded && weakSelf.flutterView &&
594 (firstResponder == weakSelf.flutterView ||
595 firstResponder == weakSelf.textInputPlugin) &&
596 ([event modifierFlags] & NSEventModifierFlagCommand) &&
597 ([event type] == NSEventTypeKeyUp)) {
598 [weakSelf keyUp:event];
604 - (void)configureTrackingArea {
605 if (!
self.viewLoaded) {
610 if (_mouseTrackingMode != kFlutterMouseTrackingModeNone &&
self.flutterView) {
611 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
612 NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag;
613 switch (_mouseTrackingMode) {
614 case kFlutterMouseTrackingModeInKeyWindow:
615 options |= NSTrackingActiveInKeyWindow;
617 case kFlutterMouseTrackingModeInActiveApp:
618 options |= NSTrackingActiveInActiveApp;
620 case kFlutterMouseTrackingModeAlways:
621 options |= NSTrackingActiveAlways;
624 NSLog(
@"Error: Unrecognized mouse tracking mode: %ld", _mouseTrackingMode);
627 _trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
631 [
self.flutterView addTrackingArea:_trackingArea];
632 }
else if (_trackingArea) {
633 [
self.flutterView removeTrackingArea:_trackingArea];
638 - (void)initializeKeyboard {
644 - (void)dispatchMouseEvent:(nonnull NSEvent*)event {
645 FlutterPointerPhase phase = _mouseState.buttons == 0
646 ? (_mouseState.flutter_state_is_down ? kUp : kHover)
647 : (_mouseState.flutter_state_is_down ? kMove : kDown);
648 [
self dispatchMouseEvent:event phase:phase];
651 - (void)dispatchGestureEvent:(nonnull NSEvent*)event {
652 if (event.phase == NSEventPhaseBegan || event.phase == NSEventPhaseMayBegin) {
653 [
self dispatchMouseEvent:event phase:kPanZoomStart];
654 }
else if (event.phase == NSEventPhaseChanged) {
655 [
self dispatchMouseEvent:event phase:kPanZoomUpdate];
656 }
else if (event.phase == NSEventPhaseEnded || event.phase == NSEventPhaseCancelled) {
657 [
self dispatchMouseEvent:event phase:kPanZoomEnd];
658 }
else if (event.phase == NSEventPhaseNone && event.momentumPhase == NSEventPhaseNone) {
659 [
self dispatchMouseEvent:event phase:kHover];
664 if (event.momentumPhase == NSEventPhaseChanged) {
665 _mouseState.last_scroll_momentum_changed_time =
event.timestamp;
668 NSAssert(event.momentumPhase != NSEventPhaseNone,
669 @"Received gesture event with unexpected phase");
673 - (void)dispatchMouseEvent:(NSEvent*)event phase:(FlutterPointerPhase)phase {
674 NSAssert(
self.viewLoaded,
@"View must be loaded before it handles the mouse event");
678 if (_mouseState.flutter_state_is_added && phase == kAdd) {
684 if (phase == kPanZoomStart || phase == kPanZoomEnd) {
685 if (event.type == NSEventTypeScrollWheel) {
686 _mouseState.pan_gesture_phase =
event.phase;
687 }
else if (event.type == NSEventTypeMagnify) {
688 _mouseState.scale_gesture_phase =
event.phase;
689 }
else if (event.type == NSEventTypeRotate) {
690 _mouseState.rotate_gesture_phase =
event.phase;
693 if (phase == kPanZoomStart) {
694 if (event.type == NSEventTypeScrollWheel) {
696 _mouseState.last_scroll_momentum_changed_time = 0;
698 if (_mouseState.flutter_state_is_pan_zoom_started) {
702 _mouseState.flutter_state_is_pan_zoom_started =
true;
704 if (phase == kPanZoomEnd) {
705 if (!_mouseState.flutter_state_is_pan_zoom_started) {
709 NSAssert(event.phase == NSEventPhaseCancelled,
710 @"Received gesture event with unexpected phase");
714 NSEventPhase all_gestures_fields = _mouseState.pan_gesture_phase |
715 _mouseState.scale_gesture_phase |
716 _mouseState.rotate_gesture_phase;
717 NSEventPhase active_mask = NSEventPhaseBegan | NSEventPhaseChanged;
718 if ((all_gestures_fields & active_mask) != 0) {
726 if (!_mouseState.flutter_state_is_added && phase != kAdd) {
728 NSEvent* addEvent = [NSEvent enterExitEventWithType:NSEventTypeMouseEntered
729 location:event.locationInWindow
731 timestamp:event.timestamp
732 windowNumber:event.windowNumber
737 [
self dispatchMouseEvent:addEvent phase:kAdd];
740 NSPoint locationInView = [
self.flutterView convertPoint:event.locationInWindow fromView:nil];
741 NSPoint locationInBackingCoordinates = [
self.flutterView convertPointToBacking:locationInView];
742 int32_t device = kMousePointerDeviceId;
743 FlutterPointerDeviceKind deviceKind = kFlutterPointerDeviceKindMouse;
744 if (phase == kPanZoomStart || phase == kPanZoomUpdate || phase == kPanZoomEnd) {
745 device = kPointerPanZoomDeviceId;
746 deviceKind = kFlutterPointerDeviceKindTrackpad;
748 FlutterPointerEvent flutterEvent = {
749 .struct_size =
sizeof(flutterEvent),
751 .timestamp =
static_cast<size_t>(event.timestamp * USEC_PER_SEC),
752 .x = locationInBackingCoordinates.x,
753 .y = -locationInBackingCoordinates.y,
755 .device_kind = deviceKind,
757 .buttons = phase == kAdd ? 0 : _mouseState.buttons,
758 .view_id = static_cast<FlutterViewIdentifier>(_viewIdentifier),
761 if (phase == kPanZoomUpdate) {
762 if (event.type == NSEventTypeScrollWheel) {
763 _mouseState.delta_x += event.scrollingDeltaX * self.flutterView.layer.contentsScale;
764 _mouseState.delta_y += event.scrollingDeltaY * self.flutterView.layer.contentsScale;
765 }
else if (event.type == NSEventTypeMagnify) {
766 _mouseState.scale += event.magnification;
767 }
else if (event.type == NSEventTypeRotate) {
768 _mouseState.rotation += event.rotation * (-M_PI / 180.0);
770 flutterEvent.pan_x = _mouseState.delta_x;
771 flutterEvent.pan_y = _mouseState.delta_y;
773 flutterEvent.scale = pow(2.0, _mouseState.scale);
774 flutterEvent.rotation = _mouseState.rotation;
775 }
else if (phase == kPanZoomEnd) {
776 _mouseState.GestureReset();
777 }
else if (phase != kPanZoomStart && event.type == NSEventTypeScrollWheel) {
778 flutterEvent.signal_kind = kFlutterPointerSignalKindScroll;
780 double pixelsPerLine = 1.0;
781 if (!event.hasPreciseScrollingDeltas) {
787 pixelsPerLine = 40.0;
789 double scaleFactor =
self.flutterView.layer.contentsScale;
798 double scaledDeltaX = -event.scrollingDeltaX * pixelsPerLine * scaleFactor;
799 double scaledDeltaY = -event.scrollingDeltaY * pixelsPerLine * scaleFactor;
800 if (event.modifierFlags & NSShiftKeyMask) {
801 flutterEvent.scroll_delta_x = scaledDeltaY;
802 flutterEvent.scroll_delta_y = scaledDeltaX;
804 flutterEvent.scroll_delta_x = scaledDeltaX;
805 flutterEvent.scroll_delta_y = scaledDeltaY;
809 [_keyboardManager syncModifiersIfNeeded:event.modifierFlags timestamp:event.timestamp];
810 [_engine sendPointerEvent:flutterEvent];
813 if (phase == kDown) {
814 _mouseState.flutter_state_is_down =
true;
815 }
else if (phase == kUp) {
816 _mouseState.flutter_state_is_down =
false;
817 if (_mouseState.has_pending_exit) {
818 [
self dispatchMouseEvent:event phase:kRemove];
819 _mouseState.has_pending_exit =
false;
821 }
else if (phase == kAdd) {
822 _mouseState.flutter_state_is_added =
true;
823 }
else if (phase == kRemove) {
828 - (void)onAccessibilityStatusChanged:(BOOL)enabled {
829 if (!enabled &&
self.viewLoaded && [_textInputPlugin isFirstResponder]) {
834 [
self.view addSubview:_textInputPlugin];
838 - (std::shared_ptr<flutter::AccessibilityBridgeMac>)createAccessibilityBridgeWithEngine:
840 return std::make_shared<flutter::AccessibilityBridgeMac>(engine,
self);
843 - (nonnull
FlutterView*)createFlutterViewWithMTLDevice:(
id<MTLDevice>)device
844 commandQueue:(
id<MTLCommandQueue>)commandQueue {
845 return [[
FlutterView alloc] initWithMTLDevice:device
846 commandQueue:commandQueue
848 threadSynchronizer:_threadSynchronizer
849 viewIdentifier:_viewIdentifier];
852 - (void)onKeyboardLayoutChanged {
853 _keyboardLayoutData = nil;
859 - (NSString*)lookupKeyForAsset:(NSString*)asset {
863 - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
867 #pragma mark - FlutterViewDelegate
872 - (void)viewDidReshape:(NSView*)view {
873 FML_DCHECK(view == _flutterView);
874 [_engine updateWindowMetricsForViewController:self];
877 - (BOOL)viewShouldAcceptFirstResponder:(NSView*)view {
878 FML_DCHECK(view == _flutterView);
882 return !_textInputPlugin.isFirstResponder;
885 #pragma mark - FlutterPluginRegistry
888 return [_engine registrarForPlugin:pluginName];
891 - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
892 return [_engine valuePublishedByPlugin:pluginKey];
895 #pragma mark - FlutterKeyboardViewDelegate
904 static NSData* CurrentKeyboardLayoutData() {
905 TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
906 CFTypeRef layout_data = TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData);
907 if (layout_data == nil) {
912 source = TISCopyCurrentKeyboardLayoutInputSource();
913 layout_data = TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData);
915 return (__bridge_transfer NSData*)CFRetain(layout_data);
918 - (void)sendKeyEvent:(const FlutterKeyEvent&)event
919 callback:(nullable FlutterKeyEventCallback)callback
920 userData:(nullable
void*)userData {
921 [_engine sendKeyEvent:event callback:callback userData:userData];
925 return _engine.binaryMessenger;
928 - (BOOL)onTextInputKeyEvent:(nonnull NSEvent*)event {
929 return [_textInputPlugin handleKeyEvent:event];
936 - (LayoutClue)lookUpLayoutForKeyCode:(uint16_t)keyCode shift:(BOOL)shift {
937 if (_keyboardLayoutData == nil) {
938 _keyboardLayoutData = CurrentKeyboardLayoutData();
940 const UCKeyboardLayout* layout =
reinterpret_cast<const UCKeyboardLayout*
>(
941 CFDataGetBytePtr((__bridge CFDataRef)_keyboardLayoutData));
943 UInt32 deadKeyState = 0;
944 UniCharCount stringLength = 0;
947 UInt32 modifierState = ((shift ? shiftKey : 0) >> 8) & 0xFF;
948 UInt32 keyboardType = LMGetKbdLast();
950 bool isDeadKey =
false;
952 UCKeyTranslate(layout, keyCode, kUCKeyActionDown, modifierState, keyboardType,
953 kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 1, &stringLength, &resultChar);
955 if (status == noErr && stringLength == 0 && deadKeyState != 0) {
958 UCKeyTranslate(layout, keyCode, kUCKeyActionDown, modifierState, keyboardType,
959 kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 1, &stringLength, &resultChar);
962 if (status == noErr && stringLength == 1 && !std::iscntrl(resultChar)) {
963 return LayoutClue{resultChar, isDeadKey};
965 return LayoutClue{0,
false};
968 - (nonnull NSDictionary*)getPressedState {
969 return [_keyboardManager getPressedState];
972 #pragma mark - NSResponder
974 - (BOOL)acceptsFirstResponder {
978 - (void)keyDown:(NSEvent*)event {
979 [_keyboardManager handleEvent:event];
982 - (void)keyUp:(NSEvent*)event {
983 [_keyboardManager handleEvent:event];
986 - (void)flagsChanged:(NSEvent*)event {
987 [_keyboardManager handleEvent:event];
990 - (void)mouseEntered:(NSEvent*)event {
991 if (_mouseState.has_pending_exit) {
992 _mouseState.has_pending_exit =
false;
994 [
self dispatchMouseEvent:event phase:kAdd];
998 - (void)mouseExited:(NSEvent*)event {
999 if (_mouseState.buttons != 0) {
1000 _mouseState.has_pending_exit =
true;
1003 [
self dispatchMouseEvent:event phase:kRemove];
1006 - (void)mouseDown:(NSEvent*)event {
1007 _mouseState.buttons |= kFlutterPointerButtonMousePrimary;
1008 [
self dispatchMouseEvent:event];
1011 - (void)mouseUp:(NSEvent*)event {
1012 _mouseState.buttons &= ~static_cast<uint64_t>(kFlutterPointerButtonMousePrimary);
1013 [
self dispatchMouseEvent:event];
1016 - (void)mouseDragged:(NSEvent*)event {
1017 [
self dispatchMouseEvent:event];
1020 - (void)rightMouseDown:(NSEvent*)event {
1021 _mouseState.buttons |= kFlutterPointerButtonMouseSecondary;
1022 [
self dispatchMouseEvent:event];
1025 - (void)rightMouseUp:(NSEvent*)event {
1026 _mouseState.buttons &= ~static_cast<uint64_t>(kFlutterPointerButtonMouseSecondary);
1027 [
self dispatchMouseEvent:event];
1030 - (void)rightMouseDragged:(NSEvent*)event {
1031 [
self dispatchMouseEvent:event];
1034 - (void)otherMouseDown:(NSEvent*)event {
1035 _mouseState.buttons |= (1 <<
event.buttonNumber);
1036 [
self dispatchMouseEvent:event];
1039 - (void)otherMouseUp:(NSEvent*)event {
1040 _mouseState.buttons &= ~static_cast<uint64_t>(1 << event.buttonNumber);
1041 [
self dispatchMouseEvent:event];
1044 - (void)otherMouseDragged:(NSEvent*)event {
1045 [
self dispatchMouseEvent:event];
1048 - (void)mouseMoved:(NSEvent*)event {
1049 [
self dispatchMouseEvent:event];
1052 - (void)scrollWheel:(NSEvent*)event {
1053 [
self dispatchGestureEvent:event];
1056 - (void)magnifyWithEvent:(NSEvent*)event {
1057 [
self dispatchGestureEvent:event];
1060 - (void)rotateWithEvent:(NSEvent*)event {
1061 [
self dispatchGestureEvent:event];
1064 - (void)swipeWithEvent:(NSEvent*)event {
1068 - (void)touchesBeganWithEvent:(NSEvent*)event {
1069 NSTouch* touch =
event.allTouches.anyObject;
1071 if ((event.timestamp - _mouseState.last_scroll_momentum_changed_time) <
1072 kTrackpadTouchInertiaCancelWindowMs) {
1075 NSPoint locationInView = [
self.flutterView convertPoint:event.locationInWindow fromView:nil];
1076 NSPoint locationInBackingCoordinates =
1077 [
self.flutterView convertPointToBacking:locationInView];
1078 FlutterPointerEvent flutterEvent = {
1079 .struct_size =
sizeof(flutterEvent),
1080 .timestamp =
static_cast<size_t>(event.timestamp * USEC_PER_SEC),
1081 .x = locationInBackingCoordinates.x,
1082 .y = -locationInBackingCoordinates.y,
1083 .device = kPointerPanZoomDeviceId,
1084 .signal_kind = kFlutterPointerSignalKindScrollInertiaCancel,
1085 .device_kind = kFlutterPointerDeviceKindTrackpad,
1089 [_engine sendPointerEvent:flutterEvent];
1091 _mouseState.last_scroll_momentum_changed_time = 0;