mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-08 18:05:32 +00:00
chore(web): decommisions domManager.ts, kmwkeyboards.ts
This commit is contained in:
parent
e54b63aa6e
commit
d436639ae4
3 changed files with 0 additions and 320 deletions
|
|
@ -553,30 +553,17 @@ export default class ContextManager extends ContextManagerBase<BrowserConfigurat
|
|||
_CommonFocusHelper(outputTarget: OutputTarget<any>): boolean {
|
||||
const focusAssistant = this.focusAssistant;
|
||||
|
||||
// if(target.ownerDocument && target instanceof target.ownerDocument.defaultView.HTMLIFrameElement) {
|
||||
// if(!this.keyman.domManager._IsEditableIframe(target, 1)) {
|
||||
// DOMEventHandlers.states._DisableInput = true;
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// DOMEventHandlers.states._DisableInput = false;
|
||||
|
||||
// const outputTarget = dom.Utils.getOutputTarget(target);
|
||||
|
||||
let activeKeyboard = this.activeKeyboard?.keyboard;
|
||||
if(!focusAssistant.restoringFocus) {
|
||||
outputTarget?.deadkeys().clear();
|
||||
activeKeyboard?.notify(0, outputTarget, 1); // I2187
|
||||
}
|
||||
|
||||
//if(!focusAssistant.restoringFocus && DOMEventHandlers.states._SelectionControl != target) {
|
||||
if(!focusAssistant.restoringFocus && this.mostRecentTarget != outputTarget) {
|
||||
focusAssistant.maintainingFocus = false;
|
||||
}
|
||||
focusAssistant.restoringFocus = false;
|
||||
|
||||
//DOMEventHandlers.states._SelectionControl = target; // effectively was .mostRecentTarget, as best as I can tell.
|
||||
|
||||
// Now that we've fully entered the new context, invalidate the context so we can generate initial predictions from it.
|
||||
// (Note that the active keyboard will have been updated by a method called before this one; the newly-focused
|
||||
// context should now be 100% ready.)
|
||||
|
|
|
|||
|
|
@ -1,212 +0,0 @@
|
|||
// Includes KMW-added property declaration extensions for HTML elements.
|
||||
/// <reference path="../kmwexthtml.ts" />
|
||||
// References the base KMW object.
|
||||
/// <reference path="../kmwbase.ts" />
|
||||
// References DOM event handling interfaces and classes.
|
||||
/// <reference path="domEventHandlers.ts" />
|
||||
// References DOM-specific output handling.
|
||||
/// <reference path="domDefaultOutput.ts" />
|
||||
// References other DOM-specific web-core overrides.
|
||||
/// <reference path="domOverrides.ts" />
|
||||
// Defines per-element-type OutputTarget element wrapping.
|
||||
/// <reference path="targets/wrapElement.ts" />
|
||||
// Defines cookie-based variable store serialization
|
||||
/// <reference path="variableStoreCookieSerializer.ts" />
|
||||
|
||||
namespace com.keyman.dom {
|
||||
|
||||
|
||||
/**
|
||||
* This class serves as the intermediary between KeymanWeb and any given web page's elements.
|
||||
*/
|
||||
export class DOMManager {
|
||||
private keyman: KeymanBase;
|
||||
|
||||
/**
|
||||
* Implements the AliasElementHandlers interface for touch interaction.
|
||||
*/
|
||||
touchHandlers?: DOMTouchHandlers;
|
||||
|
||||
/**
|
||||
* Implements stubs for the AliasElementHandlers interface for non-touch interaction.
|
||||
*/
|
||||
nonTouchHandlers: DOMEventHandlers;
|
||||
|
||||
// Used for special touch-based page interactions re: element activation on touch devices.
|
||||
deactivateOnScroll: boolean = false;
|
||||
deactivateOnRelease: boolean = false;
|
||||
touchY: number; // For scroll-related aspects on iOS.
|
||||
|
||||
touchStartActivationHandler: (e: TouchEvent) => boolean;
|
||||
touchMoveActivationHandler: (e: TouchEvent) => boolean;
|
||||
touchEndActivationHandler: (e: TouchEvent) => boolean;
|
||||
|
||||
constructor(keyman: KeymanBase) {
|
||||
this.keyman = keyman;
|
||||
|
||||
if(keyman.util.device.touchable) {
|
||||
this.touchHandlers = new DOMTouchHandlers(keyman);
|
||||
}
|
||||
|
||||
this.nonTouchHandlers = new DOMEventHandlers(keyman);
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
// Catch and notify of any shutdown errors, but don't let errors fail unit tests.
|
||||
try {
|
||||
if(this.enablementObserver) {
|
||||
this.enablementObserver.disconnect();
|
||||
}
|
||||
if(this.attachmentObserver) {
|
||||
this.attachmentObserver.disconnect();
|
||||
}
|
||||
|
||||
// On shutdown, we remove our general focus-suppression handlers as well.
|
||||
this.keyman.util.detachDOMEvent(document.body, 'focus', DOMManager.suppressFocusCheck, true);
|
||||
this.keyman.util.detachDOMEvent(document.body, 'blur', DOMManager.suppressFocusCheck, true);
|
||||
|
||||
// Also, the base-page touch handlers for activation management.
|
||||
if(this.touchStartActivationHandler) {
|
||||
this.keyman.util.detachDOMEvent(document.body, 'touchstart', this.touchStartActivationHandler, false);
|
||||
this.keyman.util.detachDOMEvent(document.body, 'touchmove', this.touchMoveActivationHandler, false);
|
||||
this.keyman.util.detachDOMEvent(document.body, 'touchend', this.touchEndActivationHandler, false);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error occurred during shutdown");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------- Editable IFrame methods ------------------- */
|
||||
|
||||
/**
|
||||
* Function _IsEditableIframe
|
||||
* Scope Private
|
||||
* @param {Object} Pelem Iframe element
|
||||
* @param {boolean|number} PtestOn 1 to test if 'designMode' is 'ON'
|
||||
* @return {boolean}
|
||||
* Description Test if element is a Mozilla editable IFrame
|
||||
*/
|
||||
_IsEditableIframe(Pelem: HTMLIFrameElement, PtestOn?: number) {
|
||||
var Ldv, Lvalid = Pelem && (Ldv=(<any>Pelem).defaultView) && Ldv.frameElement; // Probable bug!
|
||||
return (!PtestOn && Lvalid) || (PtestOn && (!Lvalid || Ldv.document.designMode.toLowerCase()=='on'));
|
||||
}
|
||||
|
||||
/* ----------------------- Initialization methods ------------------ */
|
||||
|
||||
/**
|
||||
* Function Initialization
|
||||
* Scope Public
|
||||
* @param {com.keyman.OptionType} arg object of user-defined properties
|
||||
* Description KMW window initialization
|
||||
*/
|
||||
init: (arg: com.keyman.OptionType) => Promise<any> = function(this: DOMManager, arg): Promise<any> {
|
||||
var p,opt,dTrailer,ds;
|
||||
var util = this.keyman.util;
|
||||
var device = util.device;
|
||||
|
||||
// Set callbacks for proper feedback from web-core.
|
||||
this.keyman.core.keyboardProcessor.beepHandler = this.doBeep.bind(this);
|
||||
this.keyman.core.keyboardProcessor.warningLogger = console.warn.bind(console);
|
||||
this.keyman.core.keyboardProcessor.errorLogger = console.error.bind(console);
|
||||
|
||||
// Set default device options
|
||||
this.keyman.setDefaultDeviceOptions(opt);
|
||||
|
||||
// Only do remainder of initialization once!
|
||||
if(this.keyman.initialized) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this.keyman.linkStylesheetResources();
|
||||
|
||||
const keyman: KeymanBase = this.keyman;
|
||||
const domManager = this;
|
||||
|
||||
// Do not initialize until the document has been fully loaded
|
||||
if(document.readyState !== 'complete')
|
||||
{
|
||||
return new Promise<void>(function(resolve) {
|
||||
window.setTimeout(function(){
|
||||
domManager.init(arg).then(function() {
|
||||
resolve();
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
}
|
||||
|
||||
keyman.modelManager.init();
|
||||
this.keyman._MasterDocument = window.document;
|
||||
|
||||
/*
|
||||
* Initialization of touch devices and browser interfaces must be done
|
||||
* after all resources are loaded, during final stage of initialization
|
||||
*/
|
||||
|
||||
// Set exposed initialization flag member for UI (and other) code to use
|
||||
this.keyman.setInitialized(1);
|
||||
|
||||
// Finish keymanweb and initialize the OSK once all necessary resources are available
|
||||
// OSK type selection is already modularized... but the ordering related to the parts
|
||||
// afterward, which are not yet modularized, may be important.
|
||||
if(device.touchable) {
|
||||
this.keyman.osk = new com.keyman.osk.AnchoredOSKView(device.coreSpec);
|
||||
} else {
|
||||
this.keyman.osk = new com.keyman.osk.FloatingOSKView(device.coreSpec);
|
||||
}
|
||||
const osk = this.keyman.osk;
|
||||
|
||||
// Create and save the remote keyboard loading delay indicator
|
||||
util.prepareWait();
|
||||
|
||||
// Trigger registration of deferred keyboard stubs and keyboards
|
||||
this.keyman.keyboardManager.endDeferment();
|
||||
|
||||
// Initialize the desktop UI
|
||||
this.initializeUI();
|
||||
|
||||
// Determine the default font for mapped elements
|
||||
this.keyman.appliedFont=this.keyman.baseFont=this.getBaseFont();
|
||||
|
||||
// Add orientationchange event handler to manage orientation changes on mobile devices
|
||||
// Initialize touch-screen device interface I3363 (Build 301)
|
||||
if(device.touchable) {
|
||||
this.keyman.handleRotationEvents();
|
||||
}
|
||||
// Initialize browser interface
|
||||
|
||||
// Modular form: pageContextAttachment.install()
|
||||
|
||||
// Initialize the OSK and set default OSK styles
|
||||
// Note that this should *never* be called before the OSK has been initialized.
|
||||
// However, it possibly may be called before the OSK has been fully defined with the current keyboard, need to check.
|
||||
//osk._Load();
|
||||
|
||||
//document.body.appendChild(osk._Box);
|
||||
|
||||
//osk._Load(false);
|
||||
|
||||
// I3363 (Build 301)
|
||||
if(device.touchable) {
|
||||
const osk = keyman.osk as osk.AnchoredOSKView;
|
||||
// Handle OSK touchend events (prevent propagation)
|
||||
osk._Box.addEventListener('touchend',function(e){
|
||||
e.stopPropagation();
|
||||
}, false);
|
||||
}
|
||||
|
||||
//document.body.appendChild(keymanweb._StyleBlock);
|
||||
|
||||
// Restore and reload the currently selected keyboard, selecting a default keyboard if necessary.
|
||||
this.keyman.keyboardManager.restoreCurrentKeyboard();
|
||||
|
||||
// Set exposed initialization flag to 2 to indicate deferred initialization also complete
|
||||
|
||||
// Other initialization details after this point have already been modularized:
|
||||
// within app/browser KeymanEngine.init, see `setupOskListeners` call and after.
|
||||
|
||||
this.keyman.setInitialized(2);
|
||||
return Promise.resolve();
|
||||
}.bind(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/// <reference path="../kmwbase.ts" />
|
||||
|
||||
namespace com.keyman.keyboards {
|
||||
export class KeyboardTag {
|
||||
stores: {[text: string]: text.ComplexKeyboardStore} = {};
|
||||
}
|
||||
|
||||
export class KeyboardManager {
|
||||
keymanweb: KeymanBase;
|
||||
|
||||
activeStub: KeyboardStub = null;
|
||||
keyboardStubs: KeyboardStub[] = [];
|
||||
|
||||
// For deferment of adding keyboards until keymanweb initializes
|
||||
deferment: Promise<void> = null;
|
||||
endDeferment:() => void;
|
||||
|
||||
// The following was not actually utilized within KeymanWeb; I think it's handled via different logic.
|
||||
// See setDefaultKeyboard() below.
|
||||
dfltStub = null; // First keyboard stub loaded - default for touch-screen devices, ignored on desktops
|
||||
|
||||
keyboards: any[] = [];
|
||||
|
||||
linkedScripts: HTMLScriptElement[] = [];
|
||||
|
||||
constructor(kmw: KeymanBase) {
|
||||
this.keymanweb = kmw;
|
||||
|
||||
let _this = this;
|
||||
this.deferment = new Promise(function(resolve) {
|
||||
_this.endDeferment = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
// Called on the embedded path at the end of its initialization.
|
||||
setDefaultKeyboard() {
|
||||
if(this.keyboardStubs.length > 0) {
|
||||
// Select the first stub as our active keyboard.
|
||||
this._SetActiveKeyboard(this.keyboardStubs[0]['KI'], this.keyboardStubs[0]['KLC']);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: why not use util.loadCookie and saveCookie?? */
|
||||
|
||||
/**
|
||||
* Restore the most recently used keyboard, if still available
|
||||
*/
|
||||
restoreCurrentKeyboard() {
|
||||
var stubs = this.keyboardStubs, i, n=stubs.length;
|
||||
let core = com.keyman.singleton.core;
|
||||
|
||||
// Do nothing if no stubs loaded
|
||||
if(stubs.length < 1) return;
|
||||
|
||||
// If no saved keyboard, default to US English, else first loaded stub
|
||||
var d=this.getSavedKeyboard();
|
||||
var t=d.split(':');
|
||||
|
||||
// Identify the stub with the saved keyboard
|
||||
t=d.split(':');
|
||||
if(t.length < 2) t[1]='';
|
||||
|
||||
// This loop is needed to select the correct stub when several apply to a given keyboard
|
||||
// TODO: There should be a better way!
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
if(stubs[i]['KI'] == t[0] && (stubs[i]['KLC'] == t[1] || t[1] == '')) break;
|
||||
}
|
||||
|
||||
// Sets the default stub (as specified with the `getSavedKeyboard` call) as active.
|
||||
// if((i < n) || (device.touchable && (this.activeKeyboard == null)))
|
||||
if((i < n) || (core.activeKeyboard == null))
|
||||
{
|
||||
this._SetActiveKeyboard(t[0],t[1],false);
|
||||
this.keymanweb.globalKeyboard = t[0];
|
||||
this.keymanweb.globalLanguageCode = t[1];
|
||||
|
||||
this.doKeyboardChange(t[0],t[1]); // And update the UI if necessary
|
||||
}
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
for(let script of this.linkedScripts) {
|
||||
if(script.remove) {
|
||||
script.remove();
|
||||
} else if(script.parentNode) {
|
||||
script.parentNode.removeChild(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue