Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-animated-pages' is a container for a page and animated subpages. | 7 * 'settings-animated-pages' is a container for a page and animated subpages. |
| 8 * It provides a set of common behaviors and animations. | 8 * It provides a set of common behaviors and animations. |
| 9 * | 9 * |
| 10 * Example: | 10 * Example: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 if (!this.queuedRouteChange_) | 71 if (!this.queuedRouteChange_) |
| 72 return; | 72 return; |
| 73 this.async(this.currentRouteChanged_.bind( | 73 this.async(this.currentRouteChanged_.bind( |
| 74 this, | 74 this, |
| 75 this.queuedRouteChange_.newRoute, | 75 this.queuedRouteChange_.newRoute, |
| 76 this.queuedRouteChange_.oldRoute)); | 76 this.queuedRouteChange_.oldRoute)); |
| 77 }, | 77 }, |
| 78 | 78 |
| 79 /** @private */ | 79 /** @private */ |
| 80 currentRouteChanged_: function(newRoute, oldRoute) { | 80 currentRouteChanged_: function(newRoute, oldRoute) { |
| 81 if (newRoute.section == this.section && newRoute.subpage.length > 0) { | |
|
michaelpg
2016/08/01 08:37:14
this saves some work, since all <settings-animated
| |
| 82 this.switchToSubpage_(newRoute, oldRoute); | |
| 83 } else { | |
| 84 this.$.animatedPages.exitAnimation = 'fade-out-animation'; | |
| 85 this.$.animatedPages.entryAnimation = 'fade-in-animation'; | |
| 86 this.$.animatedPages.selected = 'main'; | |
| 87 } | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * Selects the subpage specified by |newRoute|. | |
| 92 * @param {!settings.Route} newRoute | |
| 93 * @param {!settings.Route} oldRoute | |
| 94 * @private | |
| 95 */ | |
| 96 switchToSubpage_: function(newRoute, oldRoute) { | |
| 81 // Don't manipulate the light DOM until it's ready. | 97 // Don't manipulate the light DOM until it's ready. |
| 82 if (!this.lightDomReady_) { | 98 if (!this.lightDomReady_) { |
| 83 this.queuedRouteChange_ = this.queuedRouteChange_ || {oldRoute: oldRoute}; | 99 this.queuedRouteChange_ = this.queuedRouteChange_ || {oldRoute: oldRoute}; |
| 84 this.queuedRouteChange_.newRoute = newRoute; | 100 this.queuedRouteChange_.newRoute = newRoute; |
| 85 return; | 101 return; |
| 86 } | 102 } |
| 87 | 103 |
| 88 var newRouteIsSubpage = newRoute && newRoute.subpage.length; | 104 this.ensureSubpageInstance_(); |
| 89 var oldRouteIsSubpage = oldRoute && oldRoute.subpage.length; | |
| 90 | 105 |
| 91 if (newRouteIsSubpage) | 106 if (oldRoute) { |
| 92 this.ensureSubpageInstance_(); | 107 var oldRouteIsSubpage = oldRoute.subpage.length > 0; |
| 93 | 108 if (oldRouteIsSubpage && oldRoute.contains(newRoute)) { |
| 94 if (!newRouteIsSubpage || !oldRouteIsSubpage || | 109 // Slide left for a descendant subpage. |
| 95 newRoute.subpage.length == oldRoute.subpage.length) { | |
| 96 // If two routes are at the same level, or if either the new or old route | |
| 97 // is not a subpage, fade in and out. | |
| 98 this.$.animatedPages.exitAnimation = 'fade-out-animation'; | |
| 99 this.$.animatedPages.entryAnimation = 'fade-in-animation'; | |
| 100 } else { | |
| 101 // For transitioning between subpages at different levels, slide. | |
| 102 if (newRoute.subpage.length > oldRoute.subpage.length) { | |
| 103 this.$.animatedPages.exitAnimation = 'slide-left-animation'; | 110 this.$.animatedPages.exitAnimation = 'slide-left-animation'; |
| 104 this.$.animatedPages.entryAnimation = 'slide-from-right-animation'; | 111 this.$.animatedPages.entryAnimation = 'slide-from-right-animation'; |
| 105 } else { | 112 } else if (newRoute.contains(oldRoute)) { |
| 113 // Slide right for an ancestor subpage. | |
| 106 this.$.animatedPages.exitAnimation = 'slide-right-animation'; | 114 this.$.animatedPages.exitAnimation = 'slide-right-animation'; |
| 107 this.$.animatedPages.entryAnimation = 'slide-from-left-animation'; | 115 this.$.animatedPages.entryAnimation = 'slide-from-left-animation'; |
| 116 } else { | |
| 117 // The old route is not a subpage or is at the same level, so just fade. | |
| 118 this.$.animatedPages.exitAnimation = 'fade-out-animation'; | |
| 119 this.$.animatedPages.entryAnimation = 'fade-in-animation'; | |
| 120 | |
| 121 if (!oldRouteIsSubpage) { | |
| 122 // Set the height the expand animation should start at before | |
| 123 // beginning the transition to the new subpage. | |
| 124 // TODO(michaelpg): Remove MainPageBehavior's dependency on this | |
| 125 // height being set. | |
| 126 this.style.height = this.clientHeight + 'px'; | |
| 127 } | |
| 108 } | 128 } |
| 109 } | 129 } |
| 110 | 130 |
| 111 if (newRouteIsSubpage && newRoute.section == this.section) { | 131 this.$.animatedPages.selected = newRoute.subpage.slice(-1)[0]; |
| 112 if (!oldRouteIsSubpage) { | |
| 113 // Set the height the expand animation should start at before beginning | |
| 114 // the transition to the new sub-page. | |
| 115 // TODO(michaelpg): Remove MainPageBehavior's dependency on this height | |
| 116 // being set. | |
| 117 this.style.height = this.clientHeight + 'px'; | |
| 118 } | |
| 119 this.$.animatedPages.selected = newRoute.subpage.slice(-1)[0]; | |
| 120 } else { | |
| 121 this.$.animatedPages.selected = 'main'; | |
| 122 } | |
| 123 }, | 132 }, |
| 124 | 133 |
| 125 /** | 134 /** |
| 126 * Ensures that the template enclosing the subpage is stamped. | 135 * Ensures that the template enclosing the subpage is stamped. |
| 127 * @private | 136 * @private |
| 128 */ | 137 */ |
| 129 ensureSubpageInstance_: function() { | 138 ensureSubpageInstance_: function() { |
| 130 var id = this.currentRoute.subpage.slice(-1)[0]; | 139 var id = this.currentRoute.subpage.slice(-1)[0]; |
| 131 var template = Polymer.dom(this).querySelector( | 140 var template = Polymer.dom(this).querySelector( |
| 132 'template[name="' + id + '"]'); | 141 'template[name="' + id + '"]'); |
| 133 | 142 |
| 134 // Nothing to do if the subpage isn't wrapped in a <template> or the | 143 // Nothing to do if the subpage isn't wrapped in a <template> or the |
| 135 // template is already stamped. | 144 // template is already stamped. |
| 136 if (!template || template.if) | 145 if (!template || template.if) |
| 137 return; | 146 return; |
| 138 | 147 |
| 139 // Set the subpage's id for use by neon-animated-pages. | 148 // Set the subpage's id for use by neon-animated-pages. |
| 140 var subpage = /** @type {{_content: DocumentFragment}} */(template)._content | 149 var subpage = /** @type {{_content: DocumentFragment}} */(template)._content |
| 141 .querySelector('settings-subpage'); | 150 .querySelector('settings-subpage'); |
| 142 if (!subpage.id) | 151 if (!subpage.id) |
| 143 subpage.id = id; | 152 subpage.id = id; |
| 144 | 153 |
| 145 // Render synchronously so neon-animated-pages can select the subpage. | 154 // Render synchronously so neon-animated-pages can select the subpage. |
| 146 template.if = true; | 155 template.if = true; |
| 147 template.render(); | 156 template.render(); |
| 148 }, | 157 }, |
| 149 }); | 158 }); |
| OLD | NEW |