Bug 449734 part 3 - Update nsThebesDeviceContext::mWidget. r=roc a=blocking2.0:betaN
authorMats Palmgren <matspal@gmail.com>
Sat, 18 Sep 2010 13:28:50 +0200
changeset 54311 587c3e3d00801b83fe8cbcf03181368c03b4a450
parent 54310 f0993738b5990be7d4277f9b2c0bae802d877906
child 54312 6bcfca597af9db7ffc2ff7440dd0de3d83e56fd6
push id15843
push usermpalmgren@mozilla.com
push dateSat, 18 Sep 2010 11:29:47 +0000
treeherdermozilla-central@f1eec85dcfdc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, blocking2
bugs449734
milestone2.0b7pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 449734 part 3 - Update nsThebesDeviceContext::mWidget. r=roc a=blocking2.0:betaN
gfx/src/thebes/nsThebesDeviceContext.cpp
gfx/src/thebes/nsThebesDeviceContext.h
layout/generic/nsSubDocumentFrame.cpp
--- a/gfx/src/thebes/nsThebesDeviceContext.cpp
+++ b/gfx/src/thebes/nsThebesDeviceContext.cpp
@@ -283,20 +283,16 @@ nsThebesDeviceContext::nsThebesDeviceCon
     mAppUnitsPerPhysicalInch = nscoord(-1);
     mAppUnitsPerDevNotScaledPixel = nscoord(-1);
     mPixelScale = 1.0f;
 
     mFontCache = nsnull;
     mWidget = nsnull;
     mFontAliasTable = nsnull;
 
-#ifdef NS_DEBUG
-    mInitialized = PR_FALSE;
-#endif
-
     mDepth = 0;
     mWidth = 0;
     mHeight = 0;
     mPrintingScale = 1.0f;
 
 #if defined(XP_WIN) && !defined(WINCE)
     SCRIPT_DIGITSUBSTITUTE sds;
     ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &sds);
@@ -689,24 +685,24 @@ nsThebesDeviceContext::SetDPI()
     UpdateScaledAppUnits();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThebesDeviceContext::Init(nsIWidget *aWidget)
 {
+    if (mScreenManager && mWidget == aWidget)
+        return NS_OK;
+
     mWidget = aWidget;
-
     SetDPI();
 
-#ifdef NS_DEBUG
-    NS_ASSERTION(!mInitialized, "device context is initialized twice!");
-    mInitialized = PR_TRUE;
-#endif
+    if (mScreenManager)
+        return NS_OK;
 
     // register as a memory-pressure observer to free font resources
     // in low-memory situations.
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs)
         obs->AddObserver(this, "memory-pressure", PR_TRUE);
 
     mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
--- a/gfx/src/thebes/nsThebesDeviceContext.h
+++ b/gfx/src/thebes/nsThebesDeviceContext.h
@@ -155,19 +155,16 @@ protected:
     void CalcPrintingSize();
     void UpdateScaledAppUnits();
 
     PRUint32          mDepth;
     nsFontCache*      mFontCache;
     nsCOMPtr<nsIAtom> mLocaleLanguage; // XXX temp fix for performance bug
     nsHashtable*      mFontAliasTable;
     nsIWidget*        mWidget;
-#ifdef NS_DEBUG
-    PRBool            mInitialized;
-#endif
 
 private:
     nsCOMPtr<nsIScreenManager> mScreenManager;
 
     nscoord mWidth;
     nscoord mHeight;
 
     nsRefPtr<gfxASurface> mPrintingSurface;
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -53,17 +53,17 @@ using mozilla::layout::RenderFrameParent
 #include "nsGenericHTMLElement.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellLoadInfo.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeNode.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIBaseWindow.h"
 #include "nsIContentViewer.h"
-#include "nsIMarkupDocumentViewer.h"
+#include "nsIDocumentViewer.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIComponentManager.h"
 #include "nsFrameManager.h"
 #include "nsIStreamListener.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsIDocument.h"
@@ -933,16 +933,41 @@ nsSubDocumentFrame::BeginSwapDocShells(n
   return NS_OK;
 }
 
 static PRBool
 EndSwapDocShellsForDocument(nsIDocument* aDocument, void*)
 {
   NS_PRECONDITION(aDocument, "");
 
+  // Our docshell and view trees have been updated for the new hierarchy.
+  // Now also update all nsThebesDeviceContext::mWidget to that of the
+  // container view in the new hierarchy.
+  nsCOMPtr<nsISupports> container = aDocument->GetContainer();
+  nsCOMPtr<nsIDocShell> ds = do_QueryInterface(container);
+  if (ds) {
+    nsCOMPtr<nsIContentViewer> cv;
+    ds->GetContentViewer(getter_AddRefs(cv));
+    while (cv) {
+      nsCOMPtr<nsIDocumentViewer> dv = do_QueryInterface(cv);
+      if (dv) {
+        nsCOMPtr<nsPresContext> pc;
+        dv->GetPresContext(getter_AddRefs(pc));
+        nsIDeviceContext* dc = pc ? pc->DeviceContext() : nsnull;
+        if (dc) {
+          nsIView* v = dv->FindContainerView();
+          dc->Init(v ? v->GetNearestWidget(nsnull) : nsnull);
+        }
+      }
+      nsCOMPtr<nsIContentViewer> prev;
+      cv->GetPreviousViewer(getter_AddRefs(prev));
+      cv = prev;
+    }
+  }
+
   aDocument->EnumerateFreezableElements(
     nsObjectFrame::EndSwapDocShells, nsnull);
   aDocument->EnumerateSubDocuments(EndSwapDocShellsForDocument, nsnull);
   return PR_TRUE;
 }
 
 static void
 EndSwapDocShellsForViews(nsIView* aSibling)