fix(web): ensures activeElement is always an element, not iframe doc. Fixes #539

This commit is contained in:
jahorton 2020-03-31 15:23:43 +07:00
parent a78626ac6c
commit 6f366f9f80
2 changed files with 11 additions and 12 deletions

View file

@ -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<FocusEvent>(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<FocusEvent>(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();

View file

@ -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.