mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
refactor: Migrate to PointerEvents (#6598)
* refactor: Remove checks for PointerEvent support. * refactor: Deprecate and remove calls to splitEventByTouches. * refactor: Deprecate and remove calls to setClientFromTouch(). * refactor: Use PointerEvent in place of Event/MouseEvent/TouchEvent/PseudoEvent. * refactor: Update references to mouse/touch events in code and documentation to reference pointer events. * refactor: Merge Gesture and TouchGesture * chore: clang-format changed files * refactor: Bind and expect PointerEvents instead of MouseEvents. * refactor: Rename TouchGesture to Gesture. * fix: Fix test failures. * chore: clang-format changed files. * fix: Fix errant _ from merging * refactor: Clean up dead code in browser_events.ts. * chore: Update version in deprecation notices to reflect release schedule * fix: Fixed a bug that caused the browser context menu to not be suppressed in Chrome. * fix: Re-export Gesture as TouchGesture for backwards compatibility. * refactor: Deprecate and remove uses of opt_noPreventDefault. * chore: Fix error message in gesture.ts. * chore: Removed obsolete todo.
This commit is contained in:
@@ -163,7 +163,7 @@ suite('Toolbox', function() {
|
||||
test('Toolbox clicked -> Should close flyout', function() {
|
||||
const hideChaffStub = sinon.stub(
|
||||
Blockly.WorkspaceSvg.prototype, "hideChaff");
|
||||
const evt = new MouseEvent('click', {});
|
||||
const evt = new PointerEvent('pointerdown', {});
|
||||
this.toolbox.HtmlDiv.dispatchEvent(evt);
|
||||
sinon.assert.calledOnce(hideChaffStub);
|
||||
});
|
||||
|
||||
@@ -55,13 +55,9 @@ suite('Tooltip', function() {
|
||||
this.block.setTooltip('Test Tooltip');
|
||||
|
||||
// Fire pointer events directly on the relevant SVG.
|
||||
// Note the 'pointerover', due to the events registered through
|
||||
// Blockly.browserEvents.bind being registered as pointer events rather
|
||||
// than mouse events. Mousemove event is registered directly on the
|
||||
// element rather than through browserEvents.
|
||||
this.block.pathObject.svgPath.dispatchEvent(
|
||||
new MouseEvent('pointerover'));
|
||||
this.block.pathObject.svgPath.dispatchEvent(new MouseEvent('mousemove'));
|
||||
new PointerEvent('pointerover'));
|
||||
this.block.pathObject.svgPath.dispatchEvent(new PointerEvent('pointermove'));
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
|
||||
@@ -19,29 +19,29 @@
|
||||
});
|
||||
|
||||
suite('shouldHandleTouch', function() {
|
||||
test('handles mousedown event', function() {
|
||||
const mouseEvent = new MouseEvent('mousedown');
|
||||
chai.assert.isTrue(Blockly.Touch.shouldHandleEvent(mouseEvent));
|
||||
test('handles pointerdown event', function() {
|
||||
const pointerEvent = new PointerEvent('pointerdown');
|
||||
chai.assert.isTrue(Blockly.Touch.shouldHandleEvent(pointerEvent));
|
||||
});
|
||||
|
||||
test('handles multiple mousedown events', function() {
|
||||
const mouseEvent1 = new MouseEvent('mousedown');
|
||||
const mouseEvent2 = new MouseEvent('mousedown');
|
||||
Blockly.Touch.shouldHandleEvent(mouseEvent1);
|
||||
chai.assert.isTrue(Blockly.Touch.shouldHandleEvent(mouseEvent2));
|
||||
test('handles multiple pointerdown events', function() {
|
||||
const pointerEvent1 = new PointerEvent('pointerdown');
|
||||
const pointerEvent2 = new PointerEvent('pointerdown');
|
||||
Blockly.Touch.shouldHandleEvent(pointerEvent1);
|
||||
chai.assert.isTrue(Blockly.Touch.shouldHandleEvent(pointerEvent2));
|
||||
});
|
||||
|
||||
test('does not handle mouseup if not tracking touch', function() {
|
||||
const mouseEvent = new MouseEvent('mouseup');
|
||||
chai.assert.isFalse(Blockly.Touch.shouldHandleEvent(mouseEvent));
|
||||
test('does not handle pointerup if not tracking touch', function() {
|
||||
const pointerEvent = new PointerEvent('pointerup');
|
||||
chai.assert.isFalse(Blockly.Touch.shouldHandleEvent(pointerEvent));
|
||||
});
|
||||
|
||||
test('handles mouseup if already tracking a touch', function() {
|
||||
const mousedown = new MouseEvent('mousedown');
|
||||
const mouseup = new MouseEvent('mouseup');
|
||||
// Register the mousedown event first
|
||||
Blockly.Touch.shouldHandleEvent(mousedown);
|
||||
chai.assert.isTrue(Blockly.Touch.shouldHandleEvent(mouseup));
|
||||
test('handles pointerup if already tracking a touch', function() {
|
||||
const pointerdown = new PointerEvent('pointerdown');
|
||||
const pointerup = new PointerEvent('pointerup');
|
||||
// Register the pointerdown event first
|
||||
Blockly.Touch.shouldHandleEvent(pointerdown);
|
||||
chai.assert.isTrue(Blockly.Touch.shouldHandleEvent(pointerup));
|
||||
});
|
||||
|
||||
test('handles pointerdown if this is a new touch', function() {
|
||||
@@ -56,13 +56,6 @@
|
||||
chai.assert.isFalse(Blockly.Touch.shouldHandleEvent(pointerdown2));
|
||||
});
|
||||
|
||||
test('does not handle pointerdown after a mousedown', function() {
|
||||
const mouseEvent = new MouseEvent('mousedown');
|
||||
const pointerdown = new PointerEvent('pointerdown', {pointerId: 1, pointerType: 'touch'});
|
||||
Blockly.Touch.shouldHandleEvent(mouseEvent);
|
||||
chai.assert.isFalse(Blockly.Touch.shouldHandleEvent(pointerdown));
|
||||
});
|
||||
|
||||
test('does not handle pointerup if not tracking touch', function() {
|
||||
const pointerup = new PointerEvent('pointerup', {pointerId: 1, pointerType: 'touch'});
|
||||
chai.assert.isFalse(Blockly.Touch.shouldHandleEvent(pointerup));
|
||||
@@ -77,11 +70,6 @@
|
||||
});
|
||||
|
||||
suite('getTouchIdentifierFromEvent', function() {
|
||||
test('is mouse for MouseEvents', function() {
|
||||
const mousedown = new MouseEvent('mousedown');
|
||||
chai.assert.equal(Blockly.Touch.getTouchIdentifierFromEvent(mousedown), 'mouse');
|
||||
});
|
||||
|
||||
test('is pointerId for mouse PointerEvents', function() {
|
||||
const pointerdown = new PointerEvent('pointerdown', {pointerId: 7, pointerType: 'mouse'});
|
||||
chai.assert.equal(Blockly.Touch.getTouchIdentifierFromEvent(pointerdown), 7);
|
||||
|
||||
Reference in New Issue
Block a user