Ticket #9268: tb.diff.txt

File tb.diff.txt, 4.6 KB (added by cypherpunks, 6 years ago)

Compute inner size properly with taskabars, different DPI or something else

Line 
1--- torbutton.js
2+++ torbutton.js.modified
3@@ -2869,6 +2869,39 @@
4   { /*torbutton_eclog(1, 'called linkIcon'); */ return 0; }
5 }
6 
7+/* Call it to resize window. Later is better, then it counts
8+   all appeared bars to proper round inner sizes */
9+function torbutton_resize_window(win) {
10+      var diff_height = window.outerHeight - win.innerHeight;
11+      var diff_width = window.outerWidth - win.innerWidth;
12+
13+      /* Re: f2b3ddc18d
14+         window.screen not lies about sizes,
15+         it returns maximum outer size available.
16+         We no need screen resolution for desktop here,
17+         which can't to count DPI settings, taskbar or something else  */
18+      var maxHeight = window.screen.availHeight - diff_height;
19+      var maxWidth = window.screen.availWidth - diff_width;
20+
21+      var width;
22+      var height;
23+      torbutton_log(3, "About to resize new window: " + window.outerWidth +
24+        "x" + window.outerHeight + " inner: " + win.innerWidth + "x" + win.
25+        innerHeight + " in state " + window.windowState + " Have " +
26+        screen.availWidth + "x" + screen.availHeight);
27+
28+      torbutton_log(3, "Got max dimensions: " + maxWidth + "x" + maxHeight);
29+
30+
31+      if (maxWidth > 1000) {
32+        width = 1000;
33+      } else {
34+        width = Math.floor(maxWidth/200.0)*200;
35+      }
36+
37+      height = Math.floor(maxHeight/100.0)*100;
38+      win.resizeBy(width - win.innerWidth, height - win.innerHeight);
39+}
40 // Bug 1506 P1/P3: Setting a fixed window size is important, but
41 // probably not for android.
42 var torbutton_resizelistener =
43@@ -2894,10 +2927,6 @@
44         progress.removeProgressListener(this);
45         return;
46       }
47-      var screenMan = Components.classes["@mozilla.org/gfx/screenmanager;1"].
48-        getService(Components.interfaces.nsIScreenManager);
49-      var junk = {}, availWidth = {}, availHeight = {};
50-      screenMan.primaryScreen.GetRect(junk, junk, availWidth, availHeight);
51 
52       // We need to set the inner width to an initial value because it has none
53       // at this point... Choosing "300" as this works even on Windows
54@@ -2905,32 +2934,12 @@
55       win.innerWidth = 300;
56       win.innerHeight = 300;
57 
58-      torbutton_log(3, "About to resize new window: " + window.outerWidth +
59-        "x" + window.outerHeight + " inner: " + win.innerWidth + "x" + win.
60-        innerHeight + " in state " + window.windowState + " Have " +
61-        availWidth.value + "x" + availHeight.value);
62-
63-      var maxHeight = availHeight.value -
64-        (window.outerHeight - win.innerHeight) - 51;
65-      var maxWidth = availWidth.value - (window.outerWidth - win.innerWidth);
66-      torbutton_log(3, "Got max dimensions: " + maxWidth + "x" + maxHeight);
67-
68-      var width;
69-      var height;
70-
71-      if (maxWidth > 1000) {
72-        width = 1000;
73-      } else {
74-        width = Math.floor(maxWidth/200.0)*200;
75-      }
76-
77-      height = Math.floor(maxHeight/100.0)*100;
78 
79       var handler = function() {
80         if (window.windowState === 1) {
81           window.addEventListener("resize",
82             function() {
83-              win.resizeBy(width - win.innerWidth, height - win.innerHeight);
84+              torbutton_resize_window(win);
85               var calling_function = arguments.callee;
86               setTimeout(function() {
87                            torbutton_log(3, "Removing resize listener..");
88@@ -2969,10 +2978,7 @@
89       // This is fun. any attempt to directly set the inner window actually
90       // resizes the outer width to that value instead. Must use resizeBy()
91       // instead of assignment or resizeTo()
92-      win.resizeBy(width - win.innerWidth, height - win.innerHeight);
93-      torbutton_log(3, "Resized new window from: " + win.innerWidth + "x" +
94-        win.innerHeight + " to " + width + "x" + height + " in state " +
95-        window.windowState);
96+      torbutton_resize_window(win);
97 
98       // Resizing within this progress listener does not always work as overlays
99       // of other extensions might still influence the height/width of the
100@@ -2989,8 +2995,7 @@
101               torbutton_log(3, "Mutation observer: Window dimensions are: " +
102                 win.innerWidth + " x " + win.innerHeight);
103               setTimeout(function() {
104-                           win.resizeBy(width - win.innerWidth,
105-                             height - win.innerHeight);
106+                           torbutton_resize_window(win);
107                            torbutton_log(3, "Mutation observer: Window " +
108                              "dimensions are (after resizing again): " + win.
109                              innerWidth + " x " + win.innerHeight);