Bug 1254526 - Filter out empty text nodes from narrate queue. r=Gijs
MozReview-Commit-ID: 6g53pWcNtGN
--- 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;
}