Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/resources/extensions/extension_options_overlay.js

Issue 900623003: extensions: focus options overlay content when shown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@policy-icon-label
Patch Set: blur() just in case Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 initializePage: function(showOverlay) { 33 initializePage: function(showOverlay) {
34 var overlay = $('overlay'); 34 var overlay = $('overlay');
35 35
36 cr.ui.overlay.setupOverlay(overlay); 36 cr.ui.overlay.setupOverlay(overlay);
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() {
44 this.getExtensionOptions_().focus();
45 },
46
47 /** @return {?Element} */
48 getExtensionOptions_: function() {
49 return $('extension-options-overlay-guest').querySelector(
50 'extensionoptions');
51 },
52
43 /** 53 /**
44 * Handles a click on the close button. 54 * Handles a click on the close button.
45 * @param {Event} event The click event. 55 * @param {Event} event The click event.
46 * @private 56 * @private
47 */ 57 */
48 handleDismiss_: function(event) { 58 handleDismiss_: function(event) {
49 this.setVisible_(false); 59 this.setVisible_(false);
50 var extensionoptions = 60 var extensionoptions = this.getExtensionOptions_();
51 $('extension-options-overlay-guest')
52 .querySelector('extensionoptions');
53
54 if (extensionoptions) 61 if (extensionoptions)
55 $('extension-options-overlay-guest').removeChild(extensionoptions); 62 $('extension-options-overlay-guest').removeChild(extensionoptions);
56 63
57 $('extension-options-overlay-icon').removeAttribute('src'); 64 $('extension-options-overlay-icon').removeAttribute('src');
58 65
59 // Remove the options query string. 66 // Remove the options query string.
60 uber.replaceState({}, ''); 67 uber.replaceState({}, '');
61 }, 68 },
62 69
63 /** 70 /**
64 * Associate an extension with the overlay and display it. 71 * Associate an extension with the overlay and display it.
65 * @param {string} extensionId The id of the extension whose options page 72 * @param {string} extensionId The id of the extension whose options page
66 * should be displayed in the overlay. 73 * should be displayed in the overlay.
67 * @param {string} extensionName The name of the extension, which is used 74 * @param {string} extensionName The name of the extension, which is used
68 * as the header of the overlay. 75 * as the header of the overlay.
69 * @param {string} extensionIcon The URL of the extension's icon. 76 * @param {string} extensionIcon The URL of the extension's icon.
77 * @param {function():void} shownCallback A function called when show
78 * animation completes.
70 * @suppress {checkTypes} 79 * @suppress {checkTypes}
71 * TODO(vitalyp): remove the suppression after adding 80 * TODO(vitalyp): remove the suppression after adding
72 * chrome/renderer/resources/extensions/extension_options.js 81 * chrome/renderer/resources/extensions/extension_options.js
73 * to dependencies. 82 * to dependencies.
74 */ 83 */
75 setExtensionAndShowOverlay: function(extensionId, 84 setExtensionAndShowOverlay: function(extensionId,
76 extensionName, 85 extensionName,
77 extensionIcon) { 86 extensionIcon,
87 shownCallback) {
78 var overlay = $('extension-options-overlay'); 88 var overlay = $('extension-options-overlay');
79 var overlayHeader = $('extension-options-overlay-header'); 89 var overlayHeader = $('extension-options-overlay-header');
80 var overlayGuest = $('extension-options-overlay-guest'); 90 var overlayGuest = $('extension-options-overlay-guest');
81 var overlayStyle = window.getComputedStyle(overlay); 91 var overlayStyle = window.getComputedStyle(overlay);
82 92
83 $('extension-options-overlay-title').textContent = extensionName; 93 $('extension-options-overlay-title').textContent = extensionName;
84 $('extension-options-overlay-icon').src = extensionIcon; 94 $('extension-options-overlay-icon').src = extensionIcon;
85 95
86 this.setVisible_(true); 96 this.setVisible_(true);
87 97
(...skipping 30 matching lines...) Expand all
118 var newHeight = Math.min(evt.height, maxHeight); 128 var newHeight = Math.min(evt.height, maxHeight);
119 129
120 // animationTime is the amount of time in ms that will be used to resize 130 // animationTime is the amount of time in ms that will be used to resize
121 // the overlay. It is calculated by multiplying the pythagorean distance 131 // the overlay. It is calculated by multiplying the pythagorean distance
122 // between old and the new size (in px) with a constant speed of 132 // between old and the new size (in px) with a constant speed of
123 // 0.25 ms/px. 133 // 0.25 ms/px.
124 var animationTime = 0.25 * Math.sqrt( 134 var animationTime = 0.25 * Math.sqrt(
125 Math.pow(newWidth - oldWidth, 2) + 135 Math.pow(newWidth - oldWidth, 2) +
126 Math.pow(newHeight - oldHeight, 2)); 136 Math.pow(newHeight - oldHeight, 2));
127 137
128 if (animation) { 138 if (animation)
129 animation.cancel(); 139 animation.cancel();
130 } 140
131 animation = overlay.animate([ 141 animation = overlay.animate([
132 {width: oldWidth + 'px', height: oldHeight + 'px'}, 142 {width: oldWidth + 'px', height: oldHeight + 'px'},
133 {width: newWidth + 'px', height: newHeight + 'px'} 143 {width: newWidth + 'px', height: newHeight + 'px'}
134 ], { 144 ], {
135 duration: animationTime, 145 duration: animationTime,
136 delay: 0 146 delay: 0
137 }); 147 });
138 148
139 animation.onfinish = function(e) { 149 animation.onfinish = function(e) {
140 animation = null; 150 animation = null;
151
141 // The <extensionoptions> element is ready to place back in the 152 // The <extensionoptions> element is ready to place back in the
142 // overlay. Make sure that it's sized to take up the full 153 // overlay. Make sure that it's sized to take up the full width/height
143 // width/height of the overlay. 154 // of the overlay.
144 overlayGuest.style.position = ''; 155 overlayGuest.style.position = '';
145 overlayGuest.style.left = ''; 156 overlayGuest.style.left = '';
146 overlayGuest.style.width = newWidth + 'px'; 157 overlayGuest.style.width = newWidth + 'px';
147 overlayGuest.style.height = newHeight + 'px'; 158 overlayGuest.style.height = newHeight + 'px';
159
160 if (shownCallback) {
161 shownCallback();
162 shownCallback = null;
163 }
148 }; 164 };
149 }.bind(this); 165 }.bind(this);
150 166
151 // Move the <extensionoptions> off screen until the overlay is ready. 167 // Move the <extensionoptions> off screen until the overlay is ready.
152 overlayGuest.style.position = 'fixed'; 168 overlayGuest.style.position = 'fixed';
153 overlayGuest.style.left = window.outerWidth + 'px'; 169 overlayGuest.style.left = window.outerWidth + 'px';
154 // Begin rendering at the default dimensions. This is also necessary to 170 // Begin rendering at the default dimensions. This is also necessary to
155 // cancel any width/height set on a previous render. 171 // cancel any width/height set on a previous render.
156 // TODO(kalman): This causes a visual jag where the overlay guest shows 172 // TODO(kalman): This causes a visual jag where the overlay guest shows
157 // up briefly. It would be better to render this off-screen first, then 173 // up briefly. It would be better to render this off-screen first, then
(...skipping 15 matching lines...) Expand all
173 /** @type {HTMLDivElement} */($('extension-options-overlay')) : 189 /** @type {HTMLDivElement} */($('extension-options-overlay')) :
174 null); 190 null);
175 } 191 }
176 }; 192 };
177 193
178 // Export 194 // Export
179 return { 195 return {
180 ExtensionOptionsOverlay: ExtensionOptionsOverlay 196 ExtensionOptionsOverlay: ExtensionOptionsOverlay
181 }; 197 };
182 }); 198 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698