From 8e4e35d00bc679bf7aa3edfb98cca3cbaaaa6bb5 Mon Sep 17 00:00:00 2001 From: "troy@netscape.com" Date: Mon, 18 Oct 1999 22:20:37 +0000 Subject: [PATCH] r=kipp@netscape.com Moved ownership of root frame (and frame hierarchy) over to the frame manager --- layout/base/nsFrameManager.cpp | 40 ++++++++- layout/base/nsPresShell.cpp | 106 ++++++++++++------------ layout/base/public/nsIFrameManager.h | 6 ++ layout/html/base/src/nsFrameManager.cpp | 40 ++++++++- layout/html/base/src/nsPresShell.cpp | 106 ++++++++++++------------ 5 files changed, 194 insertions(+), 104 deletions(-) diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index aaee9d1ff893..ad9e87d18c94 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -157,6 +157,10 @@ public: // nsIFrameManager NS_IMETHOD Init(nsIPresShell* aPresShell, nsIStyleSet* aStyleSet); + // Gets and sets the root frame + NS_IMETHOD GetRootFrame(nsIFrame** aRootFrame) const; + NS_IMETHOD SetRootFrame(nsIFrame* aRootFrame); + // Primary frame functions NS_IMETHOD GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aPrimaryFrame); NS_IMETHOD SetPrimaryFrameFor(nsIContent* aContent, @@ -255,6 +259,7 @@ private: nsIPresShell* mPresShell; // weak link, because the pres shell owns us nsIStyleSet* mStyleSet; // weak link. pres shell holds a reference + nsIFrame* mRootFrame; nsDST::NodeArena* mDSTNodeArena; // weak link. DST owns nsDST* mPrimaryFrameMap; FrameHashTable* mPlaceholderMap; @@ -312,10 +317,23 @@ FrameManager::~FrameManager() { // Revoke any events posted to the event queue that we haven't processed yet RevokePostedEvents(); - + delete mPrimaryFrameMap; delete mPlaceholderMap; delete mUndisplayedMap; + + // Destroy the frame hierarchy. Don't destroy the property lists until after + // we've destroyed the frame hierarchy because some frames may expect to be + // able to retrieve their properties during destruction + if (mRootFrame) { + nsIPresContext* presContext; + + mPresShell->GetPresContext(&presContext); + mRootFrame->Destroy(*presContext); + mRootFrame = nsnull; + NS_IF_RELEASE(presContext); + } + DestroyPropertyList(); } @@ -346,6 +364,26 @@ FrameManager::Init(nsIPresShell* aPresShell, return NS_OK; } +NS_IMETHODIMP +FrameManager::GetRootFrame(nsIFrame** aRootFrame) const +{ + NS_ENSURE_ARG_POINTER(aRootFrame); + *aRootFrame = mRootFrame; + return NS_OK; +} + +NS_IMETHODIMP +FrameManager::SetRootFrame(nsIFrame* aRootFrame) +{ + NS_PRECONDITION(!mRootFrame, "already have a root frame"); + if (mRootFrame) { + return NS_ERROR_UNEXPECTED; + } + + mRootFrame = aRootFrame; + return NS_OK; +} + //---------------------------------------------------------------------- // Primary frame functions diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 20c53f7832c7..1ff538465501 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -334,7 +334,6 @@ protected: nsCOMPtr mDocument; nsCOMPtr mPresContext; nsCOMPtr mStyleSet; - nsIFrame* mRootFrame; nsIViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to nsILayoutHistoryState* mHistoryState; // [WEAK] session history owns this PRUint32 mUpdateCount; @@ -371,13 +370,16 @@ private: #ifdef NS_DEBUG static void -VerifyStyleTree(nsIFrameManager* aFrameManager, nsIFrame* aFrame) +VerifyStyleTree(nsIFrameManager* aFrameManager) { - if (aFrameManager && aFrame && nsIFrame::GetVerifyStyleTreeEnable()) { - aFrameManager->DebugVerifyStyleTree(aFrame); + if (aFrameManager && nsIFrame::GetVerifyStyleTreeEnable()) { + nsIFrame* rootFrame; + + aFrameManager->GetRootFrame(&rootFrame); + aFrameManager->DebugVerifyStyleTree(rootFrame); } } -#define VERIFY_STYLE_TREE VerifyStyleTree(mFrameManager, mRootFrame) +#define VERIFY_STYLE_TREE VerifyStyleTree(mFrameManager) #else #define VERIFY_STYLE_TREE #endif @@ -538,13 +540,8 @@ PresShell::~PresShell() mViewManager = nsnull; } - // Destroy the frame manager before destroying the frame hierarchy. That way - // we won't waste time removing content->frame mappings for frames being - // destroyed + // Destroy the frame manager. This will destroy the frame hierarchy NS_IF_RELEASE(mFrameManager); - if (mRootFrame) { - mRootFrame->Destroy(*mPresContext); - } if (mDocument) { mDocument->DeleteShell(this); @@ -610,7 +607,10 @@ PresShell::Init(nsIDocument* aDocument, if (NS_FAILED(result)) { return result; } - mFrameManager->Init(this, mStyleSet); + result = mFrameManager->Init(this, mStyleSet); + if (NS_FAILED(result)) { + return result; + } nsCOMPtr domSelection; mSelection->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)); @@ -893,13 +893,19 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) root = mDocument->GetRootContent(); } + // Get the root frame from the frame manager + nsIFrame* rootFrame; + mFrameManager->GetRootFrame(&rootFrame); + if (nsnull != root) { RAPTOR_STOPWATCH_DEBUGTRACE(("Reset and start: Frame Creation: PresShell::InitialReflow(), this=%p\n", this)); NS_RESET_AND_START_STOPWATCH(mFrameCreationWatch) - if (nsnull == mRootFrame) { + + if (!rootFrame) { // Have style sheet processor construct a frame for the // precursors to the root content object's frame - mStyleSet->ConstructRootFrame(mPresContext, root, mRootFrame); + mStyleSet->ConstructRootFrame(mPresContext, root, rootFrame); + mFrameManager->SetRootFrame(rootFrame); } // Have the style sheet processor construct frame for the root @@ -911,7 +917,7 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) NS_STOP_STOPWATCH(mFrameCreationWatch) } - if (nsnull != mRootFrame) { + if (rootFrame) { RAPTOR_STOPWATCH_DEBUGTRACE(("Reset and start: Reflow: PresShell::InitialReflow(), this=%p\n", this)); NS_RESET_AND_START_STOPWATCH(mReflowWatch) // Kick off a top-down reflow @@ -919,7 +925,7 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) ("enter nsPresShell::InitialReflow: %d,%d", aWidth, aHeight)); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif #ifdef DEBUG_kipp @@ -933,19 +939,19 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) nsIHTMLReflow* htmlReflow; nsIRenderingContext* rcx = nsnull; - CreateRenderingContext(mRootFrame, &rcx); + CreateRenderingContext(rootFrame, &rcx); - nsHTMLReflowState reflowState(*mPresContext, mRootFrame, + nsHTMLReflowState reflowState(*mPresContext, rootFrame, eReflowReason_Initial, rcx, maxSize); - if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { + if (NS_OK == rootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); - mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + rootFrame->SizeTo(desiredSize.width, desiredSize.height); mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width,desiredSize.height)); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif VERIFY_STYLE_TREE; @@ -991,13 +997,15 @@ PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight) // If we don't have a root frame yet, that means we haven't had our initial // reflow... - if (nsnull != mRootFrame) { + nsIFrame* rootFrame; + mFrameManager->GetRootFrame(&rootFrame); + if (rootFrame) { // Kick off a top-down reflow NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("enter nsPresShell::ResizeReflow: %d,%d", aWidth, aHeight)); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif #ifdef DEBUG_kipp @@ -1011,17 +1019,17 @@ PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight) nsIHTMLReflow* htmlReflow; nsIRenderingContext* rcx = nsnull; - CreateRenderingContext(mRootFrame, &rcx); + CreateRenderingContext(rootFrame, &rcx); - nsHTMLReflowState reflowState(*mPresContext, mRootFrame, + nsHTMLReflowState reflowState(*mPresContext, rootFrame, eReflowReason_Resize, rcx, maxSize); - if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { + if (NS_OK == rootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); - mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + rootFrame->SizeTo(desiredSize.width, desiredSize.height); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif VERIFY_STYLE_TREE; @@ -1134,13 +1142,15 @@ PresShell::StyleChangeReflow() { EnterReflowLock(); - if (nsnull != mRootFrame) { + nsIFrame* rootFrame; + mFrameManager->GetRootFrame(&rootFrame); + if (rootFrame) { // Kick off a top-down reflow NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("enter nsPresShell::StyleChangeReflow")); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif nsRect bounds; @@ -1151,18 +1161,18 @@ PresShell::StyleChangeReflow() nsIHTMLReflow* htmlReflow; nsIRenderingContext* rcx = nsnull; - CreateRenderingContext(mRootFrame, &rcx); + CreateRenderingContext(rootFrame, &rcx); // XXX We should be using eReflowReason_StyleChange - nsHTMLReflowState reflowState(*mPresContext, mRootFrame, + nsHTMLReflowState reflowState(*mPresContext, rootFrame, eReflowReason_Resize, rcx, maxSize); - if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { + if (NS_OK == rootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); - mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + rootFrame->SizeTo(desiredSize.width, desiredSize.height); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif VERIFY_STYLE_TREE; @@ -1179,12 +1189,7 @@ PresShell::StyleChangeReflow() NS_IMETHODIMP PresShell::GetRootFrame(nsIFrame** aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } - *aResult = mRootFrame; - return NS_OK; + return mFrameManager->GetRootFrame(aResult); } NS_IMETHODIMP @@ -1195,12 +1200,14 @@ PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const return NS_ERROR_NULL_POINTER; } + nsIFrame* rootFrame; nsIFrame* child; nsIPageSequenceFrame* pageSequence; // The page sequence frame should be either the immediate child or // its child - mRootFrame->FirstChild(nsnull, &child); + mFrameManager->GetRootFrame(&rootFrame); + rootFrame->FirstChild(nsnull, &child); if (nsnull != child) { if (NS_SUCCEEDED(child->QueryInterface(kIPageSequenceFrameIID, (void**)&pageSequence))) { *aResult = pageSequence; @@ -1350,7 +1357,10 @@ PresShell::ProcessReflowCommands() if (0 != mReflowCommands.Count()) { nsHTMLReflowMetrics desiredSize(nsnull); nsIRenderingContext* rcx; - CreateRenderingContext(mRootFrame, &rcx); + nsIFrame* rootFrame; + + mFrameManager->GetRootFrame(&rootFrame); + CreateRenderingContext(rootFrame, &rcx); #ifdef DEBUG if (GetVerifyReflowEnable()) { @@ -1376,7 +1386,7 @@ PresShell::ProcessReflowCommands() // Dispatch the reflow command nsSize maxSize; - mRootFrame->GetSize(maxSize); + rootFrame->GetSize(maxSize); rc->Dispatch(*mPresContext, desiredSize, maxSize, *rcx); NS_RELEASE(rc); VERIFY_STYLE_TREE; @@ -1385,7 +1395,7 @@ PresShell::ProcessReflowCommands() #ifdef DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } if (GetVerifyReflowEnable()) { // First synchronously render what we have so far so that we can @@ -1751,8 +1761,6 @@ PresShell::ContentChanged(nsIDocument *aDocument, nsIContent* aContent, nsISupports* aSubContent) { - NS_PRECONDITION(nsnull != mRootFrame, "null root frame"); - EnterReflowLock(); nsresult rv = mStyleSet->ContentChanged(mPresContext, aContent, aSubContent); VERIFY_STYLE_TREE; @@ -1766,8 +1774,6 @@ PresShell::ContentStatesChanged(nsIDocument* aDocument, nsIContent* aContent1, nsIContent* aContent2) { - NS_PRECONDITION(nsnull != mRootFrame, "null root frame"); - EnterReflowLock(); nsresult rv = mStyleSet->ContentStatesChanged(mPresContext, aContent1, aContent2); VERIFY_STYLE_TREE; @@ -1784,8 +1790,6 @@ PresShell::AttributeChanged(nsIDocument *aDocument, nsIAtom* aAttribute, PRInt32 aHint) { - NS_PRECONDITION(nsnull != mRootFrame, "null root frame"); - EnterReflowLock(); nsresult rv = mStyleSet->AttributeChanged(mPresContext, aContent, aNameSpaceID, aAttribute, aHint); VERIFY_STYLE_TREE; diff --git a/layout/base/public/nsIFrameManager.h b/layout/base/public/nsIFrameManager.h index a7781b096282..710a9a3e14e5 100644 --- a/layout/base/public/nsIFrameManager.h +++ b/layout/base/public/nsIFrameManager.h @@ -57,6 +57,12 @@ public: // Initialization NS_IMETHOD Init(nsIPresShell* aPresShell, nsIStyleSet* aStyleSet) = 0; + // Gets and sets the root frame (typically the viewport). The lifetime of the + // root frame is controlled by the frame manager. When the frame manager is + // destroyed it destroys the entire frame hierarchy + NS_IMETHOD GetRootFrame(nsIFrame** aRootFrame) const = 0; + NS_IMETHOD SetRootFrame(nsIFrame* aRootFrame) = 0; + // Primary frame functions NS_IMETHOD GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aPrimaryFrame) = 0; NS_IMETHOD SetPrimaryFrameFor(nsIContent* aContent, diff --git a/layout/html/base/src/nsFrameManager.cpp b/layout/html/base/src/nsFrameManager.cpp index aaee9d1ff893..ad9e87d18c94 100644 --- a/layout/html/base/src/nsFrameManager.cpp +++ b/layout/html/base/src/nsFrameManager.cpp @@ -157,6 +157,10 @@ public: // nsIFrameManager NS_IMETHOD Init(nsIPresShell* aPresShell, nsIStyleSet* aStyleSet); + // Gets and sets the root frame + NS_IMETHOD GetRootFrame(nsIFrame** aRootFrame) const; + NS_IMETHOD SetRootFrame(nsIFrame* aRootFrame); + // Primary frame functions NS_IMETHOD GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aPrimaryFrame); NS_IMETHOD SetPrimaryFrameFor(nsIContent* aContent, @@ -255,6 +259,7 @@ private: nsIPresShell* mPresShell; // weak link, because the pres shell owns us nsIStyleSet* mStyleSet; // weak link. pres shell holds a reference + nsIFrame* mRootFrame; nsDST::NodeArena* mDSTNodeArena; // weak link. DST owns nsDST* mPrimaryFrameMap; FrameHashTable* mPlaceholderMap; @@ -312,10 +317,23 @@ FrameManager::~FrameManager() { // Revoke any events posted to the event queue that we haven't processed yet RevokePostedEvents(); - + delete mPrimaryFrameMap; delete mPlaceholderMap; delete mUndisplayedMap; + + // Destroy the frame hierarchy. Don't destroy the property lists until after + // we've destroyed the frame hierarchy because some frames may expect to be + // able to retrieve their properties during destruction + if (mRootFrame) { + nsIPresContext* presContext; + + mPresShell->GetPresContext(&presContext); + mRootFrame->Destroy(*presContext); + mRootFrame = nsnull; + NS_IF_RELEASE(presContext); + } + DestroyPropertyList(); } @@ -346,6 +364,26 @@ FrameManager::Init(nsIPresShell* aPresShell, return NS_OK; } +NS_IMETHODIMP +FrameManager::GetRootFrame(nsIFrame** aRootFrame) const +{ + NS_ENSURE_ARG_POINTER(aRootFrame); + *aRootFrame = mRootFrame; + return NS_OK; +} + +NS_IMETHODIMP +FrameManager::SetRootFrame(nsIFrame* aRootFrame) +{ + NS_PRECONDITION(!mRootFrame, "already have a root frame"); + if (mRootFrame) { + return NS_ERROR_UNEXPECTED; + } + + mRootFrame = aRootFrame; + return NS_OK; +} + //---------------------------------------------------------------------- // Primary frame functions diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index 20c53f7832c7..1ff538465501 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -334,7 +334,6 @@ protected: nsCOMPtr mDocument; nsCOMPtr mPresContext; nsCOMPtr mStyleSet; - nsIFrame* mRootFrame; nsIViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to nsILayoutHistoryState* mHistoryState; // [WEAK] session history owns this PRUint32 mUpdateCount; @@ -371,13 +370,16 @@ private: #ifdef NS_DEBUG static void -VerifyStyleTree(nsIFrameManager* aFrameManager, nsIFrame* aFrame) +VerifyStyleTree(nsIFrameManager* aFrameManager) { - if (aFrameManager && aFrame && nsIFrame::GetVerifyStyleTreeEnable()) { - aFrameManager->DebugVerifyStyleTree(aFrame); + if (aFrameManager && nsIFrame::GetVerifyStyleTreeEnable()) { + nsIFrame* rootFrame; + + aFrameManager->GetRootFrame(&rootFrame); + aFrameManager->DebugVerifyStyleTree(rootFrame); } } -#define VERIFY_STYLE_TREE VerifyStyleTree(mFrameManager, mRootFrame) +#define VERIFY_STYLE_TREE VerifyStyleTree(mFrameManager) #else #define VERIFY_STYLE_TREE #endif @@ -538,13 +540,8 @@ PresShell::~PresShell() mViewManager = nsnull; } - // Destroy the frame manager before destroying the frame hierarchy. That way - // we won't waste time removing content->frame mappings for frames being - // destroyed + // Destroy the frame manager. This will destroy the frame hierarchy NS_IF_RELEASE(mFrameManager); - if (mRootFrame) { - mRootFrame->Destroy(*mPresContext); - } if (mDocument) { mDocument->DeleteShell(this); @@ -610,7 +607,10 @@ PresShell::Init(nsIDocument* aDocument, if (NS_FAILED(result)) { return result; } - mFrameManager->Init(this, mStyleSet); + result = mFrameManager->Init(this, mStyleSet); + if (NS_FAILED(result)) { + return result; + } nsCOMPtr domSelection; mSelection->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)); @@ -893,13 +893,19 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) root = mDocument->GetRootContent(); } + // Get the root frame from the frame manager + nsIFrame* rootFrame; + mFrameManager->GetRootFrame(&rootFrame); + if (nsnull != root) { RAPTOR_STOPWATCH_DEBUGTRACE(("Reset and start: Frame Creation: PresShell::InitialReflow(), this=%p\n", this)); NS_RESET_AND_START_STOPWATCH(mFrameCreationWatch) - if (nsnull == mRootFrame) { + + if (!rootFrame) { // Have style sheet processor construct a frame for the // precursors to the root content object's frame - mStyleSet->ConstructRootFrame(mPresContext, root, mRootFrame); + mStyleSet->ConstructRootFrame(mPresContext, root, rootFrame); + mFrameManager->SetRootFrame(rootFrame); } // Have the style sheet processor construct frame for the root @@ -911,7 +917,7 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) NS_STOP_STOPWATCH(mFrameCreationWatch) } - if (nsnull != mRootFrame) { + if (rootFrame) { RAPTOR_STOPWATCH_DEBUGTRACE(("Reset and start: Reflow: PresShell::InitialReflow(), this=%p\n", this)); NS_RESET_AND_START_STOPWATCH(mReflowWatch) // Kick off a top-down reflow @@ -919,7 +925,7 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) ("enter nsPresShell::InitialReflow: %d,%d", aWidth, aHeight)); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif #ifdef DEBUG_kipp @@ -933,19 +939,19 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) nsIHTMLReflow* htmlReflow; nsIRenderingContext* rcx = nsnull; - CreateRenderingContext(mRootFrame, &rcx); + CreateRenderingContext(rootFrame, &rcx); - nsHTMLReflowState reflowState(*mPresContext, mRootFrame, + nsHTMLReflowState reflowState(*mPresContext, rootFrame, eReflowReason_Initial, rcx, maxSize); - if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { + if (NS_OK == rootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); - mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + rootFrame->SizeTo(desiredSize.width, desiredSize.height); mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width,desiredSize.height)); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif VERIFY_STYLE_TREE; @@ -991,13 +997,15 @@ PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight) // If we don't have a root frame yet, that means we haven't had our initial // reflow... - if (nsnull != mRootFrame) { + nsIFrame* rootFrame; + mFrameManager->GetRootFrame(&rootFrame); + if (rootFrame) { // Kick off a top-down reflow NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("enter nsPresShell::ResizeReflow: %d,%d", aWidth, aHeight)); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif #ifdef DEBUG_kipp @@ -1011,17 +1019,17 @@ PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight) nsIHTMLReflow* htmlReflow; nsIRenderingContext* rcx = nsnull; - CreateRenderingContext(mRootFrame, &rcx); + CreateRenderingContext(rootFrame, &rcx); - nsHTMLReflowState reflowState(*mPresContext, mRootFrame, + nsHTMLReflowState reflowState(*mPresContext, rootFrame, eReflowReason_Resize, rcx, maxSize); - if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { + if (NS_OK == rootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); - mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + rootFrame->SizeTo(desiredSize.width, desiredSize.height); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif VERIFY_STYLE_TREE; @@ -1134,13 +1142,15 @@ PresShell::StyleChangeReflow() { EnterReflowLock(); - if (nsnull != mRootFrame) { + nsIFrame* rootFrame; + mFrameManager->GetRootFrame(&rootFrame); + if (rootFrame) { // Kick off a top-down reflow NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("enter nsPresShell::StyleChangeReflow")); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif nsRect bounds; @@ -1151,18 +1161,18 @@ PresShell::StyleChangeReflow() nsIHTMLReflow* htmlReflow; nsIRenderingContext* rcx = nsnull; - CreateRenderingContext(mRootFrame, &rcx); + CreateRenderingContext(rootFrame, &rcx); // XXX We should be using eReflowReason_StyleChange - nsHTMLReflowState reflowState(*mPresContext, mRootFrame, + nsHTMLReflowState reflowState(*mPresContext, rootFrame, eReflowReason_Resize, rcx, maxSize); - if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { + if (NS_OK == rootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); - mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + rootFrame->SizeTo(desiredSize.width, desiredSize.height); #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } #endif VERIFY_STYLE_TREE; @@ -1179,12 +1189,7 @@ PresShell::StyleChangeReflow() NS_IMETHODIMP PresShell::GetRootFrame(nsIFrame** aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } - *aResult = mRootFrame; - return NS_OK; + return mFrameManager->GetRootFrame(aResult); } NS_IMETHODIMP @@ -1195,12 +1200,14 @@ PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const return NS_ERROR_NULL_POINTER; } + nsIFrame* rootFrame; nsIFrame* child; nsIPageSequenceFrame* pageSequence; // The page sequence frame should be either the immediate child or // its child - mRootFrame->FirstChild(nsnull, &child); + mFrameManager->GetRootFrame(&rootFrame); + rootFrame->FirstChild(nsnull, &child); if (nsnull != child) { if (NS_SUCCEEDED(child->QueryInterface(kIPageSequenceFrameIID, (void**)&pageSequence))) { *aResult = pageSequence; @@ -1350,7 +1357,10 @@ PresShell::ProcessReflowCommands() if (0 != mReflowCommands.Count()) { nsHTMLReflowMetrics desiredSize(nsnull); nsIRenderingContext* rcx; - CreateRenderingContext(mRootFrame, &rcx); + nsIFrame* rootFrame; + + mFrameManager->GetRootFrame(&rootFrame); + CreateRenderingContext(rootFrame, &rcx); #ifdef DEBUG if (GetVerifyReflowEnable()) { @@ -1376,7 +1386,7 @@ PresShell::ProcessReflowCommands() // Dispatch the reflow command nsSize maxSize; - mRootFrame->GetSize(maxSize); + rootFrame->GetSize(maxSize); rc->Dispatch(*mPresContext, desiredSize, maxSize, *rcx); NS_RELEASE(rc); VERIFY_STYLE_TREE; @@ -1385,7 +1395,7 @@ PresShell::ProcessReflowCommands() #ifdef DEBUG if (nsIFrame::GetVerifyTreeEnable()) { - mRootFrame->VerifyTree(); + rootFrame->VerifyTree(); } if (GetVerifyReflowEnable()) { // First synchronously render what we have so far so that we can @@ -1751,8 +1761,6 @@ PresShell::ContentChanged(nsIDocument *aDocument, nsIContent* aContent, nsISupports* aSubContent) { - NS_PRECONDITION(nsnull != mRootFrame, "null root frame"); - EnterReflowLock(); nsresult rv = mStyleSet->ContentChanged(mPresContext, aContent, aSubContent); VERIFY_STYLE_TREE; @@ -1766,8 +1774,6 @@ PresShell::ContentStatesChanged(nsIDocument* aDocument, nsIContent* aContent1, nsIContent* aContent2) { - NS_PRECONDITION(nsnull != mRootFrame, "null root frame"); - EnterReflowLock(); nsresult rv = mStyleSet->ContentStatesChanged(mPresContext, aContent1, aContent2); VERIFY_STYLE_TREE; @@ -1784,8 +1790,6 @@ PresShell::AttributeChanged(nsIDocument *aDocument, nsIAtom* aAttribute, PRInt32 aHint) { - NS_PRECONDITION(nsnull != mRootFrame, "null root frame"); - EnterReflowLock(); nsresult rv = mStyleSet->AttributeChanged(mPresContext, aContent, aNameSpaceID, aAttribute, aHint); VERIFY_STYLE_TREE;