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

Method _getConstrainedPointerPosition

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

Gets the pointer position on the page, accounting for any position constraints.

(point: Point)

Source from the content-addressed store, hash-verified

1300
1301 /** Gets the pointer position on the page, accounting for any position constraints. */
1302 private _getConstrainedPointerPosition(point: Point): Point {
1303 const dropContainerLock = this._dropContainer ? this._dropContainer.lockAxis : null;
1304 let {x, y} = this.constrainPosition
1305 ? this.constrainPosition(point, this, this._initialDomRect!, this._pickupPositionInElement)
1306 : point;
1307
1308 if (this.lockAxis === 'x' || dropContainerLock === 'x') {
1309 y =
1310 this._pickupPositionOnPage.y -
1311 (this.constrainPosition ? this._pickupPositionInElement.y : 0);
1312 } else if (this.lockAxis === 'y' || dropContainerLock === 'y') {
1313 x =
1314 this._pickupPositionOnPage.x -
1315 (this.constrainPosition ? this._pickupPositionInElement.x : 0);
1316 }
1317
1318 if (this._boundaryRect) {
1319 // If not using a custom constrain we need to account for the pickup position in the element
1320 // otherwise we do not need to do this, as it has already been accounted for
1321 const {x: pickupX, y: pickupY} = !this.constrainPosition
1322 ? this._pickupPositionInElement
1323 : {x: 0, y: 0};
1324
1325 const boundaryRect = this._boundaryRect;
1326 const {width: previewWidth, height: previewHeight} = this._getPreviewRect();
1327 const minY = boundaryRect.top + pickupY;
1328 const maxY = boundaryRect.bottom - (previewHeight - pickupY);
1329 const minX = boundaryRect.left + pickupX;
1330 const maxX = boundaryRect.right - (previewWidth - pickupX);
1331
1332 x = clamp(x, minX, maxX);
1333 y = clamp(y, minY, maxY);
1334 }
1335
1336 return {x, y};
1337 }
1338
1339 /** Updates the current drag delta, based on the user's current pointer position on the page. */
1340 private _updatePointerDirectionDelta(pointerPositionOnPage: Point) {

Callers 2

DragRefClass · 0.95

Calls 3

_getPreviewRectMethod · 0.95
constrainPositionMethod · 0.80
clampFunction · 0.70

Tested by

no test coverage detected