Bug 1475817 - Part 7: Convert simple <listbox> to <richlistbox>, sendoptions.xul/js. r=jorgk DONTBUILD
authorRichard Marti <richard.marti@gmail.com>
Tue, 17 Jul 2018 20:19:05 +0200
changeset 31769 2501e7eabc9f3e8d6272045175d34bc4aee59dd3
parent 31768 c038f663b745ad6488576daaa49119062d164b12
child 31770 d70436bc01deae26240f769ea22c7987901c77ca
push id2308
push userclokep@gmail.com
push dateWed, 05 Sep 2018 00:34:58 +0000
treeherdercomm-beta@e326b2dcd127 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1475817
Bug 1475817 - Part 7: Convert simple <listbox> to <richlistbox>, sendoptions.xul/js. r=jorgk DONTBUILD
mail/components/preferences/sendoptions.js
mail/components/preferences/sendoptions.xul
--- a/mail/components/preferences/sendoptions.js
+++ b/mail/components/preferences/sendoptions.js
@@ -26,22 +26,22 @@ var gSendOptionsDialog = {
   saveDomainPref: function(aHTML)
   {
     var listbox = aHTML ? this.mHTMLListBox : this.mPlainTextListBox;
     var num_domains = 0;
     var pref_string = "";
 
     for (var item = listbox.firstChild; item != null; item = item.nextSibling)
     {
-      var domainid = item.getAttribute('label');
+      var domainid = item.firstChild.getAttribute("value");
       if (domainid.length > 1)
       {
         num_domains++;
 
-        //separate >1 domains by commas
+        // Separate >1 domains by commas.
         if (num_domains > 1)
           pref_string = pref_string + "," + domainid;
         else
           pref_string = domainid;
       }
     }
 
     return pref_string;
@@ -56,22 +56,21 @@ var gSendOptionsDialog = {
         var str = arrayOfPrefs[i].replace(/ /g,"");
         if (str)
           this.addItemToDomainList(aListBox, str);
       }
   },
 
   removeDomains: function(aHTML)
   {
-    var listbox = aHTML ? this.mHTMLListBox : this.mPlainTextListBox;
+    let listbox = aHTML ? this.mHTMLListBox : this.mPlainTextListBox;
 
-    var currentIndex = listbox.currentIndex;
-
-    while (listbox.selectedItems.length > 0)
-      listbox.selectedItems[0].remove();
+    let selectedCount = listbox.selectedItems.length;
+    for (let i = selectedCount - 1; i >= 0; i--)
+      listbox.selectedItems[i].remove();
 
     document.getElementById('SendOptionsDialogPane').userChangedValue(listbox);
   },
 
   addDomain: function (aHTML)
   {
     var listbox = aHTML ? this.mHTMLListBox : this.mPlainTextListBox;
 
@@ -86,29 +85,31 @@ var gSendOptionsDialog = {
       this.addItemToDomainList(listbox, domainName);
       document.getElementById('SendOptionsDialogPane').userChangedValue(listbox);
     }
 
   },
 
   domainAlreadyPresent: function(aDomainName)
   {
-    let matchingDomains = this.mHTMLListBox.querySelectorAll('[label="' + aDomainName + '"]');
+    let matchingDomains = this.mHTMLListBox.querySelectorAll('[value="' + aDomainName + '"]');
 
     if (!matchingDomains.length)
-      matchingDomains = this.mPlainTextListBox.querySelectorAll('[label="' + aDomainName + '"]');
+      matchingDomains = this.mPlainTextListBox.querySelectorAll('[value="' + aDomainName + '"]');
 
     if (matchingDomains.length)
     {
       Services.prompt.alert(window, this.mPrefsBundle.getString('domainNameErrorTitle'),
                             this.mPrefsBundle.getFormattedString("domainDuplicationError", [aDomainName]));
     }
 
     return matchingDomains.length;
   },
 
   addItemToDomainList: function (aListBox, aDomainTitle)
   {
-    var item = document.createElement('listitem');
-    item.setAttribute('label', aDomainTitle);
+    let label = document.createElement("label");
+    label.setAttribute("value", aDomainTitle);
+    let item = document.createElement("richlistitem");
+    item.appendChild(label);
     aListBox.appendChild(item);
   }
 };
--- a/mail/components/preferences/sendoptions.xul
+++ b/mail/components/preferences/sendoptions.xul
@@ -67,37 +67,37 @@
       </tabs>
 
       <tabpanels id="sendOptionsTabsPanels" flex="1">
 
         <vbox index="HTML">
           <label control="html_domains" width="1">&domaindesc.label;</label>
 
           <hbox>
-            <listbox id="html_domains" flex="1" seltype="multiple" rows="5"
-                     class="uri-element"
-                     preference="mailnews.html_domains"
-                     onsynctopreference="return gSendOptionsDialog.saveDomainPref(true);"
-                     onkeypress="if (event.keyCode == KeyEvent.DOM_VK_BACK_SPACE || event.keyCode == KeyEvent.DOM_VK_DELETE) gSendOptionsDialog.removeDomains(true);"/>
+            <richlistbox id="html_domains" flex="1" seltype="multiple"
+                         class="uri-element" height="150"
+                         preference="mailnews.html_domains"
+                         onsynctopreference="return gSendOptionsDialog.saveDomainPref(true);"
+                         onkeypress="if (event.keyCode == KeyEvent.DOM_VK_BACK_SPACE || event.keyCode == KeyEvent.DOM_VK_DELETE) gSendOptionsDialog.removeDomains(true);"/>
             <vbox>
               <button label="&AddHtmlDomain.label;" oncommand="gSendOptionsDialog.addDomain(true);" accesskey="&AddHtmlDomain.accesskey;"/>
               <button label="&DeleteHtmlDomain.label;" oncommand="gSendOptionsDialog.removeDomains(true);" accesskey="&DeleteHtmlDomain.accesskey;"/>
             </vbox>
           </hbox>
         </vbox>
 
         <vbox index="plainText">
           <label control="plaintext_domains" width="1">&domaindesc.label;</label>
 
           <hbox>
-            <listbox id="plaintext_domains" flex="1" seltype="multiple" rows="5"
-                     class="uri-element"
-                     preference="mailnews.plaintext_domains"
-                     onsynctopreference="return gSendOptionsDialog.saveDomainPref(false);"
-                     onkeypress="if (event.keyCode == KeyEvent.DOM_VK_BACK_SPACE || event.keyCode == KeyEvent.DOM_VK_DELETE) gSendOptionsDialog.removeDomains(false);"/>
+            <richlistbox id="plaintext_domains" flex="1" seltype="multiple" rows="5"
+                         class="uri-element" height="150"
+                         preference="mailnews.plaintext_domains"
+                         onsynctopreference="return gSendOptionsDialog.saveDomainPref(false);"
+                         onkeypress="if (event.keyCode == KeyEvent.DOM_VK_BACK_SPACE || event.keyCode == KeyEvent.DOM_VK_DELETE) gSendOptionsDialog.removeDomains(false);"/>
             <vbox>
               <button label="&AddPlainText.label;" oncommand="gSendOptionsDialog.addDomain(false);" accesskey="&AddPlainText.accesskey;"/>
               <button label="&DeletePlainText.label;" oncommand="gSendOptionsDialog.removeDomains(false);" accesskey="&DeletePlainText.accesskey;"/>
             </vbox>
           </hbox>
         </vbox>
 
       </tabpanels>