Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/resources/settings/settings_page/settings_animated_pages.js

Issue 2224163002: Settings Router Refactor: Replace route.subpage usage with route.path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (!this.queuedRouteChange_) 59 if (!this.queuedRouteChange_)
60 return; 60 return;
61 this.async(this.currentRouteChanged.bind( 61 this.async(this.currentRouteChanged.bind(
62 this, 62 this,
63 this.queuedRouteChange_.newRoute, 63 this.queuedRouteChange_.newRoute,
64 this.queuedRouteChange_.oldRoute)); 64 this.queuedRouteChange_.oldRoute));
65 }, 65 },
66 66
67 /** @protected */ 67 /** @protected */
68 currentRouteChanged: function(newRoute, oldRoute) { 68 currentRouteChanged: function(newRoute, oldRoute) {
69 if (newRoute.section == this.section && newRoute.subpage.length > 0) { 69 if (newRoute.section == this.section && newRoute.isSubpage()) {
70 this.switchToSubpage_(newRoute, oldRoute); 70 this.switchToSubpage_(newRoute, oldRoute);
71 } else { 71 } else {
72 this.$.animatedPages.exitAnimation = 'fade-out-animation'; 72 this.$.animatedPages.exitAnimation = 'fade-out-animation';
73 this.$.animatedPages.entryAnimation = 'fade-in-animation'; 73 this.$.animatedPages.entryAnimation = 'fade-in-animation';
74 this.$.animatedPages.selected = 'main'; 74 this.$.animatedPages.selected = 'default';
michaelpg 2016/08/10 18:45:52 THANK YOU. i've learned never to use "main" or "pa
tommycli 2016/08/10 18:52:18 Acknowledged. I debated with myself for a while as
75 } 75 }
76 }, 76 },
77 77
78 /** 78 /**
79 * Selects the subpage specified by |newRoute|. 79 * Selects the subpage specified by |newRoute|.
80 * @param {!settings.Route} newRoute 80 * @param {!settings.Route} newRoute
81 * @param {!settings.Route} oldRoute 81 * @param {!settings.Route} oldRoute
82 * @private 82 * @private
83 */ 83 */
84 switchToSubpage_: function(newRoute, oldRoute) { 84 switchToSubpage_: function(newRoute, oldRoute) {
85 // Don't manipulate the light DOM until it's ready. 85 // Don't manipulate the light DOM until it's ready.
86 if (!this.lightDomReady_) { 86 if (!this.lightDomReady_) {
87 this.queuedRouteChange_ = this.queuedRouteChange_ || {oldRoute: oldRoute}; 87 this.queuedRouteChange_ = this.queuedRouteChange_ || {oldRoute: oldRoute};
88 this.queuedRouteChange_.newRoute = newRoute; 88 this.queuedRouteChange_.newRoute = newRoute;
89 return; 89 return;
90 } 90 }
91 91
92 this.ensureSubpageInstance_(); 92 this.ensureSubpageInstance_();
93 93
94 if (oldRoute) { 94 if (oldRoute) {
95 var oldRouteIsSubpage = oldRoute.subpage.length > 0; 95 if (oldRoute.isSubpage() && oldRoute.contains(newRoute)) {
96 if (oldRouteIsSubpage && oldRoute.contains(newRoute)) {
97 // Slide left for a descendant subpage. 96 // Slide left for a descendant subpage.
98 this.$.animatedPages.exitAnimation = 'slide-left-animation'; 97 this.$.animatedPages.exitAnimation = 'slide-left-animation';
99 this.$.animatedPages.entryAnimation = 'slide-from-right-animation'; 98 this.$.animatedPages.entryAnimation = 'slide-from-right-animation';
100 } else if (newRoute.contains(oldRoute)) { 99 } else if (newRoute.contains(oldRoute)) {
101 // Slide right for an ancestor subpage. 100 // Slide right for an ancestor subpage.
102 this.$.animatedPages.exitAnimation = 'slide-right-animation'; 101 this.$.animatedPages.exitAnimation = 'slide-right-animation';
103 this.$.animatedPages.entryAnimation = 'slide-from-left-animation'; 102 this.$.animatedPages.entryAnimation = 'slide-from-left-animation';
104 } else { 103 } else {
105 // The old route is not a subpage or is at the same level, so just fade. 104 // The old route is not a subpage or is at the same level, so just fade.
106 this.$.animatedPages.exitAnimation = 'fade-out-animation'; 105 this.$.animatedPages.exitAnimation = 'fade-out-animation';
107 this.$.animatedPages.entryAnimation = 'fade-in-animation'; 106 this.$.animatedPages.entryAnimation = 'fade-in-animation';
108 107
109 if (!oldRouteIsSubpage) { 108 if (!oldRoute.isSubpage()) {
110 // Set the height the expand animation should start at before 109 // Set the height the expand animation should start at before
111 // beginning the transition to the new subpage. 110 // beginning the transition to the new subpage.
112 // TODO(michaelpg): Remove MainPageBehavior's dependency on this 111 // TODO(michaelpg): Remove MainPageBehavior's dependency on this
113 // height being set. 112 // height being set.
114 this.style.height = this.clientHeight + 'px'; 113 this.style.height = this.clientHeight + 'px';
115 this.async(function() { 114 this.async(function() {
116 this.style.height = ''; 115 this.style.height = '';
117 }); 116 });
118 } 117 }
119 } 118 }
120 } 119 }
121 120
122 this.$.animatedPages.selected = newRoute.subpage.slice(-1)[0]; 121 this.$.animatedPages.selected = newRoute.path;
123 }, 122 },
124 123
125 /** 124 /**
126 * Ensures that the template enclosing the subpage is stamped. 125 * Ensures that the template enclosing the subpage is stamped.
127 * @private 126 * @private
128 */ 127 */
129 ensureSubpageInstance_: function() { 128 ensureSubpageInstance_: function() {
130 var id = settings.getCurrentRoute().subpage.slice(-1)[0]; 129 var routePath = settings.getCurrentRoute().path;
131 var template = Polymer.dom(this).querySelector( 130 var template = Polymer.dom(this).querySelector(
132 'template[name="' + id + '"]'); 131 'template[route-path="' + routePath + '"]');
133 132
134 // Nothing to do if the subpage isn't wrapped in a <template> or the 133 // Nothing to do if the subpage isn't wrapped in a <template> or the
135 // template is already stamped. 134 // template is already stamped.
136 if (!template || template.if) 135 if (!template || template.if)
137 return; 136 return;
138 137
139 // Set the subpage's id for use by neon-animated-pages. 138 // Set the subpage's id for use by neon-animated-pages.
140 var subpage = /** @type {{_content: DocumentFragment}} */(template)._content 139 var subpage = /** @type {{_content: DocumentFragment}} */(template)._content
141 .querySelector('settings-subpage'); 140 .querySelector('settings-subpage');
142 if (!subpage.id) 141 subpage.setAttribute('route-path', routePath);
143 subpage.id = id; 142
144 // Carry over the 'no-search' attribute from the template to the stamped 143 // Carry over the 'no-search' attribute from the template to the stamped
145 // instance, such that the stamped instance will also be ignored by the 144 // instance, such that the stamped instance will also be ignored by the
146 // searching algorithm. 145 // searching algorithm.
147 if (template.hasAttribute('no-search')) 146 if (template.hasAttribute('no-search'))
148 subpage.setAttribute('no-search', ''); 147 subpage.setAttribute('no-search', '');
149 148
150 // Render synchronously so neon-animated-pages can select the subpage. 149 // Render synchronously so neon-animated-pages can select the subpage.
151 template.if = true; 150 template.if = true;
152 template.render(); 151 template.render();
153 }, 152 },
154 }); 153 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698