Bug 1383367: Part 3 - Defer getComputedStyle call if a reflow is currently pending. r=mconley

MozReview-Commit-ID: 33IRfOlaBxP

--HG--
extra : source : 1f9ec38274940ff20a1bfc0a6b8c76ea5ae16cff
This commit is contained in:
Kris Maglione 2017-07-26 14:30:00 -07:00
Родитель bb44d3f3da
Коммит 89980ca107
2 изменённых файлов: 27 добавлений и 19 удалений

Просмотреть файл

@ -8717,7 +8717,7 @@ var ToolbarIconColor = {
// to avoid unnecessary calls to getComputedStyle // to avoid unnecessary calls to getComputedStyle
_toolbarLuminanceCache: new Map(), _toolbarLuminanceCache: new Map(),
inferFromText(reason, reasonValue) { async inferFromText(reason, reasonValue) {
if (!this._initialized) if (!this._initialized)
return; return;
function parseRGB(aColorString) { function parseRGB(aColorString) {
@ -8754,20 +8754,22 @@ var ToolbarIconColor = {
// two loops to avoid flushing layout and making it dirty repeatedly. // two loops to avoid flushing layout and making it dirty repeatedly.
let cachedLuminances = this._toolbarLuminanceCache; let cachedLuminances = this._toolbarLuminanceCache;
let luminances = new Map(); let luminances = new Map();
for (let toolbar of document.querySelectorAll(toolbarSelector)) { await BrowserUtils.promiseLayoutFlushed(document, "style", () => {
// toolbars *should* all have ids, but guard anyway to avoid blowing up for (let toolbar of document.querySelectorAll(toolbarSelector)) {
let cacheKey = toolbar.id && toolbar.id + JSON.stringify(this._windowState); // toolbars *should* all have ids, but guard anyway to avoid blowing up
// lookup cached luminance value for this toolbar in this window state let cacheKey = toolbar.id && toolbar.id + JSON.stringify(this._windowState);
let luminance = cacheKey && cachedLuminances.get(cacheKey); // lookup cached luminance value for this toolbar in this window state
if (isNaN(luminance)) { let luminance = cacheKey && cachedLuminances.get(cacheKey);
let [r, g, b] = parseRGB(getComputedStyle(toolbar).color); if (isNaN(luminance)) {
luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b; let [r, g, b] = parseRGB(getComputedStyle(toolbar).color);
if (cacheKey) { luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b;
cachedLuminances.set(cacheKey, luminance); if (cacheKey) {
cachedLuminances.set(cacheKey, luminance);
}
} }
luminances.set(toolbar, luminance);
} }
luminances.set(toolbar, luminance); });
}
for (let [toolbar, luminance] of luminances) { for (let [toolbar, luminance] of luminances) {
if (luminance <= 110) if (luminance <= 110)

Просмотреть файл

@ -32,8 +32,10 @@ if (Services.appinfo.OS == "Linux") {
EXPECTED_REFLOWS.push( EXPECTED_REFLOWS.push(
[ [
"handleEvent@chrome://browser/content/tabbrowser.xml", "handleEvent@chrome://browser/content/tabbrowser.xml",
"inferFromText@chrome://browser/content/browser.js", "inferFromText/<@chrome://browser/content/browser.js",
"handleEvent@chrome://browser/content/browser.js", "promiseReflowed/</<@resource://gre/modules/BrowserUtils.jsm",
"_onReflow@resource://gre/modules/BrowserUtils.jsm",
"reflowInterruptible@resource://gre/modules/BrowserUtils.jsm",
], ],
); );
} }
@ -43,8 +45,10 @@ if (Services.appinfo.OS == "Darwin") {
EXPECTED_REFLOWS.push( EXPECTED_REFLOWS.push(
[ [
"handleEvent@chrome://browser/content/tabbrowser.xml", "handleEvent@chrome://browser/content/tabbrowser.xml",
"inferFromText@chrome://browser/content/browser.js", "inferFromText/<@chrome://browser/content/browser.js",
"handleEvent@chrome://browser/content/browser.js", "promiseReflowed/</<@resource://gre/modules/BrowserUtils.jsm",
"_onReflow@resource://gre/modules/BrowserUtils.jsm",
"reflowInterruptible@resource://gre/modules/BrowserUtils.jsm",
], ],
); );
} }
@ -67,8 +71,10 @@ if (Services.appinfo.OS == "WINNT") {
[ [
"handleEvent@chrome://browser/content/tabbrowser.xml", "handleEvent@chrome://browser/content/tabbrowser.xml",
"inferFromText@chrome://browser/content/browser.js", "inferFromText/<@chrome://browser/content/browser.js",
"handleEvent@chrome://browser/content/browser.js", "promiseReflowed/</<@resource://gre/modules/BrowserUtils.jsm",
"_onReflow@resource://gre/modules/BrowserUtils.jsm",
"reflowInterruptible@resource://gre/modules/BrowserUtils.jsm",
], ],
[ [