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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 this.advancedToggleExpanded_ = e.detail; | 75 this.advancedToggleExpanded_ = e.detail; |
76 settings.navigateTo(this.advancedToggleExpanded_ ? | 76 settings.navigateTo(this.advancedToggleExpanded_ ? |
77 settings.Route.ADVANCED : settings.Route.BASIC); | 77 settings.Route.ADVANCED : settings.Route.BASIC); |
78 }.bind(this)); | 78 }.bind(this)); |
79 | 79 |
80 }, | 80 }, |
81 | 81 |
82 /** @private */ | 82 /** @private */ |
83 overscrollChanged_: function() { | 83 overscrollChanged_: function() { |
84 if (!this.overscroll_ && this.boundScroll_) { | 84 if (!this.overscroll_ && this.boundScroll_) { |
85 this.parentNode.scroller.removeEventListener('scroll', this.boundScroll_); | 85 this.offsetParent.removeEventListener('scroll', this.boundScroll_); |
86 this.boundScroll_ = null; | 86 this.boundScroll_ = null; |
87 } else if (this.overscroll_ && !this.boundScroll_) { | 87 } else if (this.overscroll_ && !this.boundScroll_) { |
88 this.boundScroll_ = this.scrollEventListener_.bind(this); | 88 this.boundScroll_ = this.setOverscroll_.bind(this, 0); |
89 this.parentNode.scroller.addEventListener('scroll', this.boundScroll_); | 89 this.offsetParent.addEventListener('scroll', this.boundScroll_); |
90 } | 90 } |
91 }, | 91 }, |
92 | 92 |
93 /** @private */ | 93 /** |
94 scrollEventListener_: function() { | 94 * Sets the overscroll padding. Never forces a scroll, i.e., always leaves |
95 var scroller = this.parentNode.scroller; | 95 * any currently visible overflow as-is. |
96 * @param {number=} opt_minHeight The minimum overscroll height needed. | |
97 */ | |
98 setOverscroll_: function(opt_minHeight) { | |
99 var scroller = this.offsetParent; | |
100 if (!scroller) | |
101 return; | |
96 var overscroll = this.$.overscroll; | 102 var overscroll = this.$.overscroll; |
97 var visibleBottom = scroller.scrollTop + scroller.clientHeight; | 103 var visibleBottom = scroller.scrollTop + scroller.clientHeight; |
98 var overscrollBottom = overscroll.offsetTop + overscroll.scrollHeight; | 104 var overscrollBottom = overscroll.offsetTop + overscroll.scrollHeight; |
99 // How much of the overscroll is visible (may be negative). | 105 // How much of the overscroll is visible (may be negative). |
100 var visibleOverscroll = overscroll.scrollHeight - | 106 var visibleOverscroll = overscroll.scrollHeight - |
101 (overscrollBottom - visibleBottom); | 107 (overscrollBottom - visibleBottom); |
102 this.overscroll_ = Math.max(0, visibleOverscroll); | 108 this.overscroll_ = Math.max(opt_minHeight || 0, visibleOverscroll); |
103 }, | 109 }, |
104 | 110 |
105 /** | 111 /** |
106 * @param {boolean} opened Whether the menu is expanded. | 112 * @param {boolean} opened Whether the menu is expanded. |
107 * @return {string} Which icon to use. | 113 * @return {string} Which icon to use. |
108 * @private | 114 * @private |
109 */ | 115 */ |
110 arrowState_: function(opened) { | 116 arrowState_: function(opened) { |
111 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 117 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
112 }, | 118 }, |
(...skipping 28 matching lines...) Expand all Loading... | |
141 this.pageVisibility.advancedSettings !== false); | 147 this.pageVisibility.advancedSettings !== false); |
142 this.advancedToggleExpanded_ = true; | 148 this.advancedToggleExpanded_ = true; |
143 } | 149 } |
144 } | 150 } |
145 | 151 |
146 // Wait for any other changes prior to calculating the overflow padding. | 152 // Wait for any other changes prior to calculating the overflow padding. |
147 setTimeout(function() { | 153 setTimeout(function() { |
148 // Ensure any dom-if reflects the current properties. | 154 // Ensure any dom-if reflects the current properties. |
149 Polymer.dom.flush(); | 155 Polymer.dom.flush(); |
150 | 156 |
151 this.overscroll_ = this.overscrollHeight_(); | 157 this.setOverscroll_(this.overscrollHeight_()); |
152 }.bind(this)); | 158 }.bind(this)); |
153 }, | 159 }, |
154 | 160 |
155 /** | 161 /** |
156 * Return the height that the overscroll padding should be set to. | 162 * Return the height that the overscroll padding should be set to. |
157 * This is used to determine how much padding to apply to the end of the | 163 * This is used to determine how much padding to apply to the end of the |
158 * content so that the last element may align with the top of the content | 164 * content so that the last element may align with the top of the content |
159 * area. | 165 * area. |
160 * @return {number} | 166 * @return {number} |
161 * @private | 167 * @private |
162 */ | 168 */ |
163 overscrollHeight_: function() { | 169 overscrollHeight_: function() { |
164 var route = settings.getCurrentRoute(); | 170 var route = settings.getCurrentRoute(); |
165 if (route.subpage.length != 0 || this.showPages_.about) | 171 if (!route.section || route.subpage.length || this.showPages_.about) |
166 return 0; | 172 return 0; |
167 | 173 |
168 var page = this.getPage_(route); | 174 var page = this.getPage_(route); |
169 var topSection = page && page.getSection(route.section); | 175 var section = page && page.getSection(route.section); |
170 if (!topSection || !topSection.offsetParent) | 176 if (!section || !section.offsetParent) |
171 return 0; | 177 return 0; |
172 | 178 |
173 // Offset to the selected section (relative to the scrolling window). | 179 // Find the distance from the section's top to the overscroll. |
174 let sectionTop = topSection.offsetParent.offsetTop + topSection.offsetTop; | 180 var sectionTop = section.offsetParent.offsetTop + section.offsetTop; |
175 // The height of the selected section and remaining content (sections). | 181 var distanceToBottom = this.$.overscroll.offsetTop - sectionTop; |
dschuyler
2016/08/10 17:00:16
Let's make this just 'distance' rather than distan
michaelpg
2016/08/15 16:41:48
Done.
| |
176 let heightOfShownSections = this.$.overscroll.offsetTop - sectionTop; | 182 |
177 return Math.max(0, this.parentNode.scrollHeight - heightOfShownSections); | 183 return Math.max(0, this.offsetParent.clientHeight - distanceToBottom); |
178 }, | 184 }, |
179 | 185 |
180 /** @private */ | 186 /** @private */ |
181 toggleAdvancedPage_: function() { | 187 toggleAdvancedPage_: function() { |
182 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); | 188 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
183 }, | 189 }, |
184 | 190 |
185 /** | 191 /** |
186 * Returns the root page (if it exists) for a route. | 192 * Returns the root page (if it exists) for a route. |
187 * @param {!settings.Route} route | 193 * @param {!settings.Route} route |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 | 257 |
252 /** | 258 /** |
253 * @param {(boolean|undefined)} visibility | 259 * @param {(boolean|undefined)} visibility |
254 * @return {boolean} True unless visibility is false. | 260 * @return {boolean} True unless visibility is false. |
255 * @private | 261 * @private |
256 */ | 262 */ |
257 showAdvancedSettings_: function(visibility) { | 263 showAdvancedSettings_: function(visibility) { |
258 return visibility !== false; | 264 return visibility !== false; |
259 }, | 265 }, |
260 }); | 266 }); |
OLD | NEW |