home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 October / maximum-cd-2009-10.iso / DiscContents / Firefox Setup 3.5.exe / nonlocalized / chrome / toolkit.jar / content / global / viewZoomOverlay.js < prev    next >
Encoding:
JavaScript  |  2009-06-24  |  3.3 KB  |  116 lines

  1. //@line 42 "e:\builds\moz2_slave\win32_build\build\toolkit\content\viewZoomOverlay.js"
  2.  
  3. /** Document Zoom Management Code
  4.  *
  5.  * To use this, you'll need to have a getBrowser() function or use the methods
  6.  * that accept a browser to be modified.
  7.  **/
  8.  
  9. var ZoomManager = {
  10.   get _prefBranch ZoomManager_get__prefBranch() {
  11.     delete this._prefBranch;
  12.     return this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  13.                                         .getService(Components.interfaces.nsIPrefBranch);
  14.   },
  15.  
  16.   get MIN ZoomManager_get_MIN() {
  17.     delete this.MIN;
  18.     return this.MIN = this._prefBranch.getIntPref("zoom.minPercent") / 100;
  19.   },
  20.  
  21.   get MAX ZoomManager_get_MAX() {
  22.     delete this.MAX;
  23.     return this.MAX = this._prefBranch.getIntPref("zoom.maxPercent") / 100;
  24.   },
  25.  
  26.   get useFullZoom ZoomManager_get_useFullZoom() {
  27.     return this._prefBranch.getBoolPref("browser.zoom.full");
  28.   },
  29.  
  30.   set useFullZoom ZoomManager_set_useFullZoom(aVal) {
  31.     this._prefBranch.setBoolPref("browser.zoom.full", aVal);
  32.     return aVal;
  33.   },
  34.  
  35.   get zoom ZoomManager_get_zoom() {
  36.     return this.getZoomForBrowser(getBrowser());
  37.   },
  38.  
  39.   getZoomForBrowser: function ZoomManager_getZoomForBrowser(aBrowser) {
  40.     var markupDocumentViewer = aBrowser.markupDocumentViewer;
  41.  
  42.     return this.useFullZoom ? markupDocumentViewer.fullZoom
  43.                             : markupDocumentViewer.textZoom;
  44.   },
  45.  
  46.   set zoom ZoomManager_set_zoom(aVal) {
  47.     this.setZoomForBrowser(getBrowser(), aVal);
  48.     return aVal;
  49.   },
  50.  
  51.   setZoomForBrowser: function ZoomManager_setZoomForBrowser(aBrowser, aVal) {
  52.     if (aVal < this.MIN || aVal > this.MAX)
  53.       throw Components.results.NS_ERROR_INVALID_ARG;
  54.  
  55.     var markupDocumentViewer = aBrowser.markupDocumentViewer;
  56.  
  57.     if (this.useFullZoom) {
  58.       markupDocumentViewer.textZoom = 1;
  59.       markupDocumentViewer.fullZoom = aVal;
  60.     } else {
  61.       markupDocumentViewer.textZoom = aVal;
  62.       markupDocumentViewer.fullZoom = 1;
  63.     }
  64.   },
  65.  
  66.   get zoomValues ZoomManager_get_zoomValues() {
  67.     var zoomValues = this._prefBranch.getCharPref("toolkit.zoomManager.zoomValues")
  68.                                      .split(",").map(parseFloat);
  69.     zoomValues.sort(function (a, b) a - b);
  70.  
  71.     while (zoomValues[0] < this.MIN)
  72.       zoomValues.shift();
  73.  
  74.     while (zoomValues[zoomValues.length - 1] > this.MAX)
  75.       zoomValues.pop();
  76.  
  77.     delete this.zoomValues;
  78.     return this.zoomValues = zoomValues;
  79.   },
  80.  
  81.   enlarge: function ZoomManager_enlarge() {
  82.     var i = this.zoomValues.indexOf(this.snap(this.zoom)) + 1;
  83.     if (i < this.zoomValues.length)
  84.       this.zoom = this.zoomValues[i];
  85.   },
  86.  
  87.   reduce: function ZoomManager_reduce() {
  88.     var i = this.zoomValues.indexOf(this.snap(this.zoom)) - 1;
  89.     if (i >= 0)
  90.       this.zoom = this.zoomValues[i];
  91.   },
  92.  
  93.   reset: function ZoomManager_reset() {
  94.     this.zoom = 1;
  95.   },
  96.  
  97.   toggleZoom: function ZoomManager_toggleZoom() {
  98.     var zoomLevel = this.zoom;
  99.  
  100.     this.useFullZoom = !this.useFullZoom;
  101.     this.zoom = zoomLevel;
  102.   },
  103.  
  104.   snap: function ZoomManager_snap(aVal) {
  105.     var values = this.zoomValues;
  106.     for (var i = 0; i < values.length; i++) {
  107.       if (values[i] >= aVal) {
  108.         if (i > 0 && aVal - values[i - 1] < values[i] - aVal)
  109.           i--;
  110.         return values[i];
  111.       }
  112.     }
  113.     return values[i - 1];
  114.   }
  115. }
  116.