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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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('cr.ui.pageManager', function() { 5 cr.define('cr.ui.pageManager', function() {
6 /** @const */ var FocusOutlineManager = cr.ui.FocusOutlineManager; 6 /** @const */ var FocusOutlineManager = cr.ui.FocusOutlineManager;
7 7
8 /** 8 /**
9 * PageManager contains a list of root Page and overlay Page objects and 9 * PageManager contains a list of root Page and overlay Page objects and
10 * handles "navigation" by showing and hiding these pages and overlays. On 10 * handles "navigation" by showing and hiding these pages and overlays. On
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 pageName = targetPage.name.toLowerCase(); 175 pageName = targetPage.name.toLowerCase();
176 var targetPageWasVisible = targetPage.visible; 176 var targetPageWasVisible = targetPage.visible;
177 177
178 // Determine if the root page is 'sticky', meaning that it 178 // Determine if the root page is 'sticky', meaning that it
179 // shouldn't change when showing an overlay. This can happen for special 179 // shouldn't change when showing an overlay. This can happen for special
180 // pages like Search. 180 // pages like Search.
181 var isRootPageLocked = 181 var isRootPageLocked =
182 rootPage && rootPage.sticky && targetPage.parentPage; 182 rootPage && rootPage.sticky && targetPage.parentPage;
183 183
184 var allPageNames = Array.prototype.concat.call(
185 Object.keys(this.registeredPages),
186 Object.keys(this.registeredOverlayPages));
187
188 // Notify pages if they will be hidden. 184 // Notify pages if they will be hidden.
189 // TODO(michaelpg): Resolve code duplication. 185 this.forEachPage_(!isRootPageLocked, function(page) {
190 for (var i = 0; i < allPageNames.length; ++i) { 186 if (page.willHidePage && page.name != pageName &&
191 var name = allPageNames[i];
192 var page = this.registeredPages[name] ||
193 this.registeredOverlayPages[name];
194 if (!page.parentPage && isRootPageLocked)
195 continue;
196 if (page.willHidePage && name != pageName &&
197 !this.isAncestorOfPage(page, targetPage)) { 187 !this.isAncestorOfPage(page, targetPage)) {
198 page.willHidePage(); 188 page.willHidePage();
199 } 189 }
200 } 190 });
201 191
202 // Update visibilities to show only the hierarchy of the target page. 192 // Update visibilities to show only the hierarchy of the target page.
203 for (var i = 0; i < allPageNames.length; ++i) { 193 this.forEachPage_(!isRootPageLocked, function(page) {
204 var name = allPageNames[i]; 194 page.visible = page.name == pageName ||
205 var page = this.registeredPages[name] ||
206 this.registeredOverlayPages[name];
207 if (!page.parentPage && isRootPageLocked)
208 continue;
209 page.visible = name == pageName ||
210 this.isAncestorOfPage(page, targetPage); 195 this.isAncestorOfPage(page, targetPage);
211 } 196 });
212 197
213 // Update the history and current location. 198 // Update the history and current location.
214 if (opt_updateHistory) 199 if (opt_updateHistory)
215 this.updateHistoryState_(!!opt_propertyBag.replaceState); 200 this.updateHistoryState_(!!opt_propertyBag.replaceState);
216 201
217 // Update focus if any other control was focused on the previous page, 202 // Update focus if any other control was focused on the previous page,
218 // or the previous page is not known. 203 // or the previous page is not known.
219 if (document.activeElement != document.body && 204 if (document.activeElement != document.body &&
220 (!rootPage || rootPage.pageDiv.contains(document.activeElement))) { 205 (!rootPage || rootPage.pageDiv.contains(document.activeElement))) {
221 targetPage.focus(); 206 targetPage.focus();
222 } 207 }
223 208
224 // Notify pages if they were shown. 209 // Notify pages if they were shown.
225 for (var i = 0; i < allPageNames.length; ++i) { 210 this.forEachPage_(!isRootPageLocked, function(page) {
226 var name = allPageNames[i];
227 var page = this.registeredPages[name] ||
228 this.registeredOverlayPages[name];
229 if (!page.parentPage && isRootPageLocked)
230 continue;
231 if (!targetPageWasVisible && page.didShowPage && 211 if (!targetPageWasVisible && page.didShowPage &&
232 (name == pageName || this.isAncestorOfPage(page, targetPage))) { 212 (page.name == pageName ||
213 this.isAncestorOfPage(page, targetPage))) {
233 page.didShowPage(); 214 page.didShowPage();
234 } 215 }
235 } 216 });
236 217
237 // Update the document title. Do this after didShowPage was called, in 218 // Update the document title. Do this after didShowPage was called, in
238 // case a page decides to change its title. 219 // case a page decides to change its title.
239 this.updateTitle_(); 220 this.updateTitle_();
240 }, 221 },
241 222
242 /** 223 /**
243 * Returns the name of the page from the current path. 224 * Returns the name of the page from the current path.
244 * @return {string} Name of the page specified by the current path. 225 * @return {string} Name of the page specified by the current path.
245 */ 226 */
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 * @private 688 * @private
708 */ 689 */
709 updateFrozenElementHorizontalPosition_: function(e) { 690 updateFrozenElementHorizontalPosition_: function(e) {
710 if (isRTL()) { 691 if (isRTL()) {
711 e.style.right = this.horizontalOffset + 'px'; 692 e.style.right = this.horizontalOffset + 'px';
712 } else { 693 } else {
713 var scrollLeft = scrollLeftForDocument(document); 694 var scrollLeft = scrollLeftForDocument(document);
714 e.style.left = this.horizontalOffset - scrollLeft + 'px'; 695 e.style.left = this.horizontalOffset - scrollLeft + 'px';
715 } 696 }
716 }, 697 },
698
699 /**
700 * Calls the given callback with each registered page.
701 * @param {boolean} includeRootPages Whether the callback should be called
702 * for the root pages.
703 * @param {function(cr.ui.pageManager.Page)} callback The callback.
704 * @private
705 */
706 forEachPage_: function(includeRootPages, callback) {
707 var pageNames = Object.keys(this.registeredOverlayPages);
708 if (includeRootPages)
709 pageNames = Object.keys(this.registeredPages).concat(pageNames);
710
711 pageNames.forEach(function(name) {
712 callback.call(this, this.registeredOverlayPages[name] ||
713 this.registeredPages[name]);
714 }, this);
715 },
717 }; 716 };
718 717
719 /** 718 /**
720 * An observer of PageManager. 719 * An observer of PageManager.
721 * @interface 720 * @interface
722 */ 721 */
723 PageManager.Observer = function() {} 722 PageManager.Observer = function() {}
724 723
725 PageManager.Observer.prototype = { 724 PageManager.Observer.prototype = {
726 /** 725 /**
(...skipping 14 matching lines...) Expand all
741 * @param {boolean} replace If true, allow no history events to be created. 740 * @param {boolean} replace If true, allow no history events to be created.
742 */ 741 */
743 updateHistory: function(path, replace) {}, 742 updateHistory: function(path, replace) {},
744 }; 743 };
745 744
746 // Export 745 // Export
747 return { 746 return {
748 PageManager: PageManager 747 PageManager: PageManager
749 }; 748 };
750 }); 749 });
OLDNEW
« 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