Bug 1254526 - Filter out empty text nodes from narrate queue. r=Gijs draft
authorEitan Isaacson <eitan@monotonous.org>
Wed, 09 Mar 2016 12:31:25 -0800
changeset 339531 74b3a7dd5d879cb156c83a26960d374917420f6f
parent 339530 76604a26055b4961ce3d548e9c9b5bd672c76265
child 516013 e00cf668f44773fa5d92b3d10e90e577cba5c819
push id12757
push userbmo:eitan@monotonous.org
push dateFri, 11 Mar 2016 18:36:45 +0000
reviewersGijs
bugs1254526
milestone48.0a1
Bug 1254526 - Filter out empty text nodes from narrate queue. r=Gijs MozReview-Commit-ID: 6g53pWcNtGN
toolkit/components/narrate/Narrator.jsm
--- a/toolkit/components/narrate/Narrator.jsm
+++ b/toolkit/components/narrate/Narrator.jsm
@@ -61,24 +61,30 @@ Narrator.prototype = {
         // are not interesting since their text already appears in their
         // parent's textContent.
         acceptNode: function(node) {
           if (this._matches.has(node.parentNode)) {
             // Reject sub-trees of accepted nodes.
             return nf.FILTER_REJECT;
           }
 
+          if (!/\S/.test(node.textContent)) {
+            // Reject nodes with no text.
+            return nf.FILTER_REJECT;
+          }
+
           let bb = wu.getBoundsWithoutFlushing(node);
           if (!bb.width || !bb.height) {
-            // Skip non-rendered nodes.
+            // Skip non-rendered nodes. We don't reject because a zero-sized
+            // container can still have visible, "overflowed", content.
             return nf.FILTER_SKIP;
           }
 
           for (let c = node.firstChild; c; c = c.nextSibling) {
-            if (c.nodeType == c.TEXT_NODE && !!c.textContent.match(/\S/)) {
+            if (c.nodeType == c.TEXT_NODE && /\S/.test(c.textContent)) {
               // If node has a non-empty text child accept it.
               this._matches.add(node);
               return nf.FILTER_ACCEPT;
             }
           }
 
           return nf.FILTER_SKIP;
         }