diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 1216668f9a5..4ad12709754 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -4713,10 +4713,48 @@ DocumentViewerImpl::TurnScriptingOn(PRBool aDoTurnOn) scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE); } +//---------------------------------------------------------------------- +static nsresult GetSeqFrameAndCountPages(PrintObject* aPO, + nsIFrame*& aSeqFrame, + PRInt32& aCount) +{ + NS_ENSURE_ARG_POINTER(aPO); + + // Finds the SimplePageSequencer frame + // in PP mPrtPreview->mPrintObject->mSeqFrame is null + nsIFrame* curFrame; + aSeqFrame = nsnull; + aPO->mPresShell->GetRootFrame(&curFrame); + while (curFrame != nsnull) { + nsIPageSequenceFrame * sqf = nsnull; + if (NS_SUCCEEDED(CallQueryInterface(curFrame, &sqf)) && sqf) { + aSeqFrame = curFrame; + break; + } + curFrame->FirstChild(aPO->mPresContext, nsnull, &curFrame); + } + if (aSeqFrame == nsnull) return NS_ERROR_FAILURE; + + // first count the total number of pages + aCount = 0; + nsIFrame * pageFrame; + aSeqFrame->FirstChild(aPO->mPresContext, nsnull, &pageFrame); + while (pageFrame != nsnull) { + aCount++; + pageFrame->GetNextSibling(&pageFrame); + } + + return NS_OK; + +} + //---------------------------------------------------------------------- NS_IMETHODIMP DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) { +#ifdef NS_PRINT_PREVIEW + if (!mPrtPreview) return NS_ERROR_FAILURE; + nsIScrollableView* scrollableView; mViewManager->GetRootScrollableView(&scrollableView); if (scrollableView == nsnull) return NS_OK; @@ -4730,18 +4768,11 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) // Finds the SimplePageSequencer frame // in PP mPrtPreview->mPrintObject->mSeqFrame is null - nsIFrame* rootFrame; nsIFrame* seqFrame = nsnull; - mPrtPreview->mPrintObject->mPresShell->GetRootFrame(&rootFrame); - while (rootFrame != nsnull) { - nsIPageSequenceFrame * sqf = nsnull; - if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf)) && sqf) { - seqFrame = rootFrame; - break; - } - rootFrame->FirstChild(mPrtPreview->mPrintObject->mPresContext, nsnull, &rootFrame); + PRInt32 pageCount = 0; + if (NS_FAILED(GetSeqFrameAndCountPages(mPrtPreview->mPrintObject, seqFrame, pageCount))) { + return NS_ERROR_FAILURE; } - if (seqFrame == nsnull) return NS_OK; // Figure where we are currently scrolled to const nsIView * clippedView; @@ -4751,18 +4782,9 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) scrollableView->GetScrollPosition(x, y); PRInt32 pageNum = 1; - nsIFrame * pageFrame; nsIFrame * fndPageFrame = nsnull; nsIFrame * currentPage = nsnull; - // first count the total number of pages - PRInt32 pageCount = 0; - seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); - while (pageFrame != nsnull) { - pageCount++; - pageFrame->GetNextSibling(&pageFrame); - } - // If it is "End" then just do a "goto" to the last page if (aType == nsIWebBrowserPrint::PRINTPREVIEW_END) { aType = nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM; @@ -4772,6 +4794,7 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) // Now, locate the current page we are on and // and the page of the page number nscoord gap = 0; + nsIFrame * pageFrame; seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); while (pageFrame != nsnull) { nsRect pageRect; @@ -4824,9 +4847,17 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) nsIView * view; fndPageFrame->GetOffsetFromView(mPresContext, pnt, &view); - // scroll so that top of page is at the top of the scroll area - scrollableView->ScrollTo(pnt.x, fRect.y, PR_TRUE); + nscoord deadSpaceGap = 0; + nsIPageSequenceFrame * sqf; + if (NS_SUCCEEDED(CallQueryInterface(seqFrame, &sqf))) { + sqf->GetDeadSpaceValue(&deadSpaceGap); + } + + // scroll so that top of page (plus the gray area) is at the top of the scroll area + scrollableView->ScrollTo(0, fRect.y-deadSpaceGap, PR_TRUE); } +#endif // NS_PRINT_PREVIEW + return NS_OK; } @@ -4839,6 +4870,22 @@ DocumentViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) return NS_OK; } +/* readonly attribute long printPreviewNumPages; */ +NS_IMETHODIMP +DocumentViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages) +{ + NS_ENSURE_ARG_POINTER(aPrintPreviewNumPages); + + // Finds the SimplePageSequencer frame + // in PP mPrtPreview->mPrintObject->mSeqFrame is null + nsIFrame* seqFrame = nsnull; + *aPrintPreviewNumPages = 0; + if (NS_FAILED(GetSeqFrameAndCountPages(mPrtPreview->mPrintObject, seqFrame, *aPrintPreviewNumPages))) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + /* void exitPrintPreview (); */ NS_IMETHODIMP DocumentViewerImpl::ExitPrintPreview() diff --git a/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl b/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl index ffed12ce5ed..36a072eed21 100644 --- a/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl +++ b/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl @@ -98,6 +98,11 @@ interface nsIWebBrowserPrint : nsISupports */ readonly attribute boolean isFramesetDocument; + /** + * This returns the total number of pages for the Print Preview + */ + readonly attribute long printPreviewNumPages; + /** * Print the specified DOM window * diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 1216668f9a5..4ad12709754 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -4713,10 +4713,48 @@ DocumentViewerImpl::TurnScriptingOn(PRBool aDoTurnOn) scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE); } +//---------------------------------------------------------------------- +static nsresult GetSeqFrameAndCountPages(PrintObject* aPO, + nsIFrame*& aSeqFrame, + PRInt32& aCount) +{ + NS_ENSURE_ARG_POINTER(aPO); + + // Finds the SimplePageSequencer frame + // in PP mPrtPreview->mPrintObject->mSeqFrame is null + nsIFrame* curFrame; + aSeqFrame = nsnull; + aPO->mPresShell->GetRootFrame(&curFrame); + while (curFrame != nsnull) { + nsIPageSequenceFrame * sqf = nsnull; + if (NS_SUCCEEDED(CallQueryInterface(curFrame, &sqf)) && sqf) { + aSeqFrame = curFrame; + break; + } + curFrame->FirstChild(aPO->mPresContext, nsnull, &curFrame); + } + if (aSeqFrame == nsnull) return NS_ERROR_FAILURE; + + // first count the total number of pages + aCount = 0; + nsIFrame * pageFrame; + aSeqFrame->FirstChild(aPO->mPresContext, nsnull, &pageFrame); + while (pageFrame != nsnull) { + aCount++; + pageFrame->GetNextSibling(&pageFrame); + } + + return NS_OK; + +} + //---------------------------------------------------------------------- NS_IMETHODIMP DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) { +#ifdef NS_PRINT_PREVIEW + if (!mPrtPreview) return NS_ERROR_FAILURE; + nsIScrollableView* scrollableView; mViewManager->GetRootScrollableView(&scrollableView); if (scrollableView == nsnull) return NS_OK; @@ -4730,18 +4768,11 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) // Finds the SimplePageSequencer frame // in PP mPrtPreview->mPrintObject->mSeqFrame is null - nsIFrame* rootFrame; nsIFrame* seqFrame = nsnull; - mPrtPreview->mPrintObject->mPresShell->GetRootFrame(&rootFrame); - while (rootFrame != nsnull) { - nsIPageSequenceFrame * sqf = nsnull; - if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf)) && sqf) { - seqFrame = rootFrame; - break; - } - rootFrame->FirstChild(mPrtPreview->mPrintObject->mPresContext, nsnull, &rootFrame); + PRInt32 pageCount = 0; + if (NS_FAILED(GetSeqFrameAndCountPages(mPrtPreview->mPrintObject, seqFrame, pageCount))) { + return NS_ERROR_FAILURE; } - if (seqFrame == nsnull) return NS_OK; // Figure where we are currently scrolled to const nsIView * clippedView; @@ -4751,18 +4782,9 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) scrollableView->GetScrollPosition(x, y); PRInt32 pageNum = 1; - nsIFrame * pageFrame; nsIFrame * fndPageFrame = nsnull; nsIFrame * currentPage = nsnull; - // first count the total number of pages - PRInt32 pageCount = 0; - seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); - while (pageFrame != nsnull) { - pageCount++; - pageFrame->GetNextSibling(&pageFrame); - } - // If it is "End" then just do a "goto" to the last page if (aType == nsIWebBrowserPrint::PRINTPREVIEW_END) { aType = nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM; @@ -4772,6 +4794,7 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) // Now, locate the current page we are on and // and the page of the page number nscoord gap = 0; + nsIFrame * pageFrame; seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); while (pageFrame != nsnull) { nsRect pageRect; @@ -4824,9 +4847,17 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) nsIView * view; fndPageFrame->GetOffsetFromView(mPresContext, pnt, &view); - // scroll so that top of page is at the top of the scroll area - scrollableView->ScrollTo(pnt.x, fRect.y, PR_TRUE); + nscoord deadSpaceGap = 0; + nsIPageSequenceFrame * sqf; + if (NS_SUCCEEDED(CallQueryInterface(seqFrame, &sqf))) { + sqf->GetDeadSpaceValue(&deadSpaceGap); + } + + // scroll so that top of page (plus the gray area) is at the top of the scroll area + scrollableView->ScrollTo(0, fRect.y-deadSpaceGap, PR_TRUE); } +#endif // NS_PRINT_PREVIEW + return NS_OK; } @@ -4839,6 +4870,22 @@ DocumentViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) return NS_OK; } +/* readonly attribute long printPreviewNumPages; */ +NS_IMETHODIMP +DocumentViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages) +{ + NS_ENSURE_ARG_POINTER(aPrintPreviewNumPages); + + // Finds the SimplePageSequencer frame + // in PP mPrtPreview->mPrintObject->mSeqFrame is null + nsIFrame* seqFrame = nsnull; + *aPrintPreviewNumPages = 0; + if (NS_FAILED(GetSeqFrameAndCountPages(mPrtPreview->mPrintObject, seqFrame, *aPrintPreviewNumPages))) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + /* void exitPrintPreview (); */ NS_IMETHODIMP DocumentViewerImpl::ExitPrintPreview() diff --git a/mozilla/layout/base/public/nsIPageSequenceFrame.h b/mozilla/layout/base/public/nsIPageSequenceFrame.h index 07457f7c3b3..d2d06d975d2 100644 --- a/mozilla/layout/base/public/nsIPageSequenceFrame.h +++ b/mozilla/layout/base/public/nsIPageSequenceFrame.h @@ -149,6 +149,9 @@ public: NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) = 0; NS_IMETHOD SetTotalNumPages(PRInt32 aTotal) = 0; + + // Gets the dead space (the gray area) around the Print Preview Page + NS_IMETHOD GetDeadSpaceValue(nscoord* aValue) = 0; private: NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; diff --git a/mozilla/layout/generic/nsIPageSequenceFrame.h b/mozilla/layout/generic/nsIPageSequenceFrame.h index 07457f7c3b3..d2d06d975d2 100644 --- a/mozilla/layout/generic/nsIPageSequenceFrame.h +++ b/mozilla/layout/generic/nsIPageSequenceFrame.h @@ -149,6 +149,9 @@ public: NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) = 0; NS_IMETHOD SetTotalNumPages(PRInt32 aTotal) = 0; + + // Gets the dead space (the gray area) around the Print Preview Page + NS_IMETHOD GetDeadSpaceValue(nscoord* aValue) = 0; private: NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; diff --git a/mozilla/layout/generic/nsSimplePageSequence.cpp b/mozilla/layout/generic/nsSimplePageSequence.cpp index 089821697f5..b42e72e6b07 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.cpp +++ b/mozilla/layout/generic/nsSimplePageSequence.cpp @@ -317,13 +317,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, } } - nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25); + nscoord deadSpaceGap; + GetDeadSpaceValue(&deadSpaceGap); + nsMargin deadSpaceMargin(0,0,0,0); nsMargin extraMargin(0,0,0,0); nsSize shadowSize(0,0); if (ppContext) { if (adjSize.width == width && adjSize.height == height) { - deadSpaceMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch); + deadSpaceMargin.SizeTo(deadSpaceGap, deadSpaceGap, deadSpaceGap, deadSpaceGap); extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap); float p2t; aPresContext->GetScaledPixelsToTwips(&p2t); @@ -433,7 +435,7 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, y += kidSize.height; // Leave a slight gap between the pages - y += quarterInch; + y += deadSpaceGap; // Is the page complete? nsIFrame* kidNextInFlow; diff --git a/mozilla/layout/generic/nsSimplePageSequence.h b/mozilla/layout/generic/nsSimplePageSequence.h index b92404a202d..b4a720da1b0 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.h +++ b/mozilla/layout/generic/nsSimplePageSequence.h @@ -93,6 +93,10 @@ public: NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; } NS_IMETHOD SetTotalNumPages(PRInt32 aTotal) { mTotalPages = aTotal; return NS_OK; } + // Gets the dead space (the gray area) around the Print Preview Page + NS_IMETHOD GetDeadSpaceValue(nscoord* aValue) { *aValue = NS_INCHES_TO_TWIPS(0.25); return NS_OK; }; + + // Async Printing NS_IMETHOD StartPrint(nsIPresContext* aPresContext, nsIPrintSettings* aPrintSettings); diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp index 089821697f5..b42e72e6b07 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp @@ -317,13 +317,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, } } - nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25); + nscoord deadSpaceGap; + GetDeadSpaceValue(&deadSpaceGap); + nsMargin deadSpaceMargin(0,0,0,0); nsMargin extraMargin(0,0,0,0); nsSize shadowSize(0,0); if (ppContext) { if (adjSize.width == width && adjSize.height == height) { - deadSpaceMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch); + deadSpaceMargin.SizeTo(deadSpaceGap, deadSpaceGap, deadSpaceGap, deadSpaceGap); extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap); float p2t; aPresContext->GetScaledPixelsToTwips(&p2t); @@ -433,7 +435,7 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, y += kidSize.height; // Leave a slight gap between the pages - y += quarterInch; + y += deadSpaceGap; // Is the page complete? nsIFrame* kidNextInFlow; diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.h b/mozilla/layout/html/base/src/nsSimplePageSequence.h index b92404a202d..b4a720da1b0 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.h +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.h @@ -93,6 +93,10 @@ public: NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; } NS_IMETHOD SetTotalNumPages(PRInt32 aTotal) { mTotalPages = aTotal; return NS_OK; } + // Gets the dead space (the gray area) around the Print Preview Page + NS_IMETHOD GetDeadSpaceValue(nscoord* aValue) { *aValue = NS_INCHES_TO_TWIPS(0.25); return NS_OK; }; + + // Async Printing NS_IMETHOD StartPrint(nsIPresContext* aPresContext, nsIPrintSettings* aPrintSettings); diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index 72b121b6b77..9ecfaad2a76 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -883,6 +883,13 @@ PluginViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) return NS_ERROR_NOT_IMPLEMENTED; } +/* readonly attribute long printPreviewNumPages; */ +NS_IMETHODIMP +PluginViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /* void exitPrintPreview (); */ NS_IMETHODIMP PluginViewerImpl::ExitPrintPreview()