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
Compile
  • Loading branch information
dkwingsmt committed Nov 9, 2022
commit 9cec217effb8a6db3715a314f1f92015ab414744
1 change: 0 additions & 1 deletion lib/web_ui/lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export 'engine/js_interop/js_loader.dart';
export 'engine/js_interop/js_promise.dart';
export 'engine/key_map.g.dart';
export 'engine/keyboard_binding.dart';
export 'engine/keyboard_layout_detector.dart';
export 'engine/mouse_cursor.dart';
export 'engine/navigation/history.dart';
export 'engine/navigation/js_url_strategy.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/embedder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class FlutterViewEmbedder {
}

KeyboardBinding.initInstance();
PointerBinding.initInstance(glassPaneElement, KeyboardBinding.instance!.converter);
PointerBinding.initInstance(glassPaneElement, KeyboardBinding.instance.converter);

if (domWindow.visualViewport == null && isWebKit) {
// Older Safari versions sometimes give us bogus innerWidth/innerHeight
Expand Down
64 changes: 46 additions & 18 deletions lib/web_ui/lib/src/engine/keyboard_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it the case that onMacOS is only used to differentiate things for macOS, or are these keyboard quirks also present on iOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice find. I've tested it on my iPad and I confirm that they also present on iOS. I'm changing it to onDarwin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me make it a separate PR after this PR.

// are comprehended.
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:
return keyboard_layouts.kLinuxMapping;
}
}

// The `performDispatchKeyData` wrapped with tracking logic.
//
Expand Down
186 changes: 0 additions & 186 deletions lib/web_ui/lib/src/engine/keyboard_layout_detector.dart

This file was deleted.

26 changes: 2 additions & 24 deletions third_party/web_keyboard_layouts/lib/web_keyboard_layouts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,5 @@

library web_keyboard_layouts;

part 'key_mappings.g.dart';

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);
}
}
export 'web_keyboard_layouts/key_mappings.g.dart';
export 'web_keyboard_layouts/types.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
//
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.

part of web_keyboard_layouts;

final Map<String, Map<String, int>> kWinMapping = <String, Map<String, int>>{
'Backquote': <String, int>{
'0': 0x30,
Expand Down
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);
}
}
Loading