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

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

Issue 2230753002: MD Settings: methods to get root pages and sections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: defensive 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 | « chrome/browser/resources/settings/settings_main/settings_main.js ('k') | 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 /** 53 /**
54 * If possible, transitions to the current route's section (by expanding or 54 * If possible, transitions to the current route's section (by expanding or
55 * scrolling to it). If another transition is running, finishes or cancels 55 * scrolling to it). If another transition is running, finishes or cancels
56 * that one, then schedules this function again. This ensures the current 56 * that one, then schedules this function again. This ensures the current
57 * section is quickly shown, without getting the page into a broken state -- 57 * 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. 58 * if currentRoute changes in between calls, just transition to the new route.
59 * @private 59 * @private
60 */ 60 */
61 tryTransitionToSection_: function() { 61 tryTransitionToSection_: function() {
62 var currentRoute = settings.getCurrentRoute(); 62 var currentRoute = settings.getCurrentRoute();
63 var currentSection = this.getSection_(currentRoute.section); 63 var currentSection = this.getSection(currentRoute.section);
64 64
65 // If an animation is already playing, try finishing or canceling it. 65 // If an animation is already playing, try finishing or canceling it.
66 if (this.currentAnimation_) { 66 if (this.currentAnimation_) {
67 this.maybeStopCurrentAnimation_(); 67 this.maybeStopCurrentAnimation_();
68 // Either way, this function will be called again once the current 68 // Either way, this function will be called again once the current
69 // animation ends. 69 // animation ends.
70 return; 70 return;
71 } 71 }
72 72
73 var promise; 73 var promise;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 /** @private */ 219 /** @private */
220 scrollToSection_: function() { 220 scrollToSection_: function() {
221 doWhenReady( 221 doWhenReady(
222 function() { 222 function() {
223 return this.scrollHeight > 0; 223 return this.scrollHeight > 0;
224 }.bind(this), 224 }.bind(this),
225 function() { 225 function() {
226 // If the current section changes while we are waiting for the page to 226 // If the current section changes while we are waiting for the page to
227 // be ready, scroll to the newest requested section. 227 // be ready, scroll to the newest requested section.
228 var section = this.getSection_(settings.getCurrentRoute().section); 228 var section = this.getSection(settings.getCurrentRoute().section);
229 if (section) 229 if (section)
230 section.scrollIntoView(); 230 section.scrollIntoView();
231 }.bind(this)); 231 }.bind(this));
232 }, 232 },
233 233
234 /** 234 /**
235 * Helper function to get a section from the local DOM. 235 * Helper function to get a section from the local DOM.
236 * @param {string} section Section name of the element to get. 236 * @param {string} section Section name of the element to get.
237 * @return {?SettingsSectionElement} 237 * @return {?SettingsSectionElement}
238 * @private
239 */ 238 */
240 getSection_: function(section) { 239 getSection: function(section) {
241 if (!section) 240 if (!section)
242 return null; 241 return null;
243 return /** @type {?SettingsSectionElement} */( 242 return /** @type {?SettingsSectionElement} */(
244 this.$$('[section=' + section + ']')); 243 this.$$('settings-section[section="' + section + '"]'));
245 }, 244 },
246 245
247 /** 246 /**
248 * Enables or disables user scrolling, via overscroll: hidden. Room for the 247 * Enables or disables user scrolling, via overscroll: hidden. Room for the
249 * hidden scrollbar is added to prevent the page width from changing back and 248 * hidden scrollbar is added to prevent the page width from changing back and
250 * forth. 249 * forth.
251 * @param {boolean} enabled 250 * @param {boolean} enabled
252 * @private 251 * @private
253 */ 252 */
254 toggleScrolling_: function(enabled) { 253 toggleScrolling_: function(enabled) {
255 if (enabled) { 254 if (enabled) {
256 this.scroller.style.overflow = ''; 255 this.scroller.style.overflow = '';
257 this.scroller.style.width = ''; 256 this.scroller.style.width = '';
258 } else { 257 } else {
259 var scrollerWidth = this.scroller.clientWidth; 258 var scrollerWidth = this.scroller.clientWidth;
260 this.scroller.style.overflow = 'hidden'; 259 this.scroller.style.overflow = 'hidden';
261 var scrollbarWidth = this.scroller.clientWidth - scrollerWidth; 260 var scrollbarWidth = this.scroller.clientWidth - scrollerWidth;
262 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)'; 261 this.scroller.style.width = 'calc(100% - ' + scrollbarWidth + 'px)';
263 } 262 }
264 } 263 }
265 }; 264 };
266 265
267 /** @polymerBehavior */ 266 /** @polymerBehavior */
268 var MainPageBehavior = [ 267 var MainPageBehavior = [
269 settings.RouteObserverBehavior, 268 settings.RouteObserverBehavior,
270 MainPageBehaviorImpl, 269 MainPageBehaviorImpl,
271 ]; 270 ];
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/settings_main/settings_main.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698