Bug 389720: zooming frameset is poor. r+sr=roc, a=dbaron
authorsharparrow1@yahoo.com
Tue, 07 Aug 2007 13:38:35 -0700
changeset 4359 488f170434cc1f2211b02b20a84b12e2a4f6aaac
parent 4358 a789cf17ca546f5655b61b191788fbfbd16cd941
child 4360 7618ae9744560b16dfc6c4b505f236299cf2ac90
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs389720
milestone1.9a8pre
Bug 389720: zooming frameset is poor. r+sr=roc, a=dbaron
layout/base/nsDocumentViewer.cpp
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2649,43 +2649,50 @@ DocumentViewerImpl::CallChildren(CallChi
             (*aFunc)(markupCV, aClosure);
           }
         }
       }
     }
   }
 }
 
-struct TextZoomInfo
+struct ZoomInfo
 {
-  float mTextZoom;
+  float mZoom;
 };
 
 static void
 SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure)
 {
-  struct TextZoomInfo* textZoomInfo = (struct TextZoomInfo*) aClosure;
-  aChild->SetTextZoom(textZoomInfo->mTextZoom);
+  struct ZoomInfo* ZoomInfo = (struct ZoomInfo*) aClosure;
+  aChild->SetTextZoom(ZoomInfo->mZoom);
+}
+
+static void
+SetChildFullZoom(nsIMarkupDocumentViewer* aChild, void* aClosure)
+{
+  struct ZoomInfo* ZoomInfo = (struct ZoomInfo*) aClosure;
+  aChild->SetFullZoom(ZoomInfo->mZoom);
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::SetTextZoom(float aTextZoom)
 {
   mTextZoom = aTextZoom;
 
   if (mViewManager) {
     mViewManager->BeginUpdateViewBatch();
   }
       
   // Set the text zoom on all children of mContainer (even if our zoom didn't
   // change, our children's zoom may be different, though it would be unusual).
   // Do this first, in case kids are auto-sizing and post reflow commands on
   // our presshell (which should be subsumed into our own style change reflow).
-  struct TextZoomInfo textZoomInfo = { aTextZoom };
-  CallChildren(SetChildTextZoom, &textZoomInfo);
+  struct ZoomInfo ZoomInfo = { aTextZoom };
+  CallChildren(SetChildTextZoom, &ZoomInfo);
 
   // Now change our own zoom
   if (mPresContext && aTextZoom != mPresContext->TextZoom()) {
       mPresContext->SetTextZoom(aTextZoom);
   }
 
   if (mViewManager) {
     mViewManager->EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC);
@@ -2703,16 +2710,18 @@ DocumentViewerImpl::GetTextZoom(float* a
 
   *aTextZoom = mTextZoom;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::SetFullZoom(float aFullZoom)
 {
+  struct ZoomInfo ZoomInfo = { aFullZoom };
+  CallChildren(SetChildFullZoom, &ZoomInfo);
   if (mPresContext) {
       mPresContext->SetFullZoom(aFullZoom);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -156,17 +156,17 @@ destroy_loads(const void * aKey, nsCOMPt
 static NS_DEFINE_CID(kLookAndFeelCID,  NS_LOOKANDFEEL_CID);
 #include "nsContentCID.h"
 static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID);
 
   // NOTE! nsPresContext::operator new() zeroes out all members, so don't
   // bother initializing members to 0.
 
 nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
-  : mType(aType), mDocument(aDocument), mTextZoom(1.0),
+  : mType(aType), mDocument(aDocument), mTextZoom(1.0), mFullZoom(1.0),
     mPageSize(-1, -1), mPPScale(1.0f),
     mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
     mImageAnimationModePref(imgIContainer::kNormalAnimMode),
     // Font sizes default to zero; they will be set in GetFontPreferences
     mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
                          NS_FONT_WEIGHT_NORMAL, 0, 0),
     mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL,
                       NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 0, 0),
@@ -1080,31 +1080,29 @@ const nsFont*
 nsPresContext::GetDefaultFontExternal(PRUint8 aFontID) const
 {
   return GetDefaultFontInternal(aFontID);
 }
 
 void
 nsPresContext::SetFullZoom(float aZoom)
 {
-  nsPresContext* rootPresContext = RootPresContext();
-  if (rootPresContext != this) {
-    NS_WARNING("Zoom set on non-root prescontext");
-    rootPresContext->SetFullZoom(aZoom);
+  float oldWidth = mVisibleArea.width * mFullZoom;
+  float oldHeight = mVisibleArea.height * mFullZoom;
+  if (!mShell) {
     return;
   }
-  nsRect bounds(mVisibleArea);
-  bounds.ScaleRoundPreservingCentersInverse(AppUnitsPerDevPixel());
-  if (!mShell || !mDeviceContext->SetPixelScale(aZoom))
-    return;
-  mDeviceContext->FlushFontCache();
-  nscoord width = DevPixelsToAppUnits(bounds.width);
-  nscoord height = DevPixelsToAppUnits(bounds.height);
-  GetViewManager()->SetWindowDimensions(width, height);
-  ClearStyleDataAndReflow();
+  if (mDeviceContext->SetPixelScale(aZoom)) {
+    mDeviceContext->FlushFontCache();
+  }
+  if (mFullZoom != aZoom) {
+    mFullZoom = aZoom;
+    GetViewManager()->SetWindowDimensions(oldWidth / aZoom, oldHeight / aZoom);
+    ClearStyleDataAndReflow();
+  }
 }
 
 imgIRequest*
 nsPresContext::LoadImage(imgIRequest* aImage, nsIFrame* aTargetFrame)
 {
   // look and see if we have a loader for the target frame.
   nsCOMPtr<nsImageLoader> loader;
   mImageLoaders.Get(aTargetFrame, getter_AddRefs(loader));
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -462,17 +462,17 @@ public:
   nsIAtom* GetLangGroup() { return mLangGroup; }
 
   float TextZoom() { return mTextZoom; }
   void SetTextZoom(float aZoom) {
     mTextZoom = aZoom;
     ClearStyleDataAndReflow();
   }
 
-  float GetFullZoom() {return mDeviceContext->GetPixelScale();}
+  float GetFullZoom() { return mFullZoom; }
   void SetFullZoom(float aZoom);
 
   nscoord GetAutoQualityMinFontSize() {
     return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
   }
   
   static PRInt32 AppUnitsPerCSSPixel() { return nsIDeviceContext::AppUnitsPerCSSPixel(); }
   PRInt32 AppUnitsPerDevPixel() const  { return mDeviceContext->AppUnitsPerDevPixel(); }
@@ -754,16 +754,17 @@ protected:
 
   nsILinkHandler*       mLinkHandler;   // [WEAK]
   nsIAtom*              mLangGroup;     // [STRONG]
 
   nsInterfaceHashtable<nsVoidPtrHashKey, nsImageLoader> mImageLoaders;
   nsWeakPtr             mContainer;
 
   float                 mTextZoom;      // Text zoom, defaults to 1.0
+  float                 mFullZoom;      // Page zoom, defaults to 1.0
   PRInt32               mAutoQualityMinFontSizePixelsPref;
 
 #ifdef IBMBIDI
   nsBidiPresUtils*      mBidiUtils;
 #endif
 
   nsCOMPtr<nsITheme> mTheme;
   nsCOMPtr<nsILanguageAtomService> mLangService;