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

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

Issue 2228783005: MD Settings: Never underscroll (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@RefactorMainPageBehavior2
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * @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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.parentNode.scroller.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.parentNode.scroller.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 * any currently visible overflow as-is.
96 * @param {number=} minHeight The minimum overscroll height needed.
Dan Beam 2016/08/09 23:26:40 opt_minHeight
michaelpg 2016/08/09 23:46:09 Done.
97 */
98 setOverscroll_: function(opt_minHeight) {
95 var scroller = this.parentNode.scroller; 99 var scroller = this.parentNode.scroller;
96 var overscroll = this.$.overscroll; 100 var overscroll = this.$.overscroll;
97 var visibleBottom = scroller.scrollTop + scroller.clientHeight; 101 var visibleBottom = scroller.scrollTop + scroller.clientHeight;
98 var overscrollBottom = overscroll.offsetTop + overscroll.scrollHeight; 102 var overscrollBottom = overscroll.offsetTop + overscroll.scrollHeight;
99 // How much of the overscroll is visible (may be negative). 103 // How much of the overscroll is visible (may be negative).
100 var visibleOverscroll = overscroll.scrollHeight - 104 var visibleOverscroll = overscroll.scrollHeight -
101 (overscrollBottom - visibleBottom); 105 (overscrollBottom - visibleBottom);
102 this.overscroll_ = Math.max(0, visibleOverscroll); 106 if (typeof opt_minHeight == 'undefined')
107 opt_minHeight = 0;
108 this.overscroll_ = Math.max(opt_minHeight, visibleOverscroll);
Dan Beam 2016/08/09 23:26:40 nit: opt_minHeight || 0
michaelpg 2016/08/09 23:46:09 Done.
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
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.subpage.length != 0 || this.showPages_.about)
166 return 0; 172 return 0;
167 173
168 var query = 'settings-section[section="' + route.section + '"]'; 174 var query = 'settings-section[section="' + route.section + '"]';
169 var topSection = this.$$('settings-basic-page').$$(query); 175 var topSection = this.$$('settings-basic-page').$$(query);
170 if (!topSection && this.showPages_.advanced) 176 if (!topSection && this.showPages_.advanced)
171 topSection = this.$$('settings-advanced-page').$$(query); 177 topSection = this.$$('settings-advanced-page').$$(query);
172 178
173 if (!topSection || !topSection.offsetParent) 179 if (!topSection || !topSection.offsetParent)
174 return 0; 180 return 0;
175 181
176 // Offset to the selected section (relative to the scrolling window). 182 // Offset to the selected section (relative to the scrolling window).
177 let sectionTop = topSection.offsetParent.offsetTop + topSection.offsetTop; 183 let sectionTop = topSection.offsetParent.offsetTop + topSection.offsetTop;
178 // The height of the selected section and remaining content (sections). 184 // The height of the selected section and remaining content (sections).
179 let heightOfShownSections = this.$.overscroll.offsetTop - sectionTop; 185 let heightOfShownSections = this.$.overscroll.offsetTop - sectionTop;
180 return Math.max(0, this.parentNode.scrollHeight - heightOfShownSections); 186 return Math.max(0, this.parentNode.scrollHeight - heightOfShownSections);
Dan Beam 2016/08/09 23:26:40 so can we simplify any of this yet?
michaelpg 2016/08/09 23:46:09 dschuyler? I think this is still necessary to *gro
dschuyler 2016/08/10 00:06:26 I think that something called overscrollHeight_ sh
michaelpg 2016/08/10 03:12:27 Ack (unchanged)
181 }, 187 },
182 188
183 /** @private */ 189 /** @private */
184 toggleAdvancedPage_: function() { 190 toggleAdvancedPage_: function() {
185 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); 191 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_);
186 }, 192 },
187 193
188 /** 194 /**
189 * Navigates to the default search page (if necessary). 195 * Navigates to the default search page (if necessary).
190 * @private 196 * @private
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 238
233 /** 239 /**
234 * @param {(boolean|undefined)} visibility 240 * @param {(boolean|undefined)} visibility
235 * @return {boolean} True unless visibility is false. 241 * @return {boolean} True unless visibility is false.
236 * @private 242 * @private
237 */ 243 */
238 showAdvancedSettings_: function(visibility) { 244 showAdvancedSettings_: function(visibility) {
239 return visibility !== false; 245 return visibility !== false;
240 }, 246 },
241 }); 247 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698