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

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

Issue 2312423003: MD Settings: Set overscroll before attempting to scroll to section (Closed)
Patch Set: rebase Created 4 years, 2 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}} 6 * @typedef {{about: boolean, basic: boolean, advanced: boolean}}
7 */ 7 */
8 var MainPageVisibility; 8 var MainPageVisibility;
9 9
10 /** 10 /**
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 var currentRoute = settings.getCurrentRoute(); 98 var currentRoute = settings.getCurrentRoute();
99 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); 99 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage();
100 }, 100 },
101 101
102 /** @private */ 102 /** @private */
103 overscrollChanged_: function() { 103 overscrollChanged_: function() {
104 if (!this.overscroll_ && this.boundScroll_) { 104 if (!this.overscroll_ && this.boundScroll_) {
105 this.offsetParent.removeEventListener('scroll', this.boundScroll_); 105 this.offsetParent.removeEventListener('scroll', this.boundScroll_);
106 this.boundScroll_ = null; 106 this.boundScroll_ = null;
107 } else if (this.overscroll_ && !this.boundScroll_) { 107 } else if (this.overscroll_ && !this.boundScroll_) {
108 this.boundScroll_ = this.setOverscroll_.bind(this, 0); 108 this.boundScroll_ = function() {
109 if (!this.ignoreScroll_)
110 this.setOverscroll_(0);
111 }.bind(this);
109 this.offsetParent.addEventListener('scroll', this.boundScroll_); 112 this.offsetParent.addEventListener('scroll', this.boundScroll_);
110 } 113 }
111 }, 114 },
112 115
113 /** 116 /**
114 * Sets the overscroll padding. Never forces a scroll, i.e., always leaves 117 * Sets the overscroll padding. Never forces a scroll, i.e., always leaves
115 * any currently visible overflow as-is. 118 * any currently visible overflow as-is.
116 * @param {number=} opt_minHeight The minimum overscroll height needed. 119 * @param {number=} opt_minHeight The minimum overscroll height needed.
120 * @private
117 */ 121 */
118 setOverscroll_: function(opt_minHeight) { 122 setOverscroll_: function(opt_minHeight) {
119 var scroller = this.offsetParent; 123 var scroller = this.offsetParent;
120 if (!scroller) 124 if (!scroller)
121 return; 125 return;
122 var overscroll = this.$.overscroll; 126 var overscroll = this.$.overscroll;
123 var visibleBottom = scroller.scrollTop + scroller.clientHeight; 127 var visibleBottom = scroller.scrollTop + scroller.clientHeight;
124 var overscrollBottom = overscroll.offsetTop + overscroll.scrollHeight; 128 var overscrollBottom = overscroll.offsetTop + overscroll.scrollHeight;
125 // How much of the overscroll is visible (may be negative). 129 // How much of the overscroll is visible (may be negative).
126 var visibleOverscroll = overscroll.scrollHeight - 130 var visibleOverscroll = overscroll.scrollHeight -
127 (overscrollBottom - visibleBottom); 131 (overscrollBottom - visibleBottom);
128 this.overscroll_ = Math.max(opt_minHeight || 0, visibleOverscroll); 132 this.overscroll_ = Math.max(opt_minHeight || 0, visibleOverscroll);
129 }, 133 },
130 134
131 /** 135 /**
136 * Enables or disables user scrolling, via overscroll: hidden. Room for the
137 * hidden scrollbar is added to prevent the page width from changing back and
138 * forth. Also freezes the overscroll height.
139 * @param {!Event} e
140 * @param {boolean} detail True to freeze, false to unfreeze.
141 * @private
142 */
143 onFreezeScroll_: function(e, detail) {
144 if (detail) {
145 // Update the overscroll and ignore scroll events.
146 this.setOverscroll_(this.overscrollHeight_());
147 this.ignoreScroll_ = true;
148
149 // Prevent scrolling the container.
150 var scrollerWidth = this.offsetParent.clientWidth;
151 this.offsetParent.style.overflow = 'hidden';
152 var scrollbarWidth = this.offsetParent.clientWidth - scrollerWidth;
153 this.offsetParent.style.width = 'calc(100% - ' + scrollbarWidth + 'px)';
154 } else {
155 this.ignoreScroll_ = false;
156 this.offsetParent.style.overflow = '';
157 this.offsetParent.style.width = '';
158 }
159 },
160
161 /**
132 * @param {boolean} opened Whether the menu is expanded. 162 * @param {boolean} opened Whether the menu is expanded.
133 * @return {string} Which icon to use. 163 * @return {string} Which icon to use.
134 * @private 164 * @private
135 */ 165 */
136 arrowState_: function(opened) { 166 arrowState_: function(opened) {
137 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; 167 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down';
138 }, 168 },
139 169
140 /** 170 /**
141 * @return {boolean} 171 * @return {boolean}
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 this.showPages_ = { 230 this.showPages_ = {
201 about: false, 231 about: false,
202 basic: settings.Route.BASIC.contains(currentRoute) || 232 basic: settings.Route.BASIC.contains(currentRoute) ||
203 !this.hasExpandedSection_, 233 !this.hasExpandedSection_,
204 advanced: this.hasExpandedSection_ ? 234 advanced: this.hasExpandedSection_ ?
205 settings.Route.ADVANCED.contains(currentRoute) : 235 settings.Route.ADVANCED.contains(currentRoute) :
206 this.advancedToggleExpanded_, 236 this.advancedToggleExpanded_,
207 }; 237 };
208 } 238 }
209 239
210 // Wait for any other changes prior to calculating the overflow padding. 240 // Calculate and set the overflow padding.
241 this.updateOverscrollForPage_();
242
243 // Wait for any other changes, then calculate the overflow padding again.
211 setTimeout(function() { 244 setTimeout(function() {
212 // Ensure any dom-if reflects the current properties. 245 // Ensure any dom-if reflects the current properties.
213 Polymer.dom.flush(); 246 Polymer.dom.flush();
247 this.updateOverscrollForPage_();
248 }.bind(this));
249 },
214 250
215 this.setOverscroll_(this.overscrollHeight_()); 251 /**
216 }.bind(this)); 252 * Calculates the necessary overscroll and sets the overscroll to that value
253 * (at minimum). For the About page, this just zeroes the overscroll.
254 * @private
255 */
256 updateOverscrollForPage_: function() {
257 if (this.showPages_.about) {
258 // Set overscroll directly to remove any existing overscroll that
259 // setOverscroll_ would otherwise preserve.
260 this.overscroll_ = 0;
261 return;
262 }
263 this.setOverscroll_(this.overscrollHeight_());
217 }, 264 },
218 265
219 /** 266 /**
220 * Return the height that the overscroll padding should be set to. 267 * Return the height that the overscroll padding should be set to.
221 * This is used to determine how much padding to apply to the end of the 268 * This is used to determine how much padding to apply to the end of the
222 * content so that the last element may align with the top of the content 269 * content so that the last element may align with the top of the content
223 * area. 270 * area.
224 * @return {number} 271 * @return {number}
225 * @private 272 * @private
226 */ 273 */
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 363
317 /** 364 /**
318 * @param {(boolean|undefined)} visibility 365 * @param {(boolean|undefined)} visibility
319 * @return {boolean} True unless visibility is false. 366 * @return {boolean} True unless visibility is false.
320 * @private 367 * @private
321 */ 368 */
322 showAdvancedSettings_: function(visibility) { 369 showAdvancedSettings_: function(visibility) {
323 return visibility !== false; 370 return visibility !== false;
324 }, 371 },
325 }); 372 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698