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 * Responds to route changes by expanding, collapsing, or scrolling to sections | 6 * Responds to route changes by expanding, collapsing, or scrolling to sections |
7 * on the page. Expanded sections take up the full height of the container. At | 7 * on the page. Expanded sections take up the full height of the container. At |
8 * most one section should be expanded at any given time. | 8 * most one section should be expanded at any given time. |
9 * @polymerBehavior MainPageBehavior | 9 * @polymerBehavior MainPageBehavior |
10 */ | 10 */ |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return; | 68 return; |
69 } | 69 } |
70 | 70 |
71 var promise; | 71 var promise; |
72 var expandedSection = /** @type {?SettingsSectionElement} */( | 72 var expandedSection = /** @type {?SettingsSectionElement} */( |
73 this.$$('settings-section.expanded')); | 73 this.$$('settings-section.expanded')); |
74 if (expandedSection) { | 74 if (expandedSection) { |
75 // If the section shouldn't be expanded, collapse it. | 75 // If the section shouldn't be expanded, collapse it. |
76 if (!currentRoute.isSubpage() || expandedSection != currentSection) { | 76 if (!currentRoute.isSubpage() || expandedSection != currentSection) { |
77 promise = this.collapseSection_(expandedSection); | 77 promise = this.collapseSection_(expandedSection); |
78 // Scroll to the collapsed section. | |
79 if (currentSection && scrollToSection) | |
80 currentSection.scrollIntoView(); | |
81 } else { | 78 } else { |
82 // Scroll to top while sliding to another subpage. | 79 // Scroll to top while sliding to another subpage. |
83 this.scroller.scrollTop = 0; | 80 this.scroller.scrollTop = 0; |
84 } | 81 } |
85 } else if (currentSection) { | 82 } else if (currentSection) { |
86 // Expand the section into a subpage or scroll to it on the main page. | 83 // Expand the section into a subpage or scroll to it on the main page. |
87 if (currentRoute.isSubpage()) | 84 if (currentRoute.isSubpage()) |
88 promise = this.expandSection_(currentSection); | 85 promise = this.expandSection_(currentSection); |
89 else if (scrollToSection) | 86 else if (scrollToSection) |
90 currentSection.scrollIntoView(); | 87 currentSection.scrollIntoView(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return Promise.resolve(); | 217 return Promise.resolve(); |
221 } | 218 } |
222 | 219 |
223 // Play the actual collapse animation. | 220 // Play the actual collapse animation. |
224 return new Promise(function(resolve, reject) { | 221 return new Promise(function(resolve, reject) { |
225 // Wait for the other sections to show up so we can scroll properly. | 222 // Wait for the other sections to show up so we can scroll properly. |
226 setTimeout(function() { | 223 setTimeout(function() { |
227 var newSection = settings.getCurrentRoute().section && | 224 var newSection = settings.getCurrentRoute().section && |
228 this.getSection(settings.getCurrentRoute().section); | 225 this.getSection(settings.getCurrentRoute().section); |
229 | 226 |
230 this.scroller.scrollTop = this.origScrollTop_; | 227 // Scroll to the new section or the original position. |
| 228 if (newSection && !settings.lastRouteChangeWasPopstate()) |
| 229 newSection.scrollIntoView(); |
| 230 else |
| 231 this.scroller.scrollTop = this.origScrollTop_; |
231 | 232 |
232 this.currentAnimation_ = section.animateCollapse( | 233 this.currentAnimation_ = section.animateCollapse( |
233 /** @type {!HTMLElement} */(this.scroller)); | 234 /** @type {!HTMLElement} */(this.scroller)); |
234 | 235 |
235 this.currentAnimation_.finished.catch(function() { | 236 this.currentAnimation_.finished.catch(function() { |
236 // The collapse was canceled, so the page is showing a subpage still. | 237 // The collapse was canceled, so the page is showing a subpage still. |
237 this.fire('subpage-expand'); | 238 this.fire('subpage-expand'); |
238 }.bind(this)).then(function() { | 239 }.bind(this)).then(function() { |
239 // Clean up after the animation succeeds or cancels. | 240 // Clean up after the animation succeeds or cancels. |
240 section.setFrozen(false); | 241 section.setFrozen(false); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 return /** @type {?SettingsSectionElement} */( | 273 return /** @type {?SettingsSectionElement} */( |
273 this.$$('settings-section[section="' + section + '"]')); | 274 this.$$('settings-section[section="' + section + '"]')); |
274 }, | 275 }, |
275 }; | 276 }; |
276 | 277 |
277 /** @polymerBehavior */ | 278 /** @polymerBehavior */ |
278 var MainPageBehavior = [ | 279 var MainPageBehavior = [ |
279 settings.RouteObserverBehavior, | 280 settings.RouteObserverBehavior, |
280 MainPageBehaviorImpl, | 281 MainPageBehaviorImpl, |
281 ]; | 282 ]; |
OLD | NEW |