Bug 1269333 - Don't assume the height of the first row for all other rows. r?mak draft
authorJared Wein <jwein@mozilla.com>
Thu, 09 Jun 2016 19:01:31 -0400
changeset 377195 a03b276f7fcdb129e33b52f6582331feecb282d2
parent 376099 95f7a3e334349b65ef491360cea17070f4d97c66
child 523337 a40bfcc216131c5a9256fa7c2d5159976d6d841d
push id20779
push userjwein@mozilla.com
push dateThu, 09 Jun 2016 23:01:49 +0000
reviewersmak
bugs1269333
milestone49.0a1
Bug 1269333 - Don't assume the height of the first row for all other rows. r?mak MozReview-Commit-ID: C2BM3odV03m
toolkit/content/widgets/autocomplete.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -1020,17 +1020,16 @@ extends="chrome://global/content/binding
       <xul:richlistbox anonid="richlistbox" class="autocomplete-richlistbox" flex="1"/>
       <xul:hbox>
         <children/>
       </xul:hbox>
     </content>
 
     <implementation implements="nsIAutoCompletePopup">
       <field name="_currentIndex">0</field>
-      <field name="_rowHeight">0</field>
       <field name="_rlbAnimated">false</field>
 
       <!-- =================== nsIAutoCompletePopup =================== -->
 
       <property name="selectedIndex"
                 onget="return this.richlistbox.selectedIndex;">
         <setter>
           <![CDATA[
@@ -1160,36 +1159,40 @@ extends="chrome://global/content/binding
           let rows = this.richlistbox.childNodes;
           let numRows = Math.min(this._matchCount, this.maxRows, rows.length);
 
           this.removeAttribute("height");
 
           // Default the height to 0 if we have no rows to show
           let height = 0;
           if (numRows) {
-            if (!this._rowHeight) {
-              let firstRowRect = rows[0].getBoundingClientRect();
-              this._rowHeight = firstRowRect.height;
-
+            let firstRowRect = rows[0].getBoundingClientRect();
+            if (this._rlbPadding == undefined) {
               let style = window.getComputedStyle(this.richlistbox);
 
               let transition = style.transitionProperty;
               this._rlbAnimated = transition && transition != "none";
 
               let paddingTop = parseInt(style.paddingTop) || 0;
               let paddingBottom = parseInt(style.paddingBottom) || 0;
               this._rlbPadding = paddingTop + paddingBottom;
-
-              // Set a fixed max-height to avoid flicker when growing the panel.
-              this.richlistbox.style.maxHeight =
-                ((this._rowHeight * this.maxRows) + this._rlbPadding) + "px";
             }
 
+            if (numRows > this.maxRows) {
+              // Set a fixed max-height to avoid flicker when growing the panel.
+              let lastVisibleRowRect = rows[this.maxRows - 1].getBoundingClientRect();
+              let visibleHeight = lastVisibleRowRect.bottom - firstRowRect.top;
+              this.richlistbox.style.maxHeight =
+                visibleHeight + this._rlbPadding + "px";
+            }
+
+            let lastRowRect = rows[numRows - 1].getBoundingClientRect();
             // Calculate the height to have the first row to last row shown
-            height = (this._rowHeight * numRows) + this._rlbPadding;
+            height = lastRowRect.bottom - firstRowRect.top +
+                     this._rlbPadding;
           }
 
           let animate = this._rlbAnimated &&
                         this.getAttribute("dontanimate") != "true";
           let currentHeight = this.richlistbox.getBoundingClientRect().height;
           if (height > currentHeight) {
             // Grow immediately.
             if (animate) {