forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hardware keyboard: Web, embedder, and dart:ui (flutter#23466)
- Loading branch information
Showing
46 changed files
with
3,295 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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" | ||
|
||
#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.