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
--- 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;