Bug 1267069 - Strip quotes in font names. r=aceman,IanN
authorJorg K
Sun, 24 Apr 2016 20:49:16 +0200
changeset 24850 0dc66f3da4481e5f4c8c37de1179f1155991ce47
parent 24849 d0f24d25360654b65343ed6feffebae05d3e0d9e
child 24851 878afe4c65b75a96fddc1593418210d0337ccc31
push id1657
push userclokep@gmail.com
push dateMon, 06 Jun 2016 19:50:21 +0000
treeherdercomm-beta@9fac989284b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman, IanN
bugs1267069
Bug 1267069 - Strip quotes in font names. r=aceman,IanN
editor/ui/composer/content/editor.js
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -662,16 +662,22 @@ function onParagraphFormatChange(paraMen
  * @param commandID         The commandID which holds the current font name
  *                          in its "state" attribute.
  */
 function onFontFaceChange(fontFaceMenuList, commandID)
 {
   var commandNode = document.getElementById(commandID);
   var editorFont = commandNode.getAttribute("state");
 
+  // Strip quotes in font names. Experiments have shown that we only
+  // ever get double quotes around the font name, never single quotes,
+  // even if they were in the HTML source. Also single or double
+  // quotes within the font name are never returned.
+  editorFont = editorFont.replace(/"/g, "");
+
   switch (editorFont) {
   case "mixed":
     // Selection is the "mixed" ( > 1 style) state.
     fontFaceMenuList.selectedItem = null;
     fontFaceMenuList.setAttribute("label",GetString('Mixed'));
     return;
   case "":
   case "serif":
@@ -712,17 +718,17 @@ function onFontFaceChange(fontFaceMenuLi
   // 6: Separator, "menuseparator.fontFaceMenuAfterDefaultFonts"
   // from 7: Used Font Section (for quick selection)
   // followed by separator, "menuseparator.fontFaceMenuAfterUsedFonts"
   // followed by all other available fonts.
   // The following variable keeps track of where we are when we loop over the menu.
   let afterUsedFontSection = false;
 
   // The menu items not only have "label" and "value", but also some other attributes:
-  // "value_parsed": Is the toLowerCase() and space stripped value.
+  // "value_parsed": Is the toLowerCase() and space-stripped value.
   // "value_cache":  Is a concatenation of all editor fonts that were ever mapped
   //                 onto this menu item. This is done for optimization.
   // "used":         This item is in the used font section.
 
   for (let i = 0; i < menuItems.length; i++)
   {
     let menuItem = menuItems.item(i);
     if (menuItem.hasAttribute("label") && menuItem.hasAttribute("value_parsed"))
@@ -929,16 +935,23 @@ function initFontFaceMenu(menuPopup)
 
   if (menuPopup)
   {
     var children = menuPopup.childNodes;
     if (!children) return;
 
     var mixed = { value: false };
     var editorFont = GetCurrentEditor().getFontFaceState(mixed);
+
+    // Strip quotes in font names. Experiments have shown that we only
+    // ever get double quotes around the font name, never single quotes,
+    // even if they were in the HTML source. Also single or double
+    // quotes within the font name are never returned.
+    editorFont = editorFont.replace(/"/g, "");
+
     if (!mixed.value)
     {
       switch (editorFont)
       {
       case "":
       case "serif":
       case "sans-serif":
         // Generic variable width.