Enabling the specifying of the gap around the page for Print Preview

and an offset from the edge of the page for headers and footers (used in PP and Printing)
Bug 102596 r=dcone sr=attinasi


git-svn-id: svn://10.0.0.236/trunk@109137 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rods%netscape.com
2001-11-28 15:19:47 +00:00
parent 727438403c
commit 46b3aa6437
6 changed files with 118 additions and 356 deletions

View File

@@ -154,40 +154,7 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext,
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
if (eReflowReason_Incremental == aReflowState.reason) {
// We don't expect the target of the reflow command to be page frame
#ifdef NS_DEUG
NS_ASSERTION(nsnull != aReflowState.reflowCommand, "null reflow command");
nsIFrame* target;
aReflowState.reflowCommand->GetTarget(target);
NS_ASSERTION(target != this, "page frame is reflow command target");
#endif
// Verify the next reflow command frame is our one and only child frame
nsIFrame* next;
aReflowState.reflowCommand->GetNext(next);
NS_ASSERTION(next == mFrames.FirstChild(), "bad reflow frame");
// Dispatch the reflow command to our frame
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
mFrames.FirstChild(), maxSize);
kidReflowState.isTopOfPage = PR_TRUE;
ReflowChild(mFrames.FirstChild(), aPresContext, aDesiredSize,
kidReflowState, 0, 0, 0, aStatus);
// Place and size the child. Make sure the child is at least as
// tall as our max size (the containing window)
if (aDesiredSize.height < aReflowState.availableHeight) {
aDesiredSize.height = aReflowState.availableHeight;
}
FinishReflowChild(mFrames.FirstChild(), aPresContext, aDesiredSize,
0, 0, 0);
} else {
if (eReflowReason_Incremental != aReflowState.reason) {
// Do we have any children?
// XXX We should use the overflow list instead...
if (mFrames.IsEmpty() && (nsnull != mPrevInFlow)) {
@@ -219,15 +186,16 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext,
kidReflowState.availableWidth = maxSize.width;
kidReflowState.availableHeight = maxSize.height;
// calc location of frame
nscoord xc = mPD->mReflowMargin.left + mPD->mDeadSpaceMargin.left + mPD->mExtraMargin.left;
nscoord yc = mPD->mReflowMargin.top + mPD->mDeadSpaceMargin.top + mPD->mExtraMargin.top;
// Get the child's desired size
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState,
mPD->mReflowMargin.left+mPD->mExtraMargin.left,
mPD->mReflowMargin.top+mPD->mExtraMargin.top, 0, aStatus);
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, xc, yc, 0, aStatus);
// Place and size the child
FinishReflowChild(frame, aPresContext, aDesiredSize,
mPD->mReflowMargin.left+mPD->mExtraMargin.left,
mPD->mReflowMargin.top+mPD->mExtraMargin.top, 0);
FinishReflowChild(frame, aPresContext, aDesiredSize, xc, yc, 0);
// Make sure the child is at least as tall as our max size (the containing window)
if (aDesiredSize.height < aReflowState.availableHeight) {
@@ -443,7 +411,7 @@ nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext,
nscoord x = aRect.x;
switch (aJust) {
case nsIPrintOptions::kJustLeft:
// do nothing, already set
x += mPD->mExtraMargin.left + mPD->mHeadFooterGap;
break;
case nsIPrintOptions::kJustCenter:
@@ -451,10 +419,12 @@ nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext,
break;
case nsIPrintOptions::kJustRight:
x += aRect.width - width;
x += aRect.width - width - mPD->mExtraMargin.right - mPD->mHeadFooterGap;
break;
} // switch
NS_ASSERTION(x >= 0, "x can't be less than zero");
x = PR_MAX(x, 0);
return x;
}
@@ -520,6 +490,8 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord aWidth)
{
nscoord contentWidth = aWidth - (mPD->mHeadFooterGap * 2);
// first make sure we have a vaild string and that the height of the
// text will fit in the margin
if (aStr.Length() > 0 &&
@@ -534,7 +506,7 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
PRBool addEllipse = PR_FALSE;
// trim the text and add the elipses if it won't fit
while (width >= aWidth && str.Length() > 1) {
while (width >= contentWidth && str.Length() > 1) {
str.SetLength(str.Length()-1);
aRenderingContext.GetWidth(str, width);
addEllipse = PR_TRUE;
@@ -550,9 +522,9 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord x = GetXPosition(aRenderingContext, rect, aJust, str);
nscoord y;
if (aHeaderFooter == eHeader) {
y = rect.y;
y = rect.y + mPD->mExtraMargin.top + mPD->mHeadFooterGap;
} else {
y = rect.y + rect.height - aHeight;
y = rect.y + rect.height - aHeight - mPD->mExtraMargin.bottom - mPD->mHeadFooterGap;
}
// set up new clip and draw the text
@@ -646,10 +618,10 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
nsRect r;
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
fprintf(stdout, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d] SC:%s\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height, specialClipIsSet?"Yes":"No");
fprintf(stdout, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d] SC:%s\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height, specialClipIsSet?"Yes":"No");
}
#endif
@@ -665,7 +637,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
// XXX Paint a one-pixel border around the page so it's easy to see where
// each page begins and ends when we're
rct.Deflate(mMargin);
rct.Deflate(mPD->mExtraMargin);
rct.Deflate(mPD->mDeadSpaceMargin);
//float p2t;
//aPresContext->GetPixelsToTwips(&p2t);
//rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));

View File

@@ -52,6 +52,8 @@
#include "nsPageFrame.h"
#include "nsIPrintPreviewContext.h"
#include "nsIPref.h" // for header/footer gap & ExtraMargin for Print Preview
// DateTime Includes
#include "nsDateTimeFormatCID.h"
#include "nsIDateTimeFormat.h"
@@ -105,6 +107,7 @@ nsSharedPageData::nsSharedPageData() :
mReflowRect(0,0,0,0),
mReflowMargin(0,0,0,0),
mShadowSize(0,0),
mDeadSpaceMargin(0,0,0,0),
mExtraMargin(0,0,0,0)
{
}
@@ -218,115 +221,6 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsIPresContext* aPresContex
return rv;
}
// Handles incremental reflow
nsresult
nsSimplePageSequenceFrame::IncrementalReflow(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aPageSize,
nscoord aX,
nscoord& aY)
{
// We don't expect the target of the reflow command to be the simple
// page sequence frame
#ifdef NS_DEBUG
nsIFrame* targetFrame;
aReflowState.reflowCommand->GetTarget(targetFrame);
NS_ASSERTION(targetFrame != this, "simple page sequence frame is reflow command target");
#endif
// Get the next child frame in the target chain
nsIFrame* nextFrame;
aReflowState.reflowCommand->GetNext(nextFrame);
// Compute the y-offset of this page
for (nsIFrame* f = mFrames.FirstChild(); f != nextFrame; f->GetNextSibling(&f)) {
nsSize size;
f->GetSize(size);
aY += size.height + mMargin.top + mMargin.bottom;
}
// Reflow the page
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
nextFrame, aPageSize);
nsHTMLReflowMetrics kidSize(nsnull);
nsReflowStatus status;
// Dispatch the reflow command to our child frame. Allow it to be as high
// as it wants
ReflowChild(nextFrame, aPresContext, kidSize, kidReflowState, aX, aY, 0, status);
// Place and size the page. If the page is narrower than our max width, then
// center it horizontally
FinishReflowChild(nextFrame, aPresContext, kidSize, aX, aY, 0);
aY += kidSize.height + mMargin.top + mMargin.bottom;
// Check if the page is complete...
nsIFrame* kidNextInFlow;
nextFrame->GetNextInFlow(&kidNextInFlow);
if (NS_FRAME_IS_COMPLETE(status)) {
NS_ASSERTION(nsnull == kidNextInFlow, "bad child flow list");
} else {
nsReflowReason reflowReason = eReflowReason_Resize;
if (!kidNextInFlow) {
// The page isn't complete and it doesn't have a next-in-flow so
// create a continuing page
nsIFrame* continuingPage;
CreateContinuingPageFrame(aPresContext, nextFrame, &continuingPage);
// Add it to our child list
nextFrame->SetNextSibling(continuingPage);
reflowReason = eReflowReason_Initial;
}
// Reflow the remaining pages
// XXX Ideally we would only reflow the next page if the current page indicated
// its next-in-flow was dirty...
nsIFrame* kidFrame;
nextFrame->GetNextSibling(&kidFrame);
while (kidFrame) {
// Reflow the page
nsHTMLReflowMetrics childSize(nsnull);
nsHTMLReflowState childReflowState(aPresContext, aReflowState, kidFrame,
aPageSize, reflowReason);
// Place and size the page. If the page is narrower than our
// max width then center it horizontally
ReflowChild(kidFrame, aPresContext, childSize, childReflowState,
aX, aY, 0, status);
FinishReflowChild(kidFrame, aPresContext, childSize, aX, aY, 0);
aY += childSize.height;
// Leave a slight gap between the pages
aY += mMargin.top + mMargin.bottom;
// Is the page complete?
kidFrame->GetNextInFlow(&kidNextInFlow);
if (NS_FRAME_IS_COMPLETE(status)) {
NS_ASSERTION(nsnull == kidNextInFlow, "bad child flow list");
} else if (nsnull == kidNextInFlow) {
// The page isn't complete and it doesn't have a next-in-flow, so
// create a continuing page
nsIFrame* continuingPage;
CreateContinuingPageFrame(aPresContext, kidFrame, &continuingPage);
// Add it to our child list
kidFrame->SetNextSibling(continuingPage);
reflowReason = eReflowReason_Initial;
}
// Get the next page
kidFrame->GetNextSibling(&kidFrame);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
@@ -359,12 +253,31 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsRect adjSize;
aPresContext->GetPageDim(&pageSize, &adjSize);
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
nscoord extraGap = 0;
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
if (pref) {
nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0);
PRInt32 gapInTwips;
if (NS_SUCCEEDED(pref->GetIntPref("print.print_headerfooter_gap", &gapInTwips))) {
gapInTwips = PR_MAX(gapInTwips, 0);
gapInTwips = PR_MIN(gapInTwips, inchInTwips); // an inch is still probably excessive
mPageData->mHeadFooterGap = nscoord(gapInTwips);
}
if (NS_SUCCEEDED(pref->GetIntPref("print.print_extra_margin", &gapInTwips))) {
gapInTwips = PR_MAX(gapInTwips, 0);
gapInTwips = PR_MIN(gapInTwips, inchInTwips); // an inch is still probably excessive
extraGap = nscoord(gapInTwips);
}
}
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
nsMargin deadSpaceMargin(0,0,0,0);
nsMargin extraMargin(0,0,0,0);
nsSize shadowSize(0,0);
nsSize shadowSize(0,0);
if (ppContext) {
if (adjSize.width == width && adjSize.height == height) {
extraMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch);
deadSpaceMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch);
extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap);
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
nscoord fourPixels = NSIntPixelsToTwips(4, p2t);
@@ -372,8 +285,9 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
}
}
mPageData->mShadowSize = shadowSize;
mPageData->mExtraMargin = extraMargin;
mPageData->mShadowSize = shadowSize;
mPageData->mExtraMargin = extraMargin;
mPageData->mDeadSpaceMargin = deadSpaceMargin;
// absolutely ignore all other types of reflows
// we only want to have done the Initial Reflow
@@ -430,14 +344,13 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
suppressRightMargin?0:mMargin.right,
suppressBottomMargin?0:mMargin.bottom);
nscoord x = extraMargin.left;
nscoord y = extraMargin.top;// Running y-offset for each page
nscoord x = deadSpaceMargin.left;
nscoord y = deadSpaceMargin.top;// Running y-offset for each page
// See if it's an incremental reflow command
if (eReflowReason_Incremental == aReflowState.reason) {
// XXX Skip Incremental reflow,
// in fact, all we want is the initial reflow
//IncrementalReflow(aPresContext, aReflowState, pageSize, x, y);
y = mRect.height;
} else {
nsReflowReason reflowReason = aReflowState.reason;
@@ -448,8 +361,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics kidSize(nsnull);
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
// Reflow the page
nsSize availSize(pageSize.width+extraMargin.right+extraMargin.left+shadowSize.width,
pageSize.height+extraMargin.top+extraMargin.bottom+shadowSize.height);
nsSize availSize(pageSize.width+deadSpaceMargin.right+deadSpaceMargin.left+shadowSize.width+extraMargin.right+extraMargin.left,
pageSize.height+deadSpaceMargin.top+deadSpaceMargin.bottom+shadowSize.height+extraMargin.top+extraMargin.bottom);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
availSize, reflowReason);
nsReflowStatus status;
@@ -540,7 +453,7 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
// Return our desired size
aDesiredSize.height = y;
aDesiredSize.width = pageSize.width+extraMargin.left+shadowSize.width;
aDesiredSize.width = pageSize.width+deadSpaceMargin.left+shadowSize.width;
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;

