Bug 1301016 - Part 1 - Wait for custom event instead of pageshow for scroll position restoring in reader mode. r=ahunt
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 08 Sep 2016 23:00:08 +0200
changeset 344702 43e595bc39d597b1da6e6d4399acd23651bfd90d
parent 344701 69b7d6494d13848abb06440a3f74913c241653be
child 344703 4e6337f61e6bd54479e6460fa92d27250415758f
push id8
push userfmarier@mozilla.com
push dateThu, 15 Sep 2016 05:23:20 +0000
reviewersahunt
bugs1301016, 1153393
milestone51.0a1
Bug 1301016 - Part 1 - Wait for custom event instead of pageshow for scroll position restoring in reader mode. r=ahunt Some further post-processing happens after loading a page in reader mode, so the pageshow event is too early for restoring the scroll position. The fix is to do the same thing that desktop does in bug 1153393 and wait for a custom event instead. MozReview-Commit-ID: DuMA0JxnYEY
mobile/android/components/SessionStore.js
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -383,30 +383,38 @@ SessionStore.prototype = {
         // before trying to restore this data.
         log("load for tab " + window.BrowserApp.getTabForBrowser(browser).id);
         if (browser.__SS_restoreDataOnLoad) {
           delete browser.__SS_restoreDataOnLoad;
           this._restoreTextData(browser.__SS_data.formdata, browser);
         }
         break;
       }
-      case "pageshow": {
+      case "pageshow":
+      case "AboutReaderContentReady": {
         let browser = aEvent.currentTarget;
 
         // Skip subframe pageshows.
         if (browser.contentDocument !== aEvent.originalTarget) {
           return;
         }
 
+        if (browser.currentURI.spec.startsWith("about:reader") &&
+            !browser.contentDocument.body.classList.contains("loaded")) {
+          // Don't restore the scroll position of an about:reader page at this point;
+          // wait for the custom event dispatched from AboutReader.jsm instead.
+          return;
+        }
+
         // Restoring the scroll position needs to happen after the zoom level has been
         // restored, which is done by the MobileViewportManager either on first paint
         // or on load, whichever comes first.
         // In the latter case, our load handler runs before the MVM's one, which is the
         // wrong way around, so we have to use a later event instead.
-        log("pageshow for tab " + window.BrowserApp.getTabForBrowser(browser).id);
+        log(aEvent.type + " for tab " + window.BrowserApp.getTabForBrowser(browser).id);
         if (browser.__SS_restoreDataOnPageshow) {
           delete browser.__SS_restoreDataOnPageshow;
           this._restoreScrollPosition(browser.__SS_data.scrolldata, browser);
         } else {
           // We're not restoring, capture the initial scroll position on pageshow.
           this.onTabScroll(window, browser);
         }
         break;
@@ -509,16 +517,17 @@ SessionStore.prototype = {
     aBrowser.addEventListener("DOMTitleChanged", this, true);
 
     // Use load to restore text data
     aBrowser.addEventListener("load", this, true);
 
     // Gecko might set the initial zoom level after the JS "load" event,
     // so we have to restore zoom and scroll position after that.
     aBrowser.addEventListener("pageshow", this, true);
+    aBrowser.addEventListener("AboutReaderContentReady", this, true);
 
     // Use a combination of events to watch for text data changes
     aBrowser.addEventListener("change", this, true);
     aBrowser.addEventListener("input", this, true);
     aBrowser.addEventListener("DOMAutoComplete", this, true);
 
     // Record the current scroll position and zoom level.
     aBrowser.addEventListener("scroll", this, true);
@@ -532,16 +541,17 @@ SessionStore.prototype = {
     this._updateCrashReportURL(aWindow);
   },
 
   onTabRemove: function ss_onTabRemove(aWindow, aBrowser, aNoNotification) {
     // Cleanup event listeners
     aBrowser.removeEventListener("DOMTitleChanged", this, true);
     aBrowser.removeEventListener("load", this, true);
     aBrowser.removeEventListener("pageshow", this, true);
+    aBrowser.removeListener("AboutReaderContentReady", this, true);
     aBrowser.removeEventListener("change", this, true);
     aBrowser.removeEventListener("input", this, true);
     aBrowser.removeEventListener("DOMAutoComplete", this, true);
     aBrowser.removeEventListener("scroll", this, true);
     aBrowser.removeEventListener("resize", this, true);
 
     delete aBrowser.__SS_data;