Bug 581536 part 0. Change SetDocumentInternal to share the normal prescontext/presshell initialization codepath. r=dbaron

This commit is contained in:
Boris Zbarsky
2011-01-21 14:09:11 -05:00
parent aa61e777cd
commit aacda4fd6c

View File

@@ -377,12 +377,16 @@ private:
/**
* If aDoCreation is true, this creates the device context, creates a
* prescontext if necessary, and calls MakeWindow.
*
* If aForceSetNewDocument is false, then SetNewDocument won't be
* called if the window's current document is already mDocument.
*/
nsresult InitInternal(nsIWidget* aParentWidget,
nsISupports *aState,
const nsIntRect& aBounds,
PRBool aDoCreation,
PRBool aNeedMakeCX = PR_TRUE);
PRBool aNeedMakeCX = PR_TRUE,
PRBool aForceSetNewDocument = PR_TRUE);
/**
* @param aDoInitialReflow set to true if you want to kick off the initial
* reflow
@@ -400,6 +404,7 @@ private:
nsresult GetDocumentSelection(nsISelection **aSelection);
void DestroyPresShell();
void DestroyPresContext();
#ifdef NS_PRINTING
// Called when the DocViewer is notified that the state
@@ -832,8 +837,15 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
nsISupports *aState,
const nsIntRect& aBounds,
PRBool aDoCreation,
PRBool aNeedMakeCX /*= PR_TRUE*/)
PRBool aNeedMakeCX /*= PR_TRUE*/,
PRBool aForceSetNewDocument /* = PR_TRUE*/)
{
if (mIsPageMode) {
// XXXbz should the InitInternal in SetPageMode just pass PR_FALSE
// here itself?
aForceSetNewDocument = PR_FALSE;
}
// We don't want any scripts to run here. That can cause flushing,
// which can cause reentry into initialization of this document viewer,
// which would be disastrous.
@@ -952,7 +964,7 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
if (window) {
nsCOMPtr<nsIDocument> curDoc =
do_QueryInterface(window->GetExtantDocument());
if (!mIsPageMode || curDoc != mDocument) {
if (aForceSetNewDocument || curDoc != mDocument) {
window->SetNewDocument(mDocument, aState, PR_FALSE);
nsJSContext::LoadStart();
}
@@ -1623,9 +1635,7 @@ DocumentViewerImpl::Destroy()
}
if (mPresContext) {
mPresContext->SetContainer(nsnull);
mPresContext->SetLinkHandler(nsnull);
mPresContext = nsnull;
DestroyPresContext();
}
mWindow = nsnull;
@@ -1714,7 +1724,7 @@ DocumentViewerImpl::SetDocumentInternal(nsIDocument* aDocument,
window->SetNewDocument(aDocument, nsnull, aForceReuseInnerWindow);
}
// Clear the list of old child docshells. CChild docshells for the new
// Clear the list of old child docshells. Child docshells for the new
// document will be constructed as frames are created.
if (!aDocument->IsStaticDocument()) {
nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(container);
@@ -1735,37 +1745,14 @@ DocumentViewerImpl::SetDocumentInternal(nsIDocument* aDocument,
// Replace the current pres shell with a new shell for the new document
nsCOMPtr<nsILinkHandler> linkHandler;
if (mPresShell) {
nsSize currentSize(0, 0);
if (mViewManager) {
mViewManager->GetWindowDimensions(&currentSize.width, &currentSize.height);
}
if (mPresContext) {
// Save the linkhandler (nsPresShell::Destroy removes it from
// mPresContext).
linkHandler = mPresContext->GetLinkHandler();
}
DestroyPresShell();
nsIView* containerView = FindContainerView();
// This destroys the root view because it was associated with the root frame,
// which has been torn down. Recreate the viewmanager and root view.
MakeWindow(currentSize, containerView);
}
// And if we're already given a prescontext...
if (mPresContext) {
// If we had a linkHandler and it got removed, put it back.
if (linkHandler) {
mPresContext->SetLinkHandler(linkHandler);
}
DestroyPresContext();
rv = InitPresentationStuff(PR_FALSE);
InitInternal(mParentWidget, nsnull, mBounds, PR_TRUE, PR_TRUE, PR_FALSE);
}
return rv;
@@ -2048,11 +2035,8 @@ DocumentViewerImpl::Hide(void)
DestroyPresShell();
// Clear weak refs
mPresContext->SetContainer(nsnull);
mPresContext->SetLinkHandler(nsnull);
DestroyPresContext();
mPresContext = nsnull;
mViewManager = nsnull;
mWindow = nsnull;
mDeviceContext = nsnull;
@@ -4230,12 +4214,9 @@ NS_IMETHODIMP DocumentViewerImpl::SetPageMode(PRBool aPageMode, nsIPrintSettings
}
if (mPresContext) {
mPresContext->SetContainer(nsnull);
mPresContext->SetLinkHandler(nsnull);
DestroyPresContext();
}
mPresShell = nsnull;
mPresContext = nsnull;
mViewManager = nsnull;
mWindow = nsnull;
@@ -4280,6 +4261,14 @@ DocumentViewerImpl::DestroyPresShell()
mPresShell = nsnull;
}
void
DocumentViewerImpl::DestroyPresContext()
{
mPresContext->SetContainer(nsnull);
mPresContext->SetLinkHandler(nsnull);
mPresContext = nsnull;
}
PRBool
DocumentViewerImpl::IsInitializedForPrintPreview()
{