View File

@@ -57,8 +57,10 @@ public:
nsRect mReflowRect;
nsMargin mReflowMargin;
nsSize mShadowSize;
nsMargin mExtraMargin;
nsSize mShadowSize; // shadow of page in PrintPreview
nsMargin mDeadSpaceMargin; // Extra dead space around outside of Page in PrintPreview
nsMargin mExtraMargin; // Extra Margin between the printable area and the edge of the page
nscoord mHeadFooterGap; // In twips, gap between H/F from edge of page
nsCOMPtr<nsIPrintOptions> mPrintOptions;
};
@@ -122,12 +124,6 @@ protected:
nsSimplePageSequenceFrame();
virtual ~nsSimplePageSequenceFrame();
nsresult IncrementalReflow(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aPageSize,
nscoord aX,
nscoord& aY);
nsresult CreateContinuingPageFrame(nsIPresContext* aPresContext,
nsIFrame* aPageFrame,
nsIFrame** aContinuingFrame);

View File

@@ -154,40 +154,7 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext,
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
if (eReflowReason_Incremental == aReflowState.reason) {
// We don't expect the target of the reflow command to be page frame
#ifdef NS_DEUG
NS_ASSERTION(nsnull != aReflowState.reflowCommand, "null reflow command");
nsIFrame* target;
aReflowState.reflowCommand->GetTarget(target);
NS_ASSERTION(target != this, "page frame is reflow command target");
#endif
// Verify the next reflow command frame is our one and only child frame
nsIFrame* next;
aReflowState.reflowCommand->GetNext(next);
NS_ASSERTION(next == mFrames.FirstChild(), "bad reflow frame");
// Dispatch the reflow command to our frame
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
mFrames.FirstChild(), maxSize);
kidReflowState.isTopOfPage = PR_TRUE;
ReflowChild(mFrames.FirstChild(), aPresContext, aDesiredSize,
kidReflowState, 0, 0, 0, aStatus);
// Place and size the child. Make sure the child is at least as
// tall as our max size (the containing window)
if (aDesiredSize.height < aReflowState.availableHeight) {
aDesiredSize.height = aReflowState.availableHeight;
}
FinishReflowChild(mFrames.FirstChild(), aPresContext, aDesiredSize,
0, 0, 0);
} else {
if (eReflowReason_Incremental != aReflowState.reason) {
// Do we have any children?
// XXX We should use the overflow list instead...
if (mFrames.IsEmpty() && (nsnull != mPrevInFlow)) {
@@ -219,15 +186,16 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext,
kidReflowState.availableWidth = maxSize.width;
kidReflowState.availableHeight = maxSize.height;
// calc location of frame
nscoord xc = mPD->mReflowMargin.left + mPD->mDeadSpaceMargin.left + mPD->mExtraMargin.left;
nscoord yc = mPD->mReflowMargin.top + mPD->mDeadSpaceMargin.top + mPD->mExtraMargin.top;
// Get the child's desired size
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState,
mPD->mReflowMargin.left+mPD->mExtraMargin.left,
mPD->mReflowMargin.top+mPD->mExtraMargin.top, 0, aStatus);
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, xc, yc, 0, aStatus);
// Place and size the child
FinishReflowChild(frame, aPresContext, aDesiredSize,
mPD->mReflowMargin.left+mPD->mExtraMargin.left,
mPD->mReflowMargin.top+mPD->mExtraMargin.top, 0);
FinishReflowChild(frame, aPresContext, aDesiredSize, xc, yc, 0);
// Make sure the child is at least as tall as our max size (the containing window)
if (aDesiredSize.height < aReflowState.availableHeight) {
@@ -443,7 +411,7 @@ nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext,
nscoord x = aRect.x;
switch (aJust) {
case nsIPrintOptions::kJustLeft:
// do nothing, already set
x += mPD->mExtraMargin.left + mPD->mHeadFooterGap;
break;
case nsIPrintOptions::kJustCenter:
@@ -451,10 +419,12 @@ nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext,
break;
case nsIPrintOptions::kJustRight:
x += aRect.width - width;
x += aRect.width - width - mPD->mExtraMargin.right - mPD->mHeadFooterGap;
break;
} // switch
NS_ASSERTION(x >= 0, "x can't be less than zero");
x = PR_MAX(x, 0);
return x;
}
@@ -520,6 +490,8 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord aWidth)
{
nscoord contentWidth = aWidth - (mPD->mHeadFooterGap * 2);
// first make sure we have a vaild string and that the height of the
// text will fit in the margin
if (aStr.Length() > 0 &&
@@ -534,7 +506,7 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
PRBool addEllipse = PR_FALSE;
// trim the text and add the elipses if it won't fit
while (width >= aWidth && str.Length() > 1) {
while (width >= contentWidth && str.Length() > 1) {
str.SetLength(str.Length()-1);
aRenderingContext.GetWidth(str, width);
addEllipse = PR_TRUE;
@@ -550,9 +522,9 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord x = GetXPosition(aRenderingContext, rect, aJust, str);
nscoord y;
if (aHeaderFooter == eHeader) {
y = rect.y;
y = rect.y + mPD->mExtraMargin.top + mPD->mHeadFooterGap;
} else {
y = rect.y + rect.height - aHeight;
y = rect.y + rect.height - aHeight - mPD->mExtraMargin.bottom - mPD->mHeadFooterGap;
}
// set up new clip and draw the text
@@ -646,10 +618,10 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
nsRect r;
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
fprintf(stdout, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d] SC:%s\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height, specialClipIsSet?"Yes":"No");
fprintf(stdout, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d] SC:%s\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height, specialClipIsSet?"Yes":"No");
}
#endif
@@ -665,7 +637,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
// XXX Paint a one-pixel border around the page so it's easy to see where
// each page begins and ends when we're
rct.Deflate(mMargin);
rct.Deflate(mPD->mExtraMargin);
rct.Deflate(mPD->mDeadSpaceMargin);
//float p2t;
//aPresContext->GetPixelsToTwips(&p2t);
//rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));

View File

@@ -52,6 +52,8 @@
#include "nsPageFrame.h"
#include "nsIPrintPreviewContext.h"
#include "nsIPref.h" // for header/footer gap & ExtraMargin for Print Preview
// DateTime Includes
#include "nsDateTimeFormatCID.h"
#include "nsIDateTimeFormat.h"
@@ -105,6 +107,7 @@ nsSharedPageData::nsSharedPageData() :
mReflowRect(0,0,0,0),
mReflowMargin(0,0,0,0),
mShadowSize(0,0),
mDeadSpaceMargin(0,0,0,0),
mExtraMargin(0,0,0,0)
{
}
@@ -218,115 +221,6 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsIPresContext* aPresContex
return rv;
}
// Handles incremental reflow
nsresult
nsSimplePageSequenceFrame::IncrementalReflow(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aPageSize,
nscoord aX,
nscoord& aY)
{
// We don't expect the target of the reflow command to be the simple
// page sequence frame
#ifdef NS_DEBUG
nsIFrame* targetFrame;
aReflowState.reflowCommand->GetTarget(targetFrame);
NS_ASSERTION(targetFrame != this, "simple page sequence frame is reflow command target");
#endif
// Get the next child frame in the target chain
nsIFrame* nextFrame;
aReflowState.reflowCommand->GetNext(nextFrame);
// Compute the y-offset of this page
for (nsIFrame* f = mFrames.FirstChild(); f != nextFrame; f->GetNextSibling(&f)) {
nsSize size;
f->GetSize(size);
aY += size.height + mMargin.top + mMargin.bottom;
}
// Reflow the page
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
nextFrame, aPageSize);
nsHTMLReflowMetrics kidSize(nsnull);
nsReflowStatus status;
// Dispatch the reflow command to our child frame. Allow it to be as high
// as it wants
ReflowChild(nextFrame, aPresContext, kidSize, kidReflowState, aX, aY, 0, status);
// Place and size the page. If the page is narrower than our max width, then
// center it horizontally
FinishReflowChild(nextFrame, aPresContext, kidSize, aX, aY, 0);
aY += kidSize.height + mMargin.top + mMargin.bottom;
// Check if the page is complete...
nsIFrame* kidNextInFlow;
nextFrame->GetNextInFlow(&kidNextInFlow);
if (NS_FRAME_IS_COMPLETE(status)) {
NS_ASSERTION(nsnull == kidNextInFlow, "bad child flow list");
} else {
nsReflowReason reflowReason = eReflowReason_Resize;
if (!kidNextInFlow) {
// The page isn't complete and it doesn't have a next-in-flow so
// create a continuing page
nsIFrame* continuingPage;
CreateContinuingPageFrame(aPresContext, nextFrame, &continuingPage);
// Add it to our child list
nextFrame->SetNextSibling(continuingPage);
reflowReason = eReflowReason_Initial;
}
// Reflow the remaining pages
// XXX Ideally we would only reflow the next page if the current page indicated
// its next-in-flow was dirty...
nsIFrame* kidFrame;
nextFrame->GetNextSibling(&kidFrame);
while (kidFrame) {
// Reflow the page
nsHTMLReflowMetrics childSize(nsnull);
nsHTMLReflowState childReflowState(aPresContext, aReflowState, kidFrame,
aPageSize, reflowReason);
// Place and size the page. If the page is narrower than our
// max width then center it horizontally
ReflowChild(kidFrame, aPresContext, childSize, childReflowState,
aX, aY, 0, status);
FinishReflowChild(kidFrame, aPresContext, childSize, aX, aY, 0);
aY += childSize.height;
// Leave a slight gap between the pages
aY += mMargin.top + mMargin.bottom;
// Is the page complete?
kidFrame->GetNextInFlow(&kidNextInFlow);
if (NS_FRAME_IS_COMPLETE(status)) {
NS_ASSERTION(nsnull == kidNextInFlow, "bad child flow list");
} else if (nsnull == kidNextInFlow) {
// The page isn't complete and it doesn't have a next-in-flow, so
// create a continuing page
nsIFrame* continuingPage;
CreateContinuingPageFrame(aPresContext, kidFrame, &continuingPage);
// Add it to our child list
kidFrame->SetNextSibling(continuingPage);
reflowReason = eReflowReason_Initial;
}
// Get the next page
kidFrame->GetNextSibling(&kidFrame);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
@@ -359,12 +253,31 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsRect adjSize;
aPresContext->GetPageDim(&pageSize, &adjSize);
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
nscoord extraGap = 0;
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
if (pref) {
nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0);
PRInt32 gapInTwips;
if (NS_SUCCEEDED(pref->GetIntPref("print.print_headerfooter_gap", &gapInTwips))) {
gapInTwips = PR_MAX(gapInTwips, 0);
gapInTwips = PR_MIN(gapInTwips, inchInTwips); // an inch is still probably excessive
mPageData->mHeadFooterGap = nscoord(gapInTwips);
}
if (NS_SUCCEEDED(pref->GetIntPref("print.print_extra_margin", &gapInTwips))) {
gapInTwips = PR_MAX(gapInTwips, 0);
gapInTwips = PR_MIN(gapInTwips, inchInTwips); // an inch is still probably excessive
extraGap = nscoord(gapInTwips);
}
}
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
nsMargin deadSpaceMargin(0,0,0,0);
nsMargin extraMargin(0,0,0,0);
nsSize shadowSize(0,0);
nsSize shadowSize(0,0);
if (ppContext) {
if (adjSize.width == width && adjSize.height == height) {
extraMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch);
deadSpaceMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch);
extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap);
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
nscoord fourPixels = NSIntPixelsToTwips(4, p2t);
@@ -372,8 +285,9 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
}
}
mPageData->mShadowSize = shadowSize;
mPageData->mExtraMargin = extraMargin;
mPageData->mShadowSize = shadowSize;
mPageData->mExtraMargin = extraMargin;
mPageData->mDeadSpaceMargin = deadSpaceMargin;
// absolutely ignore all other types of reflows
// we only want to have done the Initial Reflow
@@ -430,14 +344,13 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
suppressRightMargin?0:mMargin.right,
suppressBottomMargin?0:mMargin.bottom);
nscoord x = extraMargin.left;
nscoord y = extraMargin.top;// Running y-offset for each page
nscoord x = deadSpaceMargin.left;
nscoord y = deadSpaceMargin.top;// Running y-offset for each page
// See if it's an incremental reflow command
if (eReflowReason_Incremental == aReflowState.reason) {
// XXX Skip Incremental reflow,
// in fact, all we want is the initial reflow
//IncrementalReflow(aPresContext, aReflowState, pageSize, x, y);
y = mRect.height;
} else {
nsReflowReason reflowReason = aReflowState.reason;
@@ -448,8 +361,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics kidSize(nsnull);
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
// Reflow the page
nsSize availSize(pageSize.width+extraMargin.right+extraMargin.left+shadowSize.width,
pageSize.height+extraMargin.top+extraMargin.bottom+shadowSize.height);
nsSize availSize(pageSize.width+deadSpaceMargin.right+deadSpaceMargin.left+shadowSize.width+extraMargin.right+extraMargin.left,
pageSize.height+deadSpaceMargin.top+deadSpaceMargin.bottom+shadowSize.height+extraMargin.top+extraMargin.bottom);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
availSize, reflowReason);
nsReflowStatus status;
@@ -540,7 +453,7 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
// Return our desired size
aDesiredSize.height = y;
aDesiredSize.width = pageSize.width+extraMargin.left+shadowSize.width;
aDesiredSize.width = pageSize.width+deadSpaceMargin.left+shadowSize.width;
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;

View File

@@ -57,8 +57,10 @@ public:
nsRect mReflowRect;
nsMargin mReflowMargin;
nsSize mShadowSize;
nsMargin mExtraMargin;
nsSize mShadowSize; // shadow of page in PrintPreview
nsMargin mDeadSpaceMargin; // Extra dead space around outside of Page in PrintPreview
nsMargin mExtraMargin; // Extra Margin between the printable area and the edge of the page
nscoord mHeadFooterGap; // In twips, gap between H/F from edge of page
nsCOMPtr<nsIPrintOptions> mPrintOptions;
};
@@ -122,12 +124,6 @@ protected:
nsSimplePageSequenceFrame();
virtual ~nsSimplePageSequenceFrame();
nsresult IncrementalReflow(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aPageSize,
nscoord aX,
nscoord& aY);
nsresult CreateContinuingPageFrame(nsIPresContext* aPresContext,
nsIFrame* aPageFrame,
nsIFrame** aContinuingFrame);