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 26 matching lines...) Expand all Loading... | |
37 cr.ui.overlay.globalInitialization(); | 37 cr.ui.overlay.globalInitialization(); |
38 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); | 38 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); |
39 | 39 |
40 this.showOverlay_ = showOverlay; | 40 this.showOverlay_ = showOverlay; |
41 }, | 41 }, |
42 | 42 |
43 setInitialFocus: function() { | 43 setInitialFocus: function() { |
44 this.getExtensionOptions_().focus(); | 44 this.getExtensionOptions_().focus(); |
45 }, | 45 }, |
46 | 46 |
47 /** @return {?Element} */ | 47 /** |
48 * @return {?Element} | |
49 * @private | |
50 */ | |
48 getExtensionOptions_: function() { | 51 getExtensionOptions_: function() { |
49 return $('extension-options-overlay-guest').querySelector( | 52 return $('extension-options-overlay-guest').querySelector( |
50 'extensionoptions'); | 53 'extensionoptions'); |
51 }, | 54 }, |
52 | 55 |
53 /** | 56 /** |
54 * Handles a click on the close button. | 57 * Handles a click on the close button. |
55 * @param {Event} event The click event. | 58 * @param {Event} event The click event. |
56 * @private | 59 * @private |
57 */ | 60 */ |
58 handleDismiss_: function(event) { | 61 handleDismiss_: function(event) { |
59 this.setVisible_(false); | 62 this.setVisible_(false); |
60 var extensionoptions = this.getExtensionOptions_(); | 63 var extensionoptions = this.getExtensionOptions_(); |
61 if (extensionoptions) | 64 if (extensionoptions) |
62 $('extension-options-overlay-guest').removeChild(extensionoptions); | 65 $('extension-options-overlay-guest').removeChild(extensionoptions); |
63 | 66 |
64 $('extension-options-overlay-icon').removeAttribute('src'); | 67 $('extension-options-overlay-icon').removeAttribute('src'); |
65 | 68 |
66 // Remove the options query string. | 69 // Remove the options query string. |
67 uber.replaceState({}, ''); | 70 uber.replaceState({}, ''); |
68 }, | 71 }, |
69 | 72 |
70 /** | 73 /** |
71 * Associate an extension with the overlay and display it. | 74 * Associate an extension with the overlay and display it. |
72 * @param {string} extensionId The id of the extension whose options page | 75 * @param {string} extensionId The id of the extension whose options page |
73 * should be displayed in the overlay. | 76 * should be displayed in the overlay. |
74 * @param {string} extensionName The name of the extension, which is used | 77 * @param {string} extensionName The name of the extension, which is used |
75 * as the header of the overlay. | 78 * as the header of the overlay. |
76 * @param {string} extensionIcon The URL of the extension's icon. | 79 * @param {string} extensionIcon The URL of the extension's icon. |
77 * @param {function():void} shownCallback A function called when show | 80 * @param {function():void} shownCallback A function called when |
78 * animation completes. | 81 * showing completes. |
79 * @suppress {checkTypes} | 82 * @suppress {checkTypes} |
80 * TODO(vitalyp): remove the suppression after adding | 83 * TODO(vitalyp): remove the suppression after adding |
81 * chrome/renderer/resources/extensions/extension_options.js | 84 * chrome/renderer/resources/extensions/extension_options.js |
82 * to dependencies. | 85 * to dependencies. |
83 */ | 86 */ |
84 setExtensionAndShowOverlay: function(extensionId, | 87 setExtensionAndShowOverlay: function(extensionId, |
85 extensionName, | 88 extensionName, |
86 extensionIcon, | 89 extensionIcon, |
87 shownCallback) { | 90 shownCallback) { |
88 var overlay = $('extension-options-overlay'); | 91 var overlay = $('extension-options-overlay'); |
89 var overlayHeader = $('extension-options-overlay-header'); | 92 var overlayHeader = $('extension-options-overlay-header'); |
90 var overlayGuest = $('extension-options-overlay-guest'); | 93 var overlayGuest = $('extension-options-overlay-guest'); |
91 var overlayStyle = window.getComputedStyle(overlay); | 94 var overlayStyle = window.getComputedStyle(overlay); |
92 | 95 |
93 $('extension-options-overlay-title').textContent = extensionName; | 96 $('extension-options-overlay-title').textContent = extensionName; |
94 $('extension-options-overlay-icon').src = extensionIcon; | 97 $('extension-options-overlay-icon').src = extensionIcon; |
95 | 98 |
96 this.setVisible_(true); | |
97 | |
98 var extensionoptions = new window.ExtensionOptions(); | 99 var extensionoptions = new window.ExtensionOptions(); |
99 extensionoptions.extension = extensionId; | 100 extensionoptions.extension = extensionId; |
100 | 101 |
101 // The <extensionoptions> content's size needs to be restricted to the | 102 // The <extensionoptions> content's size needs to be restricted to the |
102 // bounds of the overlay window. The overlay gives a minWidth and | 103 // bounds of the overlay window. The overlay gives a minWidth and |
103 // maxHeight, but the maxHeight does not include our header height (title | 104 // maxHeight, but the maxHeight does not include our header height (title |
104 // and close button), so we need to subtract that to get the maxHeight | 105 // and close button), so we need to subtract that to get the maxHeight |
105 // for the extension options. | 106 // for the extension options. |
106 var maxHeight = parseInt(overlay.style.maxHeight, 10) - | 107 var maxHeight = parseInt(overlay.style.maxHeight, 10) - |
107 overlayHeader.offsetHeight; | 108 overlayHeader.offsetHeight; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 // Begin rendering at the default dimensions. This is also necessary to | 172 // Begin rendering at the default dimensions. This is also necessary to |
172 // cancel any width/height set on a previous render. | 173 // cancel any width/height set on a previous render. |
173 // TODO(kalman): This causes a visual jag where the overlay guest shows | 174 // TODO(kalman): This causes a visual jag where the overlay guest shows |
174 // up briefly. It would be better to render this off-screen first, then | 175 // up briefly. It would be better to render this off-screen first, then |
175 // swap it in place. See crbug.com/408274. | 176 // swap it in place. See crbug.com/408274. |
176 // This may also solve crbug.com/431001 (width is 0 on initial render). | 177 // This may also solve crbug.com/431001 (width is 0 on initial render). |
177 overlayGuest.style.width = ''; | 178 overlayGuest.style.width = ''; |
178 overlayGuest.style.height = ''; | 179 overlayGuest.style.height = ''; |
179 | 180 |
180 overlayGuest.appendChild(extensionoptions); | 181 overlayGuest.appendChild(extensionoptions); |
182 | |
183 // Show the dialog after extensionoptions is in the DOM so it gets focus. | |
184 this.setVisible_(true); | |
not at google - send to devlin
2015/02/06 21:31:38
Unfortunately showing the overlay early serves a p
Dan Beam
2015/02/06 21:50:02
i don't ;), moved back
| |
181 }, | 185 }, |
182 | 186 |
183 /** | 187 /** |
184 * Toggles the visibility of the ExtensionOptionsOverlay. | 188 * Toggles the visibility of the ExtensionOptionsOverlay. |
185 * @param {boolean} isVisible Whether the overlay should be visible. | 189 * @param {boolean} isVisible Whether the overlay should be visible. |
186 * @private | 190 * @private |
187 */ | 191 */ |
188 setVisible_: function(isVisible) { | 192 setVisible_: function(isVisible) { |
189 this.showOverlay_(isVisible ? | 193 this.showOverlay_(isVisible ? |
190 /** @type {HTMLDivElement} */($('extension-options-overlay')) : | 194 /** @type {HTMLDivElement} */($('extension-options-overlay')) : |
191 null); | 195 null); |
192 } | 196 } |
193 }; | 197 }; |
194 | 198 |
195 // Export | 199 // Export |
196 return { | 200 return { |
197 ExtensionOptionsOverlay: ExtensionOptionsOverlay | 201 ExtensionOptionsOverlay: ExtensionOptionsOverlay |
198 }; | 202 }; |
199 }); | 203 }); |
OLD | NEW |