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 * @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 30 matching lines...) Expand all Loading... | |
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. |
49 * @private {!MainPageVisibility} | 49 * @private {!MainPageVisibility} |
50 */ | 50 */ |
51 showPages_: { | 51 showPages_: Object, |
52 type: Object, | |
53 value: function() { | |
54 return {about: false, basic: false, advanced: false}; | |
55 }, | |
56 }, | |
57 | 52 |
58 /** | 53 /** |
59 * The main pages that were displayed before search was initiated. When | 54 * The main pages that were displayed before search was initiated. When |
60 * |null| it indicates that currently the page is displaying its normal | 55 * |null| it indicates that currently the page is displaying its normal |
61 * contents, instead of displaying search results. | 56 * contents, instead of displaying search results. |
62 * @private {?MainPageVisibility} | 57 * @private {?MainPageVisibility} |
63 */ | 58 */ |
64 previousShowPages_: { | 59 previousShowPages_: { |
65 type: Object, | 60 type: Object, |
66 value: null, | 61 value: null, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); | 95 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); |
101 }, | 96 }, |
102 | 97 |
103 /** @private */ | 98 /** @private */ |
104 overscrollChanged_: function() { | 99 overscrollChanged_: function() { |
105 if (!this.overscroll_ && this.boundScroll_) { | 100 if (!this.overscroll_ && this.boundScroll_) { |
106 this.offsetParent.removeEventListener('scroll', this.boundScroll_); | 101 this.offsetParent.removeEventListener('scroll', this.boundScroll_); |
107 this.boundScroll_ = null; | 102 this.boundScroll_ = null; |
108 } else if (this.overscroll_ && !this.boundScroll_) { | 103 } else if (this.overscroll_ && !this.boundScroll_) { |
109 this.boundScroll_ = this.setOverscroll_.bind(this, 0); | 104 this.boundScroll_ = this.setOverscroll_.bind(this, 0); |
110 this.offsetParent.addEventListener('scroll', this.boundScroll_); | 105 // Do not react immediately to scroll events since the overscroll was |
106 // just set; we may be trying to scroll somewhere first. | |
107 setTimeout(function() { | |
michaelpg
2016/08/19 04:40:45
I wish I didn't have to do this, but when we route
dschuyler
2016/08/23 02:09:50
would afterNextRender help any better?
michaelpg
2016/09/29 01:12:48
Ended up not needing this.
| |
108 this.offsetParent.addEventListener('scroll', this.boundScroll_); | |
109 }.bind(this)); | |
111 } | 110 } |
112 }, | 111 }, |
113 | 112 |
114 /** | 113 /** |
115 * Sets the overscroll padding. Never forces a scroll, i.e., always leaves | 114 * Sets the overscroll padding. Never forces a scroll, i.e., always leaves |
116 * any currently visible overflow as-is. | 115 * any currently visible overflow as-is. |
117 * @param {number=} opt_minHeight The minimum overscroll height needed. | 116 * @param {number=} opt_minHeight The minimum overscroll height needed. |
118 */ | 117 */ |
119 setOverscroll_: function(opt_minHeight) { | 118 setOverscroll_: function(opt_minHeight) { |
120 var scroller = this.offsetParent; | 119 var scroller = this.offsetParent; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 this.hasExpandedSection_ = true; | 163 this.hasExpandedSection_ = true; |
165 this.updatePagesShown_(); | 164 this.updatePagesShown_(); |
166 }, | 165 }, |
167 | 166 |
168 /** | 167 /** |
169 * Updates the hidden state of the about, basic and advanced pages, based on | 168 * Updates the hidden state of the about, basic and advanced pages, based on |
170 * the current route and the Advanced toggle state. | 169 * the current route and the Advanced toggle state. |
171 * @private | 170 * @private |
172 */ | 171 */ |
173 updatePagesShown_: function() { | 172 updatePagesShown_: function() { |
173 var oldShowPages = this.showPages_; | |
174 | |
174 var currentRoute = settings.getCurrentRoute(); | 175 var currentRoute = settings.getCurrentRoute(); |
175 if (settings.Route.ABOUT.contains(currentRoute)) { | 176 if (settings.Route.ABOUT.contains(currentRoute)) { |
176 this.showPages_ = {about: true, basic: false, advanced: false}; | 177 this.showPages_ = {about: true, basic: false, advanced: false}; |
177 } else { | 178 } else { |
178 this.showPages_ = { | 179 this.showPages_ = { |
179 about: false, | 180 about: false, |
180 basic: settings.Route.BASIC.contains(currentRoute) || | 181 basic: settings.Route.BASIC.contains(currentRoute) || |
181 !this.hasExpandedSection_, | 182 !this.hasExpandedSection_, |
182 advanced: settings.Route.ADVANCED.contains(currentRoute) || | 183 advanced: settings.Route.ADVANCED.contains(currentRoute) || |
183 (!this.hasExpandedSection_ && this.advancedToggleExpanded_), | 184 (!this.hasExpandedSection_ && this.advancedToggleExpanded_), |
184 }; | 185 }; |
185 | 186 |
186 if (this.showPages_.advanced) { | 187 if (this.showPages_.advanced) { |
187 assert(!this.pageVisibility || | 188 assert(!this.pageVisibility || |
188 this.pageVisibility.advancedSettings !== false); | 189 this.pageVisibility.advancedSettings !== false); |
189 this.advancedToggleExpanded_ = true; | 190 this.advancedToggleExpanded_ = true; |
190 } | 191 } |
191 } | 192 } |
192 | 193 |
193 // Wait for any other changes prior to calculating the overflow padding. | 194 // Initialize the overscroll after rendering a page. |
194 setTimeout(function() { | 195 if (!oldShowPages) |
195 // Ensure any dom-if reflects the current properties. | 196 setTimeout(this.updateOverscroll_.bind(this)); |
196 Polymer.dom.flush(); | 197 else |
197 | 198 this.updateOverscroll_(); |
198 this.setOverscroll_(this.overscrollHeight_()); | |
199 }.bind(this)); | |
200 }, | 199 }, |
201 | 200 |
202 /** | 201 /** |
202 * Sets the overscroll synchronously and asynchronously, to avoid | |
203 * preventing or conflicting with other DOM changes. | |
204 * @private | |
205 */ | |
206 updateOverscroll_: function() { | |
207 // Update the overscroll padding so pages can scroll to section. | |
208 this.setOverscroll_(this.overscrollHeight_()); | |
209 | |
210 // Wait for any other changes to page height, then calculate the overflow | |
211 // padding again. | |
212 this.async(function() { | |
213 this.setOverscroll_(this.overscrollHeight_()); | |
214 }); | |
215 }, | |
216 | |
217 /** | |
203 * Return the height that the overscroll padding should be set to. | 218 * Return the height that the overscroll padding should be set to. |
204 * This is used to determine how much padding to apply to the end of the | 219 * This is used to determine how much padding to apply to the end of the |
205 * content so that the last element may align with the top of the content | 220 * content so that the last element may align with the top of the content |
206 * area. | 221 * area. |
207 * @return {number} | 222 * @return {number} |
208 * @private | 223 * @private |
209 */ | 224 */ |
210 overscrollHeight_: function() { | 225 overscrollHeight_: function() { |
211 var route = settings.getCurrentRoute(); | 226 var route = settings.getCurrentRoute(); |
212 if (!route.section || route.isSubpage() || this.showPages_.about) | 227 if (!route.section || route.isSubpage() || this.showPages_.about) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 | 327 |
313 /** | 328 /** |
314 * @param {(boolean|undefined)} visibility | 329 * @param {(boolean|undefined)} visibility |
315 * @return {boolean} True unless visibility is false. | 330 * @return {boolean} True unless visibility is false. |
316 * @private | 331 * @private |
317 */ | 332 */ |
318 showAdvancedSettings_: function(visibility) { | 333 showAdvancedSettings_: function(visibility) { |
319 return visibility !== false; | 334 return visibility !== false; |
320 }, | 335 }, |
321 }); | 336 }); |
OLD | NEW |