-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1187 from visualjerk/task/1186-support-touch-event
#1186@minor: Add support for TouchEvent.
- Loading branch information
Showing
8 changed files
with
241 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import IEventTarget from './IEventTarget.js'; | ||
|
||
export default interface ITouchInit { | ||
identifier: number; | ||
target: IEventTarget; | ||
clientX?: number; | ||
clientY?: number; | ||
screenX?: number; | ||
screenY?: number; | ||
pageX?: number; | ||
pageY?: number; | ||
radiusX?: number; | ||
radiusY?: number; | ||
rotationAngle?: number; | ||
force?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import IEventTarget from './IEventTarget.js'; | ||
import ITouchInit from './ITouchInit.js'; | ||
|
||
/** | ||
* | ||
*/ | ||
export default class Touch { | ||
public readonly identifier: number; | ||
public readonly target: IEventTarget; | ||
public readonly clientX: number; | ||
public readonly clientY: number; | ||
public readonly screenX: number; | ||
public readonly screenY: number; | ||
public readonly pageX: number; | ||
public readonly pageY: number; | ||
public readonly radiusX: number; | ||
public readonly radiusY: number; | ||
public readonly rotationAngle: number; | ||
public readonly force: number; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param [touchInit] Touch init. | ||
*/ | ||
constructor(touchInit: ITouchInit) { | ||
this.identifier = touchInit.identifier; | ||
this.target = touchInit.target; | ||
this.clientX = touchInit.clientX ?? 0; | ||
this.clientY = touchInit.clientY ?? 0; | ||
this.screenX = touchInit.screenX ?? 0; | ||
this.screenY = touchInit.screenY ?? 0; | ||
this.pageX = touchInit.pageX ?? 0; | ||
this.pageY = touchInit.pageY ?? 0; | ||
this.radiusX = touchInit.radiusX ?? 0; | ||
this.radiusY = touchInit.radiusY ?? 0; | ||
this.rotationAngle = touchInit.rotationAngle ?? 0; | ||
this.force = touchInit.force ?? 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import IUIEventInit from '../IUIEventInit.js'; | ||
import Touch from '../Touch.js'; | ||
|
||
export default interface ITouchEventInit extends IUIEventInit { | ||
touches?: Touch[] | null; | ||
targetTouches?: Touch[] | null; | ||
changedTouches?: Touch[] | null; | ||
ctrlKey?: boolean | null; | ||
shiftKey?: boolean | null; | ||
altKey?: boolean | null; | ||
metaKey?: boolean | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ITouchEventInit from './ITouchEventInit.js'; | ||
import UIEvent from '../UIEvent.js'; | ||
import Touch from '../Touch.js'; | ||
|
||
/** | ||
* | ||
*/ | ||
export default class TouchEvent extends UIEvent { | ||
public readonly altKey: boolean; | ||
public readonly changedTouches: Touch[]; | ||
public readonly ctrlKey: boolean; | ||
public readonly metaKey: boolean; | ||
public readonly shiftKey: boolean; | ||
public readonly targetTouches: Touch[]; | ||
public readonly touches: Touch[]; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param type Event type. | ||
* @param [eventInit] Event init. | ||
*/ | ||
constructor(type: string, eventInit: ITouchEventInit | null = null) { | ||
super(type, eventInit); | ||
|
||
this.altKey = eventInit?.altKey ?? false; | ||
this.changedTouches = eventInit?.changedTouches ?? []; | ||
this.ctrlKey = eventInit?.ctrlKey ?? false; | ||
this.metaKey = eventInit?.metaKey ?? false; | ||
this.shiftKey = eventInit?.shiftKey ?? false; | ||
this.targetTouches = eventInit?.targetTouches ?? []; | ||
this.touches = eventInit?.touches ?? []; | ||
} | ||
} |
Oops, something went wrong.