Bug 1502096 - Make peviewing and selecting the default theme work consistently in Dark mode. r=spohl, a=RyanVM
Differential Revision:
https://phabricator.services.mozilla.com/D9861
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -120,26 +120,17 @@ var LightweightThemeManager = {
let data = null;
if (selectedThemeID) {
data = this.getUsedTheme(selectedThemeID);
}
return data;
},
get currentThemeForDisplay() {
- var data = this.currentTheme;
-
- if (!data || data.id == DEFAULT_THEME_ID) {
- if (_fallbackThemeData) {
- return _fallbackThemeData;
- }
- if (_defaultThemeIsInDarkMode && _defaultDarkThemeID) {
- return this.getUsedTheme(_defaultDarkThemeID);
- }
- }
+ var data = _substituteDefaulThemeIfNeeded(this.currentTheme);
if (data && PERSIST_ENABLED) {
for (let key in PERSIST_FILES) {
try {
if (data[key] && _prefs.getBoolPref("persisted." + key))
data[key] = _getLocalImageURI(PERSIST_FILES[key]).spec
+ "?" + data.id + ";" + _version(data);
} catch (e) {}
@@ -216,16 +207,18 @@ var LightweightThemeManager = {
clearBuiltInThemes() {
for (let id of this._builtInThemes.keys()) {
this.forgetBuiltInTheme(id);
}
},
previewTheme(aData) {
+ aData = _substituteDefaulThemeIfNeeded(aData);
+
let cancel = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
cancel.data = false;
Services.obs.notifyObservers(cancel, "lightweight-theme-preview-requested",
JSON.stringify(aData));
if (cancel.data)
return;
if (_previewTimer)
@@ -895,16 +888,29 @@ function _updateUsedThemes(aList) {
Services.obs.notifyObservers(null, "lightweight-theme-list-changed");
}
function _notifyWindows(aThemeData) {
Services.obs.notifyObservers(null, "lightweight-theme-styling-update",
JSON.stringify({theme: aThemeData}));
}
+function _substituteDefaulThemeIfNeeded(aThemeData) {
+ if (!aThemeData || aThemeData.id == DEFAULT_THEME_ID) {
+ if (_fallbackThemeData) {
+ return _fallbackThemeData;
+ }
+ if (_defaultThemeIsInDarkMode && _defaultDarkThemeID) {
+ return LightweightThemeManager.getUsedTheme(_defaultDarkThemeID);
+ }
+ }
+
+ return aThemeData;
+}
+
var _previewTimer;
var _previewTimerCallback = {
notify() {
LightweightThemeManager.resetPreview();
},
};
/**