Bug 612373 - Add "Span" option for Windows and Linux to "Set As Desktop Background". r=Gijs
authorIan Moody <moz-ian@perix.co.uk>
Wed, 27 Mar 2019 18:26:19 +0000
changeset 525257 f292291c4ef63711ad35c5be73a65d59f368eb8e
parent 525256 b921a78c88737795ae259dbeedf962b93c6e1137
child 525258 635d208646083b487bbd32da48c1e0059d1b3bcc
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs612373, 603551, 1061416
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 612373 - Add "Span" option for Windows and Linux to "Set As Desktop Background". r=Gijs Gnome introduced this in 2.30[0], Windows in 8[1]. Preview is just an "international prohibition symbol" to save the complicated business of trying to calculate a semi-accurate one. [0] https://gitlab.gnome.org/GNOME/gnome-desktop/commit/8eb0886312751054e2e6d9b10eedbb0ddf180deb https://bugzilla.gnome.org/show_bug.cgi?id=603551 [1] https://superuser.com/questions/1061416/which-version-of-windows-introduced-the-span-wallpaper-style Differential Revision: https://phabricator.services.mozilla.com/D23336
browser/components/shell/content/setDesktopBackground.js
browser/components/shell/content/setDesktopBackground.xul
browser/components/shell/nsGNOMEShellService.cpp
browser/components/shell/nsIShellService.idl
browser/components/shell/nsWindowsShellService.cpp
browser/components/shell/test/browser_420786.js
browser/components/uitour/test/browser_UITour_defaultBrowser.js
browser/locales/en-US/chrome/browser/setDesktopBackground.dtd
--- a/browser/components/shell/content/setDesktopBackground.js
+++ b/browser/components/shell/content/setDesktopBackground.js
@@ -17,24 +17,40 @@ var gSetBackground = {
     return Cc["@mozilla.org/browser/shell-service;1"]
              .getService(Ci.nsIShellService);
   },
 
   load() {
     this._canvas = document.getElementById("screen");
     this._screenWidth = screen.width;
     this._screenHeight = screen.height;
-    if (AppConstants.platform == "macosx") {
-      document.documentElement.getButton("accept").hidden = true;
-    }
     // Cap ratio to 4 so the dialog width doesn't get ridiculous. Highest
     // regular screens seem to be 32:9 (3.56) according to Wikipedia.
     let screenRatio = Math.min(this._screenWidth / this._screenHeight, 4);
     this._canvas.width = this._canvas.height * screenRatio;
 
+    if (AppConstants.platform == "macosx") {
+      document.documentElement.getButton("accept").hidden = true;
+    } else {
+      let multiMonitors = false;
+      try {
+        const gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
+        const monitors = gfxInfo.getMonitors();
+        multiMonitors = monitors.length > 1;
+      } catch (e) {
+        // getMonitors() isn't implemented on Linux
+        multiMonitors = true;
+      }
+
+      if (!multiMonitors || AppConstants.isPlatformAndVersionAtMost("win", 6.1)) {
+        // Hide span option if < Win8 since that's when it was introduced.
+        document.getElementById("spanPosition").hidden = true;
+      }
+    }
+
     document.addEventListener("dialogaccept", function() { gSetBackground.setDesktopBackground(); });
     // make sure that the correct dimensions will be used
     setTimeout(function(self) {
       self.init(window.arguments[0], window.arguments[1]);
     }, 0, this);
   },
 
   init(aImage, aImageName) {
@@ -135,16 +151,31 @@ var gSetBackground = {
           width = this._image.naturalWidth * heightRatio;
           height = this._image.naturalHeight * heightRatio;
           x = (this._screenWidth - width) / 2;
           y = 0;
         }
         ctx.drawImage(this._image, x, y, width, height);
         break;
       }
