From 6f366f9f8046e478ddc48ffbf026568a94453283 Mon Sep 17 00:00:00 2001 From: jahorton Date: Tue, 31 Mar 2020 15:23:43 +0700 Subject: [PATCH] fix(web): ensures activeElement is always an element, not iframe doc. Fixes #539 --- web/source/dom/domEventHandlers.ts | 17 ++++++++--------- web/source/dom/domManager.ts | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/web/source/dom/domEventHandlers.ts b/web/source/dom/domEventHandlers.ts index e31617bc33..96cab878d6 100644 --- a/web/source/dom/domEventHandlers.ts +++ b/web/source/dom/domEventHandlers.ts @@ -16,8 +16,8 @@ namespace com.keyman.dom { _Selection = null; _SelectionControl: any = null; // Type behavior is as with activeElement and the like. - activeElement: any; // TODO: Add type and fix resulting bugs! - lastActiveElement: any; // TODO: Add type and fix resulting bugs! + activeElement: HTMLElement; + lastActiveElement: HTMLElement; focusing: boolean; focusTimer: number; @@ -192,7 +192,7 @@ namespace com.keyman.dom { * Respond to KMW losing focus on event */ _ControlBlur: (e: FocusEvent) => boolean = function(this: DOMEventHandlers, e: FocusEvent): boolean { - var Ltarg: HTMLElement | Document; + var Ltarg: HTMLElement; e = this.keyman._GetEventObject(e); // I2404 - Manage IE events in IFRAMEs Ltarg = this.keyman.util.eventTarget(e) as HTMLElement; @@ -223,10 +223,9 @@ namespace com.keyman.dom { Ltarg = Ltarg.parentNode as HTMLElement; } - // TODO: Needs tidy-up. if(Ltarg.ownerDocument) { if(Ltarg instanceof Ltarg.ownerDocument.defaultView.HTMLIFrameElement) { - Ltarg=Ltarg.contentWindow.document; + Ltarg=Ltarg.contentWindow.frameElement as HTMLElement; } } @@ -244,7 +243,7 @@ namespace com.keyman.dom { var isActivating = this.keyman.uiManager.isActivating; let activeKeyboard = com.keyman.singleton.textProcessor.activeKeyboard; if(!isActivating && activeKeyboard) { - activeKeyboard.notify(0, text.Processor.getOutputTarget(Ltarg as HTMLElement), 0); // I2187 + activeKeyboard.notify(0, text.Processor.getOutputTarget(Ltarg), 0); // I2187 } //e = this.keyman._GetEventObject(e); // I2404 - Manage IE events in IFRAMEs //TODO: is this really needed again???? @@ -690,9 +689,9 @@ namespace com.keyman.dom { /** * Close OSK and remove simulated caret on losing focus */ - cancelInput(): void { - if(DOMEventHandlers.states.activeElement && DOMEventHandlers.states.activeElement.hideCaret) { - DOMEventHandlers.states.activeElement.hideCaret(); + cancelInput(): void { + if(DOMEventHandlers.states.activeElement && Utils.instanceof(DOMEventHandlers.states.activeElement, "TouchAliasElement")) { + (DOMEventHandlers.states.activeElement as TouchAliasElement).hideCaret(); } DOMEventHandlers.states.activeElement=null; this.keyman.osk.hideNow(); diff --git a/web/source/dom/domManager.ts b/web/source/dom/domManager.ts index 7f9232c2ca..6510af1edf 100644 --- a/web/source/dom/domManager.ts +++ b/web/source/dom/domManager.ts @@ -1247,8 +1247,8 @@ namespace com.keyman.dom { * @param {boolean=} setFocus optionally set focus (KMEW-123) **/ setActiveElement(e: string|HTMLElement, setFocus?: boolean) { - if(typeof(e) == "string") { // Can't instanceof string, and String is a different type. - e=document.getElementById(e); + if(typeof e == "string") { // Can't instanceof string, and String is a different type. + e = document.getElementById(e); } if(this.keyman.isEmbedded) { @@ -1264,7 +1264,7 @@ namespace com.keyman.dom { // As this is an API function, someone may pass in the base of a touch element. // We need to respond appropriately. - e = e['kmw_ip'] ? e['kmw_ip'] : e; + e = (e['kmw_ip'] ? e['kmw_ip'] : e) as HTMLElement; // If we're changing controls, don't forget to properly manage the keyboard settings! // It's only an issue on 'native' (non-embedded) code paths.