Bug 1419226 - Part 1.Change observing target window of MozAfterPaint. r?mconley
Previous code, print preview waits for content window's MozAfterPaint. However
gecko prevents send MozAfterPaint to content window[1]. So this code will not
work correctly. However, software timer of firing MozAfterPaint ran this code.[2]
This patch will
* Change the observing content window to chrome window.
* Add timer of MozAfterPaint event in order to ensure this event even if display
list invalidation doesn't invalidate. Gecko create this timer in nsPresContext
previously[2], but this bug will remove it
[1] https://searchfox.org/mozilla-central/rev/919dce54f43356c22d6ff6b81c07ef412b1bf933/layout/base/nsPresContext.cpp#2452
[2] https://searchfox.org/mozilla-central/rev/919dce54f43356c22d6ff6b81c07ef412b1bf933/layout/base/nsPresContext.cpp#3466-3472
MozReview-Commit-ID: GcuKPjn0qhc
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -624,25 +624,31 @@ var Printing = {
articlePromise.then(function(article) {
// We make use of a web progress listener in order to know when the content we inject
// into the DOM has finished rendering. If our layout engine is still painting, we
// will wait for MozAfterPaint event to be fired.
let webProgressListener = {
onStateChange(webProgress, req, flags, status) {
if (flags & Ci.nsIWebProgressListener.STATE_STOP) {
webProgress.removeProgressListener(webProgressListener);
- let domUtils = content.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils);
+ let domUtils = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
// Here we tell the parent that we have parsed the document successfully
// using ReaderMode primitives and we are able to enter on preview mode.
if (domUtils.isMozAfterPaintPending) {
- addEventListener("MozAfterPaint", function onPaint() {
+ let onPaint = function() {
removeEventListener("MozAfterPaint", onPaint);
sendAsyncMessage("Printing:Preview:ReaderModeReady");
- });
+ };
+ contentWindow.addEventListener("MozAfterPaint", onPaint);
+ // This timer need when display list invalidation doesn't invalidate.
+ setTimeout(() => {
+ removeEventListener("MozAfterPaint", onPaint);
+ sendAsyncMessage("Printing:Preview:ReaderModeReady");
+ }, 100);
} else {
sendAsyncMessage("Printing:Preview:ReaderModeReady");
}
}
},
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIWebProgressListener,