Bug 1448017 - Initialize ToolbarIconColor before the initial layout to spare a potential restyle after the initial layout. r?bgrins draft
authorDão Gottwald <dao@mozilla.com>
Thu, 22 Mar 2018 16:18:20 +0100
changeset 771146 7c4b08deb2b138137312e86bbe438a6803d4b1bb
parent 771093 7771df14ea181add1dc4133f0f5559bf620bf976
child 771157 b02c9f2dc6039d9f30ce2571769ba111bbc4a370
push id103578
push userdgottwald@mozilla.com
push dateThu, 22 Mar 2018 15:18:48 +0000
reviewersbgrins
bugs1448017
milestone61.0a1
Bug 1448017 - Initialize ToolbarIconColor before the initial layout to spare a potential restyle after the initial layout. r?bgrins MozReview-Commit-ID: LLJ2EftdXZn
browser/base/content/browser.js
browser/base/content/test/performance/browser_toolbariconcolor_restyles.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1227,16 +1227,27 @@ var gBrowserInit = {
 
       if (width < TARGET_WIDTH && height < TARGET_HEIGHT) {
         document.documentElement.setAttribute("sizemode", "maximized");
       }
     }
 
     new LightweightThemeConsumer(document);
     TabsInTitlebar.init();
+
+    if (window.matchMedia("(-moz-os-version: windows-win8)").matches &&
+        window.matchMedia("(-moz-windows-default-theme)").matches) {
+      let windowFrameColor = new Color(...ChromeUtils.import("resource:///modules/Windows8WindowFrameColor.jsm", {})
+                                            .Windows8WindowFrameColor.get());
+      // Default to black for foreground text.
+      if (!windowFrameColor.isContrastRatioAcceptable(new Color(0, 0, 0))) {
+        document.documentElement.setAttribute("darkwindowframe", "true");
+      }
+    }
+    ToolbarIconColor.init();
   },
 
   onDOMContentLoaded() {
     gBrowser = window._gBrowser;
     delete window._gBrowser;
     gBrowser.init();
 
     window.QueryInterface(Ci.nsIInterfaceRequestor)
@@ -1363,28 +1374,16 @@ var gBrowserInit = {
 
     // Misc. inits.
     TabletModeUpdater.init();
     CombinedStopReload.ensureInitialized();
     gPrivateBrowsingUI.init();
     BrowserPageActions.init();
     gAccessibilityServiceIndicator.init();
 
-    if (window.matchMedia("(-moz-os-version: windows-win8)").matches &&
-        window.matchMedia("(-moz-windows-default-theme)").matches) {
-      let windowFrameColor = new Color(...ChromeUtils.import("resource:///modules/Windows8WindowFrameColor.jsm", {})
-                                            .Windows8WindowFrameColor.get());
-      // Default to black for foreground text.
-      if (!windowFrameColor.isContrastRatioAcceptable(new Color(0, 0, 0))) {
-        document.documentElement.setAttribute("darkwindowframe", "true");
-      }
-    }
-
-    ToolbarIconColor.init();
-
     gRemoteControl.updateVisualCue(Marionette.running);
 
     // If we are given a tab to swap in, take care of it before first paint to
     // avoid an about:blank flash.
     let tabToOpen = window.arguments && window.arguments[0];
     if (tabToOpen instanceof XULElement) {
       // Clear the reference to the tab from the arguments array.
       window.arguments[0] = null;
--- a/browser/base/content/test/performance/browser_toolbariconcolor_restyles.js
+++ b/browser/base/content/test/performance/browser_toolbariconcolor_restyles.js
@@ -12,16 +12,22 @@ add_task(async function test_toolbar_ele
   // create a window and snapshot the elementsStyled
   let win1 = await BrowserTestUtils.openNewBrowserWindow();
   await new Promise(resolve => waitForFocus(resolve, win1));
 
   // create a 2nd window and snapshot the elementsStyled
   let win2 = await BrowserTestUtils.openNewBrowserWindow();
   await new Promise(resolve => waitForFocus(resolve, win2));
 
+  // (De)-activate both windows once before we take a measurement. The first
+  // (de-)activation may flush styles, after that the style data should be
+  // cached.
+  Services.focus.activeWindow = win1;
+  Services.focus.activeWindow = win2;
+
   // Flush any pending styles before we take a measurement.
   win1.getComputedStyle(win1.document.firstElementChild);
   win2.getComputedStyle(win2.document.firstElementChild);
 
   // Clear the focused element from each window so that when
   // we raise them, the focus of the element doesn't cause an
   // unrelated style flush.
   Services.focus.clearFocus(win1);