Bug 1312605 - Part 1 - Don't clobber resolution changes that happen before first paint on Fennec. r?kats draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 29 Jun 2017 09:26:37 -0700
changeset 602056 67cc32ed95203d7b4225605f5753518edfb2ae55
parent 601588 eaeceb0e08383619e06f933c87b7484bd356c0b9
child 635445 5651c600f6b433160c64cfbd5d39180acb6af74e
push id66260
push usermozilla@buttercookie.de
push dateThu, 29 Jun 2017 16:31:23 +0000
reviewerskats
bugs1312605
milestone56.0a1
Bug 1312605 - Part 1 - Don't clobber resolution changes that happen before first paint on Fennec. r?kats When going back/forward through a tab's session history, the saved resolution from the LayoutHistoryState is set on the PresShell before first paint. On Fennec, this means that it is subsequently going to be overwritten by the MobileViewportManager's default zoom calculation. To fix this, we make use of the MVM's feature to set a "restored" resolution that will then be taken into account on first paint. MozReview-Commit-ID: 43o97M6fiaZ
layout/base/MobileViewportManager.cpp
layout/base/MobileViewportManager.h
mobile/android/tests/browser/chrome/test_session_scroll_position.html
--- a/layout/base/MobileViewportManager.cpp
+++ b/layout/base/MobileViewportManager.cpp
@@ -83,33 +83,44 @@ MobileViewportManager::Destroy()
   mDocument = nullptr;
   mPresShell = nullptr;
 }
 
 void
 MobileViewportManager::SetRestoreResolution(float aResolution,
                                             LayoutDeviceIntSize aDisplaySize)
 {
-  mRestoreResolution = Some(aResolution);
+  SetRestoreResolution(aResolution);
   ScreenIntSize restoreDisplaySize = ViewAs<ScreenPixel>(aDisplaySize,
     PixelCastJustification::LayoutDeviceIsScreenForBounds);
   mRestoreDisplaySize = Some(restoreDisplaySize);
 }
 
 void
+MobileViewportManager::SetRestoreResolution(float aResolution)
+{
+  mRestoreResolution = Some(aResolution);
+}
+
+void
 MobileViewportManager::RequestReflow()
 {
   MVM_LOG("%p: got a reflow request\n", this);
   RefreshViewportSize(false);
 }
 
 void
 MobileViewportManager::ResolutionUpdated()
 {
   MVM_LOG("%p: resolution updated\n", this);
+  if (!mPainted) {
+    // Save the value, so our default zoom calculation
+    // can take it into account later on.
+    SetRestoreResolution(mPresShell->GetResolution());
+  }
   RefreshSPCSPS();
 }
 
 NS_IMETHODIMP
 MobileViewportManager::HandleEvent(nsIDOMEvent* event)
 {
   nsAutoString type;
   event->GetType(type);
--- a/layout/base/MobileViewportManager.h
+++ b/layout/base/MobileViewportManager.h
@@ -32,16 +32,20 @@ public:
    * resolution computed from the viewport info metadata. This is in the same
    * "units" as the argument to nsDOMWindowUtils::SetResolutionAndScaleTo.
    * Also takes the previous display dimensions as they were at the time the
    * resolution was stored in order to correctly adjust the resolution if the
    * device was rotated in the meantime. */
   void SetRestoreResolution(float aResolution,
                             mozilla::LayoutDeviceIntSize aDisplaySize);
 
+private:
+  void SetRestoreResolution(float aResolution);
+
+public:
   /* Notify the MobileViewportManager that a reflow was requested in the
    * presShell.*/
   void RequestReflow();
 
   /* Notify the MobileViewportManager that the resolution on the presShell was
    * updated, and the SPCSPS needs to be updated. */
   void ResolutionUpdated();
 
--- a/mobile/android/tests/browser/chrome/test_session_scroll_position.html
+++ b/mobile/android/tests/browser/chrome/test_session_scroll_position.html
@@ -206,17 +206,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     pageshow = promiseBrowserEvent(browser, "pageshow");
     scroll = promiseBrowserEvent(browser, "scroll");
     browser.goBack();
     yield pageshow;
     yield scroll;
 
     utils.getResolution(zoom);
     utils.getScrollXY(false, scrollX, scrollY);
-    todo(fuzzyEquals(zoom.value, ZOOM), "zoom restored correctly"); // Bug 1312605
+    ok(fuzzyEquals(zoom.value, ZOOM), "zoom restored correctly");
     is(scrollX.value, SCROLL_X, "scrollX restored correctly");
     is(scrollY.value, SCROLL_Y, "scrollY restored correctly");
 
     // Remove the tab.
     BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
   });
 
   add_task(function* test_sessionStoreZoomLevelRecalc() {