[tbb-commits] [torbutton/master] fixup! Bug 22542: Security Settings window too small on macOS 10.12

gk at torproject.org gk at torproject.org
Tue Aug 1 09:33:27 UTC 2017


commit 8fbc96cab7ed9816da68d070b7cb01548a19a25a
Author: Kathy Brade <brade at pearlcrescent.com>
Date:   Wed Jul 12 13:52:28 2017 -0400

    fixup! Bug 22542: Security Settings window too small on macOS 10.12
    
    Automatically adjust the height of the Security Settings window so that
    no scrollbar is needed. Also, add 100 pixels to the width and increase
    maxheight and maxwidth to give users more flexibility when they choose to
    manually resize the window.
---
 src/chrome/content/preferences.js  | 46 ++++++++++++++++++++++++++++++++++----
 src/chrome/content/preferences.xul | 10 ++++-----
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index 1e47cad..a76dddb 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -42,10 +42,7 @@ function torbutton_init_security_ui() {
     getIntPref("extensions.torbutton.security_slider")));
   torbutton_set_custom(getBoolPref("extensions.torbutton.security_custom"));
 
-  // Show a scrollbar for the description text if one is needed.
-  // To avoid bug 21330, we set the overflow=auto style here instead
-  // of directly in the XUL.
-  document.getElementById("descBox").style.overflow = "auto";
+  setTimeout(adjustDialogSize, 0);
 };
 
 // Write the two prefs from the current settings.
@@ -54,3 +51,44 @@ function torbutton_save_security_settings() {
              sliderPositionToPrefSetting(state.slider));
   setBoolPref("extensions.torbutton.security_custom", state.custom);
 };
+
+// Increase the height of this window so that a vertical scrollbar is not
+// needed on the description box.
+function adjustDialogSize() {
+  try {
+    // Find the height required by the tallest description element.
+    let descHeight = 0;
+    let descs = descNames.map(name => document.getElementById(name));
+    descs.forEach(elem => {
+      let origCollapsed = elem.collapsed;
+      elem.collapsed = false;
+      let h = elem.scrollHeight;
+      elem.collapsed = origCollapsed;
+      if (h > descHeight)
+        descHeight = h;
+    });
+
+    // Cap the height (just in case).
+    const kMaxDescriptionHeight = 550;
+    if (descHeight > kMaxDescriptionHeight)
+      descHeight = kMaxDescriptionHeight;
+
+    // Increase the height of the description container if it is too short.
+    let boxElem = document.getElementById("descBox");
+    if (boxElem.clientHeight < descHeight) {
+      boxElem.setAttribute("height", descHeight);
+
+      // Resize the XUL window to account for the new description height. In
+      // order for sizeToContent() to work correctly, it seems that we must
+      // remove the height attribute from the dialog (that attribute is added
+      // after a user manually resizes the window).
+      document.documentElement.removeAttribute("height");
+      sizeToContent();
+    }
+  } catch (e) {}
+
+  // Show a scrollbar for the description text if one is needed.
+  // To avoid bug 21330, we set the overflow=auto style here instead
+  // of directly in the XUL.
+  document.getElementById("descBox").style.overflow = "auto";
+}
diff --git a/src/chrome/content/preferences.xul b/src/chrome/content/preferences.xul
index 9bd8ae3..9ebc5d6 100644
--- a/src/chrome/content/preferences.xul
+++ b/src/chrome/content/preferences.xul
@@ -13,11 +13,11 @@
         onload="torbutton_init_security_ui()"
         align="stretch"
         pack="center"
-        maxheight="350"
+        maxheight="600"
         minwidth="400"
-        maxwidth="600"
+        maxwidth="800"
         ondialogaccept="torbutton_save_security_settings()"
-        width="400" >
+        width="500" >
 
     <script type="application/x-javascript" src="torbutton_util.js"/>
     <script type="application/x-javascript" src="preferences.js"/>
@@ -26,7 +26,7 @@
           <caption label="&torbutton.prefs.sec_caption;"/>
           <hbox id="torbutton_slider_settings" flex="1" align="stretch" hidden="false">
             <vbox>
-              <hbox height="220">
+              <hbox flex="1" minheight="220">
                 <vbox>
                   <scale id="torbutton_sec_slider" flex="1" min="1" max="3"
                          movetoclick="true" orient="vertical"
@@ -57,7 +57,7 @@
                 </vbox>
               </hbox>
             </vbox>
-            <vbox id="descBox" flex="1" width="400" style="overflow: hidden;">
+            <vbox id="descBox" flex="1" style="overflow: hidden;">
               <vbox id="desc_high" collapsed="true">
                 <description
                   class="slider-text-size, slider-text-weight">



More information about the tbb-commits mailing list