Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Sep 17, 2020

Description

This enables delayed event delivery for macOS, so that shortcuts can handle keys that are headed for a text field and intercept them. This fixes the problem where pressing TAB (or other shortcuts) in a text field also inserts a tab character into the text field.

Related Issues

Tests

I added tests to make sure that the events were sent to the framework, that they were propagated if the framework didn't handle them, and that they weren't propagated if the framework did handle them.

Writing the tests was a little weird, since I needed to use OCMock to mock things, but calling OCMVerify required that it be run inside of an NSObject method (it wanted self to be available). To do that, I created Flutter TEST() methods that verify that the NSObject method succeeded.

One note: The linter doesn't like that the OCM methods throw exceptions, so I had to mark each call to the OCM macros with // NOLINT(google-objc-avoid-throwing-exceptions).

Breaking Change

  • No, no existing tests failed, so this is not a breaking change.

@gspencergoog gspencergoog marked this pull request as draft September 17, 2020 01:24
@gspencergoog gspencergoog force-pushed the macos_key_synthesis branch 8 times, most recently from c609986 to e3f2404 Compare September 25, 2020 17:40
@gspencergoog gspencergoog force-pushed the macos_key_synthesis branch 4 times, most recently from cd5dfe4 to b565965 Compare September 25, 2020 21:40
@gspencergoog gspencergoog marked this pull request as ready for review September 25, 2020 21:42
@gspencergoog gspencergoog removed the Work in progress (WIP) Not ready (yet) for review! label Sep 25, 2020
@auto-assign auto-assign bot requested a review from gw280 September 25, 2020 21:42
@gspencergoog gspencergoog requested review from stuartmorgan-g and removed request for gw280 September 25, 2020 21:42
@gspencergoog
Copy link
Contributor Author

gspencergoog commented Sep 25, 2020

Yep, looks like I hit the same problem that Justin did in #20531 (comment)

[ERROR:flutter/runtime/dart_vm_data.cc(18)] VM snapshot invalid and could not be inferred from settings.
[ERROR:flutter/runtime/dart_vm.cc(249)] Could not setup VM data to bootstrap the VM from.
[ERROR:flutter/runtime/dart_vm_lifecycle.cc(84)] Could not create Dart VM instance.
[FATAL:flutter/shell/common/shell.cc(265)] Check failed: vm. Must be able to initialize the VM.
[ERROR:flutter/fml/backtrace.cc(110)] Caught signal SIGABRT during program execution.

I'll need to keep from running the tests in run_tests.py if I want to land this, and re-enable it when flutter/flutter#66664 is fixed.

The tests do succeed when run locally.

cc @chinmaygarde @stuartmorgan

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd to describe this in the PR as "event synthesis" since all it's doing is delaying the actual events, not synthesizing new ones.

@gspencergoog gspencergoog changed the title Enable delayed event synthesis for macOS Enable delayed event delivery for macOS Sep 28, 2020
@gspencergoog
Copy link
Contributor Author

It seems odd to describe this in the PR as "event synthesis" since all it's doing is delaying the actual events, not synthesizing new ones.

Good point. I had to synthesize events on Android, so I guess the name stuck. Updated the description.

@gspencergoog gspencergoog force-pushed the macos_key_synthesis branch 2 times, most recently from 799dd88 to 25db203 Compare September 28, 2020 23:26
- (void)propagateKeyEvent:(NSEvent*)event ofType:(NSString*)type {
if ([type isEqual:@"keydown"]) {
for (FlutterIntermediateKeyResponder* responder in self.additionalKeyResponders) {
if ([responder respondsToSelector:@selector(handleKeyDown:)]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to check respondsToSelector? Since we're already limiting the elements to be FlutterIntermediateKeyResponder they should be required to implement handleKeyDown and handleKeyUp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can keep this check but remove the implementation of FlutterIntermediateKeyResponder. According to what I read this is allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Actually, I already tried to remove the implementation, and it causes compile time errors. I'll just remove the respondsToSelector checks.

@gspencergoog gspencergoog force-pushed the macos_key_synthesis branch 4 times, most recently from 45886b7 to c44e86b Compare December 3, 2020 23:40
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits

controller->_engine = [[FlutterEngine alloc] initWithName:@"io.flutter"
project:controller->_project
allowHeadlessExecution:NO];
if (controller->_engine == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I believe the prevailing style in the macOS code is !foo rather than foo == nullptr for pointer checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see about 38 comparisons to nullptr in the .mm files in the repo. It's harder to search for references to using the bang operator, so I'm not sure how many of those there are, but I was able to find >100, so I definitely agree. I'll switch this instance (I didn't make any others), and maybe we can make the others conform in another PR.

@chinmaygarde
Copy link
Member

@gspencergoog is OOO today. Should be back by next weeks PR triage.

@gspencergoog gspencergoog merged commit 21691f1 into flutter:master Dec 11, 2020
@gspencergoog gspencergoog deleted the macos_key_synthesis branch December 11, 2020 23:21
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 14, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 14, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 14, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 15, 2020
@tvolkert
Copy link
Contributor

This has been bisected to have introduced a crash in flutter/flutter#72634 (by trying to CMD-TAB away from the app). Sending a revert (assuming this reverts cleanly)

@tvolkert
Copy link
Contributor

Alas, it does not revert cleanly.

@gspencergoog
Copy link
Contributor Author

gspencergoog commented Dec 19, 2020

Yes, @tvolkert this problem is fixed in #23154

@tvolkert
Copy link
Contributor

That'll learn me to sync to ToT first 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants