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

Side by Side Diff: chrome/browser/resources/settings/settings_main/settings_main.js

Issue 2350313003: MD Settings: Ensure all search results are visible when going back. (Closed)
Patch Set: Fix Created 4 years, 3 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
OLDNEW
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 27 matching lines...) Expand all
38 */ 38 */
39 hasExpandedSection_: Boolean, 39 hasExpandedSection_: Boolean,
40 40
41 /** @private */ 41 /** @private */
42 overscroll_: { 42 overscroll_: {
43 type: Number, 43 type: Number,
44 observer: 'overscrollChanged_', 44 observer: 'overscrollChanged_',
45 }, 45 },
46 46
47 /** 47 /**
48 * Controls which main pages are displayed via dom-ifs. 48 * Controls which main pages are displayed via dom-ifs, based on the current
49 * route and the Advanced toggle state.
49 * @private {!MainPageVisibility} 50 * @private {!MainPageVisibility}
50 */ 51 */
51 showPages_: { 52 showPages_: {
52 type: Object, 53 type: Object,
53 value: function() { 54 value: function() {
54 return {about: false, basic: false, advanced: false}; 55 return {about: false, basic: false, advanced: false};
55 }, 56 },
56 }, 57 },
57 58
58 /** 59 /**
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 139
139 /** 140 /**
140 * @return {boolean} 141 * @return {boolean}
141 * @private 142 * @private
142 */ 143 */
143 showAdvancedToggle_: function() { 144 showAdvancedToggle_: function() {
144 return !this.inSearchMode_ && this.showPages_.basic && 145 return !this.inSearchMode_ && this.showPages_.basic &&
145 !this.hasExpandedSection_; 146 !this.hasExpandedSection_;
146 }, 147 },
147 148
149 /**
150 * @return {boolean} Whether to show the basic page, taking into account both
151 * routing and search state.
152 * @private
153 */
154 showBasicPage_: function() {
155 return this.showPages_.basic || (
156 this.inSearchMode_ && !this.hasExpandedSection_);
157 },
158
159 /**
160 * @return {boolean} Whether to show the advanced page, taking into account
161 * both routing and search state.
162 * @private
163 */
164 showAdvancedPage_: function() {
165 return this.showPages_.advanced || (
166 this.inSearchMode_ && !this.hasExpandedSection_);
167 },
168
169 /** @param {!settings.Route} newRoute */
148 currentRouteChanged: function(newRoute) { 170 currentRouteChanged: function(newRoute) {
149 // When the route changes from a sub-page to the main page, immediately 171 // When the route changes from a sub-page to the main page, immediately
150 // update hasExpandedSection_ to unhide the other sections. 172 // update hasExpandedSection_ to unhide the other sections.
151 if (!newRoute.isSubpage()) 173 if (!newRoute.isSubpage())
152 this.hasExpandedSection_ = false; 174 this.hasExpandedSection_ = false;
153 175
154 if (settings.Route.ADVANCED.contains(newRoute)) 176 if (settings.Route.ADVANCED.contains(newRoute))
155 this.advancedToggleExpanded_ = true; 177 this.advancedToggleExpanded_ = true;
156 178
157 this.updatePagesShown_(); 179 this.updatePagesShown_();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 ensureInDefaultSearchPage_: function() { 275 ensureInDefaultSearchPage_: function() {
254 if (settings.getCurrentRoute() != settings.Route.BASIC) 276 if (settings.getCurrentRoute() != settings.Route.BASIC)
255 settings.navigateTo(settings.Route.BASIC); 277 settings.navigateTo(settings.Route.BASIC);
256 }, 278 },
257 279
258 /** 280 /**
259 * @param {string} query 281 * @param {string} query
260 * @return {!Promise} A promise indicating that searching finished. 282 * @return {!Promise} A promise indicating that searching finished.
261 */ 283 */
262 searchContents: function(query) { 284 searchContents: function(query) {
285 // Trigger rendering of the basic and advanced pages and search once ready.
263 this.inSearchMode_ = true; 286 this.inSearchMode_ = true;
264 this.ensureInDefaultSearchPage_(); 287 this.ensureInDefaultSearchPage_();
265 this.toolbarSpinnerActive = true; 288 this.toolbarSpinnerActive = true;
266 289
267 // Trigger rendering of the basic and advanced pages and search once ready.
268 this.showPages_ = {about: false, basic: true, advanced: true};
269
270 return new Promise(function(resolve, reject) { 290 return new Promise(function(resolve, reject) {
271 setTimeout(function() { 291 setTimeout(function() {
272 var whenSearchDone = settings.getSearchManager().search( 292 var whenSearchDone = settings.getSearchManager().search(
273 query, assert(this.getPage_(settings.Route.BASIC))); 293 query, assert(this.getPage_(settings.Route.BASIC)));
274 assert( 294 assert(
275 whenSearchDone === 295 whenSearchDone ===
276 settings.getSearchManager().search( 296 settings.getSearchManager().search(
277 query, assert(this.getPage_(settings.Route.ADVANCED)))); 297 query, assert(this.getPage_(settings.Route.ADVANCED))));
278 298
279 whenSearchDone.then(function(request) { 299 whenSearchDone.then(function(request) {
280 resolve(); 300 resolve();
281 if (!request.finished) { 301 if (!request.finished) {
282 // Nothing to do here. A previous search request was canceled 302 // Nothing to do here. A previous search request was canceled
283 // because a new search request was issued before the first one 303 // because a new search request was issued before the first one
284 // completed. 304 // completed.
285 return; 305 return;
286 } 306 }
287 307
288 this.toolbarSpinnerActive = false; 308 this.toolbarSpinnerActive = false;
289 this.inSearchMode_ = !request.isSame(''); 309 this.inSearchMode_ = !request.isSame('');
290 this.showNoResultsFound_ = 310 this.showNoResultsFound_ =
291 this.inSearchMode_ && !request.didFindMatches(); 311 this.inSearchMode_ && !request.didFindMatches();
292
293 if (!this.inSearchMode_) {
294 // Restore the "advanced" page visibility as it was before search
295 // was initiated.
296 this.showPages_ = {
297 about: false, basic: true, advanced: this.advancedToggleExpanded_,
298 };
299 }
300 }.bind(this)); 312 }.bind(this));
301 }.bind(this), 0); 313 }.bind(this), 0);
302 }.bind(this)); 314 }.bind(this));
303 }, 315 },
304 316
305 /** 317 /**
306 * @param {(boolean|undefined)} visibility 318 * @param {(boolean|undefined)} visibility
307 * @return {boolean} True unless visibility is false. 319 * @return {boolean} True unless visibility is false.
308 * @private 320 * @private
309 */ 321 */
310 showAdvancedSettings_: function(visibility) { 322 showAdvancedSettings_: function(visibility) {
311 return visibility !== false; 323 return visibility !== false;
312 }, 324 },
313 }); 325 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698