| OLD | NEW |
| 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 ///////////////////////////////////////////////////////////////////////////// | 6 ///////////////////////////////////////////////////////////////////////////// |
| 7 // OptionsPage class: | 7 // OptionsPage class: |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Base class for options page. | 10 * Base class for options page. |
| 11 * @constructor | 11 * @constructor |
| 12 * @param {string} name Options page name. | 12 * @param {string} name Options page name. |
| 13 * @param {string} title Options page title, used for history. | 13 * @param {string} title Options page title, used for history. |
| 14 * @extends {EventTarget} | 14 * @extends {EventTarget} |
| 15 */ | 15 */ |
| 16 function OptionsPage(name, title, pageDivName) { | 16 function OptionsPage(name, title, pageDivName) { |
| 17 this.name = name; | 17 this.name = name; |
| 18 this.title = title; | 18 this.title = title; |
| 19 this.pageDivName = pageDivName; | 19 this.pageDivName = pageDivName; |
| 20 this.pageDiv = $(this.pageDivName); | 20 this.pageDiv = $(this.pageDivName); |
| 21 this.tab = null; | 21 this.tab = null; |
| 22 this.lastFocusedElement = null; | 22 this.lastFocusedElement = null; |
| 23 } | 23 } |
| 24 | 24 |
| 25 /** @const */ var HORIZONTAL_OFFSET = 155; | 25 /** @const */ var HORIZONTAL_OFFSET = 155; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * This is the absolute difference maintained between standard and | 28 * This is the absolute difference maintained between standard and |
| 29 * fixed-width font sizes. Refer http://crbug.com/91922. | 29 * fixed-width font sizes. Refer http://crbug.com/91922. |
| 30 * @const |
| 30 */ | 31 */ |
| 31 OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD = 3; | 32 OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD = 3; |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Main level option pages. Maps lower-case page names to the respective page | 35 * Main level option pages. Maps lower-case page names to the respective page |
| 35 * object. | 36 * object. |
| 36 * @protected | 37 * @protected |
| 37 */ | 38 */ |
| 38 OptionsPage.registeredPages = {}; | 39 OptionsPage.registeredPages = {}; |
| 39 | 40 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 * @param {Object=} opt_propertyBag An optional bag of properties including | 76 * @param {Object=} opt_propertyBag An optional bag of properties including |
| 76 * replaceState (if history state should be replaced instead of pushed). | 77 * replaceState (if history state should be replaced instead of pushed). |
| 77 * @private | 78 * @private |
| 78 */ | 79 */ |
| 79 OptionsPage.showPageByName = function(pageName, | 80 OptionsPage.showPageByName = function(pageName, |
| 80 updateHistory, | 81 updateHistory, |
| 81 opt_propertyBag) { | 82 opt_propertyBag) { |
| 82 // If |opt_propertyBag| is non-truthy, homogenize to object. | 83 // If |opt_propertyBag| is non-truthy, homogenize to object. |
| 83 opt_propertyBag = opt_propertyBag || {}; | 84 opt_propertyBag = opt_propertyBag || {}; |
| 84 | 85 |
| 86 // If a bubble is currently being shown, hide it. |
| 87 this.hideBubble(); |
| 88 |
| 85 // Find the currently visible root-level page. | 89 // Find the currently visible root-level page. |
| 86 var rootPage = null; | 90 var rootPage = null; |
| 87 for (var name in this.registeredPages) { | 91 for (var name in this.registeredPages) { |
| 88 var page = this.registeredPages[name]; | 92 var page = this.registeredPages[name]; |
| 89 if (page.visible && !page.parentPage) { | 93 if (page.visible && !page.parentPage) { |
| 90 rootPage = page; | 94 rootPage = page; |
| 91 break; | 95 break; |
| 92 } | 96 } |
| 93 } | 97 } |
| 94 | 98 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 /** | 376 /** |
| 373 * Returns the topmost visible page, or null if no page is visible. | 377 * Returns the topmost visible page, or null if no page is visible. |
| 374 * @return {OptionPage} The topmost visible page. | 378 * @return {OptionPage} The topmost visible page. |
| 375 */ | 379 */ |
| 376 OptionsPage.getTopmostVisiblePage = function() { | 380 OptionsPage.getTopmostVisiblePage = function() { |
| 377 // Check overlays first since they're top-most if visible. | 381 // Check overlays first since they're top-most if visible. |
| 378 return this.getVisibleOverlay_() || this.getTopmostVisibleNonOverlayPage_(); | 382 return this.getVisibleOverlay_() || this.getTopmostVisibleNonOverlayPage_(); |
| 379 }; | 383 }; |
| 380 | 384 |
| 381 /** | 385 /** |
| 386 * Returns the currently visible bubble, or null if no bubble is visible. |
| 387 * @return {Bubble} The bubble currently being shown. |
| 388 */ |
| 389 OptionsPage.getVisibleBubble = function() { |
| 390 var bubble = OptionsPage.bubble_; |
| 391 return bubble && !bubble.hidden ? bubble : null; |
| 392 }; |
| 393 |
| 394 /** |
| 395 * Shows an informational bubble displaying |content| and pointing at the |
| 396 * |anchor| element. If |content| has focusable elements, they join the |
| 397 * current page's tab order as siblings of |anchor|. |
| 398 * @param {HTMLDivElement} content The content of the bubble. |
| 399 * @param {HTMLElement} anchor The element at which the bubble points. |
| 400 */ |
| 401 OptionsPage.showBubble = function(content, anchor) { |
| 402 console.log('showBubble'); |
| 403 OptionsPage.hideBubble(); |
| 404 |
| 405 var bubble = new options.Bubble; |
| 406 bubble.anchorNode = anchor; |
| 407 bubble.arrowLocation = cr.ui.ArrowLocation.TOP_END; |
| 408 bubble.content = content; |
| 409 bubble.show(); |
| 410 OptionsPage.bubble_ = bubble; |
| 411 }; |
| 412 |
| 413 /** |
| 414 * Hides the currently visible bubble, if any. |
| 415 */ |
| 416 OptionsPage.hideBubble = function() { |
| 417 if (OptionsPage.bubble_) |
| 418 OptionsPage.bubble_.hide(); |
| 419 }; |
| 420 |
| 421 /** |
| 382 * Updates managed banner visibility state based on the topmost page. | 422 * Updates managed banner visibility state based on the topmost page. |
| 383 */ | 423 */ |
| 384 OptionsPage.updateManagedBannerVisibility = function() { | 424 OptionsPage.updateManagedBannerVisibility = function() { |
| 385 var topPage = this.getTopmostVisiblePage(); | 425 var topPage = this.getTopmostVisiblePage(); |
| 386 if (topPage) | 426 if (topPage) |
| 387 topPage.updateManagedBannerVisibility(); | 427 topPage.updateManagedBannerVisibility(); |
| 388 }; | 428 }; |
| 389 | 429 |
| 390 /** | 430 /** |
| 391 * Shows the tab contents for the given navigation tab. | 431 * Shows the tab contents for the given navigation tab. |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 canShowPage: function() { | 940 canShowPage: function() { |
| 901 return true; | 941 return true; |
| 902 }, | 942 }, |
| 903 }; | 943 }; |
| 904 | 944 |
| 905 // Export | 945 // Export |
| 906 return { | 946 return { |
| 907 OptionsPage: OptionsPage | 947 OptionsPage: OptionsPage |
| 908 }; | 948 }; |
| 909 }); | 949 }); |
| OLD | NEW |