Ticket #9268: tb.kludge2.diff

File tb.kludge2.diff, 4.9 KB (added by cypherpunks, 6 years ago)

Kludge2

  • 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
     2876    var diff_height = window.outerHeight - win.innerHeight;
     2877    var diff_width = window.outerWidth - win.innerWidth;
     2878
     2879
     2880    /* kludge kludge kludge
     2881       What about screenPixelsPerCSSPixel? */
     2882    var delta_fix = 0;
     2883    if (window.outerHeight == window.innerHeight)
     2884      delta_fix = (Math.round(window.mozInnerScreenY) + 1) - window.screenY;
     2885
     2886    /* window.screen.avail* returns maximum outer size available.
     2887       We no need screen resolution for desktop here,
     2888       which can't to count DPI settings, taskbar or something else  */
     2889
     2890    var maxHeight = window.screen.availHeight - (diff_height + delta_fix);
     2891    var maxWidth = window.screen.availWidth - diff_width ;
     2892
     2893    var width = 0;
     2894    var height = 0;
     2895
     2896    torbutton_log(5, "About to resize window: " +
     2897                      window.outerWidth + "x" + window.outerHeight +
     2898                     " inner: " + win.innerWidth + "x" + win.innerHeight +
     2899                     " in state " + window.windowState +
     2900                     " Available: " + window.screen.availWidth + "x" +
     2901                      window.screen.availHeight);
     2902
     2903
     2904    if (maxWidth > 1000) {
     2905      width = 1000;
     2906    } else {
     2907      width = Math.floor(maxWidth/200.0)*200;
     2908    }
     2909
     2910    height = Math.floor(maxHeight/100.0)*100;
     2911
     2912    torbutton_log(5, "Max dimensions for resize: " + maxWidth + "x" +
     2913                      maxHeight + " Requested: " + width + "x" + height);
     2914
     2915    win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2916}
    28722917// Bug 1506 P1/P3: Setting a fixed window size is important, but
    28732918// probably not for android.
    28742919var torbutton_resizelistener =
     
    28942939        progress.removeProgressListener(this);
    28952940        return;
    28962941      }
    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);
    29012942
    29022943      // We need to set the inner width to an initial value because it has none
    29032944      // at this point... Choosing "300" as this works even on Windows
     
    29052946      win.innerWidth = 300;
    29062947      win.innerHeight = 300;
    29072948
    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;
    29282949
    29292950      var handler = function() {
    29302951        if (window.windowState === 1) {
    29312952          window.addEventListener("resize",
    29322953            function() {
    2933               win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2954              torbutton_resize_window(win);
    29342955              var calling_function = arguments.callee;
    29352956              setTimeout(function() {
    29362957                           torbutton_log(3, "Removing resize listener..");
     
    29692990      // This is fun. any attempt to directly set the inner window actually
    29702991      // resizes the outer width to that value instead. Must use resizeBy()
    29712992      // 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);
     2993      torbutton_resize_window(win);
    29762994
    29772995      // Resizing within this progress listener does not always work as overlays
    29782996      // of other extensions might still influence the height/width of the
     
    29893007              torbutton_log(3, "Mutation observer: Window dimensions are: " +
    29903008                win.innerWidth + " x " + win.innerHeight);
    29913009              setTimeout(function() {
    2992                            win.resizeBy(width - win.innerWidth,
    2993                              height - win.innerHeight);
     3010                           torbutton_resize_window(win);
    29943011                           torbutton_log(3, "Mutation observer: Window " +
    29953012                             "dimensions are (after resizing again): " + win.
    29963013                             innerWidth + " x " + win.innerHeight);