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

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

Issue 2297663008: MD Settings: Prevent unexpected scrolling to section on popstates. (Closed)
Patch Set: add test Created 4 years, 3 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 * 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 var promise; 83 var promise;
84 var expandedSection = /** @type {?SettingsSectionElement} */( 84 var expandedSection = /** @type {?SettingsSectionElement} */(
85 this.$$('settings-section.expanded')); 85 this.$$('settings-section.expanded'));
86 if (expandedSection) { 86 if (expandedSection) {
87 // If the section shouldn't be expanded, collapse it. 87 // If the section shouldn't be expanded, collapse it.
88 if (!currentRoute.isSubpage() || expandedSection != currentSection) { 88 if (!currentRoute.isSubpage() || expandedSection != currentSection) {
89 promise = this.collapseSection_(expandedSection); 89 promise = this.collapseSection_(expandedSection);
90 // Scroll to the collapsed section. 90 // Scroll to the collapsed section.
91 if (currentSection) 91 if (currentSection && !settings.lastRouteChangeWasPopstate())
92 currentSection.scrollIntoView(); 92 currentSection.scrollIntoView();
93 } 93 }
94 } else if (currentSection) { 94 } else if (currentSection) {
95 // Expand the section into a subpage or scroll to it on the main page. 95 // Expand the section into a subpage or scroll to it on the main page.
96 if (currentRoute.isSubpage()) 96 if (currentRoute.isSubpage())
97 promise = this.expandSection_(currentSection); 97 promise = this.expandSection_(currentSection);
98 else 98 else if (!settings.lastRouteChangeWasPopstate())
99 currentSection.scrollIntoView(); 99 currentSection.scrollIntoView();
100 } 100 }
101 101
102 // When this animation ends, another may be necessary. Call this function 102 // When this animation ends, another may be necessary. Call this function
103 // again after the promise resolves. 103 // again after the promise resolves.
104 if (promise) 104 if (promise)
105 promise.then(this.tryTransitionToSection_.bind(this)); 105 promise.then(this.tryTransitionToSection_.bind(this));
106 }, 106 },
107 107
108 /** 108 /**
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return Promise.resolve(); 221 return Promise.resolve();
222 } 222 }
223 223
224 // Play the actual collapse animation. 224 // Play the actual collapse animation.
225 return new Promise(function(resolve, reject) { 225 return new Promise(function(resolve, reject) {
226 // Wait for the other sections to show up so we can scroll properly. 226 // Wait for the other sections to show up so we can scroll properly.
227 setTimeout(function() { 227 setTimeout(function() {
228 var newSection = settings.getCurrentRoute().section && 228 var newSection = settings.getCurrentRoute().section &&
229 this.getSection(settings.getCurrentRoute().section); 229 this.getSection(settings.getCurrentRoute().section);
230 230
231 // Scroll to the section if indicated by the route. TODO(michaelpg): Is 231 this.scroller.scrollTop = this.origScrollTop_;
232 // this the right behavior, or should we return to the previous scroll
233 // position?
234 if (newSection)
235 newSection.scrollIntoView();
236 else
237 this.scroller.scrollTop = this.origScrollTop_;
238 232
239 this.currentAnimation_ = section.animateCollapse( 233 this.currentAnimation_ = section.animateCollapse(
240 /** @type {!HTMLElement} */(this.scroller)); 234 /** @type {!HTMLElement} */(this.scroller));
241 235
242 this.currentAnimation_.finished.catch(function() { 236 this.currentAnimation_.finished.catch(function() {
243 // The collapse was canceled, so the page is showing a subpage still. 237 // The collapse was canceled, so the page is showing a subpage still.
244 this.fire('subpage-expand'); 238 this.fire('subpage-expand');
245 }.bind(this)).then(function() { 239 }.bind(this)).then(function() {
246 // Clean up after the animation succeeds or cancels. 240 // Clean up after the animation succeeds or cancels.
247 section.setFrozen(false); 241 section.setFrozen(false);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)'; 292 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)';
299 } 293 }
300 } 294 }
301 }; 295 };
302 296
303 /** @polymerBehavior */ 297 /** @polymerBehavior */
304 var MainPageBehavior = [ 298 var MainPageBehavior = [
305 settings.RouteObserverBehavior, 299 settings.RouteObserverBehavior,
306 MainPageBehaviorImpl, 300 MainPageBehaviorImpl,
307 ]; 301 ];
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/route.js ('k') | chrome/test/data/webui/settings/route_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698