2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
|
//---------------------------------------------------
|
2017-05-10 11:25:56 +03:00
|
|
|
nsPrintData::nsPrintData(ePrintDataType aType)
|
|
|
|
: mType(aType)
|
|
|
|
, mPrintDocList(0)
|
|
|
|
, mIsIFrameSelected(false)
|
|
|
|
, mIsParentAFrameSet(false)
|
|
|
|
, mOnStartSent(false)
|
|
|
|
, mIsAborted(false)
|
|
|
|
, mPreparingForPrint(false)
|
|
|
|
, mDocWasToBeDestroyed(false)
|
|
|
|
, mShrinkToFit(false)
|
|
|
|
, mPrintFrameType(nsIPrintSettings::kFramesAsIs)
|
|
|
|
, mNumPrintablePages(0)
|
|
|
|
, mNumPagesPrinted(0)
|
|
|
|
, mShrinkRatio(1.0)
|
|
|
|
, mOrigDCScale(1.0)
|
|
|
|
, mPPEventListeners(nullptr)
|
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) {
|
2017-08-04 07:40:52 +03:00
|
|
|
brandBundle->GetStringFromName("brandShortName", mBrandName);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 07:40:52 +03:00
|
|
|
if (mBrandName.IsEmpty()) {
|
|
|
|
mBrandName.AssignLiteral(u"Mozilla Document");
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintData::~nsPrintData()
|
|
|
|
{
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2017-10-05 21:15:57 +03:00
|
|
|
if (mPrintDC) {
|
2002-08-21 16:01:05 +04:00
|
|
|
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;
|
2017-04-20 18:00:33 +03:00
|
|
|
if (mType == eIsPrinting &&
|
|
|
|
mPrintDC->IsCurrentlyPrintingDocument()) {
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!isCancelled && !mIsAborted) {
|
|
|
|
rv = mPrintDC->EndDocument();
|
|
|
|
} else {
|
2017-03-06 10:35:39 +03:00
|
|
|
rv = mPrintDC->AbortDocument();
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// XXX nsPrintData::ShowPrintErrorDialog(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-05-02 11:07:45 +03:00
|
|
|
size_t numberOfListeners = mPrintProgressListeners.Length();
|
|
|
|
for (size_t i = 0; i < numberOfListeners; ++i) {
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener =
|
|
|
|
mPrintProgressListeners.SafeElementAt(i);
|
|
|
|
if (NS_WARN_IF(!listener)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
listener->OnProgressChange(nullptr, nullptr, aProgress, aMaxProgress,
|
|
|
|
aProgress, aMaxProgress);
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aDoStartStop) {
|
2017-05-02 11:07:45 +03:00
|
|
|
listener->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)
|
|
|
|
{
|
2017-05-02 11:07:45 +03:00
|
|
|
size_t numberOfListeners = mPrintProgressListeners.Length();
|
|
|
|
for (size_t i = 0; i < numberOfListeners; ++i) {
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener =
|
|
|
|
mPrintProgressListeners.SafeElementAt(i);
|
|
|
|
if (NS_WARN_IF(!listener)) {
|
|
|
|
continue;
|
2016-05-16 12:40:54 +03:00
|
|
|
}
|
2017-05-02 11:07:45 +03:00
|
|
|
listener->OnStatusChange(nullptr, nullptr, aStatus, nullptr);
|
2016-05-16 12:40:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|