From ae79f996db5cec04999d164552b75b3366cfa54a Mon Sep 17 00:00:00 2001 From: Thomas Groman Date: Fri, 24 Apr 2020 22:38:11 -0700 Subject: Remove AppConstants and do stuff in preproccessor, also remove unsupported OS code https://web.archive.org/web/20200425044233/https://github.com/MoonchildProductions/UXP/issues/65 --- .../shell/content/setDesktopBackground.js | 137 ++++++--------------- 1 file changed, 36 insertions(+), 101 deletions(-) (limited to 'webbrowser/components/shell/content/setDesktopBackground.js') diff --git a/webbrowser/components/shell/content/setDesktopBackground.js b/webbrowser/components/shell/content/setDesktopBackground.js index 53cc70d..6502fe3 100644 --- a/webbrowser/components/shell/content/setDesktopBackground.js +++ b/webbrowser/components/shell/content/setDesktopBackground.js @@ -1,14 +1,8 @@ -/* 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/. */ - -Components.utils.import("resource://gre/modules/AppConstants.jsm"); - var Ci = Components.interfaces; var gSetBackground = { - _position : AppConstants.platform == "macosx" ? "STRETCH" : "", - _backgroundColor : AppConstants.platform != "macosx" ? 0 : undefined, + _position : "", + _backgroundColor : 0, _screenWidth : 0, _screenHeight : 0, _image : null, @@ -25,24 +19,9 @@ var gSetBackground = { this._canvas = document.getElementById("screen"); this._screenWidth = screen.width; this._screenHeight = screen.height; - if (AppConstants.platform == "macosx") { - document.documentElement.getButton("accept").hidden = true; - } if (this._screenWidth / this._screenHeight >= 1.6) document.getElementById("monitor").setAttribute("aspectratio", "16:10"); - if (AppConstants.platform == "win") { - // Hide fill + fit options if < Win7 since they don't work. - var version = Components.classes["@mozilla.org/system-info;1"] - .getService(Ci.nsIPropertyBag2) - .getProperty("version"); - var isWindows7OrHigher = (parseFloat(version) >= 6.1); - if (!isWindows7OrHigher) { - document.getElementById("fillPosition").hidden = true; - document.getElementById("fitPosition").hidden = true; - } - } - // make sure that the correct dimensions will be used setTimeout(function(self) { self.init(window.arguments[0]); @@ -60,37 +39,14 @@ var gSetBackground = { var ctx = this._canvas.getContext("2d"); ctx.scale(this._canvas.clientWidth / this._screenWidth, this._canvas.clientHeight / this._screenHeight); - if (AppConstants.platform != "macosx") { - this._initColor(); - } else { - // Make sure to reset the button state in case the user has already - // set an image as their desktop background. - var setDesktopBackground = document.getElementById("setDesktopBackground"); - setDesktopBackground.hidden = false; - var bundle = document.getElementById("backgroundBundle"); - setDesktopBackground.label = bundle.getString("DesktopBackgroundSet"); - setDesktopBackground.disabled = false; - - document.getElementById("showDesktopPreferences").hidden = true; - } + this._initColor(); this.updatePosition(); }, setDesktopBackground: function () { - if (AppConstants.platform != "macosx") { - document.persist("menuPosition", "value"); - this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor); - } else { - Components.classes["@mozilla.org/observer-service;1"] - .getService(Ci.nsIObserverService) - .addObserver(this, "shell:desktop-background-changed", false); - - var bundle = document.getElementById("backgroundBundle"); - var setDesktopBackground = document.getElementById("setDesktopBackground"); - setDesktopBackground.disabled = true; - setDesktopBackground.label = bundle.getString("DesktopBackgroundDownloading"); - } + document.persist("menuPosition", "value"); + this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor); this._shell.setDesktopBackground(this._image, Ci.nsIShellService["BACKGROUND_" + this._position]); }, @@ -100,9 +56,7 @@ var gSetBackground = { var ctx = this._canvas.getContext("2d"); ctx.clearRect(0, 0, this._screenWidth, this._screenHeight); - if (AppConstants.platform != "macosx") { - this._position = document.getElementById("menuPosition").value; - } + this._position = document.getElementById("menuPosition").value; switch (this._position) { case "TILE": @@ -158,57 +112,38 @@ var gSetBackground = { } }; -if (AppConstants.platform != "macosx") { - gSetBackground["_initColor"] = function () - { - var color = this._shell.desktopBackgroundColor; - - const rMask = 4294901760; - const gMask = 65280; - const bMask = 255; - var r = (color & rMask) >> 16; - var g = (color & gMask) >> 8; - var b = (color & bMask); - this.updateColor(this._rgbToHex(r, g, b)); +gSetBackground["_initColor"] = function () +{ + var color = this._shell.desktopBackgroundColor; - var colorpicker = document.getElementById("desktopColor"); - colorpicker.color = this._backgroundColor; - }; + const rMask = 4294901760; + const gMask = 65280; + const bMask = 255; + var r = (color & rMask) >> 16; + var g = (color & gMask) >> 8; + var b = (color & bMask); + this.updateColor(this._rgbToHex(r, g, b)); - gSetBackground["updateColor"] = function (aColor) - { - this._backgroundColor = aColor; - this._canvas.style.backgroundColor = aColor; - }; - - // Converts a color string in the format "#RRGGBB" to an integer. - gSetBackground["_hexStringToLong"] = function (aString) - { - return parseInt(aString.substring(1, 3), 16) << 16 | - parseInt(aString.substring(3, 5), 16) << 8 | - parseInt(aString.substring(5, 7), 16); - }; + var colorpicker = document.getElementById("desktopColor"); + colorpicker.color = this._backgroundColor; +}; - gSetBackground["_rgbToHex"] = function (aR, aG, aB) - { - return "#" + [aR, aG, aB].map(aInt => aInt.toString(16).replace(/^(.)$/, "0$1")) - .join("").toUpperCase(); - }; -} else { - gSetBackground["observe"] = function (aSubject, aTopic, aData) - { - if (aTopic == "shell:desktop-background-changed") { - document.getElementById("setDesktopBackground").hidden = true; - document.getElementById("showDesktopPreferences").hidden = false; +gSetBackground["updateColor"] = function (aColor) +{ + this._backgroundColor = aColor; + this._canvas.style.backgroundColor = aColor; +}; - Components.classes["@mozilla.org/observer-service;1"] - .getService(Ci.nsIObserverService) - .removeObserver(this, "shell:desktop-background-changed"); - } - }; +// Converts a color string in the format "#RRGGBB" to an integer. +gSetBackground["_hexStringToLong"] = function (aString) +{ + return parseInt(aString.substring(1, 3), 16) << 16 | + parseInt(aString.substring(3, 5), 16) << 8 | + parseInt(aString.substring(5, 7), 16); +}; - gSetBackground["showDesktopPrefs"] = function() - { - this._shell.openApplication(Ci.nsIMacShellService.APPLICATION_DESKTOP); - }; -} +gSetBackground["_rgbToHex"] = function (aR, aG, aB) +{ + return "#" + [aR, aG, aB].map(aInt => aInt.toString(16).replace(/^(.)$/, "0$1")) + .join("").toUpperCase(); +}; -- cgit v1.2.3