Bug 1596685 - fix gatherTextUnder() by reverting part of bug 1570954. r=jorgk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Fri, 15 Nov 2019 11:48:40 +0100
changeset 36644 7ab3efcd2527ef7eccb2d072e97f3da77da1170a
parent 36643 54ccc35a7b0b15be4542c5c2cc12c163e1366c18
child 36645 f5213fb4cd253d07da06753c9512137e3de8f681
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)
reviewersjorgk
bugs1596685, 1570954
Bug 1596685 - fix gatherTextUnder() by reverting part of bug 1570954. r=jorgk Revert this: https://hg.mozilla.org/comm-central/rev/a128f9557e9d#l63.10
mail/base/content/utilityOverlay.js
--- a/mail/base/content/utilityOverlay.js
+++ b/mail/base/content/utilityOverlay.js
@@ -65,49 +65,52 @@ function goCopyImage() {
 }
 
 // update Find As You Type menu items, they rely on focus
 function goUpdateFindTypeMenuItems() {
   goUpdateCommand("cmd_findTypeText");
   goUpdateCommand("cmd_findTypeLinks");
 }
 
-// Gather all descendent text under given document node.
+/**
+ * Gather all descendent text under given node.
+ * @param {Node} root - The root node to gather text from.
+ * @returns {string} The text data under the node.
+ */
 function gatherTextUnder(root) {
   var text = "";
-  var node = root.firstElementChild;
+  var node = root.firstChild;
   var depth = 1;
   while (node && depth > 0) {
     // See if this node is text.
     if (node.nodeType == Node.TEXT_NODE) {
       // Add this text to our collection.
       text += " " + node.data;
     } else if (node instanceof HTMLImageElement) {
       // If it has an alt= attribute, add that.
       var altText = node.getAttribute("alt");
       if (altText && altText != "") {
         text += " " + altText;
       }
     }
     // Find next node to test.
-    // First, see if this node has children.
-    if (node.hasChildNodes()) {
-      // Go to first child.
-      node = node.firstElementChild;
+    if (node.firstChild) {
+      // If it has children, go to first child.
+      node = node.firstChild;
       depth++;
-    } else if (node.nextElementSibling) {
+    } else if (node.nextSibling) {
       // No children, try next sibling.
-      node = node.nextElementSibling;
+      node = node.nextSibling;
     } else {
       // Last resort is a sibling of an ancestor.
       while (node && depth > 0) {
         node = node.parentNode;
         depth--;
-        if (node.nextElementSibling) {
-          node = node.nextElementSibling;
+        if (node.nextSibling) {
+          node = node.nextSibling;
           break;
         }
       }
     }
   }
   // Strip leading and trailing whitespace.
   text = text.trim();
   // Compress remaining whitespace.