Bug 1148330 - Font indicator doesn't update when cursor is placed in text where core returns sans-serif; r=iann, a=rkent
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Tue, 28 Apr 2015 07:05:00 +0200
changeset 26003 e0fa5f7f42889ca73cd704f56f4dffbb0e52d820
parent 26002 49615525b791c363d64e74e1e273296ff5638807
child 26004 b1b14a3738a04d2697830aeaf39105e979b76428
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersiann, rkent
bugs1148330
Bug 1148330 - Font indicator doesn't update when cursor is placed in text where core returns sans-serif; r=iann, a=rkent
editor/ui/composer/content/editor.js
suite/mailnews/compose/prefs/pref-composing_messages.js
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -675,24 +675,34 @@ function onParagraphFormatChange(paraMen
   }
 }
 
 function onFontFaceChange(fontFaceMenuList, commandID)
 {
   var commandNode = document.getElementById(commandID);
   var state = commandNode.getAttribute("state");
 
-  if (state == "mixed")
-  {
+  switch (state) {
+  case "mixed":
     //Selection is the "mixed" ( > 1 style) state
     fontFaceMenuList.selectedItem = null;
     fontFaceMenuList.setAttribute("label",GetString('Mixed'));
-  }
-  else
-  {
+    break;
+  case "":
+  case "serif":
+  case "sans-serif":
+    // Generic variable width.
+    fontFaceMenuList.selectedIndex = 0;
+    break;
+  case "tt":
+  case "monospace":
+    // Generic fixed width.
+    fontFaceMenuList.selectedIndex = 1;
+    break;
+  default:
     var menuPopup = document.getElementById("FontFacePopup");
     var menuItems = menuPopup.childNodes;
 
     // Bug 1139524: Normalise before we compare: Make it lower case
     // and replace ", " with "," so that entries like
     // "Helvetica, Arial, sans-serif" are always recognised correctly
     var stateToLower = state.toLowerCase().replace(/, /g, ",");
 
@@ -851,17 +861,21 @@ function initLocalFontFaceMenu(menuPopup
   var useRadioMenuitems = (menuPopup.parentNode.localName == "menu"); // don't do this for menulists  
   if (menuPopup.childNodes.length == kFixedFontFaceMenuItems) 
   {
     if (gLocalFonts.length == 0) {
       menuPopup.childNodes[kFixedFontFaceMenuItems - 1].hidden = true;
     }
     for (var i = 0; i < gLocalFonts.length; ++i)
     {
-      if (gLocalFonts[i] != "")
+      // Remove Linux system generic fonts that collide with CSS generic fonts.
+      if (gLocalFonts[i] != "" &&
+          gLocalFonts[i] != "serif" &&
+          gLocalFonts[i] != "sans-serif" &&
+          gLocalFonts[i] != "monospace")
       {
         var itemNode = document.createElementNS(XUL_NS, "menuitem");
         itemNode.setAttribute("label", gLocalFonts[i]);
         itemNode.setAttribute("value", gLocalFonts[i]);
         if (useRadioMenuitems) {
           itemNode.setAttribute("type", "radio");
           itemNode.setAttribute("name", "2");
           itemNode.setAttribute("observes", "cmd_renderedHTMLEnabler");
--- a/suite/mailnews/compose/prefs/pref-composing_messages.js
+++ b/suite/mailnews/compose/prefs/pref-composing_messages.js
@@ -15,15 +15,16 @@ function EnableMailComposeAutosaveInterv
 function PopulateFonts() {
   var fontsList = document.getElementById("fontSelect");
   try {
     var enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
                                .getService(Components.interfaces.nsIFontEnumerator);
     var localFontCount = { value: 0 }
     var localFonts = enumerator.EnumerateAllFonts(localFontCount);
     for (let font of localFonts)
-      fontsList.appendItem(font, font);
+      if (font != "serif" && font != "sans-serif" && font != "monospace")
+        fontsList.appendItem(font, font);
   } catch (ex) { }
 
   // Select the item after the list is completely generated.
   document.getElementById(fontsList.getAttribute("preference"))
           .setElementValue(fontsList);
 }