Bug 1597131 - followup to make chat tooltips work again. r=khusil
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Thu, 28 Nov 2019 13:12:10 +0200
changeset 36749 e370eb044bf92725cc890db47d56b771ba1c09ce
parent 36748 30ad6ed6ebb611238dd64a64394e35289e5d19f2
child 36750 2277b9c74c7d3f8852521f4c8d48e032b5431893
push id2534
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:52:51 +0000
treeherdercomm-beta@055c50840778 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhusil
bugs1597131
Bug 1597131 - followup to make chat tooltips work again. r=khusil Previously before bug 1597131 mousethrough was used not to get popupshowing for the wrong tooltipNode. Using css pointer-events doesn't work the same for this case, so we need to do better matching in the event handler instead.
chat/content/chat-tooltip.js
--- a/chat/content/chat-tooltip.js
+++ b/chat/content/chat-tooltip.js
@@ -79,63 +79,59 @@
     }
 
     _onPopupShowing() {
       // No tooltip above the context menu.
       if (document.popupNode) {
         return false;
       }
 
-      let elt = document.tooltipNode;
       // No tooltip for elements that have already been removed.
-      if (!elt.parentNode) {
+      if (!document.tooltipNode.parentNode) {
         return false;
       }
 
       // Reset tooltip.
       let largeTooltip = this.querySelector(".largeTooltip");
       largeTooltip.hidden = false;
       this.removeAttribute("label");
 
-      let localName = elt.localName;
+      // We have a few cases that have special behavior. These are richlistitems
+      // and have tooltip="<myid>".
+      let item = document.tooltipNode.closest(
+        `[tooltip="${this.id}"] richlistitem`
+      );
 
-      if (
-        localName == "richlistitem" &&
-        elt.getAttribute("is") == "chat-group-richlistitem"
-      ) {
+      if (item && item.matches(`:scope[is="chat-group-richlistitem"]`)) {
         return false;
       }
 
-      if (
-        localName == "richlistitem" &&
-        elt.getAttribute("is") == "chat-imconv-richlistitem" &&
-        elt.conv
-      ) {
-        return this.updateTooltipFromConversation(elt.conv);
+      if (item && item.matches(`:scope[is="chat-imconv-richlistitem"]`)) {
+        return this.updateTooltipFromConversation(item.conv);
       }
 
-      if (
-        localName == "richlistitem" &&
-        elt.getAttribute("is") == "chat-contact-richlistitem"
-      ) {
+      if (item && item.matches(`:scope[is="chat-contact-richlistitem"]`)) {
         return this.updateTooltipFromBuddy(
-          elt.contact.preferredBuddy.preferredAccountBuddy
+          item.contact.preferredBuddy.preferredAccountBuddy
         );
       }
 
-      if (localName == "richlistitem") {
+      if (item) {
         let contactlistbox = document.getElementById("contactlistbox");
         let conv = contactlistbox.selectedItem.conv;
         return this.updateTooltipFromParticipant(
-          elt.chatBuddy.name,
+          item.chatBuddy.name,
           conv,
-          elt.chatBuddy
+          item.chatBuddy
         );
       }
 
+      // Tooltips are also used for the chat content, where we need to do
+      // some more general checks.
+      let elt = document.tooltipNode;
       let classList = elt.classList;
       if (
         classList.contains("ib-nick") ||
         classList.contains("ib-sender") ||
         classList.contains("ib-person")
       ) {
         let conv = getBrowser()._conv;
         if (conv.isChat) {