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

Side by Side Diff: chrome/browser/resources/settings/settings_page/main_page_behavior.js

Issue 1962943002: MD Settings: Fix minor vertical jumps in animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@AnimationFixes
Patch Set: Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // Fast out, slow in. 5 // Fast out, slow in.
6 var EASING_FUNCTION = 'cubic-bezier(0.4, 0, 0.2, 1)'; 6 var EASING_FUNCTION = 'cubic-bezier(0.4, 0, 0.2, 1)';
7 var EXPAND_DURATION = 350; 7 var EXPAND_DURATION = 350;
8 8
9 /** 9 /**
10 * Provides animations to expand and collapse individual sections in a page. 10 * Provides animations to expand and collapse individual sections in a page.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 }, 257 },
258 258
259 /** 259 /**
260 * Collapses the card in |section| back to its normal position. 260 * Collapses the card in |section| back to its normal position.
261 * @param {!SettingsSectionElement} section 261 * @param {!SettingsSectionElement} section
262 * @return {!Promise} 262 * @return {!Promise}
263 * @private 263 * @private
264 */ 264 */
265 playCollapseSection_: function(section) { 265 playCollapseSection_: function(section) {
266 var card = section.$.card; 266 var card = section.$.card;
267 var cardStyle = getComputedStyle(card);
268 267
269 this.style.margin = ''; 268 this.style.margin = '';
270 section.$.header.hidden = false; 269 section.$.header.hidden = false;
271 270
272 var startingTop = this.parentElement.getBoundingClientRect().top; 271 var startingTop = this.parentElement.getBoundingClientRect().top;
273 272
274 var cardHeightStart = card.clientHeight; 273 var cardHeightStart = card.clientHeight;
275 274
276 section.classList.add('collapsing'); 275 section.classList.add('collapsing');
277 section.classList.remove('expanding', 'expanded'); 276 section.classList.remove('expanding', 'expanded');
278 277
279 // If we navigated here directly, we don't know the original height of the 278 // If we navigated here directly, we don't know the original height of the
280 // section, so we skip the animation. 279 // section, so we skip the animation.
281 // TODO(michaelpg): remove this condition once sliding is implemented. 280 // TODO(michaelpg): remove this condition once sliding is implemented.
282 if (isNaN(card.origHeight_)) 281 if (isNaN(card.origHeight_))
283 return Promise.resolve(); 282 return Promise.resolve();
284 283
285 // Restore the section to its proper height to make room for the card. 284 // Restore the section to its proper height to make room for the card.
286 section.style.height = section.clientHeight + card.origHeight_ + 'px'; 285 section.style.height = section.clientHeight + card.origHeight_ + 'px';
287 286
288 // TODO(michaelpg): this should be in collapseSection(), but we need to wait 287 // TODO(michaelpg): this should be in collapseSection(), but we need to wait
289 // until the full page height is available (setting the section height). 288 // until the full page height is available (setting the section height).
290 this.scroller.scrollTop = this.listScrollTop_; 289 this.scroller.scrollTop = this.listScrollTop_;
291 290
292 // The card is unpositioned, so use its position as the ending state, 291 // The card is unpositioned, so use its position as the ending state,
293 // but account for scroll. 292 // but account for scroll.
294 var targetTop = card.getBoundingClientRect().top - this.scroller.scrollTop; 293 var targetTop = card.getBoundingClientRect().top - this.scroller.scrollTop;
295 294
295 // Account for the section header.
296 targetTop += section.$.header.offsetHeight +
297 parseInt(getComputedStyle(section.$.header).marginBottom) +
dpapad 2016/05/09 23:35:53 Let's pass 10 as the 2nd parameter of parseInt(),
michaelpg 2016/05/10 00:36:18 Done.
298 parseInt(getComputedStyle(section.$.header).marginTop);
dpapad 2016/05/09 23:35:53 Guessing that getComputedStyles() calls are simply
michaelpg 2016/05/10 00:36:18 Done (i thought so but i can't verify it)
299
296 var keyframes = [{ 300 var keyframes = [{
297 top: startingTop + 'px', 301 top: startingTop + 'px',
298 minHeight: cardHeightStart + 'px', 302 minHeight: cardHeightStart + 'px',
299 easing: EASING_FUNCTION, 303 easing: EASING_FUNCTION,
300 }, { 304 }, {
301 top: targetTop + 'px', 305 top: targetTop + 'px',
302 minHeight: card.origHeight_ + 'px', 306 minHeight: card.origHeight_ + 'px',
303 }]; 307 }];
304 var options = /** @type {!KeyframeEffectOptions} */({ 308 var options = /** @type {!KeyframeEffectOptions} */({
305 duration: EXPAND_DURATION 309 duration: EXPAND_DURATION
306 }); 310 });
307 var promise = this.animateElement('section', card, keyframes, options); 311 var promise = this.animateElement('section', card, keyframes, options);
308 return promise; 312 return promise;
dpapad 2016/05/09 23:35:53 Nit: Inline unnecessary local var. return this.an
michaelpg 2016/05/10 00:36:18 Done.
309 }, 313 },
310 }; 314 };
311 315
312 316
313 /** @polymerBehavior */ 317 /** @polymerBehavior */
314 var MainPageBehavior = [ 318 var MainPageBehavior = [
315 TransitionBehavior, 319 TransitionBehavior,
316 MainPageBehaviorImpl 320 MainPageBehaviorImpl
317 ]; 321 ];
318 322
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 this.$$('[section=' + section + ']')); 396 this.$$('[section=' + section + ']'));
393 }, 397 },
394 }; 398 };
395 399
396 400
397 /** @polymerBehavior */ 401 /** @polymerBehavior */
398 var RoutableBehavior = [ 402 var RoutableBehavior = [
399 MainPageBehavior, 403 MainPageBehavior,
400 RoutableBehaviorImpl 404 RoutableBehaviorImpl
401 ]; 405 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698