Bug 1353708 - Avoid autocomplete call to richlistbox's ensureElementIsVisible when there can't be a scrollbar. r=florian draft
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 05 Apr 2017 18:45:16 +0200
changeset 557788 e1d6de9c1449f0b4d9780d374e5632fb40498902
parent 555310 b5d8b27a753725c1de41ffae2e338798f3b5cacd
child 623156 b6e0424ffc39ac13690a8c93961f07841309bfda
push id52828
push usermak77@bonardo.net
push dateFri, 07 Apr 2017 09:37:10 +0000
reviewersflorian
bugs1353708
milestone55.0a1
Bug 1353708 - Avoid autocomplete call to richlistbox's ensureElementIsVisible when there can't be a scrollbar. r=florian EnsureElementIsVisible can cause a Layout flush, so we should try to avoid it when possible. MozReview-Commit-ID: Dr0D8vPl9rd
toolkit/content/widgets/autocomplete.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -1081,22 +1081,27 @@ extends="chrome://global/content/binding
 
       <!-- =================== nsIAutoCompletePopup =================== -->
 
       <property name="selectedIndex"
                 onget="return this.richlistbox.selectedIndex;">
         <setter>
           <![CDATA[
           this.richlistbox.selectedIndex = val;
-
-          // when clearing the selection (val == -1, so selectedItem will be
-          // null), we want to scroll back to the top.  see bug #406194
-          this.richlistbox.ensureElementIsVisible(
-            this.richlistbox.selectedItem || this.richlistbox.firstChild);
-
+          // Since ensureElementIsVisible may cause an expensive Layout flush,
+          // invoke it only if there may be a scrollbar, so if we could fetch
+          // more results than we can show at once.
+          // maxResults is the maximum number of fetched results, maxRows is the
+          // maximum number of rows we show at once, without a scrollbar.
+          if (this.maxResults > this.maxRows) {
+            // when clearing the selection (val == -1, so selectedItem will be
+            // null), we want to scroll back to the top.  see bug #406194
+            this.richlistbox.ensureElementIsVisible(
+              this.richlistbox.selectedItem || this.richlistbox.firstChild);
+          }
           return val;
         ]]>
         </setter>
       </property>
 
       <method name="onSearchBegin">
         <body><![CDATA[
           this.richlistbox.mouseSelectedIndex = -1;