Skip to content

Commit 7ba938a

Browse files
committed
fix(canvas): make events cancelable
1 parent bffb94c commit 7ba938a

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

packages/canvas/Canvas/common.ts

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,6 @@ export class TouchEvent extends UIEvent {
290290
this.ctrlKey = options?.ctrlKey ?? false;
291291
this.shiftKey = options?.shiftKey ?? false;
292292
}
293-
294-
preventDefault() {}
295-
296-
stopPropagation() {}
297293
}
298294

299295
interface WheelEventOptions extends UIEventOptions {
@@ -552,6 +548,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
552548
isPrimary: pointer.isPrimary,
553549
button: -1,
554550
target: this.__target ?? this,
551+
cancelable: true,
555552
preventDefault: () => {
556553
preventDefault = true;
557554
},
@@ -588,6 +585,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
588585
targetTouches: touches,
589586
changedTouches,
590587
target: this.__target ?? this,
588+
cancelable: true,
591589
preventDefault: () => {
592590
preventDefault = true;
593591
},
@@ -644,6 +642,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
644642
pageX: x,
645643
pageY: y,
646644
target: this.__target ?? this,
645+
cancelable: true,
647646
preventDefault: () => {
648647
preventDefault = true;
649648
},
@@ -707,6 +706,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
707706
targetTouches: touches,
708707
changedTouches,
709708
target: this.__target ?? this,
709+
cancelable: true,
710710
preventDefault: () => {
711711
preventDefault = true;
712712
},
@@ -767,6 +767,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
767767
pageX: x,
768768
pageY: y,
769769
target: this.__target ?? this,
770+
cancelable: true,
770771
preventDefault: () => {
771772
preventDefault = true;
772773
},
@@ -797,6 +798,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
797798
targetTouches: touches,
798799
changedTouches: this._touches,
799800
target: this.__target ?? this,
801+
cancelable: true,
800802
preventDefault: () => {
801803
preventDefault = true;
802804
},
@@ -850,6 +852,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
850852
pageY: y,
851853
isPrimary,
852854
target: this.__target ?? this,
855+
cancelable: true,
853856
preventDefault: () => {
854857
preventDefault = true;
855858
},
@@ -880,6 +883,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
880883
targetTouches: touches,
881884
changedTouches: touchesList,
882885
target: this.__target ?? this,
886+
cancelable: true,
883887
preventDefault: () => {
884888
preventDefault = true;
885889
},
@@ -943,6 +947,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
943947
movementY: pointer.y - previousEvent.y,
944948
button: -1,
945949
target: this.__target ?? this,
950+
cancelable: true,
946951
preventDefault: () => {
947952
preventDefault = true;
948953
},
@@ -968,39 +973,6 @@ export abstract class CanvasBase extends View implements ICanvasBase {
968973
);
969974
}
970975

971-
if (hasMouseCallbacks && !preventDefault) {
972-
const event = new MouseEvent('mousemove', {
973-
clientX: pointer.x,
974-
clientY: pointer.y,
975-
screenX: pointer.x,
976-
screenY: pointer.y,
977-
pageX: pointer.x,
978-
pageY: pointer.y,
979-
movementX: pointer.x - previousEvent.x,
980-
movementY: pointer.y - previousEvent.y,
981-
button: -1,
982-
target: this.__target ?? this,
983-
});
984-
985-
for (const callback of this._mouseMoveCallbacks) {
986-
callback(event);
987-
}
988-
}
989-
990-
if (hasMouseWheel) {
991-
const event = new WheelEvent('wheel', {
992-
deltaX: data.deltaX,
993-
deltaY: data.deltaY,
994-
deltaZ: 0,
995-
deltaMode: data.deltaMode,
996-
target: this.__target ?? this,
997-
});
998-
999-
for (const callback of this._mouseWheelCallbacks) {
1000-
callback(event);
1001-
}
1002-
}
1003-
1004976
this._lastPointerEventById.set(pointerId, { pointerId, x: pointer.x, y: pointer.y });
1005977
}
1006978

@@ -1012,6 +984,7 @@ export abstract class CanvasBase extends View implements ICanvasBase {
1012984
targetTouches: touches,
1013985
changedTouches,
1014986
target: this.__target ?? this,
987+
cancelable: true,
1015988
preventDefault: () => {
1016989
preventDefault = true;
1017990
},

0 commit comments

Comments
 (0)