diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index d1ef46d0116..c7d358d6e5a 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1633,12 +1633,6 @@ nsEventStateManager::DoScrollTextsize(nsIFrame *aTargetFrame, } } -inline PRBool -ShouldScrollRootView(nsPresContext* aPresContext) -{ - return (aPresContext->Type() == nsPresContext::eContext_PrintPreview); -} - static nsIFrame* GetParentFrameToScroll(nsPresContext* aPresContext, nsIFrame* aFrame) { @@ -1659,38 +1653,6 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext, PRBool aScrollHorizontal, PRBool aScrollPage) { - nsIScrollableView* scrollView = nsnull; - PRBool scrollRootView = ShouldScrollRootView(aPresContext); - - if (scrollRootView) { - // Get root scroll view - nsIViewManager* vm = aPresContext->GetViewManager(); - NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - vm->GetRootScrollableView(&scrollView); - if (!scrollView) { - // We don't have root scrollable view in current document. - // Maybe, this is sub frame on Print Preview. - // Let's pass to parent document. - nsIFrame* newFrame = nsnull; - nsCOMPtr newPresContext = nsnull; - nsresult rv = GetParentScrollingView(aEvent, aPresContext, newFrame, - *getter_AddRefs(newPresContext)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(newFrame && newPresContext, NS_ERROR_FAILURE); - return DoScrollText(newPresContext, newFrame, aEvent, aNumLines, - aScrollHorizontal, aScrollPage); - } - // find target frame that is root scrollable content - nsIFrame* targetFrame = aTargetFrame; - for ( ;targetFrame; targetFrame = targetFrame->GetParent()) { - nsCOMPtr svp = do_QueryInterface(targetFrame); - if (svp && scrollView == svp->GetScrollableView()) - break; - } - NS_ENSURE_TRUE(targetFrame, NS_ERROR_FAILURE); - aTargetFrame = targetFrame; - } - nsCOMPtr targetContent = aTargetFrame->GetContent(); if (!targetContent) GetFocusedContent(getter_AddRefs(targetContent)); @@ -1738,24 +1700,23 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext, target->DispatchEvent(event, &defaultActionEnabled); if (!defaultActionEnabled) return NS_OK; - if (!scrollRootView) { - // Re-resolve |aTargetFrame| in case it was destroyed by the - // DOM event handler above, bug 257998. - aTargetFrame = - aPresContext->GetPresShell()->GetPrimaryFrameFor(targetContent); - if (!aTargetFrame) { - // Without a frame we can't do the normal ancestor search for a view - // to scroll. Don't fall through to the "passToParent" code at the end - // because that will likely scroll the wrong view (in an enclosing - // document). - return NS_OK; - } + // Re-resolve |aTargetFrame| in case it was destroyed by the + // DOM event handler above, bug 257998. + aTargetFrame = + aPresContext->GetPresShell()->GetPrimaryFrameFor(targetContent); + if (!aTargetFrame) { + // Without a frame we can't do the normal ancestor search for a view + // to scroll. Don't fall through to the "passToParent" code at the end + // because that will likely scroll the wrong view (in an enclosing + // document). + return NS_OK; } } } + nsIScrollableView* scrollView; nsIFrame* scrollFrame = aTargetFrame; - PRBool passToParent = !scrollRootView; + PRBool passToParent = PR_TRUE; for (; scrollFrame && passToParent; scrollFrame = GetParentFrameToScroll(aPresContext, scrollFrame)) { @@ -1775,7 +1736,7 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext, (aScrollHorizontal ? ss.mHorizontal : ss.mVertical)) { continue; } - + // Check if the scrollable view can be scrolled any further. nscoord lineHeight; scrollView->GetLineHeight(&lineHeight); @@ -1828,14 +1789,11 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext, nsresult rv; nsIFrame* newFrame = nsnull; nsCOMPtr newPresContext; - rv = GetParentScrollingView(aEvent, aPresContext, newFrame, *getter_AddRefs(newPresContext)); if (NS_SUCCEEDED(rv) && newFrame) return DoScrollText(newPresContext, newFrame, aEvent, aNumLines, aScrollHorizontal, aScrollPage); - else - return NS_ERROR_FAILURE; } return NS_OK; @@ -1871,7 +1829,8 @@ nsEventStateManager::GetParentScrollingView(nsInputEvent *aEvent, break; } } - NS_ENSURE_TRUE(pPresShell, NS_ERROR_FAILURE); + if (!pPresShell) + return NS_ERROR_FAILURE; /* now find the content node in our parent docshell's document that corresponds to our docshell */ diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 6e7b1326eb4..5a9df64b264 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -4775,11 +4775,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIContent* aDocElement, // - renders the document element's background. This ensures the background covers // the entire canvas as specified by the CSS2 spec - PRBool isPaginated = presContext->IsPaginated(); - PRBool isPrintPreview = - presContext->Type() == nsPresContext::eContext_PrintPreview; - PRBool isPageLayout = - presContext->Type() == nsPresContext::eContext_PageLayout; + PRBool isPaginated = presContext->IsRootPaginatedDocument(); nsIFrame* rootFrame = nsnull; nsIAtom* rootPseudo; @@ -4842,11 +4838,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIContent* aDocElement, } if (isPaginated) { - if (isPrintPreview || isPageLayout) { - isScrollable = presContext->HasPaginatedScrolling(); - } else { - isScrollable = PR_FALSE; // we are printing - } + isScrollable = presContext->HasPaginatedScrolling(); } // We no longer need to do overflow propagation here. It's taken care of diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 6008c024295..24e440d0318 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -157,7 +157,7 @@ static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); nsPresContext::nsPresContext(nsPresContextType aType) : mType(aType), mTextZoom(1.0), mPageSize(-1, -1), mIsRootPaginatedDocument(PR_FALSE), - mCanPaginatedScroll(PR_TRUE), + mCanPaginatedScroll(PR_FALSE), mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO), mCompatibilityMode(eCompatibility_FullStandards), mImageAnimationModePref(imgIContainer::kNormalAnimMode), diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index 1887f6e7630..ee994939f95 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -91,9 +91,6 @@ #include "nsDisplayList.h" #include "nsUnicharUtils.h" -#ifdef NS_PRINTING -#include "nsIWebBrowserPrint.h" -#endif // For Accessibility #ifdef ACCESSIBILITY #include "nsIAccessibilityService.h" @@ -255,33 +252,22 @@ nsSubDocumentFrame::Init(nsIContent* aContent, contentParent = (nsIFrame*)value; } - nsHTMLContainerFrame::CreateViewForFrame(this, contentParent, PR_TRUE); + rv = nsHTMLContainerFrame::CreateViewForFrame(this, contentParent, PR_TRUE); + NS_ENSURE_SUCCESS(rv, rv); } nsIView* view = GetView(); - NS_ASSERTION(view, "We should always have a view now"); if (aParent->GetStyleDisplay()->mDisplay == NS_STYLE_DISPLAY_DECK && !view->HasWidget()) { view->CreateWidget(kCChildCID); } - // determine if we are a printcontext - PRBool shouldCreateDoc; - - if (aPresContext->Medium() == nsLayoutAtoms::print) { - if (aPresContext->Type() == nsPresContext::eContext_PrintPreview) { - // for print preview we want to create the view and widget but - // we do not want to load the document, it is already loaded. - rv = CreateViewAndWidget(eContentTypeContent); - NS_ENSURE_SUCCESS(rv,rv); - } - - shouldCreateDoc = PR_FALSE; + if (!aPresContext->IsDynamic()) { + // We let the printing code take care of loading the document; just + // create a widget for it to use + rv = CreateViewAndWidget(eContentTypeContent); + NS_ENSURE_SUCCESS(rv,rv); } else { - shouldCreateDoc = PR_TRUE; - } - - if (shouldCreateDoc) { rv = ShowDocShell(); NS_ENSURE_SUCCESS(rv,rv); mDidCreateDoc = PR_TRUE; @@ -396,13 +382,10 @@ nsSubDocumentFrame::Reflow(nsPresContext* aPresContext, aDesiredSize.width += border.left + border.right; aDesiredSize.height += border.top + border.bottom; } - - // might not have an inner view yet during printing - if (mInnerView) { - nsIViewManager* vm = mInnerView->GetViewManager(); - vm->MoveViewTo(mInnerView, offset.x, offset.y); - vm->ResizeView(mInnerView, nsRect(0, 0, innerSize.width, innerSize.height), PR_TRUE); - } + + nsIViewManager* vm = mInnerView->GetViewManager(); + vm->MoveViewTo(mInnerView, offset.x, offset.y); + vm->ResizeView(mInnerView, nsRect(nsPoint(0, 0), innerSize), PR_TRUE); if (aDesiredSize.mComputeMEW) { nscoord defaultAutoWidth = NSIntPixelsToTwips(300, aPresContext->ScaledPixelsToTwips()); diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 11c2a79ff57..34f228ca3f4 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1468,6 +1468,11 @@ nsGfxScrollFrameInner::ScrollbarStyles nsGfxScrollFrameInner::GetScrollbarStylesFromFrame() const { ScrollbarStyles result; + + if (mNeverHasVerticalScrollbar && mNeverHasHorizontalScrollbar) { + return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN); + } + if (mIsRoot) { nsPresContext *presContext = mOuter->GetPresContext(); result = presContext->GetViewportOverflowOverride(); @@ -1609,10 +1614,10 @@ nsGfxScrollFrameInner::CreateAnonymousContent(nsISupportsArray& aAnonymousChildr // Don't create scrollbars if we're printing/print previewing // Get rid of this code when printing moves to its own presentation - if (presContext->IsPaginated()) { + if (!presContext->IsDynamic()) { // allow scrollbars if this is the child of the viewport, because // we must be the scrollbars for the print preview window - if (!mIsRoot) { + if (!(mIsRoot && presContext->HasPaginatedScrolling())) { mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE; return; } diff --git a/layout/generic/nsIPageSequenceFrame.h b/layout/generic/nsIPageSequenceFrame.h index 6cf39c4157a..108975b8694 100644 --- a/layout/generic/nsIPageSequenceFrame.h +++ b/layout/generic/nsIPageSequenceFrame.h @@ -83,7 +83,6 @@ public: NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage) = 0; NS_IMETHOD DoPageEnd() = 0; - NS_IMETHOD SetOffset(nscoord aX, nscoord aY) = 0; NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) = 0; NS_IMETHOD SetTotalNumPages(PRInt32 aTotal) = 0; diff --git a/layout/generic/nsPageContentFrame.cpp b/layout/generic/nsPageContentFrame.cpp index e8a15a6d13c..107d2f9745c 100644 --- a/layout/generic/nsPageContentFrame.cpp +++ b/layout/generic/nsPageContentFrame.cpp @@ -129,6 +129,8 @@ NS_IMETHODIMP nsPageContentFrame::Reflow(nsPresContext* aPresContext, if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) { aDesiredSize.height = aReflowState.availableHeight; } + aDesiredSize.ascent = aDesiredSize.height; + aDesiredSize.descent = 0; NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); return NS_OK; diff --git a/layout/generic/nsPageFrame.cpp b/layout/generic/nsPageFrame.cpp index f13996c7f14..a8ff17db618 100644 --- a/layout/generic/nsPageFrame.cpp +++ b/layout/generic/nsPageFrame.cpp @@ -92,9 +92,6 @@ extern PRLogModuleInfo * kLayoutPrintingLogMod; #define PR_PL(_p1) #endif -// XXX Part of Temporary fix for Bug 127263 -PRBool nsPageFrame::mDoCreateWidget = PR_TRUE; - nsIFrame* NS_NewPageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) { @@ -110,22 +107,6 @@ nsPageFrame::~nsPageFrame() { } - -NS_IMETHODIMP -nsPageFrame::SetInitialChildList(nsIAtom* aListName, - nsIFrame* aChildList) -{ - nsIView* view = aChildList->GetView(); - if (view && mDoCreateWidget) { - if (GetPresContext()->Type() == nsPresContext::eContext_PrintPreview && - view->GetNearestWidget(nsnull)) { - view->CreateWidget(kCChildCID); - } - } - - return nsContainerFrame::SetInitialChildList(aListName, aChildList); -} - NS_IMETHODIMP nsPageFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, @@ -195,8 +176,8 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsPresContext* aPresContext, kidReflowState.mFlags.mIsTopOfPage = PR_TRUE; // 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; + nscoord xc = mPD->mReflowMargin.left + mPD->mExtraMargin.left; + nscoord yc = mPD->mReflowMargin.top + mPD->mExtraMargin.top; // Get the child's desired size ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, xc, yc, 0, aStatus); @@ -209,13 +190,6 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsPresContext* aPresContext, aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) { aDesiredSize.height = aReflowState.availableHeight; } - - nsIView* view = frame->GetView(); - if (view) { - nsRegion region(nsRect(0, 0, aDesiredSize.width, aDesiredSize.height)); - view->GetViewManager()->SetViewChildClipRegion(view, ®ion); - } - NS_ASSERTION(!NS_FRAME_IS_COMPLETE(aStatus) || !frame->GetNextInFlow(), "bad child flow list"); } @@ -227,6 +201,8 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsPresContext* aPresContext, if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) { aDesiredSize.height = aReflowState.availableHeight; } + aDesiredSize.ascent = aDesiredSize.height; + aDesiredSize.descent = 0; PR_PL(("PageFrame::Reflow %p ", this)); PR_PL(("[%d,%d]\n", aReflowState.availableWidth, aReflowState.availableHeight)); @@ -345,8 +321,6 @@ nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext, break; } // switch - NS_ASSERTION(x >= 0, "x can't be less than zero"); - x = PR_MAX(x, 0); return x; } diff --git a/layout/generic/nsSimplePageSequence.cpp b/layout/generic/nsSimplePageSequence.cpp index c0caaef21a5..f5353aceb0e 100644 --- a/layout/generic/nsSimplePageSequence.cpp +++ b/layout/generic/nsSimplePageSequence.cpp @@ -89,7 +89,6 @@ nsSharedPageData::nsSharedPageData() : mReflowSize(0,0), mReflowMargin(0,0,0,0), mShadowSize(0,0), - mDeadSpaceMargin(0,0,0,0), mExtraMargin(0,0,0,0), mEdgePaperMargin(0,0,0,0), mPageContentXMost(0), @@ -135,8 +134,6 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame(nsStyleContext* aContext) : // now get the default font form the print options mPageData->mPrintOptions->GetDefaultFont(*mPageData->mHeadFootFont); } - mOffsetX = 0; - mOffsetY = 0; // Doing this here so we only have to go get these formats once SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE); @@ -207,6 +204,8 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { + NS_PRECONDITION(aPresContext->IsRootPaginatedDocument(), + "A Page Sequence is only for real pages"); DO_GLOBAL_REFLOW_COUNT("nsSimplePageSequenceFrame", aReflowState.reason); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_FRAME_TRACE_REFLOW_IN("nsSimplePageSequenceFrame::Reflow"); @@ -219,6 +218,9 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, aDesiredSize.width = mSize.width; aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; + aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, + aDesiredSize.height); + FinishAndStoreOverflow(&aDesiredSize); return NS_OK; } @@ -249,11 +251,10 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, // and if this Document is in the upper left hand corner // we need to suppress the top margin or it will reflow too small - PRBool suppressMargins = !aPresContext->IsRootPaginatedDocument(); nsSize pageSize = aPresContext->GetPageSize(); mPageData->mReflowSize = pageSize; - mPageData->mReflowMargin = suppressMargins ? nsMargin(0,0,0,0) : mMargin; + mPageData->mReflowMargin = mMargin; // Compute the size of each page and the x coordinate that each page will // be placed at @@ -269,11 +270,9 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, nscoord deadSpaceGap; GetDeadSpaceValue(&deadSpaceGap); - nsMargin deadSpaceMargin(0,0,0,0); nsMargin extraMargin(0,0,0,0); nsSize shadowSize(0,0); - if (aPresContext->IsScreen() && !suppressMargins) { - deadSpaceMargin.SizeTo(deadSpaceGap, deadSpaceGap, deadSpaceGap, deadSpaceGap); + if (aPresContext->IsScreen()) { extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap); nscoord fourPixels = aPresContext->IntScaledPixelsToTwips(4); shadowSize.SizeTo(fourPixels, fourPixels); @@ -281,13 +280,16 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, mPageData->mShadowSize = shadowSize; mPageData->mExtraMargin = extraMargin; - mPageData->mDeadSpaceMargin = deadSpaceMargin; - nscoord x = deadSpaceMargin.left; - nscoord y = deadSpaceMargin.top;// Running y-offset for each page + const nscoord x = deadSpaceGap; + nscoord y = deadSpaceGap;// Running y-offset for each page nsSize reflowPageSize(0,0); + nsSize availSize(pageSize.width + shadowSize.width + extraMargin.LeftRight(), + pageSize.height + shadowSize.height + + extraMargin.TopBottom()); + // See if it's an incremental reflow command if (!aPresContext->IsDynamic() && eReflowReason_Incremental == aReflowState.reason) { @@ -295,18 +297,8 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, // in fact, all we want is the initial reflow y = mRect.height; } else { - // XXX Part of Temporary fix for Bug 127263 - nsPageFrame::SetCreateWidget(PR_TRUE); - nsReflowReason reflowReason = aReflowState.reason; - 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); - // Tile the pages vertically nsHTMLReflowMetrics kidSize(nsnull); for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) { @@ -332,17 +324,6 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, FinishReflowChild(kidFrame, aPresContext, nsnull, kidSize, x, y, 0); y += kidSize.height; - // XXX Temporary fix for Bug 127263 - // This tells the nsPageFrame class to stop creating clipping widgets - // once we reach the 32k boundary for positioning - if (nsPageFrame::GetCreateWidget()) { - float t2p; - t2p = aPresContext->TwipsToPixels(); - nscoord xp = NSTwipsToIntPixels(x, t2p); - nscoord yp = NSTwipsToIntPixels(y, t2p); - nsPageFrame::SetCreateWidget(xp < 0x8000 && yp < 0x8000); - } - // Leave a slight gap between the pages y += deadSpaceGap; @@ -404,14 +385,13 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, } // Return our desired size - aDesiredSize.height = y; - aDesiredSize.width = reflowPageSize.width+deadSpaceMargin.right+shadowSize.width+extraMargin.right+extraMargin.left; + aDesiredSize.height = y; // includes page heights and dead space + aDesiredSize.width = x + availSize.width + deadSpaceGap; aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, aDesiredSize.height); - FinishAndStoreOverflow(&aDesiredSize); // cache the size so we can set the desired size @@ -520,8 +500,6 @@ nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext, if (aDocTitle) mPageData->mDocTitle = aDocTitle; if (aDocURL) mPageData->mDocURL = aDocURL; - aPrintSettings->GetMarginInTwips(mMargin); - aPrintSettings->GetStartPageRange(&mFromPageNum); aPrintSettings->GetEndPageRange(&mToPageNum); aPrintSettings->GetMarginInTwips(mMargin); @@ -776,11 +754,10 @@ nsSimplePageSequenceFrame::PrintNextPage() NS_ASSERTION(view, "no page view"); PR_PL(("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view)); - PR_PL((" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY)); vm->SetViewContentTransparency(view, PR_FALSE); - vm->Display(view, mOffsetX, mOffsetY, clipRect); + vm->Display(view, 0, 0, clipRect); if (mSelectionHeight > -1 && selectionY < mSelectionHeight) { selectionY += height; diff --git a/layout/generic/nsSimplePageSequence.h b/layout/generic/nsSimplePageSequence.h index 3ad7b2ad188..26edf7012f7 100644 --- a/layout/generic/nsSimplePageSequence.h +++ b/layout/generic/nsSimplePageSequence.h @@ -61,10 +61,15 @@ public: nsSize mReflowSize; nsMargin mReflowMargin; - 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 - nsMargin mEdgePaperMargin; // In twips, gap between the Margin and edge of page + // shadow of page in PrintPreview; drawn around bottom and right edges + nsSize mShadowSize; + // Extra Margin between the device area and the edge of the page; + // approximates unprintable area + nsMargin mExtraMargin; + // Margin for headers and footers; it defaults to 4/100 of an inch on UNIX + // and 0 elsewhere; I think it has to do with some inconsistency in page size + // computations + nsMargin mEdgePaperMargin; nsCOMPtr mPrintSettings; nsCOMPtr mPrintOptions; @@ -114,7 +119,6 @@ public: NS_IMETHOD IsDoingPrintRange(PRBool* aDoing); NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage); NS_IMETHOD DoPageEnd(); - NS_IMETHOD SetOffset(nscoord aX, nscoord aY) { mOffsetX = aX; mOffsetY = aY; return NS_OK; } /** * Get the "type" of the frame @@ -161,9 +165,6 @@ protected: PRInt32 mToPageNum; PRPackedBool mPrintThisPage; - nscoord mOffsetX; - nscoord mOffsetY; - nsSize mSize; nsSharedPageData* mPageData; // data shared by all the nsPageFrames diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 33449655384..58d051ad1a0 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -241,7 +241,6 @@ nsPrintEngine::nsPrintEngine() : mDocViewer(nsnull), mContainer(nsnull), mDeviceContext(nsnull), - mPresContext(nsnull), mPrt(nsnull), mPagePrintTimer(nsnull), mPageSeqFrame(nsnull), @@ -334,7 +333,6 @@ nsresult nsPrintEngine::Initialize(nsIDocumentViewer* aDocViewer, mContainer = aContainer; // weak reference mDocument = aDocument; mDeviceContext = aDevContext; // weak reference - mPresContext = aPresContext; // weak reference mWindow = aWindow; mParentWidget = aParentWidget; @@ -441,7 +439,6 @@ nsPrintEngine::GetSeqFrameAndCountPagesInternal(nsPrintObject* aPO, NS_ENSURE_ARG_POINTER(aPO); // Finds the SimplePageSequencer frame - // in PP mPrtPreview->mPrintObject->mSeqFrame is null nsIPageSequenceFrame* seqFrame = nsnull; aPO->mPresShell->GetPageSequenceFrame(&seqFrame); if (seqFrame) { @@ -689,9 +686,6 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, // NS_ERROR_NOT_IMPLEMENTED indicates they want default behavior // Any other error code means we must bail out // - if (mDialogParentWin) { - domWin = mDialogParentWin; - } nsCOMPtr wbp(do_QueryInterface(mDocViewerPrint)); rv = printPromptService->ShowPrintDialog(domWin, wbp, mPrt->mPrintSettings); @@ -737,8 +731,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NODEVSPEC, rv, NS_ERROR_FAILURE); if (NS_SUCCEEDED(rv)) { - rv = mPresContext->DeviceContext()-> - GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC)); + rv = mDeviceContext->GetDeviceContextFor(devspec, + *getter_AddRefs(mPrt->mPrintDC)); if (NS_SUCCEEDED(rv)) { // Get the Original PixelScale incase we need to start changing it mPrt->mPrintDC->GetCanonicalPixelScale(mPrt->mOrigDCScale); @@ -750,54 +744,6 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, } if(webContainer) { -#ifdef DEBUG_dcone - float a1,a2; - PRInt32 i1,i2; - - printf("CRITICAL PRINTING INFORMATION\n"); - - // DEVICE CONTEXT INFORMATION from PresContext - nsIDeviceContext *dx = mPresContext->DeviceContext(); - printf("DeviceContext of Presentation Context(%x)\n", dx); - a1 = dx->DevUnitsToTwips(); - a2 = dx->TwipsToDevUnits(); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - a1 = dx->AppUnitsToDevUnits(); - a2 = dx->DevUnitsToAppUnits(); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - dx->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - dx->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - dx->GetZoom(a1); - printf(" Zoom = %f\n",a1); - dx->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - dx->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - - - // DEVICE CONTEXT INFORMATION - printf("DeviceContext created for print(%x)\n",mPrt->mPrintDC); - a1 = mPrt->mPrintDC->DevUnitsToTwips(); - a2 = mPrt->mPrintDC->TwipsToDevUnits(); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - a1 = mPrt->mPrintDC->AppUnitsToDevUnits(); - a2 = mPrt->mPrintDC->DevUnitsToAppUnits(); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - mPrt->mPrintDC->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - mPrt->mPrintDC->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - mPrt->mPrintDC->GetZoom(a1); - printf(" Zoom = %f\n",a1); - mPrt->mPrintDC->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - -#endif /* DEBUG_dcone */ - // Always check and set the print settings first and then fall back // onto the PrintService if there isn't a PrintSettings // @@ -1158,7 +1104,6 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings, // end observing the document BEFORE we do any new reflows if (cacheOldPres && !HasCachedPres()) { SetCacheOldPres(PR_TRUE); - mPresContext->PresShell()->EndObservingDocument(); } if (aWebProgressListener != nsnull) { @@ -1243,8 +1188,6 @@ nsPrintEngine::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 (!mPrtPreview || @@ -1866,21 +1809,15 @@ nsPrintEngine::IsThereAnIFrameSelected(nsIDocShell* aDocShell, // Recursively sets all the PO items to be printed // from the given item down into the tree void -nsPrintEngine::SetPrintPO(nsPrintObject* aPO, PRBool aPrint, - PRBool aIsHidden, PRUint32 aFlags) +nsPrintEngine::SetPrintPO(nsPrintObject* aPO, PRBool aPrint) { NS_ASSERTION(aPO, "Pointer is null!"); // Set whether to print flag - // If it is hidden dont' allow ANY changes to the mDontPrint - // because mDontPrint has already been turned off - if ((aFlags & eSetPrintFlag) && !aPO->mIsHidden) aPO->mDontPrint = !aPrint; - - // Set hidden flag - if (aFlags & eSetHiddenFlag) aPO->mIsHidden = aIsHidden; + aPO->mDontPrint = !aPrint; for (PRInt32 i=0;imKids.Count();i++) { - SetPrintPO((nsPrintObject*)aPO->mKids[i], aPrint, aIsHidden, aFlags); + SetPrintPO((nsPrintObject*)aPO->mKids[i], aPrint); } } @@ -2138,7 +2075,7 @@ nsPrintEngine::SetupToPrintContent(nsIDeviceContext* aDContext, } // Here we reflow all the PrintObjects - nsresult rv = ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit); + nsresult rv = ReflowDocList(mPrt->mPrintObject, doSetPixelScale); CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_REFLOWDOCLIST, rv, NS_ERROR_FAILURE); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE; @@ -2185,7 +2122,7 @@ nsPrintEngine::SetupToPrintContent(nsIDeviceContext* aDContext, // Here we reflow all the PrintObjects a second time // this time using the shrinkage values // The last param here tells reflow to NOT calc the shrinkage values - if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, PR_TRUE, PR_FALSE))) { + if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, PR_TRUE))) { return NS_ERROR_FAILURE; } } @@ -2288,13 +2225,12 @@ nsPrintEngine::SetupToPrintContent(nsIDeviceContext* aDContext, // Recursively reflow each sub-doc and then calc // all the frame locations of the sub-docs nsresult -nsPrintEngine::ReflowDocList(nsPrintObject* aPO, PRBool aSetPixelScale, PRBool aDoCalcShrink) +nsPrintEngine::ReflowDocList(nsPrintObject* aPO, PRBool aSetPixelScale) { - NS_ASSERTION(aPO, "Pointer is null!"); - if (!aPO) return NS_ERROR_FAILURE; + NS_ENSURE_ARG_POINTER(aPO); // Check to see if the subdocument's element has been hidden by the parent document - if (aPO->mParent) { + if (aPO->mParent && aPO->mParent->mPresShell) { nsIFrame * frame = aPO->mParent->mPresShell->GetPrimaryFrameFor(aPO->mContent); if (frame) { if (!frame->GetStyleVisibility()->IsVisible()) { @@ -2305,9 +2241,6 @@ nsPrintEngine::ReflowDocList(nsPrintObject* aPO, PRBool aSetPixelScale, PRBool a } } - // Don't reflow hidden POs - if (aPO->mIsHidden) return NS_OK; - // Here is where we set the shrinkage value into the DC // and this is what actually makes it shrink if (aSetPixelScale && aPO->mFrameType != eIFrame) { @@ -2320,21 +2253,15 @@ nsPrintEngine::ReflowDocList(nsPrintObject* aPO, PRBool aSetPixelScale, PRBool a mPrt->mPrintDC->SetCanonicalPixelScale(ratio*mPrt->mOrigDCScale); } + nsresult rv; // Reflow the PO - if (NS_FAILED(ReflowPrintObject(aPO, aDoCalcShrink))) { - return NS_ERROR_FAILURE; - } - - // Calc the absolute poistion of the frames - if (NS_FAILED(MapSubDocFrameLocations(aPO))) { - return NS_ERROR_FAILURE; - } + rv = ReflowPrintObject(aPO); + NS_ENSURE_SUCCESS(rv, rv); PRInt32 cnt = aPO->mKids.Count(); for (PRInt32 i=0;imKids[i], aSetPixelScale, aDoCalcShrink))) { - return NS_ERROR_FAILURE; - } + rv = ReflowDocList((nsPrintObject *)aPO->mKids[i], aSetPixelScale); + NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } @@ -2342,16 +2269,42 @@ nsPrintEngine::ReflowDocList(nsPrintObject* aPO, PRBool aSetPixelScale, PRBool a //------------------------------------------------------- // Reflow a nsPrintObject nsresult -nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) +nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) { NS_ASSERTION(aPO, "Pointer is null!"); if (!aPO) return NS_ERROR_FAILURE; - // If it is hidden don't bother reflowing it or any of its children - if (aPO->mIsHidden) return NS_OK; + nsSize adjSize; + PRBool documentIsTopLevel; + nsIFrame* frame = nsnull; + if (!aPO->IsPrintable()) + return NS_OK; + + if (aPO->mParent && aPO->mParent->IsPrintable()) { + if (aPO->mParent->mPresShell) { + frame = aPO->mParent->mPresShell->FrameManager()-> + GetPrimaryFrameFor(aPO->mContent); + } + // Without a frame, this document can't be displayed; therefore, there is no + // point to reflowing it + if (!frame) + return NS_OK; + + nsMargin borderPadding(0, 0, 0, 0); + frame->CalcBorderPadding(borderPadding); + nsRect rect(frame->GetRect()); + rect.Deflate(borderPadding); + adjSize = rect.Size(); + documentIsTopLevel = PR_FALSE; + // presshell exists because parent is printable + } else { + PRInt32 pageWidth, pageHeight; + mPrt->mPrintDocDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight); + adjSize = nsSize(pageWidth, pageHeight); + documentIsTopLevel = PR_TRUE; + } // create the PresContext - PRBool containerIsSet = PR_FALSE; aPO->mPresContext = new nsPresContext(mIsCreatingPrintPreview ? nsPresContext::eContext_PrintPreview: nsPresContext::eContext_Print); @@ -2365,13 +2318,9 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) mPrt->mPrintSettings->GetPrintBGImages(&printBGColors); aPO->mPresContext->SetBackgroundImageDraw(printBGColors); - // init it with the DC nsresult rv = aPO->mPresContext->Init(mPrt->mPrintDocDC); - if (NS_FAILED(rv)) { - aPO->mPresContext = nsnull; - return rv; - } + NS_ENSURE_SUCCESS(rv, rv); aPO->mViewManager = do_CreateInstance(kViewManagerCID, &rv); NS_ENSURE_SUCCESS(rv,rv); @@ -2394,20 +2343,6 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // The pres shell now owns the style set object. - nsSize adjSize; - PRBool documentIsTopLevel; - if (aPO->mContent == nsnull || !aPO->mPrintAsIs || - (aPO->mPrintAsIs && aPO->mParent && !aPO->mParent->mPrintAsIs) || - (aPO->mFrameType == eIFrame && aPO == mPrt->mSelectedPO)) { - PRInt32 pageWidth, pageHeight; - mPrt->mPrintDocDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight); - adjSize = nsSize(pageWidth, pageHeight); - documentIsTopLevel = PR_TRUE; - } else { - adjSize = aPO->mRect.Size(); - documentIsTopLevel = PR_FALSE; - } - PR_PL(("In DV::ReflowPrintObject PO: %p (%9s) Setting w,h to %d,%d\n", aPO, gFrameTypesStr[aPO->mFrameType], adjSize.width, adjSize.height)); @@ -2418,90 +2353,59 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // one page put it keeps it from page breaking in the middle of your // print of the selection (see also nsSimplePageSequence.cpp) PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; - if (mPrt->mPrintSettings != nsnull) { - mPrt->mPrintSettings->GetPrintRange(&printRangeType); - } + mPrt->mPrintSettings->GetPrintRange(&printRangeType); if (printRangeType == nsIPrintSettings::kRangeSelection && IsThereARangeSelection(mPrt->mPrintDocDW)) { adjSize.height = NS_UNCONSTRAINEDSIZE; } - nsRect tbounds = nsRect(nsPoint(0, 0), adjSize); - - // Create a child window of the parent that is our "root view/window" - // Note that the view has no parent, making for a discontinuous view tree. - aPO->mRootView = aPO->mViewManager->CreateView(tbounds, nsnull); - NS_ENSURE_TRUE(aPO->mRootView, NS_ERROR_OUT_OF_MEMORY); - -#ifdef NS_PRINT_PREVIEW // Here we decide whether we need scrollbars and // what the parent will be of the widget // How this logic presently works: Print Preview is always as-is (as far // as I can tell; not sure how it would work in other cases); only the root // is not eIFrame or eFrame. The child documents get a parent widget from // logic in nsFrameFrame. In any case, a child widget is created for the root - // view of the document. The widget is managed entirely by the printing code. - // This setup, although awkward, works fine. - if (mIsCreatingPrintPreview) { - PRBool canCreateScrollbars = PR_FALSE; - nsCOMPtr widget = mParentWidget; - // the top nsPrintObject's widget will always have scrollbars - if (aPO->mParent != nsnull && aPO->mContent) { - nsFrameManager *frameMan = aPO->mParent->mPresShell->FrameManager(); - nsIFrame* frame = frameMan->GetPrimaryFrameFor(aPO->mContent); - if (frame) { - nsIView* view = frame->GetView(); - NS_ASSERTION(view, "Primary frame for subdoc must have view!"); - if (view) { - if (aPO->mFrameType == eIFrame || aPO->mFrameType == eFrame) { - view = view->GetFirstChild(); - NS_ASSERTION(view, "innerView not found"); - } - - if (view && view->HasWidget()) { - widget = view->GetWidget(); - } - } - } - } else { - canCreateScrollbars = PR_TRUE; - } - rv = aPO->mRootView->CreateWidget(kWidgetCID, nsnull, - widget->GetNativeData(NS_NATIVE_WIDGET), - PR_TRUE, PR_TRUE, - eContentTypeContent); - aPO->mWindow = aPO->mRootView->GetWidget(); - aPO->mPresContext->SetPaginatedScrolling(canCreateScrollbars); + // view of the document. + PRBool canCreateScrollbars = PR_FALSE; + nsNativeWidget widget; + nsIView* parentView; + // the top nsPrintObject's widget will always have scrollbars + if (frame) { + nsIView* view = frame->GetView(); + NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); + view = view->GetFirstChild(); + NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); + parentView = view; + widget = nsnull; + } else { + canCreateScrollbars = PR_TRUE; + parentView = nsnull; + widget = mParentWidget->GetNativeData(NS_NATIVE_WIDGET); } -#endif // NS_PRINT_PREVIEW + + // Create a child window of the parent that is our "root view/window" + nsRect tbounds = nsRect(nsPoint(0, 0), adjSize); + aPO->mRootView = aPO->mViewManager->CreateView(tbounds, parentView); + NS_ENSURE_TRUE(aPO->mRootView, NS_ERROR_OUT_OF_MEMORY); + + rv = aPO->mRootView->CreateWidget(kWidgetCID, nsnull, + widget, PR_TRUE, PR_TRUE, + eContentTypeContent); + NS_ENSURE_SUCCESS(rv, rv); + aPO->mWindow = aPO->mRootView->GetWidget(); + aPO->mPresContext->SetPaginatedScrolling(canCreateScrollbars); // Setup hierarchical relationship in view manager aPO->mViewManager->SetRootView(aPO->mRootView); - if (!containerIsSet) { - nsCOMPtr supps(do_QueryInterface(aPO->mDocShell)); - aPO->mPresContext->SetContainer(supps); - } - - // get the old history - nsCOMPtr presShell; - nsCOMPtr layoutState; - rv = mDocViewer->GetPresShell(getter_AddRefs(presShell)); - NS_ENSURE_SUCCESS(rv, rv); - presShell->CaptureHistoryState(getter_AddRefs(layoutState), PR_TRUE); - - // set it on the new pres shell - aPO->mDocShell->SetLayoutHistoryState(layoutState); + // This docshell stuff is weird; will go away when we stop having multiple + // presentations per document + nsCOMPtr supps(do_QueryInterface(aPO->mDocShell)); + aPO->mPresContext->SetContainer(supps); aPO->mPresShell->BeginObservingDocument(); - if (adjSize.width == 0 || adjSize.height == 0) { - aPO->mDontPrint = PR_TRUE; - aPO->mPresShell->EndObservingDocument(); - return NS_OK; - } - aPO->mPresContext->SetPageSize(adjSize); aPO->mPresContext->SetIsRootPaginatedDocument(documentIsTopLevel); @@ -2530,7 +2434,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // Then we walk the frame tree and look for the "xmost" frame // this is the frame where the right-hand side of the frame extends // the furthest - if (mPrt->mShrinkToFit) { + if (mPrt->mShrinkToFit && documentIsTopLevel) { nsIPageSequenceFrame* pageSequence; aPO->mPresShell->GetPageSequenceFrame(&pageSequence); pageSequence->GetSTFPercent(aPO->mShrinkRatio); @@ -2585,98 +2489,6 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) return rv; } -//------------------------------------------------------- -// This recusively walks the PO tree calculating the -// the page location and the absolute frame location for -// a sub-doc. -// -// NOTE: This MUST be done after the sub-doc has been laid out -// This is called by "ReflowDocList" -// -nsresult -nsPrintEngine::MapSubDocFrameLocations(nsPrintObject* aPO) -{ - nsIPresShell* presShell = aPO->mPresShell; - NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - for (PRInt32 i = 0; i < aPO->mKids.Count(); i++) { - nsresult rv = CalcPageFrameLocation(presShell, - (nsPrintObject*)aPO->mKids[i]); - NS_ENSURE_SUCCESS(rv, rv); - } - return NS_OK; -} - -//------------------------------------------------------- -// Finds the Page Frame and the absolute location on the page -// for a Sub document. -// -// NOTE: This MUST be done after the sub-doc has been laid out -// This is called by "MapSubDocFrameLocations" -// -nsresult -nsPrintEngine::CalcPageFrameLocation(nsIPresShell* aPresShell, - nsPrintObject* aPO) -{ - NS_ASSERTION(aPresShell, "Pointer is null!"); - NS_ASSERTION(aPO, "Pointer is null!"); - - if (aPO != nsnull && aPO->mContent != nsnull) { - - // Find that frame for the sub-doc's content element - // in the parent document - // if it comes back null it probably has the style - // set to "display:none" - nsIFrame * frame = aPresShell->GetPrimaryFrameFor(aPO->mContent); - if (!frame) { - aPO->mDontPrint = PR_TRUE; - return NS_OK; - } - - nsMargin borderPadding(0, 0, 0, 0); - frame->CalcBorderPadding(borderPadding); - - // Calc absolute position of the frame all the way up - // to the SimpleSeq frame - nsRect rect(frame->GetRect()); - rect.Deflate(borderPadding); - - nsIFrame * parent = frame->GetParent(); - nsIFrame * pageFrame = nsnull; - nsIFrame * seqFrame = nsnull; - while (parent) { - rect.MoveBy(parent->GetPosition()); - nsIFrame * temp = parent; - parent = temp->GetParent(); - // Keep a pointer to the Seq and Page frames - nsIPageSequenceFrame * sqf = nsnull; - if (parent && - NS_SUCCEEDED(CallQueryInterface(parent, &sqf)) && sqf) { - pageFrame = temp; - seqFrame = parent; - break; - } - } - NS_ENSURE_TRUE(seqFrame && pageFrame, NS_ERROR_FAILURE); - - // Remember the Frame location information for later - aPO->mRect = rect; - aPO->mSeqFrame = seqFrame; - - // Calc the Page No it is on - PRInt32 pageNum = 1; - nsIFrame* child = seqFrame->GetFirstChild(nsnull); - while (child != nsnull) { - if (pageFrame == child) { - aPO->mPageNum = pageNum; - break; - } - pageNum++; - child = child->GetNextSibling(); - } // while - } - return NS_OK; -} - //------------------------------------------------------- // Figure out how many documents and how many total pages we are printing void @@ -2687,27 +2499,23 @@ nsPrintEngine::CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPage // and printable pages PRInt32 numOfPrintableDocs = 0; PRInt32 i; - for (i=0;imPrintDocList->Count();i++) { + for (i=0; imPrintDocList->Count(); i++) { nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i); NS_ASSERTION(po, "nsPrintObject can't be null!"); - if (po->IsPrintable()) { - if (po->mPresShell && - po->mFrameType != eIFrame && - po->mFrameType != eFrameSet) { - nsIPageSequenceFrame* pageSequence; - po->mPresShell->GetPageSequenceFrame(&pageSequence); - nsIFrame * seqFrame; - if (NS_SUCCEEDED(CallQueryInterface(pageSequence, &seqFrame))) { - nsIFrame* frame = seqFrame->GetFirstChild(nsnull); - while (frame) { - aNumPages++; - frame = frame->GetNextSibling(); - } + if (po->mPresContext && po->mPresContext->IsRootPaginatedDocument()) { + nsIPageSequenceFrame* pageSequence; + po->mPresShell->GetPageSequenceFrame(&pageSequence); + nsIFrame * seqFrame; + if (NS_SUCCEEDED(CallQueryInterface(pageSequence, &seqFrame))) { + nsIFrame* frame = seqFrame->GetFirstChild(nsnull); + while (frame) { + aNumPages++; + frame = frame->GetNextSibling(); } } - - numOfPrintableDocs++; } + + numOfPrintableDocs++; } } //----------------------------------------------------------------- @@ -2727,12 +2535,8 @@ nsPrintEngine::PrintDocContent(nsPrintObject* aPO, nsresult& aStatus) aStatus = NS_OK; if (!aPO->mHasBeenPrinted && aPO->IsPrintable()) { - PRBool donePrinting = PR_TRUE; - // donePrinting is only valid when when doing synchronous printing - aStatus = DoPrint(aPO, PR_FALSE, donePrinting); - if (donePrinting) { - return PR_TRUE; - } + aStatus = DoPrint(aPO); + return PR_TRUE; } // If |aPO->mPrintAsIs| and |aPO->mHasBeenPrinted| are true, @@ -2751,21 +2555,23 @@ nsPrintEngine::PrintDocContent(nsPrintObject* aPO, nsresult& aStatus) //------------------------------------------------------- nsresult -nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDonePrinting) +nsPrintEngine::DoPrint(nsPrintObject * aPO) { NS_ASSERTION(mPrt->mPrintDocList, "Pointer is null!"); PR_PL(("\n")); PR_PL(("**************************** %s ****************************\n", gFrameTypesStr[aPO->mFrameType])); - PR_PL(("****** In DV::DoPrint PO: %p aDoSyncPrinting: %s \n", aPO, PRT_YESNO(aDoSyncPrinting))); + PR_PL(("****** In DV::DoPrint PO: %p \n", aPO)); nsIDocShell* docShell = aPO->mDocShell; nsIPresShell* poPresShell = aPO->mPresShell; - nsPresContext* poPresContext = aPO->mPresContext; + nsPresContext* poPresContext = aPO->mPresContext; nsIView* poRootView = aPO->mRootView; NS_ASSERTION(docShell, "The DocShell can't be NULL!"); NS_ASSERTION(poPresContext, "PrintObject has not been reflowed"); + NS_ENSURE_TRUE(poPresContext->Type() != nsPresContext::eContext_PrintPreview, + NS_OK); if (mPrt->mPrintProgressParams) { SetDocAndURLIntoProgress(aPO, mPrt->mPrintProgressParams); @@ -2784,16 +2590,6 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDon poPresShell->GetPageSequenceFrame(&pageSequence); NS_ASSERTION(nsnull != pageSequence, "no page sequence frame"); - nscoord x = 0; - nscoord y = 0; - nsPrintObject * po = aPO; - while (po && po->mParent && po->mParent->IsPrintable()) { - x += po->mRect.x; - y += po->mRect.y; - po = po->mParent; - } - pageSequence->SetOffset(x, y); - // We are done preparing for printing, so we can turn this off mPrt->mPreparingForPrint = PR_FALSE; @@ -2891,41 +2687,17 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDon return NS_ERROR_FAILURE; } - if (poPresContext->Type() != nsPresContext::eContext_PrintPreview) { - nscoord sheight = seqFrame->GetSize().height; + mPageSeqFrame = pageSequence; + mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings, docTitleStr, docURLStr); - nsRect r = poRootView->GetBounds(); - r.x = r.y = 0; - r.height = sheight; - aPO->mViewManager->ResizeView(poRootView, r, PR_FALSE); + // Get the delay time in between the printing of each page + // this gives the user more time to press cancel + PRInt32 printPageDelay = 500; + mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay); - r = rootFrame->GetRect(); - - r.height = sheight; - rootFrame->SetRect(r); - - mPageSeqFrame = pageSequence; - mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings, docTitleStr, docURLStr); - - if (!aDoSyncPrinting) { - // Get the delay time in between the printing of each page - // this gives the user more time to press cancel - PRInt32 printPageDelay = 500; - mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay); - - // Schedule Page to Print - PR_PL(("Scheduling Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType])); - StartPagePrintTimer(poPresContext, mPrt->mPrintSettings, aPO, printPageDelay); - } else { - DoProgressForAsIsFrames(); - // Print the page synchronously - PR_PL(("Async Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType])); - PRBool inRange; - aDonePrinting = PrintPage(poPresContext, mPrt->mPrintSettings, aPO, inRange); - } - } else { - pageSequence->StartPrint(poPresContext, mPrt->mPrintSettings, docTitleStr, docURLStr); - } + // Schedule Page to Print + PR_PL(("Scheduling Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType])); + StartPagePrintTimer(poPresContext, mPrt->mPrintSettings, aPO, printPageDelay); } else { // not sure what to do here! SetIsPrinting(PR_FALSE); @@ -2933,8 +2705,8 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDon } } } else { - aPO->mDontPrint = PR_TRUE; - aDonePrinting = PR_FALSE; + // This is sort of an odd case; just continue with the next object + aPO->mHasBeenPrinted = PR_TRUE; } return NS_OK; @@ -3105,32 +2877,6 @@ nsPrintEngine::PrintPage(nsPresContext* aPresContext, return PR_TRUE; } - // Now see if any of the SubDocs are on this page - if (aPO->mPrintAsIs) { - nsIPageSequenceFrame * curPageSeq = mPageSeqFrame; - aPO->mHasBeenPrinted = PR_TRUE; - PRInt32 cnt = aPO->mKids.Count(); - for (PRInt32 i=0;imKids[i]; - if (po->IsPrintable()) { - // Now verify that SubDoc's PageNum matches the - // page num of its parent doc - curPageSeq->GetCurrentPageNum(&pageNum); - nsIFrame* fr; - CallQueryInterface(curPageSeq, &fr); - - if (fr == po->mSeqFrame && pageNum == po->mPageNum) { - PRBool donePrintingSubDoc; - // synchronous printing, it changes the value mPageSeqFrame - // Note that this only prints one page - DoPrint(po, PR_TRUE, donePrintingSubDoc); - po->mHasBeenPrinted = PR_TRUE; - } - } - } // while - mPageSeqFrame = curPageSeq; - } - mPageSeqFrame->DoPageEnd(); // XXX this is because PrintAsIs for FrameSets reflows to two pages diff --git a/layout/printing/nsPrintEngine.h b/layout/printing/nsPrintEngine.h index f9efef65e63..3700a03ef5f 100644 --- a/layout/printing/nsPrintEngine.h +++ b/layout/printing/nsPrintEngine.h @@ -156,16 +156,9 @@ public: nsPrintObject* FindSmallestSTF(); PRBool PrintDocContent(nsPrintObject* aPO, nsresult& aStatus); - nsresult DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, - PRBool& aDonePrinting); + nsresult DoPrint(nsPrintObject * aPO); - enum ePrintFlags { - eSetPrintFlag = 1U, - eSetHiddenFlag = 2U - }; - void SetPrintPO(nsPrintObject* aPO, PRBool aPrint, - PRBool aIsHidden = PR_FALSE, - PRUint32 aFlags = eSetPrintFlag); + void SetPrintPO(nsPrintObject* aPO, PRBool aPrint); void TurnScriptingOn(PRBool aDoTurnOn); PRBool CheckDocumentForPPCaching(); @@ -181,10 +174,9 @@ public: void BuildDocTree(nsIDocShellTreeNode * aParentNode, nsVoidArray * aDocList, nsPrintObject * aPO); - nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale, - PRBool aDoCalcShrink); + nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale); - nsresult ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink); + nsresult ReflowPrintObject(nsPrintObject * aPO); void CheckForChildFrameSets(nsPrintObject* aPO); @@ -273,11 +265,6 @@ public: static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell); - void SetDialogParent(nsIDOMWindow* aDOMWin) - { - mDialogParentWin = aDOMWin; - } - // These calls also update the DocViewer void SetIsPrinting(PRBool aIsPrinting); PRBool GetIsPrinting() @@ -358,11 +345,6 @@ protected: static void MapContentToWebShells(nsPrintObject* aRootPO, nsPrintObject* aPO); - static nsresult MapSubDocFrameLocations(nsPrintObject* aPO); - - static nsresult CalcPageFrameLocation(nsIPresShell* aPresShell, - nsPrintObject* aPO); - static void SetPrintAsIs(nsPrintObject* aPO, PRBool aAsIs = PR_TRUE); // Static member variables @@ -373,7 +355,6 @@ protected: nsIDocumentViewer* mDocViewer; // [WEAK] it owns me! nsISupports* mContainer; // [WEAK] it owns me! nsIDeviceContext* mDeviceContext; // not ref counted - nsPresContext* mPresContext; // not ref counted nsCOMPtr mWindow; nsPrintData* mPrt; @@ -387,7 +368,6 @@ protected: nsPrintData* mOldPrtPreview; nsCOMPtr mDocument; - nsCOMPtr mDialogParentWin; PRBool mIsCachingPresentation; CachedPresentationObj* mCachedPresObj; diff --git a/layout/printing/nsPrintObject.cpp b/layout/printing/nsPrintObject.cpp index 152a202a0c0..c1f3fb2d3db 100644 --- a/layout/printing/nsPrintObject.cpp +++ b/layout/printing/nsPrintObject.cpp @@ -41,10 +41,9 @@ //-- nsPrintObject Class Impl //--------------------------------------------------- nsPrintObject::nsPrintObject() : - mFrameType(eFrame), mRootView(nsnull), mContent(nsnull), mSeqFrame(nsnull), - mPageNum(-1), mRect(0,0,0,0), mParent(nsnull), mHasBeenPrinted(PR_FALSE), - mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE), - mSharedPresShell(PR_FALSE), mIsHidden(PR_FALSE), mInvisible(PR_FALSE), + mFrameType(eFrame), mRootView(nsnull), mContent(nsnull), mParent(nsnull), + mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE), + mSharedPresShell(PR_FALSE), mInvisible(PR_FALSE), mDocTitle(nsnull), mDocURL(nsnull), mShrinkRatio(1.0) { } diff --git a/layout/printing/nsPrintObject.h b/layout/printing/nsPrintObject.h index e1eca06ceb3..ef56aa0b23f 100644 --- a/layout/printing/nsPrintObject.h +++ b/layout/printing/nsPrintObject.h @@ -83,9 +83,6 @@ public: nsIView* mRootView; nsIContent* mContent; - nsIFrame* mSeqFrame; - PRInt32 mPageNum; - nsRect mRect; PrintObjectType mFrameType; nsVoidArray mKids; @@ -94,7 +91,6 @@ public: PRPackedBool mDontPrint; PRPackedBool mPrintAsIs; PRPackedBool mSharedPresShell; - PRPackedBool mIsHidden; // Indicates PO is hidden, not reflowed, not shown PRPackedBool mInvisible; // Indicates PO is set to not visible by CSS PRUnichar* mDocTitle;