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 // Returns the width of a scrollbar in logical pixels. | 5 // Returns the width of a scrollbar in logical pixels. |
6 function getScrollbarWidth() { | 6 function getScrollbarWidth() { |
7 // Create nested divs with scrollbars. | 7 // Create nested divs with scrollbars. |
8 var outer = document.createElement('div'); | 8 var outer = document.createElement('div'); |
9 outer.style.width = '100px'; | 9 outer.style.width = '100px'; |
10 outer.style.overflow = 'scroll'; | 10 outer.style.overflow = 'scroll'; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 setInitialFocus: function() { | 69 setInitialFocus: function() { |
70 this.getExtensionOptions_().focus(); | 70 this.getExtensionOptions_().focus(); |
71 }, | 71 }, |
72 | 72 |
73 /** | 73 /** |
74 * @return {?Element} | 74 * @return {?Element} |
75 * @private | 75 * @private |
76 */ | 76 */ |
77 getExtensionOptions_: function() { | 77 getExtensionOptions_: function() { |
78 return $('extension-options-overlay-guest').querySelector( | 78 return $('extension-options-overlay-guest') |
79 'extensionoptions'); | 79 .querySelector('extensionoptions'); |
80 }, | 80 }, |
81 | 81 |
82 /** | 82 /** |
83 * Handles a click on the close button. | 83 * Handles a click on the close button. |
84 * @param {Event} event The click event. | 84 * @param {Event} event The click event. |
85 * @private | 85 * @private |
86 */ | 86 */ |
87 handleDismiss_: function(event) { | 87 handleDismiss_: function(event) { |
88 this.setVisible_(false); | 88 this.setVisible_(false); |
89 var extensionoptions = this.getExtensionOptions_(); | 89 var extensionoptions = this.getExtensionOptions_(); |
(...skipping 10 matching lines...) Expand all Loading... |
100 * @param {string} extensionName The name of the extension, which is used | 100 * @param {string} extensionName The name of the extension, which is used |
101 * as the header of the overlay. | 101 * as the header of the overlay. |
102 * @param {string} extensionIcon The URL of the extension's icon. | 102 * @param {string} extensionIcon The URL of the extension's icon. |
103 * @param {function():void} shownCallback A function called when | 103 * @param {function():void} shownCallback A function called when |
104 * showing completes. | 104 * showing completes. |
105 * @suppress {checkTypes} | 105 * @suppress {checkTypes} |
106 * TODO(vitalyp): remove the suppression after adding | 106 * TODO(vitalyp): remove the suppression after adding |
107 * chrome/renderer/resources/extensions/extension_options.js | 107 * chrome/renderer/resources/extensions/extension_options.js |
108 * to dependencies. | 108 * to dependencies. |
109 */ | 109 */ |
110 setExtensionAndShow: function(extensionId, | 110 setExtensionAndShow: function( |
111 extensionName, | 111 extensionId, extensionName, extensionIcon, shownCallback) { |
112 extensionIcon, | |
113 shownCallback) { | |
114 var overlay = $('extension-options-overlay'); | 112 var overlay = $('extension-options-overlay'); |
115 var overlayHeader = $('extension-options-overlay-header'); | 113 var overlayHeader = $('extension-options-overlay-header'); |
116 var overlayGuest = $('extension-options-overlay-guest'); | 114 var overlayGuest = $('extension-options-overlay-guest'); |
117 var overlayStyle = window.getComputedStyle(overlay); | 115 var overlayStyle = window.getComputedStyle(overlay); |
118 | 116 |
119 $('extension-options-overlay-title').textContent = extensionName; | 117 $('extension-options-overlay-title').textContent = extensionName; |
120 $('extension-options-overlay-icon').src = extensionIcon; | 118 $('extension-options-overlay-icon').src = extensionIcon; |
121 | 119 |
122 this.setVisible_(true); | 120 this.setVisible_(true); |
123 | 121 |
124 var extensionoptions = new window.ExtensionOptions(); | 122 var extensionoptions = new window.ExtensionOptions(); |
125 extensionoptions.extension = extensionId; | 123 extensionoptions.extension = extensionId; |
126 this.extensionId_ = extensionId; | 124 this.extensionId_ = extensionId; |
127 | 125 |
128 // The <extensionoptions> content's size needs to be restricted to the | 126 // The <extensionoptions> content's size needs to be restricted to the |
129 // bounds of the overlay window. The overlay gives a minWidth and | 127 // bounds of the overlay window. The overlay gives a minWidth and |
130 // maxHeight, but the maxHeight does not include our header height (title | 128 // maxHeight, but the maxHeight does not include our header height (title |
131 // and close button), so we need to subtract that to get the maxHeight | 129 // and close button), so we need to subtract that to get the maxHeight |
132 // for the extension options. | 130 // for the extension options. |
133 var maxHeight = parseInt(overlayStyle.maxHeight, 10) - | 131 var maxHeight = |
134 overlayHeader.offsetHeight; | 132 parseInt(overlayStyle.maxHeight, 10) - overlayHeader.offsetHeight; |
135 var minWidth = parseInt(overlayStyle.minWidth, 10); | 133 var minWidth = parseInt(overlayStyle.minWidth, 10); |
136 | 134 |
137 extensionoptions.onclose = function() { | 135 extensionoptions.onclose = function() { |
138 cr.dispatchSimpleEvent($('overlay'), 'cancelOverlay'); | 136 cr.dispatchSimpleEvent($('overlay'), 'cancelOverlay'); |
139 }.bind(this); | 137 }.bind(this); |
140 | 138 |
141 // Track the current animation (used to grow/shrink the overlay content), | 139 // Track the current animation (used to grow/shrink the overlay content), |
142 // if any. Preferred size changes can fire more rapidly than the | 140 // if any. Preferred size changes can fire more rapidly than the |
143 // animation speed, and multiple animations running at the same time has | 141 // animation speed, and multiple animations running at the same time has |
144 // undesirable effects. | 142 // undesirable effects. |
(...skipping 19 matching lines...) Expand all Loading... |
164 // Enforce |minWidth| and |maxHeight|. | 162 // Enforce |minWidth| and |maxHeight|. |
165 newOverlayWidth = Math.max(newOverlayWidth, minWidth); | 163 newOverlayWidth = Math.max(newOverlayWidth, minWidth); |
166 newOverlayHeight = Math.min(newOverlayHeight, maxHeight); | 164 newOverlayHeight = Math.min(newOverlayHeight, maxHeight); |
167 | 165 |
168 // animationTime is the amount of time in ms that will be used to resize | 166 // animationTime is the amount of time in ms that will be used to resize |
169 // the overlay. It is calculated by multiplying the pythagorean distance | 167 // the overlay. It is calculated by multiplying the pythagorean distance |
170 // between old and the new size (in px) with a constant speed of | 168 // between old and the new size (in px) with a constant speed of |
171 // 0.25 ms/px. | 169 // 0.25 ms/px. |
172 var loading = document.documentElement.classList.contains('loading'); | 170 var loading = document.documentElement.classList.contains('loading'); |
173 var animationTime = loading ? 0 : | 171 var animationTime = loading ? 0 : |
174 0.25 * Math.sqrt(Math.pow(newOverlayWidth - oldOverlayWidth, 2) + | 172 0.25 * |
175 Math.pow(newOverlayHeight - oldOverlayHeight, 2)); | 173 Math.sqrt( |
| 174 Math.pow(newOverlayWidth - oldOverlayWidth, 2) + |
| 175 Math.pow(newOverlayHeight - oldOverlayHeight, 2)); |
176 | 176 |
177 if (animation) | 177 if (animation) |
178 animation.cancel(); | 178 animation.cancel(); |
179 | 179 |
180 // The header height must be added to the (old and new) preferred | 180 // The header height must be added to the (old and new) preferred |
181 // heights to get the full overlay heights. | 181 // heights to get the full overlay heights. |
182 animation = overlay.animate([ | 182 animation = overlay.animate( |
183 {width: oldOverlayWidth + 'px', height: oldOverlayHeight + 'px'}, | 183 [ |
184 {width: newOverlayWidth + 'px', height: newOverlayHeight + 'px'} | 184 {width: oldOverlayWidth + 'px', height: oldOverlayHeight + 'px'}, |
185 ], { | 185 {width: newOverlayWidth + 'px', height: newOverlayHeight + 'px'} |
186 duration: animationTime, | 186 ], |
187 delay: 0 | 187 {duration: animationTime, delay: 0}); |
188 }); | |
189 | 188 |
190 animation.onfinish = function(e) { | 189 animation.onfinish = function(e) { |
191 animation = null; | 190 animation = null; |
192 | 191 |
193 // The <extensionoptions> element is ready to place back in the | 192 // The <extensionoptions> element is ready to place back in the |
194 // overlay. Make sure that it's sized to take up the full width/height | 193 // overlay. Make sure that it's sized to take up the full width/height |
195 // of the overlay. | 194 // of the overlay. |
196 overlayGuest.style.position = ''; | 195 overlayGuest.style.position = ''; |
197 overlayGuest.style.left = ''; | 196 overlayGuest.style.left = ''; |
198 overlayGuest.style.width = newOverlayWidth + 'px'; | 197 overlayGuest.style.width = newOverlayWidth + 'px'; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 getExtensionId: function() { | 236 getExtensionId: function() { |
238 return this.extensionId_; | 237 return this.extensionId_; |
239 }, | 238 }, |
240 | 239 |
241 /** | 240 /** |
242 * Toggles the visibility of the ExtensionOptionsOverlay. | 241 * Toggles the visibility of the ExtensionOptionsOverlay. |
243 * @param {boolean} isVisible Whether the overlay should be visible. | 242 * @param {boolean} isVisible Whether the overlay should be visible. |
244 * @private | 243 * @private |
245 */ | 244 */ |
246 setVisible_: function(isVisible) { | 245 setVisible_: function(isVisible) { |
247 this.showOverlay_(isVisible ? | 246 this.showOverlay_( |
248 /** @type {HTMLDivElement} */($('extension-options-overlay')) : | 247 isVisible ? |
249 null); | 248 /** @type {HTMLDivElement} */ ($('extension-options-overlay')) : |
| 249 null); |
250 } | 250 } |
251 }; | 251 }; |
252 | 252 |
253 // Export | 253 // Export |
254 return { | 254 return {ExtensionOptionsOverlay: ExtensionOptionsOverlay}; |
255 ExtensionOptionsOverlay: ExtensionOptionsOverlay | |
256 }; | |
257 }); | 255 }); |
OLD | NEW |