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

Side by Side Diff: chrome/browser/resources/settings/settings_main/settings_main.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
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 * @typedef {{about: boolean, basic: boolean, advanced: boolean}} 6 * @typedef {{about: boolean, basic: boolean, advanced: boolean}}
7 */ 7 */
8 var MainPageVisibility; 8 var MainPageVisibility;
9 9
10 /** 10 /**
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 * content so that the last element may align with the top of the content 172 * content so that the last element may align with the top of the content
173 * area. 173 * area.
174 * @return {number} 174 * @return {number}
175 * @private 175 * @private
176 */ 176 */
177 overscrollHeight_: function() { 177 overscrollHeight_: function() {
178 var route = settings.getCurrentRoute(); 178 var route = settings.getCurrentRoute();
179 if (route.isSubpage() || this.showPages_.about) 179 if (route.isSubpage() || this.showPages_.about)
180 return 0; 180 return 0;
181 181
182 var query = 'settings-section[section="' + route.section + '"]'; 182 var page = this.getPage_(route);
183 var topSection = this.$$('settings-basic-page').$$(query); 183 var topSection = page && page.getSection(route.section);
184 if (!topSection && this.showPages_.advanced)
185 topSection = this.$$('settings-advanced-page').$$(query);
186
187 if (!topSection || !topSection.offsetParent) 184 if (!topSection || !topSection.offsetParent)
188 return 0; 185 return 0;
189 186
190 // Offset to the selected section (relative to the scrolling window). 187 // Offset to the selected section (relative to the scrolling window).
191 let sectionTop = topSection.offsetParent.offsetTop + topSection.offsetTop; 188 let sectionTop = topSection.offsetParent.offsetTop + topSection.offsetTop;
192 // The height of the selected section and remaining content (sections). 189 // The height of the selected section and remaining content (sections).
193 let heightOfShownSections = this.$.overscroll.offsetTop - sectionTop; 190 let heightOfShownSections = this.$.overscroll.offsetTop - sectionTop;
194 return Math.max(0, this.parentNode.scrollHeight - heightOfShownSections); 191 return Math.max(0, this.parentNode.scrollHeight - heightOfShownSections);
195 }, 192 },
196 193
197 /** @private */ 194 /** @private */
198 toggleAdvancedPage_: function() { 195 toggleAdvancedPage_: function() {
199 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); 196 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_);
200 }, 197 },
201 198
202 /** 199 /**
200 * Returns the root page (if it exists) for a route.
201 * @param {!settings.Route} route
202 * @return {(?SettingsAboutPageElement|?SettingsAdvancedPageElement|
203 * ?SettingsBasicPageElement)}
204 */
205 getPage_: function(route) {
206 if (settings.Route.ABOUT.contains(route)) {
207 return /** @type {?SettingsAboutPageElement} */(
208 this.$$('settings-about-page'));
209 }
210 if (settings.Route.ADVANCED.contains(route)) {
211 return /** @type {?SettingsAdvancedPageElement} */(
212 this.$$('settings-advanced-page'));
213 }
214 if (settings.Route.BASIC.contains(route)) {
215 return /** @type {?SettingsBasicPageElement} */(
216 this.$$('settings-basic-page'));
217 }
218 assertNotReached();
219 },
220
221 /**
203 * Navigates to the default search page (if necessary). 222 * Navigates to the default search page (if necessary).
204 * @private 223 * @private
205 */ 224 */
206 ensureInDefaultSearchPage_: function() { 225 ensureInDefaultSearchPage_: function() {
207 if (settings.getCurrentRoute() != settings.Route.BASIC) 226 if (settings.getCurrentRoute() != settings.Route.BASIC)
208 settings.navigateTo(settings.Route.BASIC); 227 settings.navigateTo(settings.Route.BASIC);
209 }, 228 },
210 229
211 /** 230 /**
212 * @param {string} query 231 * @param {string} query
213 * @return {!Promise} A promise indicating that searching finished. 232 * @return {!Promise} A promise indicating that searching finished.
214 */ 233 */
215 searchContents: function(query) { 234 searchContents: function(query) {
216 if (!this.previousShowPages_) { 235 if (!this.previousShowPages_) {
217 // Store which pages are shown before search, so that they can be restored 236 // Store which pages are shown before search, so that they can be restored
218 // after the user clears the search results. 237 // after the user clears the search results.
219 this.previousShowPages_ = this.showPages_; 238 this.previousShowPages_ = this.showPages_;
220 } 239 }
221 240
222 this.ensureInDefaultSearchPage_(); 241 this.ensureInDefaultSearchPage_();
223 this.toolbarSpinnerActive = true; 242 this.toolbarSpinnerActive = true;
224 243
225 // Trigger rendering of the basic and advanced pages and search once ready. 244 // Trigger rendering of the basic and advanced pages and search once ready.
226 this.showPages_ = {about: false, basic: true, advanced: true}; 245 this.showPages_ = {about: false, basic: true, advanced: true};
227 246
228 return new Promise(function(resolve, reject) { 247 return new Promise(function(resolve, reject) {
229 setTimeout(function() { 248 setTimeout(function() {
230 var whenSearchDone = settings.getSearchManager().search( 249 var whenSearchDone = settings.getSearchManager().search(
231 query, assert(this.$$('settings-basic-page'))); 250 query, assert(this.getPage_(settings.Route.BASIC)));
232 assert( 251 assert(
233 whenSearchDone === 252 whenSearchDone ===
234 settings.getSearchManager().search( 253 settings.getSearchManager().search(
235 query, assert(this.$$('settings-advanced-page')))); 254 query, assert(this.getPage_(settings.Route.ADVANCED))));
236 255
237 whenSearchDone.then(function(request) { 256 whenSearchDone.then(function(request) {
238 resolve(); 257 resolve();
239 if (!request.finished) { 258 if (!request.finished) {
240 // Nothing to do here. A previous search request was canceled 259 // Nothing to do here. A previous search request was canceled
241 // because a new search request was issued before the first one 260 // because a new search request was issued before the first one
242 // completed. 261 // completed.
243 return; 262 return;
244 } 263 }
245 264
(...skipping 14 matching lines...) Expand all
260 279
261 /** 280 /**
262 * @param {(boolean|undefined)} visibility 281 * @param {(boolean|undefined)} visibility
263 * @return {boolean} True unless visibility is false. 282 * @return {boolean} True unless visibility is false.
264 * @private 283 * @private
265 */ 284 */
266 showAdvancedSettings_: function(visibility) { 285 showAdvancedSettings_: function(visibility) {
267 return visibility !== false; 286 return visibility !== false;
268 }, 287 },
269 }); 288 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698