#375: M1334642 +efficiency patch

This commit is contained in:
Cameron Kaiser 2019-11-17 15:10:11 -08:00
parent eb6f62648e
commit 1d2b06b10d
3 changed files with 59 additions and 15 deletions

View File

@ -604,7 +604,7 @@ var FullScreen = {
} }
} }
ToolbarIconColor.inferFromText(); ToolbarIconColor.inferFromText("fullscreen", aEnterFS);
// For Lion fullscreen, all fullscreen controls are hidden, don't // For Lion fullscreen, all fullscreen controls are hidden, don't
// bother to touch them. If we don't stop here, the following code // bother to touch them. If we don't stop here, the following code

View File

@ -243,7 +243,7 @@ var TabsInTitlebar = {
menubar.style.paddingBottom = ""; menubar.style.paddingBottom = "";
} }
ToolbarIconColor.inferFromText(); ToolbarIconColor.inferFromText("tabsintitlebar", TabsInTitlebar.enabled);
if (CustomizationHandler.isCustomizing()) { if (CustomizationHandler.isCustomizing()) {
gCustomizeMode.updateLWTStyling(); gCustomizeMode.updateLWTStyling();
} }

View File

@ -5292,8 +5292,6 @@ function setToolbarVisibility(toolbar, isVisible, persist=true) {
PlacesToolbarHelper.init(); PlacesToolbarHelper.init();
BookmarkingUI.onToolbarVisibilityChange(); BookmarkingUI.onToolbarVisibilityChange();
gBrowser.updateWindowResizers(); gBrowser.updateWindowResizers();
if (isVisible)
ToolbarIconColor.inferFromText();
} }
var TabletModeUpdater = { var TabletModeUpdater = {
@ -8014,18 +8012,25 @@ function BrowserOpenNewTabOrWindow(event) {
} }
var ToolbarIconColor = { var ToolbarIconColor = {
_windowState: {
"active": false,
"fullscreen": false,
"tabsintitlebar": false
},
init: function () { init: function () {
this._initialized = true; this._initialized = true;
window.addEventListener("activate", this); window.addEventListener("activate", this);
window.addEventListener("deactivate", this); window.addEventListener("deactivate", this);
window.addEventListener("toolbarvisibilitychange", this);
Services.obs.addObserver(this, "lightweight-theme-styling-update", false); Services.obs.addObserver(this, "lightweight-theme-styling-update", false);
// If the window isn't active now, we assume that it has never been active // If the window isn't active now, we assume that it has never been active
// before and will soon become active such that inferFromText will be // before and will soon become active such that inferFromText will be
// called from the initial activate event. // called from the initial activate event.
if (Services.focus.activeWindow == window) if (Services.focus.activeWindow == window) {
this.inferFromText(); this.inferFromText("activate");
}
}, },
uninit: function () { uninit: function () {
@ -8033,14 +8038,18 @@ var ToolbarIconColor = {
window.removeEventListener("activate", this); window.removeEventListener("activate", this);
window.removeEventListener("deactivate", this); window.removeEventListener("deactivate", this);
window.removeEventListener("toolbarvisibilitychange", this);
Services.obs.removeObserver(this, "lightweight-theme-styling-update"); Services.obs.removeObserver(this, "lightweight-theme-styling-update");
}, },
handleEvent: function (event) { handleEvent: function (event) {
switch (event.type) { switch (event.type) {
case "activate": case "activate": // falls through
case "deactivate": case "deactivate":
this.inferFromText(); this.inferFromText(event.type);
break;
case "toolbarvisibilitychange":
this.inferFromText(event.type, event.visible);
break; break;
} }
}, },
@ -8050,32 +8059,67 @@ var ToolbarIconColor = {
case "lightweight-theme-styling-update": case "lightweight-theme-styling-update":
// inferFromText needs to run after LightweightThemeConsumer.jsm's // inferFromText needs to run after LightweightThemeConsumer.jsm's
// lightweight-theme-styling-update observer. // lightweight-theme-styling-update observer.
setTimeout(() => { this.inferFromText(); }, 0); setTimeout(() => {
this.inferFromText(aTopic);
}, 0);
break; break;
} }
}, },
inferFromText: function () { // a cache of luminance values for each toolbar
// to avoid unnecessary calls to getComputedStyle
_toolbarLuminanceCache: new Map(),
inferFromText(reason, reasonValue) {
if (!this._initialized) if (!this._initialized)
return; return;
function parseRGB(aColorString) { function parseRGB(aColorString) {
let rgb = aColorString.match(/^rgba?\((\d+), (\d+), (\d+)/); let rgb = aColorString.match(/^rgba?\((\d+), (\d+), (\d+)/);
rgb.shift(); rgb.shift();
return rgb.map(x => parseInt(x)); return rgb.map(x => parseInt(x));
} }
switch (reason) {
case "activate": // falls through
case "deactivate":
this._windowState.active = (reason === "activate");
break;
case "fullscreen":
this._windowState.fullscreen = reasonValue;
break;
case "lightweight-theme-styling-update":
// theme change, we'll need to recalculate all color values
this._toolbarLuminanceCache.clear();
break;
case "toolbarvisibilitychange":
// toolbar changes dont require reset of the cached color values
break;
case "tabsintitlebar":
this._windowState.tabsintitlebar = reasonValue;
break;
}
let toolbarSelector = "#navigator-toolbox > toolbar:not([collapsed=true]):not(#addon-bar)"; let toolbarSelector = "#navigator-toolbox > toolbar:not([collapsed=true]):not(#addon-bar)";
//if (AppConstants.platform == "macosx") //if (AppConstants.platform == "macosx")
toolbarSelector += ":not([type=menubar])"; toolbarSelector += ":not([type=menubar])";
// The getComputedStyle calls and setting the brighttext are separated in // The getComputedStyle calls and setting the brighttext are separated in
// 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 luminances = new Map; let luminances = new Map();
let windowStateKey = JSON.stringify(this._windowState); // TenFourFox
for (let toolbar of document.querySelectorAll(toolbarSelector)) { for (let toolbar of document.querySelectorAll(toolbarSelector)) {
let [r, g, b] = parseRGB(getComputedStyle(toolbar).color); // toolbars *should* all have ids, but guard anyway to avoid blowing up
let luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b; let cacheKey = toolbar.id && toolbar.id + windowStateKey;
// 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);
} }