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

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

Issue 2236723002: MD Settings: Hide the advanced page toggle control during searching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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}}
7 */
8 var MainPageVisibility;
9
10 /**
6 * @fileoverview 11 * @fileoverview
7 * 'settings-main' displays the selected settings page. 12 * 'settings-main' displays the selected settings page.
8 */ 13 */
9 Polymer({ 14 Polymer({
10 is: 'settings-main', 15 is: 'settings-main',
11 16
12 behaviors: [settings.RouteObserverBehavior], 17 behaviors: [settings.RouteObserverBehavior],
13 18
14 properties: { 19 properties: {
15 /** 20 /**
(...skipping 14 matching lines...) Expand all
30 inSubpage_: Boolean, 35 inSubpage_: Boolean,
31 36
32 /** @private */ 37 /** @private */
33 overscroll_: { 38 overscroll_: {
34 type: Number, 39 type: Number,
35 observer: 'overscrollChanged_', 40 observer: 'overscrollChanged_',
36 }, 41 },
37 42
38 /** 43 /**
39 * Controls which main pages are displayed via dom-ifs. 44 * Controls which main pages are displayed via dom-ifs.
40 * @type {!{about: boolean, basic: boolean, advanced: boolean}} 45 * @private {!MainPageVisibility}
41 * @private
42 */ 46 */
43 showPages_: { 47 showPages_: {
44 type: Object, 48 type: Object,
45 value: function() { 49 value: function() {
46 return {about: false, basic: false, advanced: false}; 50 return {about: false, basic: false, advanced: false};
47 }, 51 },
48 }, 52 },
49 53
54 /**
55 * The main pages that were displayed before search was initiated. When
56 * |null| it indicates that currently the page is displaying its normal
57 * contents, instead of displaying search results.
58 * @private {?MainPageVisibility}
59 */
60 previousShowPages_: {
61 type: Object,
62 value: null,
63 },
64
50 /** @private */ 65 /** @private */
51 showNoResultsFound_: { 66 showNoResultsFound_: {
52 type: Boolean, 67 type: Boolean,
53 value: false, 68 value: false,
54 }, 69 },
55 70
56 toolbarSpinnerActive: { 71 toolbarSpinnerActive: {
57 type: Boolean, 72 type: Boolean,
58 value: false, 73 value: false,
59 notify: true, 74 notify: true,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 /** 120 /**
106 * @param {boolean} opened Whether the menu is expanded. 121 * @param {boolean} opened Whether the menu is expanded.
107 * @return {string} Which icon to use. 122 * @return {string} Which icon to use.
108 * @private 123 * @private
109 */ 124 */
110 arrowState_: function(opened) { 125 arrowState_: function(opened) {
111 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; 126 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down';
112 }, 127 },
113 128
114 /** 129 /**
115 * @param {boolean} showBasicPage
116 * @param {boolean} inSubpage
117 * @return {boolean} 130 * @return {boolean}
118 * @private 131 * @private
119 */ 132 */
120 showAdvancedToggle_: function(showBasicPage, inSubpage) { 133 showAdvancedToggle_: function() {
121 return showBasicPage && !inSubpage; 134 var inSearchMode = !!this.previousShowPages_;
135 return this.showPages_.basic && !this.inSubpage_ && !inSearchMode;
122 }, 136 },
123 137
124 /** @protected */ 138 /** @protected */
125 currentRouteChanged: function(newRoute) { 139 currentRouteChanged: function(newRoute) {
126 this.inSubpage_ = newRoute.subpage.length > 0; 140 this.inSubpage_ = newRoute.subpage.length > 0;
127 this.style.height = this.inSubpage_ ? '100%' : ''; 141 this.style.height = this.inSubpage_ ? '100%' : '';
128 142
129 if (settings.Route.ABOUT.contains(newRoute)) { 143 if (settings.Route.ABOUT.contains(newRoute)) {
130 this.showPages_ = {about: true, basic: false, advanced: false}; 144 this.showPages_ = {about: true, basic: false, advanced: false};
131 } else { 145 } else {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 */ 205 */
192 ensureInDefaultSearchPage_: function() { 206 ensureInDefaultSearchPage_: function() {
193 settings.navigateTo(settings.Route.BASIC); 207 settings.navigateTo(settings.Route.BASIC);
194 }, 208 },
195 209
196 /** 210 /**
197 * @param {string} query 211 * @param {string} query
198 * @return {!Promise} A promise indicating that searching finished. 212 * @return {!Promise} A promise indicating that searching finished.
199 */ 213 */
200 searchContents: function(query) { 214 searchContents: function(query) {
215 if (!this.previousShowPages_) {
216 // Store which pages are shown before search, so that they can be restored
217 // after the user clears the search results.
218 this.previousShowPages_ = this.showPages_;
219 }
220
201 this.ensureInDefaultSearchPage_(); 221 this.ensureInDefaultSearchPage_();
202 this.toolbarSpinnerActive = true; 222 this.toolbarSpinnerActive = true;
203 223
204 // Trigger rendering of the basic and advanced pages and search once ready. 224 // Trigger rendering of the basic and advanced pages and search once ready.
205 this.showPages_ = {about: false, basic: true, advanced: true}; 225 this.showPages_ = {about: false, basic: true, advanced: true};
206 226
207 return new Promise(function(resolve, reject) { 227 return new Promise(function(resolve, reject) {
208 setTimeout(function() { 228 setTimeout(function() {
209 var whenSearchDone = settings.getSearchManager().search( 229 var whenSearchDone = settings.getSearchManager().search(
210 query, assert(this.$$('settings-basic-page'))); 230 query, assert(this.$$('settings-basic-page')));
211 assert( 231 assert(
212 whenSearchDone === 232 whenSearchDone ===
213 settings.getSearchManager().search( 233 settings.getSearchManager().search(
214 query, assert(this.$$('settings-advanced-page')))); 234 query, assert(this.$$('settings-advanced-page'))));
215 235
216 whenSearchDone.then(function(request) { 236 whenSearchDone.then(function(request) {
217 resolve(); 237 resolve();
218 if (!request.finished) { 238 if (!request.finished) {
219 // Nothing to do here. A previous search request was canceled 239 // Nothing to do here. A previous search request was canceled
220 // because a new search request was issued before the first one 240 // because a new search request was issued before the first one
221 // completed. 241 // completed.
222 return; 242 return;
223 } 243 }
224 244
225 this.toolbarSpinnerActive = false; 245 this.toolbarSpinnerActive = false;
246 var showingSearchResults = !request.isSame('');
226 this.showNoResultsFound_ = 247 this.showNoResultsFound_ =
227 !request.isSame('') && !request.didFindMatches(); 248 showingSearchResults && !request.didFindMatches();
249
250 if (!showingSearchResults) {
251 // Restore the pages that were shown before search was initiated.
252 this.showPages_ = assert(this.previousShowPages_);
253 this.previousShowPages_ = null;
254 }
228 }.bind(this)); 255 }.bind(this));
229 }.bind(this), 0); 256 }.bind(this), 0);
230 }.bind(this)); 257 }.bind(this));
231 }, 258 },
232 259
233 /** 260 /**
234 * @param {(boolean|undefined)} visibility 261 * @param {(boolean|undefined)} visibility
235 * @return {boolean} True unless visibility is false. 262 * @return {boolean} True unless visibility is false.
236 * @private 263 * @private
237 */ 264 */
238 showAdvancedSettings_: function(visibility) { 265 showAdvancedSettings_: function(visibility) {
239 return visibility !== false; 266 return visibility !== false;
240 }, 267 },
241 }); 268 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698