2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-11-05 02:21:50 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-11-05 02:21:50 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-11-05 02:21:50 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1998-11-05 02:21:50 +03:00
|
|
|
#include "nsSimplePageSequence.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2008-04-08 04:32:48 +04:00
|
|
|
#include "gfxContext.h"
|
1998-11-05 09:13:55 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-12-07 06:43:02 +03:00
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsIFontMetrics.h"
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsIPrintSettings.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsPageFrame.h"
|
2001-12-05 01:46:41 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2002-08-30 07:32:05 +04:00
|
|
|
#include "nsRegion.h"
|
2004-01-22 02:05:10 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2004-04-30 03:34:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2001-11-28 18:19:47 +03:00
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// DateTime Includes
|
|
|
|
#include "nsDateTimeFormatCID.h"
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
#define OFFSET_NOT_SET -1
|
|
|
|
|
|
|
|
// Print Options
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsIPrintSettings.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsIPrintOptions.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-05-14 18:15:19 +04:00
|
|
|
|
2002-05-14 18:32:42 +04:00
|
|
|
static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printsettings-service;1";
|
2002-05-14 16:05:00 +04:00
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
//
|
1998-12-07 06:43:02 +03:00
|
|
|
|
2002-06-20 01:51:13 +04:00
|
|
|
#include "prlog.h"
|
|
|
|
#ifdef PR_LOGGING
|
2002-08-27 01:20:31 +04:00
|
|
|
PRLogModuleInfo * kLayoutPrintingLogMod = PR_NewLogModule("printing-layout");
|
|
|
|
#define PR_PL(_p1) PR_LOG(kLayoutPrintingLogMod, PR_LOG_DEBUG, _p1)
|
2002-06-20 01:51:13 +04:00
|
|
|
#else
|
|
|
|
#define PR_PL(_p1)
|
2001-04-12 17:04:29 +04:00
|
|
|
#endif
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// This object a shared by all the nsPageFrames
|
|
|
|
// parented to a SimplePageSequenceFrame
|
|
|
|
nsSharedPageData::nsSharedPageData() :
|
|
|
|
mDateTimeStr(nsnull),
|
|
|
|
mHeadFootFont(nsnull),
|
|
|
|
mPageNumFormat(nsnull),
|
|
|
|
mPageNumAndTotalsFormat(nsnull),
|
2002-05-07 16:03:37 +04:00
|
|
|
mDocTitle(nsnull),
|
|
|
|
mDocURL(nsnull),
|
2006-03-30 04:27:42 +04:00
|
|
|
mReflowSize(0,0),
|
2001-11-03 17:59:39 +03:00
|
|
|
mReflowMargin(0,0,0,0),
|
|
|
|
mShadowSize(0,0),
|
2001-11-29 13:26:51 +03:00
|
|
|
mExtraMargin(0,0,0,0),
|
2002-09-26 15:25:04 +04:00
|
|
|
mEdgePaperMargin(0,0,0,0),
|
2002-10-01 07:42:07 +04:00
|
|
|
mPageContentXMost(0),
|
|
|
|
mPageContentSize(0)
|
2001-11-03 17:59:39 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSharedPageData::~nsSharedPageData()
|
|
|
|
{
|
|
|
|
nsMemory::Free(mDateTimeStr);
|
|
|
|
if (mHeadFootFont) delete mHeadFootFont;
|
|
|
|
nsMemory::Free(mPageNumFormat);
|
|
|
|
nsMemory::Free(mPageNumAndTotalsFormat);
|
2002-05-07 16:03:37 +04:00
|
|
|
if (mDocTitle) nsMemory::Free(mDocTitle);
|
|
|
|
if (mDocURL) nsMemory::Free(mDocURL);
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
|
|
|
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-05-12 02:03:29 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsSimplePageSequenceFrame(aContext);
|
1999-05-12 02:03:29 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSimplePageSequenceFrame)
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsSimplePageSequenceFrame::nsSimplePageSequenceFrame(nsStyleContext* aContext) :
|
|
|
|
nsContainerFrame(aContext),
|
2002-02-12 16:33:39 +03:00
|
|
|
mTotalPages(-1),
|
2001-11-03 17:59:39 +03:00
|
|
|
mSelectionHeight(-1),
|
|
|
|
mYSelOffset(0)
|
2001-01-27 17:09:34 +03:00
|
|
|
{
|
2010-08-13 13:58:04 +04:00
|
|
|
nscoord halfInch = PresContext()->CSSTwipsToAppUnits(NS_INCHES_TO_TWIPS(0.5));
|
2001-01-27 17:09:34 +03:00
|
|
|
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
|
|
|
|
|
2006-07-14 20:07:28 +04:00
|
|
|
// XXX Unsafe to assume successful allocation
|
2001-11-03 17:59:39 +03:00
|
|
|
mPageData = new nsSharedPageData();
|
2007-03-31 01:11:41 +04:00
|
|
|
mPageData->mHeadFootFont = new nsFont(*PresContext()->GetDefaultFont(kGenericFont_serif));
|
2010-08-13 13:58:04 +04:00
|
|
|
mPageData->mHeadFootFont->size = nsPresContext::CSSPointsToAppUnits(10);
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
nsresult rv;
|
2002-05-14 18:32:42 +04:00
|
|
|
mPageData->mPrintOptions = do_GetService(sPrintOptionsContractID, &rv);
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
// Doing this here so we only have to go get these formats once
|
|
|
|
SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE);
|
|
|
|
SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
|
1999-05-12 02:03:29 +04:00
|
|
|
{
|
2001-11-03 17:59:39 +03:00
|
|
|
if (mPageData) delete mPageData;
|
1999-05-12 02:03:29 +04:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsSimplePageSequenceFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIPageSequenceFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
1998-12-07 06:43:02 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
1998-11-05 02:21:50 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext,
|
1998-11-05 02:21:50 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2006-04-11 05:48:48 +04:00
|
|
|
NS_PRECONDITION(aPresContext->IsRootPaginatedDocument(),
|
|
|
|
"A Page Sequence is only for real pages");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsSimplePageSequenceFrame");
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
1998-11-05 02:21:50 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_IN("nsSimplePageSequenceFrame::Reflow");
|
|
|
|
|
1999-03-10 01:34:51 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE; // we're always complete
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2007-04-26 09:33:34 +04:00
|
|
|
// Don't do incremental reflow until we've taught tables how to do
|
|
|
|
// it right in paginated mode.
|
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2002-02-01 18:31:15 +03:00
|
|
|
// Return our desired size
|
2009-03-08 22:01:02 +03:00
|
|
|
aDesiredSize.height = mSize.height * PresContext()->GetPrintPreviewScale();
|
|
|
|
aDesiredSize.width = mSize.width * PresContext()->GetPrintPreviewScale();
|
2010-10-07 08:25:46 +04:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2006-04-11 05:48:48 +04:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2002-02-01 18:31:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
PRBool isPrintPreview =
|
2004-08-01 03:15:21 +04:00
|
|
|
aPresContext->Type() == nsPresContext::eContext_PrintPreview;
|
2002-04-23 16:05:43 +04:00
|
|
|
|
2002-01-19 01:45:06 +03:00
|
|
|
// See if we can get a Print Settings from the Context
|
2004-07-29 23:41:39 +04:00
|
|
|
if (!mPageData->mPrintSettings &&
|
2006-12-26 20:47:52 +03:00
|
|
|
aPresContext->Medium() == nsGkAtoms::print) {
|
2004-07-29 23:41:39 +04:00
|
|
|
mPageData->mPrintSettings = aPresContext->GetPrintSettings();
|
2002-01-19 01:45:06 +03:00
|
|
|
}
|
|
|
|
|
2007-11-21 08:09:58 +03:00
|
|
|
// now get out margins & edges
|
2002-01-19 01:45:06 +03:00
|
|
|
if (mPageData->mPrintSettings) {
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntMargin unwriteableTwips;
|
2008-03-19 23:51:42 +03:00
|
|
|
mPageData->mPrintSettings->GetUnwriteableMarginInTwips(unwriteableTwips);
|
|
|
|
NS_ASSERTION(unwriteableTwips.left >= 0 && unwriteableTwips.top >= 0 &&
|
|
|
|
unwriteableTwips.right >= 0 && unwriteableTwips.bottom >= 0,
|
|
|
|
"Unwriteable twips should be non-negative");
|
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntMargin marginTwips;
|
2007-02-07 10:46:44 +03:00
|
|
|
mPageData->mPrintSettings->GetMarginInTwips(marginTwips);
|
2010-08-13 13:58:04 +04:00
|
|
|
mMargin = aPresContext->CSSTwipsToAppUnits(marginTwips + unwriteableTwips);
|
2008-03-19 23:51:42 +03:00
|
|
|
|
2002-04-11 04:34:59 +04:00
|
|
|
PRInt16 printType;
|
|
|
|
mPageData->mPrintSettings->GetPrintRange(&printType);
|
|
|
|
mPrintRangeType = printType;
|
2007-11-21 08:09:58 +03:00
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntMargin edgeTwips;
|
2007-11-21 08:09:58 +03:00
|
|
|
mPageData->mPrintSettings->GetEdgeInTwips(edgeTwips);
|
|
|
|
|
2008-01-29 10:38:20 +03:00
|
|
|
// sanity check the values. three inches are sometimes needed
|
2010-08-13 13:59:16 +04:00
|
|
|
PRInt32 inchInTwips = NS_INCHES_TO_INT_TWIPS(3.0);
|
2009-09-16 19:01:36 +04:00
|
|
|
edgeTwips.top = NS_MIN(NS_MAX(edgeTwips.top, 0), inchInTwips);
|
|
|
|
edgeTwips.bottom = NS_MIN(NS_MAX(edgeTwips.bottom, 0), inchInTwips);
|
|
|
|
edgeTwips.left = NS_MIN(NS_MAX(edgeTwips.left, 0), inchInTwips);
|
|
|
|
edgeTwips.right = NS_MIN(NS_MAX(edgeTwips.right, 0), inchInTwips);
|
2007-11-21 08:09:58 +03:00
|
|
|
|
|
|
|
mPageData->mEdgePaperMargin =
|
2010-08-13 13:58:04 +04:00
|
|
|
aPresContext->CSSTwipsToAppUnits(edgeTwips + unwriteableTwips);
|
2002-01-19 01:45:06 +03:00
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// *** Special Override ***
|
|
|
|
// If this is a sub-sdoc (meaning it doesn't take the whole page)
|
|
|
|
// and if this Document is in the upper left hand corner
|
|
|
|
// we need to suppress the top margin or it will reflow too small
|
2006-03-30 04:27:42 +04:00
|
|
|
|
|
|
|
nsSize pageSize = aPresContext->GetPageSize();
|
|
|
|
|
|
|
|
mPageData->mReflowSize = pageSize;
|
2008-04-22 05:18:26 +04:00
|
|
|
// If we're printing a selection, we need to reflow with
|
|
|
|
// unconstrained height, to make sure we'll get to the selection
|
|
|
|
// even if it's beyond the first page of content.
|
|
|
|
if (nsIPrintSettings::kRangeSelection == mPrintRangeType) {
|
|
|
|
mPageData->mReflowSize.height = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
2006-04-11 05:48:48 +04:00
|
|
|
mPageData->mReflowMargin = mMargin;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
// Compute the size of each page and the x coordinate that each page will
|
|
|
|
// be placed at
|
2009-09-16 19:01:36 +04:00
|
|
|
nscoord extraThreshold = NS_MAX(pageSize.width, pageSize.height)/10;
|
2004-04-30 03:34:19 +04:00
|
|
|
PRInt32 gapInTwips = nsContentUtils::GetIntPref("print.print_extra_margin");
|
2009-09-16 19:01:36 +04:00
|
|
|
gapInTwips = NS_MAX(0, gapInTwips);
|
2004-04-30 03:34:19 +04:00
|
|
|
|
2010-08-13 13:58:04 +04:00
|
|
|
nscoord extraGap = aPresContext->CSSTwipsToAppUnits(gapInTwips);
|
2009-09-16 19:01:36 +04:00
|
|
|
extraGap = NS_MIN(extraGap, extraThreshold); // clamp to 1/10 of the largest dim of the page
|
2001-11-28 18:19:47 +03:00
|
|
|
|
2006-11-24 11:14:37 +03:00
|
|
|
nscoord deadSpaceGap = 0;
|
2007-11-21 08:09:58 +03:00
|
|
|
if (isPrintPreview) {
|
2008-01-31 09:12:52 +03:00
|
|
|
GetDeadSpaceValue(&gapInTwips);
|
2010-08-13 13:58:04 +04:00
|
|
|
deadSpaceGap = aPresContext->CSSTwipsToAppUnits(gapInTwips);
|
2007-11-21 08:09:58 +03:00
|
|
|
}
|
2002-02-15 02:18:09 +03:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
nsMargin extraMargin(0,0,0,0);
|
2001-11-28 18:19:47 +03:00
|
|
|
nsSize shadowSize(0,0);
|
2006-04-11 05:48:48 +04:00
|
|
|
if (aPresContext->IsScreen()) {
|
2006-03-30 04:27:42 +04:00
|
|
|
extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap);
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord fourPixels = nsPresContext::CSSPixelsToAppUnits(4);
|
2006-03-30 04:27:42 +04:00
|
|
|
shadowSize.SizeTo(fourPixels, fourPixels);
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
mPageData->mShadowSize = shadowSize;
|
|
|
|
mPageData->mExtraMargin = extraMargin;
|
2001-11-06 17:34:00 +03:00
|
|
|
|
2006-04-11 05:48:48 +04:00
|
|
|
const nscoord x = deadSpaceGap;
|
|
|
|
nscoord y = deadSpaceGap;// Running y-offset for each page
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2006-04-11 05:48:48 +04:00
|
|
|
nsSize availSize(pageSize.width + shadowSize.width + extraMargin.LeftRight(),
|
|
|
|
pageSize.height + shadowSize.height +
|
|
|
|
extraMargin.TopBottom());
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Tile the pages vertically
|
|
|
|
nsHTMLReflowMetrics kidSize;
|
|
|
|
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
|
2008-02-09 05:54:55 +03:00
|
|
|
// Set the shared data into the page frame before reflow
|
|
|
|
nsPageFrame * pf = static_cast<nsPageFrame*>(kidFrame);
|
|
|
|
pf->SetSharedPageData(mPageData);
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Reflow the page
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
|
|
|
|
availSize);
|
|
|
|
nsReflowStatus status;
|
|
|
|
|
2007-01-26 03:05:12 +03:00
|
|
|
kidReflowState.SetComputedWidth(kidReflowState.availableWidth);
|
2007-08-02 22:08:05 +04:00
|
|
|
//kidReflowState.SetComputedHeight(kidReflowState.availableHeight);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
PR_PL(("AV W: %d H: %d\n", kidReflowState.availableWidth, kidReflowState.availableHeight));
|
|
|
|
|
|
|
|
// Place and size the page. If the page is narrower than our
|
|
|
|
// max width then center it horizontally
|
|
|
|
ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, x, y, 0, status);
|
|
|
|
|
|
|
|
FinishReflowChild(kidFrame, aPresContext, nsnull, kidSize, x, y, 0);
|
|
|
|
y += kidSize.height;
|
|
|
|
|
|
|
|
// Leave a slight gap between the pages
|
|
|
|
y += deadSpaceGap;
|
|
|
|
|
|
|
|
// Is the page complete?
|
|
|
|
nsIFrame* kidNextInFlow = kidFrame->GetNextInFlow();
|
|
|
|
|
2007-10-02 09:57:45 +04:00
|
|
|
if (NS_FRAME_IS_FULLY_COMPLETE(status)) {
|
2009-09-18 15:09:35 +04:00
|
|
|
NS_ASSERTION(!kidNextInFlow, "bad child flow list");
|
|
|
|
} else if (!kidNextInFlow) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// The page isn't complete and it doesn't have a next-in-flow, so
|
2009-09-18 15:09:35 +04:00
|
|
|
// create a continuing page.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsIFrame* continuingPage;
|
2009-09-18 15:09:35 +04:00
|
|
|
nsresult rv = aPresContext->PresShell()->FrameConstructor()->
|
|
|
|
CreateContinuingFrame(aPresContext, kidFrame, this, &continuingPage);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
break;
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Add it to our child list
|
2009-09-18 15:09:35 +04:00
|
|
|
mFrames.InsertFrame(nsnull, kidFrame, continuingPage);
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
2001-09-26 18:01:26 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Get the next page
|
|
|
|
kidFrame = kidFrame->GetNextSibling();
|
|
|
|
}
|
2001-09-26 18:01:26 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Get Total Page Count
|
|
|
|
nsIFrame* page;
|
|
|
|
PRInt32 pageTot = 0;
|
|
|
|
for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) {
|
|
|
|
pageTot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Page Number Info
|
|
|
|
PRInt32 pageNum = 1;
|
|
|
|
for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsPageFrame * pf = static_cast<nsPageFrame*>(page);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (pf != nsnull) {
|
|
|
|
pf->SetPageNumInfo(pageNum, pageTot);
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
pageNum++;
|
|
|
|
}
|
2001-09-26 18:01:26 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Create current Date/Time String
|
|
|
|
if (!mDateFormatter)
|
|
|
|
mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID);
|
2008-10-09 07:51:54 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
NS_ENSURE_TRUE(mDateFormatter, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsAutoString formattedDateString;
|
|
|
|
time_t ltime;
|
|
|
|
time( <ime );
|
|
|
|
if (NS_SUCCEEDED(mDateFormatter->FormatTime(nsnull /* nsILocale* locale */,
|
|
|
|
kDateFormatShort,
|
|
|
|
kTimeFormatNoSeconds,
|
|
|
|
ltime,
|
|
|
|
formattedDateString))) {
|
|
|
|
PRUnichar * uStr = ToNewUnicode(formattedDateString);
|
|
|
|
SetDateTimeStr(uStr); // memory will be freed
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return our desired size
|
2007-02-14 01:36:59 +03:00
|
|
|
// Adjustr the reflow size by PrintPreviewScale so the scrollbars end up the
|
|
|
|
// correct size
|
2009-03-08 22:01:02 +03:00
|
|
|
nscoord w = (x + availSize.width + deadSpaceGap);
|
2007-03-31 01:11:41 +04:00
|
|
|
aDesiredSize.height = y * PresContext()->GetPrintPreviewScale(); // includes page heights and dead space
|
2009-03-08 22:01:02 +03:00
|
|
|
aDesiredSize.width = w * PresContext()->GetPrintPreviewScale();
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2010-10-07 08:25:46 +04:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2006-04-01 05:19:28 +04:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// cache the size so we can set the desired size
|
|
|
|
// for the other reflows that happen
|
2009-03-08 22:01:02 +03:00
|
|
|
mSize.width = w;
|
|
|
|
mSize.height = y;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus);
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
1998-11-05 02:21:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-07 06:43:02 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-11-05 02:21:50 +03:00
|
|
|
NS_IMETHODIMP
|
2001-11-14 04:33:42 +03:00
|
|
|
nsSimplePageSequenceFrame::GetFrameName(nsAString& aResult) const
|
1998-11-05 02:21:50 +03:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SimplePageSequence"), aResult);
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2001-03-27 15:56:03 +04:00
|
|
|
//====================================================================
|
|
|
|
//== Asynch Printing
|
|
|
|
//====================================================================
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetCurrentPageNum(PRInt32* aPageNum)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPageNum);
|
|
|
|
|
|
|
|
*aPageNum = mPageNum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetNumPages(PRInt32* aNumPages)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumPages);
|
|
|
|
|
|
|
|
*aNumPages = mTotalPages;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::IsDoingPrintRange(PRBool* aDoing)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDoing);
|
|
|
|
|
|
|
|
*aDoing = mDoingPageRange;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFromPage);
|
|
|
|
NS_ENSURE_ARG_POINTER(aToPage);
|
|
|
|
|
|
|
|
*aFromPage = mFromPageNum;
|
|
|
|
*aToPage = mToPageNum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// Helper Function
|
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, PRBool aPageNumOnly)
|
|
|
|
{
|
|
|
|
// Doing this here so we only have to go get these formats once
|
2005-01-19 02:46:59 +03:00
|
|
|
nsXPIDLString pageNumberFormat;
|
2001-09-26 18:01:26 +04:00
|
|
|
// Now go get the Localized Page Formating String
|
2004-12-17 23:40:48 +03:00
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES,
|
|
|
|
aPropName, pageNumberFormat);
|
2002-01-07 16:31:18 +03:00
|
|
|
if (NS_FAILED(rv)) { // back stop formatting
|
2004-07-25 16:18:04 +04:00
|
|
|
pageNumberFormat.AssignASCII(aDefPropVal);
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
2002-01-07 16:31:18 +03:00
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// Sets the format into a static data member which will own the memory and free it
|
2001-09-29 12:28:41 +04:00
|
|
|
PRUnichar* uStr = ToNewUnicode(pageNumberFormat);
|
2001-09-26 18:01:26 +04:00
|
|
|
if (uStr != nsnull) {
|
2001-11-03 17:59:39 +03:00
|
|
|
SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext,
|
2002-05-07 16:03:37 +04:00
|
|
|
nsIPrintSettings* aPrintSettings,
|
|
|
|
PRUnichar* aDocTitle,
|
|
|
|
PRUnichar* aDocURL)
|
2001-03-27 15:56:03 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
2002-01-01 15:58:53 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
|
|
|
|
|
|
|
if (!mPageData->mPrintSettings) {
|
|
|
|
mPageData->mPrintSettings = aPrintSettings;
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-05-07 16:03:37 +04:00
|
|
|
// Only set them if they are not null
|
|
|
|
if (aDocTitle) mPageData->mDocTitle = aDocTitle;
|
|
|
|
if (aDocURL) mPageData->mDocURL = aDocURL;
|
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
aPrintSettings->GetStartPageRange(&mFromPageNum);
|
|
|
|
aPrintSettings->GetEndPageRange(&mToPageNum);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
mDoingPageRange = nsIPrintSettings::kRangeSpecifiedPageRange == mPrintRangeType ||
|
|
|
|
nsIPrintSettings::kRangeSelection == mPrintRangeType;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
// If printing a range of pages make sure at least the starting page
|
|
|
|
// number is valid
|
|
|
|
PRInt32 totalPages = mFrames.GetLength();
|
|
|
|
|
|
|
|
if (mDoingPageRange) {
|
|
|
|
if (mFromPageNum > totalPages) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Begin printing of the document
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Determine if we are rendering only the selection
|
2002-01-01 15:58:53 +03:00
|
|
|
aPresContext->SetIsRenderingOnlySelection(nsIPrintSettings::kRangeSelection == mPrintRangeType);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (mDoingPageRange) {
|
|
|
|
// XXX because of the hack for making the selection all print on one page
|
|
|
|
// we must make sure that the page is sized correctly before printing.
|
2007-11-21 08:09:58 +03:00
|
|
|
nscoord height = aPresContext->GetPageSize().height;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
PRInt32 pageNum = 1;
|
2001-11-03 17:59:39 +03:00
|
|
|
nscoord y = 0;//mMargin.top;
|
2001-12-01 17:31:45 +03:00
|
|
|
|
2003-06-30 22:52:23 +04:00
|
|
|
for (nsIFrame* page = mFrames.FirstChild(); page;
|
|
|
|
page = page->GetNextSibling()) {
|
2007-02-26 01:26:47 +03:00
|
|
|
if (pageNum >= mFromPageNum && pageNum <= mToPageNum) {
|
2003-06-30 22:52:23 +04:00
|
|
|
nsRect rect = page->GetRect();
|
2001-03-27 15:56:03 +04:00
|
|
|
rect.y = y;
|
|
|
|
rect.height = height;
|
2003-06-30 22:52:23 +04:00
|
|
|
page->SetRect(rect);
|
2001-03-27 15:56:03 +04:00
|
|
|
y += rect.height + mMargin.top + mMargin.bottom;
|
|
|
|
}
|
|
|
|
pageNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust total number of pages
|
2002-02-12 16:33:39 +03:00
|
|
|
if (nsIPrintSettings::kRangeSelection != mPrintRangeType) {
|
2001-03-27 15:56:03 +04:00
|
|
|
totalPages = pageNum - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mPageNum = 1;
|
|
|
|
mCurrentPageFrame = mFrames.FirstChild();
|
|
|
|
|
2002-02-12 16:33:39 +03:00
|
|
|
if (mTotalPages == -1) {
|
|
|
|
mTotalPages = totalPages;
|
|
|
|
}
|
|
|
|
|
2001-03-27 15:56:03 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-03-30 04:27:42 +04:00
|
|
|
nsSimplePageSequenceFrame::PrintNextPage()
|
2001-03-27 15:56:03 +04:00
|
|
|
{
|
|
|
|
// Print each specified page
|
|
|
|
// pageNum keeps track of the current page and what pages are printing
|
|
|
|
//
|
|
|
|
// printedPageNum keeps track of the current page number to be printed
|
|
|
|
// Note: When print al the pages or a page range the printed page shows the
|
|
|
|
// actual page number, when printing selection it prints the page number starting
|
|
|
|
// with the first page of the selection. For example if the user has a
|
|
|
|
// selection that starts on page 2 and ends on page 3, the page numbers when
|
|
|
|
// print are 1 and then two (which is different than printing a page range, where
|
|
|
|
// the page numbers would have been 2 and then 3)
|
|
|
|
|
|
|
|
if (mCurrentPageFrame == nsnull) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool printEvenPages, printOddPages;
|
2002-01-01 15:58:53 +03:00
|
|
|
mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintEvenPages, &printEvenPages);
|
|
|
|
mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintOddPages, &printOddPages);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
// Begin printing of the document
|
2007-03-31 01:11:41 +04:00
|
|
|
nsIDeviceContext *dc = PresContext()->DeviceContext();
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// See whether we should print this page
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_TRUE;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
// If printing a range of pages check whether the page number is in the
|
|
|
|
// range of pages to print
|
|
|
|
if (mDoingPageRange) {
|
|
|
|
if (mPageNum < mFromPageNum) {
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_FALSE;
|
2001-03-27 15:56:03 +04:00
|
|
|
} else if (mPageNum > mToPageNum) {
|
|
|
|
mPageNum++;
|
|
|
|
mCurrentPageFrame = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for printing of odd and even pages
|
|
|
|
if (mPageNum & 0x1) {
|
|
|
|
if (!printOddPages) {
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_FALSE; // don't print odd numbered page
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!printEvenPages) {
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_FALSE; // don't print even numbered page
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
}
|
2006-03-30 04:27:42 +04:00
|
|
|
|
|
|
|
if (nsIPrintSettings::kRangeSelection == mPrintRangeType) {
|
|
|
|
mPrintThisPage = PR_TRUE;
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
if (mPrintThisPage) {
|
2001-11-03 17:59:39 +03:00
|
|
|
// XXX This is temporary fix for printing more than one page of a selection
|
|
|
|
// This does a poor man's "dump" pagination (see Bug 89353)
|
|
|
|
// It has laid out as one long page and now we are just moving or view up/down
|
|
|
|
// one page at a time and printing the contents of what is exposed by the rect.
|
|
|
|
// currently this does not work for IFrames
|
|
|
|
// I will soon improve this to work with IFrames
|
|
|
|
PRBool continuePrinting = PR_TRUE;
|
2007-11-21 08:09:58 +03:00
|
|
|
nscoord width, height;
|
2007-03-31 01:11:41 +04:00
|
|
|
width = PresContext()->GetPageSize().width;
|
|
|
|
height = PresContext()->GetPageSize().height;
|
2001-11-03 17:59:39 +03:00
|
|
|
height -= mMargin.top + mMargin.bottom;
|
|
|
|
width -= mMargin.left + mMargin.right;
|
|
|
|
nscoord selectionY = height;
|
2007-02-26 01:26:47 +03:00
|
|
|
nsIFrame* conFrame = mCurrentPageFrame->GetFirstChild(nsnull);
|
2007-11-21 08:09:58 +03:00
|
|
|
if (mSelectionHeight >= 0) {
|
2007-02-26 01:26:47 +03:00
|
|
|
conFrame->SetPosition(conFrame->GetPosition() + nsPoint(0, -mYSelOffset));
|
2008-04-29 02:55:04 +04:00
|
|
|
nsContainerFrame::PositionChildViews(conFrame);
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
2006-03-30 04:27:42 +04:00
|
|
|
// cast the frame to be a page frame
|
2007-07-08 11:08:04 +04:00
|
|
|
nsPageFrame * pf = static_cast<nsPageFrame*>(mCurrentPageFrame);
|
2006-03-30 04:27:42 +04:00
|
|
|
pf->SetPageNumInfo(mPageNum, mTotalPages);
|
|
|
|
pf->SetSharedPageData(mPageData);
|
|
|
|
|
|
|
|
PRInt32 printedPageNum = 1;
|
2001-11-03 17:59:39 +03:00
|
|
|
while (continuePrinting) {
|
2007-03-31 01:11:41 +04:00
|
|
|
if (PresContext()->IsRootPaginatedDocument()) {
|
2002-06-20 01:51:13 +04:00
|
|
|
PR_PL(("\n"));
|
|
|
|
PR_PL(("***************** BeginPage *****************\n"));
|
2002-02-12 16:33:39 +03:00
|
|
|
rv = dc->BeginPage();
|
2006-03-30 04:27:42 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-02-12 16:33:39 +03:00
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
PR_PL(("SeqFr::PrintNextPage -> %p PageNo: %d", pf, mPageNum));
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2007-02-26 01:26:47 +03:00
|
|
|
nsCOMPtr<nsIRenderingContext> renderingContext;
|
2010-08-20 23:29:01 +04:00
|
|
|
dc->CreateRenderingContext(*getter_AddRefs(renderingContext));
|
|
|
|
NS_ENSURE_TRUE(renderingContext, NS_ERROR_OUT_OF_MEMORY);
|
2008-04-08 04:32:48 +04:00
|
|
|
|
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
// On linux, need to rotate landscape-mode output on printed surfaces
|
|
|
|
PRInt32 orientation;
|
|
|
|
mPageData->mPrintSettings->GetOrientation(&orientation);
|
|
|
|
if (nsIPrintSettings::kLandscapeOrientation == orientation) {
|
|
|
|
// Shift up by one landscape-page-height (in points) before we rotate.
|
|
|
|
float offset = POINTS_PER_INCH_FLOAT *
|
2010-08-13 13:58:04 +04:00
|
|
|
(mCurrentPageFrame->GetSize().height / float(dc->AppUnitsPerCSSInch()));
|
2008-04-08 04:32:48 +04:00
|
|
|
renderingContext->ThebesContext()->Translate(gfxPoint(offset, 0));
|
|
|
|
renderingContext->ThebesContext()->Rotate(M_PI/2);
|
|
|
|
}
|
|
|
|
#endif // XP_UNIX && !XP_MACOSX
|
|
|
|
|
2007-02-26 02:23:09 +03:00
|
|
|
nsRect drawingRect(nsPoint(0, 0),
|
|
|
|
mCurrentPageFrame->GetSize());
|
|
|
|
nsRegion drawingRegion(drawingRect);
|
2007-02-26 01:26:47 +03:00
|
|
|
nsLayoutUtils::PaintFrame(renderingContext, mCurrentPageFrame,
|
2009-09-13 02:44:18 +04:00
|
|
|
drawingRegion, NS_RGBA(0,0,0,0),
|
|
|
|
nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES);
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2007-11-21 08:09:58 +03:00
|
|
|
if (mSelectionHeight >= 0 && selectionY < mSelectionHeight) {
|
2001-11-03 17:59:39 +03:00
|
|
|
selectionY += height;
|
2006-03-30 04:27:42 +04:00
|
|
|
printedPageNum++;
|
|
|
|
pf->SetPageNumInfo(printedPageNum, mTotalPages);
|
2007-02-26 01:26:47 +03:00
|
|
|
conFrame->SetPosition(conFrame->GetPosition() + nsPoint(0, -height));
|
2008-06-24 20:30:55 +04:00
|
|
|
nsContainerFrame::PositionChildViews(conFrame);
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2006-03-30 04:27:42 +04:00
|
|
|
PR_PL(("***************** End Page (PrintNextPage) *****************\n"));
|
|
|
|
rv = dc->EndPage();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-11-03 17:59:39 +03:00
|
|
|
} else {
|
|
|
|
continuePrinting = PR_FALSE;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-03-30 04:27:42 +04:00
|
|
|
nsSimplePageSequenceFrame::DoPageEnd()
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2006-03-30 04:27:42 +04:00
|
|
|
nsresult rv = NS_OK;
|
2007-03-31 01:11:41 +04:00
|
|
|
if (PresContext()->IsRootPaginatedDocument() && mPrintThisPage) {
|
2006-03-30 04:27:42 +04:00
|
|
|
PR_PL(("***************** End Page (DoPageEnd) *****************\n"));
|
2007-03-31 01:11:41 +04:00
|
|
|
rv = PresContext()->DeviceContext()->EndPage();
|
2006-03-30 04:27:42 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mPageNum++;
|
2006-03-30 04:27:42 +04:00
|
|
|
|
2003-06-30 22:52:23 +04:00
|
|
|
if (mCurrentPageFrame) {
|
|
|
|
mCurrentPageFrame = mCurrentPageFrame->GetNextSibling();
|
2001-04-25 18:26:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2007-02-14 01:36:59 +03:00
|
|
|
static void PaintPageSequence(nsIFrame* aFrame, nsIRenderingContext* aCtx,
|
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsSimplePageSequenceFrame*>(aFrame)->PaintPageSequence(*aCtx, aDirtyRect, aPt);
|
2007-02-14 01:36:59 +03:00
|
|
|
}
|
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
//------------------------------------------------------------------------------
|
2007-02-14 01:36:59 +03:00
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::PaintPageSequence(nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsPoint aPt) {
|
|
|
|
nsRect rect = aDirtyRect;
|
2007-03-31 01:11:41 +04:00
|
|
|
float scale = PresContext()->GetPrintPreviewScale();
|
2007-02-14 01:36:59 +03:00
|
|
|
aRenderingContext.PushState();
|
|
|
|
nsPoint framePos = aPt;
|
|
|
|
aRenderingContext.Translate(framePos.x, framePos.y);
|
|
|
|
rect -= framePos;
|
|
|
|
aRenderingContext.Scale(scale, scale);
|
|
|
|
rect.ScaleRoundOut(1.0f / scale);
|
|
|
|
|
|
|
|
// Now the rect and the rendering coordinates are are relative to this frame.
|
|
|
|
// Loop over the pages and paint them.
|
|
|
|
nsIFrame* child = GetFirstChild(nsnull);
|
|
|
|
while (child) {
|
|
|
|
nsPoint pt = child->GetPosition();
|
|
|
|
// The rendering context has to be translated before each call to PaintFrame
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(pt.x, pt.y);
|
|
|
|
nsLayoutUtils::PaintFrame(&aRenderingContext, child,
|
2009-09-13 02:44:18 +04:00
|
|
|
nsRegion(rect - pt), NS_RGBA(0,0,0,0),
|
|
|
|
nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES);
|
2007-02-14 01:36:59 +03:00
|
|
|
aRenderingContext.PopState();
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
aRenderingContext.PopState();
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-02-14 01:36:59 +03:00
|
|
|
rv = aLists.Content()->AppendNewToTop(new (aBuilder)
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayGeneric(aBuilder, this, ::PaintPageSequence, "PageSequence",
|
2010-07-16 01:07:49 +04:00
|
|
|
nsDisplayItem::TYPE_PAGE_SEQUENCE));
|
2007-02-14 01:36:59 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsSimplePageSequenceFrame::GetType() const
|
2002-03-04 15:55:20 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::sequenceFrame;
|
2002-03-04 15:55:20 +03:00
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFormatStr != nsnull, "Format string cannot be null!");
|
|
|
|
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
|
|
|
|
|
|
|
if (aForPageNumOnly) {
|
|
|
|
if (mPageData->mPageNumFormat != nsnull) {
|
|
|
|
nsMemory::Free(mPageData->mPageNumFormat);
|
|
|
|
}
|
|
|
|
mPageData->mPageNumFormat = aFormatStr;
|
|
|
|
} else {
|
|
|
|
if (mPageData->mPageNumAndTotalsFormat != nsnull) {
|
|
|
|
nsMemory::Free(mPageData->mPageNumAndTotalsFormat);
|
|
|
|
}
|
|
|
|
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetDateTimeStr(PRUnichar * aDateTimeStr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aDateTimeStr != nsnull, "DateTime string cannot be null!");
|
|
|
|
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
|
|
|
|
|
|
|
if (mPageData->mDateTimeStr != nsnull) {
|
|
|
|
nsMemory::Free(mPageData->mDateTimeStr);
|
|
|
|
}
|
|
|
|
mPageData->mDateTimeStr = aDateTimeStr;
|
|
|
|
}
|
|
|
|
|
2002-09-20 01:45:07 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// For Shrink To Fit
|
|
|
|
//
|
|
|
|
// Return the percentage that the page needs to shrink to
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetSTFPercent(float& aSTFPercent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPageData, NS_ERROR_UNEXPECTED);
|
|
|
|
aSTFPercent = 1.0f;
|
2002-09-26 15:25:04 +04:00
|
|
|
if (mPageData && (mPageData->mPageContentXMost > mPageData->mPageContentSize)) {
|
|
|
|
aSTFPercent = float(mPageData->mPageContentSize) / float(mPageData->mPageContentXMost);
|
2002-09-20 01:45:07 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|