* Sets up the different variables and subscriptions * that will be necessary for the dragging sequence. * @param referenceElement Element that started the drag sequence. * @param event Browser event object that started the sequence.
(referenceElement: HTMLElement, event: MouseEvent | TouchEvent)
| 968 | * @param event Browser event object that started the sequence. |
| 969 | */ |
| 970 | private _initializeDragSequence(referenceElement: HTMLElement, event: MouseEvent | TouchEvent) { |
| 971 | // Stop propagation if the item is inside another |
| 972 | // draggable so we don't start multiple drag sequences. |
| 973 | if (this._parentDragRef) { |
| 974 | event.stopPropagation(); |
| 975 | } |
| 976 | |
| 977 | const isDragging = this.isDragging(); |
| 978 | const isTouchSequence = isTouchEvent(event); |
| 979 | const isAuxiliaryMouseButton = !isTouchSequence && (event as MouseEvent).button !== 0; |
| 980 | const rootElement = this._rootElement; |
| 981 | const target = _getEventTarget(event); |
| 982 | const isSyntheticEvent = |
| 983 | !isTouchSequence && |
| 984 | this._lastTouchEventTime && |
| 985 | this._lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date.now(); |
| 986 | const isFakeEvent = isTouchSequence |
| 987 | ? isFakeTouchstartFromScreenReader(event as TouchEvent) |
| 988 | : isFakeMousedownFromScreenReader(event as MouseEvent); |
| 989 | |
| 990 | // If the event started from an element with the native HTML drag&drop, it'll interfere |
| 991 | // with our own dragging (e.g. `img` tags do it by default). Prevent the default action |
| 992 | // to stop it from happening. Note that preventing on `dragstart` also seems to work, but |
| 993 | // it's flaky and it fails if the user drags it away quickly. Also note that we only want |
| 994 | // to do this for `mousedown` since doing the same for `touchstart` will stop any `click` |
| 995 | // events from firing on touch devices. |
| 996 | if (target && (target as HTMLElement).draggable && event.type === 'mousedown') { |
| 997 | event.preventDefault(); |
| 998 | } |
| 999 | |
| 1000 | // Abort if the user is already dragging or is using a mouse button other than the primary one. |
| 1001 | if (isDragging || isAuxiliaryMouseButton || isSyntheticEvent || isFakeEvent) { |
| 1002 | return; |
| 1003 | } |
| 1004 | |
| 1005 | // If we've got handles, we need to disable the tap highlight on the entire root element, |
| 1006 | // otherwise iOS will still add it, even though all the drag interactions on the handle |
| 1007 | // are disabled. |
| 1008 | if (this._handles.length) { |
| 1009 | const rootStyles = rootElement.style as DragCSSStyleDeclaration; |
| 1010 | this._rootElementTapHighlight = rootStyles.webkitTapHighlightColor || ''; |
| 1011 | rootStyles.webkitTapHighlightColor = 'transparent'; |
| 1012 | } |
| 1013 | |
| 1014 | this._hasMoved = false; |
| 1015 | this._hasStartedDragging.set(this._hasMoved); |
| 1016 | |
| 1017 | // Avoid multiple subscriptions and memory leaks when multi touch |
| 1018 | // (isDragging check above isn't enough because of possible temporal and/or dimensional delays) |
| 1019 | this._removeListeners(); |
| 1020 | this._initialDomRect = this._rootElement.getBoundingClientRect(); |
| 1021 | this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove); |
| 1022 | this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp); |
| 1023 | this._scrollSubscription = this._dragDropRegistry |
| 1024 | .scrolled(this._getShadowRoot()) |
| 1025 | .subscribe(scrollEvent => this._updateOnScroll(scrollEvent)); |
| 1026 | |
| 1027 | if (this._boundaryElement) { |
no test coverage detected