diff --git a/web/source/osk/inputEventCoordinate.ts b/web/source/osk/inputEventCoordinate.ts index cda6eea669..97c3f51f08 100644 --- a/web/source/osk/inputEventCoordinate.ts +++ b/web/source/osk/inputEventCoordinate.ts @@ -14,28 +14,25 @@ namespace com.keyman.osk { } } - // Converts a MouseEvent into the base coordinates needed by the mouse-dragging operations. - public static fromMouseEvent(e: MouseEvent) { - if (e.pageX) { - return new InputEventCoordinate(e.pageX, e.pageY, e); - } else if (e.clientX) { - const x = e.clientX + document.body.scrollLeft; - const y = e.clientY + document.body.scrollTop; - - return new InputEventCoordinate(x, y, e); + // Converts a MouseEvent or TouchEvent into the base coordinates needed + // by the mouse-dragging operations. + public static fromEvent(e: MouseEvent | TouchEvent) { + let coordSource: MouseEvent | Touch; + if(e instanceof TouchEvent) { + coordSource = e.changedTouches[0]; + } else { + coordSource = e; } - } - public static fromTouchEvent(e: TouchEvent) { - let touch = e.changedTouches[0]; - - if(touch.pageX) { - return new InputEventCoordinate(touch.pageX, touch.pageY, e); - } else if (touch.clientX) { - const x = touch.clientX + document.body.scrollLeft; - const y = touch.clientY + document.body.scrollTop; + if (coordSource.pageX) { + return new InputEventCoordinate(coordSource.pageX, coordSource.pageY, e); + } else if (coordSource.clientX) { + const x = coordSource.clientX + document.body.scrollLeft; + const y = coordSource.clientY + document.body.scrollTop; return new InputEventCoordinate(x, y, e); + } else { + return new InputEventCoordinate(null, null, e); } } diff --git a/web/source/osk/layouts/mouseDragOperation.ts b/web/source/osk/layouts/mouseDragOperation.ts index c0a16048b6..01777ffe9f 100644 --- a/web/source/osk/layouts/mouseDragOperation.ts +++ b/web/source/osk/layouts/mouseDragOperation.ts @@ -92,7 +92,7 @@ namespace com.keyman.osk.layouts { this._mouseStartSnapshot = new MouseStartSnapshot(e); } - this._startCoord = InputEventCoordinate.fromMouseEvent(e); + this._startCoord = InputEventCoordinate.fromEvent(e); document.onmousemove = this._VMoveMouseMove.bind(this); document.onmouseup = this._VMoveMouseUp.bind(this); @@ -129,7 +129,7 @@ namespace com.keyman.osk.layouts { if(!this._mouseStartSnapshot.matchesCausingClick(e)) { // I1472 - Dragging off edge of browser window causes muckup return this._VMoveMouseUp(e); } else { - const coord = InputEventCoordinate.fromMouseEvent(e); + const coord = InputEventCoordinate.fromEvent(e); const deltaX = coord.x - this._startCoord.x; const deltaY = coord.y - this._startCoord.y; diff --git a/web/source/osk/touchEventEngine.ts b/web/source/osk/touchEventEngine.ts index 28b65b5f3c..2f081d12ec 100644 --- a/web/source/osk/touchEventEngine.ts +++ b/web/source/osk/touchEventEngine.ts @@ -40,12 +40,12 @@ namespace com.keyman.osk { } onTouchStart(event: TouchEvent) { - this.onInputStart(InputEventCoordinate.fromTouchEvent(event)); + this.onInputStart(InputEventCoordinate.fromEvent(event)); } onTouchMove(event: TouchEvent) { this.preventPropagation(event); - const coord = InputEventCoordinate.fromTouchEvent(event); + const coord = InputEventCoordinate.fromEvent(event); if(this.vkbd.detectWithinBounds(coord)) { this.onInputMove(coord); @@ -55,7 +55,7 @@ namespace com.keyman.osk { } onTouchEnd(event: TouchEvent) { - this.onInputEnd(InputEventCoordinate.fromTouchEvent(event)); + this.onInputEnd(InputEventCoordinate.fromEvent(event)); } } } \ No newline at end of file