Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
8cf086a
WIP
dkwingsmt Jun 27, 2022
21c50f0
WIP: Better debug log
dkwingsmt Jun 28, 2022
0883f87
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Jun 28, 2022
22d2ccf
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Jul 1, 2022
3c05c3d
WIP
dkwingsmt Jul 1, 2022
becbf08
Merge branch 'web-layout-detection' of https://github.com/dkwingsmt/e…
dkwingsmt Jul 1, 2022
e82bc25
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Jul 7, 2022
416f574
Finish logic (untested)
dkwingsmt Jul 7, 2022
5ed152d
Use third_party for layouts
dkwingsmt Jul 13, 2022
cb3b06d
Update gen
dkwingsmt Jul 13, 2022
e7a6473
Fix filtering bugs
dkwingsmt Jul 13, 2022
b88d06f
Format
dkwingsmt Jul 13, 2022
2175a4a
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Oct 10, 2022
4f1083f
Merge remote-tracking branch 'dkwingsmt/web-layout-detection' into we…
dkwingsmt Oct 10, 2022
0a85ed9
Fix build
dkwingsmt Oct 11, 2022
4b0d8e4
Add scripts
dkwingsmt Oct 11, 2022
d4920f4
Try license
dkwingsmt Oct 11, 2022
249542c
Copyright
dkwingsmt Oct 11, 2022
3c4cac8
Rename license
dkwingsmt Oct 11, 2022
84703c7
Use case insensitive
dkwingsmt Oct 11, 2022
1a7b3d9
more lower case
dkwingsmt Oct 11, 2022
8798bbc
Sort. Migrate to better types.
dkwingsmt Oct 12, 2022
f05dc33
Fix template
dkwingsmt Oct 12, 2022
f5704c5
Marshall and unmarshall
dkwingsmt Oct 12, 2022
c1a964b
Comments
dkwingsmt Oct 13, 2022
35d42b1
Gen types file
dkwingsmt Oct 17, 2022
162e790
gen json
dkwingsmt Oct 17, 2022
0227c4c
engine compilable
dkwingsmt Oct 18, 2022
66eb8a8
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Oct 24, 2022
9d8e1ce
benchmark_detector
dkwingsmt Oct 25, 2022
ca87473
Move github to separate file
dkwingsmt Oct 25, 2022
f1f5b80
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Oct 27, 2022
f329b68
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Oct 31, 2022
b894f71
Generate full mapping
dkwingsmt Oct 31, 2022
49198b0
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Oct 31, 2022
0a40d4d
test cases
dkwingsmt Nov 1, 2022
ae05f6b
Unified dead key
dkwingsmt Nov 1, 2022
a6eb42d
Correct key
dkwingsmt Nov 1, 2022
1a80988
remove duplicate file
dkwingsmt Nov 1, 2022
7f985ee
letter in test cases
dkwingsmt Nov 1, 2022
013ea9a
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Nov 8, 2022
9cec217
Compile
dkwingsmt Nov 9, 2022
0010a73
int keycode, and fix compile
dkwingsmt Nov 9, 2022
ca82c56
Correct gen directory
dkwingsmt Nov 10, 2022
d0a7c45
Heuristic
dkwingsmt Nov 10, 2022
5638316
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Nov 14, 2022
3a68127
Heuristic benchmark
dkwingsmt Nov 14, 2022
4953e1f
Reorganize logical key
dkwingsmt Nov 14, 2022
d2636a3
Move to common
dkwingsmt Nov 15, 2022
4d78abf
Docs
dkwingsmt Nov 15, 2022
d089597
Combine into bin
dkwingsmt Nov 15, 2022
1343f01
Remove layout_types
dkwingsmt Nov 15, 2022
d0cd62c
Rename to locale_keymap
dkwingsmt Nov 15, 2022
d4fbac1
Rename class
dkwingsmt Nov 15, 2022
cf2df77
Rename to heuristicMapper
dkwingsmt Nov 15, 2022
af178f6
Format
dkwingsmt Nov 15, 2022
b2a63bf
Fix license
dkwingsmt Nov 15, 2022
0c51f44
Fix test
dkwingsmt Nov 15, 2022
7675615
Test license
dkwingsmt Nov 15, 2022
f594a0d
Fix tests
dkwingsmt Nov 15, 2022
c4d0aab
Fix import as
dkwingsmt Nov 16, 2022
5dc792a
Fix analyze problem
dkwingsmt Nov 16, 2022
0c5dffe
Fix license
dkwingsmt Nov 16, 2022
6450c92
Update license pattern
dkwingsmt Nov 16, 2022
0ab2d9c
The MIT license
dkwingsmt Nov 16, 2022
ec0a719
License diff
dkwingsmt Nov 16, 2022
f1334ce
Fix license
dkwingsmt Nov 17, 2022
c0ba71e
Update signature
dkwingsmt Nov 17, 2022
2809d26
readme
dkwingsmt Nov 17, 2022
8b36170
fix signature?
dkwingsmt Nov 17, 2022
3754b08
fix signature?
dkwingsmt Nov 17, 2022
f7de833
Fix license count
dkwingsmt Nov 17, 2022
7857246
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Nov 17, 2022
3b938c3
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Nov 18, 2022
1582aa2
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Nov 27, 2022
b1bce40
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Nov 27, 2022
edfdd0f
Fix build
dkwingsmt Nov 28, 2022
13e6fb4
Compression
dkwingsmt Nov 28, 2022
f970ce1
Fix _eventKeyIsKeyname
dkwingsmt Nov 28, 2022
de98688
remove gitignore
dkwingsmt Nov 28, 2022
fdd3225
Fix nullable
dkwingsmt Nov 28, 2022
0e32e71
Fix doc
dkwingsmt Nov 28, 2022
0d570e2
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt Nov 28, 2022
a507c33
Add underscore lead. Make everything lower case. Print by line.
dkwingsmt Nov 28, 2022
3cfaf33
Better event code encoding
dkwingsmt Nov 28, 2022
c33c9f2
Signature
dkwingsmt Nov 28, 2022
cedb9bf
Comment. Change dead key mapping to the last.
dkwingsmt Nov 28, 2022
fe356c0
Better digit heuristic. Better _eventKeyIsKeyName
dkwingsmt Nov 29, 2022
884e783
en-in test
dkwingsmt Nov 29, 2022
3c48e3d
Remove unnecessary build change
dkwingsmt Nov 29, 2022
e27af08
Better order
dkwingsmt Nov 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Gen types file
  • Loading branch information
