Bug 1658648 - Use Unicode instead of images for chat emoticons. r=khushil DONTBUILD
authorPatrick Cloke <clokep@gmail.com>
Fri, 14 Aug 2020 12:15:23 +0300
changeset 30365 bba92cc7febf01687f694dda5c4a3f9a9c87fb18
parent 30364 b77dd3965f8c8cb4009c7e08b9888d612d0c1b10
child 30366 6f4962ef80edecc2f822724d98b498a9b20b9ae7
push id17843
push usermkmelin@iki.fi
push dateFri, 14 Aug 2020 09:16:07 +0000
treeherdercomm-central@bba92cc7febf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhushil
bugs1658648
Bug 1658648 - Use Unicode instead of images for chat emoticons. r=khushil DONTBUILD
chat/components/src/components.conf
chat/components/src/moz.build
chat/components/src/smileProtocolHandler.jsm
chat/modules/imSmileys.jsm
chat/themes/conv.css
mail/components/im/jar.mn
mail/components/im/smileys/angry.png
mail/components/im/smileys/confused.png
mail/components/im/smileys/cool.png
mail/components/im/smileys/cry.png
mail/components/im/smileys/embarrassed.png
mail/components/im/smileys/grin.png
mail/components/im/smileys/heart.png
mail/components/im/smileys/manga_annoyed.png
mail/components/im/smileys/manga_embarrassed.png
mail/components/im/smileys/manga_smile.png
mail/components/im/smileys/manga_stunned.png
mail/components/im/smileys/manga_tired.png
mail/components/im/smileys/sad.png
mail/components/im/smileys/shocked.png
mail/components/im/smileys/slant.png
mail/components/im/smileys/slant2.png
mail/components/im/smileys/smile.png
mail/components/im/smileys/sp_laugh.png
mail/components/im/smileys/straight_face.png
mail/components/im/smileys/theme.json
mail/components/im/smileys/tongue.png
mail/components/im/smileys/wink.png
--- a/chat/components/src/components.conf
+++ b/chat/components/src/components.conf
@@ -43,15 +43,9 @@ Classes = [
   },
   {
     'cid': '{fb0dc220-2c7a-4216-9f19-6b8f3480eae9}',
     'contract_ids': ['@mozilla.org/chat/logger;1'],
     'jsm': 'resource:///modules/logger.jsm',
     'constructor': 'Logger',
     'categories': {'profile-after-change': 'Logger'},
   },
-  {
-    'cid': '{04e58eae-dfbc-4c9e-8130-6d9ef19cbff4}',
-    'contract_ids': ['@mozilla.org/network/protocol;1?name=smile'],
-    'jsm': 'resource:///modules/smileProtocolHandler.jsm',
-    'constructor': 'smileProtocolHandler',
-  },
 ]
