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 */ |
| 11 var MainPageBehaviorImpl = { | 11 var MainPageBehaviorImpl = { |
| 12 properties: { | 12 properties: { |
| 13 /** | 13 /** |
| 14 * Help CSS to alter style during the horizontal swipe animation. | |
| 15 * Note that this is unrelated to the |currentAnimation_| (which refers to | |
| 16 * the vertical exapand animation). | |
| 17 */ | |
| 18 isSubpageAnimating: { | |
| 19 reflectToAttribute: true, | |
| 20 type: Boolean, | |
| 21 }, | |
| 22 | |
| 23 /** | |
| 14 * Whether a search operation is in progress or previous search results are | 24 * Whether a search operation is in progress or previous search results are |
| 15 * being displayed. | 25 * being displayed. |
| 16 * @private {boolean} | 26 * @private {boolean} |
| 17 */ | 27 */ |
| 18 inSearchMode: { | 28 inSearchMode: { |
| 19 type: Boolean, | 29 type: Boolean, |
| 20 value: false, | 30 value: false, |
| 21 observer: 'inSearchModeChanged_', | 31 observer: 'inSearchModeChanged_', |
| 22 }, | 32 }, |
| 23 }, | 33 }, |
| 24 | 34 |
| 25 /** @type {?HTMLElement} The scrolling container. */ | 35 /** @type {?HTMLElement} The scrolling container. */ |
| 26 scroller: null, | 36 scroller: null, |
| 27 | 37 |
| 38 listeners: { | |
| 39 'neon-animation-finish': 'onNeonAnimationFinish_' | |
| 40 }, | |
| 41 | |
| 28 /** @override */ | 42 /** @override */ |
| 29 attached: function() { | 43 attached: function() { |
| 30 if (this.domHost && this.domHost.parentNode.tagName == 'PAPER-HEADER-PANEL') | 44 if (this.domHost && this.domHost.parentNode.tagName == 'PAPER-HEADER-PANEL') |
| 31 this.scroller = this.domHost.parentNode.scroller; | 45 this.scroller = this.domHost.parentNode.scroller; |
| 32 else | 46 else |
| 33 this.scroller = document.body; // Used in unit tests. | 47 this.scroller = document.body; // Used in unit tests. |
| 34 }, | 48 }, |
| 35 | 49 |
| 36 /** | 50 /** |
| 51 * Remove the is-animating attribute once the animation is complete. | |
| 52 * This may catch unrelated animations finishing. | |
| 53 * @private | |
| 54 */ | |
| 55 onNeonAnimationFinish_: function() { | |
| 56 this.isSubpageAnimating = false; | |
| 57 }, | |
| 58 | |
| 59 /** | |
| 37 * @param {!settings.Route} newRoute | 60 * @param {!settings.Route} newRoute |
| 38 * @param {settings.Route} oldRoute | 61 * @param {settings.Route} oldRoute |
| 39 */ | 62 */ |
| 40 currentRouteChanged: function(newRoute, oldRoute) { | 63 currentRouteChanged: function(newRoute, oldRoute) { |
| 41 var oldRouteWasSection = | 64 var oldRouteWasSection = |
| 42 !!oldRoute && !!oldRoute.parent && !!oldRoute.section && | 65 !!oldRoute && !!oldRoute.parent && !!oldRoute.section && |
| 43 oldRoute.parent.section != oldRoute.section; | 66 oldRoute.parent.section != oldRoute.section; |
| 44 | 67 |
| 45 // Always scroll to the top if navigating from a section to the root route | 68 // Always scroll to the top if navigating from a section to the root route |
| 46 // or when navigating to the About page. | 69 // or when navigating to the About page. |
| 47 if (this.scroller && | 70 if (this.scroller && |
| 48 ((oldRouteWasSection && newRoute == settings.Route.BASIC) || | 71 ((oldRouteWasSection && newRoute == settings.Route.BASIC) || |
| 49 newRoute == settings.Route.ABOUT)) { | 72 newRoute == settings.Route.ABOUT)) { |
| 50 this.scroller.scrollTop = 0; | 73 this.scroller.scrollTop = 0; |
| 51 return; | 74 return; |
| 52 } | 75 } |
| 53 | 76 |
| 54 // Scroll to the section except for back/forward. Also scroll for any | 77 // Scroll to the section except for back/forward. Also scroll for any |
| 55 // in-page back/forward navigations (from a section or the root page). | 78 // in-page back/forward navigations (from a section or the root page). |
| 56 var scrollToSection = | 79 var scrollToSection = |
| 57 !settings.lastRouteChangeWasPopstate() || oldRouteWasSection || | 80 !settings.lastRouteChangeWasPopstate() || oldRouteWasSection || |
| 58 oldRoute == settings.Route.BASIC; | 81 oldRoute == settings.Route.BASIC; |
| 59 | 82 |
| 83 if (oldRoute && oldRoute.depth == 3 && oldRoute.depth > newRoute.depth) | |
|
Dan Beam
2017/03/18 00:53:26
why == 3?
dschuyler
2017/03/18 01:02:31
How about isSubpage() and I remove the 3.
| |
| 84 this.isSubpageAnimating = true; | |
| 85 | |
| 60 // For previously uncreated pages (including on first load), allow the page | 86 // For previously uncreated pages (including on first load), allow the page |
| 61 // to render before scrolling to or expanding the section. | 87 // to render before scrolling to or expanding the section. |
| 62 if (!oldRoute || this.scrollHeight == 0) | 88 if (!oldRoute || this.scrollHeight == 0) |
| 63 setTimeout(this.tryTransitionToSection_.bind(this, scrollToSection)); | 89 setTimeout(this.tryTransitionToSection_.bind(this, scrollToSection)); |
| 64 else | 90 else |
| 65 this.tryTransitionToSection_(scrollToSection); | 91 this.tryTransitionToSection_(scrollToSection); |
| 66 }, | 92 }, |
| 67 | 93 |
| 68 /** | 94 /** |
| 69 * When exiting search mode, we need to make another attempt to scroll to | 95 * When exiting search mode, we need to make another attempt to scroll to |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 return /** @type {?SettingsSectionElement} */( | 330 return /** @type {?SettingsSectionElement} */( |
| 305 this.$$('settings-section[section="' + section + '"]')); | 331 this.$$('settings-section[section="' + section + '"]')); |
| 306 }, | 332 }, |
| 307 }; | 333 }; |
| 308 | 334 |
| 309 /** @polymerBehavior */ | 335 /** @polymerBehavior */ |
| 310 var MainPageBehavior = [ | 336 var MainPageBehavior = [ |
| 311 settings.RouteObserverBehavior, | 337 settings.RouteObserverBehavior, |
| 312 MainPageBehaviorImpl, | 338 MainPageBehaviorImpl, |
| 313 ]; | 339 ]; |
| OLD | NEW |