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 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-main' displays the selected settings page. | 7 * 'settings-main' displays the selected settings page. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-main', | 10 is: 'settings-main', |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 * @type {!{about: boolean, basic: boolean, advanced: boolean}} | 40 * @type {!{about: boolean, basic: boolean, advanced: boolean}} |
| 41 * @private | 41 * @private |
| 42 */ | 42 */ |
| 43 showPages_: { | 43 showPages_: { |
| 44 type: Object, | 44 type: Object, |
| 45 value: function() { | 45 value: function() { |
| 46 return {about: false, basic: false, advanced: false}; | 46 return {about: false, basic: false, advanced: false}; |
| 47 }, | 47 }, |
| 48 }, | 48 }, |
| 49 | 49 |
| 50 /** | |
| 51 * The main pages that were displayed before search was initiated. When | |
| 52 * |null| it indicates that currently the page is displaying its normal | |
| 53 * contents, instead of displaying search results. | |
| 54 * @type {?{about: boolean, basic: boolean, advanced: boolean}} | |
|
Dan Beam
2016/08/11 05:32:34
can we typedef this?
dpapad
2016/08/11 18:20:03
Done.
| |
| 55 * @private | |
| 56 */ | |
| 57 previousShowPages_: { | |
| 58 type: Object, | |
| 59 value: null, | |
| 60 }, | |
| 61 | |
| 50 /** @private */ | 62 /** @private */ |
| 51 showNoResultsFound_: { | 63 showNoResultsFound_: { |
| 52 type: Boolean, | 64 type: Boolean, |
| 53 value: false, | 65 value: false, |
| 54 }, | 66 }, |
| 55 | 67 |
| 56 toolbarSpinnerActive: { | 68 toolbarSpinnerActive: { |
| 57 type: Boolean, | 69 type: Boolean, |
| 58 value: false, | 70 value: false, |
| 59 notify: true, | 71 notify: true, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 /** | 117 /** |
| 106 * @param {boolean} opened Whether the menu is expanded. | 118 * @param {boolean} opened Whether the menu is expanded. |
| 107 * @return {string} Which icon to use. | 119 * @return {string} Which icon to use. |
| 108 * @private | 120 * @private |
| 109 */ | 121 */ |
| 110 arrowState_: function(opened) { | 122 arrowState_: function(opened) { |
| 111 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 123 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 112 }, | 124 }, |
| 113 | 125 |
| 114 /** | 126 /** |
| 115 * @param {boolean} showBasicPage | |
| 116 * @param {boolean} inSubpage | |
| 117 * @return {boolean} | 127 * @return {boolean} |
| 118 * @private | 128 * @private |
| 119 */ | 129 */ |
| 120 showAdvancedToggle_: function(showBasicPage, inSubpage) { | 130 showAdvancedToggle_: function() { |
|
Dan Beam
2016/08/11 05:32:34
nit:
var isSearching = !!this.previousShowPages_;
dpapad
2016/08/11 18:20:03
Done. I chose a slightly different name, inSearchM
| |
| 121 return showBasicPage && !inSubpage; | 131 return this.showPages_.basic && !this.inSubpage_ && |
| 132 !this.previousShowPages_; | |
| 122 }, | 133 }, |
| 123 | 134 |
| 124 /** @protected */ | 135 /** @protected */ |
| 125 currentRouteChanged: function(newRoute) { | 136 currentRouteChanged: function(newRoute) { |
| 126 this.inSubpage_ = newRoute.subpage.length > 0; | 137 this.inSubpage_ = newRoute.subpage.length > 0; |
| 127 this.style.height = this.inSubpage_ ? '100%' : ''; | 138 this.style.height = this.inSubpage_ ? '100%' : ''; |
| 128 | 139 |
| 129 if (settings.Route.ABOUT.contains(newRoute)) { | 140 if (settings.Route.ABOUT.contains(newRoute)) { |
| 130 this.showPages_ = {about: true, basic: false, advanced: false}; | 141 this.showPages_ = {about: true, basic: false, advanced: false}; |
| 131 } else { | 142 } else { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 */ | 202 */ |
| 192 ensureInDefaultSearchPage_: function() { | 203 ensureInDefaultSearchPage_: function() { |
| 193 settings.navigateTo(settings.Route.BASIC); | 204 settings.navigateTo(settings.Route.BASIC); |
| 194 }, | 205 }, |
| 195 | 206 |
| 196 /** | 207 /** |
| 197 * @param {string} query | 208 * @param {string} query |
| 198 * @return {!Promise} A promise indicating that searching finished. | 209 * @return {!Promise} A promise indicating that searching finished. |
| 199 */ | 210 */ |
| 200 searchContents: function(query) { | 211 searchContents: function(query) { |
| 212 if (!this.previousShowPages_) { | |
| 213 // Store which pages are shown before search, so that they can be restored | |
| 214 // after the user clears the search results. | |
| 215 this.previousShowPages_ = this.showPages_; | |
| 216 } | |
| 217 | |
| 201 this.ensureInDefaultSearchPage_(); | 218 this.ensureInDefaultSearchPage_(); |
| 202 this.toolbarSpinnerActive = true; | 219 this.toolbarSpinnerActive = true; |
| 203 | 220 |
| 204 // Trigger rendering of the basic and advanced pages and search once ready. | 221 // Trigger rendering of the basic and advanced pages and search once ready. |
| 205 this.showPages_ = {about: false, basic: true, advanced: true}; | 222 this.showPages_ = {about: false, basic: true, advanced: true}; |
| 206 | 223 |
| 207 return new Promise(function(resolve, reject) { | 224 return new Promise(function(resolve, reject) { |
| 208 setTimeout(function() { | 225 setTimeout(function() { |
| 209 var whenSearchDone = settings.getSearchManager().search( | 226 var whenSearchDone = settings.getSearchManager().search( |
| 210 query, assert(this.$$('settings-basic-page'))); | 227 query, assert(this.$$('settings-basic-page'))); |
| 211 assert( | 228 assert( |
| 212 whenSearchDone === | 229 whenSearchDone === |
| 213 settings.getSearchManager().search( | 230 settings.getSearchManager().search( |
| 214 query, assert(this.$$('settings-advanced-page')))); | 231 query, assert(this.$$('settings-advanced-page')))); |
| 215 | 232 |
| 216 whenSearchDone.then(function(request) { | 233 whenSearchDone.then(function(request) { |
| 217 resolve(); | 234 resolve(); |
| 218 if (!request.finished) { | 235 if (!request.finished) { |
| 219 // Nothing to do here. A previous search request was canceled | 236 // Nothing to do here. A previous search request was canceled |
| 220 // because a new search request was issued before the first one | 237 // because a new search request was issued before the first one |
| 221 // completed. | 238 // completed. |
| 222 return; | 239 return; |
| 223 } | 240 } |
| 224 | 241 |
| 225 this.toolbarSpinnerActive = false; | 242 this.toolbarSpinnerActive = false; |
| 243 var showingSearchResults = !request.isSame(''); | |
| 226 this.showNoResultsFound_ = | 244 this.showNoResultsFound_ = |
| 227 !request.isSame('') && !request.didFindMatches(); | 245 showingSearchResults && !request.didFindMatches(); |
| 246 | |
| 247 if (!showingSearchResults) { | |
| 248 // Restore the pages that were shown before search was initiated. | |
| 249 this.showPages_ = assert(this.previousShowPages_); | |
| 250 this.previousShowPages_ = null; | |
| 251 } | |
| 228 }.bind(this)); | 252 }.bind(this)); |
| 229 }.bind(this), 0); | 253 }.bind(this), 0); |
| 230 }.bind(this)); | 254 }.bind(this)); |
| 231 }, | 255 }, |
| 232 | 256 |
| 233 /** | 257 /** |
| 234 * @param {(boolean|undefined)} visibility | 258 * @param {(boolean|undefined)} visibility |
| 235 * @return {boolean} True unless visibility is false. | 259 * @return {boolean} True unless visibility is false. |
| 236 * @private | 260 * @private |
| 237 */ | 261 */ |
| 238 showAdvancedSettings_: function(visibility) { | 262 showAdvancedSettings_: function(visibility) { |
| 239 return visibility !== false; | 263 return visibility !== false; |
| 240 }, | 264 }, |
| 241 }); | 265 }); |
| OLD | NEW |