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

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

Issue 2825203003: MD Settings: Remove subpage animation when landing directly on it. (Closed)
Patch Set: fix compiler error Created 3 years, 7 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 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 */
(...skipping 12 matching lines...) Expand all
23 /** 23 /**
24 * 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
25 * being displayed. 25 * being displayed.
26 * @private {boolean} 26 * @private {boolean}
27 */ 27 */
28 inSearchMode: { 28 inSearchMode: {
29 type: Boolean, 29 type: Boolean,
30 value: false, 30 value: false,
31 observer: 'inSearchModeChanged_', 31 observer: 'inSearchModeChanged_',
32 }, 32 },
33
34 // Whether to hide parent container during loading state.
35 shouldHideContainer: {type: Boolean, value: false, notify: true},
dpapad 2017/05/03 17:47:20 Let's add a trailing comma after "notify: true" wh
33 }, 36 },
34 37
35 /** @type {?HTMLElement} The scrolling container. */ 38 /** @type {?HTMLElement} The scrolling container. */
36 scroller: null, 39 scroller: null,
37 40
38 listeners: { 41 listeners: {'neon-animation-finish': 'onNeonAnimationFinish_'},
39 'neon-animation-finish': 'onNeonAnimationFinish_'
40 },
41 42
42 /** @override */ 43 /** @override */
43 attached: function() { 44 attached: function() {
44 this.scroller = this.domHost ? this.domHost.parentNode : document.body; 45 this.scroller = this.domHost ? this.domHost.parentNode : document.body;
45 }, 46 },
46 47
47 /** 48 /**
48 * Remove the is-animating attribute once the animation is complete. 49 * Remove the is-animating attribute once the animation is complete.
49 * This may catch animations finishing more often than needed, which is not 50 * This may catch animations finishing more often than needed, which is not
50 * known to cause any issues (e.g. when animating from a shallower page to a 51 * known to cause any issues (e.g. when animating from a shallower page to a
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 88
88 // TODO(dschuyler): This doesn't set the flag in the case of going to or 89 // TODO(dschuyler): This doesn't set the flag in the case of going to or
89 // from the main page. It seems sensible to set the flag in those cases, 90 // from the main page. It seems sensible to set the flag in those cases,
90 // unfortunately bug 708465 happens. Figure out why that is and then set 91 // unfortunately bug 708465 happens. Figure out why that is and then set
91 // this flag more broadly. 92 // this flag more broadly.
92 if (oldRoute && oldRoute.isSubpage() && newRoute.isSubpage()) 93 if (oldRoute && oldRoute.isSubpage() && newRoute.isSubpage())
93 this.isSubpageAnimating = true; 94 this.isSubpageAnimating = true;
94 95
95 // For previously uncreated pages (including on first load), allow the page 96 // For previously uncreated pages (including on first load), allow the page
96 // to render before scrolling to or expanding the section. 97 // to render before scrolling to or expanding the section.
97 if (!oldRoute || this.scrollHeight == 0) 98 if (!oldRoute || this.scrollHeight == 0) {
98 setTimeout(this.tryTransitionToSection_.bind(this, scrollToSection)); 99 this.shouldHideContainer = true;
99 else 100 setTimeout(function() {
101 this.shouldHideContainer = false;
102 this.tryTransitionToSection_(scrollToSection, true);
103 }.bind(this));
104 } else
100 this.tryTransitionToSection_(scrollToSection); 105 this.tryTransitionToSection_(scrollToSection);
101 }, 106 },
102 107
103 /** 108 /**
104 * When exiting search mode, we need to make another attempt to scroll to 109 * When exiting search mode, we need to make another attempt to scroll to
105 * the correct section, since it has just been re-rendered. 110 * the correct section, since it has just been re-rendered.
106 * @private 111 * @private
107 */ 112 */
108 inSearchModeChanged_: function(inSearchMode) { 113 inSearchModeChanged_: function(inSearchMode) {
109 if (!this.isAttached) 114 if (!this.isAttached)
110 return; 115 return;
111 116
112 if (!inSearchMode) 117 if (!inSearchMode)
113 this.tryTransitionToSection_(!settings.lastRouteChangeWasPopstate()); 118 this.tryTransitionToSection_(!settings.lastRouteChangeWasPopstate());
114 }, 119 },
115 120
116 /** 121 /**
117 * If possible, transitions to the current route's section (by expanding or 122 * If possible, transitions to the current route's section (by expanding or
118 * scrolling to it). If another transition is running, finishes or cancels 123 * scrolling to it). If another transition is running, finishes or cancels
119 * that one, then schedules this function again. This ensures the current 124 * that one, then schedules this function again. This ensures the current
120 * section is quickly shown, without getting the page into a broken state -- 125 * section is quickly shown, without getting the page into a broken state --
121 * if currentRoute changes in between calls, just transition to the new route. 126 * if currentRoute changes in between calls, just transition to the new route.
122 * @param {boolean} scrollToSection 127 * @param {boolean} scrollToSection
128 * @param {boolean=} immediate Whether to instantly expand instead of animate.
123 * @private 129 * @private
124 */ 130 */
125 tryTransitionToSection_: function(scrollToSection) { 131 tryTransitionToSection_: function(scrollToSection, immediate) {
126 var currentRoute = settings.getCurrentRoute(); 132 var currentRoute = settings.getCurrentRoute();
127 var currentSection = this.getSection(currentRoute.section); 133 var currentSection = this.getSection(currentRoute.section);
128 134
129 // If an animation is already playing, try finishing or canceling it. 135 // If an animation is already playing, try finishing or canceling it.
130 if (this.currentAnimation_) { 136 if (this.currentAnimation_) {
131 this.maybeStopCurrentAnimation_(); 137 this.maybeStopCurrentAnimation_();
132 // Either way, this function will be called again once the current 138 // Either way, this function will be called again once the current
133 // animation ends. 139 // animation ends.
134 return; 140 return;
135 } 141 }
136 142
137 var promise; 143 var promise;
138 var expandedSection = /** @type {?SettingsSectionElement} */( 144 var expandedSection = /** @type {?SettingsSectionElement} */(
139 this.$$('settings-section.expanded')); 145 this.$$('settings-section.expanded'));
140 if (expandedSection) { 146 if (expandedSection) {
141 // If the section shouldn't be expanded, collapse it. 147 // If the section shouldn't be expanded, collapse it.
142 if (!currentRoute.isSubpage() || expandedSection != currentSection) { 148 if (!currentRoute.isSubpage() || expandedSection != currentSection) {
143 promise = this.collapseSection_(expandedSection); 149 promise = this.collapseSection_(expandedSection);
144 } else { 150 } else {
145 // Scroll to top while sliding to another subpage. 151 // Scroll to top while sliding to another subpage.
146 this.scroller.scrollTop = 0; 152 this.scroller.scrollTop = 0;
147 } 153 }
148 } else if (currentSection) { 154 } else if (currentSection) {
149 // Expand the section into a subpage or scroll to it on the main page. 155 // Expand the section into a subpage or scroll to it on the main page.
150 if (currentRoute.isSubpage()) 156 if (currentRoute.isSubpage())
151 promise = this.expandSection_(currentSection); 157 if (immediate)
158 this.expandSectionImmediate_(currentSection);
159 else
160 promise = this.expandSection_(currentSection);
152 else if (scrollToSection) 161 else if (scrollToSection)
153 currentSection.scrollIntoView(); 162 currentSection.scrollIntoView();
154 } else if ( 163 } else if (
155 this.tagName == 'SETTINGS-BASIC-PAGE' && 164 this.tagName == 'SETTINGS-BASIC-PAGE' &&
156 settings.Route.ADVANCED.contains(currentRoute) && 165 settings.Route.ADVANCED.contains(currentRoute) &&
157 // Need to exclude routes that correspond to 'non-sectioned' children of 166 // Need to exclude routes that correspond to 'non-sectioned' children of
158 // ADVANCED, otherwise tryTransitionToSection_ will recurse endlessly. 167 // ADVANCED, otherwise tryTransitionToSection_ will recurse endlessly.
159 !currentRoute.isNavigableDialog) { 168 !currentRoute.isNavigableDialog) {
160 assert(currentRoute.section); 169 assert(currentRoute.section);
170 // Hide the container again while Advanecd Page template is being loaded.
171 this.shouldHideContainer = true;
161 promise = this.$$('#advancedPageTemplate').get(); 172 promise = this.$$('#advancedPageTemplate').get();
162 } 173 }
163 174
164 // When this animation ends, another may be necessary. Call this function 175 // When this animation ends, another may be necessary. Call this function
165 // again after the promise resolves. 176 // again after the promise resolves.
166 if (promise) 177 if (promise) {
167 promise.then(this.tryTransitionToSection_.bind(this, scrollToSection)); 178 promise.then(this.tryTransitionToSection_.bind(this, scrollToSection))
179 .then(function() {
180 this.shouldHideContainer = false;
181 }.bind(this));
182 }
168 }, 183 },
169 184
170 /** 185 /**
171 * If the current animation is inconsistent with the current route, stops the 186 * If the current animation is inconsistent with the current route, stops the
172 * animation by finishing or canceling it so the new route can be animated to. 187 * animation by finishing or canceling it so the new route can be animated to.
173 * @private 188 * @private
174 */ 189 */
175 maybeStopCurrentAnimation_: function() { 190 maybeStopCurrentAnimation_: function() {
176 var currentRoute = settings.getCurrentRoute(); 191 var currentRoute = settings.getCurrentRoute();
177 var animatingSection = /** @type {?SettingsSectionElement} */( 192 var animatingSection = /** @type {?SettingsSectionElement} */(
(...skipping 21 matching lines...) Expand all
199 this.currentAnimation_.cancel(); 214 this.currentAnimation_.cancel();
200 return; 215 return;
201 } 216 }
202 217
203 // The current route is a subpage, so that section needs to expand. 218 // The current route is a subpage, so that section needs to expand.
204 // Immediately finish the current collapse animation so that can happen. 219 // Immediately finish the current collapse animation so that can happen.
205 this.currentAnimation_.finish(); 220 this.currentAnimation_.finish();
206 }, 221 },
207 222
208 /** 223 /**
224 * Immediately expand the card in |section| to fill the page.
225 * @param {!SettingsSectionElement} section
226 * @private
227 */
228 expandSectionImmediate_: function(section) {
229 assert(this.scroller);
230 section.immediateExpand(this.scroller);
231 this.finishedExpanding_(section);
232 //TODO(scottchen): iron-list inside subpages need this to render correctly.
233 this.fire('resize');
234 },
235
236 /**
209 * Animates the card in |section|, expanding it to fill the page. 237 * Animates the card in |section|, expanding it to fill the page.
210 * @param {!SettingsSectionElement} section 238 * @param {!SettingsSectionElement} section
211 * @return {!Promise} Resolved when the transition is finished or canceled. 239 * @return {!Promise} Resolved when the transition is finished or canceled.
212 * @private 240 * @private
213 */ 241 */
214 expandSection_: function(section) { 242 expandSection_: function(section) {
215 assert(this.scroller); 243 assert(this.scroller);
216
217 if (!section.canAnimateExpand()) { 244 if (!section.canAnimateExpand()) {
218 // Try to wait for the section to be created. 245 // Try to wait for the section to be created.
219 return new Promise(function(resolve, reject) { 246 return new Promise(function(resolve, reject) {
220 setTimeout(resolve); 247 setTimeout(resolve);
221 }); 248 });
222 } 249 }
223 250
224 // Save the scroller position before freezing it. 251 // Save the scroller position before freezing it.
225 this.origScrollTop_ = this.scroller.scrollTop; 252 this.origScrollTop_ = this.scroller.scrollTop;
226 this.fire('freeze-scroll', true); 253 this.fire('freeze-scroll', true);
227 254
228 // Freeze the section's height so its card can be removed from the flow. 255 // Freeze the section's height so its card can be removed from the flow.
229 section.setFrozen(true); 256 section.setFrozen(true);
230 257
231 this.currentAnimation_ = section.animateExpand(this.scroller); 258 this.currentAnimation_ = section.animateExpand(this.scroller);
232 259
233 var finished; 260 return this.currentAnimation_.finished
234 return this.currentAnimation_.finished.then(function() { 261 .then(
235 // Hide other sections and scroll to the top of the subpage. 262 function() {
236 this.classList.add('showing-subpage'); 263 this.finishedExpanding_(section);
237 this.toggleOtherSectionsHidden_(section.section, true); 264 }.bind(this),
238 this.scroller.scrollTop = 0; 265 function() {
239 section.setFrozen(false); 266 // The animation was canceled; restore the section and scroll
267 // position.
268 section.setFrozen(false);
269 this.scroller.scrollTop = this.origScrollTop_;
270 }.bind(this))
271 .then(function() {
272 this.fire('freeze-scroll', false);
273 this.currentAnimation_ = null;
274 }.bind(this));
275 },
240 276
241 // Notify that the page is fully expanded. 277 /** @private */
242 this.fire('subpage-expand'); 278 finishedExpanding_: function(section) {
279 // Hide other sections and scroll to the top of the subpage.
280 this.classList.add('showing-subpage');
281 this.toggleOtherSectionsHidden_(section.section, true);
282 this.scroller.scrollTop = 0;
283 section.setFrozen(false);
243 284
244 finished = true; 285 // Notify that the page is fully expanded.
245 }.bind(this), function() { 286 this.fire('subpage-expand');
246 // The animation was canceled; restore the section and scroll position.
247 section.setFrozen(false);
248 this.scroller.scrollTop = this.origScrollTop_;
249
250 finished = false;
251 }.bind(this)).then(function() {
252 this.fire('freeze-scroll', false);
253 this.currentAnimation_ = null;
254 }.bind(this));
255 }, 287 },
256 288
257 /** 289 /**
258 * Animates the card in |section|, collapsing it back into its section. 290 * Animates the card in |section|, collapsing it back into its section.
259 * @param {!SettingsSectionElement} section 291 * @param {!SettingsSectionElement} section
260 * @return {!Promise} Resolved when the transition is finished or canceled. 292 * @return {!Promise} Resolved when the transition is finished or canceled.
261 */ 293 */
262 collapseSection_: function(section) { 294 collapseSection_: function(section) {
263 assert(this.scroller); 295 assert(this.scroller);
264 assert(section.classList.contains('expanded')); 296 assert(section.classList.contains('expanded'));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 return /** @type {?SettingsSectionElement} */( 381 return /** @type {?SettingsSectionElement} */(
350 this.$$('settings-section[section="' + section + '"]')); 382 this.$$('settings-section[section="' + section + '"]'));
351 }, 383 },
352 }; 384 };
353 385
354 /** @polymerBehavior */ 386 /** @polymerBehavior */
355 var MainPageBehavior = [ 387 var MainPageBehavior = [
356 settings.RouteObserverBehavior, 388 settings.RouteObserverBehavior,
357 MainPageBehaviorImpl, 389 MainPageBehaviorImpl,
358 ]; 390 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698