| 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 21 matching lines...) Expand all Loading... |
| 32 /** @override */ | 32 /** @override */ |
| 33 attached: function() { | 33 attached: function() { |
| 34 if (this.domHost && this.domHost.parentNode.tagName == 'PAPER-HEADER-PANEL') | 34 if (this.domHost && this.domHost.parentNode.tagName == 'PAPER-HEADER-PANEL') |
| 35 this.scroller = this.domHost.parentNode.scroller; | 35 this.scroller = this.domHost.parentNode.scroller; |
| 36 else | 36 else |
| 37 this.scroller = document.body; // Used in unit tests. | 37 this.scroller = document.body; // Used in unit tests. |
| 38 }, | 38 }, |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * @param {!settings.Route} newRoute | 41 * @param {!settings.Route} newRoute |
| 42 * @param {!settings.Route} oldRoute | 42 * @param {settings.Route} oldRoute |
| 43 */ | 43 */ |
| 44 currentRouteChanged: function(newRoute, oldRoute) { | 44 currentRouteChanged: function(newRoute, oldRoute) { |
| 45 // Allow the page to load before expanding the section. TODO(michaelpg): | 45 // Allow the page to load before expanding the section. TODO(michaelpg): |
| 46 // Time this better when refactoring settings-animated-pages. | 46 // Time this better when refactoring settings-animated-pages. |
| 47 if (!oldRoute && newRoute.subpage.length) | 47 if (!oldRoute && newRoute.isSubpage()) |
| 48 setTimeout(this.tryTransitionToSection_.bind(this)); | 48 setTimeout(this.tryTransitionToSection_.bind(this)); |
| 49 else | 49 else |
| 50 this.tryTransitionToSection_(); | 50 this.tryTransitionToSection_(); |
| 51 }, | 51 }, |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * If possible, transitions to the current route's section (by expanding or | 54 * If possible, transitions to the current route's section (by expanding or |
| 55 * scrolling to it). If another transition is running, finishes or cancels | 55 * scrolling to it). If another transition is running, finishes or cancels |
| 56 * that one, then schedules this function again. This ensures the current | 56 * that one, then schedules this function again. This ensures the current |
| 57 * section is quickly shown, without getting the page into a broken state -- | 57 * section is quickly shown, without getting the page into a broken state -- |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 // Either way, this function will be called again once the current | 68 // Either way, this function will be called again once the current |
| 69 // animation ends. | 69 // animation ends. |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 | 72 |
| 73 var promise; | 73 var promise; |
| 74 var expandedSection = /** @type {?SettingsSectionElement} */( | 74 var expandedSection = /** @type {?SettingsSectionElement} */( |
| 75 this.$$('settings-section.expanded')); | 75 this.$$('settings-section.expanded')); |
| 76 if (expandedSection) { | 76 if (expandedSection) { |
| 77 // If the section shouldn't be expanded, collapse it. | 77 // If the section shouldn't be expanded, collapse it. |
| 78 if (!currentRoute.subpage.length || expandedSection != currentSection) { | 78 if (!currentRoute.isSubpage() || expandedSection != currentSection) { |
| 79 promise = this.collapseSection_(expandedSection); | 79 promise = this.collapseSection_(expandedSection); |
| 80 // Scroll to the collapsed section. TODO(michaelpg): This can look weird | 80 // Scroll to the collapsed section. TODO(michaelpg): This can look weird |
| 81 // because the collapse we just scheduled calculated its end target | 81 // because the collapse we just scheduled calculated its end target |
| 82 // based on the current scroll position. This bug existed before, and is | 82 // based on the current scroll position. This bug existed before, and is |
| 83 // fixed in the next patch by making the card position: absolute. | 83 // fixed in the next patch by making the card position: absolute. |
| 84 if (currentSection) | 84 if (currentSection) |
| 85 this.scrollToSection_(); | 85 this.scrollToSection_(); |
| 86 } | 86 } |
| 87 } else if (currentSection) { | 87 } else if (currentSection) { |
| 88 // Expand the section into a subpage or scroll to it on the main page. | 88 // Expand the section into a subpage or scroll to it on the main page. |
| 89 if (currentRoute.subpage.length) | 89 if (currentRoute.isSubpage()) |
| 90 promise = this.expandSection_(currentSection); | 90 promise = this.expandSection_(currentSection); |
| 91 else | 91 else |
| 92 this.scrollToSection_(); | 92 this.scrollToSection_(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // When this animation ends, another may be necessary. Call this function | 95 // When this animation ends, another may be necessary. Call this function |
| 96 // again after the promise resolves. | 96 // again after the promise resolves. |
| 97 if (promise) | 97 if (promise) |
| 98 promise.then(this.tryTransitionToSection_.bind(this)); | 98 promise.then(this.tryTransitionToSection_.bind(this)); |
| 99 }, | 99 }, |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * If the current animation is inconsistent with the current route, stops the | 102 * If the current animation is inconsistent with the current route, stops the |
| 103 * animation by finishing or canceling it so the new route can be animated to. | 103 * animation by finishing or canceling it so the new route can be animated to. |
| 104 * @private | 104 * @private |
| 105 */ | 105 */ |
| 106 maybeStopCurrentAnimation_: function() { | 106 maybeStopCurrentAnimation_: function() { |
| 107 var currentRoute = settings.getCurrentRoute(); | 107 var currentRoute = settings.getCurrentRoute(); |
| 108 var animatingSection = /** @type {?SettingsSectionElement} */( | 108 var animatingSection = /** @type {?SettingsSectionElement} */( |
| 109 this.$$('settings-section.expanding, settings-section.collapsing')); | 109 this.$$('settings-section.expanding, settings-section.collapsing')); |
| 110 assert(animatingSection); | 110 assert(animatingSection); |
| 111 | 111 |
| 112 if (animatingSection.classList.contains('expanding')) { | 112 if (animatingSection.classList.contains('expanding')) { |
| 113 // Cancel the animation to go back to the main page if the animating | 113 // Cancel the animation to go back to the main page if the animating |
| 114 // section shouldn't be expanded. | 114 // section shouldn't be expanded. |
| 115 if (animatingSection.section != currentRoute.section || | 115 if (animatingSection.section != currentRoute.section || |
| 116 !currentRoute.subpage.length) { | 116 !currentRoute.isSubpage()) { |
| 117 this.currentAnimation_.cancel(); | 117 this.currentAnimation_.cancel(); |
| 118 } | 118 } |
| 119 // Otherwise, let the expand animation continue. | 119 // Otherwise, let the expand animation continue. |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 assert(animatingSection.classList.contains('collapsing')); | 123 assert(animatingSection.classList.contains('collapsing')); |
| 124 if (!currentRoute.subpage.length) | 124 if (!currentRoute.isSubpage()) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 // If the collapsing section actually matches the current route's section, | 127 // If the collapsing section actually matches the current route's section, |
| 128 // we can just cancel the animation to re-expand the section. | 128 // we can just cancel the animation to re-expand the section. |
| 129 if (animatingSection.section == currentRoute.section) { | 129 if (animatingSection.section == currentRoute.section) { |
| 130 this.currentAnimation_.cancel(); | 130 this.currentAnimation_.cancel(); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // The current route is a subpage, so that section needs to expand. | 134 // The current route is a subpage, so that section needs to expand. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)'; | 262 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)'; |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 /** @polymerBehavior */ | 267 /** @polymerBehavior */ |
| 268 var MainPageBehavior = [ | 268 var MainPageBehavior = [ |
| 269 settings.RouteObserverBehavior, | 269 settings.RouteObserverBehavior, |
| 270 MainPageBehaviorImpl, | 270 MainPageBehaviorImpl, |
| 271 ]; | 271 ]; |
| OLD | NEW |