Bug 1356532: Part 2 - Avoid layout flushes during adjustSiteIconStart(). r?florian draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 22 Jul 2017 15:52:40 -0700
changeset 613826 3ae48a326e5b082d16d0bce98eb861ae2e878179
parent 613825 0adcbdd64f3b6402037964218c38b977605cb518
child 613827 b81d08f2058eb7a7e60afe71366cbe4fecf40a1c
push id69862
push usermaglione.k@gmail.com
push dateSun, 23 Jul 2017 00:25:43 +0000
reviewersflorian
bugs1356532
milestone56.0a1
Bug 1356532: Part 2 - Avoid layout flushes during adjustSiteIconStart(). r?florian MozReview-Commit-ID: 3DiWGUYGDoU
toolkit/content/widgets/autocomplete.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -2370,34 +2370,44 @@ extends="chrome://global/content/binding
                   the window.  Pass undefined to reset the icon's position to
                   whatever is specified in CSS.
            @return True if the icon's position changed, false if not. -->
       <method name="adjustSiteIconStart">
         <parameter name="newStart"/>
         <body>
           <![CDATA[
           if (typeof(newStart) != "number") {
-            this._typeIcon.style.removeProperty("margin-inline-start");
+            requestAnimationFrame(() => {
+              this._typeIcon.style.removeProperty("margin-inline-start");
+            });
             return true;
           }
+
           let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
                             .getInterface(Ci.nsIDOMWindowUtils);
           let rect = utils.getBoundsWithoutFlushing(this._siteIcon);
 
           let dir = this.getAttribute("dir");
           let delta = dir == "rtl" ? rect.right - newStart
                                    : newStart - rect.left;
-          let px = this._typeIcon.style.marginInlineStart;
-          if (!px) {
-            // Allow margin-inline-start not to be specified in CSS initially.
-            let style = window.getComputedStyle(this._typeIcon);
-            px = dir == "rtl" ? style.marginRight : style.marginLeft;
-          }
-          let typeIconStart = Number(px.substr(0, px.length - 2));
-          this._typeIcon.style.marginInlineStart = (typeIconStart + delta) + "px";
+          (async () => {
+            let px = this._typeIcon.style.marginInlineStart;
+            if (!px) {
+              // Allow margin-inline-start not to be specified in CSS initially.
+              await PromiseUtils.layoutFlushed(document, "layout", () => {
+                let style = window.getComputedStyle(this._typeIcon);
+                px = dir == "rtl" ? style.marginRight : style.marginLeft;
+              });
+            }
+            let typeIconStart = Number(px.substr(0, px.length - 2));
+
+            requestAnimationFrame(() => {
+              this._typeIcon.style.marginInlineStart = (typeIconStart + delta) + "px";
+            });
+          })();
           return delta > 0;
           ]]>
         </body>
       </method>
 
       <!-- This method truncates the displayed strings as necessary. -->
       <method name="_handleOverflow">
         <body><![CDATA[