提交 c7da9389 编写于 作者: M Matt Bierner

Move theme change logic into webview itself

上级 cc3f1aad
......@@ -204,7 +204,6 @@ class WebviewEditor extends BaseWebviewEditor {
enableWrappedPostMessage: true
};
this.webview.contents = input.html;
this.webview.style(this.themeService.getTheme());
}
private get webview(): Webview {
......@@ -214,6 +213,7 @@ class WebviewEditor extends BaseWebviewEditor {
this._webview = new Webview(
this.webviewContent,
this._partService.getContainer(Parts.EDITOR_PART),
this.themeService,
this._environmentService,
this._contextService,
this._contextViewService,
......@@ -223,17 +223,9 @@ class WebviewEditor extends BaseWebviewEditor {
enableWrappedPostMessage: true
},
false);
this.webview.style(this.themeService.getTheme());
this._webview.onDidClickLink(this.onDidClickLink, this, this._contentDisposables);
this.themeService.onThemeChange(theme => {
if (this._webview) {
this._webview.style(theme);
}
}, null, this._contentDisposables);
this._webview.onMessage(message => {
if (this.input) {
(this.input as WebviewInput).events.onMessage(message);
......
......@@ -421,11 +421,9 @@ export class ExtensionEditor extends BaseEditor {
.then<void>(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.environmentService, this.contextService, this.contextViewService, this.contextKey, this.findInputFocusContextKey, webViewOptions, false);
this.activeWebview = new Webview(this.content, this.partService.getContainer(Parts.EDITOR_PART), this.themeService, this.environmentService, this.contextService, this.contextViewService, this.contextKey, this.findInputFocusContextKey, webViewOptions, false);
const removeLayoutParticipant = arrays.insert(this.layoutParticipants, this.activeWebview);
this.contentDisposables.push(toDisposable(removeLayoutParticipant));
this.activeWebview.style(this.themeService.getTheme());
this.activeWebview.contents = body;
this.activeWebview.onDidClickLink(link => {
......@@ -434,7 +432,6 @@ export class ExtensionEditor extends BaseEditor {
this.openerService.open(link);
}
}, null, this.contentDisposables);
this.themeService.onThemeChange(theme => this.activeWebview.style(theme), null, this.contentDisposables);
this.contentDisposables.push(this.activeWebview);
})
.then(null, () => {
......
......@@ -91,6 +91,7 @@ export class HtmlPreviewPart extends WebviewEditor {
this._webview = new Webview(
this.content,
this.partService.getContainer(Parts.EDITOR_PART),
this.themeService,
this._environmentService,
this._contextService,
this._contextViewService,
......@@ -107,7 +108,6 @@ export class HtmlPreviewPart extends WebviewEditor {
const resourceUri = this.input.getResource();
this.webview.baseUrl = resourceUri.toString(true);
}
this._webview.style(this.themeService.getTheme());
this._webviewDisposables = [
this._webview,
this._webview.onDidClickLink(uri => this.openerService.open(uri)),
......
......@@ -10,7 +10,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import Event, { Emitter } from 'vs/base/common/event';
import { addDisposableListener, addClass } from 'vs/base/browser/dom';
import { editorBackground, editorForeground, textLinkForeground } from 'vs/platform/theme/common/colorRegistry';
import { ITheme, LIGHT, DARK } from 'vs/platform/theme/common/themeService';
import { ITheme, LIGHT, DARK, IThemeService } from 'vs/platform/theme/common/themeService';
import { WebviewFindWidget } from './webviewFindWidget';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
......@@ -38,6 +38,7 @@ export class Webview {
constructor(
private readonly parent: HTMLElement,
private readonly _styleElement: Element,
private readonly _themeService: IThemeService,
private readonly _environmentService: IEnvironmentService,
private readonly _contextService: IWorkspaceContextService,
private readonly _contextViewService: IContextViewService,
......@@ -178,6 +179,9 @@ export class Webview {
this._webviewFindWidget = new WebviewFindWidget(this._contextViewService, this);
this._disposables.push(this._webviewFindWidget);
this.style(this._themeService.getTheme());
this._themeService.onThemeChange(this.style, this, this._disposables);
if (parent) {
parent.appendChild(this._webviewFindWidget.getDomNode());
parent.appendChild(this._webview);
......@@ -257,7 +261,7 @@ export class Webview {
});
}
style(theme: ITheme): void {
private style(theme: ITheme): void {
const { fontFamily, fontWeight, fontSize } = window.getComputedStyle(this._styleElement); // TODO@theme avoid styleElement
const styles = {
......
......@@ -74,13 +74,6 @@ export abstract class WebviewEditor extends BaseWebviewEditor {
}
}
public updateStyles() {
super.updateStyles();
if (this._webview) {
this._webview.style(this.themeService.getTheme());
}
}
public get isWebviewEditor() {
return true;
}
......
......@@ -91,6 +91,7 @@ export class ReleaseNotesEditor extends WebviewEditor {
this._webview = new Webview(
this.content,
this.partService.getContainer(Parts.EDITOR_PART),
this.themeService,
this.environmentService,
this._contextService,
this._contextViewService,
......@@ -105,7 +106,6 @@ export class ReleaseNotesEditor extends WebviewEditor {
this._webview.initialScrollProgress = state.scrollYPercentage;
}
}
this._webview.style(this.themeService.getTheme());
this._webview.contents = body;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册