OLD | NEW |
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 /** | 5 /** |
6 * Calls |readyTest| repeatedly until it returns true, then calls | 6 * Calls |readyTest| repeatedly until it returns true, then calls |
7 * |readyCallback|. | 7 * |readyCallback|. |
8 * @param {function():boolean} readyTest | 8 * @param {function():boolean} readyTest |
9 * @param {!Function} readyCallback | 9 * @param {!Function} readyCallback |
10 */ | 10 */ |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 if (!section.canAnimateExpand()) { | 164 if (!section.canAnimateExpand()) { |
165 // Try to wait for the section to be created. | 165 // Try to wait for the section to be created. |
166 return new Promise(function(resolve, reject) { | 166 return new Promise(function(resolve, reject) { |
167 setTimeout(resolve); | 167 setTimeout(resolve); |
168 }); | 168 }); |
169 } | 169 } |
170 | 170 |
171 // Save the scroller position before freezing it. | 171 // Save the scroller position before freezing it. |
172 this.origScrollTop_ = this.scroller.scrollTop; | 172 this.origScrollTop_ = this.scroller.scrollTop; |
173 this.toggleScrolling_(false); | 173 this.fire('freeze-scroll', true); |
174 | 174 |
175 // Freeze the section's height so its card can be removed from the flow. | 175 // Freeze the section's height so its card can be removed from the flow. |
176 section.setFrozen(true); | 176 section.setFrozen(true); |
177 | 177 |
178 this.currentAnimation_ = section.animateExpand(this.scroller); | 178 this.currentAnimation_ = section.animateExpand(this.scroller); |
179 | 179 |
180 var finished; | 180 var finished; |
181 return this.currentAnimation_.finished.then(function() { | 181 return this.currentAnimation_.finished.then(function() { |
182 // Hide other sections and scroll to the top of the subpage. | 182 // Hide other sections and scroll to the top of the subpage. |
183 this.classList.add('showing-subpage'); | 183 this.classList.add('showing-subpage'); |
184 this.toggleOtherSectionsHidden_(section.section, true); | 184 this.toggleOtherSectionsHidden_(section.section, true); |
185 this.scroller.scrollTop = 0; | 185 this.scroller.scrollTop = 0; |
186 section.setFrozen(false); | 186 section.setFrozen(false); |
187 | 187 |
188 // Notify that the page is fully expanded. | 188 // Notify that the page is fully expanded. |
189 this.fire('subpage-expand'); | 189 this.fire('subpage-expand'); |
190 | 190 |
191 finished = true; | 191 finished = true; |
192 }.bind(this), function() { | 192 }.bind(this), function() { |
193 // The animation was canceled; restore the section and scroll position. | 193 // The animation was canceled; restore the section and scroll position. |
194 section.setFrozen(false); | 194 section.setFrozen(false); |
195 this.scroller.scrollTop = this.origScrollTop_; | 195 this.scroller.scrollTop = this.origScrollTop_; |
196 | 196 |
197 finished = false; | 197 finished = false; |
198 }.bind(this)).then(function() { | 198 }.bind(this)).then(function() { |
199 this.toggleScrolling_(true); | 199 this.fire('freeze-scroll', false); |
200 this.currentAnimation_ = null; | 200 this.currentAnimation_ = null; |
201 }.bind(this)); | 201 }.bind(this)); |
202 }, | 202 }, |
203 | 203 |
204 /** | 204 /** |
205 * Animates the card in |section|, collapsing it back into its section. | 205 * Animates the card in |section|, collapsing it back into its section. |
206 * @param {!SettingsSectionElement} section | 206 * @param {!SettingsSectionElement} section |
207 * @return {!Promise} Resolved when the transition is finished or canceled. | 207 * @return {!Promise} Resolved when the transition is finished or canceled. |
208 */ | 208 */ |
209 collapseSection_: function(section) { | 209 collapseSection_: function(section) { |
210 assert(this.scroller); | 210 assert(this.scroller); |
211 assert(section.classList.contains('expanded')); | 211 assert(section.classList.contains('expanded')); |
212 | 212 |
213 // Don't animate the collapse if we are transitioning between Basic/Advanced | 213 // Don't animate the collapse if we are transitioning between Basic/Advanced |
214 // and About, since the section won't be visible. | 214 // and About, since the section won't be visible. |
215 var needAnimate = | 215 var needAnimate = |
216 settings.Route.ABOUT.contains(settings.getCurrentRoute()) == | 216 settings.Route.ABOUT.contains(settings.getCurrentRoute()) == |
217 (section.domHost.tagName == 'SETTINGS-ABOUT-PAGE'); | 217 (section.domHost.tagName == 'SETTINGS-ABOUT-PAGE'); |
218 | 218 |
219 // Animate the collapse if the section knows the original height, except | 219 // Animate the collapse if the section knows the original height, except |
220 // when switching between Basic/Advanced and About. | 220 // when switching between Basic/Advanced and About. |
221 var shouldAnimateCollapse = needAnimate && section.canAnimateCollapse(); | 221 var shouldAnimateCollapse = needAnimate && section.canAnimateCollapse(); |
222 if (shouldAnimateCollapse) { | 222 if (shouldAnimateCollapse) { |
223 this.toggleScrolling_(false); | 223 this.fire('freeze-scroll', true); |
224 // Do the initial collapse setup, which takes the section out of the flow, | 224 // Do the initial collapse setup, which takes the section out of the flow, |
225 // before showing everything. | 225 // before showing everything. |
226 section.setUpAnimateCollapse(this.scroller); | 226 section.setUpAnimateCollapse(this.scroller); |
227 } else { | 227 } else { |
228 section.classList.remove('expanded'); | 228 section.classList.remove('expanded'); |
229 } | 229 } |
230 | 230 |
231 // Show everything. | 231 // Show everything. |
232 this.toggleOtherSectionsHidden_(section.section, false); | 232 this.toggleOtherSectionsHidden_(section.section, false); |
233 this.classList.remove('showing-subpage'); | 233 this.classList.remove('showing-subpage'); |
(...skipping 16 matching lines...) Expand all Loading... |
250 this.currentAnimation_ = section.animateCollapse( | 250 this.currentAnimation_ = section.animateCollapse( |
251 /** @type {!HTMLElement} */(this.scroller)); | 251 /** @type {!HTMLElement} */(this.scroller)); |
252 | 252 |
253 this.currentAnimation_.finished.catch(function() { | 253 this.currentAnimation_.finished.catch(function() { |
254 // The collapse was canceled, so the page is showing a subpage still. | 254 // The collapse was canceled, so the page is showing a subpage still. |
255 this.fire('subpage-expand'); | 255 this.fire('subpage-expand'); |
256 }.bind(this)).then(function() { | 256 }.bind(this)).then(function() { |
257 // Clean up after the animation succeeds or cancels. | 257 // Clean up after the animation succeeds or cancels. |
258 section.setFrozen(false); | 258 section.setFrozen(false); |
259 section.classList.remove('collapsing'); | 259 section.classList.remove('collapsing'); |
260 this.toggleScrolling_(true); | 260 this.fire('freeze-scroll', false); |
261 this.currentAnimation_ = null; | 261 this.currentAnimation_ = null; |
262 resolve(); | 262 resolve(); |
263 }.bind(this)); | 263 }.bind(this)); |
264 }.bind(this)); | 264 }.bind(this)); |
265 }.bind(this)); | 265 }.bind(this)); |
266 }, | 266 }, |
267 | 267 |
268 /** | 268 /** |
269 /** | 269 /** |
270 * Hides or unhides the sections not being expanded. | 270 * Hides or unhides the sections not being expanded. |
(...skipping 12 matching lines...) Expand all Loading... |
283 * Helper function to get a section from the local DOM. | 283 * Helper function to get a section from the local DOM. |
284 * @param {string} section Section name of the element to get. | 284 * @param {string} section Section name of the element to get. |
285 * @return {?SettingsSectionElement} | 285 * @return {?SettingsSectionElement} |
286 */ | 286 */ |
287 getSection: function(section) { | 287 getSection: function(section) { |
288 if (!section) | 288 if (!section) |
289 return null; | 289 return null; |
290 return /** @type {?SettingsSectionElement} */( | 290 return /** @type {?SettingsSectionElement} */( |
291 this.$$('settings-section[section="' + section + '"]')); | 291 this.$$('settings-section[section="' + section + '"]')); |
292 }, | 292 }, |
293 | |
294 /** | |
295 * Enables or disables user scrolling, via overscroll: hidden. Room for the | |
296 * hidden scrollbar is added to prevent the page width from changing back and | |
297 * forth. | |
298 * @param {boolean} enabled | |
299 * @private | |
300 */ | |
301 toggleScrolling_: function(enabled) { | |
302 if (enabled) { | |
303 this.scroller.style.overflow = ''; | |
304 this.scroller.style.width = ''; | |
305 } else { | |
306 var scrollerWidth = this.scroller.clientWidth; | |
307 this.scroller.style.overflow = 'hidden'; | |
308 var scrollbarWidth = this.scroller.clientWidth - scrollerWidth; | |
309 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)'; | |
310 } | |
311 } | |
312 }; | 293 }; |
313 | 294 |
314 /** @polymerBehavior */ | 295 /** @polymerBehavior */ |
315 var MainPageBehavior = [ | 296 var MainPageBehavior = [ |
316 settings.RouteObserverBehavior, | 297 settings.RouteObserverBehavior, |
317 MainPageBehaviorImpl, | 298 MainPageBehaviorImpl, |
318 ]; | 299 ]; |
OLD | NEW |