Skip to content

Commit 43b505a

Browse files
committed
chore: remove custom drag&drop implementation for chromium
1 parent df0e0fb commit 43b505a

File tree

4 files changed

+38
-193
lines changed

4 files changed

+38
-193
lines changed

packages/playwright-core/src/server/chromium/crDragDrop.ts

Lines changed: 0 additions & 140 deletions
This file was deleted.

packages/playwright-core/src/server/chromium/crInput.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ import { toButtonsMask, toModifiersMask } from './crProtocolHelper';
2222

2323
import type * as types from '../types';
2424
import type { CRSession } from './crConnection';
25-
import type { DragManager } from './crDragDrop';
2625
import type { CRPage } from './crPage';
2726

2827

2928
export class RawKeyboardImpl implements input.RawKeyboard {
3029
constructor(
3130
private _client: CRSession,
3231
private _isMac: boolean,
33-
private _dragManger: DragManager,
3432
) { }
3533

3634
_commandsForCode(code: string, modifiers: Set<types.KeyboardModifier>) {
@@ -54,8 +52,8 @@ export class RawKeyboardImpl implements input.RawKeyboard {
5452

5553
async keydown(modifiers: Set<types.KeyboardModifier>, keyName: string, description: input.KeyDescription, autoRepeat: boolean): Promise<void> {
5654
const { code, key, location, text } = description;
57-
if (code === 'Escape' && await this._dragManger.cancelDrag())
58-
return;
55+
if (code === 'Escape')
56+
await this._client.send('Input.cancelDragging', {});
5957
const commands = this._commandsForCode(code, modifiers);
6058
await this._client.send('Input.dispatchKeyEvent', {
6159
type: text ? 'keyDown' : 'rawKeyDown',
@@ -92,37 +90,25 @@ export class RawKeyboardImpl implements input.RawKeyboard {
9290
export class RawMouseImpl implements input.RawMouse {
9391
private _client: CRSession;
9492
private _page: CRPage;
95-
private _dragManager: DragManager;
9693

97-
constructor(page: CRPage, client: CRSession, dragManager: DragManager) {
94+
constructor(page: CRPage, client: CRSession) {
9895
this._page = page;
9996
this._client = client;
100-
this._dragManager = dragManager;
10197
}
10298

10399
async move(x: number, y: number, button: types.MouseButton | 'none', buttons: Set<types.MouseButton>, modifiers: Set<types.KeyboardModifier>, forClick: boolean): Promise<void> {
104-
const actualMove = async () => {
105-
await this._client.send('Input.dispatchMouseEvent', {
106-
type: 'mouseMoved',
107-
button,
108-
buttons: toButtonsMask(buttons),
109-
x,
110-
y,
111-
modifiers: toModifiersMask(modifiers),
112-
force: buttons.size > 0 ? 0.5 : 0,
113-
});
114-
};
115-
if (forClick) {
116-
// Avoid extra protocol calls related to drag and drop, because click relies on
117-
// move-down-up protocol commands being sent synchronously.
118-
return actualMove();
119-
}
120-
await this._dragManager.interceptDragCausedByMove(x, y, button, buttons, modifiers, actualMove);
100+
await this._client.send('Input.dispatchMouseEvent', {
101+
type: 'mouseMoved',
102+
button,
103+
buttons: toButtonsMask(buttons),
104+
x,
105+
y,
106+
modifiers: toModifiersMask(modifiers),
107+
force: buttons.size > 0 ? 0.5 : 0,
108+
});
121109
}
122110

123111
async down(x: number, y: number, button: types.MouseButton, buttons: Set<types.MouseButton>, modifiers: Set<types.KeyboardModifier>, clickCount: number): Promise<void> {
124-
if (this._dragManager.isDragging())
125-
return;
126112
await this._client.send('Input.dispatchMouseEvent', {
127113
type: 'mousePressed',
128114
button,
@@ -136,10 +122,6 @@ export class RawMouseImpl implements input.RawMouse {
136122
}
137123

138124
async up(x: number, y: number, button: types.MouseButton, buttons: Set<types.MouseButton>, modifiers: Set<types.KeyboardModifier>, clickCount: number): Promise<void> {
139-
if (this._dragManager.isDragging()) {
140-
await this._dragManager.drop(x, y, modifiers);
141-
return;
142-
}
143125
await this._client.send('Input.dispatchMouseEvent', {
144126
type: 'mouseReleased',
145127
button,

packages/playwright-core/src/server/chromium/crPage.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { registry } from '../registry';
3131
import { getAccessibilityTree } from './crAccessibility';
3232
import { CRBrowserContext } from './crBrowser';
3333
import { CRCoverage } from './crCoverage';
34-
import { DragManager } from './crDragDrop';
3534
import { createHandle, CRExecutionContext } from './crExecutionContext';
3635
import { RawKeyboardImpl, RawMouseImpl, RawTouchscreenImpl } from './crInput';
3736
import { CRNetworkManager } from './crNetworkManager';
@@ -86,9 +85,8 @@ export class CRPage implements PageDelegate {
8685
this._targetId = targetId;
8786
this._opener = opener;
8887
this._isBackgroundPage = bits.isBackgroundPage;
89-
const dragManager = new DragManager(this);
90-
this.rawKeyboard = new RawKeyboardImpl(client, browserContext._browser._platform() === 'mac', dragManager);
91-
this.rawMouse = new RawMouseImpl(this, client, dragManager);
88+
this.rawKeyboard = new RawKeyboardImpl(client, browserContext._browser._platform() === 'mac');
89+
this.rawMouse = new RawMouseImpl(this, client);
9290
this.rawTouchscreen = new RawTouchscreenImpl(client);
9391
this._pdf = new CRPDF(client);
9492
this._coverage = new CRCoverage(client);

tests/page/page-drag.spec.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ it.describe('Drag and drop', () => {
5353
]);
5454
});
5555

56-
it('should not send dragover on the first mousemove', async ({ server, page, browserName }) => {
57-
it.fixme(browserName !== 'chromium');
58-
56+
it.fixme('should not send dragover on the first mousemove', async ({ server, page, browserName }) => {
5957
await page.goto(server.PREFIX + '/drag-n-drop.html');
6058
const events = await trackEvents(await page.$('body'));
6159
await page.hover('#source');
@@ -115,14 +113,15 @@ it.describe('Drag and drop', () => {
115113
browserName === 'firefox' ? 'dragstart at 120;86' : 'mousemove at 240;350',
116114
browserName === 'firefox' ? 'mousemove at 240;350' : 'dragstart at 120;86',
117115
'dragenter at 240;350',
118-
browserName === 'chromium' ? null : 'dragover at 240;350',
116+
'dragover at 240;350',
117+
browserName === 'chromium' ? 'dragleave at 240;350' : null,
119118
'dragend',
120119
'mouseup at 240;350',
121120
].filter(Boolean));
122121
});
123122

124123
it.describe('iframe', () => {
125-
it.fixme(true, 'implement dragging with iframes');
124+
it.fixme(({ browserName }) => browserName !== 'chromium', 'iframes dragging is not implemented');
126125

127126
it('should drag into an iframe', async ({ server, page, browserName }) => {
128127
await page.goto(server.PREFIX + '/drag-n-drop.html');
@@ -133,7 +132,6 @@ it.describe('Drag and drop', () => {
133132
iframe.style.marginLeft = '500px';
134133
iframe.style.marginTop = '60px';
135134
});
136-
await page.waitForTimeout(5000);
137135
const pageEvents = await trackEvents(await page.$('body'));
138136
const frameEvents = await trackEvents(await frame.$('body'));
139137
await page.hover('#source');
@@ -142,21 +140,28 @@ it.describe('Drag and drop', () => {
142140
await page.mouse.up();
143141
expect(await frame.$eval('#target', target => target.contains(document.querySelector('#source')))).toBe(true); // could not find source in target
144142
expect(await pageEvents.jsonValue()).toEqual([
145-
'mousemove',
146-
'mousedown',
147-
browserName === 'firefox' ? 'dragstart' : 'mousemove',
148-
browserName === 'firefox' ? 'mousemove' : 'dragstart',
143+
'mousemove at 120;86',
144+
'mousedown at 120;86',
145+
'mousemove at 742;412',
146+
'dragstart at 120;86',
147+
'dragend',
149148
]);
150149
expect(await frameEvents.jsonValue()).toEqual([
151-
'dragenter',
152-
'dragover',
153-
'drop',
150+
'dragenter at 240;350',
151+
'dragover at 240;350',
152+
'drop at 240;350',
154153
]);
155154
});
156155

157156
it('should drag out of an iframe', async ({ server, page }) => {
158157
await page.goto(server.PREFIX + '/drag-n-drop.html');
159158
const frame = await attachFrame(page, 'oopif', server.PREFIX + '/drag-n-drop.html');
159+
await page.$eval('iframe', iframe => {
160+
iframe.style.width = '500px';
161+
iframe.style.height = '600px';
162+
iframe.style.marginLeft = '500px';
163+
iframe.style.marginTop = '60px';
164+
});
160165
const pageEvents = await trackEvents(await page.$('body'));
161166
const frameEvents = await trackEvents(await frame.$('body'));
162167
await frame.hover('#source');
@@ -165,15 +170,15 @@ it.describe('Drag and drop', () => {
165170
await page.mouse.up();
166171
expect(await page.$eval('#target', target => target.contains(document.querySelector('#source')))).toBe(true); // could not find source in target
167172
expect(await frameEvents.jsonValue()).toEqual([
168-
'mousemove',
169-
'mousedown',
170-
'dragstart',
173+
'mousemove at 120;86',
174+
'mousedown at 120;86',
175+
'dragstart at 120;86',
171176
'dragend',
172177
]);
173178
expect(await pageEvents.jsonValue()).toEqual([
174-
'dragenter',
175-
'dragover',
176-
'drop',
179+
'dragenter at 240;350',
180+
'dragover at 240;350',
181+
'drop at 240;350',
177182
]);
178183
});
179184
});

0 commit comments

Comments
 (0)