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

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: Add test. 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 || this.inSearchMode_;
156 },
157
158 /**
159 * @return {boolean} Whether to show the advanced page, taking into account
160 * both routing and search state.
161 * @private
162 */
163 showAdvancedPage_: function() {
164 return this.showPages_.advanced || this.inSearchMode_;
165 },
166
167 /** @param {!settings.Route} newRoute */
148 currentRouteChanged: function(newRoute) { 168 currentRouteChanged: function(newRoute) {
149 // When the route changes from a sub-page to the main page, immediately 169 // When the route changes from a sub-page to the main page, immediately
150 // update hasExpandedSection_ to unhide the other sections. 170 // update hasExpandedSection_ to unhide the other sections.
151 if (!newRoute.isSubpage()) 171 if (!newRoute.isSubpage())
152 this.hasExpandedSection_ = false; 172 this.hasExpandedSection_ = false;
153 173
154 if (settings.Route.ADVANCED.contains(newRoute)) 174 if (settings.Route.ADVANCED.contains(newRoute))
155 this.advancedToggleExpanded_ = true; 175 this.advancedToggleExpanded_ = true;
156 176
157 this.updatePagesShown_(); 177 this.updatePagesShown_();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 ensureInDefaultSearchPage_: function() { 273 ensureInDefaultSearchPage_: function() {
254 if (settings.getCurrentRoute() != settings.Route.BASIC) 274 if (settings.getCurrentRoute() != settings.Route.BASIC)
255 settings.navigateTo(settings.Route.BASIC); 275 settings.navigateTo(settings.Route.BASIC);
256 }, 276 },
257 277
258 /** 278 /**
259 * @param {string} query 279 * @param {string} query
260 * @return {!Promise} A promise indicating that searching finished. 280 * @return {!Promise} A promise indicating that searching finished.
261 */ 281 */
262 searchContents: function(query) { 282 searchContents: function(query) {
283 // Trigger rendering of the basic and advanced pages and search once ready.
263 this.inSearchMode_ = true; 284 this.inSearchMode_ = true;
dpapad 2016/09/20 22:32:15 Using inSearchMode_ to force the basic and advance
264 this.ensureInDefaultSearchPage_(); 285 this.ensureInDefaultSearchPage_();
265 this.toolbarSpinnerActive = true; 286 this.toolbarSpinnerActive = true;
266 287
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) { 288 return new Promise(function(resolve, reject) {
271 setTimeout(function() { 289 setTimeout(function() {
272 var whenSearchDone = settings.getSearchManager().search( 290 var whenSearchDone = settings.getSearchManager().search(
273 query, assert(this.getPage_(settings.Route.BASIC))); 291 query, assert(this.getPage_(settings.Route.BASIC)));
274 assert( 292 assert(
275 whenSearchDone === 293 whenSearchDone ===
276 settings.getSearchManager().search( 294 settings.getSearchManager().search(
277 query, assert(this.getPage_(settings.Route.ADVANCED)))); 295 query, assert(this.getPage_(settings.Route.ADVANCED))));
278 296
279 whenSearchDone.then(function(request) { 297 whenSearchDone.then(function(request) {
280 resolve(); 298 resolve();
281 if (!request.finished) { 299 if (!request.finished) {
282 // Nothing to do here. A previous search request was canceled 300 // Nothing to do here. A previous search request was canceled
283 // because a new search request was issued before the first one 301 // because a new search request was issued before the first one
284 // completed. 302 // completed.
285 return; 303 return;
286 } 304 }
287 305
288 this.toolbarSpinnerActive = false; 306 this.toolbarSpinnerActive = false;
289 this.inSearchMode_ = !request.isSame(''); 307 this.inSearchMode_ = !request.isSame('');
290 this.showNoResultsFound_ = 308 this.showNoResultsFound_ =
291 this.inSearchMode_ && !request.didFindMatches(); 309 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)); 310 }.bind(this));
301 }.bind(this), 0); 311 }.bind(this), 0);
302 }.bind(this)); 312 }.bind(this));
303 }, 313 },
304 314
305 /** 315 /**
306 * @param {(boolean|undefined)} visibility 316 * @param {(boolean|undefined)} visibility
307 * @return {boolean} True unless visibility is false. 317 * @return {boolean} True unless visibility is false.
308 * @private 318 * @private
309 */ 319 */
310 showAdvancedSettings_: function(visibility) { 320 showAdvancedSettings_: function(visibility) {
311 return visibility !== false; 321 return visibility !== false;
312 }, 322 },
313 }); 323 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698