2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-09-24 18:43:43 -07:00
|
|
|
|
2014-02-18 00:58:22 -08:00
|
|
|
#include "nsSimplePageSequenceFrame.h"
|
2013-09-24 18:43:43 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
2008-04-07 17:32:48 -07:00
|
|
|
#include "gfxContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPrintSettings.h"
|
|
|
|
#include "nsPageFrame.h"
|
2012-08-30 17:24:35 -07:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
2012-08-30 17:24:35 -07:00
|
|
|
#include "nsHTMLCanvasFrame.h"
|
2013-01-03 21:16:14 -08:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2012-08-30 17:24:35 -07:00
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2013-08-22 11:32:52 -07:00
|
|
|
#include "nsIDateTimeFormat.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// DateTime Includes
|
|
|
|
#include "nsDateTimeFormatCID.h"
|
|
|
|
|
|
|
|
#define OFFSET_NOT_SET -1
|
|
|
|
|
|
|
|
// Print Options
|
|
|
|
#include "nsIPrintOptions.h"
|
|
|
|
|
2011-05-24 23:32:00 -07:00
|
|
|
using namespace mozilla;
|
2013-01-03 21:16:14 -08:00
|
|
|
using namespace mozilla::dom;
|
2011-05-24 23:32:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printsettings-service;1";
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "prlog.h"
|
|
|
|
#ifdef PR_LOGGING
|
2012-10-29 16:32:10 -07:00
|
|
|
PRLogModuleInfo *
|
|
|
|
GetLayoutPrintingLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sLog;
|
|
|
|
if (!sLog)
|
|
|
|
sLog = PR_NewLogModule("printing-layout");
|
|
|
|
return sLog;
|
|
|
|
}
|
|
|
|
#define PR_PL(_p1) PR_LOG(GetLayoutPrintingLog(), PR_LOG_DEBUG, _p1)
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
#define PR_PL(_p1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsSimplePageSequenceFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSimplePageSequenceFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSimplePageSequenceFrame::nsSimplePageSequenceFrame(nsStyleContext* aContext) :
|
|
|
|
nsContainerFrame(aContext),
|
|
|
|
mTotalPages(-1),
|
|
|
|
mSelectionHeight(-1),
|
2012-08-30 17:24:35 -07:00
|
|
|
mYSelOffset(0),
|
2012-10-09 22:00:05 -07:00
|
|
|
mCalledBeginPage(false),
|
|
|
|
mCurrentCanvasListSetup(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-13 02:58:04 -07:00
|
|
|
nscoord halfInch = PresContext()->CSSTwipsToAppUnits(NS_INCHES_TO_TWIPS(0.5));
|
2007-03-22 10:30:00 -07:00
|
|
|
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
|
|
|
|
|
|
|
|
// XXX Unsafe to assume successful allocation
|
|
|
|
mPageData = new nsSharedPageData();
|
2012-01-25 15:52:26 -08:00
|
|
|
mPageData->mHeadFootFont =
|
2013-07-24 04:48:55 -07:00
|
|
|
*PresContext()->GetDefaultFont(kGenericFont_serif,
|
|
|
|
aContext->StyleFont()->mLanguage);
|
|
|
|
mPageData->mHeadFootFont.size = nsPresContext::CSSPointsToAppUnits(10);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
mPageData->mPrintOptions = do_GetService(sPrintOptionsContractID, &rv);
|
|
|
|
|
|
|
|
// Doing this here so we only have to go get these formats once
|
2011-10-17 07:59:28 -07:00
|
|
|
SetPageNumberFormat("pagenumber", "%1$d", true);
|
|
|
|
SetPageNumberFormat("pageofpages", "%1$d of %2$d", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
|
|
|
|
{
|
2011-05-17 07:01:36 -07:00
|
|
|
delete mPageData;
|
2012-10-02 10:42:21 -07:00
|
|
|
ResetPrintCanvasList();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsSimplePageSequenceFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIPageSequenceFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2011-06-10 03:07:26 -07:00
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord aWidth,
|
|
|
|
nscoord aHeight)
|
|
|
|
{
|
|
|
|
// Aim to fill the whole size of the document, not only so we
|
|
|
|
// can act as a background in print preview but also handle overflow
|
|
|
|
// in child page frames correctly.
|
|
|
|
// Use availableWidth so we don't cause a needless horizontal scrollbar.
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Width() = std::max(aReflowState.AvailableWidth(),
|
2011-06-10 03:07:26 -07:00
|
|
|
nscoord(aWidth * PresContext()->GetPrintPreviewScale()));
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Height() = std::max(aReflowState.ComputedHeight(),
|
2011-06-10 03:07:26 -07:00
|
|
|
nscoord(aHeight * PresContext()->GetPrintPreviewScale()));
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresContext->IsRootPaginatedDocument(),
|
|
|
|
"A Page Sequence is only for real pages");
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsSimplePageSequenceFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
NS_FRAME_TRACE_REFLOW_IN("nsSimplePageSequenceFrame::Reflow");
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE; // we're always complete
|
|
|
|
|
2007-04-25 22:33:34 -07: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)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Return our desired size
|
2011-06-10 03:07:26 -07:00
|
|
|
SetDesiredSize(aDesiredSize, aReflowState, mSize.width, mSize.height);
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2014-05-12 17:47:52 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if we can get a Print Settings from the Context
|
|
|
|
if (!mPageData->mPrintSettings &&
|
|
|
|
aPresContext->Medium() == nsGkAtoms::print) {
|
|
|
|
mPageData->mPrintSettings = aPresContext->GetPrintSettings();
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:09:58 -08:00
|
|
|
// now get out margins & edges
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mPageData->mPrintSettings) {
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntMargin unwriteableTwips;
|
2008-03-19 13:51:42 -07: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-14 19:27:09 -08:00
|
|
|
nsIntMargin marginTwips;
|
2007-03-22 10:30:00 -07:00
|
|
|
mPageData->mPrintSettings->GetMarginInTwips(marginTwips);
|
2010-08-13 02:58:04 -07:00
|
|
|
mMargin = aPresContext->CSSTwipsToAppUnits(marginTwips + unwriteableTwips);
|
2008-03-19 13:51:42 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t printType;
|
2007-03-22 10:30:00 -07:00
|
|
|
mPageData->mPrintSettings->GetPrintRange(&printType);
|
|
|
|
mPrintRangeType = printType;
|
2007-11-20 21:09:58 -08:00
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntMargin edgeTwips;
|
2007-11-20 21:09:58 -08:00
|
|
|
mPageData->mPrintSettings->GetEdgeInTwips(edgeTwips);
|
|
|
|
|
2008-01-28 23:38:20 -08:00
|
|
|
// sanity check the values. three inches are sometimes needed
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t inchInTwips = NS_INCHES_TO_INT_TWIPS(3.0);
|
2011-10-28 11:33:28 -07:00
|
|
|
edgeTwips.top = clamped(edgeTwips.top, 0, inchInTwips);
|
|
|
|
edgeTwips.bottom = clamped(edgeTwips.bottom, 0, inchInTwips);
|
|
|
|
edgeTwips.left = clamped(edgeTwips.left, 0, inchInTwips);
|
|
|
|
edgeTwips.right = clamped(edgeTwips.right, 0, inchInTwips);
|
2007-11-20 21:09:58 -08:00
|
|
|
|
|
|
|
mPageData->mEdgePaperMargin =
|
2010-08-13 02:58:04 -07:00
|
|
|
aPresContext->CSSTwipsToAppUnits(edgeTwips + unwriteableTwips);
|
2007-03-22 10:30:00 -07: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
|
|
|
|
|
|
|
|
nsSize pageSize = aPresContext->GetPageSize();
|
|
|
|
|
|
|
|
mPageData->mReflowSize = pageSize;
|
2008-04-21 18:18:26 -07: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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
mPageData->mReflowMargin = mMargin;
|
|
|
|
|
2011-06-10 03:07:26 -07:00
|
|
|
// We use the CSS "margin" property on the -moz-page pseudoelement
|
|
|
|
// to determine the space between each page in print preview.
|
|
|
|
// Keep a running y-offset for each page.
|
|
|
|
nscoord y = 0;
|
|
|
|
nscoord maxXMost = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Tile the pages vertically
|
2013-12-31 05:50:31 -08:00
|
|
|
nsHTMLReflowMetrics kidSize(aReflowState);
|
2012-07-30 07:20:58 -07:00
|
|
|
for (nsIFrame* kidFrame = mFrames.FirstChild(); nullptr != kidFrame; ) {
|
2008-02-08 18:54:55 -08:00
|
|
|
// Set the shared data into the page frame before reflow
|
|
|
|
nsPageFrame * pf = static_cast<nsPageFrame*>(kidFrame);
|
|
|
|
pf->SetSharedPageData(mPageData);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Reflow the page
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
|
2012-08-31 14:20:56 -07:00
|
|
|
pageSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsReflowStatus status;
|
|
|
|
|
2013-12-27 09:59:21 -08:00
|
|
|
kidReflowState.SetComputedWidth(kidReflowState.AvailableWidth());
|
|
|
|
//kidReflowState.SetComputedHeight(kidReflowState.AvailableHeight());
|
|
|
|
PR_PL(("AV W: %d H: %d\n", kidReflowState.AvailableWidth(), kidReflowState.AvailableHeight()));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-27 09:59:21 -08:00
|
|
|
nsMargin pageCSSMargin = kidReflowState.ComputedPhysicalMargin();
|
2011-06-10 03:07:26 -07:00
|
|
|
y += pageCSSMargin.top;
|
|
|
|
const nscoord x = pageCSSMargin.left;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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);
|
|
|
|
|
2014-01-16 17:34:44 -08:00
|
|
|
FinishReflowChild(kidFrame, aPresContext, kidSize, nullptr, x, y, 0);
|
2013-12-27 09:59:52 -08:00
|
|
|
y += kidSize.Height();
|
2011-06-10 03:07:26 -07:00
|
|
|
y += pageCSSMargin.bottom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-27 09:59:52 -08:00
|
|
|
maxXMost = std::max(maxXMost, x + kidSize.Width() + pageCSSMargin.right);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Is the page complete?
|
|
|
|
nsIFrame* kidNextInFlow = kidFrame->GetNextInFlow();
|
|
|
|
|
2007-10-01 22:57:45 -07:00
|
|
|
if (NS_FRAME_IS_FULLY_COMPLETE(status)) {
|
2009-09-18 04:09:35 -07:00
|
|
|
NS_ASSERTION(!kidNextInFlow, "bad child flow list");
|
|
|
|
} else if (!kidNextInFlow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The page isn't complete and it doesn't have a next-in-flow, so
|
2009-09-18 04:09:35 -07:00
|
|
|
// create a continuing page.
|
2013-03-19 18:47:49 -07:00
|
|
|
nsIFrame* continuingPage = aPresContext->PresShell()->FrameConstructor()->
|
|
|
|
CreateContinuingFrame(aPresContext, kidFrame, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Add it to our child list
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrames.InsertFrame(nullptr, kidFrame, continuingPage);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the next page
|
|
|
|
kidFrame = kidFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get Total Page Count
|
|
|
|
nsIFrame* page;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pageTot = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) {
|
|
|
|
pageTot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Page Number Info
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pageNum = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsPageFrame * pf = static_cast<nsPageFrame*>(page);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (pf != nullptr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
pf->SetPageNumInfo(pageNum, pageTot);
|
|
|
|
}
|
|
|
|
pageNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create current Date/Time String
|
2014-05-12 17:47:52 -07:00
|
|
|
if (!mDateFormatter) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID);
|
2014-05-12 17:47:52 -07:00
|
|
|
}
|
|
|
|
if (!mDateFormatter) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString formattedDateString;
|
|
|
|
time_t ltime;
|
|
|
|
time( <ime );
|
2012-07-30 07:20:58 -07:00
|
|
|
if (NS_SUCCEEDED(mDateFormatter->FormatTime(nullptr /* nsILocale* locale */,
|
2007-03-22 10:30:00 -07:00
|
|
|
kDateFormatShort,
|
|
|
|
kTimeFormatNoSeconds,
|
|
|
|
ltime,
|
|
|
|
formattedDateString))) {
|
2013-07-24 04:48:54 -07:00
|
|
|
SetDateTimeStr(formattedDateString);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return our desired size
|
2011-06-10 03:07:26 -07:00
|
|
|
// Adjust the reflow size by PrintPreviewScale so the scrollbars end up the
|
2007-03-22 10:30:00 -07:00
|
|
|
// correct size
|
2011-06-10 03:07:26 -07:00
|
|
|
SetDesiredSize(aDesiredSize, aReflowState, maxXMost, y);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
|
|
|
// cache the size so we can set the desired size
|
|
|
|
// for the other reflows that happen
|
2011-06-10 03:07:26 -07:00
|
|
|
mSize.width = maxXMost;
|
2009-03-08 12:01:02 -07:00
|
|
|
mSize.height = y;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus);
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSimplePageSequenceFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SimplePageSequence"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
//== Asynch Printing
|
|
|
|
//====================================================================
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSimplePageSequenceFrame::GetCurrentPageNum(int32_t* aPageNum)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPageNum);
|
|
|
|
|
|
|
|
*aPageNum = mPageNum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSimplePageSequenceFrame::GetNumPages(int32_t* aNumPages)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumPages);
|
|
|
|
|
|
|
|
*aNumPages = mTotalPages;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSimplePageSequenceFrame::IsDoingPrintRange(bool* aDoing)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDoing);
|
|
|
|
|
|
|
|
*aDoing = mDoingPageRange;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSimplePageSequenceFrame::GetPrintRange(int32_t* aFromPage, int32_t* aToPage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFromPage);
|
|
|
|
NS_ENSURE_ARG_POINTER(aToPage);
|
|
|
|
|
|
|
|
*aFromPage = mFromPageNum;
|
|
|
|
*aToPage = mToPageNum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper Function
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, bool aPageNumOnly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Doing this here so we only have to go get these formats once
|
|
|
|
nsXPIDLString pageNumberFormat;
|
|
|
|
// Now go get the Localized Page Formating String
|
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES,
|
|
|
|
aPropName, pageNumberFormat);
|
|
|
|
if (NS_FAILED(rv)) { // back stop formatting
|
|
|
|
pageNumberFormat.AssignASCII(aDefPropVal);
|
|
|
|
}
|
|
|
|
|
2013-07-24 04:48:54 -07:00
|
|
|
SetPageNumberFormat(pageNumberFormat, aPageNumOnly);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-07-24 04:48:37 -07:00
|
|
|
nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPrintSettings* aPrintSettings,
|
2013-07-24 04:48:37 -07:00
|
|
|
const nsAString& aDocTitle,
|
|
|
|
const nsAString& aDocURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
|
|
|
|
|
|
|
if (!mPageData->mPrintSettings) {
|
|
|
|
mPageData->mPrintSettings = aPrintSettings;
|
|
|
|
}
|
|
|
|
|
2013-07-24 04:48:37 -07:00
|
|
|
if (!aDocTitle.IsEmpty()) {
|
|
|
|
mPageData->mDocTitle = aDocTitle;
|
|
|
|
}
|
|
|
|
if (!aDocURL.IsEmpty()) {
|
|
|
|
mPageData->mDocURL = aDocURL;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aPrintSettings->GetStartPageRange(&mFromPageNum);
|
|
|
|
aPrintSettings->GetEndPageRange(&mToPageNum);
|
2011-12-06 20:45:06 -08:00
|
|
|
aPrintSettings->GetPageRanges(mPageRanges);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mDoingPageRange = nsIPrintSettings::kRangeSpecifiedPageRange == mPrintRangeType ||
|
|
|
|
nsIPrintSettings::kRangeSelection == mPrintRangeType;
|
|
|
|
|
|
|
|
// If printing a range of pages make sure at least the starting page
|
|
|
|
// number is valid
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t totalPages = mFrames.GetLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
aPresContext->SetIsRenderingOnlySelection(nsIPrintSettings::kRangeSelection == mPrintRangeType);
|
|
|
|
|
|
|
|
|
|
|
|
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-20 21:09:58 -08:00
|
|
|
nscoord height = aPresContext->GetPageSize().height;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pageNum = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord y = 0;//mMargin.top;
|
|
|
|
|
|
|
|
for (nsIFrame* page = mFrames.FirstChild(); page;
|
|
|
|
page = page->GetNextSibling()) {
|
|
|
|
if (pageNum >= mFromPageNum && pageNum <= mToPageNum) {
|
|
|
|
nsRect rect = page->GetRect();
|
|
|
|
rect.y = y;
|
|
|
|
rect.height = height;
|
|
|
|
page->SetRect(rect);
|
|
|
|
y += rect.height + mMargin.top + mMargin.bottom;
|
|
|
|
}
|
|
|
|
pageNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust total number of pages
|
|
|
|
if (nsIPrintSettings::kRangeSelection != mPrintRangeType) {
|
|
|
|
totalPages = pageNum - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 04:48:55 -07:00
|
|
|
mPageNum = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mTotalPages == -1) {
|
|
|
|
mTotalPages = totalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-30 17:24:35 -07:00
|
|
|
void
|
2013-01-03 21:16:14 -08:00
|
|
|
GetPrintCanvasElementsInFrame(nsIFrame* aFrame, nsTArray<nsRefPtr<HTMLCanvasElement> >* aArr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-05 12:02:27 -07:00
|
|
|
if (!aFrame) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-30 17:24:35 -07:00
|
|
|
for (nsIFrame::ChildListIterator childLists(aFrame);
|
|
|
|
!childLists.IsDone(); childLists.Next()) {
|
|
|
|
|
|
|
|
nsFrameList children = childLists.CurrentList();
|
|
|
|
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
|
|
|
|
// Check if child is a nsHTMLCanvasFrame.
|
|
|
|
nsHTMLCanvasFrame* canvasFrame = do_QueryFrame(child);
|
|
|
|
|
|
|
|
// If there is a canvasFrame, try to get actual canvas element.
|
|
|
|
if (canvasFrame) {
|
2013-01-03 21:16:14 -08:00
|
|
|
HTMLCanvasElement* canvas =
|
|
|
|
HTMLCanvasElement::FromContentOrNull(canvasFrame->GetContent());
|
2013-09-11 15:35:51 -07:00
|
|
|
if (canvas && canvas->GetMozPrintCallback()) {
|
2012-08-30 17:24:35 -07:00
|
|
|
aArr->AppendElement(canvas);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-30 17:24:35 -07:00
|
|
|
if (!child->GetFirstPrincipalChild()) {
|
|
|
|
nsSubDocumentFrame* subdocumentFrame = do_QueryFrame(child);
|
|
|
|
if (subdocumentFrame) {
|
|
|
|
// Descend into the subdocument
|
|
|
|
nsIFrame* root = subdocumentFrame->GetSubdocumentRootFrame();
|
|
|
|
child = root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The current child is not a nsHTMLCanvasFrame OR it is but there is
|
2013-01-03 21:16:14 -08:00
|
|
|
// no HTMLCanvasElement on it. Check if children of `child` might
|
|
|
|
// contain a HTMLCanvasElement.
|
2012-08-30 17:24:35 -07:00
|
|
|
GetPrintCanvasElementsInFrame(child, aArr);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-30 17:24:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-30 17:24:35 -07:00
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::DetermineWhetherToPrintPage()
|
|
|
|
{
|
|
|
|
// See whether we should print this page
|
|
|
|
mPrintThisPage = true;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool printEvenPages, printOddPages;
|
2007-03-22 10:30:00 -07:00
|
|
|
mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintEvenPages, &printEvenPages);
|
|
|
|
mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintOddPages, &printOddPages);
|
|
|
|
|
|
|
|
// If printing a range of pages check whether the page number is in the
|
|
|
|
// range of pages to print
|
|
|
|
if (mDoingPageRange) {
|
|
|
|
if (mPageNum < mFromPageNum) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mPrintThisPage = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (mPageNum > mToPageNum) {
|
|
|
|
mPageNum++;
|
2012-08-30 17:24:35 -07:00
|
|
|
mPrintThisPage = false;
|
|
|
|
return;
|
2011-12-06 20:45:06 -08:00
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t length = mPageRanges.Length();
|
2011-12-06 20:45:06 -08:00
|
|
|
|
|
|
|
// Page ranges are pairs (start, end)
|
|
|
|
if (length && (length % 2 == 0)) {
|
|
|
|
mPrintThisPage = false;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i;
|
2011-12-06 20:45:06 -08:00
|
|
|
for (i = 0; i < length; i += 2) {
|
|
|
|
if (mPageRanges[i] <= mPageNum && mPageNum <= mPageRanges[i+1]) {
|
|
|
|
mPrintThisPage = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for printing of odd and even pages
|
|
|
|
if (mPageNum & 0x1) {
|
|
|
|
if (!printOddPages) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mPrintThisPage = false; // don't print odd numbered page
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!printEvenPages) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mPrintThisPage = false; // don't print even numbered page
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsIPrintSettings::kRangeSelection == mPrintRangeType) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mPrintThisPage = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-30 17:24:35 -07:00
|
|
|
}
|
|
|
|
|
2013-07-24 04:48:55 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsSimplePageSequenceFrame::GetCurrentPageFrame()
|
|
|
|
{
|
|
|
|
int32_t i = 1;
|
|
|
|
for (nsFrameList::Enumerator childFrames(mFrames); !childFrames.AtEnd();
|
|
|
|
childFrames.Next()) {
|
|
|
|
if (i == mPageNum) {
|
|
|
|
return childFrames.get();
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-08-30 17:24:35 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::PrePrintNextPage(nsITimerCallback* aCallback, bool* aDone)
|
|
|
|
{
|
2013-07-24 04:48:55 -07:00
|
|
|
nsIFrame* currentPage = GetCurrentPageFrame();
|
|
|
|
if (!currentPage) {
|
2012-08-30 17:24:35 -07:00
|
|
|
*aDone = true;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DetermineWhetherToPrintPage();
|
|
|
|
// Nothing to do if the current page doesn't get printed OR rendering to
|
|
|
|
// preview. For preview, the `CallPrintCallback` is called from within the
|
2013-01-03 21:16:14 -08:00
|
|
|
// HTMLCanvasElement::HandlePrintCallback.
|
2012-08-30 17:24:35 -07:00
|
|
|
if (!mPrintThisPage || !PresContext()->IsRootPaginatedDocument()) {
|
|
|
|
*aDone = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the canvasList is null, then generate it and start the render
|
|
|
|
// process for all the canvas.
|
|
|
|
if (!mCurrentCanvasListSetup) {
|
|
|
|
mCurrentCanvasListSetup = true;
|
2013-07-24 04:48:55 -07:00
|
|
|
GetPrintCanvasElementsInFrame(currentPage, &mCurrentCanvasList);
|
2012-08-30 17:24:35 -07:00
|
|
|
|
|
|
|
if (mCurrentCanvasList.Length() != 0) {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Begin printing of the document
|
|
|
|
nsDeviceContext *dc = PresContext()->DeviceContext();
|
|
|
|
PR_PL(("\n"));
|
|
|
|
PR_PL(("***************** BeginPage *****************\n"));
|
|
|
|
rv = dc->BeginPage();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mCalledBeginPage = true;
|
|
|
|
|
2014-04-14 20:15:01 -07:00
|
|
|
nsRefPtr<nsRenderingContext> renderingContext =
|
|
|
|
dc->CreateRenderingContext();
|
2012-08-30 17:24:35 -07:00
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> renderingSurface =
|
|
|
|
renderingContext->ThebesContext()->CurrentSurface();
|
|
|
|
NS_ENSURE_TRUE(renderingSurface, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-09-06 07:11:28 -07:00
|
|
|
for (int32_t i = mCurrentCanvasList.Length() - 1; i >= 0 ; i--) {
|
2013-01-03 21:16:14 -08:00
|
|
|
HTMLCanvasElement* canvas = mCurrentCanvasList[i];
|
2012-08-30 17:24:35 -07:00
|
|
|
nsIntSize size = canvas->GetSize();
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> printSurface = renderingSurface->
|
|
|
|
CreateSimilarSurface(
|
2014-01-23 10:26:40 -08:00
|
|
|
gfxContentType::COLOR_ALPHA,
|
2012-08-30 17:24:35 -07:00
|
|
|
size
|
|
|
|
);
|
|
|
|
|
2013-01-14 14:45:53 -08:00
|
|
|
if (!printSurface) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-30 17:24:35 -07:00
|
|
|
nsICanvasRenderingContextInternal* ctx = canvas->GetContextAtIndex(0);
|
|
|
|
|
|
|
|
if (!ctx) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the context with the new printSurface.
|
2013-10-08 11:47:21 -07:00
|
|
|
ctx->InitializeWithSurface(nullptr, printSurface, size.width, size.height);
|
2012-08-30 17:24:35 -07:00
|
|
|
|
|
|
|
// Start the rendering process.
|
|
|
|
nsWeakFrame weakFrame = this;
|
|
|
|
canvas->DispatchPrintCallback(aCallback);
|
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-11 14:33:25 -07:00
|
|
|
uint32_t doneCounter = 0;
|
2012-09-06 07:11:28 -07:00
|
|
|
for (int32_t i = mCurrentCanvasList.Length() - 1; i >= 0 ; i--) {
|
2013-01-03 21:16:14 -08:00
|
|
|
HTMLCanvasElement* canvas = mCurrentCanvasList[i];
|
2012-08-30 17:24:35 -07:00
|
|
|
|
|
|
|
if (canvas->IsPrintCallbackDone()) {
|
|
|
|
doneCounter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If all canvas have finished rendering, return true, otherwise false.
|
|
|
|
*aDone = doneCounter == mCurrentCanvasList.Length();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::ResetPrintCanvasList()
|
|
|
|
{
|
2012-09-06 07:11:28 -07:00
|
|
|
for (int32_t i = mCurrentCanvasList.Length() - 1; i >= 0 ; i--) {
|
2013-01-03 21:16:14 -08:00
|
|
|
HTMLCanvasElement* canvas = mCurrentCanvasList[i];
|
2012-08-30 17:24:35 -07:00
|
|
|
canvas->ResetPrintCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentCanvasList.Clear();
|
|
|
|
mCurrentCanvasListSetup = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::PrintNextPage()
|
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
|
2013-07-24 04:48:55 -07:00
|
|
|
nsIFrame* currentPage = GetCurrentPageFrame();
|
|
|
|
if (!currentPage) {
|
2012-08-30 17:24:35 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
DetermineWhetherToPrintPage();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mPrintThisPage) {
|
2012-08-30 17:24:35 -07:00
|
|
|
// Begin printing of the document
|
|
|
|
nsDeviceContext* dc = PresContext()->DeviceContext();
|
|
|
|
|
2007-03-22 10:30:00 -07: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
|
2011-09-28 23:19:26 -07:00
|
|
|
bool continuePrinting = true;
|
2007-11-20 21:09:58 -08:00
|
|
|
nscoord width, height;
|
2007-03-30 14:11:41 -07:00
|
|
|
width = PresContext()->GetPageSize().width;
|
|
|
|
height = PresContext()->GetPageSize().height;
|
2007-03-22 10:30:00 -07:00
|
|
|
height -= mMargin.top + mMargin.bottom;
|
|
|
|
width -= mMargin.left + mMargin.right;
|
|
|
|
nscoord selectionY = height;
|
2013-07-24 04:48:55 -07:00
|
|
|
nsIFrame* conFrame = currentPage->GetFirstPrincipalChild();
|
2007-11-20 21:09:58 -08:00
|
|
|
if (mSelectionHeight >= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
conFrame->SetPosition(conFrame->GetPosition() + nsPoint(0, -mYSelOffset));
|
2008-04-28 15:55:04 -07:00
|
|
|
nsContainerFrame::PositionChildViews(conFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// cast the frame to be a page frame
|
2013-07-24 04:48:55 -07:00
|
|
|
nsPageFrame * pf = static_cast<nsPageFrame*>(currentPage);
|
2007-03-22 10:30:00 -07:00
|
|
|
pf->SetPageNumInfo(mPageNum, mTotalPages);
|
|
|
|
pf->SetSharedPageData(mPageData);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t printedPageNum = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (continuePrinting) {
|
2007-03-30 14:11:41 -07:00
|
|
|
if (PresContext()->IsRootPaginatedDocument()) {
|
2012-08-30 17:24:35 -07:00
|
|
|
if (!mCalledBeginPage) {
|
|
|
|
PR_PL(("\n"));
|
|
|
|
PR_PL(("***************** BeginPage *****************\n"));
|
|
|
|
rv = dc->BeginPage();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
mCalledBeginPage = false;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
PR_PL(("SeqFr::PrintNextPage -> %p PageNo: %d", pf, mPageNum));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-14 20:15:01 -07:00
|
|
|
nsRefPtr<nsRenderingContext> renderingContext =
|
|
|
|
dc->CreateRenderingContext();
|
2008-04-07 17:32:48 -07:00
|
|
|
|
2013-07-24 04:48:55 -07:00
|
|
|
nsRect drawingRect(nsPoint(0, 0), currentPage->GetSize());
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRegion drawingRegion(drawingRect);
|
2013-07-24 04:48:55 -07:00
|
|
|
nsLayoutUtils::PaintFrame(renderingContext, currentPage,
|
2009-09-12 15:44:18 -07:00
|
|
|
drawingRegion, NS_RGBA(0,0,0,0),
|
|
|
|
nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-20 21:09:58 -08:00
|
|
|
if (mSelectionHeight >= 0 && selectionY < mSelectionHeight) {
|
2007-03-22 10:30:00 -07:00
|
|
|
selectionY += height;
|
|
|
|
printedPageNum++;
|
|
|
|
pf->SetPageNumInfo(printedPageNum, mTotalPages);
|
|
|
|
conFrame->SetPosition(conFrame->GetPosition() + nsPoint(0, -height));
|
2008-06-24 09:30:55 -07:00
|
|
|
nsContainerFrame::PositionChildViews(conFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PR_PL(("***************** End Page (PrintNextPage) *****************\n"));
|
|
|
|
rv = dc->EndPage();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
continuePrinting = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::DoPageEnd()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2007-03-30 14:11:41 -07:00
|
|
|
if (PresContext()->IsRootPaginatedDocument() && mPrintThisPage) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_PL(("***************** End Page (DoPageEnd) *****************\n"));
|
2007-03-30 14:11:41 -07:00
|
|
|
rv = PresContext()->DeviceContext()->EndPage();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2012-08-30 17:24:35 -07:00
|
|
|
ResetPrintCanvasList();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mPageNum++;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-19 16:26:35 -07:00
|
|
|
static gfx3DMatrix
|
|
|
|
ComputePageSequenceTransform(nsIFrame* aFrame, float aAppUnitsPerPixel)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-19 16:26:35 -07:00
|
|
|
float scale = aFrame->PresContext()->GetPrintPreviewScale();
|
|
|
|
return gfx3DMatrix::ScalingMatrix(scale, scale, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSimplePageSequenceFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-19 16:26:35 -07:00
|
|
|
nsDisplayList content;
|
2013-04-15 00:10:19 -07:00
|
|
|
|
|
|
|
{
|
|
|
|
// Clear clip state while we construct the children of the
|
|
|
|
// nsDisplayTransform, since they'll be in a different coordinate system.
|
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
|
|
|
clipState.Clear();
|
|
|
|
|
|
|
|
nsIFrame* child = GetFirstPrincipalChild();
|
|
|
|
while (child) {
|
|
|
|
child->BuildDisplayListForStackingContext(aBuilder,
|
|
|
|
child->GetVisualOverflowRectRelativeToSelf(), &content);
|
2013-06-18 02:15:37 -07:00
|
|
|
aBuilder->ResetMarkedFramesForDisplayList();
|
2013-04-15 00:10:19 -07:00
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
2012-09-19 16:26:35 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
content.AppendNewToTop(new (aBuilder)
|
2012-10-04 19:29:56 -07:00
|
|
|
nsDisplayTransform(aBuilder, this, &content, ::ComputePageSequenceTransform));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-19 16:26:35 -07:00
|
|
|
aLists.Content()->AppendToTop(&content);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsSimplePageSequenceFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::sequenceFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2013-07-24 04:48:54 -07:00
|
|
|
nsSimplePageSequenceFrame::SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(mPageData != nullptr, "mPageData string cannot be null!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aForPageNumOnly) {
|
|
|
|
mPageData->mPageNumFormat = aFormatStr;
|
|
|
|
} else {
|
|
|
|
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2013-07-24 04:48:54 -07:00
|
|
|
nsSimplePageSequenceFrame::SetDateTimeStr(const nsAString& aDateTimeStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(mPageData != nullptr, "mPageData string cannot be null!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mPageData->mDateTimeStr = aDateTimeStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// 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);
|
2014-02-03 18:12:13 -08:00
|
|
|
aSTFPercent = mPageData->mShrinkToFitRatio;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|