Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
f111fei authored Jul 6, 2016
1 parent a620fa8 commit 36a8dcd
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/vs/workbench/parts/html/browser/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {addDisposableListener, addClass} from 'vs/base/browser/dom';
import {addDisposableListener, addClass, EventType} from 'vs/base/browser/dom';
import {isLightTheme, isDarkTheme} from 'vs/platform/theme/common/themes';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';

declare interface WebviewElement extends HTMLElement {
src: string;
Expand Down Expand Up @@ -45,14 +47,27 @@ KeybindingsRegistry.registerCommandDesc({

type ApiThemeClassName = 'vscode-light' | 'vscode-dark' | 'vscode-high-contrast';

function isDefaultKeyboardEvent(e: KeyboardEvent): boolean {
let keyEvent = new StandardKeyboardEvent(e);
let keybinding = keyEvent.asKeybinding();
switch (keybinding) {
case KeyMod.CtrlCmd | KeyCode.KEY_C:
case KeyMod.CtrlCmd | KeyCode.KEY_V:
case KeyMod.CtrlCmd | KeyCode.KEY_X:
case KeyMod.CtrlCmd | KeyCode.KEY_A:
return true;
}
return false;
}

export default class Webview {

private _webview: WebviewElement;
private _ready: TPromise<this>;
private _disposables: IDisposable[];

constructor(private _parent: HTMLElement, private _styleElement: Element, onDidClickLink:(uri:URI)=>any) {
this._webview = <any>document.createElement('webview');
constructor(private _parent: HTMLElement, private _styleElement: Element, onDidClickLink: (uri: URI) => any) {
this._webview = <WebviewElement>document.createElement('webview');

this._webview.style.width = '100%';
this._webview.style.height = '100%';
Expand Down Expand Up @@ -93,6 +108,17 @@ export default class Webview {
this._webview.style.opacity = '';
return;
}
}),
addDisposableListener(this._webview, EventType.KEY_DOWN, (event: KeyboardEvent) => {
if (isDefaultKeyboardEvent(event)) {
event.stopImmediatePropagation();
}
}),
addDisposableListener(this._webview, EventType.DRAG_OVER, (event: DragEvent) => {
event.stopImmediatePropagation();
}),
addDisposableListener(this._webview, EventType.DROP, (event: DragEvent) => {
event.stopImmediatePropagation();
})
];

Expand Down Expand Up @@ -174,7 +200,7 @@ export default class Webview {

activeTheme = 'vscode-light';

} else if (isDarkTheme(themeId)){
} else if (isDarkTheme(themeId)) {
value += `
::-webkit-scrollbar-thumb {
background-color: rgba(121, 121, 121, 0.4);
Expand Down

0 comments on commit 36a8dcd

Please sign in to comment.