Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
| 6 * @typedef {{about: boolean, basic: boolean, advanced: boolean}} | 6 * @typedef {{about: boolean, basic: boolean, advanced: boolean}} |
| 7 */ | 7 */ |
| 8 var MainPageVisibility; | 8 var MainPageVisibility; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 * @return {boolean} Whether to show the advanced page, taking into account | 187 * @return {boolean} Whether to show the advanced page, taking into account |
| 188 * both routing and search state. | 188 * both routing and search state. |
| 189 * @private | 189 * @private |
| 190 */ | 190 */ |
| 191 showAdvancedPage_: function() { | 191 showAdvancedPage_: function() { |
| 192 return this.showPages_.advanced || ( | 192 return this.showPages_.advanced || ( |
| 193 this.inSearchMode_ && !this.hasExpandedSection_); | 193 this.inSearchMode_ && !this.hasExpandedSection_); |
| 194 }, | 194 }, |
| 195 | 195 |
| 196 /** @param {!settings.Route} newRoute */ | 196 /** @param {!settings.Route} newRoute */ |
| 197 currentRouteChanged: function(newRoute) { | 197 currentRouteChanged: function(newRoute, previousRoute) { |
| 198 // Don't issue any new search requests, if the current page is a subpage or | |
| 199 // if user returns to a top-level from a subpage, since the search hits are | |
| 200 // already highlighted. | |
| 201 if (!newRoute.isSubpage() && | |
|
dpapad
2016/10/27 17:39:58
As I was explaining this logic to Tommy, he found
| |
| 202 (!previousRoute || !previousRoute.isSubpage())) { | |
| 203 var searchQuery = settings.getQueryParameters().get('search') || ''; | |
| 204 if (searchQuery) | |
| 205 this.searchContents_(searchQuery); | |
| 206 else if (this.inSearchMode_) | |
| 207 this.searchContents_(''); | |
| 208 } | |
| 209 | |
| 198 // When the route changes from a sub-page to the main page, immediately | 210 // When the route changes from a sub-page to the main page, immediately |
| 199 // update hasExpandedSection_ to unhide the other sections. | 211 // update hasExpandedSection_ to unhide the other sections. |
| 200 if (!newRoute.isSubpage()) | 212 if (!newRoute.isSubpage()) |
| 201 this.hasExpandedSection_ = false; | 213 this.hasExpandedSection_ = false; |
| 202 | 214 |
| 203 if (settings.Route.ADVANCED.contains(newRoute)) | 215 if (settings.Route.ADVANCED.contains(newRoute)) |
| 204 this.advancedToggleExpanded = true; | 216 this.advancedToggleExpanded = true; |
| 205 | 217 |
| 206 this.updatePagesShown_(); | 218 this.updatePagesShown_(); |
| 207 }, | 219 }, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 this.$$('settings-advanced-page')); | 318 this.$$('settings-advanced-page')); |
| 307 } | 319 } |
| 308 if (settings.Route.BASIC.contains(route)) { | 320 if (settings.Route.BASIC.contains(route)) { |
| 309 return /** @type {?SettingsBasicPageElement} */( | 321 return /** @type {?SettingsBasicPageElement} */( |
| 310 this.$$('settings-basic-page')); | 322 this.$$('settings-basic-page')); |
| 311 } | 323 } |
| 312 assertNotReached(); | 324 assertNotReached(); |
| 313 }, | 325 }, |
| 314 | 326 |
| 315 /** | 327 /** |
| 316 * Navigates to the default search page (if necessary). | |
| 317 * @private | |
| 318 */ | |
| 319 ensureInDefaultSearchPage_: function() { | |
| 320 if (settings.getCurrentRoute() != settings.Route.BASIC) | |
| 321 settings.navigateTo(settings.Route.BASIC); | |
| 322 }, | |
| 323 | |
| 324 /** | |
| 325 * @param {string} query | 328 * @param {string} query |
| 326 * @return {!Promise} A promise indicating that searching finished. | 329 * @return {!Promise} A promise indicating that searching finished. |
| 327 */ | 330 */ |
| 328 searchContents: function(query) { | 331 searchContents_: function(query) { |
| 329 // Trigger rendering of the basic and advanced pages and search once ready. | 332 // Trigger rendering of the basic and advanced pages and search once ready. |
| 330 this.inSearchMode_ = true; | 333 this.inSearchMode_ = true; |
| 331 this.ensureInDefaultSearchPage_(); | |
| 332 this.toolbarSpinnerActive = true; | 334 this.toolbarSpinnerActive = true; |
| 333 | 335 |
| 334 return new Promise(function(resolve, reject) { | 336 return new Promise(function(resolve, reject) { |
| 335 setTimeout(function() { | 337 setTimeout(function() { |
| 336 var whenSearchDone = settings.getSearchManager().search( | 338 var whenSearchDone = settings.getSearchManager().search( |
| 337 query, assert(this.getPage_(settings.Route.BASIC))); | 339 query, assert(this.getPage_(settings.Route.BASIC))); |
| 338 assert( | 340 assert( |
| 339 whenSearchDone === | 341 whenSearchDone === |
| 340 settings.getSearchManager().search( | 342 settings.getSearchManager().search( |
| 341 query, assert(this.getPage_(settings.Route.ADVANCED)))); | 343 query, assert(this.getPage_(settings.Route.ADVANCED)))); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 360 | 362 |
| 361 /** | 363 /** |
| 362 * @param {(boolean|undefined)} visibility | 364 * @param {(boolean|undefined)} visibility |
| 363 * @return {boolean} True unless visibility is false. | 365 * @return {boolean} True unless visibility is false. |
| 364 * @private | 366 * @private |
| 365 */ | 367 */ |
| 366 showAdvancedSettings_: function(visibility) { | 368 showAdvancedSettings_: function(visibility) { |
| 367 return visibility !== false; | 369 return visibility !== false; |
| 368 }, | 370 }, |
| 369 }); | 371 }); |
| OLD | NEW |