mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1785046 - Part 3: Let nsIDeviceContextSpec::EndDocument
& nsDeviceContext::EndDocument
return MozPromise
. r=nika,emilio,geckoview-reviewers,m_kato
All implementors currently simply resolve the promise right away, using crutch code. Asynchronous usage will be added in the changeset that follows. Differential Revision: https://phabricator.services.mozilla.com/D163508
This commit is contained in:
parent
824e42a012
commit
aab93348e9
@ -270,7 +270,7 @@ nsresult nsDeviceContext::BeginDocument(const nsAString& aTitle,
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsDeviceContext::EndDocument() {
|
||||
RefPtr<PrintEndDocumentPromise> nsDeviceContext::EndDocument() {
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsCurrentlyPrintingDoc,
|
||||
"Mismatched BeginDocument/EndDocument calls");
|
||||
MOZ_DIAGNOSTIC_ASSERT(mPrintTarget);
|
||||
@ -278,16 +278,20 @@ nsresult nsDeviceContext::EndDocument() {
|
||||
mIsCurrentlyPrintingDoc = false;
|
||||
|
||||
if (mPrintTarget) {
|
||||
MOZ_TRY(mPrintTarget->EndPrinting());
|
||||
auto result = mPrintTarget->EndPrinting();
|
||||
if (NS_FAILED(result)) {
|
||||
return PrintEndDocumentPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
|
||||
__func__);
|
||||
}
|
||||
mPrintTarget->Finish();
|
||||
mPrintTarget = nullptr;
|
||||
}
|
||||
|
||||
if (mDeviceContextSpec) {
|
||||
MOZ_TRY(mDeviceContextSpec->EndDocument());
|
||||
return mDeviceContextSpec->EndDocument();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return PrintEndDocumentPromise::CreateAndResolve(true, __func__);
|
||||
}
|
||||
|
||||
nsresult nsDeviceContext::AbortDocument() {
|
||||
@ -298,7 +302,7 @@ nsresult nsDeviceContext::AbortDocument() {
|
||||
mIsCurrentlyPrintingDoc = false;
|
||||
|
||||
if (mDeviceContextSpec) {
|
||||
mDeviceContextSpec->EndDocument();
|
||||
Unused << mDeviceContextSpec->EndDocument();
|
||||
}
|
||||
|
||||
mPrintTarget = nullptr;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "mozilla/AppUnits.h" // for AppUnits
|
||||
#include "nsFontMetrics.h" // for nsFontMetrics::Params
|
||||
#include "mozilla/gfx/PrintTarget.h" // for PrintTarget::PageDoneCallback
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
|
||||
class gfxContext;
|
||||
class gfxTextPerfMetrics;
|
||||
@ -179,9 +180,9 @@ class nsDeviceContext final {
|
||||
* Inform the output device that output of a document is ending.
|
||||
* Used for print related device contexts. Must be matched 1:1 with
|
||||
* BeginDocument()
|
||||
* @return error status
|
||||
* @return Promise that can be chained once the operation is complete.
|
||||
*/
|
||||
nsresult EndDocument();
|
||||
RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument();
|
||||
|
||||
/**
|
||||
* Inform the output device that output of a document is being aborted.
|
||||
|
18
gfx/thebes/PrintPromise.h
Normal file
18
gfx/thebes/PrintPromise.h
Normal file
@ -0,0 +1,18 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* 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/. */
|
||||
|
||||
#ifndef MOZILLA_GFX_PRINTPROMISE_H
|
||||
#define MOZILLA_GFX_PRINTPROMISE_H
|
||||
|
||||
#include "ErrorList.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
|
||||
namespace mozilla::gfx {
|
||||
|
||||
using PrintEndDocumentPromise = MozPromise</* unused */ bool, nsresult, false>;
|
||||
|
||||
} // namespace mozilla::gfx
|
||||
|
||||
#endif
|
@ -70,6 +70,7 @@ EXPORTS.mozilla.gfx += [
|
||||
"D3D11Checks.h",
|
||||
"DeviceManagerDx.h",
|
||||
"DisplayConfigWindows.h",
|
||||
"PrintPromise.h",
|
||||
"PrintTarget.h",
|
||||
"PrintTargetThebes.h",
|
||||
"ThebesRLBox.h",
|
||||
|
@ -207,11 +207,48 @@ static void NotifyStateChange(
|
||||
}
|
||||
}
|
||||
|
||||
static void Cleanup(const nsCOMArray<nsIWebProgressListener>& aListeners,
|
||||
RefPtr<nsDeviceContext>& aAbortContext,
|
||||
const bool aPrintingInterrupted, const nsresult aResult) {
|
||||
auto result = aResult;
|
||||
if (MOZ_UNLIKELY(aPrintingInterrupted && NS_SUCCEEDED(result))) {
|
||||
result = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
if (NS_FAILED(result)) {
|
||||
NotifyStatusChange(aListeners, result);
|
||||
}
|
||||
if (aPrintingInterrupted && aAbortContext) {
|
||||
// Abort any started print.
|
||||
Unused << aAbortContext->AbortDocument();
|
||||
}
|
||||
// However the print went, let the listeners know that we're done.
|
||||
NotifyStateChange(aListeners,
|
||||
nsIWebProgressListener::STATE_STOP |
|
||||
nsIWebProgressListener::STATE_IS_DOCUMENT,
|
||||
result);
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult RemotePrintJobParent::RecvFinalizePrint() {
|
||||
// EndDocument is sometimes called in the child even when BeginDocument has
|
||||
// not been called. See bug 1223332.
|
||||
if (mPrintDeviceContext) {
|
||||
mStatus = mPrintDeviceContext->EndDocument();
|
||||
mPrintDeviceContext->EndDocument()->Then(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[listeners = std::move(mPrintProgressListeners)](
|
||||
const mozilla::gfx::PrintEndDocumentPromise::ResolveOrRejectValue&
|
||||
aResult) {
|
||||
// Printing isn't interrupted, so we don't need the device context
|
||||
// here.
|
||||
RefPtr<nsDeviceContext> empty;
|
||||
if (aResult.IsResolve()) {
|
||||
Cleanup(listeners, empty, /* aPrintingInterrupted = */ false,
|
||||
NS_OK);
|
||||
} else {
|
||||
Cleanup(listeners, empty, /* aPrintingInterrupted = */ false,
|
||||
aResult.RejectValue());
|
||||
}
|
||||
});
|
||||
mStatus = NS_OK;
|
||||
}
|
||||
|
||||
mIsDoingPrinting = false;
|
||||
@ -270,19 +307,8 @@ void RemotePrintJobParent::ActorDestroy(ActorDestroyReason aWhy) {
|
||||
if (MOZ_UNLIKELY(mIsDoingPrinting && NS_SUCCEEDED(mStatus))) {
|
||||
mStatus = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
if (NS_FAILED(mStatus)) {
|
||||
NotifyStatusChange(mPrintProgressListeners, mStatus);
|
||||
}
|
||||
if (mIsDoingPrinting && mPrintDeviceContext) {
|
||||
// Abort any started print.
|
||||
Unused << mPrintDeviceContext->AbortDocument();
|
||||
}
|
||||
// However the print went, let the listeners know that we're done.
|
||||
NotifyStateChange(mPrintProgressListeners,
|
||||
nsIWebProgressListener::STATE_STOP |
|
||||
nsIWebProgressListener::STATE_IS_DOCUMENT,
|
||||
mStatus);
|
||||
|
||||
Cleanup(mPrintProgressListeners, mPrintDeviceContext, mIsDoingPrinting,
|
||||
mStatus);
|
||||
// At any rate, this actor is done and cleaned up.
|
||||
mIsDoingPrinting = false;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "nsPrintData.h"
|
||||
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsPrintObject.h"
|
||||
@ -20,61 +21,12 @@ extern mozilla::LazyLogModule gPrintingLog;
|
||||
|
||||
#define PR_PL(_p1) MOZ_LOG(gPrintingLog, mozilla::LogLevel::Debug, _p1);
|
||||
|
||||
//---------------------------------------------------
|
||||
//-- nsPrintData Class Impl
|
||||
//---------------------------------------------------
|
||||
nsPrintData::nsPrintData(ePrintDataType aType)
|
||||
: mType(aType), mOnStartSent(false), mIsAborted(false) {}
|
||||
|
||||
nsPrintData::~nsPrintData() {
|
||||
// Only Send an OnEndPrinting if we have started printing
|
||||
if (mOnStartSent && mType != eIsPrintPreview) {
|
||||
OnEndPrinting();
|
||||
}
|
||||
|
||||
if (mPrintDC) {
|
||||
PR_PL(("****************** End Document ************************\n"));
|
||||
PR_PL(("\n"));
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (mType == eIsPrinting && mPrintDC->IsCurrentlyPrintingDocument()) {
|
||||
if (!mIsAborted) {
|
||||
rv = mPrintDC->EndDocument();
|
||||
} else {
|
||||
rv = mPrintDC->AbortDocument();
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
// XXX nsPrintData::ShowPrintErrorDialog(rv);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsPrintData::OnStartPrinting() {
|
||||
if (!mOnStartSent) {
|
||||
DoOnProgressChange(0, 0, true,
|
||||
nsIWebProgressListener::STATE_START |
|
||||
nsIWebProgressListener::STATE_IS_DOCUMENT |
|
||||
nsIWebProgressListener::STATE_IS_NETWORK);
|
||||
mOnStartSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
void nsPrintData::OnEndPrinting() {
|
||||
DoOnProgressChange(100, 100, true,
|
||||
nsIWebProgressListener::STATE_STOP |
|
||||
nsIWebProgressListener::STATE_IS_DOCUMENT);
|
||||
DoOnProgressChange(100, 100, true,
|
||||
nsIWebProgressListener::STATE_STOP |
|
||||
nsIWebProgressListener::STATE_IS_NETWORK);
|
||||
}
|
||||
|
||||
void nsPrintData::DoOnProgressChange(int32_t aProgress, int32_t aMaxProgress,
|
||||
bool aDoStartStop, int32_t aFlag) {
|
||||
size_t numberOfListeners = mPrintProgressListeners.Length();
|
||||
static void InformListenersOfProgressChange(
|
||||
const nsCOMArray<nsIWebProgressListener>& aListeners, int32_t aProgress,
|
||||
int32_t aMaxProgress, bool aDoStartStop, int32_t aFlag) {
|
||||
size_t numberOfListeners = aListeners.Length();
|
||||
for (size_t i = 0; i < numberOfListeners; ++i) {
|
||||
nsCOMPtr<nsIWebProgressListener> listener =
|
||||
mPrintProgressListeners.SafeElementAt(i);
|
||||
nsCOMPtr<nsIWebProgressListener> listener = aListeners.SafeElementAt(i);
|
||||
if (NS_WARN_IF(!listener)) {
|
||||
continue;
|
||||
}
|
||||
@ -86,6 +38,81 @@ void nsPrintData::DoOnProgressChange(int32_t aProgress, int32_t aMaxProgress,
|
||||
}
|
||||
}
|
||||
|
||||
static void InformListenersOfEndPrinting(
|
||||
const nsCOMArray<nsIWebProgressListener>& aListeners) {
|
||||
InformListenersOfProgressChange(
|
||||
aListeners, 100, 100, true,
|
||||
nsIWebProgressListener::STATE_STOP |
|
||||
nsIWebProgressListener::STATE_IS_DOCUMENT);
|
||||
InformListenersOfProgressChange(aListeners, 100, 100, true,
|
||||
nsIWebProgressListener::STATE_STOP |
|
||||
nsIWebProgressListener::STATE_IS_NETWORK);
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
//-- nsPrintData Class Impl
|
||||
//---------------------------------------------------
|
||||
nsPrintData::nsPrintData(ePrintDataType aType)
|
||||
: mType(aType), mOnStartSent(false), mIsAborted(false) {}
|
||||
|
||||
nsPrintData::~nsPrintData() {
|
||||
// Two things need to be done:
|
||||
// - Inform the listeners
|
||||
// - End/Abort document
|
||||
// Preview requires neither, so return early.
|
||||
if (mType == eIsPrintPreview) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mPrintDC) {
|
||||
PR_PL(("****************** End Document ************************\n"));
|
||||
PR_PL(("\n"));
|
||||
if (mPrintDC->IsCurrentlyPrintingDocument()) {
|
||||
if (!mIsAborted) {
|
||||
auto promise = mPrintDC->EndDocument();
|
||||
if (mOnStartSent) {
|
||||
promise->Then(mozilla::GetMainThreadSerialEventTarget(), __func__,
|
||||
[listeners = std::move(mPrintProgressListeners)](
|
||||
// We're in dtor, so capture listeners by move.
|
||||
const mozilla::gfx::PrintEndDocumentPromise::
|
||||
ResolveOrRejectValue&) {
|
||||
InformListenersOfEndPrinting(listeners);
|
||||
});
|
||||
}
|
||||
// Informing listeners asynchronously, or don't need to inform them, so
|
||||
// return early.
|
||||
return;
|
||||
}
|
||||
mPrintDC->AbortDocument();
|
||||
}
|
||||
}
|
||||
if (mOnStartSent) {
|
||||
// Synchronously notify the listeners.
|
||||
OnEndPrinting();
|
||||
}
|
||||
}
|
||||
|
||||
void nsPrintData::OnStartPrinting() {
|
||||
if (!mOnStartSent) {
|
||||
InformListenersOfProgressChange(
|
||||
mPrintProgressListeners, 0, 0, true,
|
||||
nsIWebProgressListener::STATE_START |
|
||||
nsIWebProgressListener::STATE_IS_DOCUMENT |
|
||||
nsIWebProgressListener::STATE_IS_NETWORK);
|
||||
mOnStartSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
void nsPrintData::OnEndPrinting() {
|
||||
InformListenersOfEndPrinting(mPrintProgressListeners);
|
||||
}
|
||||
|
||||
void nsPrintData::DoOnProgressChange(int32_t aProgress, int32_t aMaxProgress,
|
||||
bool aDoStartStop, int32_t aFlag) {
|
||||
InformListenersOfProgressChange(mPrintProgressListeners, aProgress,
|
||||
aMaxProgress, aDoStartStop, aFlag);
|
||||
}
|
||||
|
||||
void nsPrintData::DoOnStatusChange(nsresult aStatus) {
|
||||
size_t numberOfListeners = mPrintProgressListeners.Length();
|
||||
for (size_t i = 0; i < numberOfListeners; ++i) {
|
||||
|
@ -1988,11 +1988,10 @@ nsresult nsPrintJob::FinishPrintPreview() {
|
||||
|
||||
// mPrt may be cleared during a call of nsPrintData::OnEndPrinting()
|
||||
// because that method invokes some arbitrary listeners.
|
||||
// TODO(dshin): Does any listener attach to print preview? Doesn't seem like
|
||||
// we call matching `OnStartPrinting()` for previews.
|
||||
RefPtr<nsPrintData> printData = mPrt;
|
||||
if (NS_FAILED(rv)) {
|
||||
/* cleanup done, let's fire-up an error dialog to notify the user
|
||||
* what went wrong...
|
||||
*/
|
||||
printData->OnEndPrinting();
|
||||
|
||||
return rv;
|
||||
|
@ -71,8 +71,13 @@ nsDeviceContextSpecAndroid::BeginDocument(const nsAString& aTitle,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<PrintEndDocumentPromise> nsDeviceContextSpecAndroid::EndDocument() {
|
||||
return nsIDeviceContextSpec::EndDocumentPromiseFromResult(DoEndDocument(),
|
||||
__func__);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDeviceContextSpecAndroid::EndDocument() {
|
||||
nsDeviceContextSpecAndroid::DoEndDocument() {
|
||||
if (mPrintSettings->GetOutputDestination() ==
|
||||
nsIPrintSettings::kOutputDestinationFile &&
|
||||
mTempFile) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "nsIDeviceContextSpec.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
|
||||
class nsDeviceContextSpecAndroid final : public nsIDeviceContextSpec {
|
||||
private:
|
||||
@ -21,11 +22,12 @@ class nsDeviceContextSpecAndroid final : public nsIDeviceContextSpec {
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
const nsAString& aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage) override;
|
||||
NS_IMETHOD EndDocument() override;
|
||||
RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() override;
|
||||
NS_IMETHOD BeginPage() override { return NS_OK; }
|
||||
NS_IMETHOD EndPage() override { return NS_OK; }
|
||||
|
||||
private:
|
||||
nsresult DoEndDocument();
|
||||
nsCOMPtr<nsIFile> mTempFile;
|
||||
};
|
||||
#endif // nsDeviceContextAndroid_h__
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
class nsDeviceContextSpecX : public nsIDeviceContextSpec {
|
||||
@ -25,7 +27,7 @@ class nsDeviceContextSpecX : public nsIDeviceContextSpec {
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
const nsAString& aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage) override;
|
||||
NS_IMETHOD EndDocument() override;
|
||||
RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() override;
|
||||
NS_IMETHOD BeginPage() override { return NS_OK; };
|
||||
NS_IMETHOD EndPage() override { return NS_OK; };
|
||||
|
||||
@ -44,6 +46,8 @@ class nsDeviceContextSpecX : public nsIDeviceContextSpec {
|
||||
// file "print" output generated if printing via PDF
|
||||
nsCOMPtr<nsIFile> mTempFile;
|
||||
#endif
|
||||
private:
|
||||
nsresult DoEndDocument();
|
||||
};
|
||||
|
||||
#endif // nsDeviceContextSpecX_h_
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "nsDeviceContextSpecX.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -36,6 +37,7 @@
|
||||
|
||||
using namespace mozilla;
|
||||
using mozilla::gfx::IntSize;
|
||||
using mozilla::gfx::PrintEndDocumentPromise;
|
||||
using mozilla::gfx::PrintTarget;
|
||||
using mozilla::gfx::PrintTargetCG;
|
||||
#ifdef MOZ_ENABLE_SKIA_PDF
|
||||
@ -165,7 +167,11 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle,
|
||||
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecX::EndDocument() {
|
||||
RefPtr<PrintEndDocumentPromise> nsDeviceContextSpecX::EndDocument() {
|
||||
return nsIDeviceContextSpec::EndDocumentPromiseFromResult(DoEndDocument(), __func__);
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextSpecX::DoEndDocument() {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
#ifdef MOZ_ENABLE_SKIA_PDF
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "nsDeviceContextSpecG.h"
|
||||
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
#include "mozilla/gfx/PrintTargetPDF.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/Services.h"
|
||||
@ -46,6 +47,7 @@
|
||||
using namespace mozilla;
|
||||
|
||||
using mozilla::gfx::IntSize;
|
||||
using mozilla::gfx::PrintEndDocumentPromise;
|
||||
using mozilla::gfx::PrintTarget;
|
||||
using mozilla::gfx::PrintTargetPDF;
|
||||
|
||||
@ -335,7 +337,12 @@ nsDeviceContextSpecGTK::BeginDocument(const nsAString& aTitle,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK::EndDocument() {
|
||||
RefPtr<PrintEndDocumentPromise> nsDeviceContextSpecGTK::EndDocument() {
|
||||
return nsIDeviceContextSpec::EndDocumentPromiseFromResult(DoEndDocument(),
|
||||
__func__);
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextSpecGTK::DoEndDocument() {
|
||||
switch (mPrintSettings->GetOutputDestination()) {
|
||||
case nsIPrintSettings::kOutputDestinationPrinter: {
|
||||
// At this point, we might have a GtkPrinter set up in nsPrintSettingsGTK,
|
||||
|
@ -14,6 +14,7 @@ struct JSContext;
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
|
||||
#include "nsCRT.h" /* should be <limits.h>? */
|
||||
|
||||
@ -37,7 +38,7 @@ class nsDeviceContextSpecGTK : public nsIDeviceContextSpec {
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
const nsAString& aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage) override;
|
||||
NS_IMETHOD EndDocument() override;
|
||||
RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() override;
|
||||
NS_IMETHOD BeginPage() override { return NS_OK; }
|
||||
NS_IMETHOD EndPage() override { return NS_OK; }
|
||||
|
||||
@ -51,6 +52,7 @@ class nsDeviceContextSpecGTK : public nsIDeviceContextSpec {
|
||||
nsCString mTitle;
|
||||
|
||||
private:
|
||||
nsresult DoEndDocument();
|
||||
void EnumeratePrinters();
|
||||
void StartPrintJob();
|
||||
static gboolean PrinterEnumerator(GtkPrinter* aPrinter, gpointer aData);
|
||||
|
@ -115,28 +115,18 @@ nsDeviceContextSpecProxy::BeginDocument(const nsAString& aTitle,
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RefPtr<mozilla::gfx::PrintEndDocumentPromise>
|
||||
nsDeviceContextSpecProxy::EndDocument() {
|
||||
if (!mRemotePrintJob || mRemotePrintJob->IsDestroyed()) {
|
||||
mRemotePrintJob = nullptr;
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return mozilla::gfx::PrintEndDocumentPromise::CreateAndReject(
|
||||
NS_ERROR_NOT_AVAILABLE, __func__);
|
||||
}
|
||||
|
||||
Unused << mRemotePrintJob->SendFinalizePrint();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDeviceContextSpecProxy::AbortDocument() {
|
||||
if (!mRemotePrintJob || mRemotePrintJob->IsDestroyed()) {
|
||||
mRemotePrintJob = nullptr;
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
Unused << mRemotePrintJob->SendAbortPrint(NS_OK);
|
||||
|
||||
return NS_OK;
|
||||
return mozilla::gfx::PrintEndDocumentPromise::CreateAndResolve(true,
|
||||
__func__);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/layout/printing/DrawEventRecorder.h"
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
|
||||
class nsIFile;
|
||||
class nsIUUIDGenerator;
|
||||
@ -40,9 +41,7 @@ class nsDeviceContextSpecProxy final : public nsIDeviceContextSpec {
|
||||
const nsAString& aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage) final;
|
||||
|
||||
NS_IMETHOD EndDocument() final;
|
||||
|
||||
NS_IMETHOD AbortDocument() final;
|
||||
RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() final;
|
||||
|
||||
NS_IMETHOD BeginPage() final;
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "gfxPoint.h"
|
||||
#include "nsIPrintSettings.h"
|
||||
|
||||
using mozilla::gfx::PrintEndDocumentPromise;
|
||||
|
||||
// We have some platform specific code here rather than in the appropriate
|
||||
// nsIDeviceContextSpec subclass. We structure the code this way so that
|
||||
// nsIDeviceContextSpecProxy gets the correct behavior without us having to
|
||||
@ -48,3 +50,11 @@ gfxPoint nsIDeviceContextSpec::GetPrintingTranslate() {
|
||||
return gfxPoint(0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
RefPtr<PrintEndDocumentPromise>
|
||||
nsIDeviceContextSpec::EndDocumentPromiseFromResult(nsresult aResult,
|
||||
const char* aSite) {
|
||||
return NS_SUCCEEDED(aResult)
|
||||
? PrintEndDocumentPromise::CreateAndResolve(true, aSite)
|
||||
: PrintEndDocumentPromise::CreateAndReject(aResult, aSite);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "gfxPoint.h"
|
||||
#include "nsISupports.h"
|
||||
#include "mozilla/StaticPrefs_print.h"
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
|
||||
class nsIWidget;
|
||||
class nsIPrintSettings;
|
||||
@ -76,12 +77,14 @@ class nsIDeviceContextSpec : public nsISupports {
|
||||
const nsAString& aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage) = 0;
|
||||
|
||||
NS_IMETHOD EndDocument() = 0;
|
||||
NS_IMETHOD AbortDocument() { return EndDocument(); }
|
||||
virtual RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() = 0;
|
||||
NS_IMETHOD BeginPage() = 0;
|
||||
NS_IMETHOD EndPage() = 0;
|
||||
|
||||
protected:
|
||||
static RefPtr<mozilla::gfx::PrintEndDocumentPromise>
|
||||
EndDocumentPromiseFromResult(nsresult aResult, const char* aSite);
|
||||
|
||||
nsCOMPtr<nsIPrintSettings> mPrintSettings;
|
||||
|
||||
#ifdef MOZ_ENABLE_SKIA_PDF
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "nsDeviceContextSpecWin.h"
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
#include "mozilla/gfx/PrintTargetPDF.h"
|
||||
#include "mozilla/gfx/PrintTargetWindows.h"
|
||||
#include "mozilla/Logging.h"
|
||||
@ -331,7 +332,12 @@ already_AddRefed<PrintTarget> nsDeviceContextSpecWin::MakePrintTarget() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecWin::EndDocument() {
|
||||
RefPtr<PrintEndDocumentPromise> nsDeviceContextSpecWin::EndDocument() {
|
||||
return nsIDeviceContextSpec::EndDocumentPromiseFromResult(DoEndDocument(),
|
||||
__func__);
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextSpecWin::DoEndDocument() {
|
||||
if (mPrintSettings->GetOutputDestination() !=
|
||||
nsIPrintSettings::kOutputDestinationFile ||
|
||||
mOutputFormat != nsIPrintSettings::kOutputFormatPDF) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <windows.h>
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/gfx/PrintPromise.h"
|
||||
|
||||
class nsIFile;
|
||||
class nsIWidget;
|
||||
@ -29,7 +30,7 @@ class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
|
||||
int32_t aStartPage, int32_t aEndPage) override {
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD EndDocument() override;
|
||||
RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() override;
|
||||
NS_IMETHOD BeginPage() override { return NS_OK; }
|
||||
NS_IMETHOD EndPage() override { return NS_OK; }
|
||||
|
||||
@ -68,6 +69,9 @@ class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
|
||||
// A temporary file to create an "anonymous" print target. See bug 1664253,
|
||||
// this should ideally not be needed.
|
||||
nsCOMPtr<nsIFile> mTempFile;
|
||||
|
||||
private:
|
||||
nsresult DoEndDocument();
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user