MCPcopy Create free account
hub / github.com/angular/components / createTouchEvent

Function createTouchEvent

src/cdk/testing/testbed/fake-events/event-objects.ts:109–125  ·  view source on GitHub ↗
(type: string, pageX = 0, pageY = 0, clientX = 0, clientY = 0)

Source from the content-addressed store, hash-verified

107 * @docs-private
108 */
109export 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.

Calls 1

Tested by 1