Chromium Code Reviews| Index: chrome/browser/resources/options/options_page.js |
| =================================================================== |
| --- chrome/browser/resources/options/options_page.js (revision 70013) |
| +++ chrome/browser/resources/options/options_page.js (working copy) |
| @@ -48,9 +48,18 @@ |
| */ |
| OptionsPage.showPageByName = function(pageName) { |
| var targetPage = this.registeredPages[pageName]; |
| + |
| + // Determine if the current top-level page is 'sticky', meaning that it |
| + // shouldn't change when showing a sub-page. This can happen for special |
| + // pages like Search. |
| + var topPage = this.getTopmostVisiblePage(); |
| + var isTopPageLocked = (topPage && topPage.sticky && targetPage.parentPage); |
| + |
| // Notify pages if they will be hidden. |
| for (var name in this.registeredPages) { |
| var page = this.registeredPages[name]; |
| + if (!page.parentPage && isTopPageLocked) |
| + continue; |
| if (page.willHidePage && name != pageName && |
| !page.isAncestorOfPage(targetPage)) |
| page.willHidePage(); |
| @@ -59,6 +68,8 @@ |
| // Update visibilities to show only the hierarchy of the target page. |
| for (var name in this.registeredPages) { |
| var page = this.registeredPages[name]; |
| + if (!page.parentPage && isTopPageLocked) |
| + continue; |
| page.visible = name == pageName || |
| (document.documentElement.getAttribute('hide-menu') != 'true' && |
| page.isAncestorOfPage(targetPage)); |
| @@ -67,7 +78,10 @@ |
| // Notify pages if they were shown. |
| for (var name in this.registeredPages) { |
| var page = this.registeredPages[name]; |
| - if (name == pageName && page.didShowPage) |
| + if (!page.parentPage && isTopPageLocked) |
| + continue; |
| + if (page.didShowPage && (name == pageName || |
| + page.isAncestorOfPage(targetPage))) |
| page.didShowPage(); |
| } |
| }; |
| @@ -215,12 +229,37 @@ |
| }; |
| /** |
| + * Fine an enclosing section for an element if it exists. |
| + * @param {Element} element Element to search. |
| + * @return {OptionPage} The section element, or null. |
| + * @private |
| + */ |
| + OptionsPage.findSectionForNode_ = function(node) { |
| + while (node = node.parentNode) { |
| + if (node.nodeType == document.ELEMENT_NODE && |
| + node.nodeName.toLowerCase() == 'section') |
| + return node; |
| + } |
| + return null; |
| + }; |
| + |
| + /** |
| * Registers a new Sub tab page. |
| * @param {OptionsPage} page Page to register. |
|
James Hawkins
2010/12/23 01:16:29
s/page/subPage/
csilv
2010/12/23 02:59:46
Done.
|
| + * @param {OptionsPage} parentPage Parent page to register. |
|
James Hawkins
2010/12/23 01:16:29
'Parent page to register' ? Seems like 'Associated
csilv
2010/12/23 02:59:46
Done.
|
| + * @param {Array} associatedControls Array of control elements associated with |
|
James Hawkins
2010/12/23 01:16:29
Hmm, from just reading this description, I have no
csilv
2010/12/23 02:59:46
Tweaked the wording, PTAL.
|
| + * this page. |
| */ |
| - OptionsPage.registerSubPage = function(subPage, parentPage) { |
| + OptionsPage.registerSubPage = function(subPage, |
| + parentPage, |
| + associatedControls) { |
| this.registeredPages[subPage.name] = subPage; |
| subPage.parentPage = parentPage; |
| + subPage.associatedControls = associatedControls; |
| + if (associatedControls && associatedControls.length) { |
| + subPage.associatedSection = |
| + this.findSectionForNode_(associatedControls[0]); |
| + } |
| subPage.tab = undefined; |
| subPage.initializePage(); |
| }; |
| @@ -228,10 +267,16 @@ |
| /** |
| * Registers a new Overlay page. |
| * @param {OptionsPage} page Page to register, must be a class derived from |
| - * OptionsPage. |
| + * @param {Array} associatedControls Array of control elements associated with |
| + * this page. |
| */ |
| - OptionsPage.registerOverlay = function(page) { |
| + OptionsPage.registerOverlay = function(page, |
| + associatedControls) { |
| this.registeredOverlayPages[page.name] = page; |
| + page.associatedControls = associatedControls; |
| + if (associatedControls && associatedControls.length) { |
| + page.associatedSection = this.findSectionForNode_(associatedControls[0]); |
| + } |
| page.tab = undefined; |
| page.isOverlay = true; |
| page.initializePage(); |
| @@ -321,6 +366,20 @@ |
| parentPage: null, |
| /** |
| + * The section on the parent page that is associated with this page. |
| + * Can be null. |
| + * @type {Element} |
| + */ |
| + associatedSection: null, |
| + |
| + /** |
| + * An array of controls that are associated with this page. The first |
| + * control should be located on a top-level page. |
| + * @type {OptionsPage} |
| + */ |
| + associatedControls: null, |
| + |
| + /** |
| * Initializes page content. |
| */ |
| initializePage: function() {}, |
| @@ -420,6 +479,15 @@ |
| }, |
| /** |
| + * Checks whether the page is considered 'sticky', such that it will |
| + * remain a top-level page even if sub-pages change. |
| + * @return {boolean} True if this page is sticky. |
| + */ |
| + get sticky() { |
| + return false; |
| + }, |
| + |
| + /** |
| * Checks whether this page is an ancestor of the given page in terms of |
| * subpage nesting. |
| * @param {OptionsPage} page |