From ddab4d65a2784c5f942a04450d516ceb1c95b1ef Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 6 Mar 2018 14:04:49 -0800 Subject: [PATCH] Don't take parent in webview ctor --- .../parts/extensions/browser/extensionEditor.ts | 3 ++- .../parts/html/browser/htmlPreviewPart.ts | 2 +- src/vs/workbench/parts/html/browser/webview.ts | 16 +++++++++------- .../webview/electron-browser/webviewEditor.ts | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts index 2ff081caed9..a025a7cb8b6 100644 --- a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts +++ b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts @@ -426,7 +426,8 @@ export class ExtensionEditor extends BaseEditor { .then(body => { const allowedBadgeProviders = this.extensionsWorkbenchService.allowedBadgeProviders; const webViewOptions = allowedBadgeProviders.length > 0 ? { allowScripts: false, allowSvgs: false, svgWhiteList: allowedBadgeProviders } : {}; - this.activeWebview = new Webview(this.content, this.partService.getContainer(Parts.EDITOR_PART), this.themeService, this.environmentService, this.contextViewService, this.contextKey, this.findInputFocusContextKey, webViewOptions); + this.activeWebview = new Webview(this.partService.getContainer(Parts.EDITOR_PART), this.themeService, this.environmentService, this.contextViewService, this.contextKey, this.findInputFocusContextKey, webViewOptions); + this.activeWebview.mountTo(this.content); const removeLayoutParticipant = arrays.insert(this.layoutParticipants, this.activeWebview); this.contentDisposables.push(toDisposable(removeLayoutParticipant)); this.activeWebview.contents = body; diff --git a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts index deae182e531..a1bce8f5e1f 100644 --- a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts +++ b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts @@ -93,7 +93,6 @@ export class HtmlPreviewPart extends BaseWebviewEditor { } this._webview = new Webview( - this.content, this.partService.getContainer(Parts.EDITOR_PART), this.themeService, this._environmentService, @@ -104,6 +103,7 @@ export class HtmlPreviewPart extends BaseWebviewEditor { ...webviewOptions, useSameOriginForRoot: true }); + this._webview.mountTo(this.content); if (this.input && this.input instanceof HtmlInput) { const state = this.loadViewState(this.input.getResource()); diff --git a/src/vs/workbench/parts/html/browser/webview.ts b/src/vs/workbench/parts/html/browser/webview.ts index 00669ce6dad..33a00e419d3 100644 --- a/src/vs/workbench/parts/html/browser/webview.ts +++ b/src/vs/workbench/parts/html/browser/webview.ts @@ -37,7 +37,6 @@ export class Webview { private _contents: string = ''; constructor( - private readonly parent: HTMLElement, private readonly _styleElement: Element, private readonly _themeService: IThemeService, private readonly _environmentService: IEnvironmentService, @@ -180,11 +179,11 @@ export class Webview { this.style(this._themeService.getTheme()); this._themeService.onThemeChange(this.style, this, this._disposables); + } - if (parent) { - parent.appendChild(this._webviewFindWidget.getDomNode()); - parent.appendChild(this._webview); - } + public mountTo(parent: HTMLElement) { + parent.appendChild(this._webviewFindWidget.getDomNode()); + parent.appendChild(this._webview); } public notifyFindWidgetFocusChanged(isFocused: boolean) { @@ -293,9 +292,12 @@ export class Webview { } contents.setZoomFactor(factor); + if (!this._webview || !this._webview.parentElement) { + return; + } - const width = this.parent.clientWidth; - const height = this.parent.clientHeight; + const width = this._webview.parentElement.clientWidth; + const height = this._webview.parentElement.clientHeight; contents.setSize({ normal: { width: Math.floor(width * factor), diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts index 685a91c94db..7cdd29a490d 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts @@ -191,7 +191,6 @@ export class WebviewEditor extends BaseWebviewEditor { this.findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(this._contextKeyService); this._webview = new Webview( - this.webviewContent, this._partService.getContainer(Parts.EDITOR_PART), this.themeService, this._environmentService, @@ -202,6 +201,7 @@ export class WebviewEditor extends BaseWebviewEditor { enableWrappedPostMessage: true, useSameOriginForRoot: false }); + this._webview.mountTo(this.webviewContent); input.webview = this._webview; if (input.options.tryRestoreScrollPosition) { -- GitLab