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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 * content so that the last element may align with the top of the content | 158 * content so that the last element may align with the top of the content |
159 * area. | 159 * area. |
160 * @return {number} | 160 * @return {number} |
161 * @private | 161 * @private |
162 */ | 162 */ |
163 overscrollHeight_: function() { | 163 overscrollHeight_: function() { |
164 var route = settings.getCurrentRoute(); | 164 var route = settings.getCurrentRoute(); |
165 if (route.subpage.length != 0 || this.showPages_.about) | 165 if (route.subpage.length != 0 || this.showPages_.about) |
166 return 0; | 166 return 0; |
167 | 167 |
168 var query = 'settings-section[section="' + route.section + '"]'; | 168 var page = this.getPage_(route); |
169 var topSection = this.$$('settings-basic-page').$$(query); | 169 var topSection = page && page.getSection(route.section); |
170 if (!topSection && this.showPages_.advanced) | |
171 topSection = this.$$('settings-advanced-page').$$(query); | |
172 | |
173 if (!topSection || !topSection.offsetParent) | 170 if (!topSection || !topSection.offsetParent) |
174 return 0; | 171 return 0; |
175 | 172 |
176 // Offset to the selected section (relative to the scrolling window). | 173 // Offset to the selected section (relative to the scrolling window). |
177 let sectionTop = topSection.offsetParent.offsetTop + topSection.offsetTop; | 174 let sectionTop = topSection.offsetParent.offsetTop + topSection.offsetTop; |
178 // The height of the selected section and remaining content (sections). | 175 // The height of the selected section and remaining content (sections). |
179 let heightOfShownSections = this.$.overscroll.offsetTop - sectionTop; | 176 let heightOfShownSections = this.$.overscroll.offsetTop - sectionTop; |
180 return Math.max(0, this.parentNode.scrollHeight - heightOfShownSections); | 177 return Math.max(0, this.parentNode.scrollHeight - heightOfShownSections); |
181 }, | 178 }, |
182 | 179 |
183 /** @private */ | 180 /** @private */ |
184 toggleAdvancedPage_: function() { | 181 toggleAdvancedPage_: function() { |
185 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); | 182 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
186 }, | 183 }, |
187 | 184 |
188 /** | 185 /** |
186 * Returns the root page (if it exists) for a route. | |
187 * @param {!settings.Route} route | |
188 * @return {(?SettingsAboutPageElement|?SettingsAdvancedPageElement| | |
189 * ?SettingsBasicPageElement)} | |
190 */ | |
191 getPage_: function(route) { | |
dschuyler
2016/08/10 17:16:17
I'd like to hear more about why this function help
michaelpg
2016/08/15 18:08:11
No, it only queries the page for the current route
| |
192 if (settings.Route.ABOUT.contains(route)) { | |
193 return /** @type {?SettingsAboutPageElement} */( | |
194 this.$$('settings-about-page')); | |
195 } | |
196 if (settings.Route.ADVANCED.contains(route)) { | |
197 return /** @type {?SettingsAdvancedPageElement} */( | |
198 this.$$('settings-advanced-page')); | |
199 } | |
200 if (settings.Route.BASIC.contains(route)) { | |
201 return /** @type {?SettingsBasicPageElement} */( | |
202 this.$$('settings-basic-page')); | |
203 } | |
204 assertNotReached(); | |
205 }, | |
206 | |
207 /** | |
189 * Navigates to the default search page (if necessary). | 208 * Navigates to the default search page (if necessary). |
190 * @private | 209 * @private |
191 */ | 210 */ |
192 ensureInDefaultSearchPage_: function() { | 211 ensureInDefaultSearchPage_: function() { |
193 settings.navigateTo(settings.Route.BASIC); | 212 settings.navigateTo(settings.Route.BASIC); |
194 }, | 213 }, |
195 | 214 |
196 /** | 215 /** |
197 * @param {string} query | 216 * @param {string} query |
198 * @return {!Promise} A promise indicating that searching finished. | 217 * @return {!Promise} A promise indicating that searching finished. |
199 */ | 218 */ |
200 searchContents: function(query) { | 219 searchContents: function(query) { |
201 this.ensureInDefaultSearchPage_(); | 220 this.ensureInDefaultSearchPage_(); |
202 this.toolbarSpinnerActive = true; | 221 this.toolbarSpinnerActive = true; |
203 | 222 |
204 // Trigger rendering of the basic and advanced pages and search once ready. | 223 // Trigger rendering of the basic and advanced pages and search once ready. |
205 this.showPages_ = {about: false, basic: true, advanced: true}; | 224 this.showPages_ = {about: false, basic: true, advanced: true}; |
206 | 225 |
207 return new Promise(function(resolve, reject) { | 226 return new Promise(function(resolve, reject) { |
208 setTimeout(function() { | 227 setTimeout(function() { |
209 var whenSearchDone = settings.getSearchManager().search( | 228 var whenSearchDone = settings.getSearchManager().search( |
210 query, assert(this.$$('settings-basic-page'))); | 229 query, assert(this.getPage_(settings.Route.BASIC))); |
211 assert( | 230 assert( |
212 whenSearchDone === | 231 whenSearchDone === |
213 settings.getSearchManager().search( | 232 settings.getSearchManager().search( |
214 query, assert(this.$$('settings-advanced-page')))); | 233 query, assert(this.getPage_(settings.Route.ADVANCED)))); |
215 | 234 |
216 whenSearchDone.then(function(request) { | 235 whenSearchDone.then(function(request) { |
217 resolve(); | 236 resolve(); |
218 if (!request.finished) { | 237 if (!request.finished) { |
219 // Nothing to do here. A previous search request was canceled | 238 // Nothing to do here. A previous search request was canceled |
220 // because a new search request was issued before the first one | 239 // because a new search request was issued before the first one |
221 // completed. | 240 // completed. |
222 return; | 241 return; |
223 } | 242 } |
224 | 243 |
225 this.toolbarSpinnerActive = false; | 244 this.toolbarSpinnerActive = false; |
226 this.showNoResultsFound_ = | 245 this.showNoResultsFound_ = |
227 !request.isSame('') && !request.didFindMatches(); | 246 !request.isSame('') && !request.didFindMatches(); |
228 }.bind(this)); | 247 }.bind(this)); |
229 }.bind(this), 0); | 248 }.bind(this), 0); |
230 }.bind(this)); | 249 }.bind(this)); |
231 }, | 250 }, |
232 | 251 |
233 /** | 252 /** |
234 * @param {(boolean|undefined)} visibility | 253 * @param {(boolean|undefined)} visibility |
235 * @return {boolean} True unless visibility is false. | 254 * @return {boolean} True unless visibility is false. |
236 * @private | 255 * @private |
237 */ | 256 */ |
238 showAdvancedSettings_: function(visibility) { | 257 showAdvancedSettings_: function(visibility) { |
239 return visibility !== false; | 258 return visibility !== false; |
240 }, | 259 }, |
241 }); | 260 }); |
OLD | NEW |