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

[Win32, Keyboard] TextInputPlugin is no longer a KeyboardHandlerBase #30456

Merged

Conversation

dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Dec 22, 2021

This PR refactors the Win32 keyboard system so that TextInputPlugin no longer derives from KeyboardHandlerBase. In this way, KeyboardKeyHandler is now the only KeyboardKeyBase.

image

With this change, the KeyboardHandlerBase abstract is practically useless, but is kept to minimize changes of this PR. In the future it will be simplified and absorbed into KeyboardKeyHandler.

This change serves two purposes:

Simply class structure

The previous structure, which consists of a two-layer abstract structure of KeyboardHandlerBase and KeyboardKeyHandlerDelegate, turns out to be over-engineering:

  • The functionality of TextInputPlugin hardly overlaps with KeyboardKeyHandler at all. Making them derive the same base class adds a number of empty methods for KeyboardKeyHandler.
  • Their only method in common is KeyboardHook, but TextInputPlugin.KeyboardHook never returns any value other than false. It's just a "listener".
  • This structure won't even work if we are to add a 3rd KeyboardHandlerBase (fortunately, we don't.)

Simplify async flow

With this change, FlutterWindowsView::SendKey will contain only one potentially asynchronous subroutine.

As one of the most important steps of flutter/flutter#88021, it's planned to lift the redispatching mechanism from KeyboardKeyHandler to KeyboardManagerWin32, which needs to make FlutterWindowsView::SendKey an asynchronous function by adding a "callback" argument.

Currently FlutterWindowsView::SendKey traverses all of its 2 KeyboardHandlerBase to see if they'd like to handle the key. In theory, either KeyboardHandlerBase can return true synchronously, and decide not to handle the key later, causing a redispatch. Therefore, to make FlutterWindowsView::SendKey asynchronous, it will have to manually implement something similar to Promise.all. However, in practice, KeyboardKeyHandler is the only one that can be asynchronous, and by no longer recognizing TextInputPlugin as a KeyboardHandlerBase, the "callback" can be processed in a much simpler way.


This is one of the many steps to refactor the windows keyboard system.

This PR shouldn't need extra tests since it's only a refactor.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

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

Modulo the make_unique changes.

flutter::BinaryMessenger* messenger,
flutter::KeyboardKeyHandler::EventDispatcher dispatch_event,
flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state)
override {
auto spy_key_event_handler = std::make_unique<SpyKeyboardKeyHandler>(
auto spy_key_event_handler = new SpyKeyboardKeyHandler(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not keep the make_unique here? That way if someone later adds code that throws an exception or returns before the end of the function, this won't leak.


std::unique_ptr<TextInputPlugin> CreateTextInputPlugin(
flutter::BinaryMessenger* messenger) override {
auto spy_key_event_handler = new SpyTextInputPlugin(messenger);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: use make_unique instead.

@dkwingsmt dkwingsmt merged commit 0176295 into flutter:main Jan 5, 2022
@dkwingsmt dkwingsmt deleted the win-key-text-no-longer-key-handler branch January 5, 2022 12:09
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 6, 2022
zanderso pushed a commit to flutter/flutter that referenced this pull request Jan 6, 2022
* 9481a79 Roll Skia from 45f64bd52835 to 6bebf036a502 (2 revisions) (flutter/engine#30659)

* fb4a86c Roll Fuchsia Mac SDK from RyUwCnr_M... to vpa6vKu7U... (flutter/engine#30661)

* 154bd96 Roll Skia from 6bebf036a502 to 5726d457cf15 (1 revision) (flutter/engine#30665)

* ba23c6c Roll Skia from 5726d457cf15 to 61d0fbbca795 (5 revisions) (flutter/engine#30673)

* e749ba3 Impl and test (flutter/engine#30488)

* a78103c Removed "UiThread" annotation from MethodChannel#Result. (flutter/engine#30671)

* f8a398f Fix crash in BackdropFilterLayer::Diff (flutter/engine#30460)

* a6a856f Only provide frame damage to rasterizer if partial repaint is enabled (flutter/engine#30461)

* 3a667ab Roll Fuchsia Mac SDK from vpa6vKu7U... to Al-HXHXyQ... (flutter/engine#30677)

* 830abeb [web] roll CanvasKit 0.32.0; fix frame order in animated images (flutter/engine#30680)

* c726121 Add a new display_list_benchmarks test suite (flutter/engine#30678)

* f181c4d [web] flip browser image codec flag to opt-out (flutter/engine#30681)

* 436a346 Remove the ios_tools Chromium-style dependency (flutter/engine#30538)

* 3f63998 [web] bring libraries.yaml/libraries.json up to date (flutter/engine#30467)

* ab1e8f5 Roll Skia from 61d0fbbca795 to 4981c921c6d7 (1 revision) (flutter/engine#30684)

* 8e4124b Roll Skia from 4981c921c6d7 to d7771857e9e2 (2 revisions) (flutter/engine#30685)

* acb60b4 Roll Fuchsia Mac SDK from Al-HXHXyQ... to G04Sc3__F... (flutter/engine#30687)

* 0176295 [Win32, Keyboard] TextInputPlugin is no longer a KeyboardHandlerBase (flutter/engine#30456)

* bcb4b35 Roll Skia from d7771857e9e2 to ec2e8f11b97a (1 revision) (flutter/engine#30688)

* e09f8d1 Roll Dart SDK from 1697706df708 to ab5047720a9e (5 revisions) (flutter/engine#30690)

* d60c816 Roll Dart SDK from 1697706df708 to f59531cc2973 (10 revisions) (flutter/engine#30691)

* 417042c GN targets for generating release artifacts (flutter/engine#30679)

* 7f31015 Roll Skia from ec2e8f11b97a to 84d6cf9b5b76 (7 revisions) (flutter/engine#30693)

* fed9e0b Roll Skia from 84d6cf9b5b76 to 88c5af7ecd72 (3 revisions) (flutter/engine#30695)

* 36eafae [fuchsia][shader warmup] fix for fxbug.dev/90387 (flutter/engine#30482)

* 0c036a7 Revert "Only provide frame damage to rasterizer if partial repaint is enabled (#30461)" (flutter/engine#30696)

* 8498779 [fuchsia] Fix failing SDK roll. (flutter/engine#30675)
JsouLiang pushed a commit to JsouLiang/engine that referenced this pull request Jan 14, 2022
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.

2 participants