Chromium Code Reviews| Index: chrome/renderer/resources/extensions/web_view.js |
| diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js |
| index ff807f861df79a21e3982b30959060ad8a0837d1..ff185319b9265a89027f439520030a6791e84c46 100644 |
| --- a/chrome/renderer/resources/extensions/web_view.js |
| +++ b/chrome/renderer/resources/extensions/web_view.js |
| @@ -24,9 +24,22 @@ var webView = require('binding').Binding.create('webview').generate(); |
| // API can access it and not external developers. |
| var secret = {}; |
| +var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; |
| +var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; |
| +var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; |
| +var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; |
| + |
| /** @type {Array.<string>} */ |
| -var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', |
| - 'minwidth', 'maxheight', 'maxwidth']; |
| +var WEB_VIEW_ATTRIBUTES = [ |
| + 'name', |
| + 'src', |
| + 'partition', |
| + 'autosize', |
| + WEB_VIEW_ATTRIBUTE_MINHEIGHT, |
| + WEB_VIEW_ATTRIBUTE_MINWIDTH, |
| + WEB_VIEW_ATTRIBUTE_MAXHEIGHT, |
| + WEB_VIEW_ATTRIBUTE_MAXWIDTH |
| +]; |
| var webViewInstanceIdCounter = 0; |
| @@ -114,6 +127,52 @@ var WEB_VIEW_EXT_EVENTS = { |
| fields: ['processId'] |
| }, |
| 'sizechanged': { |
| + customHandler: function(webview, event, webviewEvent) { |
| + var node = webview.webviewNode_; |
|
Fady Samuel
2013/08/28 19:14:38
Could you please move all this code to a helper me
|
| + |
| + // Check the current bounds to make sure we do not resize <webview> |
| + // outside of current constraints. |
| + var minWidth = 0; |
| + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINWIDTH) && |
| + node[WEB_VIEW_ATTRIBUTE_MINWIDTH]) { |
| + minWidth = node[WEB_VIEW_ATTRIBUTE_MINWIDTH]; |
| + } |
| + var maxWidth; |
| + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXWIDTH) && |
| + node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]) { |
| + maxWidth = node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]; |
| + } else { |
| + maxWidth = node.offsetWidth; |
| + } |
| + if (minWidth > maxWidth) { |
| + minWidth = maxWidth; |
| + } |
| + |
| + var minHeight = 0; |
| + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINHEIGHT) && |
| + node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]) { |
| + minHeight = node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]; |
| + } |
| + var maxHeight; |
| + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXHEIGHT) && |
| + node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]) { |
| + maxHeight = node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]; |
| + } else { |
| + maxHeight = node.offsetHeight; |
| + } |
| + if (minHeight > maxHeight) { |
| + minHeight = maxHeight; |
| + } |
| + |
| + if (webviewEvent.newWidth >= minWidth && |
| + webviewEvent.newWidth <= maxWidth && |
| + webviewEvent.newHeight >= minHeight && |
| + webviewEvent.newHeight <= maxHeight) { |
| + webview.webviewNode_.style.width = webviewEvent.newWidth + 'px'; |
| + webview.webviewNode_.style.height = webviewEvent.newHeight + 'px'; |
| + } |
| + webview.webviewNode_.dispatchEvent(webviewEvent); |
| + }, |
| evt: createEvent('webview.onSizeChanged'), |
| fields: ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'] |
| }, |