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

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

Issue 2224673002: MD Settings: simplify animation scheduling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'settings-section' shows a paper material themed section with a header 7 * 'settings-section' shows a paper material themed section with a header
8 * which shows its page title. 8 * which shows its page title.
9 * 9 *
10 * The section can expand vertically to fill its container's padding edge. 10 * The section can expand vertically to fill its container's padding edge.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 canAnimateExpand: function() { 88 canAnimateExpand: function() {
89 return !this.classList.contains('expanded'); 89 return !this.classList.contains('expanded');
90 }, 90 },
91 91
92 /** 92 /**
93 * Animates the section expanding to fill the container. The section is fixed 93 * Animates the section expanding to fill the container. The section is fixed
94 * in the viewport during the animation. The section adds the "expanding" 94 * in the viewport during the animation. The section adds the "expanding"
95 * class while the animation plays. 95 * class while the animation plays.
96 * 96 *
97 * @param {!HTMLElement} container The scrolling container to fill. 97 * @param {!HTMLElement} container The scrolling container to fill.
98 * @return {?SettingsSectionElement.AnimationConfig} 98 * @return {?settings.animation.Animation} Animation played, if any.
99 */ 99 */
100 animateExpand: function(container) { 100 animateExpand: function(container) {
101 var card = this.$.card; 101 var card = this.$.card;
102 102
103 // The card should start at the top of the page. 103 // The card should start at the top of the page.
104 var targetTop = container.getBoundingClientRect().top; 104 var targetTop = container.getBoundingClientRect().top;
105 105
106 this.classList.add('expanding'); 106 this.classList.add('expanding');
107 107
108 // Nothing to animate. 108 // Nothing to animate.
(...skipping 10 matching lines...) Expand all
119 minHeight: card.style.height, 119 minHeight: card.style.height,
120 easing: EASING_FUNCTION, 120 easing: EASING_FUNCTION,
121 }, { 121 }, {
122 top: targetTop + 'px', 122 top: targetTop + 'px',
123 minHeight: 'calc(100% - ' + targetTop + 'px)', 123 minHeight: 'calc(100% - ' + targetTop + 'px)',
124 }]; 124 }];
125 var options = /** @type {!KeyframeEffectOptions} */({ 125 var options = /** @type {!KeyframeEffectOptions} */({
126 duration: EXPAND_DURATION 126 duration: EXPAND_DURATION
127 }); 127 });
128 // TODO(michaelpg): Change elevation of sections. 128 // TODO(michaelpg): Change elevation of sections.
129 return {card: card, keyframes: keyframes, options: options}; 129 return new settings.animation.Animation(card, keyframes, options);
130 }, 130 },
131 131
132 /** 132 /**
133 * Cleans up after animateExpand(). 133 * Cleans up after animateExpand().
134 * @param {boolean} finished Whether the animation finished successfully. 134 * @param {boolean} finished Whether the animation finished successfully.
135 */ 135 */
136 cleanUpAnimateExpand: function(finished) { 136 cleanUpAnimateExpand: function(finished) {
137 if (finished) { 137 if (finished) {
138 this.classList.add('expanded'); 138 this.classList.add('expanded');
139 this.$.card.style.top = ''; 139 this.$.card.style.top = '';
(...skipping 10 matching lines...) Expand all
150 canAnimateCollapse: function() { 150 canAnimateCollapse: function() {
151 return this.classList.contains('expanded'); 151 return this.classList.contains('expanded');
152 }, 152 },
153 153
154 /** 154 /**
155 * Collapses an expanded section's card back into position in the main page. 155 * Collapses an expanded section's card back into position in the main page.
156 * Adds the "expanding" class during the animation. 156 * Adds the "expanding" class during the animation.
157 * @param {!HTMLElement} container The scrolling container the card fills. 157 * @param {!HTMLElement} container The scrolling container the card fills.
158 * @param {number} prevScrollTop scrollTop of the container before this 158 * @param {number} prevScrollTop scrollTop of the container before this
159 * section expanded. 159 * section expanded.
160 * @return {?SettingsSectionElement.AnimationConfig} 160 * @return {?settings.animation.Animation} Animation played, if any.
161 */ 161 */
162 animateCollapse: function(container, prevScrollTop) { 162 animateCollapse: function(container, prevScrollTop) {
163 this.$.header.hidden = false; 163 this.$.header.hidden = false;
164 164
165 var startingTop = container.getBoundingClientRect().top; 165 var startingTop = container.getBoundingClientRect().top;
166 166
167 var card = this.$.card; 167 var card = this.$.card;
168 var cardHeightStart = card.clientHeight; 168 var cardHeightStart = card.clientHeight;
169 var cardWidthStart = card.clientWidth; 169 var cardWidthStart = card.clientWidth;
170 170
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 }, { 202 }, {
203 top: targetTop + 'px', 203 top: targetTop + 'px',
204 minHeight: card.origHeight_ + 'px', 204 minHeight: card.origHeight_ + 'px',
205 }]; 205 }];
206 var options = /** @type {!KeyframeEffectOptions} */({ 206 var options = /** @type {!KeyframeEffectOptions} */({
207 duration: EXPAND_DURATION 207 duration: EXPAND_DURATION
208 }); 208 });
209 209
210 card.style.width = cardWidthStart + 'px'; 210 card.style.width = cardWidthStart + 'px';
211 211
212 return {card: card, keyframes: keyframes, options: options}; 212 return new settings.animation.Animation(card, keyframes, options);
213 }, 213 },
214 214
215 /** 215 /**
216 * Cleans up after animateCollapse(). 216 * Cleans up after animateCollapse().
217 * @param {boolean} finished Whether the animation finished successfully. 217 * @param {boolean} finished Whether the animation finished successfully.
218 */ 218 */
219 cleanUpAnimateCollapse: function(finished) { 219 cleanUpAnimateCollapse: function(finished) {
220 if (finished) 220 if (finished)
221 this.$.card.style.width = ''; 221 this.$.card.style.width = '';
222 }, 222 },
223 }); 223 });
224
225 /**
226 * Information needed by TransitionBehavior to schedule animations.
227 * @typedef {{
228 * card: !HTMLElement,
229 * keyframes: !Array<!Object>,
230 * options: !KeyframeEffectOptions
231 * }}
232 */
233 SettingsSectionElement.AnimationConfig;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698