Skip to content

Commit 4e5bf49

Browse files
authored
Continuously check for pointer capture on web (#2563)
## Description Read the comment in the code. ## Test plan Tested on the example app.
1 parent a69a563 commit 4e5bf49

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/web/tools/PointerEventManager.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ export default class PointerEventManager extends EventManager {
7777
}
7878

7979
const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.MOVE);
80+
const target = event.target as HTMLElement;
81+
82+
// You may be wondering why are we setting pointer capture here, when we
83+
// already set it in `pointerdown` handler. Well, that's a great question,
84+
// for which I don't have an answer. Specification (https://www.w3.org/TR/pointerevents2/#dom-element-setpointercapture)
85+
// says that the requirement for `setPointerCapture` to work is that pointer
86+
// must be in 'active buttons state`, otherwise it will fail silently, which
87+
// is lovely. Obviously, when `pointerdown` is fired, one of the buttons
88+
// (when using mouse) is pressed, but that doesn't mean that `setPointerCapture`
89+
// will succeed, for some reason. Since it fails silently, we don't actually know
90+
// if it worked or not (there's `gotpointercapture` event, but the complexity of
91+
// incorporating it here seems stupid), so we just call it again here, every time
92+
// pointer moves until it succeeds.
93+
// God, I do love web development.
94+
if (!target.hasPointerCapture(event.pointerId)) {
95+
target.setPointerCapture(event.pointerId);
96+
}
8097

8198
const inBounds: boolean = isPointerInBounds(this.view, {
8299
x: adaptedEvent.x,

0 commit comments

Comments
 (0)