+      case "SPAN": {
+        ctx.fillStyle = "black";
+        ctx.fillRect(0, 0, this._screenWidth, this._screenHeight);
+        let x = this._screenWidth / 2;
+        let y = this._screenHeight / 2;
+        let radius = this._screenHeight * .4;
+        let delta = Math.sin(.25 * Math.PI) * radius; // opp = sin * hyp
+        ctx.lineWidth = radius / 4.5;
+        ctx.strokeStyle = "#9B2423";
+        ctx.arc(x, y, radius, -.75 * Math.PI, 1.25 * Math.PI);
+        ctx.stroke();
+        ctx.lineWidth *= .8;
+        ctx.lineTo(x + delta, y + delta);
+        ctx.stroke();
+      }
     }
   },
 };
 
 if (AppConstants.platform != "macosx") {
   gSetBackground._initColor = function() {
     var color = this._shell.desktopBackgroundColor;
 
--- a/browser/components/shell/content/setDesktopBackground.xul
+++ b/browser/components/shell/content/setDesktopBackground.xul
@@ -46,16 +46,17 @@
                 label="&position.label;"
                 oncommand="gSetBackground.updatePosition();">
         <menupopup>
           <menuitem label="&center.label;"  value="CENTER"/>
           <menuitem label="&tile.label;"    value="TILE"/>
           <menuitem label="&stretch.label;" value="STRETCH"/>
           <menuitem label="&fill.label;"    value="FILL"/>
           <menuitem label="&fit.label;"     value="FIT"/>
+          <menuitem label="&span.label;"    value="SPAN" id="spanPosition"/>
         </menupopup>
       </menulist>
       <spacer flex="1"/>
       <label value="&color.label;"/>
       <html:input id="desktopColor"
                   type="color"
                   onchange="gSetBackground.updateColor(this.value);"/> 
     </hbox>
--- a/browser/components/shell/nsGNOMEShellService.cpp
+++ b/browser/components/shell/nsGNOMEShellService.cpp
@@ -410,16 +410,18 @@ nsGNOMEShellService::SetDesktopBackgroun
   if (aPosition == BACKGROUND_TILE)
     options.AssignLiteral("wallpaper");
   else if (aPosition == BACKGROUND_STRETCH)
     options.AssignLiteral("stretched");
   else if (aPosition == BACKGROUND_FILL)
     options.AssignLiteral("zoom");
   else if (aPosition == BACKGROUND_FIT)
     options.AssignLiteral("scaled");
+  else if (aPosition == BACKGROUND_SPAN)
+    options.AssignLiteral("spanned");
   else
     options.AssignLiteral("centered");
 
   // Write the background file to the home directory.
   nsAutoCString filePath(PR_GetEnv("HOME"));
 
   // get the product brand name from localized strings
   nsAutoString brandName;
--- a/browser/components/shell/nsIShellService.idl
+++ b/browser/components/shell/nsIShellService.idl
@@ -38,16 +38,17 @@ interface nsIShellService : nsISupports
   /** 
    * Flags for positioning/sizing of the Desktop Background image.
    */
   const long BACKGROUND_TILE      = 1;
   const long BACKGROUND_STRETCH   = 2;
   const long BACKGROUND_CENTER    = 3;
   const long BACKGROUND_FILL      = 4;
   const long BACKGROUND_FIT       = 5;
+  const long BACKGROUND_SPAN      = 6;
 
     /**
      * Sets the desktop background image using either the HTML <IMG> 
      * element supplied or the background image of the element supplied.
      *
      * @param aImageElement Either a HTML <IMG> element or an element with
      *                      a background image from which to source the
      *                      background image. 
--- a/browser/components/shell/nsWindowsShellService.cpp
+++ b/browser/components/shell/nsWindowsShellService.cpp
@@ -535,16 +535,20 @@ nsWindowsShellService::SetDesktopBackgro
       case BACKGROUND_FILL:
         style.AssignLiteral("10");
         tile.Assign('0');
         break;
       case BACKGROUND_FIT:
         style.Assign('6');
         tile.Assign('0');
         break;
+      case BACKGROUND_SPAN:
+        style.AssignLiteral("22");
+        tile.Assign('0');
+        break;
     }
 
     rv = regKey->WriteStringValue(NS_LITERAL_STRING("TileWallpaper"), tile);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = regKey->WriteStringValue(NS_LITERAL_STRING("WallpaperStyle"), style);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = regKey->Close();
     NS_ENSURE_SUCCESS(rv, rv);
--- a/browser/components/shell/test/browser_420786.js
+++ b/browser/components/shell/test/browser_420786.js
@@ -96,16 +96,17 @@ add_task(async function() {
       };
     }
 
     checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper");
     checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched");
     checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered");
     checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "zoom");
     checkWallpaper(Ci.nsIShellService.BACKGROUND_FIT, "scaled");
+    checkWallpaper(Ci.nsIShellService.BACKGROUND_SPAN, "spanned");
 
     restoreSettings();
 
     // Restore files
     if (wpFileBackup.exists())
       wpFileBackup.moveTo(null, wpFile.leafName);
   });
 });
--- a/browser/components/uitour/test/browser_UITour_defaultBrowser.js
+++ b/browser/components/uitour/test/browser_UITour_defaultBrowser.js
@@ -17,16 +17,17 @@ MockShellService.prototype = {
   },
   shouldCheckDefaultBrowser: false,
   canSetDesktopBackground: false,
   BACKGROUND_TILE: 1,
   BACKGROUND_STRETCH: 2,
   BACKGROUND_CENTER: 3,
   BACKGROUND_FILL: 4,
   BACKGROUND_FIT: 5,
+  BACKGROUND_SPAN: 6,
   setDesktopBackground(aElement, aPosition) {},
   APPLICATION_MAIL: 0,
   APPLICATION_NEWS: 1,
   openApplication(aApplication) {},
   desktopBackgroundColor: 0,
   openApplicationWithURI(aApplication, aURI) {},
 };
 
--- a/browser/locales/en-US/chrome/browser/setDesktopBackground.dtd
+++ b/browser/locales/en-US/chrome/browser/setDesktopBackground.dtd
@@ -3,12 +3,18 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <!ENTITY position.label             "Position:">
 <!ENTITY tile.label                 "Tile">
 <!ENTITY center.label               "Center">
 <!ENTITY stretch.label              "Stretch">
 <!ENTITY fill.label                 "Fill">
 <!ENTITY fit.label                  "Fit">
+<!-- LOCALIZATION NOTE (span.label): This refers to the wallpaper "spanning"
+                       multiple monitors when the user has more than one. Only
+                       some of the entire image will be on each monitor.
+                       This should ideally match the wording in Windows' own
+                       Desktop Background settings page. -->
+<!ENTITY span.label                 "Span">
 <!ENTITY color.label                "Color:">
 <!ENTITY setDesktopBackground.title "Set Desktop Background">
 <!ENTITY openDesktopPrefs.label     "Open Desktop Preferences">
 <!ENTITY closeWindow.key            "w">