Chromium Code Reviews| Index: chrome/renderer/resources/extensions/extension_options.js |
| diff --git a/chrome/renderer/resources/extensions/extension_options.js b/chrome/renderer/resources/extensions/extension_options.js |
| index d88c3d1460a5bd490e6ba0ba423f1c3f03bf0863..8c884e0df844f17b136c99fc6e4ffea515053a79 100644 |
| --- a/chrome/renderer/resources/extensions/extension_options.js |
| +++ b/chrome/renderer/resources/extensions/extension_options.js |
| @@ -24,6 +24,8 @@ function ExtensionOptionsInternal(extensionoptionsNode) { |
| this.extensionoptionsNode = extensionoptionsNode; |
| this.viewInstanceId = IdGenerator.GetNextId(); |
| + this.autosizeDeferred = false; |
| + |
| // on* Event handlers. |
| this.eventHandlers = {}; |
| @@ -134,9 +136,18 @@ ExtensionOptionsInternal.prototype.init = function() { |
| this.createGuest(); |
| }; |
| -ExtensionOptionsInternal.prototype.onSizeChanged = function(width, height) { |
| - this.browserPluginNode.style.width = width + 'px'; |
| - this.browserPluginNode.style.height = height + 'px'; |
| +ExtensionOptionsInternal.prototype.onSizeChanged = |
| + function(newWidth, newHeight, oldWidth, oldHeight) { |
| + if (this.autosizeDeferred) { |
| + this.deferredAutoSizeState = { |
| + newWidth: newWidth, |
| + newHeight: newHeight, |
| + oldWidth: oldWidth, |
| + oldHeight: oldHeight |
| + }; |
| + } else { |
| + this.resize(newWidth, newHeight, oldWidth, oldHeight); |
| + } |
| }; |
| ExtensionOptionsInternal.prototype.parseExtensionAttribute = function() { |
| @@ -147,6 +158,32 @@ ExtensionOptionsInternal.prototype.parseExtensionAttribute = function() { |
| return false; |
| }; |
| +ExtensionOptionsInternal.prototype.resize = |
| + function(newWidth, newHeight, oldWidth, oldHeight) { |
| + this.browserPluginNode.style.width = newWidth + 'px'; |
| + this.browserPluginNode.style.height = newHeight + 'px'; |
| + |
| + // Do not allow the options page's dimensions to shrink so that the options |
| + // page has a consistent UI. If the new size is larger than the minimum, |
| + // make that the new minimum size. |
| + if (newWidth > this.minwidth) |
| + this.minwidth = newWidth; |
| + if (newHeight > this.minheight) |
| + this.minheight = newHeight; |
| + |
| + GuestViewInternal.setAutoSize(this.instanceId, { |
| + 'enableAutoSize': this.extensionoptionsNode.hasAttribute('autosize'), |
| + 'min': { |
| + 'width': parseInt(this.minwidth || 0), |
| + 'height': parseInt(this.minheight || 0) |
| + }, |
| + 'max': { |
| + 'width': parseInt(this.maxwidth || 0), |
| + 'height': parseInt(this.maxheight || 0) |
| + } |
| + }); |
| +}; |
| + |
| // Adds an 'on<event>' property on the view, which can be used to set/unset |
| // an event handler. |
| ExtensionOptionsInternal.prototype.setupEventProperty = function(eventName) { |
| @@ -212,7 +249,33 @@ ExtensionOptionsInternal.prototype.resetSizeConstraintsIfInvalid = function () { |
| this.minwidth = AUTO_SIZE_ATTRIBUTES.minwidth; |
| this.maxwidth = AUTO_SIZE_ATTRIBUTES.maxwidth; |
| } |
| -} |
| +}; |
| + |
| +/** |
| + * Toggles whether autosizing should be performed immediately or not. |
| + * If set to true, sizechanged events will provide the preferred dimensions |
| + * of the element, but will not resize it until resumeDeferredAutoSize is |
| + * called. If set to false (the default setting), resizing will occur |
| + * automatically. |
| + */ |
| +ExtensionOptionsInternal.prototype.shouldDeferAutoSize = function(value) { |
| + if (!value) |
| + resumeDeferredAutoSize(); |
| + this.autosizeDeferred = value; |
| +}; |
| + |
| +/** |
| + * If the shouldDeferAutoSize setting is true, resize the element to the most |
| + * recent preferred dimensions provided by the browser plugin autosize. |
| + */ |
| +ExtensionOptionsInternal.prototype.resumeDeferredAutoSize = function() { |
|
not at google - send to devlin
2014/08/20 02:07:15
You could combine these into a method like setAuto
ericzeng
2014/08/20 02:23:30
shouldDeferAutoSize(true|false) does what you desc
not at google - send to devlin
2014/08/20 02:29:34
Ah.
In that case, s/shouldDeferAutosize/setDeferA
ericzeng
2014/08/20 18:44:07
Done.
|
| + if (this.autosizeDeferred) { |
| + this.resize(this.deferredAutoSizeState.newWidth, |
| + this.deferredAutoSizeState.newHeight, |
| + this.deferredAutoSizeState.oldWidth, |
| + this.deferredAutoSizeState.oldHeight); |
| + } |
| +}; |
| function registerBrowserPluginElement() { |
| var proto = Object.create(HTMLObjectElement.prototype); |
| @@ -251,6 +314,22 @@ function registerExtensionOptionsElement() { |
| internal.handleExtensionOptionsAttributeMutation(name, oldValue, newValue); |
| }; |
| + var methods = [ |
| + 'shouldDeferAutoSize', |
| + 'resumeDeferredAutoSize' |
| + ]; |
| + |
| + // Forward proto.foo* method calls to ExtensionOptionsInternal.foo*. |
| + for (var i = 0; methods[i]; ++i) { |
| + var createHandler = function(m) { |
| + return function(var_args) { |
| + var internal = privates(this).internal; |
| + return $Function.apply(internal[m], internal, arguments); |
| + }; |
| + }; |
| + proto[methods[i]] = createHandler(methods[i]); |
| + } |
| + |
| window.ExtensionOptions = |
| DocumentNatives.RegisterElement('extensionoptions', {prototype: proto}); |