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

Method _getPointerPositionOnPage

src/cdk/drag-drop/drag-ref.ts:1269–1298  ·  view source on GitHub ↗

Determines the point of the page that was touched by the user.

(event: MouseEvent | TouchEvent)

Source from the content-addressed store, hash-verified

1267
1268 /** Determines the point of the page that was touched by the user. */
1269 private _getPointerPositionOnPage(event: MouseEvent | TouchEvent): Point {
1270 const scrollPosition = this._getViewportScrollPosition();
1271 const point = isTouchEvent(event)
1272 ? // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
1273 // Also note that on real devices we're guaranteed for either `touches` or `changedTouches`
1274 // to have a value, but Firefox in device emulation mode has a bug where both can be empty
1275 // for `touchstart` and `touchend` so we fall back to a dummy object in order to avoid
1276 // throwing an error. The value returned here will be incorrect, but since this only
1277 // breaks inside a developer tool and the value is only used for secondary information,
1278 // we can get away with it. See https://bugzilla.mozilla.org/show_bug.cgi?id=1615824.
1279 event.touches[0] || event.changedTouches[0] || {pageX: 0, pageY: 0}
1280 : event;
1281
1282 const x = point.pageX - scrollPosition.left;
1283 const y = point.pageY - scrollPosition.top;
1284
1285 // if dragging SVG element, try to convert from the screen coordinate system to the SVG
1286 // coordinate system
1287 if (this._ownerSVGElement) {
1288 const svgMatrix = this._ownerSVGElement.getScreenCTM();
1289 if (svgMatrix) {
1290 const svgPoint = this._ownerSVGElement.createSVGPoint();
1291 svgPoint.x = x;
1292 svgPoint.y = y;
1293 return svgPoint.matrixTransform(svgMatrix.inverse());
1294 }
1295 }
1296
1297 return {x, y};
1298 }
1299
1300 /** Gets the pointer position on the page, accounting for any position constraints. */
1301 private _getConstrainedPointerPosition(point: Point): Point {

Callers 4

DragRefClass · 0.95
_endDragSequenceMethod · 0.95
_cleanupDragArtifactsMethod · 0.95

Calls 2

isTouchEventFunction · 0.85

Tested by

no test coverage detected