mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
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:
parent
075593c873
commit
a49800a500
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user