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

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

Issue 1012233002: Fixed resizing animation for extension options. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comment. Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 var oldWidth = parseInt(overlayStyle.width, 10); 128 var oldOverlayWidth = parseInt(overlayStyle.width, 10);
129 var oldHeight = parseInt(overlayStyle.height, 10); 129 var oldOverlayHeight = parseInt(overlayStyle.height, 10);
130 // The overlay must be slightly larger than the extension options to 130 // The overlay must be slightly larger than the extension options to
131 // avoid creating scrollbars. 131 // avoid creating scrollbars.
132 // TODO(paulmeyer): This shouldn't be necessary, but the preferred size 132 // 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 133 // (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 134 // 2-pixel addition should be removed once this problem is investigated
135 // and corrected. 135 // and corrected.
136 var newWidth = Math.max(evt.width + 2, minWidth); 136 var newOverlayWidth = Math.max(evt.width + 2, minWidth);
137 var newHeight = Math.min(evt.height + 2, maxHeight); 137 // |evt.height| is just the new overlay guest height, and does not
138 // include the overlay header height, so it needs to be added.
139 var newOverlayHeight =
140 Math.min(evt.height + overlayHeader.offsetHeight + 2, maxHeight);
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(newOverlayWidth - oldOverlayWidth, 2) +
146 Math.pow(newHeight - oldHeight, 2)); 149 Math.pow(newOverlayHeight - oldOverlayHeight, 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.
not at google - send to devlin 2015/03/18 22:31:44 This comment no longer relevant.
151 animation = overlay.animate([ 156 animation = overlay.animate([
152 {width: oldWidth + 'px', height: oldHeight + 'px'}, 157 {width: oldOverlayWidth + 'px', height: oldOverlayHeight + 'px'},
153 {width: newWidth + 'px', height: newHeight + 'px'} 158 {width: newOverlayWidth + 'px', height: newOverlayHeight + 'px'}
154 ], { 159 ], {
155 duration: animationTime, 160 duration: animationTime,
156 delay: 0 161 delay: 0
157 }); 162 });
158 163
159 animation.onfinish = function(e) { 164 animation.onfinish = function(e) {
160 animation = null; 165 animation = null;
161 166
162 // The <extensionoptions> element is ready to place back in the 167 // 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 168 // overlay. Make sure that it's sized to take up the full width/height
164 // of the overlay. 169 // of the overlay.
165 overlayGuest.style.position = ''; 170 overlayGuest.style.position = '';
166 overlayGuest.style.left = ''; 171 overlayGuest.style.left = '';
167 overlayGuest.style.width = newWidth + 'px'; 172 overlayGuest.style.width = newOverlayWidth + 'px';
168 overlayGuest.style.height = newHeight + 'px'; 173 // |newOverlayHeight| includes the header height, so it needs to be
174 // subtracted to get the new guest height.
175 overlayGuest.style.height =
176 (newOverlayHeight - overlayHeader.offsetHeight) + 'px';
169 177
170 if (shownCallback) { 178 if (shownCallback) {
171 shownCallback(); 179 shownCallback();
172 shownCallback = null; 180 shownCallback = null;
173 } 181 }
174 }; 182 };
175 }.bind(this); 183 }.bind(this);
176 184
177 // Move the <extensionoptions> off screen until the overlay is ready. 185 // Move the <extensionoptions> off screen until the overlay is ready.
178 overlayGuest.style.position = 'fixed'; 186 overlayGuest.style.position = 'fixed';
(...skipping 20 matching lines...) Expand all
199 /** @type {HTMLDivElement} */($('extension-options-overlay')) : 207 /** @type {HTMLDivElement} */($('extension-options-overlay')) :
200 null); 208 null);
201 } 209 }
202 }; 210 };
203 211
204 // Export 212 // Export
205 return { 213 return {
206 ExtensionOptionsOverlay: ExtensionOptionsOverlay 214 ExtensionOptionsOverlay: ExtensionOptionsOverlay
207 }; 215 };
208 }); 216 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698