Bug 1254526 - Filter out empty text nodes from narrate queue. r=Gijs
authorEitan Isaacson <eitan@monotonous.org>
Wed, 09 Mar 2016 12:31:25 -0800
changeset 339587 5b6bcc1fec089df9ab8a72dca6abc9d74b81e12c
parent 339586 fa1daaba023bb75fcb6fe9509d71a5d658e6d92c
child 339588 940a177ba6a4875625482f17d52da5608bd1a2dd
child 340299 07044980d09389fa1d01202d33a68f5c451b5c61
push id12762
push userbmo:rail@mozilla.com
push dateFri, 11 Mar 2016 19:47: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;
         }