Bug 577607 part 3. Use the main doc refresh driver for resource documents and the parent document's refresh driver for documents that are not roots of their type. r=roc, a=joe
☠☠ backed out by 06b4065f00be ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 11 Aug 2010 17:05:27 -0400
changeset 49572 b7900afb72e53a4ebeea30e03931999b2a531be4
parent 49571 0c4519d63a982f1e5943dcbd1320b516dd613957
child 49573 464f978cfca50ddf05085fd0f0e614b2b43d6c08
child 49581 06b4065f00be168cb38ec3fd66e272f1a5bdaca8
push idunknown
push userunknown
push dateunknown
reviewersroc, joe
bugs577607
milestone2.0b4pre
Bug 577607 part 3. Use the main doc refresh driver for resource documents and the parent document's refresh driver for documents that are not roots of their type. r=roc, a=joe
layout/base/nsPresContext.cpp
layout/base/nsPresShell.cpp
layout/base/nsRefreshDriver.h
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -259,17 +259,17 @@ nsPresContext::~nsPresContext()
   SetShell(nsnull);
 
   if (mTransitionManager) {
     mTransitionManager->Disconnect();
   }
 
   // Disconnect the refresh driver *after* the transition manager, which
   // needs it.
-  if (mRefreshDriver) {
+  if (mRefreshDriver && mRefreshDriver->PresContext() == this) {
     mRefreshDriver->Disconnect();
   }
 
   if (mEventManager) {
     // unclear if these are needed, but can't hurt
     mEventManager->NotifyDestroyPresContext(this);
     mEventManager->SetPresContext(nsnull);
 
@@ -886,19 +886,47 @@ nsPresContext::Init(nsIDeviceContext* aD
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(mEventManager);
 
   mTransitionManager = new nsTransitionManager(this);
   if (!mTransitionManager)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  mRefreshDriver = new nsRefreshDriver(this);
-  if (!mRefreshDriver)
-    return NS_ERROR_OUT_OF_MEMORY;
+  if (mDocument->GetDisplayDocument()) {
+    NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
+                 mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
+                 "Why are we being initialized?");
+    mRefreshDriver = mDocument->GetDisplayDocument()->GetShell()->
+      GetPresContext()->RefreshDriver();
+  } else {
+    nsIDocument* parent = mDocument->GetParentDocument();
+    if (parent) {
+      NS_ASSERTION(parent->GetShell() && parent->GetShell()->GetPresContext(),
+                   "How did we get a presshell?");
+
+      // We don't have our container set yet at this point
+      nsCOMPtr<nsISupports> ourContainer = mDocument->GetContainer();
+
+      nsCOMPtr<nsIDocShellTreeItem> ourItem = do_QueryInterface(ourContainer);
+      if (ourItem) {
+        nsCOMPtr<nsIDocShellTreeItem> parentItem;
+        ourItem->GetSameTypeParent(getter_AddRefs(parentItem));
+        if (parentItem) {
+          mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
+        }
+      }
+    }
+
+    if (!mRefreshDriver) {
+      mRefreshDriver = new nsRefreshDriver(this);
+      if (!mRefreshDriver)
+        return NS_ERROR_OUT_OF_MEMORY;
+    }
+  }
 
   mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
 
   // Register callbacks so we're notified when the preferences change
   nsContentUtils::RegisterPrefCallback("font.",
                                        nsPresContext::PrefChangedCallback,
                                        this);
   nsContentUtils::RegisterPrefCallback("browser.display.",
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -7262,17 +7262,18 @@ PresShell::Freeze()
     mCaret->SetCaretVisible(PR_FALSE);
 
   mPaintingSuppressed = PR_TRUE;
 
   if (mDocument)
     mDocument->EnumerateSubDocuments(FreezeSubDocument, nsnull);
 
   nsPresContext* presContext = GetPresContext();
-  if (presContext) {
+  if (presContext &&
+      presContext->RefreshDriver()->PresContext() == presContext) {
     presContext->RefreshDriver()->Freeze();
   }
 }
 
 void
 PresShell::FireOrClearDelayedEvents(PRBool aFireEvents)
 {
   mNoDelayedMouseEvents = PR_FALSE;
@@ -7315,17 +7316,18 @@ ThawSubDocument(nsIDocument *aDocument, 
 
   return PR_TRUE;
 }
 
 void
 PresShell::Thaw()
 {
   nsPresContext* presContext = GetPresContext();
-  if (presContext) {
+  if (presContext &&
+      presContext->RefreshDriver()->PresContext() == presContext) {
     presContext->RefreshDriver()->Thaw();
   }
 
   mDocument->EnumerateFreezableElements(ThawElement, this);
 
   if (mDocument)
     mDocument->EnumerateSubDocuments(ThawSubDocument, nsnull);
 
--- a/layout/base/nsRefreshDriver.h
+++ b/layout/base/nsRefreshDriver.h
@@ -157,16 +157,21 @@ public:
   void Freeze();
 
   /**
    * Thaw the refresh driver.  If needed, it should start delivering
    * refreshes again.
    */
   void Thaw();
 
+  /**
+   * Return the prescontext we were initialized with
+   */
+  nsPresContext* PresContext() const { return mPresContext; }
+
 #ifdef DEBUG
   /**
    * Check whether the given observer is an observer for the given flush type
    */
   PRBool IsRefreshObserver(nsARefreshObserver *aObserver,
 			   mozFlushType aFlushType);
 #endif