commit 488b7569d78e80a13839eb768c367b862be72480 Author: Mike Perry mikeperry-git@fscked.org Date: Wed Jun 29 17:50:34 2011 -0700
Bug #1282: Set fixed window size for each new window.
Rather than one fixed size, we try to bin the resolution into just a few possibilities, choosing the largest bin possible for a given desktop resolution. We also cap the width at 1000. --- src/chrome/content/torbutton.js | 85 ++++++++++++++++++------------- src/defaults/preferences/preferences.js | 1 + 2 files changed, 50 insertions(+), 36 deletions(-)
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js index 8621e7a..e620fec 100644 --- a/src/chrome/content/torbutton.js +++ b/src/chrome/content/torbutton.js @@ -3622,42 +3622,17 @@ function torbutton_check_round(browser) if(torbutton_is_windowed(window) && m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled") && m_tb_prefs.getBoolPref("extensions.torbutton.resize_on_toggle")) { - - /* - if(Math.abs(browser.contentWindow.innerHeight - - Math.floor(Math.round(browser.contentWindow.innerHeight/50.0)*50)) - > 0.1) { - if(m_tb_window_height < 100 && m_tb_window_width < 100) { - torbutton_log(3, "Window size damn near zero: ("+ - m_tb_window_height+", "+m_tb_window_width+")"); - m_tb_window_height = window.outerHeight; - m_tb_window_width = window.outerWidth; - } else { - torbutton_log(3, "Restoring orig window size: "+window.windowState); - window.outerHeight = m_tb_window_height; - window.outerWidth = m_tb_window_width; - } - } - */ - - // Always round. - torbutton_log(3, "Resizing window on load: "+window.windowState); var bWin = browser.contentWindow; - /* - * Instead of direct adjustment, we must update the outer window - * size, because firefox is sloppy about repositioning widgets - * properly after inner size changes. - bWin.innerHeight = Math.round(bWin.innerHeight/50.0)*50; - bWin.innerWidth = Math.round(bWin.innerWidth/50.0)*50; - */ + torbutton_log(2, "About to resize load window: "+bWin.innerWidth+"x"+bWin.innerHeight+" in state "+window.windowState);
- var hDelta = Math.round(bWin.innerHeight/50.0)*50 - bWin.innerHeight; - var wDelta = Math.round(bWin.innerWidth/50.0)*50 - bWin.innerWidth; + var height = Math.round(bWin.innerHeight/50.0)*50; + var width = Math.round(bWin.innerWidth/50.0)*50;
- window.resizeBy(wDelta,hDelta); - torbutton_log(2, "Resized window: ("+window.outerHeight+","+window.outerWidth+") ?= (" - +bWin.innerHeight+","+bWin.innerWidth+")"); - //+bWin.screen.availHeight+","+bWin.screen.availWidth+")"); + // This is fun. any attempt to resize the inner window actually resizes the outer width first. + // This hack seems to do the trick: + bWin.resizeTo(width,height); + bWin.resizeBy(width-bWin.innerWidth,height-bWin.innerHeight); + torbutton_log(3, "Resized window on load to: "+bWin.innerWidth+"x"+bWin.innerHeight+" in state "+window.windowState);
m_tb_window_height = window.outerHeight; m_tb_window_width = window.outerWidth; @@ -3665,6 +3640,43 @@ function torbutton_check_round(browser) } }
+function torbutton_set_window_size(bWin) { + if (!bWin || typeof(bWin) == "undefined") { + torbutton_log(5, "No initial browser content window?"); + return; + } + + if (m_tb_prefs.getBoolPref("extensions.torbutton.resize_new_windows") + && m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled") + && torbutton_is_windowed(window)) { + // We need to set the inner width to an initial value because it has none + // at this point... + bWin.innerWidth = 200; + bWin.innerHeight = 200; + torbutton_log(2, "About to resize new window: "+window.outerWidth+"x"+window.outerHeight+" in state "+window.windowState); + + var maxHeight = window.screen.availHeight - (window.outerHeight - bWin.innerHeight) - 1; + var maxWidth = window.screen.availWidth - (window.outerWidth - bWin.innerWidth) -1; + + var width; + var height; + + if (maxWidth > 1000) { + width = 1000; + } else { + width = Math.floor(maxWidth/200.0)*200; + } + + height = Math.floor(maxHeight/100.0)*100; + + // This is fun. any attempt to resize the inner window actually resizes the outer width first. + // This hack seems to do the trick: + bWin.resizeTo(width,height); + bWin.resizeBy(width-bWin.innerWidth,height-bWin.innerHeight); + torbutton_log(3, "Resized new window from: "+bWin.innerWidth+"x"+bWin.innerHeight+" to "+width+"x"+height+" in state "+window.windowState); + } +} + function torbutton_new_window(event) { torbutton_log(3, "New window"); @@ -3675,15 +3687,14 @@ function torbutton_new_window(event) return; }
- // Add tab open listener.. - browser.tabContainer.addEventListener("TabOpen", torbutton_new_tab, false); - m_tb_window_height = window.outerHeight; m_tb_window_width = window.outerWidth;
if (!m_tb_wasinited) { torbutton_init(); } + // Add tab open listener.. + browser.tabContainer.addEventListener("TabOpen", torbutton_new_tab, false);
torbutton_do_startup(); torbutton_crash_recover(); @@ -3695,6 +3706,8 @@ function torbutton_new_window(event) !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled"), m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins"));
+ torbutton_set_window_size(browser.contentWindow); + //window.addEventListener("resize", torbutton_do_resize, true); }
diff --git a/src/defaults/preferences/preferences.js b/src/defaults/preferences/preferences.js index 6c874b6..9a406f5 100644 --- a/src/defaults/preferences/preferences.js +++ b/src/defaults/preferences/preferences.js @@ -149,6 +149,7 @@ pref("extensions.torbutton.close_tor",false); pref("extensions.torbutton.close_nontor",false); pref("extensions.torbutton.block_js_history",true); pref("extensions.torbutton.resize_on_toggle",true); +pref("extensions.torbutton.resize_new_windows",true); pref("extensions.torbutton.banned_ports","8118,8123,9050,9051"); pref("extensions.torbutton.block_tor_file_net",true); pref("extensions.torbutton.block_nontor_file_net",false);