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

Unified Diff: Source/web/resources/listPicker.js

Issue 1042733002: ListPicker calculate accurate scroll height (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixe problem with scrollHeight calculation when hidden options and no options Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/forms/select/popup-menu-appearance-fractional-width.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/resources/listPicker.js
diff --git a/Source/web/resources/listPicker.js b/Source/web/resources/listPicker.js
index a159aacff77c09909932fb05e1bdc3fd935e8c1c..09184f1bddcd4c0ea747c28ac248808cfdbabaf6 100644
--- a/Source/web/resources/listPicker.js
+++ b/Source/web/resources/listPicker.js
@@ -177,11 +177,7 @@ ListPicker.prototype._fixWindowSize = function() {
var maxHeight = this._selectElement.offsetHeight;
this._selectElement.style.height = "0";
var heightOutsideOfContent = this._selectElement.offsetHeight - this._selectElement.clientHeight;
- var desiredWindowHeight = this._selectElement.scrollHeight + heightOutsideOfContent;
- this._selectElement.style.height = desiredWindowHeight + "px";
- // scrollHeight returns floored value so we needed this check.
- if (this._hasVerticalScrollbar())
- desiredWindowHeight += 1;
+ var desiredWindowHeight = Math.round(this._calculateScrollHeight() + heightOutsideOfContent);
if (desiredWindowHeight > maxHeight)
desiredWindowHeight = maxHeight;
var desiredWindowWidth = Math.max(this._config.anchorRectInScreen.width, this._selectElement.offsetWidth);
@@ -192,8 +188,20 @@ ListPicker.prototype._fixWindowSize = function() {
setWindowRect(windowRect);
};
-ListPicker.prototype._hasVerticalScrollbar = function() {
- return this._selectElement.scrollWidth > this._selectElement.clientWidth;
+ListPicker.prototype._calculateScrollHeight = function() {
+ // Element.scrollHeight returns an integer value but this calculate the
+ // actual fractional value.
+ var top = Infinity;
+ var bottom = -Infinity;
+ for (var i = 0; i < this._selectElement.children.length; i++) {
+ var rect = this._selectElement.children[i].getBoundingClientRect();
+ // Skip hidden elements.
+ if (rect.width === 0 && rect.height === 0)
+ continue;
+ top = Math.min(top, rect.top);
+ bottom = Math.max(bottom, rect.bottom);
+ }
+ return Math.max(bottom - top, 0);
};
ListPicker.prototype._listItemCount = function() {
« no previous file with comments | « LayoutTests/fast/forms/select/popup-menu-appearance-fractional-width.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698