From 5e0560d8957b67984a05657b981572ea07421e01 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Mon, 27 Jan 2020 04:06:17 -0500 Subject: [PATCH] [Pale-Moon] Issue MoonchildProductions/UXP#65 - Remove AppConstants Pale Moon.. again. --- .../palemoon/base/content/autocomplete.xml | 32 ++-- .../components/shell/ShellService.jsm | 44 +++-- .../shell/content/setDesktopBackground.js | 169 +++++++++--------- application/palemoon/components/shell/jar.mn | 2 +- .../palemoon/components/shell/moz.build | 2 +- 5 files changed, 128 insertions(+), 121 deletions(-) diff --git a/application/palemoon/base/content/autocomplete.xml b/application/palemoon/base/content/autocomplete.xml index bd0928436f..a9a4d9a831 100644 --- a/application/palemoon/base/content/autocomplete.xml +++ b/application/palemoon/base/content/autocomplete.xml @@ -449,12 +449,14 @@ var cancel = false; - let { AppConstants } = - Components.utils.import("resource://gre/modules/AppConstants.jsm", {}); // Catch any keys that could potentially move the caret. Ctrl can be // used in combination with these keys on Windows and Linux; and Alt // can be used on OS X, so make sure the unused one isn't used. - let metaKey = AppConstants.platform == "macosx" ? aEvent.ctrlKey : aEvent.altKey; +#ifdef XP_MACOSX + let metaKey = aEvent.ctrlKey; +#else + let metaKey = aEvent.altKey; +#endif if (!this.disableKeyNavigation && !metaKey) { switch (aEvent.keyCode) { case KeyEvent.DOM_VK_LEFT: @@ -492,11 +494,11 @@ cancel = this.mController.handleEscape(); break; case KeyEvent.DOM_VK_RETURN: - if (AppConstants.platform == "macosx") { - // Prevent the default action, since it will beep on Mac - if (aEvent.metaKey) - aEvent.preventDefault(); - } +#ifdef XP_MACOSX + // Prevent the default action, since it will beep on Mac + if (aEvent.metaKey) + aEvent.preventDefault(); +#endif this.mEnterEvent = aEvent; if (this.mController.selection) { this._selectionDetails = { @@ -507,15 +509,19 @@ cancel = this.handleEnter(); break; case KeyEvent.DOM_VK_DELETE: - if (AppConstants.platform == "macosx" && !aEvent.shiftKey) { +#ifdef XP_MACOSX + if (!aEvent.shiftKey) { break; } +#endif cancel = this.handleDelete(); break; case KeyEvent.DOM_VK_BACK_SPACE: - if (AppConstants.platform == "macosx" && aEvent.shiftKey) { +#ifdef XP_MACOSX + if (aEvent.shiftKey) { cancel = this.handleDelete(); } +#endif break; case KeyEvent.DOM_VK_DOWN: case KeyEvent.DOM_VK_UP: @@ -523,9 +529,9 @@ this.toggleHistoryPopup(); break; case KeyEvent.DOM_VK_F4: - if (AppConstants.platform != "macosx") { - this.toggleHistoryPopup(); - } +#ifndef XP_MACOSX + this.toggleHistoryPopup(); +#endif break; } diff --git a/application/palemoon/components/shell/ShellService.jsm b/application/palemoon/components/shell/ShellService.jsm index 74632b6926..f453dcbc86 100644 --- a/application/palemoon/components/shell/ShellService.jsm +++ b/application/palemoon/components/shell/ShellService.jsm @@ -8,7 +8,6 @@ this.EXPORTED_SYMBOLS = ["ShellService"]; const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; -Cu.import("resource://gre/modules/AppConstants.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "WindowsRegistry", @@ -26,20 +25,17 @@ var ShellServiceInternal = { * environments. */ get canSetDesktopBackground() { - if (AppConstants.platform == "win" || - AppConstants.platform == "macosx") { - return true; +#ifdef XP_LINUX + if (this.shellService) { + let linuxShellService = this.shellService + .QueryInterface(Ci.nsIGNOMEShellService); + return linuxShellService.canSetDesktopBackground; } - - if (AppConstants.platform == "linux") { - if (this.shellService) { - let linuxShellService = this.shellService - .QueryInterface(Ci.nsIGNOMEShellService); - return linuxShellService.canSetDesktopBackground; - } - } - +#elif defined(XP_WIN) || defined(XP_MACOSX) + return true; +#else return false; +#endif }, /** @@ -60,18 +56,18 @@ var ShellServiceInternal = { return false; } - if (AppConstants.platform == "win") { - let optOutValue = WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, - "Software\\Mozilla\\PaleMoon", - "DefaultBrowserOptOut"); - WindowsRegistry.removeRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, - "Software\\Mozilla\\PaleMoon", - "DefaultBrowserOptOut"); - if (optOutValue == "True") { - Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", false); - return false; - } +#ifdef XP_WIN + let optOutValue = WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, + "Software\\Mozilla\\PaleMoon", + "DefaultBrowserOptOut"); + WindowsRegistry.removeRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, + "Software\\Mozilla\\PaleMoon", + "DefaultBrowserOptOut"); + if (optOutValue == "True") { + Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", false); + return false; } +#endif return true; }, diff --git a/application/palemoon/components/shell/content/setDesktopBackground.js b/application/palemoon/components/shell/content/setDesktopBackground.js index 53cc70db0d..4c11b9d331 100644 --- a/application/palemoon/components/shell/content/setDesktopBackground.js +++ b/application/palemoon/components/shell/content/setDesktopBackground.js @@ -7,8 +7,13 @@ 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, +#ifdef XP_MACOSX + _position : "STRETCH", + _backgroundColor : undefined, +#else + _position : "", + _backgroundColor : 0, +#endif _screenWidth : 0, _screenHeight : 0, _image : null, @@ -25,23 +30,23 @@ 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; - } +#ifdef XP_MACOSX + document.documentElement.getButton("accept").hidden = true; +#endif 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; - } +#ifdef XP_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; } +#endif // make sure that the correct dimensions will be used setTimeout(function(self) { @@ -60,28 +65,25 @@ 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; +#ifdef XP_MACOSX + // 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; - } + document.getElementById("showDesktopPreferences").hidden = true; +#else + this._initColor(); +#endif this.updatePosition(); }, setDesktopBackground: function () { - if (AppConstants.platform != "macosx") { - document.persist("menuPosition", "value"); - this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor); - } else { +#ifdef XP_MACOSX Components.classes["@mozilla.org/observer-service;1"] .getService(Ci.nsIObserverService) .addObserver(this, "shell:desktop-background-changed", false); @@ -90,7 +92,10 @@ var gSetBackground = { var setDesktopBackground = document.getElementById("setDesktopBackground"); setDesktopBackground.disabled = true; setDesktopBackground.label = bundle.getString("DesktopBackgroundDownloading"); - } +#else + document.persist("menuPosition", "value"); + this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor); +#endif this._shell.setDesktopBackground(this._image, Ci.nsIShellService["BACKGROUND_" + this._position]); }, @@ -100,9 +105,9 @@ 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; - } +#ifndef XP_MACOSX + this._position = document.getElementById("menuPosition").value; +#endif switch (this._position) { case "TILE": @@ -158,57 +163,57 @@ var gSetBackground = { } }; -if (AppConstants.platform != "macosx") { - gSetBackground["_initColor"] = function () - { - var color = this._shell.desktopBackgroundColor; +#ifdef XP_MACOSX +gSetBackground["observe"] = function (aSubject, aTopic, aData) +{ + if (aTopic == "shell:desktop-background-changed") { + document.getElementById("setDesktopBackground").hidden = true; + document.getElementById("showDesktopPreferences").hidden = false; - 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)); + Components.classes["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService) + .removeObserver(this, "shell:desktop-background-changed"); + } +}; - var colorpicker = document.getElementById("desktopColor"); - colorpicker.color = this._backgroundColor; - }; +gSetBackground["showDesktopPrefs"] = function() +{ + this._shell.openApplication(Ci.nsIMacShellService.APPLICATION_DESKTOP); +}; +#else +gSetBackground["_initColor"] = function () +{ + var color = this._shell.desktopBackgroundColor; - gSetBackground["updateColor"] = function (aColor) - { - this._backgroundColor = aColor; - this._canvas.style.backgroundColor = aColor; - }; + 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)); - // 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(); +}; +#endif diff --git a/application/palemoon/components/shell/jar.mn b/application/palemoon/components/shell/jar.mn index 0864e1b306..39303f275b 100644 --- a/application/palemoon/components/shell/jar.mn +++ b/application/palemoon/components/shell/jar.mn @@ -4,4 +4,4 @@ browser.jar: * content/browser/setDesktopBackground.xul (content/setDesktopBackground.xul) - content/browser/setDesktopBackground.js (content/setDesktopBackground.js) +* content/browser/setDesktopBackground.js (content/setDesktopBackground.js) diff --git a/application/palemoon/components/shell/moz.build b/application/palemoon/components/shell/moz.build index 16bffd7d9d..b11d9747c8 100644 --- a/application/palemoon/components/shell/moz.build +++ b/application/palemoon/components/shell/moz.build @@ -32,7 +32,7 @@ EXTRA_COMPONENTS += [ 'nsSetDefaultBrowser.manifest', ] -EXTRA_JS_MODULES += ['ShellService.jsm'] +EXTRA_PP_JS_MODULES += ['ShellService.jsm'] for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION'): DEFINES[var] = '"%s"' % CONFIG[var]