mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
b0c1ba9c9e
--HG-- rename : toolkit/mozapps/shared/CertUtils.jsm => toolkit/modules/CertUtils.jsm rename : toolkit/content/DeferredTask.jsm => toolkit/modules/DeferredTask.jsm rename : toolkit/content/Deprecated.jsm => toolkit/modules/Deprecated.jsm rename : toolkit/content/Dict.jsm => toolkit/modules/Dict.jsm rename : toolkit/mozapps/shared/FileUtils.jsm => toolkit/modules/FileUtils.jsm rename : toolkit/content/Geometry.jsm => toolkit/modules/Geometry.jsm rename : toolkit/content/InlineSpellChecker.jsm => toolkit/modules/InlineSpellChecker.jsm rename : toolkit/content/LightweightThemeConsumer.jsm => toolkit/modules/LightweightThemeConsumer.jsm rename : toolkit/content/PageMenu.jsm => toolkit/modules/PageMenu.jsm rename : toolkit/content/PopupNotifications.jsm => toolkit/modules/PopupNotifications.jsm rename : toolkit/content/PrivateBrowsingUtils.jsm => toolkit/modules/PrivateBrowsingUtils.jsm rename : toolkit/content/PropertyListUtils.jsm => toolkit/modules/PropertyListUtils.jsm rename : toolkit/content/Services.jsm => toolkit/modules/Services.jsm rename : toolkit/content/Task.jsm => toolkit/modules/Task.jsm rename : toolkit/content/Troubleshoot.jsm => toolkit/modules/Troubleshoot.jsm rename : toolkit/content/UpdateChannel.jsm => toolkit/modules/UpdateChannel.jsm rename : toolkit/content/WindowDraggingUtils.jsm => toolkit/modules/WindowDraggingUtils.jsm rename : toolkit/content/debug.js => toolkit/modules/debug.js rename : toolkit/content/tests/browser/browser_DeferredTask.js => toolkit/modules/tests/browser/browser_DeferredTask.js rename : toolkit/content/tests/browser/browser_Deprecated.js => toolkit/modules/tests/browser/browser_Deprecated.js rename : toolkit/content/tests/browser/browser_Geometry.js => toolkit/modules/tests/browser/browser_Geometry.js rename : toolkit/content/tests/browser/browser_InlineSpellChecker.js => toolkit/modules/tests/browser/browser_InlineSpellChecker.js rename : toolkit/content/tests/browser/browser_Services.js => toolkit/modules/tests/browser/browser_Services.js rename : toolkit/content/tests/browser/browser_Troubleshoot.js => toolkit/modules/tests/browser/browser_Troubleshoot.js rename : toolkit/mozapps/shared/test/chrome/Makefile.in => toolkit/modules/tests/chrome/Makefile.in rename : toolkit/mozapps/shared/test/chrome/moz.build => toolkit/modules/tests/chrome/moz.build rename : toolkit/mozapps/shared/test/chrome/test_bug544442_checkCert.xul => toolkit/modules/tests/chrome/test_bug544442_checkCert.xul rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListBinary.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListBinary.plist rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListXML.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListXML.plist rename : toolkit/mozapps/shared/test/unit/test_FileUtils.js => toolkit/modules/tests/xpcshell/test_FileUtils.js rename : toolkit/content/tests/unit/test_dict.js => toolkit/modules/tests/xpcshell/test_dict.js rename : toolkit/content/tests/unit/test_propertyListsUtils.js => toolkit/modules/tests/xpcshell/test_propertyListsUtils.js rename : toolkit/mozapps/shared/test/unit/test_readCertPrefs.js => toolkit/modules/tests/xpcshell/test_readCertPrefs.js rename : toolkit/content/tests/unit/test_task.js => toolkit/modules/tests/xpcshell/test_task.js
129 lines
4.2 KiB
JavaScript
129 lines
4.2 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
this.EXPORTED_SYMBOLS = ["LightweightThemeConsumer"];
|
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeImageOptimizer",
|
|
"resource://gre/modules/LightweightThemeImageOptimizer.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
this.LightweightThemeConsumer =
|
|
function LightweightThemeConsumer(aDocument) {
|
|
this._doc = aDocument;
|
|
this._win = aDocument.defaultView;
|
|
this._footerId = aDocument.documentElement.getAttribute("lightweightthemesfooter");
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(this._win) &&
|
|
!PrivateBrowsingUtils.permanentPrivateBrowsing) {
|
|
return;
|
|
}
|
|
|
|
let screen = this._win.screen;
|
|
this._lastScreenWidth = screen.width;
|
|
this._lastScreenHeight = screen.height;
|
|
|
|
Components.classes["@mozilla.org/observer-service;1"]
|
|
.getService(Components.interfaces.nsIObserverService)
|
|
.addObserver(this, "lightweight-theme-styling-update", false);
|
|
|
|
var temp = {};
|
|
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", temp);
|
|
this._update(temp.LightweightThemeManager.currentThemeForDisplay);
|
|
this._win.addEventListener("resize", this);
|
|
}
|
|
|
|
LightweightThemeConsumer.prototype = {
|
|
_lastData: null,
|
|
_lastScreenWidth: null,
|
|
_lastScreenHeight: null,
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
|
if (aTopic != "lightweight-theme-styling-update")
|
|
return;
|
|
|
|
this._update(JSON.parse(aData));
|
|
},
|
|
|
|
handleEvent: function (aEvent) {
|
|
let {width, height} = this._win.screen;
|
|
|
|
if (this._lastScreenWidth != width || this._lastScreenHeight != height) {
|
|
this._lastScreenWidth = width;
|
|
this._lastScreenHeight = height;
|
|
this._update(this._lastData);
|
|
}
|
|
},
|
|
|
|
destroy: function () {
|
|
if (!PrivateBrowsingUtils.isWindowPrivate(this._win) ||
|
|
PrivateBrowsingUtils.permanentPrivateBrowsing) {
|
|
Components.classes["@mozilla.org/observer-service;1"]
|
|
.getService(Components.interfaces.nsIObserverService)
|
|
.removeObserver(this, "lightweight-theme-styling-update");
|
|
|
|
this._win.removeEventListener("resize", this);
|
|
}
|
|
|
|
this._win = this._doc = null;
|
|
},
|
|
|
|
_update: function (aData) {
|
|
if (!aData)
|
|
aData = { headerURL: "", footerURL: "", textcolor: "", accentcolor: "" };
|
|
|
|
this._lastData = aData;
|
|
aData = LightweightThemeImageOptimizer.optimize(aData, this._win.screen);
|
|
|
|
var root = this._doc.documentElement;
|
|
var active = !!aData.headerURL;
|
|
|
|
if (active) {
|
|
root.style.color = aData.textcolor || "black";
|
|
root.style.backgroundColor = aData.accentcolor || "white";
|
|
let [r, g, b] = _parseRGB(this._doc.defaultView.getComputedStyle(root, "").color);
|
|
let luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b;
|
|
root.setAttribute("lwthemetextcolor", luminance <= 110 ? "dark" : "bright");
|
|
root.setAttribute("lwtheme", "true");
|
|
} else {
|
|
root.style.color = "";
|
|
root.style.backgroundColor = "";
|
|
root.removeAttribute("lwthemetextcolor");
|
|
root.removeAttribute("lwtheme");
|
|
}
|
|
|
|
_setImage(root, active, aData.headerURL);
|
|
if (this._footerId) {
|
|
let footer = this._doc.getElementById(this._footerId);
|
|
footer.style.backgroundColor = active ? aData.accentcolor || "white" : "";
|
|
_setImage(footer, active, aData.footerURL);
|
|
if (active && aData.footerURL)
|
|
footer.setAttribute("lwthemefooter", "true");
|
|
else
|
|
footer.removeAttribute("lwthemefooter");
|
|
}
|
|
|
|
#ifdef XP_MACOSX
|
|
if (active)
|
|
root.setAttribute("drawintitlebar", "true");
|
|
else
|
|
root.removeAttribute("drawintitlebar");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
function _setImage(aElement, aActive, aURL) {
|
|
aElement.style.backgroundImage =
|
|
(aActive && aURL) ? 'url("' + aURL.replace(/"/g, '\\"') + '")' : "";
|
|
}
|
|
|
|
function _parseRGB(aColorString) {
|
|
var rgb = aColorString.match(/^rgba?\((\d+), (\d+), (\d+)/);
|
|
rgb.shift();
|
|
return rgb.map(function (x) parseInt(x));
|
|
}
|