| 15 | } |
| 16 | |
| 17 | export class GlobalPointerMoveMonitor implements IDisposable { |
| 18 | |
| 19 | private readonly _hooks = new DisposableStore(); |
| 20 | private _pointerMoveCallback: IPointerMoveCallback | null = null; |
| 21 | private _onStopCallback: IOnStopCallback | null = null; |
| 22 | |
| 23 | public dispose(): void { |
| 24 | this.stopMonitoring(false); |
| 25 | this._hooks.dispose(); |
| 26 | } |
| 27 | |
| 28 | public stopMonitoring(invokeStopCallback: boolean, browserEvent?: PointerEvent | KeyboardEvent): void { |
| 29 | if (!this.isMonitoring()) { |
| 30 | // Not monitoring |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | // Unhook |
| 35 | this._hooks.clear(); |
| 36 | this._pointerMoveCallback = null; |
| 37 | const onStopCallback = this._onStopCallback; |
| 38 | this._onStopCallback = null; |
| 39 | |
| 40 | if (invokeStopCallback && onStopCallback) { |
| 41 | onStopCallback(browserEvent); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | public isMonitoring(): boolean { |
| 46 | return !!this._pointerMoveCallback; |
| 47 | } |
| 48 | |
| 49 | public startMonitoring( |
| 50 | initialElement: Element, |
| 51 | pointerId: number, |
| 52 | initialButtons: number, |
| 53 | pointerMoveCallback: IPointerMoveCallback, |
| 54 | onStopCallback: IOnStopCallback |
| 55 | ): void { |
| 56 | if (this.isMonitoring()) { |
| 57 | this.stopMonitoring(false); |
| 58 | } |
| 59 | this._pointerMoveCallback = pointerMoveCallback; |
| 60 | this._onStopCallback = onStopCallback; |
| 61 | |
| 62 | let eventSource: Element | Window = initialElement; |
| 63 | |
| 64 | try { |
| 65 | initialElement.setPointerCapture(pointerId); |
| 66 | this._hooks.add(toDisposable(() => { |
| 67 | try { |
| 68 | initialElement.releasePointerCapture(pointerId); |
| 69 | } catch (err) { |
| 70 | // See https://github.com/microsoft/vscode/issues/161731 |
| 71 | // |
| 72 | // `releasePointerCapture` sometimes fails when being invoked with the exception: |
| 73 | // DOMException: Failed to execute 'releasePointerCapture' on 'Element': |
| 74 | // No active pointer with the given id is found. |
nothing calls this directly
no outgoing calls
no test coverage detected