dkwingsmt committed Oct 17, 2022
commit 35d42b1bce0fc206a5c8fc201cfb9442d412cfc9
27 changes: 0 additions & 27 deletions third_party/web_keyboard_layouts/lib/base.dart

This file was deleted.

4 changes: 2 additions & 2 deletions third_party/web_keyboard_layouts/lib/definitions.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

part of web_keyboard_layouts;

const String kCompressedBody =
final LayoutStore kCompressedBody = unmarshallStoreCompressed(
'H4sIAAAAAAAAE+1c+XdUVba+51ShdPf7IwTbdgAEBRnUVpzneRaliRolgoAh2N2K'
'rCSEDBBkFEgCARJCGAIkjEkgsFbdKn/o1Hqv+A+e+Af4L7z9ffucW7cqlQHa99S3'
'WIuz7qnKpVK1v29/ezi7MjP5Qvk/HzOP4fK4eRyXJ8wTuDxpnsTlKfMULk+bp3F5'
Expand Down Expand Up @@ -140,4 +140,4 @@ const String kCompressedBody =
'OV5wP/4AVyeFebEb4p7mZVm/9zRBVb5HVZkpGEbg0vttut3NRkBgKMziWxwezOy3'
'mXb9Yye0hVyn4vz24QLV9hWUqvStXy+dsbRsxYgh3psdjDE6GImfL9VMoIehR/Sl'
'mhjB+Kev8jsaoyaGPGjKtzGCkl2MxE/VW2U1R5mUPNgma3OUbMqDmqifIS/ZJqu1'
'xHGs/M7Ez0PtPJGVW5rl/230nQ3Z18ralO9uyB37XX/jfwDr7kubSFEAAA=='; // 7996 bytes
'xHGs/M7Ez0PtPJGVW5rl/230nQ3Z18ralO9uyB37XX/jfwDr7kubSFEAAA=='); // 7996 bytes
200 changes: 200 additions & 0 deletions third_party/web_keyboard_layouts/lib/types.g.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
//
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
// layout_types.dart in the same pacakge.
//
// Edit the following files instead:
//
// - Script: lib/main.dart
// - Templates: data/*.tmpl
//
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.

