diff options
author | lazyboy@chromium.org <lazyboy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-03 21:12:11 +0000 |
---|---|---|
committer | lazyboy@chromium.org <lazyboy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-03 21:12:11 +0000 |
commit | a949bc06e41cb648c417ffd11d35f0f8d2b5edf8 (patch) | |
tree | ec28ebcc17a4ee70d8442f01ae1895bcd758daef /chrome/renderer/resources/extensions/web_view.js | |
parent | b550dc1946fa6bdd14d91fd7f1f98aad0f5f6549 (diff) | |
download | chromium_src-a949bc06e41cb648c417ffd11d35f0f8d2b5edf8.zip chromium_src-a949bc06e41cb648c417ffd11d35f0f8d2b5edf8.tar.gz chromium_src-a949bc06e41cb648c417ffd11d35f0f8d2b5edf8.tar.bz2 |
Reland after fix: Improve <webview> autosize:
a. Expand/shrink <webview> element when 'sizechange' event fires, to
match with the new view size (in shim).
b. For SW mode, fix a bug where damage buffer would remain smaller than
the view size and would result in crash. Added test for this case.
BUG=173238, 282116
Test=WebViewTest.AutoSize.*, <webview>.autosize=true now should autosize
webview container within the constraints
(minwidth/maxwidth/minheight/maxheight).
Review URL: https://chromiumcodereview.appspot.com/23503023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/resources/extensions/web_view.js')
-rw-r--r-- | chrome/renderer/resources/extensions/web_view.js | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js index a3760d3..7954261 100644 --- a/chrome/renderer/resources/extensions/web_view.js +++ b/chrome/renderer/resources/extensions/web_view.js @@ -24,9 +24,21 @@ 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', 'partition', 'autosize', 'minheight', - 'minwidth', 'maxheight', 'maxwidth']; +var WEB_VIEW_ATTRIBUTES = [ + 'name', + 'partition', + 'autosize', + WEB_VIEW_ATTRIBUTE_MINHEIGHT, + WEB_VIEW_ATTRIBUTE_MINWIDTH, + WEB_VIEW_ATTRIBUTE_MAXHEIGHT, + WEB_VIEW_ATTRIBUTE_MAXWIDTH +]; var webViewInstanceIdCounter = 0; @@ -113,6 +125,9 @@ var WEB_VIEW_EVENTS = { }, 'sizechanged': { evt: CreateEvent('webview.onSizeChanged'), + customHandler: function(webViewInternal, event, webViewEvent) { + webViewInternal.handleSizeChangedEvent_(event, webViewEvent); + }, fields: ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'] }, 'unresponsive': { @@ -475,6 +490,62 @@ WebViewInternal.prototype.getEvents_ = function() { return WEB_VIEW_EVENTS; }; +WebViewInternal.prototype.handleSizeChangedEvent_ = + function(event, webViewEvent) { + var node = this.webviewNode_; + + var width = node.offsetWidth; + var height = node.offsetHeight; + + // Check the current bounds to make sure we do not resize <webview> + // outside of current constraints. + var maxWidth; + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXWIDTH) && + node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]) { + maxWidth = node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]; + } else { + maxWidth = width; + } + + var minWidth; + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINWIDTH) && + node[WEB_VIEW_ATTRIBUTE_MINWIDTH]) { + minWidth = node[WEB_VIEW_ATTRIBUTE_MINWIDTH]; + } else { + minWidth = width; + } + if (minWidth > maxWidth) { + minWidth = maxWidth; + } + + var maxHeight; + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXHEIGHT) && + node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]) { + maxHeight = node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]; + } else { + maxHeight = height; + } + var minHeight; + if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINHEIGHT) && + node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]) { + minHeight = node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]; + } else { + minHeight = height; + } + if (minHeight > maxHeight) { + minHeight = maxHeight; + } + + if (webViewEvent.newWidth >= minWidth && + webViewEvent.newWidth <= maxWidth && + webViewEvent.newHeight >= minHeight && + webViewEvent.newHeight <= maxHeight) { + node.style.width = webViewEvent.newWidth + 'px'; + node.style.height = webViewEvent.newHeight + 'px'; + } + node.dispatchEvent(webViewEvent); +}; + /** * @private */ |