Bug 804968 - Adjusting the height of an autocomplete popup requires too many reflows and layouts. r=enn
authorJared Wein <jwein@mozilla.com>
Thu, 25 Oct 2012 12:27:30 -0700
changeset 111565 0fc382c36b4c020fe2258b911dc1bc26d394dffa
parent 111564 54591f4e0f792eb796228b6577a2be3bfce0af13
child 111566 fd7180e292112211664414194b80319cf85be038
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersenn
bugs804968
milestone19.0a1
Bug 804968 - Adjusting the height of an autocomplete popup requires too many reflows and layouts. r=enn
toolkit/content/widgets/autocomplete.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -939,16 +939,17 @@
       <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>
 
       <!-- =================== nsIAutoCompletePopup =================== -->
 
       <property name="selectedIndex"
                 onget="return this.richlistbox.selectedIndex;">
         <setter>
           <![CDATA[
           this.richlistbox.selectedIndex = val;
@@ -1057,21 +1058,23 @@
           <![CDATA[
           // Figure out how many rows to show
           let rows = this.richlistbox.childNodes;
           let numRows = Math.min(this._matchCount, this.maxRows, rows.length);
 
           // Default the height to 0 if we have no rows to show
           let height = 0;
           if (numRows) {
-            let firstRowRect = rows[0].getBoundingClientRect();
-            let lastRowRect = rows[numRows - 1].getBoundingClientRect();
+            if (!this._rowHeight) {
+              let firstRowRect = rows[0].getBoundingClientRect();
+              this._rowHeight = firstRowRect.height;
+            }
 
             // Calculate the height to have the first row to last row shown
-            height = lastRowRect.bottom - firstRowRect.top;
+            height = this._rowHeight * numRows;
           }
 
           // Only update the height if we have a non-zero height and if it
           // changed (the richlistbox is collapsed if there are no results)
           if (height && height != this.richlistbox.height)
             this.richlistbox.height = height;
           ]]>
         </body>