Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 inSearchMode: { | 28 inSearchMode: { |
| 29 type: Boolean, | 29 type: Boolean, |
| 30 value: false, | 30 value: false, |
| 31 observer: 'inSearchModeChanged_', | 31 observer: 'inSearchModeChanged_', |
| 32 }, | 32 }, |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 /** @type {?HTMLElement} The scrolling container. */ | 35 /** @type {?HTMLElement} The scrolling container. */ |
| 36 scroller: null, | 36 scroller: null, |
| 37 | 37 |
| 38 listeners: { | 38 listeners: {'neon-animation-finish': 'onNeonAnimationFinish_'}, |
| 39 'neon-animation-finish': 'onNeonAnimationFinish_' | |
| 40 }, | |
| 41 | 39 |
| 42 /** @override */ | 40 /** @override */ |
| 43 attached: function() { | 41 attached: function() { |
| 44 this.scroller = this.domHost ? this.domHost.parentNode : document.body; | 42 this.scroller = this.domHost ? this.domHost.parentNode : document.body; |
| 45 }, | 43 }, |
| 46 | 44 |
| 47 /** | 45 /** |
| 48 * Remove the is-animating attribute once the animation is complete. | 46 * Remove the is-animating attribute once the animation is complete. |
| 49 * This may catch animations finishing more often than needed, which is not | 47 * This may catch animations finishing more often than needed, which is not |
| 50 * known to cause any issues (e.g. when animating from a shallower page to a | 48 * known to cause any issues (e.g. when animating from a shallower page to a |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 // Also always scroll when coming from either the About or root page. | 81 // Also always scroll when coming from either the About or root page. |
| 84 var scrollToSection = !settings.lastRouteChangeWasPopstate() || | 82 var scrollToSection = !settings.lastRouteChangeWasPopstate() || |
| 85 oldRouteWasSection || oldRoute == settings.Route.BASIC || | 83 oldRouteWasSection || oldRoute == settings.Route.BASIC || |
| 86 oldRoute == settings.Route.ABOUT; | 84 oldRoute == settings.Route.ABOUT; |
| 87 | 85 |
| 88 if (oldRoute && (oldRoute.isSubpage() || newRoute.isSubpage())) | 86 if (oldRoute && (oldRoute.isSubpage() || newRoute.isSubpage())) |
| 89 this.isSubpageAnimating = true; | 87 this.isSubpageAnimating = true; |
| 90 | 88 |
| 91 // For previously uncreated pages (including on first load), allow the page | 89 // For previously uncreated pages (including on first load), allow the page |
| 92 // to render before scrolling to or expanding the section. | 90 // to render before scrolling to or expanding the section. |
| 93 if (!oldRoute || this.scrollHeight == 0) | 91 if (!oldRoute || this.scrollHeight == 0) { |
| 94 setTimeout(this.tryTransitionToSection_.bind(this, scrollToSection)); | 92 document.body.querySelector('settings-ui::shadow #container') |
|
michaelpg
2017/04/22 04:01:58
::shadow makes me sad, is there no other way to ge
scottchen
2017/04/26 17:26:40
I changed settings-ui to pass a "shouldHideContain
| |
| 95 else | 93 .setAttribute('hidden', true); |
|
scottchen
2017/04/19 18:05:22
without this line, the basic page will briefly app
michaelpg
2017/04/22 04:01:58
Yeah, it's probably necessary unless we want to ma
scottchen
2017/04/26 17:26:40
Acknowledged.
| |
| 94 setTimeout( | |
| 95 this.tryTransitionToSection_.bind(this, scrollToSection, true)); | |
| 96 } else | |
| 96 this.tryTransitionToSection_(scrollToSection); | 97 this.tryTransitionToSection_(scrollToSection); |
| 97 }, | 98 }, |
| 98 | 99 |
| 99 /** | 100 /** |
| 100 * When exiting search mode, we need to make another attempt to scroll to | 101 * When exiting search mode, we need to make another attempt to scroll to |
| 101 * the correct section, since it has just been re-rendered. | 102 * the correct section, since it has just been re-rendered. |
| 102 * @private | 103 * @private |
| 103 */ | 104 */ |
| 104 inSearchModeChanged_: function(inSearchMode) { | 105 inSearchModeChanged_: function(inSearchMode) { |
| 105 if (!this.isAttached) | 106 if (!this.isAttached) |
| 106 return; | 107 return; |
| 107 | 108 |
| 108 if (!inSearchMode) | 109 if (!inSearchMode) |
| 109 this.tryTransitionToSection_(!settings.lastRouteChangeWasPopstate()); | 110 this.tryTransitionToSection_(!settings.lastRouteChangeWasPopstate()); |
| 110 }, | 111 }, |
| 111 | 112 |
| 112 /** | 113 /** |
| 113 * If possible, transitions to the current route's section (by expanding or | 114 * If possible, transitions to the current route's section (by expanding or |
| 114 * scrolling to it). If another transition is running, finishes or cancels | 115 * scrolling to it). If another transition is running, finishes or cancels |
| 115 * that one, then schedules this function again. This ensures the current | 116 * that one, then schedules this function again. This ensures the current |
| 116 * section is quickly shown, without getting the page into a broken state -- | 117 * section is quickly shown, without getting the page into a broken state -- |
| 117 * if currentRoute changes in between calls, just transition to the new route. | 118 * if currentRoute changes in between calls, just transition to the new route. |
| 118 * @param {boolean} scrollToSection | 119 * @param {boolean} scrollToSection |
| 119 * @private | 120 * @private |
| 120 */ | 121 */ |
| 121 tryTransitionToSection_: function(scrollToSection) { | 122 tryTransitionToSection_: function(scrollToSection, immediate) { |
| 123 document.body.querySelector('settings-ui::shadow #container') | |
|
michaelpg
2017/04/22 04:01:58
Does this only take effect on the first call? Perh
scottchen
2017/04/26 17:26:40
Done.
| |
| 124 .removeAttribute('hidden'); | |
| 122 var currentRoute = settings.getCurrentRoute(); | 125 var currentRoute = settings.getCurrentRoute(); |
| 123 var currentSection = this.getSection(currentRoute.section); | 126 var currentSection = this.getSection(currentRoute.section); |
| 124 | 127 |
| 125 // If an animation is already playing, try finishing or canceling it. | 128 // If an animation is already playing, try finishing or canceling it. |
| 126 if (this.currentAnimation_) { | 129 if (this.currentAnimation_) { |
| 127 this.maybeStopCurrentAnimation_(); | 130 this.maybeStopCurrentAnimation_(); |
| 128 // Either way, this function will be called again once the current | 131 // Either way, this function will be called again once the current |
| 129 // animation ends. | 132 // animation ends. |
| 130 return; | 133 return; |
| 131 } | 134 } |
| 132 | 135 |
| 133 var promise; | 136 var promise; |
| 134 var expandedSection = /** @type {?SettingsSectionElement} */( | 137 var expandedSection = /** @type {?SettingsSectionElement} */( |
| 135 this.$$('settings-section.expanded')); | 138 this.$$('settings-section.expanded')); |
| 136 if (expandedSection) { | 139 if (expandedSection) { |
| 137 // If the section shouldn't be expanded, collapse it. | 140 // If the section shouldn't be expanded, collapse it. |
| 138 if (!currentRoute.isSubpage() || expandedSection != currentSection) { | 141 if (!currentRoute.isSubpage() || expandedSection != currentSection) { |
| 139 promise = this.collapseSection_(expandedSection); | 142 promise = this.collapseSection_(expandedSection); |
| 140 } else { | 143 } else { |
| 141 // Scroll to top while sliding to another subpage. | 144 // Scroll to top while sliding to another subpage. |
| 142 this.scroller.scrollTop = 0; | 145 this.scroller.scrollTop = 0; |
| 143 } | 146 } |
| 144 } else if (currentSection) { | 147 } else if (currentSection) { |
| 145 // Expand the section into a subpage or scroll to it on the main page. | 148 // Expand the section into a subpage or scroll to it on the main page. |
| 146 if (currentRoute.isSubpage()) | 149 if (currentRoute.isSubpage()) |
| 147 promise = this.expandSection_(currentSection); | 150 promise = this.expandSection_(currentSection, immediate); |
| 148 else if (scrollToSection) | 151 else if (scrollToSection) |
| 149 currentSection.scrollIntoView(); | 152 currentSection.scrollIntoView(); |
| 150 } else if ( | 153 } else if ( |
| 151 this.tagName == 'SETTINGS-BASIC-PAGE' && | 154 this.tagName == 'SETTINGS-BASIC-PAGE' && |
| 152 settings.Route.ADVANCED.contains(currentRoute) && | 155 settings.Route.ADVANCED.contains(currentRoute) && |
| 153 // Need to exclude routes that correspond to 'non-sectioned' children of | 156 // Need to exclude routes that correspond to 'non-sectioned' children of |
| 154 // ADVANCED, otherwise tryTransitionToSection_ will recurse endlessly. | 157 // ADVANCED, otherwise tryTransitionToSection_ will recurse endlessly. |
| 155 !currentRoute.isNavigableDialog) { | 158 !currentRoute.isNavigableDialog) { |
| 156 assert(currentRoute.section); | 159 assert(currentRoute.section); |
| 157 promise = this.$$('#advancedPageTemplate').get(); | 160 promise = this.$$('#advancedPageTemplate').get(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 // Immediately finish the current collapse animation so that can happen. | 203 // Immediately finish the current collapse animation so that can happen. |
| 201 this.currentAnimation_.finish(); | 204 this.currentAnimation_.finish(); |
| 202 }, | 205 }, |
| 203 | 206 |
| 204 /** | 207 /** |
| 205 * Animates the card in |section|, expanding it to fill the page. | 208 * Animates the card in |section|, expanding it to fill the page. |
| 206 * @param {!SettingsSectionElement} section | 209 * @param {!SettingsSectionElement} section |
| 207 * @return {!Promise} Resolved when the transition is finished or canceled. | 210 * @return {!Promise} Resolved when the transition is finished or canceled. |
| 208 * @private | 211 * @private |
| 209 */ | 212 */ |
| 210 expandSection_: function(section) { | 213 expandSection_: function(section, immediate) { |
| 211 assert(this.scroller); | 214 assert(this.scroller); |
| 212 | 215 |
| 216 if (immediate) { | |
| 217 section.immediateExpand(this.scroller); | |
| 218 | |
| 219 this.classList.add('showing-subpage'); | |
| 220 this.toggleOtherSectionsHidden_(section.section, true); | |
| 221 this.scroller.scrollTop = 0; | |
|
michaelpg
2017/04/22 04:01:58
when is this not starting at 0?
scottchen
2017/04/26 17:26:41
Never, this is not necessary. Removing.
| |
| 222 // Notify that the page is fully expanded. | |
| 223 this.fire('subpage-expand'); | |
| 224 return; | |
| 225 } | |
| 226 | |
| 213 if (!section.canAnimateExpand()) { | 227 if (!section.canAnimateExpand()) { |
| 214 // Try to wait for the section to be created. | 228 // Try to wait for the section to be created. |
|
michaelpg
2017/04/22 04:01:58
We *might* not need this anymore if the goal is to
scottchen
2017/04/26 17:26:40
Using !section.canAnimateExpand() to indicate firs
| |
| 215 return new Promise(function(resolve, reject) { | 229 return new Promise(function(resolve, reject) { |
| 216 setTimeout(resolve); | 230 setTimeout(resolve); |
| 217 }); | 231 }); |
| 218 } | 232 } |
| 219 | 233 |
| 220 // Save the scroller position before freezing it. | 234 // Save the scroller position before freezing it. |
| 221 this.origScrollTop_ = this.scroller.scrollTop; | 235 this.origScrollTop_ = this.scroller.scrollTop; |
| 222 this.fire('freeze-scroll', true); | 236 this.fire('freeze-scroll', true); |
| 223 | 237 |
| 224 // Freeze the section's height so its card can be removed from the flow. | 238 // Freeze the section's height so its card can be removed from the flow. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 return /** @type {?SettingsSectionElement} */( | 359 return /** @type {?SettingsSectionElement} */( |
| 346 this.$$('settings-section[section="' + section + '"]')); | 360 this.$$('settings-section[section="' + section + '"]')); |
| 347 }, | 361 }, |
| 348 }; | 362 }; |
| 349 | 363 |
| 350 /** @polymerBehavior */ | 364 /** @polymerBehavior */ |
| 351 var MainPageBehavior = [ | 365 var MainPageBehavior = [ |
| 352 settings.RouteObserverBehavior, | 366 settings.RouteObserverBehavior, |
| 353 MainPageBehaviorImpl, | 367 MainPageBehaviorImpl, |
| 354 ]; | 368 ]; |
| OLD | NEW |