diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index 1af5c9b1a5..aa1d157088 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -286,38 +286,44 @@ static void OnKeyboardLayoutChanged(CFNotificationCenterRef center, return @[ _flutterView ]; } +// TODO(cbracken): https://github.com/flutter/flutter/issues/154063 +// Remove this whole method override when we drop support for macOS 12 (Monterey). - (void)mouseDown:(NSEvent*)event { - // Work around an AppKit bug where mouseDown/mouseUp are not called on the view controller if the - // view is the content view of an NSPopover AND macOS's Reduced Transparency accessibility setting - // is enabled. - // - // This simply calls mouseDown on the next responder in the responder chain as the default - // implementation on NSResponder is documented to do. - // - // See: https://github.com/flutter/flutter/issues/115015 - // See: http://www.openradar.me/FB12050037 - // See: https://developer.apple.com/documentation/appkit/nsresponder/1524634-mousedown - // - // TODO(cbracken): https://github.com/flutter/flutter/issues/154063 - // Remove this workaround when we drop support for macOS 12 (Monterey). - [self.nextResponder mouseDown:event]; + if (@available(macOS 13.3.1, *)) { + [super mouseDown:event]; + } else { + // Work around an AppKit bug where mouseDown/mouseUp are not called on the view controller if + // the view is the content view of an NSPopover AND macOS's Reduced Transparency accessibility + // setting is enabled. + // + // This simply calls mouseDown on the next responder in the responder chain as the default + // implementation on NSResponder is documented to do. + // + // See: https://github.com/flutter/flutter/issues/115015 + // See: http://www.openradar.me/FB12050037 + // See: https://developer.apple.com/documentation/appkit/nsresponder/1524634-mousedown + [self.nextResponder mouseDown:event]; + } } +// TODO(cbracken): https://github.com/flutter/flutter/issues/154063 +// Remove this workaround when we drop support for macOS 12 (Monterey). - (void)mouseUp:(NSEvent*)event { - // Work around an AppKit bug where mouseDown/mouseUp are not called on the view controller if the - // view is the content view of an NSPopover AND macOS's Reduced Transparency accessibility setting - // is enabled. - // - // This simply calls mouseUp on the next responder in the responder chain as the default - // implementation on NSResponder is documented to do. - // - // See: https://github.com/flutter/flutter/issues/115015 - // See: http://www.openradar.me/FB12050037 - // See: https://developer.apple.com/documentation/appkit/nsresponder/1535349-mouseup - // - // TODO(cbracken): https://github.com/flutter/flutter/issues/154063 - // Remove this workaround when we drop support for macOS 12 (Monterey). - [self.nextResponder mouseUp:event]; + if (@available(macOS 13.3.1, *)) { + [super mouseUp:event]; + } else { + // Work around an AppKit bug where mouseDown/mouseUp are not called on the view controller if + // the view is the content view of an NSPopover AND macOS's Reduced Transparency accessibility + // setting is enabled. + // + // This simply calls mouseUp on the next responder in the responder chain as the default + // implementation on NSResponder is documented to do. + // + // See: https://github.com/flutter/flutter/issues/115015 + // See: http://www.openradar.me/FB12050037 + // See: https://developer.apple.com/documentation/appkit/nsresponder/1535349-mouseup + [self.nextResponder mouseUp:event]; + } } @end diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm index 3421d78019..b63cf439c9 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm @@ -1082,7 +1082,16 @@ static void SwizzledNoop(id self, SEL _cmd) {} // See: https://github.com/flutter/flutter/issues/115015 // See: http://www.openradar.me/FB12050037 // See: https://developer.apple.com/documentation/appkit/nsresponder/1524634-mousedown +// +// TODO(cbracken): https://github.com/flutter/flutter/issues/154063 +// Remove this test when we drop support for macOS 12 (Monterey). - (bool)testMouseDownUpEventsSentToNextResponder:(id)engineMock { + if (@available(macOS 13.3.1, *)) { + // This workaround is disabled for macOS 13.3.1 onwards, since the underlying AppKit bug is + // fixed. + return true; + } + // The root cause of the above bug is NSResponder mouseDown/mouseUp methods that don't correctly // walk the responder chain calling the appropriate method on the next responder under certain // conditions. Simulate this by swizzling out the default implementations and replacing them with