1) Enables the PageSeq frame to specify the "gap" of gray space around

it in Print Preview
2) It now positions the page in the window with the gray "gap" showing.
3) factors out code for calc'ing the number of pages
4) Adds the methods to get the number of page while in PP
Bug 125151 r=sgehanisr=attinasi


git-svn-id: svn://10.0.0.236/trunk@114536 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rods%netscape.com
2002-02-14 23:18:09 +00:00
parent e206b014b9
commit 1d1f95e7c0
10 changed files with 172 additions and 48 deletions

View File

@@ -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()

View File

@@ -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
*

View File

@@ -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()

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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()