2002-08-21 16:01:05 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
#include "nsPrintData.h"
|
|
|
|
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2006-12-10 11:05:05 +03:00
|
|
|
#include "nsPrintObject.h"
|
|
|
|
#include "nsPrintPreviewListener.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
2010-05-14 13:24:41 +04:00
|
|
|
#include "mozilla/Services.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
// PR LOGGING
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
#define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
|
2015-11-06 01:35:03 +03:00
|
|
|
static mozilla::LazyLogModule gPrintingLog("printing");
|
|
|
|
|
|
|
|
#define PR_PL(_p1) MOZ_LOG(gPrintingLog, mozilla::LogLevel::Debug, _p1);
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
//---------------------------------------------------
|
|
|
|
//-- nsPrintData Class Impl
|
|
|
|
//---------------------------------------------------
|
|
|
|
nsPrintData::nsPrintData(ePrintDataType aType) :
|
2012-07-30 18:20:58 +04:00
|
|
|
mType(aType), mDebugFilePtr(nullptr), mPrintObject(nullptr), mSelectedPO(nullptr),
|
2012-07-20 15:16:17 +04:00
|
|
|
mPrintDocList(0), mIsIFrameSelected(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsParentAFrameSet(false), mOnStartSent(false),
|
|
|
|
mIsAborted(false), mPreparingForPrint(false), mDocWasToBeDestroyed(false),
|
|
|
|
mShrinkToFit(false), mPrintFrameType(nsIPrintSettings::kFramesAsIs),
|
2006-12-10 11:05:05 +03:00
|
|
|
mNumPrintablePages(0), mNumPagesPrinted(0),
|
2013-10-08 22:47:21 +04:00
|
|
|
mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(nullptr),
|
2012-07-30 18:20:58 +04:00
|
|
|
mBrandName(nullptr)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2011-06-16 22:20:13 +04:00
|
|
|
MOZ_COUNT_CTOR(nsPrintData);
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIStringBundle> brandBundle;
|
2010-05-14 13:24:41 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> svc =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2002-08-21 16:01:05 +04:00
|
|
|
if (svc) {
|
2005-03-10 07:38:35 +03:00
|
|
|
svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) );
|
2002-08-21 16:01:05 +04:00
|
|
|
if (brandBundle) {
|
2016-07-21 08:03:25 +03:00
|
|
|
brandBundle->GetStringFromName(u"brandShortName", &mBrandName );
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mBrandName) {
|
|
|
|
mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintData::~nsPrintData()
|
|
|
|
{
|
2011-06-16 22:20:13 +04:00
|
|
|
MOZ_COUNT_DTOR(nsPrintData);
|
2002-08-21 16:01:05 +04: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-29 10:19:26 +04:00
|
|
|
bool isCancelled = false;
|
2002-08-21 16:01:05 +04: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) {
|
2015-04-01 08:29:55 +03:00
|
|
|
free(mBrandName);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrintData::OnStartPrinting()
|
|
|
|
{
|
|
|
|
if (!mOnStartSent) {
|
2011-11-29 01:43:33 +04:00
|
|
|
DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK);
|
2011-10-17 18:59:28 +04:00
|
|
|
mOnStartSent = true;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPrintData::OnEndPrinting()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT);
|
2011-11-29 01:43:33 +04:00
|
|
|
DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_NETWORK);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPrintData::DoOnProgressChange(int32_t aProgress,
|
|
|
|
int32_t aMaxProgress,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoStartStop,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aFlag)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i=0;i<mPrintProgressListeners.Count();i++) {
|
2006-12-10 11:05:05 +03:00
|
|
|
nsIWebProgressListener* wpl = mPrintProgressListeners.ObjectAt(i);
|
2012-07-30 18:20:58 +04:00
|
|
|
wpl->OnProgressChange(nullptr, nullptr, aProgress, aMaxProgress, aProgress, aMaxProgress);
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aDoStartStop) {
|
2012-07-27 17:59:29 +04:00
|
|
|
wpl->OnStateChange(nullptr, nullptr, aFlag, NS_OK);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:40:54 +03:00
|
|
|
void
|
|
|
|
nsPrintData::DoOnStatusChange(nsresult aStatus)
|
|
|
|
{
|
|
|
|
uint32_t numberOfListeners = mPrintProgressListeners.Length();
|
|
|
|
for (uint32_t i = 0; i < numberOfListeners; ++i) {
|
|
|
|
nsIWebProgressListener* listener = mPrintProgressListeners.SafeElementAt(i);
|
|
|
|
if (listener) {
|
|
|
|
listener->OnStatusChange(nullptr, nullptr, aStatus, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|