home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / firefox-3.0.14 / chrome / browser.jar / content / browser / setDesktopBackground.js < prev    next >
Encoding:
JavaScript  |  2007-09-02  |  4.9 KB  |  127 lines

  1. //@line 39 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  2.  
  3. var Ci = Components.interfaces;
  4.  
  5. var gSetBackground = {
  6. //@line 44 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  7.   _position        : "",
  8.   _backgroundColor : 0,
  9. //@line 49 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  10.   _screenWidth     : 0,
  11.   _screenHeight    : 0,
  12.   _image           : null,
  13.   _canvas          : null,
  14.  
  15.   get _shell()
  16.   {
  17.     return Components.classes["@mozilla.org/browser/shell-service;1"]
  18.                      .getService(Ci.nsIShellService);
  19.   },
  20.  
  21.   load: function ()
  22.   {
  23.     this._canvas = document.getElementById("screen");
  24.     this._screenWidth = screen.width;
  25.     this._screenHeight = screen.height;
  26. //@line 68 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  27.     if (this._screenWidth / this._screenHeight >= 1.6)
  28.       document.getElementById("monitor").setAttribute("aspectratio", "16:10");
  29.  
  30.     // make sure that the correct dimensions will be used
  31.     setTimeout(function(self) {
  32.       self.init(window.arguments[0]);
  33.     }, 0, this);
  34.   },
  35.  
  36.   init: function (aImage)
  37.   {
  38.     this._image = aImage;
  39.  
  40.     // set the size of the coordinate space
  41.     this._canvas.width = this._canvas.clientWidth;
  42.     this._canvas.height = this._canvas.clientHeight;
  43.  
  44.     var ctx = this._canvas.getContext("2d");
  45.     ctx.scale(this._canvas.clientWidth / this._screenWidth, this._canvas.clientHeight / this._screenHeight);
  46.  
  47. //@line 89 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  48.     this._initColor();
  49. //@line 101 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  50.     this.updatePosition();
  51.   },
  52.  
  53. //@line 105 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  54.   _initColor: function ()
  55.   {
  56.     var color = this._shell.desktopBackgroundColor;
  57.  
  58.     const rMask = 4294901760;
  59.     const gMask = 65280;
  60.     const bMask = 255;
  61.     var r = (color & rMask) >> 16;
  62.     var g = (color & gMask) >> 8;
  63.     var b = (color & bMask);
  64.     this.updateColor(this._rgbToHex(r, g, b));
  65.  
  66.     var colorpicker = document.getElementById("desktopColor");
  67.     colorpicker.color = this._backgroundColor;
  68.   },
  69.  
  70.   updateColor: function (aColor)
  71.   {
  72.     this._backgroundColor = aColor;
  73.     this._canvas.style.backgroundColor = aColor;
  74.   },
  75.  
  76.   // Converts a color string in the format "#RRGGBB" to an integer.
  77.   _hexStringToLong: function (aString)
  78.   {
  79.     return parseInt(aString.substring(1,3), 16) << 16 |
  80.            parseInt(aString.substring(3,5), 16) << 8 |
  81.            parseInt(aString.substring(5,7), 16);
  82.   },
  83.  
  84.   _rgbToHex: function (aR, aG, aB)
  85.   {
  86.     return "#" + [aR, aG, aB].map(function(aInt) aInt.toString(16).replace(/^(.)$/, "0$1"))
  87.                              .join("").toUpperCase();
  88.   },
  89. //@line 158 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  90.  
  91.   setDesktopBackground: function ()
  92.   {
  93. //@line 162 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  94.     document.persist("menuPosition", "value");
  95.     this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor);
  96. //@line 174 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  97.     this._shell.setDesktopBackground(this._image,
  98.                                      Ci.nsIShellService["BACKGROUND_" + this._position]);
  99.   },
  100.  
  101.   updatePosition: function ()
  102.   {
  103.     var ctx = this._canvas.getContext("2d");
  104.     ctx.clearRect(0, 0, this._screenWidth, this._screenHeight);
  105.  
  106. //@line 184 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  107.     this._position = document.getElementById("menuPosition").value;
  108. //@line 186 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/shell/content/setDesktopBackground.js"
  109.  
  110.     switch (this._position) {
  111.       case "TILE":
  112.         ctx.save();
  113.         ctx.fillStyle = ctx.createPattern(this._image, "repeat");
  114.         ctx.fillRect(0, 0, this._screenWidth, this._screenHeight);
  115.         ctx.restore();
  116.         break;
  117.       case "STRETCH":
  118.         ctx.drawImage(this._image, 0, 0, this._screenWidth, this._screenHeight);
  119.         break;
  120.       case "CENTER":
  121.         var x = (this._screenWidth - this._image.naturalWidth) / 2;
  122.         var y = (this._screenHeight - this._image.naturalHeight) / 2;
  123.         ctx.drawImage(this._image, x, y);
  124.     }
  125.   }
  126. };
  127.