Bug 794579. Remove view from existing parent before setting it as the root view. r=tnikkel
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 02 Oct 2012 16:25:47 -0500
changeset 108945 9b9bf8702da4f76bc5e9fcfb5c58ec376529fb01
parent 108944 a0ee436cc856ecfc14a3ff3917fc486ffbb9e65a
child 108946 95c8501bbefbd7ffc618d46264386fdde0de27dc
push id15773
push usertnikkel@gmail.com
push dateTue, 02 Oct 2012 21:26:05 +0000
treeherdermozilla-inbound@9b9bf8702da4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs794579
milestone18.0a1
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 794579. Remove view from existing parent before setting it as the root view. r=tnikkel
layout/printing/nsPrintEngine.cpp
view/src/nsView.h
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2128,19 +2128,21 @@ nsPrintEngine::SetRootView(
   } else {
     nscoord pageWidth, pageHeight;
     mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
     adjSize = nsSize(pageWidth, pageHeight);
     documentIsTopLevel = true;
     parentView = GetParentViewForRoot();
   }
 
-  if (aPO->mPresShell->GetViewManager()->GetRootView()) {
+  if (aPO->mViewManager->GetRootView()) {
     // Reuse the root view that is already on the root frame.
-    rootView = aPO->mPresShell->GetRootFrame()->GetView();
+    rootView = aPO->mViewManager->GetRootView();
+    // Remove it from its existing parent if necessary
+    aPO->mViewManager->RemoveChild(rootView);
     reinterpret_cast<nsView*>(rootView)->SetParent(reinterpret_cast<nsView*>(parentView));
   } else {
     // Create a child window of the parent that is our "root view/window"
     nsRect tbounds = nsRect(nsPoint(0, 0), adjSize);
     rootView = aPO->mViewManager->CreateView(tbounds, parentView);
     NS_ENSURE_TRUE(rootView, NS_ERROR_OUT_OF_MEMORY);
   }
     
--- a/view/src/nsView.h
+++ b/view/src/nsView.h
@@ -133,17 +133,21 @@ public:
     }
     return mDirtyRegion;
   }
 
   void InsertChild(nsView *aChild, nsView *aSibling);
   void RemoveChild(nsView *aChild);
 
   void SetParent(nsView *aParent) { mParent = aParent; }
-  void SetNextSibling(nsView *aSibling) { mNextSibling = aSibling; }
+  void SetNextSibling(nsView *aSibling)
+  {
+    NS_ASSERTION(aSibling != this, "Can't be our own sibling!");
+    mNextSibling = aSibling;
+  }
 
   uint32_t GetViewFlags() const { return mVFlags; }
   void SetViewFlags(uint32_t aFlags) { mVFlags = aFlags; }
 
   void SetTopMost(bool aTopMost) { aTopMost ? mVFlags |= NS_VIEW_FLAG_TOPMOST : mVFlags &= ~NS_VIEW_FLAG_TOPMOST; }
   bool IsTopMost() { return((mVFlags & NS_VIEW_FLAG_TOPMOST) != 0); }
 
   void ResetWidgetBounds(bool aRecurse, bool aForceSync);