Bug 1710233 - Move statusbar code from menus.xul to chatzilla.xul. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sat, 08 May 2021 17:51:22 +0100
changeset 33038 78f673ce1edc1124ad546be9471404ec34d02253
parent 33037 25efd35b0559c61cec98bf2a1b24e358beccc4c5
child 33039 129487a78cca75d69c2a74a4b1579fe051e51223
push id18945
push userfrgrahl@gmx.net
push dateWed, 07 Jul 2021 14:17:49 +0000
treeherdercomm-central@98dea07858ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg
bugs1710233
Bug 1710233 - Move statusbar code from menus.xul to chatzilla.xul. r=frg
suite/chatzilla/xul/content/chatzilla.xul
suite/chatzilla/xul/content/handlers.js
suite/chatzilla/xul/content/menus.js
suite/chatzilla/xul/content/menus.xul
suite/chatzilla/xul/content/prefs.js
suite/chatzilla/xul/content/static.js
suite/chatzilla/xul/skin/chatzilla.css
--- a/suite/chatzilla/xul/content/chatzilla.xul
+++ b/suite/chatzilla/xul/content/chatzilla.xul
@@ -106,11 +106,36 @@
             onfocus="onInputFocus();" tabindex="-1"/>
         </box>
         <toolbarbutton id="button-multiline-expand" 
           oncommand="dispatch('pref multiline true');" 
           tooltiptext="&multiline-expand.tooltip;"/>
       </hbox>
     </hbox>
 
-  <overlaytarget id="statusbar-overlay-target"/>
+  <statusbar id="status-bar"
+             class="chromeclass-status"
+             persist="collapsed">
+    <statusbarpanel id="component-bar"/>
+    <statusbarpanel id="status-text" label="" flex="1" crop="right"/>
+    <statusbarpanel id="status-progress-panel" class="statusbarpanel-progress">
+      <progressmeter id="status-progress-bar"
+                     class="progressmeter-statusbar"
+                     mode="undetermined"
+                     value="0"/>
+    </statusbarpanel>
+    <statusbarpanel id="security-button"
+                    class="statusbarpanel-iconic-text"
+                    dir="reverse"
+                    label=""
+                    oncommand="displayCertificateInfo();"/>
+    <statusbarpanel id="alert-status"
+                    class="statusbarpanel-iconic"
+                    oncommand="updateAlertIcon(true);"/>
+    <statusbarpanel id="logging-status"
+                    class="statusbarpanel-iconic"
+                    oncommand="onLoggingIcon();"/>
+    <statusbarpanel id="offline-status"
+                    class="statusbarpanel-iconic"
+                    oncommand="client.offlineObserver.toggleOffline();"/>
+  </statusbar>
 
 </window>
--- a/suite/chatzilla/xul/content/handlers.js
+++ b/suite/chatzilla/xul/content/handlers.js
@@ -69,22 +69,16 @@ function onLoad()
 function initHandlers()
 {
     var node;
     node = document.getElementById("input");
     node.addEventListener("keypress", onInputKeyPress, false);
     node = document.getElementById("multiline-input");
     node.addEventListener("keypress", onMultilineInputKeyPress, false);
     node.active = false;
-    node = document.getElementById("security-button");
-    node.addEventListener("dblclick", onSecurityIconDblClick, false);
-    node = document.getElementById("logging-status");
-    node.addEventListener("click", onLoggingIconClick, false);
-    node = document.getElementById("alert-status");
-    node.addEventListener("click", onAlertIconClick, false);
 
     window.onkeypress = onWindowKeyPress;
 
     window.isFocused = false;
     window.addEventListener("focus", onWindowFocus, true);
     window.addEventListener("blur", onWindowBlue, true);
 
     client.inputPopup = null;
@@ -275,37 +269,16 @@ function onMouseOver (e)
         ++i;
         target = target.parentNode;
     }
 
     // Setting client.status to "" will revert it to the default automatically.
     client.status = status;
 }
 
