mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-27 10:07:40 +00:00
Merge pull request #2870 from keymanapp/refactor/web/engine/keyMapManager
refactor(web/engine): headless-friendly keymapping
This commit is contained in:
commit
2d34ffa809
6 changed files with 52 additions and 48 deletions
|
|
@ -107,15 +107,6 @@ if(!window['keyman']['initialized']) {
|
|||
|
||||
keymanweb.delayedInit();
|
||||
|
||||
// I732 START - Support for European underlying keyboards #1
|
||||
if(typeof(window['KeymanWeb_BaseLayout']) !== 'undefined')
|
||||
com.keyman.osk.Layouts._BaseLayout = window['KeymanWeb_BaseLayout'];
|
||||
else
|
||||
com.keyman.osk.Layouts._BaseLayout = 'us';
|
||||
|
||||
|
||||
keymanweb._BrowserIsSafari = (navigator.userAgent.indexOf('AppleWebKit') >= 0); // I732 END - Support for European underlying keyboards #1
|
||||
|
||||
//TODO: find all references to next three routines and disambiguate!!
|
||||
|
||||
// Complete page initialization only after the page is fully loaded, including any embedded fonts
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
/// <reference path="text/kbdInterface.ts" />
|
||||
// Defines keyboard data & management classes.
|
||||
/// <reference path="keyboards/kmwkeyboards.ts" />
|
||||
// Defines built-in keymapping.
|
||||
/// <reference path="kmwkeymaps.ts" />
|
||||
// Defines KMW's hotkey management object.
|
||||
/// <reference path="kmwhotkeys.ts" />
|
||||
// Defines the ui management code that tracks UI activation and such.
|
||||
|
|
@ -55,7 +53,8 @@ namespace com.keyman {
|
|||
|
||||
initialized: number; // Signals the initialization state of the KeymanWeb system.
|
||||
isHeadless = false; // Indicates that KMW lacks any access to the DOM. Nothing yet implemented for '= true'.
|
||||
'build' = 300; // TS needs this to be defined within the class.
|
||||
'build' = 300; // TS needs this to be defined within the class.
|
||||
_BrowserIsSafari: boolean; // A legacy browser-check variable.
|
||||
|
||||
// Used as placeholders during initialization.
|
||||
// The corresponding class properties should be dropped after a refactor;
|
||||
|
|
@ -72,7 +71,6 @@ namespace com.keyman {
|
|||
domManager: DOMManager;
|
||||
hotkeyManager: HotkeyManager;
|
||||
uiManager: UIManager;
|
||||
keyMapManager: KeyMapManager;
|
||||
textProcessor: text.Processor;
|
||||
modelManager: text.prediction.ModelManager;
|
||||
|
||||
|
|
@ -118,8 +116,17 @@ namespace com.keyman {
|
|||
this.domManager = new DOMManager(this);
|
||||
this.hotkeyManager = new HotkeyManager(this);
|
||||
this.uiManager = new UIManager(this);
|
||||
this.keyMapManager = new KeyMapManager();
|
||||
this.textProcessor = new text.Processor();
|
||||
|
||||
// I732 START - Support for European underlying keyboards #1
|
||||
var baseLayout: string;
|
||||
if(typeof(window['KeymanWeb_BaseLayout']) !== 'undefined') {
|
||||
baseLayout = window['KeymanWeb_BaseLayout'];
|
||||
} else {
|
||||
baseLayout = 'us';
|
||||
}
|
||||
this._BrowserIsSafari = (navigator.userAgent.indexOf('AppleWebKit') >= 0); // I732 END - Support for European underlying keyboards #1
|
||||
|
||||
this.textProcessor = new text.Processor(baseLayout);
|
||||
// Used by the embedded apps.
|
||||
this['interface'] = this.textProcessor.keyboardInterface;
|
||||
|
||||
|
|
|
|||
|
|
@ -101,12 +101,6 @@ namespace com.keyman.osk {
|
|||
'leftctrl-shift': '*LCtrlShift*',
|
||||
'rightctrl-shift': '*RCtrlShift*'
|
||||
};
|
||||
|
||||
static _BaseLayout: string = 'us'; // default BaseLayout
|
||||
static _BaseLayoutEuro: {[code: string]: string} = {
|
||||
'se': '\u00a71234567890+´~~~QWERTYUIOP\u00c5\u00a8\'~~~ASDFGHJKL\u00d6\u00c4~~~~~<ZXCVBNM,.-~~~~~ ', // Swedish
|
||||
'uk': '`1234567890-=~~~QWERTYUIOP[]#~~~ASDFGHJKL;\'~~~~~\\ZXCVBNM,./~~~~~ ' // UK
|
||||
}; // I1299 (not currently exposed, but may need to be e.g. for external users)
|
||||
|
||||
/**
|
||||
* Build a default layout for keyboards with no explicit layout
|
||||
|
|
|
|||
|
|
@ -528,12 +528,11 @@ namespace com.keyman.text {
|
|||
* @return {boolean} true if keypress event
|
||||
* Description Test if event as a keypress event
|
||||
*/
|
||||
isKeypress(e: KeyEvent):boolean {
|
||||
let keyman = com.keyman.singleton;
|
||||
isKeypress(e: KeyEvent): boolean {
|
||||
if(this.activeKeyboard.isMnemonic) { // I1380 - support KIK for positional layouts
|
||||
return !e.LisVirtualKey; // will now return true for U_xxxx keys, but not for T_xxxx keys
|
||||
} else {
|
||||
return keyman.keyMapManager._USKeyCodeToCharCode(e) ? true : false; // I1380 - support KIK for positional layouts
|
||||
return KeyMapping._USKeyCodeToCharCode(e) ? true : false; // I1380 - support KIK for positional layouts
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ namespace com.keyman {
|
|||
class LanguageKeyMaps {
|
||||
[languageCode: string]: KeyMap;
|
||||
|
||||
// // Here are some old legacy definitions that were no longer referenced but are likely related:
|
||||
// static _BaseLayoutEuro: {[code: string]: string} = {
|
||||
// 'se': '\u00a71234567890+´~~~QWERTYUIOP\u00c5\u00a8\'~~~ASDFGHJKL\u00d6\u00c4~~~~~<ZXCVBNM,.-~~~~~ ', // Swedish
|
||||
// 'uk': '`1234567890-=~~~QWERTYUIOP[]#~~~ASDFGHJKL;\'~~~~~\\ZXCVBNM,./~~~~~ ' // UK
|
||||
|
||||
constructor() {
|
||||
/* I732 START - 13/03/2007 MCD: Swedish: Start mapping of keystroke to US keyboard #2 */
|
||||
// Swedish key map
|
||||
|
|
@ -45,17 +50,17 @@ namespace com.keyman {
|
|||
}
|
||||
}
|
||||
|
||||
export class KeyMapManager {
|
||||
browserMap: BrowserKeyMaps = new BrowserKeyMaps();
|
||||
languageMap: LanguageKeyMaps = new LanguageKeyMaps();
|
||||
export class KeyMapping {
|
||||
static readonly browserMap: BrowserKeyMaps = new BrowserKeyMaps();
|
||||
static readonly languageMap: LanguageKeyMaps = new LanguageKeyMaps();
|
||||
|
||||
_usCharCodes: KeyMap[];
|
||||
private static _usCharCodes: KeyMap[];
|
||||
|
||||
constructor() {
|
||||
this._usCodeInit();
|
||||
private constructor() {
|
||||
// Do not construct this class.
|
||||
}
|
||||
|
||||
_usCodeInit() {
|
||||
private static _usCodeInit() {
|
||||
var s0=new KeyMap(),s1=new KeyMap();
|
||||
|
||||
s0['k192'] = 96;
|
||||
|
|
@ -154,7 +159,7 @@ namespace com.keyman {
|
|||
s1['k190'] = 62;
|
||||
s1['k191'] = 63;
|
||||
|
||||
this._usCharCodes = [s0,s1];
|
||||
KeyMapping._usCharCodes = [s0,s1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,8 +169,16 @@ namespace com.keyman {
|
|||
* @return {number} Character code
|
||||
* Description Translate keyboard codes to standard US layout codes
|
||||
*/
|
||||
_USKeyCodeToCharCode(Levent: com.keyman.text.KeyEvent) {
|
||||
return this._usCharCodes[Levent.Lmodifiers & 0x10 ? 1 : 0]['k'+Levent.Lcode];
|
||||
static _USKeyCodeToCharCode(Levent: com.keyman.text.KeyEvent) {
|
||||
return KeyMapping.usCharCodes[Levent.Lmodifiers & 0x10 ? 1 : 0]['k'+Levent.Lcode];
|
||||
};
|
||||
|
||||
public static get usCharCodes() {
|
||||
if(!KeyMapping._usCharCodes) {
|
||||
KeyMapping._usCodeInit();
|
||||
}
|
||||
|
||||
return KeyMapping._usCharCodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@
|
|||
/// <reference path="defaultOutput.ts" />
|
||||
// Defines the keyboard wrapper object.
|
||||
/// <reference path="../keyboards/keyboard.ts" />
|
||||
// Defines built-in keymapping.
|
||||
/// <reference path="keyMapping.ts" />
|
||||
|
||||
namespace com.keyman.text {
|
||||
export class LegacyKeyEvent {
|
||||
|
|
@ -35,9 +37,12 @@ namespace com.keyman.text {
|
|||
swallowKeypress: boolean = false;
|
||||
|
||||
keyboardInterface: KeyboardInterface;
|
||||
|
||||
baseLayout: string;
|
||||
private keyboard: keyboards.Keyboard;
|
||||
|
||||
constructor() {
|
||||
constructor(baseLayout?: string) {
|
||||
this.baseLayout = baseLayout || 'us'; // default BaseLayout
|
||||
this.keyboardInterface = new KeyboardInterface();
|
||||
this.installInterface();
|
||||
}
|
||||
|
|
@ -225,7 +230,7 @@ namespace com.keyman.text {
|
|||
|
||||
// Support version 1.0 KeymanWeb keyboards that do not define positional vs mnemonic
|
||||
if(!activeKeyboard.definesPositionalOrMnemonic) {
|
||||
Lkc.Lcode=keyman.keyMapManager._USKeyCodeToCharCode(Lkc);
|
||||
Lkc.Lcode = KeyMapping._USKeyCodeToCharCode(Lkc);
|
||||
Lkc.LisVirtualKey=false;
|
||||
}
|
||||
|
||||
|
|
@ -263,13 +268,12 @@ namespace com.keyman.text {
|
|||
|
||||
processKeystroke(keyEvent: KeyEvent, outputTarget: OutputTarget, fromOSK: boolean): RuleBehavior {
|
||||
let keyman = com.keyman.singleton;
|
||||
let keyMapManager = keyman.keyMapManager;
|
||||
|
||||
if(!keyman.isEmbedded && !fromOSK && keyman.util.device.browser == 'firefox') {
|
||||
// I1466 - Convert the - keycode on mnemonic as well as positional layouts
|
||||
// FireFox, Mozilla Suite
|
||||
if(keyMapManager.browserMap.FF['k'+keyEvent.Lcode]) {
|
||||
keyEvent.Lcode=keyMapManager.browserMap.FF['k'+keyEvent.Lcode];
|
||||
if(KeyMapping.browserMap.FF['k'+keyEvent.Lcode]) {
|
||||
keyEvent.Lcode=KeyMapping.browserMap.FF['k'+keyEvent.Lcode];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -318,6 +322,7 @@ namespace com.keyman.text {
|
|||
*/
|
||||
processKeyEvent(keyEvent: KeyEvent, e?: osk.KeyElement | boolean): boolean {
|
||||
let keyman = com.keyman.singleton;
|
||||
let formFactor = keyman.util.device.formFactor;
|
||||
|
||||
// Determine the current target for text output and create a "mock" backup
|
||||
// of its current, pre-input state.
|
||||
|
|
@ -330,9 +335,6 @@ namespace com.keyman.text {
|
|||
e = null as osk.KeyElement; // Cast is necessary for TS type-checking later in the method.
|
||||
}
|
||||
|
||||
let formFactor = keyman.util.device.formFactor;
|
||||
let keyMapManager = keyman.keyMapManager;
|
||||
|
||||
this.swallowKeypress = false;
|
||||
|
||||
if(fromOSK && !keyman.isEmbedded) {
|
||||
|
|
@ -367,8 +369,8 @@ namespace com.keyman.text {
|
|||
if(!keyman.isEmbedded && !fromOSK && keyman.util.device.browser == 'firefox') {
|
||||
// I1466 - Convert the - keycode on mnemonic as well as positional layouts
|
||||
// FireFox, Mozilla Suite
|
||||
if(keyMapManager.browserMap.FF['k'+keyEvent.Lcode]) {
|
||||
keyEvent.Lcode=keyMapManager.browserMap.FF['k'+keyEvent.Lcode];
|
||||
if(KeyMapping.browserMap.FF['k'+keyEvent.Lcode]) {
|
||||
keyEvent.Lcode = KeyMapping.browserMap.FF['k'+keyEvent.Lcode];
|
||||
}
|
||||
} //else
|
||||
//{
|
||||
|
|
@ -1140,14 +1142,12 @@ namespace com.keyman.text {
|
|||
var LisVirtualKeyCode = (typeof e.charCode != 'undefined' && e.charCode != null && (e.charCode == 0 || (s.Lmodifiers & 0x6F) != 0));
|
||||
s.LisVirtualKey = LisVirtualKeyCode || e.type != 'keypress';
|
||||
|
||||
let keyMapManager = keyman.keyMapManager;
|
||||
|
||||
// Other minor physical-keyboard adjustments
|
||||
if(activeKeyboard && !activeKeyboard.isMnemonic) {
|
||||
// Positional Layout
|
||||
|
||||
/* 13/03/2007 MCD: Swedish: Start mapping of keystroke to US keyboard */
|
||||
var Lbase=keyMapManager.languageMap[com.keyman.osk.Layouts._BaseLayout];
|
||||
var Lbase = KeyMapping.languageMap[this.baseLayout];
|
||||
if(Lbase && Lbase['k'+s.Lcode]) {
|
||||
s.Lcode=Lbase['k'+s.Lcode];
|
||||
}
|
||||
|
|
@ -1156,7 +1156,7 @@ namespace com.keyman.text {
|
|||
if(!activeKeyboard.definesPositionalOrMnemonic && !(s.Lmodifiers & 0x60)) {
|
||||
// Support version 1.0 KeymanWeb keyboards that do not define positional vs mnemonic
|
||||
s = {
|
||||
Lcode: keyMapManager._USKeyCodeToCharCode(s),
|
||||
Lcode: KeyMapping._USKeyCodeToCharCode(s),
|
||||
Ltarg: s.Ltarg,
|
||||
Lmodifiers: 0,
|
||||
LisVirtualKey: false,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue