Bug 390180: Full page zoom interacts badly with bfcache. r+sr+a=roc
authorsharparrow1@yahoo.com
Mon, 27 Aug 2007 18:20:17 -0700
changeset 5357 aa9c9aea7391a50f5262fd48ec16798a8184da96
parent 5356 10217e6ee280df5c17b6b6e36aae07a8389bfad0
child 5358 2b640fb7fed648e6a6b4e1bb03e2d1fc2addd906
push idunknown
push userunknown
push dateunknown
bugs390180
milestone1.9a8pre
Bug 390180: Full page zoom interacts badly with bfcache. r+sr+a=roc
docshell/base/nsDocShell.cpp
layout/base/nsDocumentViewer.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -5428,19 +5428,22 @@ nsDocShell::RestoreFromHistory()
         nsIRequest *request = nsnull;
         if (doc)
             request = doc->GetChannel();
         mSavingOldViewer = CanSavePresentation(mLoadType, request, doc);
     }
 
     nsCOMPtr<nsIMarkupDocumentViewer> oldMUDV(do_QueryInterface(mContentViewer));
     nsCOMPtr<nsIMarkupDocumentViewer> newMUDV(do_QueryInterface(viewer));
-    float zoom = 1.0;
-    if (oldMUDV && newMUDV)
-        oldMUDV->GetTextZoom(&zoom);
+    float textZoom = 1.0f;
+    float pageZoom = 1.0f;
+    if (oldMUDV && newMUDV) {
+        oldMUDV->GetTextZoom(&textZoom);
+        oldMUDV->GetFullZoom(&pageZoom);
+    }
 
     // Protect against mLSHE going away via a load triggered from
     // pagehide or unload.
     nsCOMPtr<nsISHEntry> origLSHE = mLSHE;
 
     // Notify the old content viewer that it's being hidden.
     FirePageHideNotification(!mSavingOldViewer);
 
@@ -5609,18 +5612,20 @@ nsDocShell::RestoreFromHistory()
     mEODForCurrentDocument = PR_FALSE;
 
     // Tell the event loop to favor plevents over user events, see comments
     // in CreateContentViewer.
     if (++gNumberOfDocumentsLoading == 1)
         FavorPerformanceHint(PR_TRUE, NS_EVENT_STARVATION_DELAY_HINT);
 
 
