| 107 | * @docs-private |
| 108 | */ |
| 109 | export function createTouchEvent(type: string, pageX = 0, pageY = 0, clientX = 0, clientY = 0) { |
| 110 | // We cannot use the `TouchEvent` or `Touch` because Firefox and Safari lack support. |
| 111 | // TODO: Switch to the constructor API when it is available for Firefox and Safari. |
| 112 | const event = document.createEvent('UIEvent'); |
| 113 | const touchDetails = {pageX, pageY, clientX, clientY, identifier: uniqueIds++}; |
| 114 | |
| 115 | // TS3.6 removes the initUIEvent method and suggests porting to "new UIEvent()". |
| 116 | (event as any).initUIEvent(type, true, true, window, 0); |
| 117 | |
| 118 | // Most of the browsers don't have a "initTouchEvent" method that can be used to define |
| 119 | // the touch details. |
| 120 | defineReadonlyEventProperty(event, 'touches', [touchDetails]); |
| 121 | defineReadonlyEventProperty(event, 'targetTouches', [touchDetails]); |
| 122 | defineReadonlyEventProperty(event, 'changedTouches', [touchDetails]); |
| 123 | |
| 124 | return event; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Creates a keyboard event with the specified key and modifiers. |