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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsPrintData.h"
|
|
|
|
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsPrintObject.h"
|
|
|
|
#include "nsPrintPreviewListener.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
2010-05-14 02:24:41 -07:00
|
|
|
#include "mozilla/Services.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
// PR LOGGING
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
#define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
|
2012-10-29 16:32:10 -07:00
|
|
|
static PRLogModuleInfo *
|
|
|
|
GetPrintingLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sLog;
|
|
|
|
if (!sLog)
|
|
|
|
sLog = PR_NewLogModule("printing");
|
|
|
|
return sLog;
|
|
|
|
}
|
|
|
|
#define PR_PL(_p1) PR_LOG(GetPrintingLog(), PR_LOG_DEBUG, _p1);
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
#define PRT_YESNO(_p)
|
|
|
|
#define PR_PL(_p1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//---------------------------------------------------
|
|
|
|
//-- nsPrintData Class Impl
|
|
|
|
//---------------------------------------------------
|
|
|
|
nsPrintData::nsPrintData(ePrintDataType aType) :
|
2012-07-30 07:20:58 -07:00
|
|
|
mType(aType), mDebugFilePtr(nullptr), mPrintObject(nullptr), mSelectedPO(nullptr),
|
2012-07-20 04:16:17 -07:00
|
|
|
mPrintDocList(0), mIsIFrameSelected(false),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsParentAFrameSet(false), mOnStartSent(false),
|
|
|
|
mIsAborted(false), mPreparingForPrint(false), mDocWasToBeDestroyed(false),
|
|
|
|
mShrinkToFit(false), mPrintFrameType(nsIPrintSettings::kFramesAsIs),
|
2007-03-22 10:30:00 -07:00
|
|
|
mNumPrintablePages(0), mNumPagesPrinted(0),
|
2013-10-08 11:47:21 -07:00
|
|
|
mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(nullptr),
|
2012-07-30 07:20:58 -07:00
|
|
|
mBrandName(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-16 11:20:13 -07:00
|
|
|
MOZ_COUNT_CTOR(nsPrintData);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIStringBundle> brandBundle;
|
2010-05-14 02:24:41 -07:00
|
|
|
nsCOMPtr<nsIStringBundleService> svc =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (svc) {
|
|
|
|
svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) );
|
|
|
|
if (brandBundle) {
|
2013-12-12 17:50:01 -08:00
|
|
|
brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"), &mBrandName );
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mBrandName) {
|
|
|
|
mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintData::~nsPrintData()
|
|
|
|
{
|
2011-06-16 11:20:13 -07:00
|
|
|
MOZ_COUNT_DTOR(nsPrintData);
|
2007-03-22 10:30:00 -07:00
|
|
|
// remove the event listeners
|
|
|
|
if (mPPEventListeners) {
|
|
|
|
mPPEventListeners->RemoveListeners();
|
|
|
|
NS_RELEASE(mPPEventListeners);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only Send an OnEndPrinting if we have started printing
|
|
|
|
if (mOnStartSent && mType != eIsPrintPreview) {
|
|
|
|
OnEndPrinting();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPrintDC && !mDebugFilePtr) {
|
|
|
|
PR_PL(("****************** End Document ************************\n"));
|
|
|
|
PR_PL(("\n"));
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isCancelled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
mPrintSettings->GetIsCancelled(&isCancelled);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mType == eIsPrinting) {
|
|
|
|
if (!isCancelled && !mIsAborted) {
|
|
|
|
rv = mPrintDC->EndDocument();
|
|
|
|
} else {
|
|
|
|
rv = mPrintDC->AbortDocument();
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// XXX nsPrintData::ShowPrintErrorDialog(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete mPrintObject;
|
|
|
|
|
|
|
|
if (mBrandName) {
|
|
|
|
NS_Free(mBrandName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrintData::OnStartPrinting()
|
|
|
|
{
|
|
|
|
if (!mOnStartSent) {
|
2011-11-28 13:43:33 -08:00
|
|
|
DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK);
|
2011-10-17 07:59:28 -07:00
|
|
|
mOnStartSent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrintData::OnEndPrinting()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
|
2011-11-28 13:43:33 -08:00
|
|
|
DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_NETWORK);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsPrintData::DoOnProgressChange(int32_t aProgress,
|
|
|
|
int32_t aMaxProgress,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoStartStop,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFlag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i=0;i<mPrintProgressListeners.Count();i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIWebProgressListener* wpl = mPrintProgressListeners.ObjectAt(i);
|
2012-07-30 07:20:58 -07:00
|
|
|
wpl->OnProgressChange(nullptr, nullptr, aProgress, aMaxProgress, aProgress, aMaxProgress);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDoStartStop) {
|
2012-07-27 06:59:29 -07:00
|
|
|
wpl->OnStateChange(nullptr, nullptr, aFlag, NS_OK);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|