part of web_keyboard_layouts;

/// The platform that the browser is running on.
enum LayoutPlatform {
/// Windows.
win,
/// Linux.
linux,
/// MacOS or iOS.
darwin,
}

// The length of [LayoutEntry.printable].
const int _kPrintableLength = 4;

/// Describes the characters that a physical keyboard key will be mapped to
/// under different modifier states, for a given language on a given
/// platform.
class LayoutEntry {
/// Create a layout entry.
LayoutEntry(this.printables, this.deadMasks)
: assert(printables.length == _kPrintableLength);

/// The printable characters that a key should be mapped to under different
/// modifier states.
///
/// The [printables] always have a length of 4, corresponding to "without any
/// modifiers", "with Shift", "with AltGr", and "with Shift and AltGr"
/// respectively. Some values might be empty, or be dead keys that are
/// indiecated by [deadMasks].
final List<String> printables;

/// Whether the outcome of a key is a dead key under different modifier
/// states.
///
/// The four LSB [deadMasks] correspond to the four conditions of
/// [printables]: 0x1 for "without any modifiers", 0x2 for "with Shift",
/// 0x4 for "with AltGr", and 0x8 for "with Shift and AltGr". A set bit means
/// the character is a dead key.
final int deadMasks;

/// An empty [LayoutEntry] that produces dead keys under all conditions.
static final LayoutEntry empty = LayoutEntry(
const <String>['', '', '', ''], 0xf);
}

/// Describes the characters that all goal keys will be mapped to for a given
/// language on a given platform.
class Layout {
/// Create a [Layout].
const Layout(this.language, this.platform, this.entries);

/// The language being used.
final String language;

/// The platform that the browser is running on.
final LayoutPlatform platform;

/// Maps from DOM `KeyboardKey.key`s to the characters they produce.
final Map<String, LayoutEntry> entries;
}

/// Describes all information needed to detect keyboard layout for any languages
/// on any platforms.
class LayoutStore {
/// Create a [LayoutStore].
const LayoutStore(this.goals, this.layouts);

/// The list of goals, mapping from DOM `KeyboardKey.key` to their mandatory
/// goal characters, or null if this goal is optional.
///
/// Mandatory goals are characters that must be fulfilled during keyboard
/// layout detection. If the character of a mandatory goal is not assigned in
/// earlier stages, this character (the value of this map) will be assigned
/// to its corresponding key (the key of this map).
///
/// Optional goals are keys that will be tested to see if they can be mapped
/// to mandatory goal characters.
final Map<String, String?> goals;

/// The layout information for different languages on different platforms.
final List<Layout> layouts;
}

// A [ByteBuffer] that records a offset for the convenience of reading
// sequentially.
class _ByteStream {
_ByteStream(this.buffer)
: _data = buffer.asByteData(), _offset = 0;

final ByteBuffer buffer;
final ByteData _data;

// The current offset.
//
// The next read will start from this byte (inclusive).
int get offest => _offset;
int _offset;

// Read the next byte as an 8-bit unsigned integer, and increase [offset] by
// 1.
int readUint8() {
final int result = _data.getUint8(_offset);
_offset += 1;
return result;
}

// Read the next few bytes as a UTF-8 string, and increase [offset]
// accordingly.
//
// The first byte will be a uint8, `length`, the number of bytes of the UTF-8
// sequence. Following that is the UTF-8 sequence. Therefore, the total
// increment for [offset] is `length + 1`.
//
// If the `length` is 0, then an empty string is returned.
String readString() {
final int length = _data.getUint8(_offset);
if (length == 0) {
_offset += 1;
return '';
}
final Uint8List bytes = buffer.asUint8List(_offset + 1, length);
final String result = utf8.decode(bytes);
_offset += 1 + length;
return result;
}

// Read the next few bytes as a nullable UTF-8 string, and increase [offset]
// accordingly.
//
// It is the same as [readString], except that if the `length` is 0, a null is
// returned.
String? readNullableString() {
final int length = _data.getUint8(_offset);
if (length == 0) {
_offset += 1;
return null;
}
return readString();
}
}

/// Decode a [LayoutStore] out of the compressed binary data.
LayoutStore unmarshallStoreCompressed(String compressed) {
final Uint8List bytes = Uint8List.fromList(gzip.decode(base64.decode(compressed)));
return _unmarshallStore(bytes.buffer);
}

