browser(firefox): send dragend after drop and survive navigations (#4506)

This commit is contained in:
Joel Einbinder 2020-11-25 03:47:34 -08:00 committed by GitHub
parent c6d5bc3081
commit d06afadb8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 28 deletions

View File

@ -1,2 +1,2 @@
1214 1215
Changed: lushnikov@chromium.org Mon 23 Nov 2020 04:14:36 PM PST Changed: joel.einbinder@gmail.com Wed 25 Nov 2020 03:31:22 AM PST

View File

@ -125,7 +125,7 @@ class PageAgent {
this._docShell = docShell; this._docShell = docShell;
this._initialDPPX = docShell.contentViewer.overrideDPPX; this._initialDPPX = docShell.contentViewer.overrideDPPX;
this._customScrollbars = null; this._customScrollbars = null;
this._dataTransfer = null; this._dragging = false;
// Dispatch frameAttached events for all initial frames // Dispatch frameAttached events for all initial frames
for (const frame of this._frameTree.frames()) { for (const frame of this._frameTree.frames()) {
@ -663,7 +663,7 @@ class PageAgent {
async _dispatchKeyEvent({type, keyCode, code, key, repeat, location, text}) { async _dispatchKeyEvent({type, keyCode, code, key, repeat, location, text}) {
// key events don't fire if we are dragging. // key events don't fire if we are dragging.
if (this._dataTransfer) { if (this._dragging) {
if (type === 'keydown' && key === 'Escape') if (type === 'keydown' && key === 'Escape')
this._cancelDragIfNeeded(); this._cancelDragIfNeeded();
return; return;
@ -817,7 +817,7 @@ class PageAgent {
modifiers & 8 /* metaKey */, modifiers & 8 /* metaKey */,
0 /* button */, // firefox always has the button as 0 on drops, regardless of which was pressed 0 /* button */, // firefox always has the button as 0 on drops, regardless of which was pressed
null /* relatedTarget */, null /* relatedTarget */,
this._dataTransfer dragService.getCurrentSession().dataTransfer.mozCloneForEvent(type)
); );
window.windowUtils.dispatchDOMEventViaPresShellForTesting(element, event); window.windowUtils.dispatchDOMEventViaPresShellForTesting(element, event);
@ -826,18 +826,20 @@ class PageAgent {
} }
_cancelDragIfNeeded() { _cancelDragIfNeeded() {
this._dataTransfer = null; this._dragging = false;
const sess = dragService.getCurrentSession(); const sess = dragService.getCurrentSession();
if (sess) if (sess)
dragService.endDragSession(false); dragService.endDragSession(true);
} }
async _dispatchMouseEvent({type, x, y, button, clickCount, modifiers, buttons}) { async _dispatchMouseEvent({type, x, y, button, clickCount, modifiers, buttons}) {
this._startDragSessionIfNeeded(); this._startDragSessionIfNeeded();
const trapDrag = subject => { const trapDrag = subject => {
this._dataTransfer = subject.mozCloneForEvent('drop'); this._dragging = true;
} }
// Don't send mouse events if there is an active drag
if (!this._dragging) {
const frame = this._frameTree.mainFrame(); const frame = this._frameTree.mainFrame();
obs.addObserver(trapDrag, 'on-datatransfer-available'); obs.addObserver(trapDrag, 'on-datatransfer-available');
@ -871,9 +873,10 @@ class PageAgent {
undefined /*isWidgetEventSynthesized*/, undefined /*isWidgetEventSynthesized*/,
buttons); buttons);
} }
}
// update drag state // update drag state
if (this._dataTransfer) { if (this._dragging) {
if (type === 'mousemove') if (type === 'mousemove')
this._simulateDragEvent('dragover', x, y, modifiers); this._simulateDragEvent('dragover', x, y, modifiers);
else if (type === 'mouseup') // firefox will do drops when any mouse button is released else if (type === 'mouseup') // firefox will do drops when any mouse button is released