| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 * @private {!MainPageVisibility} | 49 * @private {!MainPageVisibility} |
| 50 */ | 50 */ |
| 51 showPages_: { | 51 showPages_: { |
| 52 type: Object, | 52 type: Object, |
| 53 value: function() { | 53 value: function() { |
| 54 return {about: false, basic: false, advanced: false}; | 54 return {about: false, basic: false, advanced: false}; |
| 55 }, | 55 }, |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * The main pages that were displayed before search was initiated. When | 59 * Whether a search operation is in progress or previous search results are |
| 60 * |null| it indicates that currently the page is displaying its normal | 60 * being displayed. |
| 61 * contents, instead of displaying search results. | 61 * @private {boolean} |
| 62 * @private {?MainPageVisibility} | |
| 63 */ | 62 */ |
| 64 previousShowPages_: { | 63 inSearchMode_: { |
| 65 type: Object, | 64 type: Boolean, |
| 66 value: null, | 65 value: false, |
| 67 }, | 66 }, |
| 68 | 67 |
| 69 /** @private */ | 68 /** @private */ |
| 70 showNoResultsFound_: { | 69 showNoResultsFound_: { |
| 71 type: Boolean, | 70 type: Boolean, |
| 72 value: false, | 71 value: false, |
| 73 }, | 72 }, |
| 74 | 73 |
| 75 toolbarSpinnerActive: { | 74 toolbarSpinnerActive: { |
| 76 type: Boolean, | 75 type: Boolean, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 */ | 134 */ |
| 136 arrowState_: function(opened) { | 135 arrowState_: function(opened) { |
| 137 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 136 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 138 }, | 137 }, |
| 139 | 138 |
| 140 /** | 139 /** |
| 141 * @return {boolean} | 140 * @return {boolean} |
| 142 * @private | 141 * @private |
| 143 */ | 142 */ |
| 144 showAdvancedToggle_: function() { | 143 showAdvancedToggle_: function() { |
| 145 var inSearchMode = !!this.previousShowPages_; | 144 return !this.inSearchMode_ && this.showPages_.basic && |
| 146 return !inSearchMode && this.showPages_.basic && !this.hasExpandedSection_; | 145 !this.hasExpandedSection_; |
| 147 }, | 146 }, |
| 148 | 147 |
| 149 currentRouteChanged: function(newRoute) { | 148 currentRouteChanged: function(newRoute) { |
| 150 // When the route changes from a sub-page to the main page, immediately | 149 // When the route changes from a sub-page to the main page, immediately |
| 151 // update hasExpandedSection_ to unhide the other sections. | 150 // update hasExpandedSection_ to unhide the other sections. |
| 152 if (!newRoute.isSubpage()) | 151 if (!newRoute.isSubpage()) |
| 153 this.hasExpandedSection_ = false; | 152 this.hasExpandedSection_ = false; |
| 154 | 153 |
| 155 if (settings.Route.ADVANCED.contains(newRoute)) | 154 if (settings.Route.ADVANCED.contains(newRoute)) |
| 156 this.advancedToggleExpanded_ = true; | 155 this.advancedToggleExpanded_ = true; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 ensureInDefaultSearchPage_: function() { | 253 ensureInDefaultSearchPage_: function() { |
| 255 if (settings.getCurrentRoute() != settings.Route.BASIC) | 254 if (settings.getCurrentRoute() != settings.Route.BASIC) |
| 256 settings.navigateTo(settings.Route.BASIC); | 255 settings.navigateTo(settings.Route.BASIC); |
| 257 }, | 256 }, |
| 258 | 257 |
| 259 /** | 258 /** |
| 260 * @param {string} query | 259 * @param {string} query |
| 261 * @return {!Promise} A promise indicating that searching finished. | 260 * @return {!Promise} A promise indicating that searching finished. |
| 262 */ | 261 */ |
| 263 searchContents: function(query) { | 262 searchContents: function(query) { |
| 264 if (!this.previousShowPages_) { | 263 this.inSearchMode_ = true; |
| 265 // Store which pages are shown before search, so that they can be restored | |
| 266 // after the user clears the search results. | |
| 267 this.previousShowPages_ = this.showPages_; | |
| 268 } | |
| 269 | |
| 270 this.ensureInDefaultSearchPage_(); | 264 this.ensureInDefaultSearchPage_(); |
| 271 this.toolbarSpinnerActive = true; | 265 this.toolbarSpinnerActive = true; |
| 272 | 266 |
| 273 // Trigger rendering of the basic and advanced pages and search once ready. | 267 // Trigger rendering of the basic and advanced pages and search once ready. |
| 274 this.showPages_ = {about: false, basic: true, advanced: true}; | 268 this.showPages_ = {about: false, basic: true, advanced: true}; |
| 275 | 269 |
| 276 return new Promise(function(resolve, reject) { | 270 return new Promise(function(resolve, reject) { |
| 277 setTimeout(function() { | 271 setTimeout(function() { |
| 278 var whenSearchDone = settings.getSearchManager().search( | 272 var whenSearchDone = settings.getSearchManager().search( |
| 279 query, assert(this.getPage_(settings.Route.BASIC))); | 273 query, assert(this.getPage_(settings.Route.BASIC))); |
| 280 assert( | 274 assert( |
| 281 whenSearchDone === | 275 whenSearchDone === |
| 282 settings.getSearchManager().search( | 276 settings.getSearchManager().search( |
| 283 query, assert(this.getPage_(settings.Route.ADVANCED)))); | 277 query, assert(this.getPage_(settings.Route.ADVANCED)))); |
| 284 | 278 |
| 285 whenSearchDone.then(function(request) { | 279 whenSearchDone.then(function(request) { |
| 286 resolve(); | 280 resolve(); |
| 287 if (!request.finished) { | 281 if (!request.finished) { |
| 288 // Nothing to do here. A previous search request was canceled | 282 // Nothing to do here. A previous search request was canceled |
| 289 // because a new search request was issued before the first one | 283 // because a new search request was issued before the first one |
| 290 // completed. | 284 // completed. |
| 291 return; | 285 return; |
| 292 } | 286 } |
| 293 | 287 |
| 294 this.toolbarSpinnerActive = false; | 288 this.toolbarSpinnerActive = false; |
| 295 var showingSearchResults = !request.isSame(''); | 289 this.inSearchMode_ = !request.isSame(''); |
| 296 this.showNoResultsFound_ = | 290 this.showNoResultsFound_ = |
| 297 showingSearchResults && !request.didFindMatches(); | 291 this.inSearchMode_ && !request.didFindMatches(); |
| 298 | 292 |
| 299 if (!showingSearchResults) { | 293 if (!this.inSearchMode_) { |
| 300 // Restore the pages that were shown before search was initiated. | 294 // Restore the "advanced" page visibility as it was before search |
| 301 this.showPages_ = assert(this.previousShowPages_); | 295 // was initiated. |
| 302 this.previousShowPages_ = null; | 296 this.showPages_ = { |
| 297 about: false, basic: true, advanced: this.advancedToggleExpanded_, |
| 298 }; |
| 303 } | 299 } |
| 304 }.bind(this)); | 300 }.bind(this)); |
| 305 }.bind(this), 0); | 301 }.bind(this), 0); |
| 306 }.bind(this)); | 302 }.bind(this)); |
| 307 }, | 303 }, |
| 308 | 304 |
| 309 /** | 305 /** |
| 310 * @param {(boolean|undefined)} visibility | 306 * @param {(boolean|undefined)} visibility |
| 311 * @return {boolean} True unless visibility is false. | 307 * @return {boolean} True unless visibility is false. |
| 312 * @private | 308 * @private |
| 313 */ | 309 */ |
| 314 showAdvancedSettings_: function(visibility) { | 310 showAdvancedSettings_: function(visibility) { |
| 315 return visibility !== false; | 311 return visibility !== false; |
| 316 }, | 312 }, |
| 317 }); | 313 }); |
| OLD | NEW |