Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/vs/workbench/parts/extensions/browser/extensionEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ export class ExtensionEditor extends BaseEditor {
.then(renderBody)
.then<void>(body => {
const webview = new WebView(this.content, this.partService.getContainer(Parts.EDITOR_PART));
const removeLayoutParticipant = arrays.insert(this.layoutParticipants, webview);
this.contentDisposables.push(toDisposable(removeLayoutParticipant));

webview.style(this.themeService.getTheme());
webview.contents = [body];

Expand Down
4 changes: 3 additions & 1 deletion src/vs/workbench/parts/html/browser/htmlPreviewPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ export class HtmlPreviewPart extends BaseEditor {

public layout(dimension: Dimension): void {
const {width, height} = dimension;
// we take the padding we set on create into account
this._container.style.width = `${width}px`;
this._container.style.height = `${height}px`;
if (this._webview) {
this._webview.layout();
}
}

public focus(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/html/browser/webview.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" style="width: 100%; height: 100%">
<head>
<title>Virtual Document</title>
</head>
Expand Down
26 changes: 24 additions & 2 deletions src/vs/workbench/parts/html/browser/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ export default class Webview {
private _onDidClickLink = new Emitter<URI>();
private _onDidLoadContent = new Emitter<{ stats: any }>();

constructor(parent: HTMLElement, private _styleElement: Element) {
constructor(
private parent: HTMLElement,
private _styleElement: Element
) {
this._webview = <any>document.createElement('webview');

this._webview.style.width = '100%';
this._webview.style.height = '100%';
this._webview.style.outline = '0';
this._webview.style.opacity = '0';
this._webview.autoSize = 'on';
this._webview.contextIsolation = true;

// disable auxclick events (see https://developers.google.com/web/updates/2016/10/auxclick)
Expand Down Expand Up @@ -99,6 +101,7 @@ export default class Webview {
this._webview.style.opacity = '';
let [stats] = event.args;
this._onDidLoadContent.fire({ stats });
this.layout();
return;
}
})
Expand Down Expand Up @@ -235,4 +238,23 @@ export default class Webview {

this._send('styles', value, activeTheme);
}

public layout(): void {
const contents = (this._webview as any).getWebContents();
if (!contents) {
return;
}

const width = this.parent.clientWidth;
const height = this.parent.clientHeight;

contents.getZoomFactor(factor => {
contents.setSize({
normal: {
width: Math.floor(width * factor),
height: Math.floor(height * factor)
}
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export class ReleaseNotesEditor extends BaseEditor {
}

layout(): void {
// noop
if (this.webview) {
this.webview.layout();
}
}

focus(): void {
Expand Down