Resizing contents inside a webview

580 views
Skip to first unread message

George Crawford

unread,
Mar 12, 2013, 8:03:58 AM3/12/13
to chromi...@chromium.org
Hi,

I have a webview with autosize="on" style="width: 100%; height: 100%;", inside a chrome.app.window instance declared with minWidth: 1024, minHeight: 768 attributes. When I resize the main app window, I expected the webview's contents to also resize. Inspecting the DOM for the various views shows that the <webview> element has the new size as expected, but that the DOM of the webview contents still has the original dimensions from launch.

I've looked at http://developer.chrome.com/dev/apps/webview_tag.html for clues, and see this:

autosize
<webview id="foo" src="http://www.google.com/" style="width:640px; height:480px" autosize="on" minwidth="576" minheight="432"></webview>
If "on", the webview will fire the sizechanged event and adjust the size of the guest content within the webview container, provided you have written event handlers to change these dimensions.

I've tried setting a listener for the sizechanged event:

window.addEventListener('load', function() {
var webview = document.getElementById('econ-webview');
webview.addEventListener('sizechanged', function(event) {
console.log('Size changed:', event.oldWidth, event.oldHeight, event.newWidth, event.newHeight);
});
});

This logs the initial size at launch - Size changed: 0 0 1024 768 - but does not log any further events when I resize the app window.

Does anyone have a suggestion as to what I must do to get the webview contents resizing in tandem with the main app window?

Thanks.

George Crawford

unread,
Mar 12, 2013, 8:34:06 AM3/12/13
to chromi...@chromium.org
Interestingly, if I remove the autosize="on" attribute, the webview contents do receive resize events. With the attribute, the event is never fired. Is this correct?

Another observation is that resizing the window vertically doesn't fire an event - only horizontal resizing seems to propagate through to the contents DOM.
Reply all
Reply to author
Forward
0 new messages