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

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

Issue 2199723002: MD Settings: Minor refactor of settings-animated-pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@FixSubpageExpandStartHeight
Patch Set: rebase 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
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 this.async(function() {
128 this.style.height = '';
129 });
130 }
108 } 131 }
109 } 132 }
110 133
111 if (newRouteIsSubpage && newRoute.section == this.section) { 134 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 this.async(function() {
119 this.style.height = '';
120 });
121 }
122 this.$.animatedPages.selected = newRoute.subpage.slice(-1)[0];
123 } else {
124 this.$.animatedPages.selected = 'main';
125 }
126 }, 135 },
127 136
128 /** 137 /**
129 * Ensures that the template enclosing the subpage is stamped. 138 * Ensures that the template enclosing the subpage is stamped.
130 * @private 139 * @private
131 */ 140 */
132 ensureSubpageInstance_: function() { 141 ensureSubpageInstance_: function() {
133 var id = this.currentRoute.subpage.slice(-1)[0]; 142 var id = this.currentRoute.subpage.slice(-1)[0];
134 var template = Polymer.dom(this).querySelector( 143 var template = Polymer.dom(this).querySelector(
135 'template[name="' + id + '"]'); 144 'template[name="' + id + '"]');
136 145
137 // Nothing to do if the subpage isn't wrapped in a <template> or the 146 // Nothing to do if the subpage isn't wrapped in a <template> or the
138 // template is already stamped. 147 // template is already stamped.
139 if (!template || template.if) 148 if (!template || template.if)
140 return; 149 return;
141 150
142 // Set the subpage's id for use by neon-animated-pages. 151 // Set the subpage's id for use by neon-animated-pages.
143 var subpage = /** @type {{_content: DocumentFragment}} */(template)._content 152 var subpage = /** @type {{_content: DocumentFragment}} */(template)._content
144 .querySelector('settings-subpage'); 153 .querySelector('settings-subpage');
145 if (!subpage.id) 154 if (!subpage.id)
146 subpage.id = id; 155 subpage.id = id;
147 156
148 // Render synchronously so neon-animated-pages can select the subpage. 157 // Render synchronously so neon-animated-pages can select the subpage.
149 template.if = true; 158 template.if = true;
150 template.render(); 159 template.render();
151 }, 160 },
152 }); 161 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698