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

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

Issue 6360016: dom-ui settings: Improve search field behavior.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 ///////////////////////////////////////////////////////////////////////////// 6 /////////////////////////////////////////////////////////////////////////////
7 // OptionsPage class: 7 // OptionsPage class:
8 8
9 /** 9 /**
10 * Base class for options page. 10 * Base class for options page.
(...skipping 25 matching lines...) Expand all
36 */ 36 */
37 OptionsPage.registeredOverlayPages = {}; 37 OptionsPage.registeredOverlayPages = {};
38 38
39 /** 39 /**
40 * Whether or not |initialize| has been called. 40 * Whether or not |initialize| has been called.
41 * @private 41 * @private
42 */ 42 */
43 OptionsPage.initialized_ = false; 43 OptionsPage.initialized_ = false;
44 44
45 /** 45 /**
46 * Shows the default page.
47 */
48 OptionsPage.showDefaultPage = function() {
49 // TODO(csilv): Persist the current page.
50 this.showPageByName(BrowserOptions.getInstance().name);
51 };
52
53 /**
46 * Shows a registered page. This handles both top-level pages and sub-pages. 54 * Shows a registered page. This handles both top-level pages and sub-pages.
47 * @param {string} pageName Page name. 55 * @param {string} pageName Page name.
48 */ 56 */
49 OptionsPage.showPageByName = function(pageName) { 57 OptionsPage.showPageByName = function(pageName) {
50 var targetPage = this.registeredPages[pageName]; 58 var targetPage = this.registeredPages[pageName];
51 59
52 // Determine if the root page is 'sticky', meaning that it 60 // Determine if the root page is 'sticky', meaning that it
53 // shouldn't change when showing a sub-page. This can happen for special 61 // shouldn't change when showing a sub-page. This can happen for special
54 // pages like Search. 62 // pages like Search.
55 var rootPage = null; 63 var rootPage = null;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 true); 340 true);
333 341
334 // Hook up the close buttons. 342 // Hook up the close buttons.
335 subpageCloseButtons = document.querySelectorAll('.close-subpage'); 343 subpageCloseButtons = document.querySelectorAll('.close-subpage');
336 for (var i = 0; i < subpageCloseButtons.length; i++) { 344 for (var i = 0; i < subpageCloseButtons.length; i++) {
337 subpageCloseButtons[i].onclick = function() { 345 subpageCloseButtons[i].onclick = function() {
338 self.closeTopSubPage(); 346 self.closeTopSubPage();
339 }; 347 };
340 }; 348 };
341 349
342 // Close the top overlay or sub-page on esc. 350 // Install handler for key presses.
343 document.addEventListener('keydown', function(e) { 351 document.addEventListener('keydown', this.keyDownEventHandler_.bind(this));
344 if (e.keyCode == 27) { // Esc
345 if (self.isOverlayVisible_())
346 self.clearOverlays();
347 else
348 self.closeTopSubPage();
349 }
350 });
351 }; 352 };
352 353
353 /** 354 /**
354 * Returns a function to handle clicks behind a subpage at level |level| by 355 * Returns a function to handle clicks behind a subpage at level |level| by
355 * closing all subpages down to |level| - 1. 356 * closing all subpages down to |level| - 1.
356 * @param {number} level The level of the subpage being handled. 357 * @param {number} level The level of the subpage being handled.
357 * @return {Function} a function to handle clicks outside the given subpage. 358 * @return {Function} a function to handle clicks outside the given subpage.
358 * @private 359 * @private
359 */ 360 */
360 OptionsPage.subPageClosingClickHandler_ = function(level) { 361 OptionsPage.subPageClosingClickHandler_ = function(level) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 400
400 // Events should not fall through to the main view, 401 // Events should not fall through to the main view,
401 // but they can fall through for the sidebar. 402 // but they can fall through for the sidebar.
402 if ($('mainview-content').contains(event.target)) { 403 if ($('mainview-content').contains(event.target)) {
403 event.stopPropagation(); 404 event.stopPropagation();
404 event.preventDefault(); 405 event.preventDefault();
405 } 406 }
406 }; 407 };
407 408
408 /** 409 /**
410 * A function to handle key press events.
411 * @return {Event} a keydown event.
412 * @private
413 */
414 OptionsPage.keyDownEventHandler_ = function(event) {
415 // Close the top overlay or sub-page on esc.
416 if (event.keyCode == 27) { // Esc
417 if (this.isOverlayVisible_())
418 this.clearOverlays();
419 else
420 this.closeTopSubPage();
421 }
422 };
423
424 /**
409 * Re-initializes the C++ handlers if necessary. This is called if the 425 * Re-initializes the C++ handlers if necessary. This is called if the
410 * handlers are torn down and recreated but the DOM may not have been (in 426 * handlers are torn down and recreated but the DOM may not have been (in
411 * which case |initialize| won't be called again). If |initialize| hasn't been 427 * which case |initialize| won't be called again). If |initialize| hasn't been
412 * called, this does nothing (since it will be later, once the DOM has 428 * called, this does nothing (since it will be later, once the DOM has
413 * finished loading). 429 * finished loading).
414 */ 430 */
415 OptionsPage.reinitializeCore = function() { 431 OptionsPage.reinitializeCore = function() {
416 if (this.initialized_) 432 if (this.initialized_)
417 chrome.send('coreOptionsInitialize'); 433 chrome.send('coreOptionsInitialize');
418 } 434 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 OptionsPage.showOverlay(hash); 591 OptionsPage.showOverlay(hash);
576 }, 592 },
577 }; 593 };
578 594
579 // Export 595 // Export
580 return { 596 return {
581 OptionsPage: OptionsPage 597 OptionsPage: OptionsPage
582 }; 598 };
583 599
584 }); 600 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/options.js ('k') | chrome/browser/resources/options/search_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698