-function onSecurityIconDblClick(e)
-{
-    if (e.button == 0)
-        displayCertificateInfo();
-}
-
-function onLoggingIconClick(e)
-{
-    if (e.button == 0)
-        client.currentObject.dispatch("log", { state: "toggle" });
-}
-
-function onAlertIconClick(e)
-{
-    if (e.button == 0)
-    {
-        client.prefs["alert.globalEnabled"] = !client.prefs["alert.globalEnabled"];
-        updateAlertIcon();
-    }
-}
-
 function onMultilineInputKeyPress (e)
 {
     if ((e.ctrlKey || e.metaKey) && e.keyCode == 13)
     {
         /* meta-enter, execute buffer */
         onMultilineSend(e);
     }
     else
--- a/suite/chatzilla/xul/content/menus.js
+++ b/suite/chatzilla/xul/content/menus.js
@@ -451,18 +451,16 @@ function initMenus()
     };
 
 }
 
 function createMenus()
 {
     client.menuManager.createMenus(document, "mainmenu");
     client.menuManager.createContextMenus(document);
-
-    document.getElementById("component-bar").collapsed = false;
 }
 
 function getCommandContext (id, event)
 {
     var cx = { originalEvent: event };
 
     if (id in client.menuSpecs)
     {
--- a/suite/chatzilla/xul/content/menus.xul
+++ b/suite/chatzilla/xul/content/menus.xul
@@ -88,30 +88,10 @@
              do about it. -->
         <menu id="menu_Help"/>
       </menubar>  
 
     </toolbox>  
 
   </overlaytarget>
 
-  <!-- Statusbar (hey, it's /almost/ a menu) -->
-  <overlaytarget id="statusbar-overlay-target">
-    <statusbar class="chromeclass-status" id="status-bar" 
-        persist="collapsed" flex="1">
-      <statusbarpanel id="component-bar" collapsed="true"/>
-      <statusbarpanel id="status-text" label="" flex="1" crop="right"/>
-      <statusbarpanel class="statusbarpanel-progress" id="status-progress-panel">
-        <progressmeter class="progressmeter-statusbar" id="status-progress-bar" 
-            mode="undetermined" value="0"/>
-      </statusbarpanel>
-      <statusbarpanel id="security-button">
-        <label id="security-button-label"/>
-        <image id="security-button-image"/>
-      </statusbarpanel>
-      <statusbarpanel class="statusbarpanel-iconic" id="alert-status"/>
-      <statusbarpanel class="statusbarpanel-iconic" id="logging-status"/>
-      <statusbarpanel class="statusbarpanel-iconic" id="offline-status"/>
-    </statusbar>
-  </overlaytarget>
-
 </overlay>
   
--- a/suite/chatzilla/xul/content/prefs.js
+++ b/suite/chatzilla/xul/content/prefs.js
@@ -801,17 +801,17 @@ function onPrefChanged(prefName, newValu
             client.dispatch("sync-timestamp");
             break;
 
         case "log":
             client.dispatch("sync-log");
             break;
 
         case "alert.globalEnabled":
-            updateAlertIcon();
+            updateAlertIcon(false);
             break;
 
         case "alert.floodDensity":
             if (client.alert && client.alert.floodProtector)
                 client.alert.floodProtector.floodDensity = newValue;
             break;
 
         case "alert.floodDispersion":
--- a/suite/chatzilla/xul/content/static.js
+++ b/suite/chatzilla/xul/content/static.js
@@ -171,17 +171,17 @@ function init()
     processStartupScripts();
 
     client.commandManager.installKeys(document);
     createMenus();
 
     client.busy = false;
     updateProgress();
     initOfflineIcon();
-    updateAlertIcon();
+    updateAlertIcon(false);
     client.isIdleAway = false;
     initIdleAutoAway(client.prefs["awayIdleTime"]);
 
     client.initialized = true;
 
     dispatch("help", { hello: true });
     dispatch("networks");
 
@@ -1925,60 +1925,63 @@ function updateProgress()
     if (progress >= 0)
         client.progressBar.value = progress;
 }
 
 function updateSecurityIcon()
 {
     var o = getObjectDetails(client.currentObject);
     var securityButton = window.document.getElementById("security-button");
-    securityButton.firstChild.value = "";
+    securityButton.label = "";
     securityButton.removeAttribute("level");
     securityButton.removeAttribute("tooltiptext");
     if (!o.server || !o.server.isConnected) // No server or connection?
     {
         securityButton.setAttribute("tooltiptext", MSG_SECURITY_INFO);
         return;
     }
 
+    let tooltiptext = MSG_SECURITY_INFO;
     switch (o.server.connection.getSecurityState()) {
         case STATE_IS_SECURE:
-            securityButton.firstChild.value = o.server.hostname;
             securityButton.setAttribute("level", "high");
 
-            // Add the tooltip:
+            // Update the tooltip.
             var issuer = o.server.connection.getCertificate().issuerOrganization;
-            var tooltiptext = getMsg(MSG_SECURE_CONNECTION, issuer);
-            securityButton.setAttribute("tooltiptext", tooltiptext);
-            securityButton.firstChild.setAttribute("tooltiptext", tooltiptext);
-            securityButton.lastChild.setAttribute("tooltiptext", tooltiptext);
+            tooltiptext = getMsg(MSG_SECURE_CONNECTION, issuer);
             break;
         case STATE_IS_BROKEN:
             securityButton.setAttribute("level", "broken");
-            // No break to make sure we get the correct tooltip
+            break;
         case STATE_IS_INSECURE:
         default:
-            securityButton.setAttribute("tooltiptext", MSG_SECURITY_INFO);
-    }
+            securityButton.setAttribute("level", "none");
+    }
+    securityButton.label = o.server.hostname;
+    securityButton.setAttribute("tooltiptext", tooltiptext);
 }
 
 function updateLoggingIcon()
 {
     var state = client.currentObject.prefs["log"] ? "on" : "off";
     var icon = window.document.getElementById("logging-status");
     icon.setAttribute("loggingstate", state);
     icon.setAttribute("tooltiptext", getMsg("msg.logging.icon." + state));
 }
 
-function updateAlertIcon()
-{
-    var state = client.prefs["alert.globalEnabled"] ? "on" : "off";
-    var icon = window.document.getElementById("alert-status");
-    icon.setAttribute("alertstate", state);
-    icon.setAttribute("tooltiptext", getMsg("msg.alert.icon." + state));
+function updateAlertIcon(aToggle) {
+  let alertState = client.prefs["alert.globalEnabled"];
+  if (aToggle) {
+    alertState = !alertState;
+    client.prefs["alert.globalEnabled"] = alertState;
+  }
+  let state = alertState ? "on" : "off";
+  let icon = window.document.getElementById("alert-status");
+  icon.setAttribute("alertstate", state);
+  icon.setAttribute("tooltiptext", getMsg("msg.alert.icon." + state));
 }
 
 function initOfflineIcon()
 {
     const PRBool_CID = "@mozilla.org/supports-PRBool;1";
     const OS_CID = "@mozilla.org/observer-service;1";
     const nsISupportsPRBool = Components.interfaces.nsISupportsPRBool;
 
@@ -2050,23 +2053,20 @@ function initOfflineIcon()
         os.addObserver(client.offlineObserver,
                        "network:offline-status-changed", false);
     }
     catch (ex)
     {
         dd("Exception when trying to register offline observers: " + ex);
     }
 
-    var elem = client.offlineObserver._element;
-    elem.setAttribute("onclick", "client.offlineObserver.toggleOffline()");
     client.offlineObserver.updateOfflineUI();
 
     // Don't leak:
     delete os;
-    delete elem;
 }
 
 function uninitOfflineIcon()
 {
     const OS_CID = "@mozilla.org/observer-service;1";
     try
     {
         var os = getService(OS_CID, "nsIObserverService");
@@ -2412,16 +2412,20 @@ function displayCertificateInfo()
     {
         alert(getMsg(MSG_INSECURE_SERVER, o.server.hostname));
         return;
     }
 
     viewCert(o.server.connection.getCertificate());
 }
 
+function onLoggingIcon() {
+  client.currentObject.dispatch("log", { state: "toggle" });
+}
+
 function newInlineText (data, className, tagName)
 {
     if (typeof tagName == "undefined")
         tagName = "html:span";
 
     var a = document.createElementNS(XHTML_NS, tagName);
     if (className)
         a.setAttribute ("class", className);
--- a/suite/chatzilla/xul/skin/chatzilla.css
+++ b/suite/chatzilla/xul/skin/chatzilla.css
@@ -326,33 +326,28 @@ progressmeter[mode="undetermined"] {
 #status-text[notice="true"] {
     font-weight: bold;
 }
 
 #security-button {
     min-width: 20px;
 }
 
-#security-button:not([level="high"]):not([level="broken"]) {
+#security-button:not([level="none"]):not([level="high"]):not([level="broken"]) {
     display: none;
 }
 
-#security-button[level="high"] > image {
+#security-button[level="high"] {
     list-style-image: url("chrome://chatzilla/skin/images/secure.png");
 }
 
-#security-button[level="broken"] > image {
+#security-button[level="broken"] {
     list-style-image: url("chrome://chatzilla/skin/images/secure-broken.png");
 }
 
-/* prevent margins of a value-less label from shifting the image */
-#security-button > label:not([value]) {
-    display: none;
-}
-
 #alert-status[alertstate="off"] {
     list-style-image: url("chrome://chatzilla/skin/images/spbubble-off.png");
 }
 
 #alert-status[alertstate="on"] {
     list-style-image: url("chrome://chatzilla/skin/images/spbubble-on.png");
 }