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

Move theme change logic into webview itself

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