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

Side by Side Diff: chrome/browser/resources/options/browser_options.js

Issue 11414204: Delay scroll to section until page initialization is complete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary flag reset. Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/options_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 cr.define('options', function() { 5 cr.define('options', function() {
6 var OptionsPage = options.OptionsPage; 6 var OptionsPage = options.OptionsPage;
7 var ArrayDataModel = cr.ui.ArrayDataModel; 7 var ArrayDataModel = cr.ui.ArrayDataModel;
8 var RepeatingButton = cr.ui.RepeatingButton; 8 var RepeatingButton = cr.ui.RepeatingButton;
9 9
10 // 10 //
(...skipping 14 matching lines...) Expand all
25 syncSetupCompleted: false, 25 syncSetupCompleted: false,
26 26
27 /** 27 /**
28 * Keeps track of whether |onShowHomeButtonChanged_| has been called. See 28 * Keeps track of whether |onShowHomeButtonChanged_| has been called. See
29 * |onShowHomeButtonChanged_|. 29 * |onShowHomeButtonChanged_|.
30 * @type {bool} 30 * @type {bool}
31 * @private 31 * @private
32 */ 32 */
33 onShowHomeButtonChangedCalled_: false, 33 onShowHomeButtonChangedCalled_: false,
34 34
35 /**
36 * Track if page initialization is complete. All C++ UI handlers have the
37 * chance to manipulate page content within their InitializePage mathods.
38 * This flag is set to true after all initializers have been called.
39 * @type (boolean}
40 * @private
41 */
42 initializationComplete_: false,
43
35 /** @override */ 44 /** @override */
36 initializePage: function() { 45 initializePage: function() {
37 OptionsPage.prototype.initializePage.call(this); 46 OptionsPage.prototype.initializePage.call(this);
38 var self = this; 47 var self = this;
39 48
40 // Ensure that navigation events are unblocked on uber page. A reload of 49 // Ensure that navigation events are unblocked on uber page. A reload of
41 // the settings page while an overlay is open would otherwise leave uber 50 // the settings page while an overlay is open would otherwise leave uber
42 // page in a blocked state, where tab switching is not possible. 51 // page in a blocked state, where tab switching is not possible.
43 uber.invokeMethodOnParent('stopInterceptingEvents'); 52 uber.invokeMethodOnParent('stopInterceptingEvents');
44 53
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 OptionsPage.navigateToPage('factoryResetData'); 420 OptionsPage.navigateToPage('factoryResetData');
412 }; 421 };
413 } 422 }
414 }, 423 },
415 424
416 /** @override */ 425 /** @override */
417 didShowPage: function() { 426 didShowPage: function() {
418 $('search-field').focus(); 427 $('search-field').focus();
419 }, 428 },
420 429
430 /**
431 * Called after all C++ UI handlers have called InitializePage to notify
432 * that initialization is complete.
433 * @private
434 */
435 notifyInitializationComplete_: function() {
436 this.initializationComplete_ = true;
437 cr.dispatchSimpleEvent(document, 'initializationComplete');
438 },
439
421 /** 440 /**
422 * Event listener for the 'session.restore_on_startup' pref. 441 * Event listener for the 'session.restore_on_startup' pref.
423 * @param {Event} event The preference change event. 442 * @param {Event} event The preference change event.
424 * @private 443 * @private
425 */ 444 */
426 onRestoreOnStartupChanged_: function(event) { 445 onRestoreOnStartupChanged_: function(event) {
427 /** @const */ var showHomePageValue = 0; 446 /** @const */ var showHomePageValue = 0;
428 447
429 if (event.value.value == showHomePageValue) { 448 if (event.value.value == showHomePageValue) {
430 // If the user previously selected "Show the homepage", the 449 // If the user previously selected "Show the homepage", the
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 */ 558 */
540 scrollToSection_: function(section) { 559 scrollToSection_: function(section) {
541 var advancedSettings = $('advanced-settings'); 560 var advancedSettings = $('advanced-settings');
542 var container = $('advanced-settings-container'); 561 var container = $('advanced-settings-container');
543 if (advancedSettings.hidden && section.parentNode == container) { 562 if (advancedSettings.hidden && section.parentNode == container) {
544 this.showSection_($('advanced-settings'), 563 this.showSection_($('advanced-settings'),
545 $('advanced-settings-container'), 564 $('advanced-settings-container'),
546 /* animate */ false); 565 /* animate */ false);
547 this.updateAdvancedSettingsExpander_(); 566 this.updateAdvancedSettingsExpander_();
548 } 567 }
568
569 if (!this.initializationComplete_) {
570 var self = this;
571 var callback = function() {
572 document.removeEventListener('initializationComplete', callback);
573 self.scrollToSection_(section);
574 };
575 document.addEventListener('initializationComplete', callback);
576 return;
577 }
578
549 var pageContainer = $('page-container'); 579 var pageContainer = $('page-container');
550 var pageTop = parseFloat(pageContainer.style.top); 580 var pageTop = parseFloat(pageContainer.style.top);
551 var topSection = document.querySelector('#page-container section'); 581 var topSection = document.querySelector('#page-container section');
552 var pageHeight = document.body.scrollHeight - topSection.offsetTop; 582 var pageHeight = document.body.scrollHeight - topSection.offsetTop;
553 var sectionTop = section.offsetTop; 583 var sectionTop = section.offsetTop;
554 var sectionHeight = section.offsetHeight; 584 var sectionHeight = section.offsetHeight;
555 var marginBottom = window.getComputedStyle(section).marginBottom; 585 var marginBottom = window.getComputedStyle(section).marginBottom;
556 if (marginBottom) 586 if (marginBottom)
557 sectionHeight += parseFloat(marginBottom); 587 sectionHeight += parseFloat(marginBottom);
558 if (pageHeight - pageTop < sectionTop + sectionHeight) { 588 if (pageHeight - pageTop < sectionTop + sectionHeight) {
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 1309
1280 }; 1310 };
1281 1311
1282 //Forward public APIs to private implementations. 1312 //Forward public APIs to private implementations.
1283 [ 1313 [
1284 'addBluetoothDevice', 1314 'addBluetoothDevice',
1285 'enableFactoryResetSection', 1315 'enableFactoryResetSection',
1286 'getCurrentProfile', 1316 'getCurrentProfile',
1287 'getStartStopSyncButton', 1317 'getStartStopSyncButton',
1288 'hideBluetoothSettings', 1318 'hideBluetoothSettings',
1319 'notifyInitializationComplete',
1289 'removeBluetoothDevice', 1320 'removeBluetoothDevice',
1290 'removeCloudPrintConnectorSection', 1321 'removeCloudPrintConnectorSection',
1291 'scrollToSection', 1322 'scrollToSection',
1292 'setAutoOpenFileTypesDisplayed', 1323 'setAutoOpenFileTypesDisplayed',
1293 'setBluetoothState', 1324 'setBluetoothState',
1294 'setFontSize', 1325 'setFontSize',
1295 'setGtkThemeButtonEnabled', 1326 'setGtkThemeButtonEnabled',
1296 'setHighContrastCheckboxState', 1327 'setHighContrastCheckboxState',
1297 'setMetricsReportingCheckboxState', 1328 'setMetricsReportingCheckboxState',
1298 'setMetricsReportingSettingVisibility', 1329 'setMetricsReportingSettingVisibility',
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 BrowserOptions.getLoggedInUsername = function() { 1362 BrowserOptions.getLoggedInUsername = function() {
1332 return BrowserOptions.getInstance().username_; 1363 return BrowserOptions.getInstance().username_;
1333 }; 1364 };
1334 } 1365 }
1335 1366
1336 // Export 1367 // Export
1337 return { 1368 return {
1338 BrowserOptions: BrowserOptions 1369 BrowserOptions: BrowserOptions
1339 }; 1370 };
1340 }); 1371 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/options_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698