This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Hardware keyboard: Web, embedder, and dart:ui #23466
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
29bcc33
Merge pull request #1 from flutter/master
dkwingsmt 550c23f
Merge branch 'master' of https://github.com/flutter/engine
dkwingsmt f93d22c
Split out web
dkwingsmt 08c9507
Include embedder changes
dkwingsmt aac6837
Fix buildgn for embedder
dkwingsmt a2d0c78
Fix license
dkwingsmt 226cd56
Fix license
dkwingsmt 3828055
Fix VoidCallback
dkwingsmt 99cd26c
Fix tests
dkwingsmt ee54d7b
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 09ccc39
Fix compile
dkwingsmt c10ca64
Fix compile: implement virtual methods
dkwingsmt 55b8c42
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 7a3dd53
Better toString
dkwingsmt bf7c992
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 736d4f6
Fix doc. Add async callback
dkwingsmt 4be1c0f
Rename back to KeyDataPacket
dkwingsmt 26ccf41
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 5089d0f
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 15388e6
Unit test
dkwingsmt 9a097da
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 8baf82b
Fix compile
dkwingsmt d63c9f2
First unit test passed
dkwingsmt 091765c
Complete tests
dkwingsmt e80cef7
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt f4c7b41
Rename to type
dkwingsmt 7de3628
Rename callback
dkwingsmt 86c4e9b
Simplify KeyDataPacket's API.
dkwingsmt b367ce3
More comments
dkwingsmt 855ffde
Rename embedder kind -> type
dkwingsmt 8cbf7e1
All comments
dkwingsmt 41732a5
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 54479e3
Format
dkwingsmt a31d475
Format
dkwingsmt 9f192ee
Format3
dkwingsmt bc406f9
Remove unused
dkwingsmt c6d5221
Fix web compile
dkwingsmt 54f3231
Add return value handling to web
dkwingsmt 5428e99
Add some handling test
dkwingsmt f2fd10d
Fix signatures
dkwingsmt bf643a5
Better doc
dkwingsmt 771dfe6
format
dkwingsmt a657246
Merge remote-tracking branch 'upstream/master' into keyboard-web
dkwingsmt 749c161
Deflake
dkwingsmt 04b31e5
Explain the sync return
dkwingsmt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| // @dart = 2.12 | ||
|
|
||
| part of dart.ui; | ||
|
|
||
| /// The type of a key event. | ||
| // Must match the KeyEventType enum in ui/window/key_data.h. | ||
| enum KeyEventType { | ||
| /// The key is pressed. | ||
| down, | ||
|
|
||
| /// The key is released. | ||
| up, | ||
|
|
||
| /// The key is held, causing a repeated key input. | ||
| repeat, | ||
| } | ||
|
|
||
| /// Information about a key event. | ||
| class KeyData { | ||
| /// Creates an object that represents a key event. | ||
| const KeyData({ | ||
| required this.timeStamp, | ||
| required this.type, | ||
| required this.physical, | ||
| required this.logical, | ||
| required this.character, | ||
| required this.synthesized, | ||
| }); | ||
|
|
||
| /// Time of event dispatch, relative to an arbitrary timeline. | ||
| /// | ||
| /// For synthesized events, the [timeStamp] might not be the actual time that | ||
| /// the key press or release happens. | ||
| final Duration timeStamp; | ||
|
|
||
| /// The type of the event. | ||
| final KeyEventType type; | ||
|
|
||
| /// The key code for the physical key that has changed. | ||
| final int physical; | ||
|
|
||
| /// The key code for the logical key that has changed. | ||
| final int logical; | ||
|
|
||
| /// Character input from the event. | ||
| /// | ||
| /// Ignored for up events. | ||
| final String? character; | ||
|
|
||
| /// If [synthesized] is true, this event does not correspond to a native event. | ||
| /// | ||
| /// Although most of Flutter's keyboard events are transformed from native | ||
| /// events, some events are not based on native events, and are synthesized | ||
| /// only to conform Flutter's key event model (as documented in | ||
| /// the `HardwareKeyboard` class in the framework). | ||
| /// | ||
| /// For example, some key downs or ups might be lost when the window loses | ||
| /// focus. Some platforms provides ways to query whether a key is being held. | ||
| /// If the embedder detects an inconsistancy between its internal record and | ||
| /// the state returned by the system, the embedder will synthesize a | ||
| /// corresponding event to synchronize the state without breaking the event | ||
| /// model. | ||
| /// | ||
| /// As another example, macOS treats CapsLock in a special way by sending | ||
| /// down and up events at the down of alterate presses to indicate the | ||
| /// direction in which the lock is toggled instead of that the physical key is | ||
| /// going. A macOS embedder should normalize the behavior by converting a | ||
| /// native down event into a down event followed immediately by a synthesized | ||
| /// up event, and the native up event also into a down event followed | ||
| /// immediately by a synthesized up event. | ||
| /// | ||
| /// Synthesized events do not have a trustworthy [timeStamp], and should not be | ||
| /// processed as if the key actually went down or up at the time of the | ||
| /// callback. | ||
| /// | ||
| /// [KeyRepeatEvent] is never synthesized. | ||
| final bool synthesized; | ||
|
|
||
| @override | ||
| String toString() => 'KeyData(type: ${_typeToString(type)}, physical: 0x${physical.toRadixString(16)}, ' | ||
| 'logical: 0x${logical.toRadixString(16)}, character: $character)'; | ||
|
|
||
| /// Returns a complete textual description of the information in this object. | ||
| String toStringFull() { | ||
| return '$runtimeType(' | ||
| 'type: ${_typeToString(type)}, ' | ||
| 'timeStamp: $timeStamp, ' | ||
| 'physical: 0x${physical.toRadixString(16)}, ' | ||
| 'logical: 0x${logical.toRadixString(16)}, ' | ||
| 'character: $character, ' | ||
| 'synthesized: $synthesized' | ||
| ')'; | ||
| } | ||
|
|
||
| static String _typeToString(KeyEventType type) { | ||
| switch (type) { | ||
| case KeyEventType.up: | ||
| return 'up'; | ||
| case KeyEventType.down: | ||
| return 'down'; | ||
| case KeyEventType.repeat: | ||
| return 'repeat'; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/lib/ui/window/key_data.h" | ||
|
|
||
| #include <cstring> | ||
|
|
||
| namespace flutter { | ||
|
|
||
| static_assert(sizeof(KeyData) == kBytesPerKeyField * kKeyDataFieldCount, | ||
| "KeyData has the wrong size"); | ||
|
|
||
| void KeyData::Clear() { | ||
| memset(this, 0, sizeof(KeyData)); | ||
| } | ||
|
|
||
| } // namespace flutter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_LIB_UI_WINDOW_KEY_DATA_H_ | ||
| #define FLUTTER_LIB_UI_WINDOW_KEY_DATA_H_ | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace flutter { | ||
|
|
||
| // If this value changes, update the key data unpacking code in hooks.dart. | ||
| static constexpr int kKeyDataFieldCount = 5; | ||
| static constexpr int kBytesPerKeyField = sizeof(int64_t); | ||
|
|
||
| // The change of the key event, used by KeyData. | ||
| // | ||
| // Must match the KeyEventType enum in ui/key.dart. | ||
| enum class KeyEventType : int64_t { | ||
| kDown = 0, | ||
| kUp, | ||
| kRepeat, | ||
| }; | ||
|
|
||
| // The fixed-length sections of a KeyDataPacket. | ||
| // | ||
| // KeyData does not contain `character`, for variable-length data are stored in | ||
| // a different way in KeyDataPacket. | ||
| // | ||
| // This structure is unpacked by hooks.dart. | ||
| struct alignas(8) KeyData { | ||
| // Timestamp in microseconds from an arbitrary and consistant start point | ||
| uint64_t timestamp; | ||
| KeyEventType type; | ||
| uint64_t physical; | ||
| uint64_t logical; | ||
| // True if the event does not correspond to a native event. | ||
| // | ||
| // The value is 1 for true, and 0 for false. | ||
| uint64_t synthesized; | ||
|
|
||
| // Sets all contents of `Keydata` to 0. | ||
| void Clear(); | ||
| }; | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_LIB_UI_WINDOW_POINTER_DATA_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/lib/ui/window/key_data_packet.h" | ||
|
|
||
dkwingsmt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <cstring> | ||
|
|
||
| #include "flutter/fml/logging.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| KeyDataPacket::KeyDataPacket(const KeyData& event, const char* character) { | ||
| size_t char_size = character == nullptr ? 0 : strlen(character); | ||
| uint64_t char_size_64 = char_size; | ||
| data_.resize(sizeof(uint64_t) + sizeof(KeyData) + char_size); | ||
| memcpy(CharacterSizeStart(), &char_size_64, sizeof(char_size)); | ||
| memcpy(KeyDataStart(), &event, sizeof(KeyData)); | ||
| if (character != nullptr) { | ||
| memcpy(CharacterStart(), character, char_size); | ||
| } | ||
| } | ||
|
|
||
| KeyDataPacket::~KeyDataPacket() = default; | ||
|
|
||
| } // namespace flutter | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.