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

Side by Side Diff: chrome/browser/resources/options/search_page.js

Issue 410293004: Split OptionsPage into Page and PageManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ugh just no 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
OLDNEW
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 /** @const */ var OptionsPage = options.OptionsPage; 6 /** @const */ var Page = cr.ui.pageManager.Page;
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
7 8
8 /** 9 /**
9 * Encapsulated handling of a search bubble. 10 * Encapsulated handling of a search bubble.
10 * @constructor 11 * @constructor
11 */ 12 */
12 function SearchBubble(text) { 13 function SearchBubble(text) {
13 var el = cr.doc.createElement('div'); 14 var el = cr.doc.createElement('div');
14 SearchBubble.decorate(el); 15 SearchBubble.decorate(el);
15 el.content = text; 16 el.content = text;
16 return el; 17 return el;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 this.lastTop = top; 108 this.lastTop = top;
108 } 109 }
109 }, 110 },
110 }; 111 };
111 112
112 /** 113 /**
113 * Encapsulated handling of the search page. 114 * Encapsulated handling of the search page.
114 * @constructor 115 * @constructor
115 */ 116 */
116 function SearchPage() { 117 function SearchPage() {
117 OptionsPage.call(this, 'search', 118 Page.call(this, 'search',
118 loadTimeData.getString('searchPageTabTitle'), 119 loadTimeData.getString('searchPageTabTitle'),
119 'searchPage'); 120 'searchPage');
120 } 121 }
121 122
122 cr.addSingletonGetter(SearchPage); 123 cr.addSingletonGetter(SearchPage);
123 124
124 SearchPage.prototype = { 125 SearchPage.prototype = {
125 // Inherit SearchPage from OptionsPage. 126 // Inherit SearchPage from Page.
126 __proto__: OptionsPage.prototype, 127 __proto__: Page.prototype,
127 128
128 /** 129 /**
129 * A boolean to prevent recursion. Used by setSearchText_(). 130 * A boolean to prevent recursion. Used by setSearchText_().
130 * @type {boolean} 131 * @type {boolean}
131 * @private 132 * @private
132 */ 133 */
133 insideSetSearchText_: false, 134 insideSetSearchText_: false,
134 135
135 /** @override */ 136 /** @override */
136 initializePage: function() { 137 initializePage: function() {
137 // Call base class implementation to start preference initialization. 138 Page.prototype.initializePage.call(this);
138 OptionsPage.prototype.initializePage.call(this);
139 139
140 this.searchField = $('search-field'); 140 this.searchField = $('search-field');
141 141
142 // Handle search events. (No need to throttle, WebKit's search field 142 // Handle search events. (No need to throttle, WebKit's search field
143 // will do that automatically.) 143 // will do that automatically.)
144 this.searchField.onsearch = function(e) { 144 this.searchField.onsearch = function(e) {
145 this.setSearchText_(e.currentTarget.value); 145 this.setSearchText_(e.currentTarget.value);
146 }.bind(this); 146 }.bind(this);
147 147
148 // Install handler for key presses. 148 // Install handler for key presses.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 this.searchActive_ = active; 190 this.searchActive_ = active;
191 191
192 if (active) { 192 if (active) {
193 var hash = location.hash; 193 var hash = location.hash;
194 if (hash) { 194 if (hash) {
195 this.searchField.value = 195 this.searchField.value =
196 decodeURIComponent(hash.slice(1).replace(/\+/g, ' ')); 196 decodeURIComponent(hash.slice(1).replace(/\+/g, ' '));
197 } else if (!this.searchField.value) { 197 } else if (!this.searchField.value) {
198 // This should only happen if the user goes directly to 198 // This should only happen if the user goes directly to
199 // chrome://settings-frame/search 199 // chrome://settings-frame/search
200 OptionsPage.showDefaultPage(); 200 PageManager.showDefaultPage();
201 return; 201 return;
202 } 202 }
203 203
204 // Move 'advanced' sections into the main settings page to allow 204 // Move 'advanced' sections into the main settings page to allow
205 // searching. 205 // searching.
206 if (!this.advancedSections_) { 206 if (!this.advancedSections_) {
207 this.advancedSections_ = 207 this.advancedSections_ =
208 $('advanced-settings-container').querySelectorAll('section'); 208 $('advanced-settings-container').querySelectorAll('section');
209 for (var i = 0, section; section = this.advancedSections_[i]; i++) 209 for (var i = 0, section; section = this.advancedSections_[i]; i++)
210 $('settings').appendChild(section); 210 $('settings').appendChild(section);
(...skipping 14 matching lines...) Expand all
225 if (active) { 225 if (active) {
226 if (childDiv.tagName != 'SECTION') 226 if (childDiv.tagName != 'SECTION')
227 childDiv.classList.add('search-hidden'); 227 childDiv.classList.add('search-hidden');
228 } else { 228 } else {
229 childDiv.classList.remove('search-hidden'); 229 childDiv.classList.remove('search-hidden');
230 } 230 }
231 } 231 }
232 232
233 if (active) { 233 if (active) {
234 // When search is active, remove the 'hidden' tag. This tag may have 234 // When search is active, remove the 'hidden' tag. This tag may have
235 // been added by the OptionsPage. 235 // been added by the PageManager.
236 page.pageDiv.hidden = false; 236 page.pageDiv.hidden = false;
237 } 237 }
238 } 238 }
239 239
240 if (active) { 240 if (active) {
241 this.setSearchText_(this.searchField.value); 241 this.setSearchText_(this.searchField.value);
242 this.searchField.focus(); 242 this.searchField.focus();
243 } else { 243 } else {
244 // After hiding all page content, remove any search results. 244 // After hiding all page content, remove any search results.
245 this.unhighlightMatches_(); 245 this.unhighlightMatches_();
(...skipping 22 matching lines...) Expand all
268 text = SearchPage.canonicalizeQuery(text); 268 text = SearchPage.canonicalizeQuery(text);
269 269
270 // Set the hash on the current page, and the enclosing uber page 270 // Set the hash on the current page, and the enclosing uber page
271 var hash = text ? '#' + encodeURIComponent(text) : ''; 271 var hash = text ? '#' + encodeURIComponent(text) : '';
272 var path = text ? this.name : ''; 272 var path = text ? this.name : '';
273 uber.pushState({}, path + hash); 273 uber.pushState({}, path + hash);
274 274
275 // Toggle the search page if necessary. 275 // Toggle the search page if necessary.
276 if (text) { 276 if (text) {
277 if (!this.searchActive_) 277 if (!this.searchActive_)
278 OptionsPage.showPageByName(this.name, false); 278 PageManager.showPageByName(this.name, false);
279 } else { 279 } else {
280 if (this.searchActive_) 280 if (this.searchActive_)
281 OptionsPage.showPageByName(OptionsPage.getDefaultPage().name, false); 281 PageManager.showDefaultPage(false);
282 282
283 this.insideSetSearchText_ = false; 283 this.insideSetSearchText_ = false;
284 return; 284 return;
285 } 285 }
286 286
287 var foundMatches = false; 287 var foundMatches = false;
288 288
289 // Remove any prior search results. 289 // Remove any prior search results.
290 this.unhighlightMatches_(); 290 this.unhighlightMatches_();
291 this.removeSearchBubbles_(); 291 this.removeSearchBubbles_();
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 }, 483 },
484 484
485 /** 485 /**
486 * Builds a list of top-level pages to search. Omits the search page and 486 * Builds a list of top-level pages to search. Omits the search page and
487 * all sub-pages. 487 * all sub-pages.
488 * @return {Array} An array of pages to search. 488 * @return {Array} An array of pages to search.
489 * @private 489 * @private
490 */ 490 */
491 getSearchablePages_: function() { 491 getSearchablePages_: function() {
492 var name, page, pages = []; 492 var name, page, pages = [];
493 for (name in OptionsPage.registeredPages) { 493 for (name in PageManager.registeredPages) {
494 if (name != this.name) { 494 if (name != this.name) {
495 page = OptionsPage.registeredPages[name]; 495 page = PageManager.registeredPages[name];
496 if (!page.parentPage) 496 if (!page.parentPage)
497 pages.push(page); 497 pages.push(page);
498 } 498 }
499 } 499 }
500 return pages; 500 return pages;
501 }, 501 },
502 502
503 /** 503 /**
504 * Builds a list of sub-pages (and overlay pages) to search. Ignore pages 504 * Builds a list of sub-pages (and overlay pages) to search. Ignore pages
505 * that have no associated controls, or whose controls are hidden. 505 * that have no associated controls, or whose controls are hidden.
506 * @return {Array} An array of pages to search. 506 * @return {Array} An array of pages to search.
507 * @private 507 * @private
508 */ 508 */
509 getSearchableSubPages_: function() { 509 getSearchableSubPages_: function() {
510 var name, pageInfo, page, pages = []; 510 var name, pageInfo, page, pages = [];
511 for (name in OptionsPage.registeredPages) { 511 for (name in PageManager.registeredPages) {
512 page = OptionsPage.registeredPages[name]; 512 page = PageManager.registeredPages[name];
513 if (page.parentPage && 513 if (page.parentPage &&
514 page.associatedSection && 514 page.associatedSection &&
515 !page.associatedSection.hidden) { 515 !page.associatedSection.hidden) {
516 pages.push(page); 516 pages.push(page);
517 } 517 }
518 } 518 }
519 for (name in OptionsPage.registeredOverlayPages) { 519 for (name in PageManager.registeredOverlayPages) {
520 page = OptionsPage.registeredOverlayPages[name]; 520 page = PageManager.registeredOverlayPages[name];
521 if (page.associatedSection && 521 if (page.associatedSection &&
522 !page.associatedSection.hidden && 522 !page.associatedSection.hidden &&
523 page.pageDiv != undefined) { 523 page.pageDiv != undefined) {
524 pages.push(page); 524 pages.push(page);
525 } 525 }
526 } 526 }
527 return pages; 527 return pages;
528 }, 528 },
529 529
530 /** 530 /**
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // Trim beginning and ending whitespace. 566 // Trim beginning and ending whitespace.
567 return text.replace(/^\s+|\s+$/g, ''); 567 return text.replace(/^\s+|\s+$/g, '');
568 }; 568 };
569 569
570 // Export 570 // Export
571 return { 571 return {
572 SearchPage: SearchPage 572 SearchPage: SearchPage
573 }; 573 };
574 574
575 }); 575 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/search_engine_manager.js ('k') | chrome/browser/resources/options/settings_dialog.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698