Allow removing iframe when it is being printed, r=roc

This commit is contained in:
Olli Pettay 2011-03-24 13:42:54 +02:00
parent 04b6972e10
commit 5590c58b15

View File

@ -440,6 +440,7 @@ protected:
// class, please make the ownership explicit (pinkerton, scc).
nsWeakPtr mContainer; // it owns me!
nsWeakPtr mTopContainerWhilePrinting;
nsCOMPtr<nsIDeviceContext> mDeviceContext; // We create and own this baby
// the following six items are explicitly in this order
@ -4085,22 +4086,24 @@ DocumentViewerImpl::SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode
PRBool aIsPrintingOrPP,
PRBool aStartAtTop)
{
NS_ASSERTION(aParentNode, "Parent can't be NULL!");
nsCOMPtr<nsIDocShellTreeItem> parentItem(do_QueryInterface(aParentNode));
// find top of "same parent" tree
if (aStartAtTop) {
while (parentItem) {
nsCOMPtr<nsIDocShellTreeItem> parent;
parentItem->GetSameTypeParent(getter_AddRefs(parent));
if (!parent) {
break;
if (aIsPrintingOrPP) {
while (parentItem) {
nsCOMPtr<nsIDocShellTreeItem> parent;
parentItem->GetSameTypeParent(getter_AddRefs(parent));
if (!parent) {
break;
}
parentItem = do_QueryInterface(parent);
}
parentItem = do_QueryInterface(parent);
mTopContainerWhilePrinting = do_GetWeakReference(parentItem);
} else {
parentItem = do_QueryReferent(mTopContainerWhilePrinting);
}
}
NS_ASSERTION(parentItem, "parentItem can't be null");
// Check to see if the DocShell's ContentViewer is printing/PP
nsCOMPtr<nsIContentViewerContainer> viewerContainer(do_QueryInterface(parentItem));
@ -4108,6 +4111,10 @@ DocumentViewerImpl::SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode
viewerContainer->SetIsPrinting(aIsPrintingOrPP);
}
if (!aParentNode) {
return;
}
// Traverse children to see if any of them are printing.
PRInt32 n;
aParentNode->GetChildCount(&n);
@ -4176,14 +4183,11 @@ DocumentViewerImpl::SetIsPrinting(PRBool aIsPrinting)
#ifdef NS_PRINTING
// Set all the docShells in the docshell tree to be printing.
// that way if anyone of them tries to "navigate" it can't
if (mContainer) {
nsCOMPtr<nsIDocShellTreeNode> docShellTreeNode(do_QueryReferent(mContainer));
NS_ASSERTION(docShellTreeNode, "mContainer has to be a nsIDocShellTreeNode");
if (docShellTreeNode) {
SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrinting, PR_TRUE);
} else {
NS_WARNING("Bug 549251 Did you close a window while printing?");
}
nsCOMPtr<nsIDocShellTreeNode> docShellTreeNode(do_QueryReferent(mContainer));
if (docShellTreeNode || !aIsPrinting) {
SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrinting, PR_TRUE);
} else {
NS_WARNING("Did you close a window before printing?");
}
#endif
}
@ -4211,9 +4215,8 @@ DocumentViewerImpl::SetIsPrintPreview(PRBool aIsPrintPreview)
#ifdef NS_PRINTING
// Set all the docShells in the docshell tree to be printing.
// that way if anyone of them tries to "navigate" it can't
if (mContainer) {
nsCOMPtr<nsIDocShellTreeNode> docShellTreeNode(do_QueryReferent(mContainer));
NS_ASSERTION(docShellTreeNode, "mContainer has to be a nsIDocShellTreeNode");
nsCOMPtr<nsIDocShellTreeNode> docShellTreeNode(do_QueryReferent(mContainer));
if (docShellTreeNode || !aIsPrintPreview) {
SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrintPreview, PR_TRUE);
}
#endif