-
Notifications
You must be signed in to change notification settings - Fork 6k
Enable delayed event delivery for macOS #21231
Enable delayed event delivery for macOS #21231
Conversation
c609986 to
e3f2404
Compare
cd5dfe4 to
b565965
Compare
b565965 to
43b38a2
Compare
|
Yep, looks like I hit the same problem that Justin did in #20531 (comment) I'll need to keep from running the tests in The tests do succeed when run locally. |
stuartmorgan-g
left a comment
There was a problem hiding this 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.
shell/platform/darwin/macos/framework/Headers/FlutterViewController.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
Good point. I had to synthesize events on Android, so I guess the name stuck. Updated the description. |
799dd88 to
25db203
Compare
c1b1184 to
7a4c145
Compare
| - (void)propagateKeyEvent:(NSEvent*)event ofType:(NSString*)type { | ||
| if ([type isEqual:@"keydown"]) { | ||
| for (FlutterIntermediateKeyResponder* responder in self.additionalKeyResponders) { | ||
| if ([responder respondsToSelector:@selector(handleKeyDown:)]) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
shell/platform/darwin/macos/framework/Headers/FlutterViewController.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterIntermediateKeyResponder.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterIntermediateKeyResponder.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
45886b7 to
c44e86b
Compare
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits
shell/platform/darwin/macos/framework/Source/FlutterIntermediateKeyResponder.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterIntermediateKeyResponder.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterIntermediateKeyResponder.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterIntermediateKeyResponder.h
Show resolved
Hide resolved
| controller->_engine = [[FlutterEngine alloc] initWithName:@"io.flutter" | ||
| project:controller->_project | ||
| allowHeadlessExecution:NO]; | ||
| if (controller->_engine == nullptr) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm
Outdated
Show resolved
Hide resolved
|
@gspencergoog is OOO today. Should be back by next weeks PR triage. |
c44e86b to
96035f5
Compare
|
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) |
|
Alas, it does not revert cleanly. |
|
That'll learn me to sync to ToT first 😄 |
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
OCMockto mock things, but callingOCMVerifyrequired that it be run inside of anNSObjectmethod (it wantedselfto be available). To do that, I created FlutterTEST()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