mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
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:
parent
bb44d3f3da
commit
89980ca107
@ -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)
|
||||
|
@ -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/</<@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(
|
||||
[
|
||||
"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/</<@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",
|
||||
"inferFromText@chrome://browser/content/browser.js",
|
||||
"handleEvent@chrome://browser/content/browser.js",
|
||||
"inferFromText/<@chrome://browser/content/browser.js",
|
||||
"promiseReflowed/</<@resource://gre/modules/BrowserUtils.jsm",
|
||||
"_onReflow@resource://gre/modules/BrowserUtils.jsm",
|
||||
"reflowInterruptible@resource://gre/modules/BrowserUtils.jsm",
|
||||
],
|
||||
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user