Bug 1309272, part 7 - Restructure the PMSessionBeginCGDocumentNoDialog related code to live in PrintTargetCG. r=lsalzman

This commit is contained in:
Jonathan Watt 2016-11-22 16:39:08 +00:00
Родитель 4d09d162ad
Коммит a986dd0cf9
4 изменённых файлов: 91 добавлений и 46 удалений

Просмотреть файл

@ -19,8 +19,17 @@ class PrintTargetCG final : public PrintTarget
{
public:
static already_AddRefed<PrintTargetCG>
CreateOrNull(PMPrintSession aPrintSession, const IntSize& aSize);
CreateOrNull(PMPrintSession aPrintSession,
PMPageFormat aPageFormat,
PMPrintSettings aPrintSettings,
const IntSize& aSize);
virtual nsresult BeginPrinting(const nsAString& aTitle,
const nsAString& aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage) final;
virtual nsresult EndPrinting() final;
virtual nsresult AbortPrinting() final;
virtual nsresult BeginPage() final;
virtual nsresult EndPage() final;
@ -29,10 +38,14 @@ public:
private:
PrintTargetCG(PMPrintSession aPrintSession,
PMPageFormat aPageFormat,
PMPrintSettings aPrintSettings,
const IntSize& aSize);
~PrintTargetCG();
PMPrintSession mPrintSession;
PMPageFormat mPageFormat;
PMPrintSettings mPrintSettings;
};
} // namespace gfx

Просмотреть файл

@ -14,9 +14,13 @@ namespace mozilla {
namespace gfx {
PrintTargetCG::PrintTargetCG(PMPrintSession aPrintSession,
PMPageFormat aPageFormat,
PMPrintSettings aPrintSettings,
const IntSize& aSize)
: PrintTarget(/* aCairoSurface */ nullptr, aSize)
, mPrintSession(aPrintSession)
, mPageFormat(aPageFormat)
, mPrintSettings(aPrintSettings)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
@ -39,13 +43,17 @@ PrintTargetCG::~PrintTargetCG()
}
/* static */ already_AddRefed<PrintTargetCG>
PrintTargetCG::CreateOrNull(PMPrintSession aPrintSession, const IntSize& aSize)
PrintTargetCG::CreateOrNull(PMPrintSession aPrintSession,
PMPageFormat aPageFormat,
PMPrintSettings aPrintSettings,
const IntSize& aSize)
{
if (!Factory::CheckSurfaceSize(aSize)) {
return nullptr;
}
RefPtr<PrintTargetCG> target = new PrintTargetCG(aPrintSession, aSize);
RefPtr<PrintTargetCG> target = new PrintTargetCG(aPrintSession, aPageFormat,
aPrintSettings, aSize);
return target.forget();
}
@ -99,13 +107,60 @@ PrintTargetCG::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
return do_AddRef(mRefDT);
}
nsresult
PrintTargetCG::BeginPrinting(const nsAString& aTitle,
const nsAString& aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
OSStatus status;
status = ::PMSetFirstPage(mPrintSettings, aStartPage, false);
NS_ASSERTION(status == noErr, "PMSetFirstPage failed");
status = ::PMSetLastPage(mPrintSettings, aEndPage, false);
NS_ASSERTION(status == noErr, "PMSetLastPage failed");
status = ::PMSessionBeginCGDocumentNoDialog(mPrintSession, mPrintSettings, mPageFormat);
return status == noErr ? NS_OK : NS_ERROR_ABORT;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult
PrintTargetCG::EndPrinting()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
::PMSessionEndDocumentNoDialog(mPrintSession);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult
PrintTargetCG::AbortPrinting()
{
#ifdef DEBUG
mHasActivePage = false;
#endif
return EndPrinting();
}
nsresult
PrintTargetCG::BeginPage()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
PMSessionError(mPrintSession);
OSStatus status = ::PMSessionBeginPageNoDialog(mPrintSession, mPageFormat, NULL);
if (status != noErr) {
return NS_ERROR_ABORT;
}
CGContextRef context;
// This call will fail if we are not called between the PMSessionBeginPage/
// This call will fail if it wasn't called between the PMSessionBeginPage/
// PMSessionEndPage calls:
::PMSessionGetCGGraphicsContext(mPrintSession, &context);
@ -138,9 +193,19 @@ PrintTargetCG::BeginPage()
nsresult
PrintTargetCG::EndPage()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
cairo_surface_finish(mCairoSurface);
mCairoSurface = nullptr;
OSStatus status = ::PMSessionEndPageNoDialog(mPrintSession);
if (status != noErr) {
return NS_ERROR_ABORT;
}
return PrintTarget::EndPage();
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
} // namespace gfx

Просмотреть файл

@ -24,8 +24,12 @@ public:
int32_t aStartPage,
int32_t aEndPage) override;
NS_IMETHOD EndDocument() override;
NS_IMETHOD BeginPage() override;
NS_IMETHOD EndPage() override;
NS_IMETHOD BeginPage() override {
return NS_OK;
};
NS_IMETHOD EndPage() override {
return NS_OK;
};
void GetPaperRect(double* aTop, double* aLeft, double* aBottom, double* aRight);

Просмотреть файл

@ -76,16 +76,6 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle,
}
}
OSStatus status;
status = ::PMSetFirstPage(mPrintSettings, aStartPage, false);
NS_ASSERTION(status == noErr, "PMSetFirstPage failed");
status = ::PMSetLastPage(mPrintSettings, aEndPage, false);
NS_ASSERTION(status == noErr, "PMSetLastPage failed");
status = ::PMSessionBeginCGDocumentNoDialog(mPrintSession, mPrintSettings, mPageFormat);
if (status != noErr)
return NS_ERROR_ABORT;
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
@ -93,35 +83,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle,
NS_IMETHODIMP nsDeviceContextSpecX::EndDocument()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
::PMSessionEndDocumentNoDialog(mPrintSession);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsDeviceContextSpecX::BeginPage()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
PMSessionError(mPrintSession);
OSStatus status = ::PMSessionBeginPageNoDialog(mPrintSession, mPageFormat, NULL);
if (status != noErr) return NS_ERROR_ABORT;
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsDeviceContextSpecX::EndPage()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
OSStatus status = ::PMSessionEndPageNoDialog(mPrintSession);
if (status != noErr) return NS_ERROR_ABORT;
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
return NS_OK;
}
void nsDeviceContextSpecX::GetPaperRect(double* aTop, double* aLeft, double* aBottom, double* aRight)
@ -145,5 +107,6 @@ already_AddRefed<PrintTarget> nsDeviceContextSpecX::MakePrintTarget()
const double height = bottom - top;
IntSize size = IntSize::Floor(width, height);
return PrintTargetCG::CreateOrNull(mPrintSession, size);
return PrintTargetCG::CreateOrNull(mPrintSession, mPageFormat,
mPrintSettings, size);
}