Bug 1679706 - Communicate to the front-end whether there are no visible pages at all. r=jfkthame

This will allow them to react however they want to empty page ranges as
a result of another setting change.

Differential Revision: https://phabricator.services.mozilla.com/D98183
This commit is contained in:
Emilio Cobos Álvarez 2020-12-02 21:48:03 +00:00
Родитель 075593c873
Коммит a49800a500
10 изменённых файлов: 42 добавлений и 4 удалений

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

@ -3237,6 +3237,7 @@ already_AddRefed<Promise> nsFrameLoader::PrintPreview(
info.mSheetCount = aInfo.sheetCount();
info.mTotalPageCount = aInfo.totalPageCount();
info.mHasSelection = aInfo.hasSelection();
info.mIsEmpty = aInfo.isEmpty();
promise->MaybeResolve(info);
} else {
promise->MaybeRejectWithUnknownError("Print preview failed");

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

@ -248,6 +248,11 @@ dictionary PrintPreviewSuccessInfo {
*/
unsigned long totalPageCount = 0;
/**
* Whether the preview is empty because of page range selection.
*/
boolean isEmpty = false;
/**
* Whether the document has a selection that can be printed.
*/

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

@ -2324,7 +2324,7 @@ mozilla::ipc::IPCResult BrowserChild::RecvPrintPreview(
// went wrong.
auto sendCallbackError = MakeScopeExit([&] {
if (aCallback) {
aCallback(PrintPreviewResultInfo(0, 0, false)); // signal error
aCallback(PrintPreviewResultInfo(0, 0, false, false)); // signal error
}
});

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

@ -166,6 +166,7 @@ struct PrintPreviewResultInfo
{
uint32_t sheetCount;
uint32_t totalPageCount;
bool isEmpty;
bool hasSelection;
};

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

@ -244,6 +244,7 @@ void PrintedSheetFrame::Reflow(nsPresContext* aPresContext,
MOZ_ASSERT(numPagesOnThisSheet <= desiredPagesPerSheet,
"Shouldn't have more than desired number of displayable pages "
"on this sheet");
mNumPages = numPagesOnThisSheet;
// Populate our ReflowOutput outparam -- just use up all the
// available space, for both our desired size & overflow areas.

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

@ -41,6 +41,8 @@ class PrintedSheetFrame final : public nsContainerFrame {
nsresult GetFrameName(nsAString& aResult) const override;
#endif
uint32_t GetNumPages() const { return mNumPages; }
private:
// Private construtor & destructor, to avoid accidental (non-FrameArena)
// instantiation/deletion:
@ -51,6 +53,8 @@ class PrintedSheetFrame final : public nsContainerFrame {
// Note: this will be set before reflow, and it's strongly owned by our
// nsPageSequenceFrame, which outlives us.
nsSharedPageData* mPD = nullptr;
// The number of visible pages in this sheet.
uint32_t mNumPages = 0;
};
} // namespace mozilla

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

@ -232,6 +232,16 @@ nscoord nsPageSequenceFrame::ComputeCenteringMargin(
return NSToCoordRound(scaledExtraSpace * 0.5 / scale);
}
uint32_t nsPageSequenceFrame::GetPagesInFirstSheet() const {
nsIFrame* firstSheet = mFrames.FirstChild();
if (!firstSheet) {
return 0;
}
MOZ_DIAGNOSTIC_ASSERT(firstSheet->IsPrintedSheetFrame());
return static_cast<PrintedSheetFrame*>(firstSheet)->GetNumPages();
}
/*
* Note: we largely position/size out our children (page frames) using
* \*physical\* x/y/width/height values, because the print preview UI is always

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

@ -133,6 +133,8 @@ class nsPageSequenceFrame final : public nsContainerFrame {
int32_t GetRawNumPages() const { return mPageData->mRawNumPages; }
uint32_t GetPagesInFirstSheet() const;
nsresult DoPageEnd();
// We must allow Print Preview UI to have a background, no matter what the

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

@ -862,7 +862,7 @@ nsresult nsPrintJob::PrintPreview(Document* aSourceDoc,
if (NS_FAILED(rv)) {
if (mPrintPreviewCallback) {
mPrintPreviewCallback(
PrintPreviewResultInfo(0, 0, false)); // signal error
PrintPreviewResultInfo(0, 0, false, false)); // signal error
mPrintPreviewCallback = nullptr;
}
}
@ -875,6 +875,17 @@ int32_t nsPrintJob::GetRawNumPages() const {
return seqFrame ? seqFrame->GetRawNumPages() : 0;
}
bool nsPrintJob::GetIsEmpty() const {
auto [seqFrame, numSheets] = GetSeqFrameAndCountSheets();
if (!seqFrame) {
return true;
}
if (numSheets > 1) {
return false;
}
return seqFrame->GetPagesInFirstSheet() > 0;
}
int32_t nsPrintJob::GetPrintPreviewNumSheets() const {
auto [seqFrame, numSheets] = GetSeqFrameAndCountSheets();
Unused << seqFrame;
@ -1066,7 +1077,8 @@ nsresult nsPrintJob::CleanupOnFailure(nsresult aResult, bool aIsPrinting) {
//---------------------------------------------------------------------
void nsPrintJob::FirePrintingErrorEvent(nsresult aPrintError) {
if (mPrintPreviewCallback) {
mPrintPreviewCallback(PrintPreviewResultInfo(0, 0, false)); // signal error
mPrintPreviewCallback(
PrintPreviewResultInfo(0, 0, false, false)); // signal error
mPrintPreviewCallback = nullptr;
}
@ -2589,7 +2601,7 @@ nsresult nsPrintJob::FinishPrintPreview() {
if (mPrintPreviewCallback) {
mPrintPreviewCallback(PrintPreviewResultInfo(
GetPrintPreviewNumSheets(), GetRawNumPages(),
GetPrintPreviewNumSheets(), GetRawNumPages(), GetIsEmpty(),
!mDisallowSelectionPrint && printData->mSelectionRoot));
mPrintPreviewCallback = nullptr;
}

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

@ -127,6 +127,8 @@ class nsPrintJob final : public nsIObserver,
bool HasEverPrinted() const { return mHasEverPrinted; }
/// If the returned value is not greater than zero, an error occurred.
int32_t GetRawNumPages() const;
// Returns whether the preview is empty due to page range exclusion.
bool GetIsEmpty() const;
// Returns the total number of PrintedSheetFrames (i.e. faces of a sheet of
// paper) for this print job. (This may be less than the raw number of pages,