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

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Jan 6, 2021

Description

This PR contains the macOS changes for the Hardware Keyboard project.

Classes has been adjusted as follows:

Before After Explain
FlutterViewController FlutterViewController (Unchanged)
FlutterKeyChannelHandler Handles events by sending raw information to the framework, corresponding to RawKeyboard API.
FlutterKeyboardManager Handles how events are dispatched between handlers and whether to propagate them to the next responder.
FlutterIntermediateKeyResponder FlutterKeyFinalResponder An interface for additional key handlers.
- FlutterKeyHandler An interface for key handlers.
- FlutterKeyEmbedderHandler Handles events by sending converted events to the framework, corresponding to HardwardKeyboard API.

Related Issues

Tests

I added the following tests:

  • FlutterKeyChannelHandlerUnittests
    • BasicKeyEvent
    • EmptyResponseIsTakenAsHandled
  • FlutterKeyEmbedderHandlerUnittests
    • BasicKeyEvent
    • NonAsciiCharacters
    • IgnoreDuplicateDownEvent
    • ToggleModifiersDuringKeyTap
    • SpecialModiferFlags
    • IdentifyLeftAndRightModifiers
    • SynthesizeMissedModifierEvents
    • SynthesizeMissedModifierEventsInNormalEvents
    • ConvertCapsLockEvents
    • SynchronizeCapsLockStateOnCapsLock
    • SynchronizeCapsLockStateOnNormalKey
  • FlutterKeyboardManagerUnittests
    • NextResponderShouldThrowOnKeyUp
    • SingleAsyncHandler
    • DoubleAsyncHandlers
    • SingleFinalResponder
    • EmptyNextResponder

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Reviewer Checklist

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

@dkwingsmt dkwingsmt requested a review from gspencergoog March 12, 2021 03:21
@dkwingsmt
Copy link
Contributor Author

@gspencergoog I have finished the fixes. Here are some non-trivial changes:

  • Renamed handler and additionalHandler to primaryResponder and secondaryResponder
  • Added a FlutterKeyCallbackGuard to ensure the callback is handled exactly once
  • Added logic and test for ignoring duplicate Up events

among other mostly doc changes.

Can you take a look? Thanks!

// 0xF747 is actually used. Here we choose to filter out 0xF700-0xF7FF
// section. The reason for keeping the 0xF800-0xF8FF section is because
// 0xF8FF is used for the "Apple logo" character (Option-Shift-K on US
// keyboard.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you document here why you're including the 0xF800-0xF8FE region? e.g. "The 0xF800-0xF8FE region is included in anticipation of any new private values that are printable."

Do you have any documentation that this is how they split it up, or is that just a feeling? If it's not just a feeling, including a link to that information would be good.

I'm still a little leery of making the assumption that the region will include printable characters, but the consequences aren't huge, so I guess it's OK.

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 understand. It is indeed only a feeling, and a result out of experimentation. The only documentation I can find is the one I included that reserves 0xF700-0xF8FF. Since we're trusting the official documentation, the doc only declared a limited number of values (https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?language=objc), all of which are within 0xF700-0xF747. I'll add a little more to the doc. We can always come back and adjust this range anyway.

Copy link
Contributor Author

@dkwingsmt dkwingsmt Mar 16, 2021

Choose a reason for hiding this comment

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

How does this look?

    // Some function keys are assigned characters with codepoints from the
    // private use area. These characters are filtered out since they're
    // unprintable.
    //
    // The official documentation reserves 0xF700-0xF8FF as private use area
    // (https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?language=objc).
    // But macOS seems to only use a reduced range of it. The official doc
    // defines a few constants, all of which are within 0xF700-0xF747.
    // (https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?language=objc).
    // This mostly aligns with the experimentation result, except for 0xF8FF,
    // which is used for the "Apple logo" character (Option-Shift-K on a US
    // keyboard.)
    //
    // We hereby assume that non-printable function keys are defined from
    // 0xF700 upwards, and printable private keys are defined from 0xF8FF
    // downwards. We want to keep the printable private keys, therefore
    // we only filter out 0xF700-0xF7FF.

