Ticket #9268: tb.kludge.diff

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

Kludge

  • 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    /* kludge for some platforms,
     2880       but will reduce correct maxHeight for OS Windows
     2881       Anybody knows how to kludge this kludge?  */
     2882
     2883    var delta_fix = (Math.round(window.mozInnerScreenY) + 1) - window.screenY;
     2884
     2885    /* window.screen.avail* returns maximum outer size available.
     2886       We no need screen resolution for desktop here,
     2887       which can't to count DPI settings, taskbar or something else  */
     2888
     2889    var maxHeight = window.screen.availHeight - (diff_height + delta_fix);
     2890    var maxWidth = window.screen.availWidth - diff_width ;
     2891
     2892    var width = 0;
     2893    var height = 0;
     2894
     2895    torbutton_log(5, "About to resize window: " +
     2896                      window.outerWidth + "x" + window.outerHeight +
     2897                     " inner: " + win.innerWidth + "x" + win.innerHeight +
     2898                     " in state " + window.windowState +
     2899                     " Available: " + window.screen.availWidth + "x" +
     2900                      window.screen.availHeight);
     2901
     2902
     2903    if (maxWidth > 1000) {
     2904      width = 1000;
     2905    } else {
     2906      width = Math.floor(maxWidth/200.0)*200;
     2907    }
     2908
     2909    height = Math.floor(maxHeight/100.0)*100;
     2910
     2911    torbutton_log(5, "Max dimensions for resize: " + maxWidth + "x" +
     2912                      maxHeight + " Requested: " + width + "x" + height);
     2913
     2914    win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2915}
    28722916// Bug 1506 P1/P3: Setting a fixed window size is important, but
    28732917// probably not for android.
    28742918var torbutton_resizelistener =
     
    28942938        progress.removeProgressListener(this);
    28952939        return;
    28962940      }
    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);
    29012941
    29022942      // We need to set the inner width to an initial value because it has none
    29032943      // at this point... Choosing "300" as this works even on Windows
     
    29052945      win.innerWidth = 300;
    29062946      win.innerHeight = 300;
    29072947
    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;
    29282948
    29292949      var handler = function() {
    29302950        if (window.windowState === 1) {
    29312951          window.addEventListener("resize",
    29322952            function() {
    2933               win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2953              torbutton_resize_window(win);
    29342954              var calling_function = arguments.callee;
    29352955              setTimeout(function() {
    29362956                           torbutton_log(3, "Removing resize listener..");
     
    29692989      // This is fun. any attempt to directly set the inner window actually
    29702990      // resizes the outer width to that value instead. Must use resizeBy()
    29712991      // 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);
     2992      torbutton_resize_window(win);
    29762993
    29772994      // Resizing within this progress listener does not always work as overlays
    29782995      // of other extensions might still influence the height/width of the
     
    29893006              torbutton_log(3, "Mutation observer: Window dimensions are: " +
    29903007                win.innerWidth + " x " + win.innerHeight);
    29913008              setTimeout(function() {
    2992                            win.resizeBy(width - win.innerWidth,
    2993                              height - win.innerHeight);
     3009                           torbutton_resize_window(win);
    29943010                           torbutton_log(3, "Mutation observer: Window " +
    29953011                             "dimensions are (after resizing again): " + win.
    29963012                             innerWidth + " x " + win.innerHeight);