From 91b96d53cae62049244897e3fec2949e580a5bf8 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Mon, 27 Apr 2015 15:58:24 +0100 Subject: [PATCH] Bug 1153384 - improve isProbablyReaderable detection, r=margaret --HG-- extra : rebase_source : 37154ce2a688269bcbd96b2181da22af922980c2 --- toolkit/components/reader/ReaderMode.jsm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/toolkit/components/reader/ReaderMode.jsm b/toolkit/components/reader/ReaderMode.jsm index 60de244c82f4..581c47657da7 100644 --- a/toolkit/components/reader/ReaderMode.jsm +++ b/toolkit/components/reader/ReaderMode.jsm @@ -20,6 +20,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm XPCOMUtils.defineLazyGetter(this, "Readability", function() { let scope = {}; + scope.dump = this.dump; Services.scriptloader.loadSubScript("resource://gre/modules/reader/Readability.js", scope); return scope["Readability"]; }); @@ -116,7 +117,20 @@ this.ReaderMode = { return false; } - return new Readability(uri, doc).isProbablyReaderable(); + let utils = this.getUtilsForWin(doc.defaultView); + // We pass in a helper function to determine if a node is visible, because + // it uses gecko APIs that the engine-agnostic readability code can't rely + // upon. + return new Readability(uri, doc).isProbablyReaderable(this.isNodeVisible.bind(this, utils)); + }, + + isNodeVisible: function(utils, node) { + let bounds = utils.getBoundsWithoutFlushing(node); + return bounds.height > 0 && bounds.width > 0; + }, + + getUtilsForWin: function(win) { + return win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils); }, /**