Ticket #9268: tb.kludgefinal.diff

File tb.kludgefinal.diff, 5.0 KB (added by cypherpunks, 6 years ago)

Final 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
     2880    /* kludge kludge kludge.
     2881       but working. */
     2882    var delta_fix = 0;
     2883    if (window.outerHeight == window.innerHeight) {
     2884      delta_fix = Math.floor(window.mozInnerScreenY) - window.screenY;
     2885      if (delta_fix == 0) // zero? it's maximized or no yet window
     2886        delta_fix = Math.floor(diff_height / 2);
     2887      else
     2888        delta_fix++;
     2889    }
     2890
     2891    /* window.screen.avail* returns maximum outer size available.
     2892       We no need screen resolution for desktop here,
     2893       which can't to count DPI settings, taskbar or something else  */
     2894
     2895    var maxHeight = window.screen.availHeight - (diff_height + delta_fix);
     2896    var maxWidth = window.screen.availWidth - diff_width ;
     2897
     2898    var width = 0;
     2899    var height = 0;
     2900
     2901    torbutton_log(5, "About to resize window: " +
     2902                      window.outerWidth + "x" + window.outerHeight +
     2903                     " inner: " + win.innerWidth + "x" + win.innerHeight +
     2904                     " in state " + window.windowState +
     2905                     " Available: " + window.screen.availWidth + "x" +
     2906                      window.screen.availHeight);
     2907
     2908
     2909    if (maxWidth > 1000) {
     2910      width = 1000;
     2911    } else {
     2912      width = Math.floor(maxWidth/200.0)*200;
     2913    }
     2914
     2915    height = Math.floor(maxHeight/100.0)*100;
     2916
     2917    torbutton_log(5, "Max dimensions for resize: " + maxWidth + "x" +
     2918                      maxHeight + " Requested: " + width + "x" + height);
     2919
     2920    win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2921}
    28722922// Bug 1506 P1/P3: Setting a fixed window size is important, but
    28732923// probably not for android.
    28742924var torbutton_resizelistener =
     
    28942944        progress.removeProgressListener(this);
    28952945        return;
    28962946      }
    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);
    29012947
    29022948      // We need to set the inner width to an initial value because it has none
    29032949      // at this point... Choosing "300" as this works even on Windows
     
    29052951      win.innerWidth = 300;
    29062952      win.innerHeight = 300;
    29072953
    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;
    29282954
    29292955      var handler = function() {
    29302956        if (window.windowState === 1) {
    29312957          window.addEventListener("resize",
    29322958            function() {
    2933               win.resizeBy(width - win.innerWidth, height - win.innerHeight);
     2959              torbutton_resize_window(win);
    29342960              var calling_function = arguments.callee;
    29352961              setTimeout(function() {
    29362962                           torbutton_log(3, "Removing resize listener..");
     
    29692995      // This is fun. any attempt to directly set the inner window actually
    29702996      // resizes the outer width to that value instead. Must use resizeBy()
    29712997      // 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);
     2998      torbutton_resize_window(win);
    29762999
    29773000      // Resizing within this progress listener does not always work as overlays
    29783001      // of other extensions might still influence the height/width of the
     
    29893012              torbutton_log(3, "Mutation observer: Window dimensions are: " +
    29903013                win.innerWidth + " x " + win.innerHeight);
    29913014              setTimeout(function() {
    2992                            win.resizeBy(width - win.innerWidth,
    2993                              height - win.innerHeight);
     3015                           torbutton_resize_window(win);
    29943016                           torbutton_log(3, "Mutation observer: Window " +
    29953017                             "dimensions are (after resizing again): " + win.
    29963018                             innerWidth + " x " + win.innerHeight);