Commit 2d952ff0 authored by michaelpg's avatar michaelpg Committed by Commit bot

Clean up cr.ui.pageManager.Page prototype

BUG=313244
R=dbeam@chromium.org

Review URL: https://codereview.chromium.org/514503002

Cr-Commit-Position: refs/heads/master@{#295628}
parent efe56eaf
...@@ -104,9 +104,7 @@ cr.define('options', function() { ...@@ -104,9 +104,7 @@ cr.define('options', function() {
chrome.send('onChangePicturePageInitialized'); chrome.send('onChangePicturePageInitialized');
}, },
/** /** @override */
* Called right after the page has been shown to user.
*/
didShowPage: function() { didShowPage: function() {
var imageGrid = $('user-image-grid'); var imageGrid = $('user-image-grid');
// Reset camera element. // Reset camera element.
...@@ -115,9 +113,7 @@ cr.define('options', function() { ...@@ -115,9 +113,7 @@ cr.define('options', function() {
chrome.send('onChangePicturePageShown'); chrome.send('onChangePicturePageShown');
}, },
/** /** @override */
* Called right before the page is hidden.
*/
willHidePage: function() { willHidePage: function() {
var imageGrid = $('user-image-grid'); var imageGrid = $('user-image-grid');
imageGrid.blur(); // Make sure the image grid is not active. imageGrid.blur(); // Make sure the image grid is not active.
...@@ -130,10 +126,10 @@ cr.define('options', function() { ...@@ -130,10 +126,10 @@ cr.define('options', function() {
}, },
/** /**
* Called right after the page has been hidden. * Either willHidePage or didClosePage may be called depending on the way
* the page was closed.
* @override
*/ */
// TODO(ivankr): both callbacks are required as only one of them is called
// depending on the way the page was closed, see http://crbug.com/118923.
didClosePage: function() { didClosePage: function() {
this.willHidePage(); this.willHidePage();
}, },
......
...@@ -66,9 +66,7 @@ cr.define('options', function() { ...@@ -66,9 +66,7 @@ cr.define('options', function() {
}; };
}, },
/** /** @override */
* Called by the options page when this page has been shown.
*/
didShowPage: function() { didShowPage: function() {
// The fonts list may be large so we only load it when this page is // The fonts list may be large so we only load it when this page is
// loaded for the first time. This makes opening the options window // loaded for the first time. This makes opening the options window
......
...@@ -164,13 +164,11 @@ cr.define('options', function() { ...@@ -164,13 +164,11 @@ cr.define('options', function() {
return true; return true;
}, },
/** /** @override */
* Called after this page has shown.
*/
didShowPage: function() { didShowPage: function() {
// This method is called by the Options page after all pages have // This method is called by the PageManager after all pages have had their
// had their visibilty attribute set. At this point we can perform the // visibility attribute set. At this point we can perform the
// search specific DOM manipulation. // search-specific DOM manipulation.
this.setSearchActive_(true); this.setSearchActive_(true);
}, },
...@@ -179,14 +177,11 @@ cr.define('options', function() { ...@@ -179,14 +177,11 @@ cr.define('options', function() {
this.setSearchActive_(true); this.setSearchActive_(true);
}, },
/** /** @override */
* Called before this page will be hidden.
*/
willHidePage: function() { willHidePage: function() {
// This method is called by the Options page before all pages have // This method is called by the PageManager before all pages have their
// their visibilty attribute set. Before that happens, we need to // visibility attribute set. Before that happens, we need to undo the
// undo the search specific DOM manipulation that was performed in // search-specific DOM manipulation that was performed in didShowPage.
// didShowPage.
this.setSearchActive_(false); this.setSearchActive_(false);
}, },
......
...@@ -137,6 +137,22 @@ cr.define('cr.ui.pageManager', function() { ...@@ -137,6 +137,22 @@ cr.define('cr.ui.pageManager', function() {
PageManager.onPageHashChanged(this); PageManager.onPageHashChanged(this);
}, },
/**
* Called after the page has been shown.
*/
didShowPage: function() {},
/**
* Called before the page will be hidden, e.g., when a different root page
* will be shown.
*/
willHidePage: function() {},
/**
* Called after the overlay has been closed.
*/
didClosePage: function() {},
/** /**
* Gets the container div for this page if it is an overlay. * Gets the container div for this page if it is an overlay.
* @type {HTMLDivElement} * @type {HTMLDivElement}
......
...@@ -185,10 +185,8 @@ cr.define('cr.ui.pageManager', function() { ...@@ -185,10 +185,8 @@ cr.define('cr.ui.pageManager', function() {
// Notify pages if they will be hidden. // Notify pages if they will be hidden.
this.forEachPage_(!isRootPageLocked, function(page) { this.forEachPage_(!isRootPageLocked, function(page) {
if (page.willHidePage && page.name != pageName && if (page.name != pageName && !this.isAncestorOfPage(page, targetPage))
!this.isAncestorOfPage(page, targetPage)) {
page.willHidePage(); page.willHidePage();
}
}); });
// Update the page's hash. // Update the page's hash.
...@@ -213,7 +211,7 @@ cr.define('cr.ui.pageManager', function() { ...@@ -213,7 +211,7 @@ cr.define('cr.ui.pageManager', function() {
// Notify pages if they were shown. // Notify pages if they were shown.
this.forEachPage_(!isRootPageLocked, function(page) { this.forEachPage_(!isRootPageLocked, function(page) {
if (!targetPageWasVisible && page.didShowPage && if (!targetPageWasVisible &&
(page.name == pageName || (page.name == pageName ||
this.isAncestorOfPage(page, targetPage))) { this.isAncestorOfPage(page, targetPage))) {
page.didShowPage(); page.didShowPage();
...@@ -333,9 +331,8 @@ cr.define('cr.ui.pageManager', function() { ...@@ -333,9 +331,8 @@ cr.define('cr.ui.pageManager', function() {
return; return;
overlay.visible = false; overlay.visible = false;
overlay.didClosePage();
if (overlay.didClosePage)
overlay.didClosePage();
this.updateHistoryState_(false); this.updateHistoryState_(false);
this.updateTitle_(); this.updateTitle_();
...@@ -422,7 +419,7 @@ cr.define('cr.ui.pageManager', function() { ...@@ -422,7 +419,7 @@ cr.define('cr.ui.pageManager', function() {
this.defaultPage_; this.defaultPage_;
if (currentOverlay && !this.isAncestorOfPage(currentOverlay, newPage)) { if (currentOverlay && !this.isAncestorOfPage(currentOverlay, newPage)) {
currentOverlay.visible = false; currentOverlay.visible = false;
if (currentOverlay.didClosePage) currentOverlay.didClosePage(); currentOverlay.didClosePage();
} }
this.showPageByName(pageName, false, {hash: hash}); this.showPageByName(pageName, false, {hash: hash});
}, },
...@@ -442,7 +439,7 @@ cr.define('cr.ui.pageManager', function() { ...@@ -442,7 +439,7 @@ cr.define('cr.ui.pageManager', function() {
*/ */
willClose: function() { willClose: function() {
var overlay = this.getVisibleOverlay_(); var overlay = this.getVisibleOverlay_();
if (overlay && overlay.didClosePage) if (overlay)
overlay.didClosePage(); overlay.didClosePage();
}, },
...@@ -500,8 +497,7 @@ cr.define('cr.ui.pageManager', function() { ...@@ -500,8 +497,7 @@ cr.define('cr.ui.pageManager', function() {
overlay.hash = hash; overlay.hash = hash;
if (!overlay.visible) { if (!overlay.visible) {
overlay.visible = true; overlay.visible = true;
if (overlay.didShowPage) overlay.didShowPage();
overlay.didShowPage();
} else { } else {
overlay.didChangeHash(); overlay.didChangeHash();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment