Skip to content

Commit

Permalink
feat: Add coalesced flag to mouse and touch move events
Browse files Browse the repository at this point in the history
  • Loading branch information
Denes Sapi committed Dec 16, 2024
1 parent 8ab4997 commit b276972
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,22 @@ class Handlers {

// `pointermove` and `mousemove` event handler
handlePointerMove(event) {
let events = [];
if (this._captureCoalescedEvents && event.getCoalescedEvents) {
event.getCoalescedEvents().forEach((coalescedEvent) => {
this.handleSinglePointerMove(coalescedEvent);
});
} else {
this.handleSinglePointerMove(event);
events = event.getCoalescedEvents();
}
if (events.length === 0) {
events = [event];
}
events.forEach((coalescedEvent, index) => {
this.handleSinglePointerMove(coalescedEvent, index !== events.length - 1);
});
}

handleSinglePointerMove(event) {
handleSinglePointerMove(event, coalesced) {
switch (event.pointerType) {
case 'mouse':
this.handleMouseMove(event);
this.handleMouseMove(event, coalesced);
break;
case 'touch':
this.push(
Expand All @@ -255,6 +258,7 @@ class Handlers {
event.pointerId,
event.screenX,
event.screenY,
coalesced ? 1 : 0,
);
break;
default:
Expand Down Expand Up @@ -303,13 +307,14 @@ class Handlers {
}

// `mousemove` event handler
handleMouseMove(event) {
handleMouseMove(event, coalesced) {
this.push(
MOUSE_MOVE_MESSAGE_TYPE,
TimeUtils.convertEventTimeToTs(event.timeStamp),
event.screenX,
event.screenY,
event.buttons,
coalesced ? 1 : 0,
);
}

Expand Down Expand Up @@ -359,6 +364,7 @@ class Handlers {
touch.identifier,
touch.screenX,
touch.screenY,
false,
);
});
}
Expand Down
3 changes: 3 additions & 0 deletions test/trap.pointer-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ describe('browser with pointer events', () => {
1,
2,
0,
1,
]);

expect(moveEvents[1])
Expand All @@ -186,6 +187,7 @@ describe('browser with pointer events', () => {
3,
4,
0,
0,
]);
});

Expand Down Expand Up @@ -217,6 +219,7 @@ describe('browser with pointer events', () => {
3,
4,
0,
0,
]);
});

Expand Down

0 comments on commit b276972

Please sign in to comment.