continue;
}
BOOL shouldDown = (currentFlagsOfInterest & currentFlag) != 0;
[self sendModifierEventOfType:shouldDown
Copy link
Contributor

@gspencergoog gspencergoog Mar 12, 2021

Choose a reason for hiding this comment

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

Couldn't it just be a bitmask of the current modifier state? You could convert the bitmask to a platform-independent version here.

Actually, I guess it doesn't really matter much. It's not going to be THAT many events (like maybe four max per event).

@dkwingsmt
Copy link
Contributor Author

dkwingsmt commented Mar 16, 2021

@gspencergoog The reason why lastModifierFlags is not simply event.modifierFlags does involve a bit of taste, and is explained as follows:

  • At the end of synchronizeModifiers:, instead of simply assigning _lastModifierFlags = event.modifierFlags, only the affected bits are updated, in order to avoid covering potential synchronization issues.
  • In this way, the uninteresting bits of _lastModifierFlags will never be updated.
  • Therefore, the assertion at the end of handleFlagEvent will never be NSAssert(_lastModifierFlags == event.modifierFlags), but always NSAssert(_lastModifierFlags & modifierFlagOfInterestMask == event.modifierFlags & modifierFlagOfInterestMask).
  • Since changing the definition for _lastModifierFlags does not make the assertion simpler, I'd rather make lastModifierFlags easier to write logic for, by saying that it doesn't contain any uninterested bits. It actually makes some docs and logic simpler.

I'm renaming it to lastModifierFlagsOfInterest to avoid confusion.

@dkwingsmt dkwingsmt requested a review from gspencergoog March 16, 2021 00:40
Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@dkwingsmt dkwingsmt merged commit 0f52360 into flutter:master Mar 16, 2021
@dkwingsmt dkwingsmt deleted the keyboard-macos branch March 16, 2021 05:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 16, 2021
zanderso pushed a commit to flutter/flutter that referenced this pull request Mar 16, 2021
* b2d02f7 Roll Fuchsia Linux SDK from GsRYVri0-... to aRqEDMjwC... (flutter/engine#24990)

* 3a1a3e6 Roll Skia from 7854da39b3c1 to 4fb13e026b6b (20 revisions) (flutter/engine#24993)

* e3a84f9 Fixed issue where the gpu disable syncswitch was being overridden after init. (flutter/engine#24958)

* aa83691 fix selectable text selections are not announced in voice over (flutter/engine#24933)

* 04b0451 fixes reference retaining issue in flutter text input plugin (flutter/engine#24768)

* 1ea7dc6 Set automatic simulator rotation in scenario test (flutter/engine#24985)

* 38977a5 Implement AXPlatformNodeBase::GetInstanceCountForTesting (flutter/engine#24999)

* a25b0de Roll Fuchsia Mac SDK from xOxFrRRO6... to pmsuWkRQA... (flutter/engine#24997)

* 3270c87 Roll Skia from 4fb13e026b6b to 1aa25c3217b6 (25 revisions) (flutter/engine#25001)

* 96d5104 [deferred components] Handle base module loading units (flutter/engine#24983)

* 6a3d8c7 Roll Skia from 1aa25c3217b6 to ead52dc068d5 (1 revision) (flutter/engine#25005)

* 0f52360 Hardware Keyboard: macOS (flutter/engine#23469)
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
The macOS changes for the Hardware Keyboard project.
chriscraws pushed a commit to chriscraws/engine that referenced this pull request Mar 23, 2021
The macOS changes for the Hardware Keyboard project.
- (instancetype)initWithViewController:(FlutterViewController*)viewController {
self = [super init];
if (self != nil) {
_flutterViewController = viewController;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we remove the _flutterViewController? if we do want to remove it, we should remove all the reference to it and the private property as well. cc @dkwingsmt

Copy link
Contributor Author

@dkwingsmt dkwingsmt Apr 13, 2021

Choose a reason for hiding this comment

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

The reason I removed it is because it's not used after initializing _channel.

It's indeed an oversight for me not to remove the private property. I can submit a new PR if you agree with the removal.

Copy link
Contributor

Choose a reason for hiding this comment

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

A later commit reused flutterViewController #24867, I think we should add it back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Sorry for the confusion I caused.
Although I see #25524 is pending to fix the caret, can you just ask him to include this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

will do :)

Copy link
Member

Choose a reason for hiding this comment

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

duanqz pushed a commit to duanqz/engine that referenced this pull request Apr 16, 2021
The macOS changes for the Hardware Keyboard project.
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