LayoutStore _unmarshallStore(ByteBuffer buffer) {
final _ByteStream stream = _ByteStream(buffer);
final Map<String, String?> goals = _unmarshallGoals(stream);
final List<String> goalKeys = goals.keys.toList();
final int layoutNum = stream.readUint8();
final List<Layout> layouts = List<Layout>.generate(layoutNum, (_) {
return _unmarshallLayout(stream, goalKeys);
});
return LayoutStore(goals, layouts);
}

Map<String, String?> _unmarshallGoals(_ByteStream stream) {
final int goalsLength = stream.readUint8();
return Map<String, String?>.fromEntries((() sync* {
for (int goalIndex = 0; goalIndex < goalsLength; goalIndex += 1) {
yield MapEntry<String, String?>(stream.readString(), stream.readNullableString());
}
})());
}

Layout _unmarshallLayout(_ByteStream stream, List<String> goalKeys) {
final String language = stream.readString();
final LayoutPlatform platform = LayoutPlatform.values[stream.readUint8()];
final Map<String, LayoutEntry> entries = Map<String, LayoutEntry>.fromIterables(
goalKeys,
goalKeys.map((_) => _unmarshallLayoutEntry(stream)),
);
return Layout(language, platform, entries);
}

LayoutEntry _unmarshallLayoutEntry(_ByteStream stream) {
final List<String> printables = List<String>.generate(_kPrintableLength,
(_) => stream.readString());
final int deadMasks = stream.readUint8();
return LayoutEntry(printables, deadMasks);
}
;
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@

library web_keyboard_layouts;

part 'base.dart';
import 'dart:convert' show base64, utf8;
import 'dart:io' hide BytesBuilder;
import 'dart:typed_data';

part 'types.g.dart';
part 'definitions.g.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Future<void> main(List<String> rawArguments) async {
githubToken: envGithubToken,
cacheRoot: path.join(packageRoot.path, '.cache'),
dataRoot: path.join(packageRoot.path, 'data'),
libRoot: path.join(packageRoot.path, 'lib'),
force: parsedArguments['force'] as bool,
outputRoot: path.join(packageRoot.parent.parent.path,
'third_party', 'web_keyboard_layouts', 'lib'),
Expand Down
4 changes: 2 additions & 2 deletions tools/gen_web_keyboard_layouts/data/definitions.dart.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

part of web_keyboard_layouts;

const String kCompressedBody =
@@@BODY@@@; // @@@BODY_LENGTH@@@ bytes
final LayoutStore kCompressedBody = unmarshallStoreCompressed(
@@@BODY@@@); // @@@BODY_LENGTH@@@ bytes

This file was deleted.

17 changes: 17 additions & 0 deletions tools/gen_web_keyboard_layouts/data/types.dart.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
//
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
// layout_types.dart in the same pacakge.
//
// Edit the following files instead:
//
// - Script: lib/main.dart
// - Templates: data/*.tmpl
//
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.

part of web_keyboard_layouts;
@@@BODY@@@;
18 changes: 18 additions & 0 deletions tools/gen_web_keyboard_layouts/lib/layout_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import 'dart:convert' show base64, utf8;
import 'dart:io' hide BytesBuilder;
import 'dart:typed_data';

// Changing the structure of layouting classes must change the following places
// as well:
//
// * Marshalling,
// * Unmarshalling,
// * Verification.

// The following segment is not only used in the generating script, but also
// copied to the generated package.
/*@@@ SHARED SEGMENT START @@@*/

/// The platform that the browser is running on.
enum LayoutPlatform {
/// Windows.
Expand Down Expand Up @@ -189,7 +200,14 @@ LayoutEntry _unmarshallLayoutEntry(_ByteStream stream) {
return LayoutEntry(printables, deadMasks);
}

/*@@@ SHARED SEGMENT END @@@*/

/// Compress a [LayoutStore] into the compressed binary data.
///
/// See [unmarshallStoreCompressed] for decompression.
///
/// The corretness of compression and decompression is checked by
/// [verifyLayoutStoreEqual], which is run at the end of every generation.
String marshallStoreCompressed(LayoutStore store) {
final BytesBuilder bodyBuilder = BytesBuilder();
_marshallStore(bodyBuilder, store);
Expand Down
Loading