Skip to content

Commit

Permalink
Merge pull request #53 from cursorinsight/denes-coalesced
Browse files Browse the repository at this point in the history
feat: Add coalesced flag to mouse and touch move events
  • Loading branch information
denessapi authored Dec 17, 2024
2 parents 8ab4997 + 74df637 commit abc3d77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,27 @@ class Handlers {

// `pointermove` and `mousemove` event handler
handlePointerMove(event) {
let events = [];
if (this._captureCoalescedEvents && event.getCoalescedEvents) {
event.getCoalescedEvents().forEach((coalescedEvent) => {
this.handleSinglePointerMove(coalescedEvent);
});
events = event.getCoalescedEvents();
}

if (events.length === 0) {
this.handleSinglePointerMove(event, false);
} else {
this.handleSinglePointerMove(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 +263,7 @@ class Handlers {
event.pointerId,
event.screenX,
event.screenY,
coalesced ? 1 : 0,
);
break;
default:
Expand Down Expand Up @@ -303,13 +312,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 +369,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 abc3d77

Please sign in to comment.