Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('extensions', function() { | 5 cr.define('extensions', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * The ExtensionOptionsOverlay will show an extension's options page using | 9 * The ExtensionOptionsOverlay will show an extension's options page using |
| 10 * an <extensionoptions> element. | 10 * an <extensionoptions> element. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 this.setVisible_(true); | 99 this.setVisible_(true); |
| 100 | 100 |
| 101 var extensionoptions = new window.ExtensionOptions(); | 101 var extensionoptions = new window.ExtensionOptions(); |
| 102 extensionoptions.extension = extensionId; | 102 extensionoptions.extension = extensionId; |
| 103 | 103 |
| 104 // The <extensionoptions> content's size needs to be restricted to the | 104 // The <extensionoptions> content's size needs to be restricted to the |
| 105 // bounds of the overlay window. The overlay gives a minWidth and | 105 // bounds of the overlay window. The overlay gives a minWidth and |
| 106 // maxHeight, but the maxHeight does not include our header height (title | 106 // maxHeight, but the maxHeight does not include our header height (title |
| 107 // and close button), so we need to subtract that to get the maxHeight | 107 // and close button), so we need to subtract that to get the maxHeight |
| 108 // for the extension options. | 108 // for the extension options. |
| 109 var maxHeight = parseInt(overlay.style.maxHeight, 10) - | 109 var maxHeight = parseInt(overlayStyle.maxHeight, 10) - |
| 110 overlayHeader.offsetHeight; | 110 overlayHeader.offsetHeight; |
| 111 var minWidth = parseInt(overlayStyle.minWidth, 10); | 111 var minWidth = parseInt(overlayStyle.minWidth, 10); |
| 112 | 112 |
| 113 extensionoptions.onclose = function() { | 113 extensionoptions.onclose = function() { |
| 114 cr.dispatchSimpleEvent($('overlay'), 'cancelOverlay'); | 114 cr.dispatchSimpleEvent($('overlay'), 'cancelOverlay'); |
| 115 }.bind(this); | 115 }.bind(this); |
| 116 | 116 |
| 117 // Track the current animation (used to grow/shrink the overlay content), | 117 // Track the current animation (used to grow/shrink the overlay content), |
| 118 // if any. Preferred size changes can fire more rapidly than the | 118 // if any. Preferred size changes can fire more rapidly than the |
| 119 // animation speed, and multiple animations running at the same time has | 119 // animation speed, and multiple animations running at the same time has |
| 120 // undesirable effects. | 120 // undesirable effects. |
| 121 var animation = null; | 121 var animation = null; |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Resize the overlay if the <extensionoptions> changes preferred size. | 124 * Resize the overlay if the <extensionoptions> changes preferred size. |
| 125 * @param {{width: number, height: number}} evt | 125 * @param {{width: number, height: number}} evt |
| 126 */ | 126 */ |
| 127 extensionoptions.onpreferredsizechanged = function(evt) { | 127 extensionoptions.onpreferredsizechanged = function(evt) { |
| 128 // |overlayStyle.height| includes the header height, so it needs to be | |
| 129 // subtracted to get the true old preferred height. | |
| 128 var oldWidth = parseInt(overlayStyle.width, 10); | 130 var oldWidth = parseInt(overlayStyle.width, 10); |
| 129 var oldHeight = parseInt(overlayStyle.height, 10); | 131 var oldHeight = |
| 132 parseInt(overlayStyle.height, 10) - overlayHeader.offsetHeight; | |
| 130 // The overlay must be slightly larger than the extension options to | 133 // The overlay must be slightly larger than the extension options to |
| 131 // avoid creating scrollbars. | 134 // avoid creating scrollbars. |
| 132 // TODO(paulmeyer): This shouldn't be necessary, but the preferred size | 135 // TODO(paulmeyer): This shouldn't be necessary, but the preferred size |
| 133 // (coming from Blink) seems to be too small for some zoom levels. The | 136 // (coming from Blink) seems to be too small for some zoom levels. The |
| 134 // 2-pixel addition should be removed once this problem is investigated | 137 // 2-pixel addition should be removed once this problem is investigated |
| 135 // and corrected. | 138 // and corrected. |
| 136 var newWidth = Math.max(evt.width + 2, minWidth); | 139 var newWidth = Math.max(evt.width + 2, minWidth); |
| 137 var newHeight = Math.min(evt.height + 2, maxHeight); | 140 var newHeight = Math.min(evt.height + 2, maxHeight); |
|
not at google - send to devlin
2015/03/18 20:59:15
Actually - should we be adding overlayHeader.width
paulmeyer
2015/03/18 21:41:46
Yes, adding the header height to the newheight cou
| |
| 138 | 141 |
| 139 // animationTime is the amount of time in ms that will be used to resize | 142 // animationTime is the amount of time in ms that will be used to resize |
| 140 // the overlay. It is calculated by multiplying the pythagorean distance | 143 // the overlay. It is calculated by multiplying the pythagorean distance |
| 141 // between old and the new size (in px) with a constant speed of | 144 // between old and the new size (in px) with a constant speed of |
| 142 // 0.25 ms/px. | 145 // 0.25 ms/px. |
| 143 var loading = document.documentElement.classList.contains('loading'); | 146 var loading = document.documentElement.classList.contains('loading'); |
| 144 var animationTime = loading ? 0 : | 147 var animationTime = loading ? 0 : |
| 145 0.25 * Math.sqrt(Math.pow(newWidth - oldWidth, 2) + | 148 0.25 * Math.sqrt(Math.pow(newWidth - oldWidth, 2) + |
| 146 Math.pow(newHeight - oldHeight, 2)); | 149 Math.pow(newHeight - oldHeight, 2)); |
| 147 | 150 |
| 148 if (animation) | 151 if (animation) |
| 149 animation.cancel(); | 152 animation.cancel(); |
| 150 | 153 |
| 154 // The header height must be added to the (old and new) preferred | |
| 155 // heights to get the full overlay heights. | |
| 151 animation = overlay.animate([ | 156 animation = overlay.animate([ |
| 152 {width: oldWidth + 'px', height: oldHeight + 'px'}, | 157 {width: oldWidth + 'px', |
| 153 {width: newWidth + 'px', height: newHeight + 'px'} | 158 height: (oldHeight + overlayHeader.offsetHeight) + 'px'}, |
| 159 {width: newWidth + 'px', | |
| 160 height: (newHeight + overlayHeader.offsetHeight) + 'px'} | |
| 154 ], { | 161 ], { |
| 155 duration: animationTime, | 162 duration: animationTime, |
| 156 delay: 0 | 163 delay: 0 |
| 157 }); | 164 }); |
| 158 | 165 |
| 159 animation.onfinish = function(e) { | 166 animation.onfinish = function(e) { |
| 160 animation = null; | 167 animation = null; |
| 161 | 168 |
| 162 // The <extensionoptions> element is ready to place back in the | 169 // The <extensionoptions> element is ready to place back in the |
| 163 // overlay. Make sure that it's sized to take up the full width/height | 170 // overlay. Make sure that it's sized to take up the full width/height |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 /** @type {HTMLDivElement} */($('extension-options-overlay')) : | 206 /** @type {HTMLDivElement} */($('extension-options-overlay')) : |
| 200 null); | 207 null); |
| 201 } | 208 } |
| 202 }; | 209 }; |
| 203 | 210 |
| 204 // Export | 211 // Export |
| 205 return { | 212 return { |
| 206 ExtensionOptionsOverlay: ExtensionOptionsOverlay | 213 ExtensionOptionsOverlay: ExtensionOptionsOverlay |
| 207 }; | 214 }; |
| 208 }); | 215 }); |
| OLD | NEW |