Skip to content

Commit

Permalink
Revert "Fixes microsoft#182449 : Pressing Shift re-enables webview du…
Browse files Browse the repository at this point in the history
…ring Drag and Drop Events (microsoft#209211)" (microsoft#225000)

This reverts commit 51917e8.
  • Loading branch information
mjbvz authored and zongou committed Aug 13, 2024
1 parent 46c9888 commit 2ea1686
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 64 deletions.
22 changes: 3 additions & 19 deletions src/vs/workbench/contrib/webview/browser/pre/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<meta charset="UTF-8">

<meta http-equiv="Content-Security-Policy"

content="default-src 'none'; script-src 'sha256-ikaxwm2UFoiIKkEZTEU4mnSxpYf3lmsrhy5KqqJZfek=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">

content="default-src 'none'; script-src 'sha256-dvxt5dlghGbz8hrqqochfoKEaHIMZ+yJVRvjJnGopzs=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">

<!-- Disable pinch zooming -->
<meta name="viewport"
Expand Down Expand Up @@ -797,17 +795,6 @@
}
}


function handleInnerDragEvent(/** @type {DragEvent} */ e) {
if (!e.dataTransfer) {
return;
}

hostMessaging.postMessage('drag', {
shiftKey: e.shiftKey
});
}

/**
* @param {() => void} callback
*/
Expand Down Expand Up @@ -898,9 +885,7 @@
window.addEventListener('keydown', handleInnerKeydown);
window.addEventListener('keyup', handleInnerKeyup);
window.addEventListener('dragenter', handleInnerDragStartEvent);
window.addEventListener('dragover', handleInnerDragEvent);
window.addEventListener('drag', handleInnerDragEvent);

window.addEventListener('dragover', handleInnerDragStartEvent);

onDomReady(() => {
if (!document.body) {
Expand Down Expand Up @@ -1182,8 +1167,7 @@
});

contentWindow.addEventListener('dragenter', handleInnerDragStartEvent);
contentWindow.addEventListener('dragover', handleInnerDragEvent);
contentWindow.addEventListener('drag', handleInnerDragEvent);
contentWindow.addEventListener('dragover', handleInnerDragStartEvent);

unloadMonitor.onIframeLoaded(newFrame);
}
Expand Down
17 changes: 1 addition & 16 deletions src/vs/workbench/contrib/webview/browser/webviewElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { loadLocalResource, WebviewResourceResponse } from 'vs/workbench/contrib
import { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/browser/themeing';
import { areWebviewContentOptionsEqual, IWebview, WebviewContentOptions, WebviewExtensionDescription, WebviewInitInfo, WebviewMessageReceivedEvent, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewFindDelegate, WebviewFindWidget } from 'vs/workbench/contrib/webview/browser/webviewFindWidget';
import { FromWebviewMessage, KeyEvent, ToWebviewMessage, WebViewDragEvent } from 'vs/workbench/contrib/webview/browser/webviewMessages';
import { FromWebviewMessage, KeyEvent, ToWebviewMessage } from 'vs/workbench/contrib/webview/browser/webviewMessages';
import { decodeAuthority, webviewGenericCspSource, webviewRootResourceAuthority } from 'vs/workbench/contrib/webview/common/webview';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { CodeWindow } from 'vs/base/browser/window';
Expand Down Expand Up @@ -310,10 +310,6 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this._startBlockingIframeDragEvents();
}));

this._register(this.on('drag', (event) => {
this.handleDragEvent('drag', event);
}));

if (initInfo.options.enableFindWidget) {
this._webviewFindWidget = this._register(instantiationService.createInstance(WebviewFindWidget, this));
}
Expand Down Expand Up @@ -701,17 +697,6 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this.window?.dispatchEvent(emulatedKeyboardEvent);
}

private handleDragEvent(type: 'drag', event: WebViewDragEvent) {
// Create a fake DragEvent from the data provided
const emulatedDragEvent = new DragEvent(type, event);
// Force override the target
Object.defineProperty(emulatedDragEvent, 'target', {
get: () => this.element,
});
// And re-dispatch
this.window?.dispatchEvent(emulatedDragEvent);
}

windowDidDragStart(): void {
// Webview break drag and dropping around the main window (no events are generated when you are over them)
// Work around this by disabling pointer events during the drag.
Expand Down
5 changes: 0 additions & 5 deletions src/vs/workbench/contrib/webview/browser/webviewMessages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ type KeyEvent = {
repeat: boolean;
}

type WebViewDragEvent = {
shiftKey: boolean;
}

export type FromWebviewMessage = {
'onmessage': { message: any; transfer?: ArrayBuffer[] };
'did-click-link': { uri: string };
Expand All @@ -40,7 +36,6 @@ export type FromWebviewMessage = {
'did-keyup': KeyEvent;
'did-context-menu': { clientX: number; clientY: number; context: { [key: string]: unknown } };
'drag-start': void;
'drag': WebViewDragEvent
};

interface UpdateContentEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,19 @@ export class WebviewWindowDragMonitor extends Disposable {
constructor(targetWindow: CodeWindow, getWebview: () => IWebview | undefined) {
super();

const onDragStart = () => {
this._register(DOM.addDisposableListener(targetWindow, DOM.EventType.DRAG_START, () => {
getWebview()?.windowDidDragStart();
};
}));

const onDragEnd = () => {
getWebview()?.windowDidDragEnd();
};

this._register(DOM.addDisposableListener(targetWindow, DOM.EventType.DRAG_START, () => {
onDragStart();
}));

this._register(DOM.addDisposableListener(targetWindow, DOM.EventType.DRAG_END, onDragEnd));

this._register(DOM.addDisposableListener(targetWindow, DOM.EventType.MOUSE_MOVE, currentEvent => {
if (currentEvent.buttons === 0) {
onDragEnd();
}
}));

this._register(DOM.addDisposableListener(targetWindow, DOM.EventType.DRAG, (event) => {
if (event.shiftKey) {
onDragEnd();
} else {
onDragStart();
}
}));

this._register(DOM.addDisposableListener(targetWindow, DOM.EventType.DRAG_OVER, (event) => {
if (event.shiftKey) {
onDragEnd();
} else {
onDragStart();
}
}));

}
}

0 comments on commit 2ea1686

Please sign in to comment.