-    if (oldMUDV && newMUDV)
-        newMUDV->SetTextZoom(zoom);
+    if (oldMUDV && newMUDV) {
+        newMUDV->SetTextZoom(textZoom);
+        newMUDV->SetFullZoom(pageZoom);
+    }
 
     nsCOMPtr<nsIDocument> document = do_QueryInterface(domDoc);
     if (document) {
         // Use the uri from the mLSHE we had when we entered this function
         // (which need not match the document's URI if anchors are involved),
         // since that's the history entry we're loading.  Note that if we use
         // origLSHE we don't have to worry about whether the entry in question
         // is still mLSHE or whether it's now mOSHE.
@@ -5942,16 +5947,17 @@ nsDocShell::SetupNewViewer(nsIContentVie
     nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
 
     nsCAutoString defaultCharset;
     nsCAutoString forceCharset;
     nsCAutoString hintCharset;
     PRInt32 hintCharsetSource;
     nsCAutoString prevDocCharset;
     float textZoom;
+    float pageZoom;
     PRBool styleDisabled;
     // |newMUDV| also serves as a flag to set the data from the above vars
     nsCOMPtr<nsIMarkupDocumentViewer> newMUDV;
 
     if (mContentViewer || parent) {
         nsCOMPtr<nsIMarkupDocumentViewer> oldMUDV;
         if (mContentViewer) {
             // Get any interesting state from old content viewer
@@ -5992,16 +5998,19 @@ nsDocShell::SetupNewViewer(nsIContentVie
                                   NS_ERROR_FAILURE);
                 NS_ENSURE_SUCCESS(oldMUDV->
                                   GetHintCharacterSetSource(&hintCharsetSource),
                                   NS_ERROR_FAILURE);
                 NS_ENSURE_SUCCESS(oldMUDV->
                                   GetTextZoom(&textZoom),
                                   NS_ERROR_FAILURE);
                 NS_ENSURE_SUCCESS(oldMUDV->
+                                  GetFullZoom(&pageZoom),
+                                  NS_ERROR_FAILURE);
+                NS_ENSURE_SUCCESS(oldMUDV->
                                   GetAuthorStyleDisabled(&styleDisabled),
                                   NS_ERROR_FAILURE);
                 NS_ENSURE_SUCCESS(oldMUDV->
                                   GetPrevDocCharacterSet(prevDocCharset),
                                   NS_ERROR_FAILURE);
             }
         }
     }
@@ -6125,16 +6134,18 @@ nsDocShell::SetupNewViewer(nsIContentVie
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(newMUDV->
                           SetHintCharacterSetSource(hintCharsetSource),
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(newMUDV->SetPrevDocCharacterSet(prevDocCharset),
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(newMUDV->SetTextZoom(textZoom),
                           NS_ERROR_FAILURE);
+        NS_ENSURE_SUCCESS(newMUDV->SetFullZoom(pageZoom),
+                          NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(newMUDV->SetAuthorStyleDisabled(styleDisabled),
                           NS_ERROR_FAILURE);
     }
 
     // End copying block (Don't mess with the old content/document viewer
     // beyond here!!)
 
     // See the book I wrote above regarding why the focus controller is 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -407,16 +407,17 @@ protected:
   nsCOMPtr<nsIDOMFocusListener> mFocusListener;
 
   nsCOMPtr<nsIContentViewer> mPreviousViewer;
   nsCOMPtr<nsISHEntry> mSHEntry;
 
   nsIWidget* mParentWidget;          // purposely won't be ref counted
 
   float mTextZoom;      // Text zoom, defaults to 1.0
+  float mPageZoom;
 
   PRInt16 mNumURLStarts;
   PRInt16 mDestroyRefCount;    // a second "refcount" for the document viewer's "destroy"
 
   unsigned      mEnableRendering : 1;
   unsigned      mStopped : 1;
   unsigned      mLoaded : 1;
   unsigned      mDeferredWindowClose : 1;
@@ -502,17 +503,17 @@ void DocumentViewerImpl::PrepareToStartL
   mDebugFile = nsnull;
 #endif
 
 #endif // NS_PRINTING
 }
 
 // Note: operator new zeros our memory, so no need to init things to null.
 DocumentViewerImpl::DocumentViewerImpl()
-  : mTextZoom(1.0),
+  : mTextZoom(1.0), mPageZoom(1.0),
     mIsSticky(PR_TRUE),
     mHintCharsetSource(kCharsetUninitialized)
 {
   PrepareToStartLoad();
 }
 
 NS_IMPL_ADDREF(DocumentViewerImpl)
 NS_IMPL_RELEASE(DocumentViewerImpl)
@@ -677,22 +678,23 @@ DocumentViewerImpl::InitPresentationStuf
   }
 
   mPresShell->BeginObservingDocument();
 
   // Initialize our view manager
   nsRect bounds;
   mWindow->GetBounds(bounds);
 
-  nscoord width = mPresContext->DevPixelsToAppUnits(bounds.width);
-  nscoord height = mPresContext->DevPixelsToAppUnits(bounds.height);
+  nscoord width = mPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel() * bounds.width;
+  nscoord height = mPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel() * bounds.height;
 
   mViewManager->DisableRefresh();
   mViewManager->SetWindowDimensions(width, height);
   mPresContext->SetTextZoom(mTextZoom);
+  mPresContext->SetFullZoom(mPageZoom);
 
   // Setup default view manager background color
 
   // This may be overridden by the docshell with the background color
   // for the last document loaded into the docshell
   mViewManager->SetDefaultBackgroundColor(mPresContext->DefaultBackgroundColor());
 
   if (aDoInitialReflow) {
@@ -2711,30 +2713,33 @@ DocumentViewerImpl::GetTextZoom(float* a
 
   *aTextZoom = mTextZoom;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::SetFullZoom(float aFullZoom)
 {
+  mPageZoom = aFullZoom;
   struct ZoomInfo ZoomInfo = { aFullZoom };
   CallChildren(SetChildFullZoom, &ZoomInfo);
   if (mPresContext) {
       mPresContext->SetFullZoom(aFullZoom);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::GetFullZoom(float* aFullZoom)
 {
   NS_ENSURE_ARG_POINTER(aFullZoom);
-  *aFullZoom = mPresContext ? mPresContext->GetFullZoom() : 1.0;
+  NS_ASSERTION(!mPresContext || mPresContext->GetFullZoom() == mPageZoom, 
+               "mPresContext->GetFullZoom() != mPageZoom");
+  *aFullZoom = mPresContext ? mPresContext->GetFullZoom() : 1.0f;
   return NS_OK;
 }
 
 static void
 SetChildAuthorStyleDisabled(nsIMarkupDocumentViewer* aChild, void* aClosure)
 {
   PRBool styleDisabled  = *static_cast<PRBool*>(aClosure);
   aChild->SetAuthorStyleDisabled(styleDisabled);