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 var canAnimateCollapse = section.canAnimateCollapse(); | 213 var canAnimateCollapse = section.canAnimateCollapse(); |
214 if (canAnimateCollapse) { | 214 if (canAnimateCollapse) { |
215 this.toggleScrolling_(false); | 215 this.fire('freeze-scroll', true); |
216 // Do the initial collapse setup, which takes the section out of the flow, | 216 // Do the initial collapse setup, which takes the section out of the flow, |
217 // before showing everything. | 217 // before showing everything. |
218 section.setUpAnimateCollapse(this.scroller); | 218 section.setUpAnimateCollapse(this.scroller); |
219 } else { | 219 } else { |
220 section.classList.remove('expanded'); | 220 section.classList.remove('expanded'); |
221 } | 221 } |
222 | 222 |
223 // Show everything. | 223 // Show everything. |
224 this.toggleOtherSectionsHidden_(section.section, false); | 224 this.toggleOtherSectionsHidden_(section.section, false); |
225 this.classList.remove('showing-subpage'); | 225 this.classList.remove('showing-subpage'); |
(...skipping 16 matching lines...) Expand all Loading... |
242 this.currentAnimation_ = section.animateCollapse( | 242 this.currentAnimation_ = section.animateCollapse( |
243 /** @type {!HTMLElement} */(this.scroller)); | 243 /** @type {!HTMLElement} */(this.scroller)); |
244 | 244 |
245 this.currentAnimation_.finished.catch(function() { | 245 this.currentAnimation_.finished.catch(function() { |
246 // The collapse was canceled, so the page is showing a subpage still. | 246 // The collapse was canceled, so the page is showing a subpage still. |
247 this.fire('subpage-expand'); | 247 this.fire('subpage-expand'); |
248 }.bind(this)).then(function() { | 248 }.bind(this)).then(function() { |
249 // Clean up after the animation succeeds or cancels. | 249 // Clean up after the animation succeeds or cancels. |
250 section.setFrozen(false); | 250 section.setFrozen(false); |
251 section.classList.remove('collapsing'); | 251 section.classList.remove('collapsing'); |
252 this.toggleScrolling_(true); | 252 this.fire('freeze-scroll', false); |
253 this.currentAnimation_ = null; | 253 this.currentAnimation_ = null; |
254 resolve(); | 254 resolve(); |
255 }.bind(this)); | 255 }.bind(this)); |
256 }.bind(this)); | 256 }.bind(this)); |
257 }.bind(this)); | 257 }.bind(this)); |
258 }, | 258 }, |
259 | 259 |
260 /** | 260 /** |
261 /** | 261 /** |
262 * Hides or unhides the sections not being expanded. | 262 * Hides or unhides the sections not being expanded. |
(...skipping 12 matching lines...) Expand all Loading... |
275 * Helper function to get a section from the local DOM. | 275 * Helper function to get a section from the local DOM. |
276 * @param {string} section Section name of the element to get. | 276 * @param {string} section Section name of the element to get. |
277 * @return {?SettingsSectionElement} | 277 * @return {?SettingsSectionElement} |
278 */ | 278 */ |
279 getSection: function(section) { | 279 getSection: function(section) { |
280 if (!section) | 280 if (!section) |
281 return null; | 281 return null; |
282 return /** @type {?SettingsSectionElement} */( | 282 return /** @type {?SettingsSectionElement} */( |
283 this.$$('settings-section[section="' + section + '"]')); | 283 this.$$('settings-section[section="' + section + '"]')); |
284 }, | 284 }, |
285 | |
286 /** | |
287 * Enables or disables user scrolling, via overscroll: hidden. Room for the | |
288 * hidden scrollbar is added to prevent the page width from changing back and | |
289 * forth. | |
290 * @param {boolean} enabled | |
291 * @private | |
292 */ | |
293 toggleScrolling_: function(enabled) { | |
294 if (enabled) { | |
295 this.scroller.style.overflow = ''; | |
296 this.scroller.style.width = ''; | |
297 } else { | |
298 var scrollerWidth = this.scroller.clientWidth; | |
299 this.scroller.style.overflow = 'hidden'; | |
300 var scrollbarWidth = this.scroller.clientWidth - scrollerWidth; | |
301 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)'; | |
302 } | |
303 } | |
304 }; | 285 }; |
305 | 286 |
306 /** @polymerBehavior */ | 287 /** @polymerBehavior */ |
307 var MainPageBehavior = [ | 288 var MainPageBehavior = [ |
308 settings.RouteObserverBehavior, | 289 settings.RouteObserverBehavior, |
309 MainPageBehaviorImpl, | 290 MainPageBehaviorImpl, |
310 ]; | 291 ]; |
OLD | NEW |