--- a/chat/components/src/moz.build
+++ b/chat/components/src/moz.build
@@ -7,14 +7,13 @@ XPCSHELL_TESTS_MANIFESTS += ['test/xpcsh
 
 EXTRA_JS_MODULES += [
     'imAccounts.jsm',
     'imCommands.jsm',
     'imContacts.jsm',
     'imConversations.jsm',
     'imCore.jsm',
     'logger.jsm',
-    'smileProtocolHandler.jsm'
 ]
 
 XPCOM_MANIFESTS += [
     'components.conf',
 ]
deleted file mode 100644
--- a/chat/components/src/smileProtocolHandler.jsm
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-var EXPORTED_SYMBOLS = ["smileProtocolHandler"];
-
-var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
-var { getSmileRealURI } = ChromeUtils.import(
-  "resource:///modules/imSmileys.jsm"
-);
-
-var kSmileRegexp = /^smile:\/\//;
-
-function smileProtocolHandler() {}
-
-smileProtocolHandler.prototype = {
-  scheme: "smile",
-  defaultPort: -1,
-  protocolFlags:
-    Ci.nsIProtocolHandler.URI_NORELATIVE |
-    Ci.nsIProtocolHandler.URI_NOAUTH |
-    Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE |
-    Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE,
-  newChannel(aURI, aLoadInfo) {
-    let smile = aURI.spec.replace(kSmileRegexp, "");
-    let uri = Services.io.newURI(getSmileRealURI(smile));
-    let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
-    channel.originalURI = aURI;
-    return channel;
-  },
-  allowPort(aPort, aScheme) {
-    return false;
-  },
-
-  QueryInterface: ChromeUtils.generateQI(["nsIProtocolHandler"]),
-  classDescription: "Smile Protocol Handler",
-};
--- a/chat/modules/imSmileys.jsm
+++ b/chat/modules/imSmileys.jsm
@@ -13,21 +13,17 @@ XPCOMUtils.defineLazyGetter(this, "gText
 
 ChromeUtils.defineModuleGetter(
   this,
   "NetUtil",
   "resource://gre/modules/NetUtil.jsm"
 );
 
 const EXPORTED_SYMBOLS = [
-  "smileImMarkup", // used to add smile:// img tags into IM markup.
-  "smileTextNode", // used to add smile:// img tags to the content of a textnode
-  "smileString", // used to add smile:// img tags into a string without parsing it as HTML. Be sure the string doesn't contain HTML tags.
-  "getSmileRealURI", // used to retrieve the chrome URI for a smile:// URI
-  "getSmileyList", // used to display a list of smileys in the UI
+  "smileTextNode", // used to add smileys to the content of a textnode
 ];
 
 var kEmoticonsThemePref = "messenger.options.emoticonsTheme";
 var kThemeFile = "theme.json";
 
 Object.defineProperty(this, "gTheme", {
   configurable: true,
   enumerable: true,
@@ -48,41 +44,16 @@ var gPrefObserver = {
     if (aTopic != "nsPref:changed" || aMsg != kEmoticonsThemePref) {
       throw new Error("bad notification");
     }
 
     gTheme = getTheme();
   },
 };
 
-function getSmileRealURI(aSmile) {
-  aSmile = Services.textToSubURI.unEscapeURIForUI(aSmile);
-  if (aSmile in gTheme.iconsHash) {
-    return gTheme.baseUri + gTheme.iconsHash[aSmile].filename;
-  }
-
-  throw new Error("Invalid smile!");
-}
-
-function getSmileyList(aThemeName) {
-  let theme = aThemeName == gTheme.name ? gTheme : getTheme(aThemeName);
-  if (!theme.json) {
-    return null;
-  }
-
-  let addAbsoluteUrls = function(aSmiley) {
-    return {
-      filename: aSmiley.filename,
-      src: theme.baseUri + aSmiley.filename,
-      textCodes: aSmiley.textCodes,
-    };
-  };
-  return theme.json.smileys.map(addAbsoluteUrls);
-}
-
 function getTheme(aName) {
   let name = aName || Services.prefs.getCharPref(kEmoticonsThemePref);
 
   let theme = {
     name,
     iconsHash: null,
     json: null,
     regExp: null,
@@ -159,25 +130,16 @@ function getRegexp() {
     gTheme.iconsHash = null;
     return null;
   }
 
   gTheme.regExp = new RegExp(emoticonList.join("|"), "g");
   return gTheme.regExp;
 }
 
-// unused. May be useful later to process a string instead of an HTML node
-function smileString(aString) {
-  const kSmileFormat =
-    '<img class="ib-img-smile" src="smile://$&" alt="$&" title="$&"/>';
-
-  let exp = getRegexp();
-  return exp ? aString.replace(exp, kSmileFormat) : aString;
-}
-
 function smileTextNode(aNode) {
   /*
    * Skip text nodes that contain the href in the child text node.
    * We must check both the testNode.textContent and the aNode.data since they
    * cover different cases:
    *   textContent: The URL is split over multiple nodes for some reason
    *   data: The URL is not the only content in the link, skip only the one node
    * Check the class name to skip any autolinked nodes from mozTXTToHTMLConv.
@@ -203,55 +165,21 @@ function smileTextNode(aNode) {
   let match;
   while ((match = exp.exec(aNode.data))) {
     let smileNode = aNode.splitText(match.index);
     aNode = smileNode.splitText(exp.lastIndex - match.index);
     // at this point, smileNode is a text node with only the text
     // of the smiley and aNode is a text node with the text after
     // the smiley. The text in aNode hasn't been processed yet.
     let smile = smileNode.data;
-    let elt = aNode.ownerDocument.createElement("img");
-    elt.setAttribute("src", "smile://" + smile);
+    let elt = aNode.ownerDocument.createElement("span");
+    elt.appendChild(
+      aNode.ownerDocument.createTextNode(gTheme.iconsHash[smile].glyph)
+    );
+    // Add the title attribute (to show the original text in a tooltip) in case
+    // the replacement was done incorrectly.
     elt.setAttribute("title", smile);
-    elt.setAttribute("alt", smile);
-    elt.setAttribute("class", "ib-img-smile");
     smileNode.parentNode.replaceChild(elt, smileNode);
     result += 2;
     exp.lastIndex = 0;
   }
   return result;
 }
-
-function smileNode(aNode) {
-  for (let i = 0; i < aNode.childNodes.length; ++i) {
-    let node = aNode.childNodes[i];
-    if (
-      node.nodeType == node.ELEMENT_NODE &&
-      node.namespaceURI == "http://www.w3.org/1999/xhtml"
-    ) {
-      // we are on a tag, recurse to process its children
-      smileNode(node);
-    } else if (
-      node.nodeType == node.TEXT_NODE ||
-      node.nodeType == node.CDATA_SECTION_NODE
-    ) {
-      // we are on a text node, process it
-      smileTextNode(node);
-    }
-  }
-}
-
-function smileImMarkup(aDocument, aText) {
-  if (!aDocument) {
-    throw new Error("providing an HTML document is required");
-  }
-
-  // return early if smileys are disabled
-  if (!gTheme.iconsHash) {
-    return aText;
-  }
-
-  let div = aDocument.createElement("div");
-  // eslint-disable-next-line no-unsanitized/property
-  div.innerHTML = aText;
-  smileNode(div);
-  return div.innerHTML;
-}
--- a/chat/themes/conv.css
+++ b/chat/themes/conv.css
@@ -2,26 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 .ib-msg-txt {
   white-space: pre-wrap;
   word-wrap: break-word;
 }
 
-.ib-img-smile {
-  vertical-align: middle;
-}
-
-*:any-link .ib-img-smile {
-  border: none;
-  border-bottom: solid 1px;
-  margin-bottom: 1px;
-}
-
 .moz-txt-underscore {
   text-decoration: underline;
 }
 
 /* disable overflow in themes until bug 42676 is fixed in Mozilla */
 #Chat {
   overflow: hidden !important;
 }
--- a/mail/components/im/jar.mn
+++ b/mail/components/im/jar.mn
@@ -184,29 +184,8 @@ messenger.jar:
 	skin/classic/messenger/messages/simple/Incoming/NextContext.html (messages/simple/Incoming/NextContext.html)
 	skin/classic/messenger/messages/simple/Info.plist            (messages/simple/Info.plist)
 	skin/classic/messenger/messages/simple/main.css              (messages/simple/main.css)
 	skin/classic/messenger/messages/simple/Status.html           (messages/simple/Status.html)
 	skin/classic/messenger/messages/simple/Variants/Normal.css   (messages/simple/Variants/Normal.css)
 	skin/classic/messenger/messages/simple/Variants/Dark.css     (messages/simple/Variants/Dark.css)
 % skin messenger-emoticons classic/1.0 %skin/classic/messenger/smileys/
 	skin/classic/messenger/smileys/theme.json            (smileys/theme.json)
-	skin/classic/messenger/smileys/angry.png             (smileys/angry.png)
-	skin/classic/messenger/smileys/confused.png          (smileys/confused.png)
-	skin/classic/messenger/smileys/cool.png              (smileys/cool.png)
-	skin/classic/messenger/smileys/cry.png               (smileys/cry.png)
-	skin/classic/messenger/smileys/embarrassed.png       (smileys/embarrassed.png)
-	skin/classic/messenger/smileys/grin.png              (smileys/grin.png)
-	skin/classic/messenger/smileys/heart.png             (smileys/heart.png)
-	skin/classic/messenger/smileys/manga_annoyed.png     (smileys/manga_annoyed.png)
-	skin/classic/messenger/smileys/manga_embarrassed.png (smileys/manga_embarrassed.png)
-	skin/classic/messenger/smileys/manga_smile.png       (smileys/manga_smile.png)
-	skin/classic/messenger/smileys/manga_stunned.png     (smileys/manga_stunned.png)
-	skin/classic/messenger/smileys/manga_tired.png       (smileys/manga_tired.png)
-	skin/classic/messenger/smileys/sad.png               (smileys/sad.png)
-	skin/classic/messenger/smileys/shocked.png           (smileys/shocked.png)
-	skin/classic/messenger/smileys/slant.png             (smileys/slant.png)
-	skin/classic/messenger/smileys/slant2.png            (smileys/slant2.png)
-	skin/classic/messenger/smileys/smile.png             (smileys/smile.png)
-	skin/classic/messenger/smileys/sp_laugh.png          (smileys/sp_laugh.png)
-	skin/classic/messenger/smileys/straight_face.png     (smileys/straight_face.png)
-	skin/classic/messenger/smileys/tongue.png            (smileys/tongue.png)
-	skin/classic/messenger/smileys/wink.png              (smileys/wink.png)
deleted file mode 100644
index 14ea2967f031b5871c516fbb9491ab2ba247f786..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 46cb432cd74541585dcb6a7a6158102139f109ef..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index cf0096f553ef97a6ddf0e57dbfda458f832097e5..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 9ebf7d8988ba0df51b9859d15ee1ffe8d236bc37..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index d80fc10827e5cbcae4c195e26caaf236a8c0670d..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index b0d4196537da459df1ff0176d832f92fdc0b8b5f..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index a7e1bd066dc56b8394bd3377bcc0f622c56c8028..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index e7072732a52396dd3b73b5bb4a0a8e54f110db26..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index f375aefa737eb75545983547b5a9406834d5d7d3..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index c20601bbe2f51f977dac330f09c9afe53320e6f4..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 9903039dfdcc35c2f06d312ee061a1ad4445e72e..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 3de53a97d6fece2c00dae657f9e944fcfd0b6e6d..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 8c579f47e383d63d755a09251eca17ee7a8fabb3..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 65ee06bf7b41197695bcf0fde9c27ad46e3e822e..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index f0622a02c3320f161010a868ea1524df7bb2e796..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 2825b9659f67197201c39ed1d6a2fbb376bf6da3..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 074d1cc0167b828f2e1a8465f8ba8037e9f177f2..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 40d84ea7d62ab5b6b9c7ac650566274db6745cef..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index db62c654ebac741cf436a325a5c151499bacd5ad..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
--- a/mail/components/im/smileys/theme.json
+++ b/mail/components/im/smileys/theme.json
@@ -1,25 +1,22 @@
 {
   "smileys": [
-    {"filename": "smile.png", "textCodes": [":-)", ":)", "(-:", "(:"]},
-    {"filename": "grin.png", "textCodes": [":-D", ":D"]},
-    {"filename": "wink.png", "textCodes": [";-)", ";)"]},
-    {"filename": "cry.png", "textCodes": [":'("]},
-    {"filename": "shocked.png", "textCodes": [":-o", ":-O"]},
-    {"filename": "confused.png", "textCodes": [":-S", ":S", ":-s", ":s"]},
-    {"filename": "slant.png", "textCodes": [":-/"]},
-    {"filename": "slant2.png", "textCodes": [":-\\"], "hidden": true},
-    {"filename": "angry.png", "textCodes": ["x-("]},
-    {"filename": "sad.png", "textCodes": [":-(", ":(", ")-:", "):"]},
-    {"filename": "cool.png", "textCodes": ["B-)", "8-)"]},
-    {"filename": "tongue.png", "textCodes": [":-P", ":P", ":-p", ":p"]},
-    {"filename": "embarrassed.png", "textCodes": [":-]", ":]"]},
-    {"filename": "heart.png", "textCodes": ["<3"]},
-    {"filename": "straight_face.png", "textCodes": [":-|"]},
-    {"filename": "manga_smile.png", "textCodes": ["^^"]},
-    {"filename": "manga_embarrassed.png", "textCodes": ["^^'"]},
-    {"filename": "manga_tired.png", "textCodes": ["-_-"]},
-    {"filename": "manga_annoyed.png", "textCodes": ["-_-'", "--'"]},
-    {"filename": "manga_stunned.png", "textCodes": ["o_o", "O_O"]},
-    {"filename": "sp_laugh.png", "textCodes": ["XD", "xD"]}
+    {"glyph": "\uD83D\uDE01", "textCodes": [":-)", ":)", "(-:", "(:"]},
+    {"glyph": "\uD83D\uDE02", "textCodes": [":-D", ":D"]},
+    {"glyph": "\uD83D\uDE09", "textCodes": [";-)", ";)"]},
+    {"glyph": "\uD83D\uDE2D", "textCodes": [":'("]},
+    {"glyph": "\uD83D\uDE2D", "textCodes": [":-o", ":-O", "o_o", "O_O"]},
+    {"glyph": "\uD83D\uDE15", "textCodes": [":-S", ":S", ":-s", ":s"]},
+    {"glyph": "\uD83D\uDE1F", "textCodes": [":-/", ":-\\"]},
+    {"glyph": "\uD83D\uDE20", "textCodes": ["x-("]},
+    {"glyph": "\uD83D\uDE41", "textCodes": [":-(", ":(", ")-:", "):"]},
+    {"glyph": "\uD83D\uDE0E", "textCodes": ["B-)", "8-)"]},
+    {"glyph": "\uD83D\uDE1B", "textCodes": [":-P", ":P", ":-p", ":p"]},
+    {"glyph": "\uD83D\uDE05", "textCodes": [":-]", ":]", "^^'"]},
+    {"glyph": "♥", "textCodes": ["<3"]},
+    {"glyph": "\uD83D\uDE10", "textCodes": [":-|"]},
+    {"glyph": "☺", "textCodes": ["^^"]},
+    {"glyph": "\uD83D\uDE2B", "textCodes": ["-_-"]},
+    {"glyph": "\uD83D\uDE24", "textCodes": ["-_-'", "--'"]},
+    {"glyph": "\uD83E\uDD23", "textCodes": ["XD", "xD"]}
   ]
 }
deleted file mode 100644
index 225b661df76c22499c28e1bea8091ca90be29708..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 556c2a5c72849e90fe4c34d4163174c08e72af06..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001