Bug 1519967, remove box object computations in richlistbox, r=paolo
authorNeil Deakin <neil@mozilla.com>
Fri, 15 Feb 2019 15:25:35 -0500
changeset 459560 75b0a937397c76253bd72bfe1d548d842b81066d
parent 459559 d576a84575c4763024514aa479a40fa5e7ce6114
child 459561 41da7f72eb6eb912a702170e912db116195f6beb
push id111968
push userneil@mozilla.com
push dateFri, 15 Feb 2019 20:28:01 +0000
treeherdermozilla-inbound@4414af4d7368 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs1519967
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519967, remove box object computations in richlistbox, r=paolo
toolkit/content/widgets/richlistbox.js
--- a/toolkit/content/widgets/richlistbox.js
+++ b/toolkit/content/widgets/richlistbox.js
@@ -613,36 +613,37 @@ MozElements.RichListBox = class RichList
     // at the extreme we're moving away from
     if (!this.currentItem) {
       return aDirection == -1 ? children.length : 0;
     }
 
     // If the current item is visible, scroll by one page so that
     // the new current item is at approximately the same position as
     // the existing current item.
+    let height = this.getBoundingClientRect().height;
     if (this._isItemVisible(this.currentItem)) {
-      this.scrollBy(0, this.clientHeight * aDirection);
+      this.scrollBy(0, height * aDirection);
     }
 
     // Figure out, how many items fully fit into the view port
     // (including the currently selected one), and determine
     // the index of the first one lying (partially) outside
-    var height = this.clientHeight;
-    var startBorder = this.currentItem.boxObject.y;
+    let currentItemRect = this.currentItem.getBoundingClientRect();
+    var startBorder = currentItemRect.y;
     if (aDirection == -1) {
-      startBorder += this.currentItem.clientHeight;
+      startBorder += currentItemRect.height;
     }
 
     var index = this.currentIndex;
     for (var ix = index; 0 <= ix && ix < children.length; ix += aDirection) {
-      var boxObject = children[ix].boxObject;
-      if (boxObject.height == 0) {
+      let childRect = children[ix].getBoundingClientRect();
+      if (childRect.height == 0) {
         continue; // hidden children have a y of 0
       }
-      var endBorder = boxObject.y + (aDirection == -1 ? boxObject.height : 0);
+      var endBorder = childRect.y + (aDirection == -1 ? childRect.height : 0);
       if ((endBorder - startBorder) * aDirection > height) {
         break; // we've reached the desired distance
       }
       index = ix;
     }
 
     return index != this.currentIndex ? index - this.currentIndex : aDirection;
   }
@@ -673,17 +674,17 @@ MozElements.RichListBox = class RichList
           this._currentIndex - 1, this.getRowCount()));
       }
       if (currentItem) {
         this.currentItem = currentItem;
         if (this.selType != "multiple" && this.selectedCount == 0) {
           this.selectedItem = currentItem;
         }
 
-        if (this.clientHeight) {
+        if (this.getBoundingClientRect().height) {
           this.ensureElementIsVisible(currentItem);
         } else {
           // XXX hack around a bug in ensureElementIsVisible as it will
           // scroll beyond the last element, bug 493645.
           this.ensureElementIsVisible(currentItem.previousElementSibling);
         }
       }
       this._suppressOnSelect = suppressSelect;
@@ -735,21 +736,22 @@ MozElements.RichListBox = class RichList
     }
   }
 
   _isItemVisible(aItem) {
     if (!aItem) {
       return false;
     }
 
-    var y = this.scrollTop + this.boxObject.y;
+    var y = this.getBoundingClientRect().y;
 
     // Partially visible items are also considered visible
-    return (aItem.boxObject.y + aItem.clientHeight > y) &&
-      (aItem.boxObject.y < y + this.clientHeight);
+    let itemRect = aItem.getBoundingClientRect();
+    return (itemRect.y + itemRect.height > y) &&
+           (itemRect.y < y + this.clientHeight);
   }
 
   moveByOffset(aOffset, aIsSelecting, aIsSelectingRange) {
     if ((aIsSelectingRange || !aIsSelecting) &&
       this.selType != "multiple") {
       return;
     }