mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-28 18:47:41 +00:00
refactor(web): merges mouse + touch processing, extra branch for unit tests
This commit is contained in:
parent
227eb91e1f
commit
52fad6e400
3 changed files with 20 additions and 23 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue