Fix a webview initial zoom possibly being incorrect

This commit is contained in:
Matt Bierner 2017-04-12 17:56:36 -07:00
parent 8d3f2bf45b
commit d1b315f030

View file

@ -67,14 +67,14 @@ export default class Webview {
// disable auxclick events (see https://developers.google.com/web/updates/2016/10/auxclick)
this._webview.setAttribute('disableblinkfeatures', 'Auxclick');
this._webview.setAttribute('disableguestresize', '');
this._webview.preload = require.toUrl('./webview-pre.js');
this._webview.src = require.toUrl('./webview.html');
this._ready = new TPromise<this>(resolve => {
const subscription = addDisposableListener(this._webview, 'ipc-message', (event) => {
if (event.channel === 'webview-ready') {
this.layout();
// console.info('[PID Webview] ' + event.args[0]);
addClass(this._webview, 'ready'); // can be found by debug command
@ -88,6 +88,9 @@ export default class Webview {
addDisposableListener(this._webview, 'console-message', function (e: { level: number; message: string; line: number; sourceId: string; }) {
console.log(`[Embedded Page] ${e.message}`);
}),
addDisposableListener(this._webview, 'dom-ready', () => {
this.layout();
}),
addDisposableListener(this._webview, 'crashed', function () {
console.error('embedded page crashed');
}),
@ -245,11 +248,15 @@ export default class Webview {
if (!contents) {
return;
}
const window = contents.getOwnerBrowserWindow();
if (!window || !window.webContents) {
return;
}
window.webContents.getZoomFactor(factor => {
contents.setZoomFactor(factor);
const width = this.parent.clientWidth;
const height = this.parent.clientHeight;
contents.getZoomFactor(factor => {
const width = this.parent.clientWidth;
const height = this.parent.clientHeight;
contents.setSize({
normal: {
width: Math.floor(width * factor),