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
[Web, keyboard] Locale layout mapping #34625
Merged
Merged
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
8cf086a
WIP
dkwingsmt 21c50f0
WIP: Better debug log
dkwingsmt 0883f87
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 22d2ccf
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 3c05c3d
WIP
dkwingsmt becbf08
Merge branch 'web-layout-detection' of https://github.com/dkwingsmt/e…
dkwingsmt e82bc25
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 416f574
Finish logic (untested)
dkwingsmt 5ed152d
Use third_party for layouts
dkwingsmt cb3b06d
Update gen
dkwingsmt e7a6473
Fix filtering bugs
dkwingsmt b88d06f
Format
dkwingsmt 2175a4a
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 4f1083f
Merge remote-tracking branch 'dkwingsmt/web-layout-detection' into we…
dkwingsmt 0a85ed9
Fix build
dkwingsmt 4b0d8e4
Add scripts
dkwingsmt d4920f4
Try license
dkwingsmt 249542c
Copyright
dkwingsmt 3c4cac8
Rename license
dkwingsmt 84703c7
Use case insensitive
dkwingsmt 1a7b3d9
more lower case
dkwingsmt 8798bbc
Sort. Migrate to better types.
dkwingsmt f05dc33
Fix template
dkwingsmt f5704c5
Marshall and unmarshall
dkwingsmt c1a964b
Comments
dkwingsmt 35d42b1
Gen types file
dkwingsmt 162e790
gen json
dkwingsmt 0227c4c
engine compilable
dkwingsmt 66eb8a8
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 9d8e1ce
benchmark_detector
dkwingsmt ca87473
Move github to separate file
dkwingsmt f1f5b80
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt f329b68
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt b894f71
Generate full mapping
dkwingsmt 49198b0
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 0a40d4d
test cases
dkwingsmt ae05f6b
Unified dead key
dkwingsmt a6eb42d
Correct key
dkwingsmt 1a80988
remove duplicate file
dkwingsmt 7f985ee
letter in test cases
dkwingsmt 013ea9a
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 9cec217
Compile
dkwingsmt 0010a73
int keycode, and fix compile
dkwingsmt ca82c56
Correct gen directory
dkwingsmt d0a7c45
Heuristic
dkwingsmt 5638316
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 3a68127
Heuristic benchmark
dkwingsmt 4953e1f
Reorganize logical key
dkwingsmt d2636a3
Move to common
dkwingsmt 4d78abf
Docs
dkwingsmt d089597
Combine into bin
dkwingsmt 1343f01
Remove layout_types
dkwingsmt d0cd62c
Rename to locale_keymap
dkwingsmt d4fbac1
Rename class
dkwingsmt cf2df77
Rename to heuristicMapper
dkwingsmt af178f6
Format
dkwingsmt b2a63bf
Fix license
dkwingsmt 0c51f44
Fix test
dkwingsmt 7675615
Test license
dkwingsmt f594a0d
Fix tests
dkwingsmt c4d0aab
Fix import as
dkwingsmt 5dc792a
Fix analyze problem
dkwingsmt 0c5dffe
Fix license
dkwingsmt 6450c92
Update license pattern
dkwingsmt 0ab2d9c
The MIT license
dkwingsmt ec0a719
License diff
dkwingsmt f1334ce
Fix license
dkwingsmt c0ba71e
Update signature
dkwingsmt 2809d26
readme
dkwingsmt 8b36170
fix signature?
dkwingsmt 3754b08
fix signature?
dkwingsmt f7de833
Fix license count
dkwingsmt 7857246
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 3b938c3
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt 1582aa2
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt b1bce40
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt edfdd0f
Fix build
dkwingsmt 13e6fb4
Compression
dkwingsmt f970ce1
Fix _eventKeyIsKeyname
dkwingsmt de98688
remove gitignore
dkwingsmt fdd3225
Fix nullable
dkwingsmt 0e32e71
Fix doc
dkwingsmt 0d570e2
Merge remote-tracking branch 'origin/main' into web-layout-detection
dkwingsmt a507c33
Add underscore lead. Make everything lower case. Print by line.
dkwingsmt 3cfaf33
Better event code encoding
dkwingsmt c33c9f2
Signature
dkwingsmt cedb9bf
Comment. Change dead key mapping to the last.
dkwingsmt fe356c0
Better digit heuristic. Better _eventKeyIsKeyName
dkwingsmt 884e783
en-in test
dkwingsmt 3c48e3d
Remove unnecessary build change
dkwingsmt e27af08
Better order
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
Compile
- Loading branch information
commit 9cec217effb8a6db3715a314f1f92015ab414744
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,12 @@ | |
|
|
||
| import 'package:meta/meta.dart'; | ||
| import 'package:ui/ui.dart' as ui; | ||
| import 'package:web_keyboard_layouts/web_keyboard_layouts.dart' as keyboard_layouts; | ||
|
|
||
| import '../engine.dart' show registerHotRestartListener; | ||
| import 'browser_detection.dart'; | ||
| import 'dom.dart'; | ||
| import 'key_map.g.dart'; | ||
| import 'keyboard_layout_detector.dart'; | ||
| import 'platform_dispatcher.dart'; | ||
| import 'safe_browser_api.dart'; | ||
| import 'semantics.dart'; | ||
|
|
@@ -101,11 +101,17 @@ Duration _eventTimeStampToDuration(num milliseconds) { | |
|
|
||
| class KeyboardBinding { | ||
| KeyboardBinding._() { | ||
| _setup(); | ||
| _addEventListener('keydown', allowInterop((DomEvent domEvent) { | ||
| final FlutterHtmlKeyboardEvent event = FlutterHtmlKeyboardEvent(domEvent as DomKeyboardEvent); | ||
| return _converter.handleEvent(event); | ||
| })); | ||
| _addEventListener('keyup', allowInterop((DomEvent event) { | ||
| return _converter.handleEvent(FlutterHtmlKeyboardEvent(event as DomKeyboardEvent)); | ||
| })); | ||
| } | ||
|
|
||
| /// The singleton instance of this object. | ||
| static KeyboardBinding? get instance => _instance; | ||
| static KeyboardBinding get instance => _instance!; | ||
| static KeyboardBinding? _instance; | ||
|
|
||
| static void initInstance() { | ||
|
|
@@ -118,9 +124,23 @@ class KeyboardBinding { | |
| } | ||
| } | ||
|
|
||
| final KeyboardLayoutDetector layoutDetector = KeyboardLayoutDetector(); | ||
| static void debugClearInstance() { | ||
| _instance = null; | ||
| } | ||
|
|
||
| /// The platform as used in the initialization. | ||
| /// | ||
| /// By default it is derived from [operatingSystem]. | ||
| @protected | ||
| OperatingSystem get localPlatform { | ||
| return operatingSystem; | ||
| } | ||
|
|
||
| KeyboardConverter get converter => _converter; | ||
| late final KeyboardConverter _converter; | ||
| late final KeyboardConverter _converter = KeyboardConverter( | ||
| _onKeyData, | ||
| localPlatform, | ||
| ); | ||
| final Map<String, DomEventListener> _listeners = <String, DomEventListener>{}; | ||
|
|
||
| void _addEventListener(String eventName, DomEventListener handler) { | ||
|
|
@@ -156,18 +176,6 @@ class KeyboardBinding { | |
| return result!; | ||
| } | ||
|
|
||
| void _setup() { | ||
| _addEventListener('keydown', allowInterop((DomEvent event) { | ||
| layoutDetector.update(event as DomKeyboardEvent); | ||
| print('${event.code} 0x${layoutDetector.getKey(event.code ?? '')?.toRadixString(16)}'); | ||
| return _converter.handleEvent(FlutterHtmlKeyboardEvent(event)); | ||
| })); | ||
| _addEventListener('keyup', allowInterop((DomEvent event) { | ||
| return _converter.handleEvent(FlutterHtmlKeyboardEvent(event as DomKeyboardEvent)); | ||
| })); | ||
| _converter = KeyboardConverter(_onKeyData, onMacOs: operatingSystem == OperatingSystem.macOs); | ||
| } | ||
|
|
||
| void _reset() { | ||
| _clearListeners(); | ||
| _converter.dispose(); | ||
|
|
@@ -214,10 +222,30 @@ class FlutterHtmlKeyboardEvent { | |
| // [dispatchKeyData] as given in the constructor. Some key data might be | ||
| // dispatched asynchronously. | ||
| class KeyboardConverter { | ||
| KeyboardConverter(this.performDispatchKeyData, {this.onMacOs = false}); | ||
| KeyboardConverter(this.performDispatchKeyData, OperatingSystem platform) | ||
| : onMacOs = platform == OperatingSystem.macOs, | ||
| _mapping = _mappingFromPlatform(platform); | ||
|
|
||
| final DispatchKeyData performDispatchKeyData; | ||
| // Whether the current platform is macOS, which affects how certain key events | ||
|
||
| // are comprehended. | ||
dkwingsmt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final bool onMacOs; | ||
| // A huge map that maps certain key event properties to logical keys. | ||
| // | ||
| // It is a map of KeyboardEvent.code -> KeyboardEvent.key -> logical_key. | ||
| final Map<String, Map<String, int>> _mapping; | ||
|
|
||
| static Map<String, Map<String, int>> _mappingFromPlatform(OperatingSystem platform) { | ||
| switch (platform) { | ||
| case OperatingSystem.iOs: | ||
| case OperatingSystem.macOs: | ||
| return keyboard_layouts.kDarwinMapping; | ||
| case OperatingSystem.windows: | ||
| return keyboard_layouts.kWinMapping; | ||
| default: | ||
dkwingsmt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return keyboard_layouts.kLinuxMapping; | ||
| } | ||
| } | ||
|
|
||
| // The `performDispatchKeyData` wrapped with tracking logic. | ||
| // | ||
|
|
||
186 changes: 0 additions & 186 deletions
186
lib/web_ui/lib/src/engine/keyboard_layout_detector.dart
This file was deleted.
Oops, something went wrong.
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
25 changes: 25 additions & 0 deletions
25
third_party/web_keyboard_layouts/lib/web_keyboard_layouts/types.dart
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,25 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| const int _kUseKeyCode = 1; | ||
|
|
||
| class LayoutMapping { | ||
| LayoutMapping.win() : _mapping = kWinMapping; | ||
| LayoutMapping.linux() : _mapping = kLinuxMapping; | ||
| LayoutMapping.darwin() : _mapping = kDarwinMapping; | ||
|
|
||
| int? getLogicalKey(String eventCode, String eventKey, String eventKeyCode) { | ||
| final int? result = _mapping[eventCode]?[eventKey]; | ||
| if (result == _kUseKeyCode) { | ||
| return getLetterCode(eventKeyCode.toUpperCase()); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| final Map<String, Map<String, int>> _mapping; | ||
|
|
||
| static int? getLetterCode(String letter) { | ||
| assert (letter.length == 1); | ||
| return letter.codeUnitAt(0); | ||
| } | ||
| } |
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.