diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 59d10c875190..c504170e89d7 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -8717,7 +8717,7 @@ var ToolbarIconColor = { // to avoid unnecessary calls to getComputedStyle _toolbarLuminanceCache: new Map(), - inferFromText(reason, reasonValue) { + async inferFromText(reason, reasonValue) { if (!this._initialized) return; function parseRGB(aColorString) { @@ -8754,20 +8754,22 @@ var ToolbarIconColor = { // two loops to avoid flushing layout and making it dirty repeatedly. let cachedLuminances = this._toolbarLuminanceCache; let luminances = new Map(); - for (let toolbar of document.querySelectorAll(toolbarSelector)) { - // toolbars *should* all have ids, but guard anyway to avoid blowing up - let cacheKey = toolbar.id && toolbar.id + JSON.stringify(this._windowState); - // lookup cached luminance value for this toolbar in this window state - let luminance = cacheKey && cachedLuminances.get(cacheKey); - if (isNaN(luminance)) { - let [r, g, b] = parseRGB(getComputedStyle(toolbar).color); - luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b; - if (cacheKey) { - cachedLuminances.set(cacheKey, luminance); + await BrowserUtils.promiseLayoutFlushed(document, "style", () => { + for (let toolbar of document.querySelectorAll(toolbarSelector)) { + // toolbars *should* all have ids, but guard anyway to avoid blowing up + let cacheKey = toolbar.id && toolbar.id + JSON.stringify(this._windowState); + // lookup cached luminance value for this toolbar in this window state + let luminance = cacheKey && cachedLuminances.get(cacheKey); + if (isNaN(luminance)) { + let [r, g, b] = parseRGB(getComputedStyle(toolbar).color); + luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b; + if (cacheKey) { + cachedLuminances.set(cacheKey, luminance); + } } + luminances.set(toolbar, luminance); } - luminances.set(toolbar, luminance); - } + }); for (let [toolbar, luminance] of luminances) { if (luminance <= 110) diff --git a/browser/base/content/test/performance/browser_windowopen_reflows.js b/browser/base/content/test/performance/browser_windowopen_reflows.js index f00ef85dc659..e7e85ee983e8 100644 --- a/browser/base/content/test/performance/browser_windowopen_reflows.js +++ b/browser/base/content/test/performance/browser_windowopen_reflows.js @@ -32,8 +32,10 @@ if (Services.appinfo.OS == "Linux") { EXPECTED_REFLOWS.push( [ "handleEvent@chrome://browser/content/tabbrowser.xml", - "inferFromText@chrome://browser/content/browser.js", - "handleEvent@chrome://browser/content/browser.js", + "inferFromText/<@chrome://browser/content/browser.js", + "promiseReflowed/