nsRect area = mPresContext->GetVisibleArea();
DocumentViewerImpl::ReturnToGalleyPresentation(){#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)  if (!GetIsPrintPreview()) {    NS_ASSERTION(0, "Wow, we should never get here!");    return;  }  // Get the current size of what is being viewed  nsRect area = mPresContext->GetVisibleArea();  nsRect bounds;  mWindow->GetBounds(bounds);  // In case we have focus focus the parent DocShell  // which in this case should always be chrome  nsCOMPtr<nsIDocShellTreeItem>  dstParentItem;  nsCOMPtr<nsIDocShellTreeItem>  dstItem(do_QueryInterface(mContainer));  if (dstItem) {    dstItem->GetParent(getter_AddRefs(dstParentItem));    nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(dstParentItem));    if (docShell) {      docShell->SetHasFocus(PR_TRUE);    }  }  // Start to kill off the old Presentation  // by cleaning up the PresShell  if (mPresShell) {    // Break circular reference (or something)    mPresShell->EndObservingDocument();    nsCOMPtr<nsISelection> selection;    nsresult rv = GetDocumentSelection(getter_AddRefs(selection));    nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));    if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener)      selPrivate->RemoveSelectionListener(mSelectionListener);    mPresShell->Destroy();  }  // clear weak references before we go away  if (mPresContext) {    mPresContext->SetContainer(nsnull);    mPresContext->SetLinkHandler(nsnull);  }  //------------------------------------------------  // NOTE:  // Here is why the code below is a little confusing:  //   1) Scripting needs to be turned back on before   //      the print engine is destroyed  //   2) The PrintEngine must be destroyed BEFORE   //      calling InitInternal when caching documents (framesets)  //      BUT the PrintEngine must be destroyed AFTER   //      calling InitInternal when NOT caching documents (no framesets)  //------------------------------------------------  // wasCached will be used below to indicate whether the   // InitInternal should create all new objects or just  // initialize the existing ones  PRBool wasCached = PR_FALSE;  if (mPrintEngine && mPrintEngine->HasCachedPres()) {    mPrintEngine->GetCachedPresentation(mPresShell, mPresContext, mViewManager, mWindow);    // Tell the "real" presshell to start observing the document    // again.    mPresShell->BeginObservingDocument();    mWindow->Show(PR_TRUE);    wasCached = PR_TRUE;  } else {    // Destroy the old Presentation    mPresShell    = nsnull;    mPresContext  = nsnull;    mViewManager  = nsnull;    mWindow       = nsnull;  }  if (mPrintEngine) {    // Very important! Turn On scripting    mPrintEngine->TurnScriptingOn(PR_TRUE);    if (wasCached) {      mPrintEngine->Destroy();      NS_RELEASE(mPrintEngine);    }  }  InitInternal(mParentWidget, mDeviceContext, bounds, !wasCached, PR_TRUE);  if (mPrintEngine && !wasCached) {    mPrintEngine->Destroy();    NS_RELEASE(mPrintEngine);  }  // this needs to be set here not earlier,  // because it is needing when re-constructing the Galley Mode)  SetIsPrintPreview(PR_FALSE);  mViewManager->EnableRefresh(NS_VMREFRESH_NO_SYNC);  Show();#endif // NS_PRINTING && NS_PRINT_PREVIEW}