Ticket #9268: tb.idea.diff

File tb.idea.diff, 5.1 KB (added by cypherpunks, 6 years ago)

Idea

  • torbutton.js

    old new  
    28692869  { /*torbutton_eclog(1, 'called linkIcon'); */ return 0; }
    28702870}
    28712871
     2872/* Call it to resize window. Later is better, then it counts
     2873   all appeared bars to proper round inner sizes */
     2874function torbutton_resize_window(win) {
     2875      var diff_height = window.outerHeight - win.innerHeight;
     2876      var diff_width = window.outerWidth - win.innerWidth;
     2877
     2878      /* Re: f2b3ddc18d
     2879         window.screen not lies about sizes,
     2880         it returns maximum outer size available.
     2881         We no need screen resolution for desktop here,
     2882         which can't to count DPI settings, taskbar or something else  */
     2883      /* maximum outer size is screen.avail + border */
     2884      var maxHeight = window.screen.availHeight - diff_height;
     2885      var maxWidth = window.screen.availWidth - diff_width ;
     2886
     2887      while (true) { // This is SPARTA!!!
     2888        var width;
     2889        var height;
     2890
     2891        /* some logs here */
     2892        torbutton_log(3, "About to resize new window: " + window.outerWidth +
     2893          "x" + window.outerHeight + " inner: " + win.innerWidth + "x" + win.
     2894          innerHeight + " in state " + window.windowState + " Have " +
     2895          window.screen.availWidth + "x" + window.screen.availHeight);
     2896
     2897        torbutton_log(3, "Got max dimensions: " + maxWidth + "x" + maxHeight);
     2898
     2899
     2900        if (maxWidth > 1000) {
     2901          width = 1000;
     2902        } else {
     2903          width = Math.floor(maxWidth/200.0)*200;
     2904        }
     2905
     2906        height = Math.floor(maxHeight/100.0)*100;
     2907 
     2908        win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2909        /* everything ok */
     2910        if (win.innerHeight == height && win.innerWidth == width)
     2911          break;
     2912        /* if result is higher then break too, something wrong. XXX logs */
     2913        if (win.innerHeight > height || win.innerWidth > width)
     2914          break;
     2915        maxHeight = win.innerHeight;
     2916        maxWidth = win.innerWidth;
     2917      }
     2918     
     2919}
    28722920// Bug 1506 P1/P3: Setting a fixed window size is important, but
    28732921// probably not for android.
    28742922var torbutton_resizelistener =
     
    28942942        progress.removeProgressListener(this);
    28952943        return;
    28962944      }
    2897       var screenMan = Components.classes["@mozilla.org/gfx/screenmanager;1"].
    2898         getService(Components.interfaces.nsIScreenManager);
    2899       var junk = {}, availWidth = {}, availHeight = {};
    2900       screenMan.primaryScreen.GetRect(junk, junk, availWidth, availHeight);
    29012945
    29022946      // We need to set the inner width to an initial value because it has none
    29032947      // at this point... Choosing "300" as this works even on Windows
     
    29052949      win.innerWidth = 300;
    29062950      win.innerHeight = 300;
    29072951
    2908       torbutton_log(3, "About to resize new window: " + window.outerWidth +
    2909         "x" + window.outerHeight + " inner: " + win.innerWidth + "x" + win.
    2910         innerHeight + " in state " + window.windowState + " Have " +
    2911         availWidth.value + "x" + availHeight.value);
    2912 
    2913       var maxHeight = availHeight.value -
    2914         (window.outerHeight - win.innerHeight) - 51;
    2915       var maxWidth = availWidth.value - (window.outerWidth - win.innerWidth);
    2916       torbutton_log(3, "Got max dimensions: " + maxWidth + "x" + maxHeight);
    2917 
    2918       var width;
    2919       var height;
    2920 
    2921       if (maxWidth > 1000) {
    2922         width = 1000;
    2923       } else {
    2924         width = Math.floor(maxWidth/200.0)*200;
    2925       }
    2926 
    2927       height = Math.floor(maxHeight/100.0)*100;
    29282952
    29292953      var handler = function() {
    29302954        if (window.windowState === 1) {
    29312955          window.addEventListener("resize",
    29322956            function() {
    2933               win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2957              torbutton_resize_window(win);
    29342958              var calling_function = arguments.callee;
    29352959              setTimeout(function() {
    29362960                           torbutton_log(3, "Removing resize listener..");
     
    29692993      // This is fun. any attempt to directly set the inner window actually
    29702994      // resizes the outer width to that value instead. Must use resizeBy()
    29712995      // instead of assignment or resizeTo()
    2972       win.resizeBy(width - win.innerWidth, height - win.innerHeight);
    2973       torbutton_log(3, "Resized new window from: " + win.innerWidth + "x" +
    2974         win.innerHeight + " to " + width + "x" + height + " in state " +
    2975         window.windowState);
     2996      torbutton_resize_window(win);
    29762997
    29772998      // Resizing within this progress listener does not always work as overlays
    29782999      // of other extensions might still influence the height/width of the
     
    29893010              torbutton_log(3, "Mutation observer: Window dimensions are: " +
    29903011                win.innerWidth + " x " + win.innerHeight);
    29913012              setTimeout(function() {
    2992                            win.resizeBy(width - win.innerWidth,
    2993                              height - win.innerHeight);
     3013                           torbutton_resize_window(win);
    29943014                           torbutton_log(3, "Mutation observer: Window " +
    29953015                             "dimensions are (after resizing again): " + win.
    29963016                             innerWidth + " x " + win.innerHeight);