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

Unified Diff: ui/webui/resources/js/cr/ui/page_manager/page_manager.js

Issue 488083005: Remove code duplication in PageManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/js/cr/ui/page_manager/page_manager.js
diff --git a/ui/webui/resources/js/cr/ui/page_manager/page_manager.js b/ui/webui/resources/js/cr/ui/page_manager/page_manager.js
index 0fd4a185cc605c6ef26c06c3e612d0b3c89d06b8..0c0c92a189fee3277d24f42bde8c7cfa46d1bb93 100644
--- a/ui/webui/resources/js/cr/ui/page_manager/page_manager.js
+++ b/ui/webui/resources/js/cr/ui/page_manager/page_manager.js
@@ -181,34 +181,19 @@ cr.define('cr.ui.pageManager', function() {
var isRootPageLocked =
rootPage && rootPage.sticky && targetPage.parentPage;
- var allPageNames = Array.prototype.concat.call(
- Object.keys(this.registeredPages),
- Object.keys(this.registeredOverlayPages));
-
// Notify pages if they will be hidden.
- // TODO(michaelpg): Resolve code duplication.
- for (var i = 0; i < allPageNames.length; ++i) {
- var name = allPageNames[i];
- var page = this.registeredPages[name] ||
- this.registeredOverlayPages[name];
- if (!page.parentPage && isRootPageLocked)
- continue;
- if (page.willHidePage && name != pageName &&
+ this.forEachPage_(!isRootPageLocked, function(page) {
+ if (page.willHidePage && page.name != pageName &&
!this.isAncestorOfPage(page, targetPage)) {
page.willHidePage();
}
- }
+ });
// Update visibilities to show only the hierarchy of the target page.
- for (var i = 0; i < allPageNames.length; ++i) {
- var name = allPageNames[i];
- var page = this.registeredPages[name] ||
- this.registeredOverlayPages[name];
- if (!page.parentPage && isRootPageLocked)
- continue;
- page.visible = name == pageName ||
+ this.forEachPage_(!isRootPageLocked, function(page) {
+ page.visible = page.name == pageName ||
this.isAncestorOfPage(page, targetPage);
- }
+ });
// Update the history and current location.
if (opt_updateHistory)
@@ -222,17 +207,13 @@ cr.define('cr.ui.pageManager', function() {
}
// Notify pages if they were shown.
- for (var i = 0; i < allPageNames.length; ++i) {
- var name = allPageNames[i];
- var page = this.registeredPages[name] ||
- this.registeredOverlayPages[name];
- if (!page.parentPage && isRootPageLocked)
- continue;
+ this.forEachPage_(!isRootPageLocked, function(page) {
if (!targetPageWasVisible && page.didShowPage &&
- (name == pageName || this.isAncestorOfPage(page, targetPage))) {
+ (page.name == pageName ||
+ this.isAncestorOfPage(page, targetPage))) {
page.didShowPage();
}
- }
+ });
// Update the document title. Do this after didShowPage was called, in
// case a page decides to change its title.
@@ -714,6 +695,24 @@ cr.define('cr.ui.pageManager', function() {
e.style.left = this.horizontalOffset - scrollLeft + 'px';
}
},
+
+ /**
+ * Calls the given callback with each registered page.
+ * @param {boolean} includeRootPages Whether the callback should be called
+ * for the root pages.
+ * @param {function(cr.ui.pageManager.Page)} callback The callback.
+ * @private
+ */
+ forEachPage_: function(includeRootPages, callback) {
+ var pageNames = Object.keys(this.registeredOverlayPages);
+ if (includeRootPages)
+ pageNames = Object.keys(this.registeredPages).concat(pageNames);
+
+ pageNames.forEach(function(name) {
+ callback.call(this, this.registeredOverlayPages[name] ||
+ this.registeredPages[name]);
+ }, this);
+ },
};
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698