summaryrefslogtreecommitdiffstats
path: root/comm/suite/components/shell/content
diff options
context:
space:
mode:
Diffstat (limited to 'comm/suite/components/shell/content')
-rw-r--r--comm/suite/components/shell/content/setDesktopBackground.js78
-rw-r--r--comm/suite/components/shell/content/setDesktopBackground.xul49
2 files changed, 127 insertions, 0 deletions
diff --git a/comm/suite/components/shell/content/setDesktopBackground.js b/comm/suite/components/shell/content/setDesktopBackground.js
new file mode 100644
index 0000000000..efcc5734e4
--- /dev/null
+++ b/comm/suite/components/shell/content/setDesktopBackground.js
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * 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/. */
+
+var {AppConstants} = ChromeUtils.import(
+ "resource://gre/modules/AppConstants.jsm"
+);
+
+var gShell = Cc["@mozilla.org/suite/shell-service;1"]
+ .getService(Ci.nsIShellService);
+
+var gImage, gImageName, gPosition, gPicker, gDesktop;
+
+function onLoad()
+{
+ document.getElementById("itemsBox").hidden = AppConstants.platform == "macosx";
+ gImage = window.arguments[0];
+ gImageName = window.arguments[1];
+ gPosition = document.getElementById("position");
+ gPicker = document.getElementById("picker");
+ gDesktop = document.getElementById("desktop");
+
+ sizeToContent();
+ window.innerWidth += screen.width / 2 - gDesktop.boxObject.width;
+ window.innerHeight += screen.height / 2 - gDesktop.boxObject.height;
+
+ try {
+ var color = gShell.desktopBackgroundColor;
+ color = (0xF000000 | color).toString(16).toUpperCase().replace("F", "#");
+ gDesktop.style.backgroundColor = color;
+ gPicker.color = color;
+ } catch (e) {
+ gPicker.parentNode.hidden = true;
+ }
+
+ gDesktop.style.backgroundImage = 'url("' + gImage.src + '")';
+
+ updatePosition();
+}
+
+function onApply()
+{
+ if (!gPicker.parentNode.hidden)
+ gShell.desktopBackgroundColor = parseInt(gPicker.color.substr(1), 16);
+
+ gShell.setDesktopBackground(gImage, Ci.nsIShellService[gPosition.value],
+ gImageName);
+}
+
+function updatePosition()
+{
+ gDesktop.style.backgroundPosition = "center";
+ gDesktop.style.backgroundRepeat = "no-repeat";
+ switch (gPosition.value) {
+ case "BACKGROUND_FIT":
+ gDesktop.style.backgroundSize = "contain";
+ return;
+ case "BACKGROUND_FILL":
+ gDesktop.style.backgroundSize = "cover";
+ return;
+ case "BACKGROUND_STRETCH":
+ gDesktop.style.backgroundPosition = "";
+ gDesktop.style.backgroundSize = "100% 100%";
+ return;
+ case "BACKGROUND_TILE":
+ gDesktop.style.backgroundPosition = "";
+ gDesktop.style.backgroundRepeat = "repeat";
+ }
+ gDesktop.style.backgroundSize =
+ (gImage.naturalWidth / 2) + "px " + (gImage.naturalHeight / 2) + "px";
+}
+
+function updateColor()
+{
+ gDesktop.style.backgroundColor = gPicker.color;
+}
diff --git a/comm/suite/components/shell/content/setDesktopBackground.xul b/comm/suite/components/shell/content/setDesktopBackground.xul
new file mode 100644
index 0000000000..16fb384658
--- /dev/null
+++ b/comm/suite/components/shell/content/setDesktopBackground.xul
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+
+<!-- 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/. -->
+
+<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
+
+<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/setDesktopBackground.dtd">
+
+<dialog id="setDesktopBackground"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="onLoad();"
+ buttons="accept,extra2"
+ buttoniconaccept="close"
+ buttonlabelaccept="&close.label;"
+ buttoniconextra2="apply"
+ buttonlabelextra2="&apply.label;"
+ buttonaccesskeyextra2="&apply.accesskey;"
+ ondialogextra2="onApply();"
+ title="&setDesktopBackground.title;">
+
+ <script src="chrome://communicator/content/setDesktopBackground.js"/>
+
+ <hbox id="itemsBox" align="center">
+ <label value="&position.label;" accesskey="&position.accesskey;"/>
+ <menulist id="position"
+ value="BACKGROUND_STRETCH"
+ persist="value"
+ oncommand="updatePosition();">
+ <menupopup>
+ <menuitem value="BACKGROUND_TILE" label="&position.tile.label;"/>
+ <menuitem value="BACKGROUND_STRETCH" label="&position.stretch.label;"/>
+ <menuitem value="BACKGROUND_CENTER" label="&position.center.label;"/>
+ <menuitem value="BACKGROUND_FILL" label="&position.fill.label;"/>
+ <menuitem value="BACKGROUND_FIT" label="&position.fit.label;"/>
+ </menupopup>
+ </menulist>
+ <hbox flex="1" pack="end">
+ <label value="&picker.label;" accesskey="&picker.accesskey;"/>
+ <colorpicker id="picker" type="button" onchange="updateColor();"/>
+ </hbox>
+ </hbox>
+
+ <groupbox flex="1">
+ <caption label="&preview.caption;"/>
+ <spacer id="desktop" flex="1"/>
+ </groupbox>
+</dialog>