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

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

Issue 2274693003: [MD settings] scroll to section from URL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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 26 matching lines...) Expand all
37 this.scroller = document.body; // Used in unit tests. 37 this.scroller = document.body; // Used in unit tests.
38 }, 38 },
39 39
40 /** 40 /**
41 * @param {!settings.Route} newRoute 41 * @param {!settings.Route} newRoute
42 * @param {settings.Route} oldRoute 42 * @param {settings.Route} oldRoute
43 */ 43 */
44 currentRouteChanged: function(newRoute, oldRoute) { 44 currentRouteChanged: function(newRoute, oldRoute) {
45 // Allow the page to load before expanding the section. TODO(michaelpg): 45 // Allow the page to load before expanding the section. TODO(michaelpg):
46 // Time this better when refactoring settings-animated-pages. 46 // Time this better when refactoring settings-animated-pages.
47 if (!oldRoute && newRoute.isSubpage()) 47 if (!oldRoute && newRoute.isSubpage()) {
48 setTimeout(this.tryTransitionToSection_.bind(this)); 48 setTimeout(this.tryTransitionToSection_.bind(this));
49 else 49 } else {
50 this.tryTransitionToSection_(); 50 doWhenReady(
michaelpg 2016/08/24 22:01:59 can we change doWhenReady to run the callback imme
51 function() {
52 return this.scrollHeight > 0;
53 }.bind(this),
54 this.tryTransitionToSection_.bind(this));
55 }
51 }, 56 },
52 57
53 /** 58 /**
54 * If possible, transitions to the current route's section (by expanding or 59 * If possible, transitions to the current route's section (by expanding or
55 * scrolling to it). If another transition is running, finishes or cancels 60 * scrolling to it). If another transition is running, finishes or cancels
56 * that one, then schedules this function again. This ensures the current 61 * that one, then schedules this function again. This ensures the current
57 * section is quickly shown, without getting the page into a broken state -- 62 * section is quickly shown, without getting the page into a broken state --
58 * if currentRoute changes in between calls, just transition to the new route. 63 * if currentRoute changes in between calls, just transition to the new route.
59 * @private 64 * @private
60 */ 65 */
(...skipping 14 matching lines...) Expand all
75 this.$$('settings-section.expanded')); 80 this.$$('settings-section.expanded'));
76 if (expandedSection) { 81 if (expandedSection) {
77 // If the section shouldn't be expanded, collapse it. 82 // If the section shouldn't be expanded, collapse it.
78 if (!currentRoute.isSubpage() || expandedSection != currentSection) { 83 if (!currentRoute.isSubpage() || expandedSection != currentSection) {
79 promise = this.collapseSection_(expandedSection); 84 promise = this.collapseSection_(expandedSection);
80 // Scroll to the collapsed section. TODO(michaelpg): This can look weird 85 // Scroll to the collapsed section. TODO(michaelpg): This can look weird
81 // because the collapse we just scheduled calculated its end target 86 // because the collapse we just scheduled calculated its end target
82 // based on the current scroll position. This bug existed before, and is 87 // based on the current scroll position. This bug existed before, and is
83 // fixed in the next patch by making the card position: absolute. 88 // fixed in the next patch by making the card position: absolute.
84 if (currentSection) 89 if (currentSection)
85 this.scrollToSection_(); 90 currentSection.scrollIntoView();
86 } 91 }
87 } else if (currentSection) { 92 } else if (currentSection) {
88 // Expand the section into a subpage or scroll to it on the main page. 93 // Expand the section into a subpage or scroll to it on the main page.
89 if (currentRoute.isSubpage()) 94 if (currentRoute.isSubpage())
90 promise = this.expandSection_(currentSection); 95 promise = this.expandSection_(currentSection);
91 else 96 else
92 this.scrollToSection_(); 97 currentSection.scrollIntoView();
93 } 98 }
94 99
95 // When this animation ends, another may be necessary. Call this function 100 // When this animation ends, another may be necessary. Call this function
96 // again after the promise resolves. 101 // again after the promise resolves.
97 if (promise) 102 if (promise)
98 promise.then(this.tryTransitionToSection_.bind(this)); 103 promise.then(this.tryTransitionToSection_.bind(this));
99 }, 104 },
100 105
101 /** 106 /**
102 * If the current animation is inconsistent with the current route, stops the 107 * If the current animation is inconsistent with the current route, stops the
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 * @param {boolean} hidden Whether the sections should be hidden. 214 * @param {boolean} hidden Whether the sections should be hidden.
210 * @private 215 * @private
211 */ 216 */
212 toggleOtherSectionsHidden_: function(sectionName, hidden) { 217 toggleOtherSectionsHidden_: function(sectionName, hidden) {
213 var sections = Polymer.dom(this.root).querySelectorAll( 218 var sections = Polymer.dom(this.root).querySelectorAll(
214 'settings-section'); 219 'settings-section');
215 for (var section of sections) 220 for (var section of sections)
216 section.hidden = hidden && (section.section != sectionName); 221 section.hidden = hidden && (section.section != sectionName);
217 }, 222 },
218 223
219 /** @private */
220 scrollToSection_: function() {
221 doWhenReady(
222 function() {
223 return this.scrollHeight > 0;
224 }.bind(this),
225 function() {
226 // If the current section changes while we are waiting for the page to
227 // be ready, scroll to the newest requested section.
228 var section = this.getSection(settings.getCurrentRoute().section);
229 if (section)
230 section.scrollIntoView();
231 }.bind(this));
232 },
233
234 /** 224 /**
235 * Helper function to get a section from the local DOM. 225 * Helper function to get a section from the local DOM.
236 * @param {string} section Section name of the element to get. 226 * @param {string} section Section name of the element to get.
237 * @return {?SettingsSectionElement} 227 * @return {?SettingsSectionElement}
238 */ 228 */
239 getSection: function(section) { 229 getSection: function(section) {
240 if (!section) 230 if (!section)
241 return null; 231 return null;
242 return /** @type {?SettingsSectionElement} */( 232 return /** @type {?SettingsSectionElement} */(
243 this.$$('settings-section[section="' + section + '"]')); 233 this.$$('settings-section[section="' + section + '"]'));
(...skipping 17 matching lines...) Expand all
261 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)'; 251 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)';
262 } 252 }
263 } 253 }
264 }; 254 };
265 255
266 /** @polymerBehavior */ 256 /** @polymerBehavior */
267 var MainPageBehavior = [ 257 var MainPageBehavior = [
268 settings.RouteObserverBehavior, 258 settings.RouteObserverBehavior,
269 MainPageBehaviorImpl, 259 MainPageBehaviorImpl,
270 ]; 260 ];
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