Bug 1721265 Part 2 - Send information about CSS page-size values to the print frontend through FinishPrintPreview r=emilio

This adds an optional paper orientation to PrintPreviewResultInfo populates it
from the CSS page size when finishing print preview. The value is then placed
in the PrintPreviewSuccessInfo to be sent to the frontend.

Differential Revision: https://phabricator.services.mozilla.com/D124248
This commit is contained in:
Emily McDonough 2021-09-21 16:38:53 +00:00
parent 4294039c89
commit 4f6abc1d13
5 changed files with 40 additions and 5 deletions

View File

@ -3355,6 +3355,7 @@ already_AddRefed<Promise> nsFrameLoader::PrintPreview(
return promise.forget();
#else
auto resolve = [promise](PrintPreviewResultInfo aInfo) {
using Orientation = dom::PrintPreviewOrientation;
if (aInfo.sheetCount() > 0) {
PrintPreviewSuccessInfo info;
info.mSheetCount = aInfo.sheetCount();
@ -3362,6 +3363,13 @@ already_AddRefed<Promise> nsFrameLoader::PrintPreview(
info.mHasSelection = aInfo.hasSelection();
info.mHasSelfSelection = aInfo.hasSelfSelection();
info.mIsEmpty = aInfo.isEmpty();
if (aInfo.printLandscape()) {
info.mOrientation = aInfo.printLandscape().value()
? Orientation::Landscape
: Orientation::Portrait;
} else {
MOZ_ASSERT(info.mOrientation == Orientation::Unspecified);
}
promise->MaybeResolve(info);
} else {
promise->MaybeRejectWithUnknownError("Print preview failed");

View File

@ -203,6 +203,12 @@ interface mixin WebBrowserPersistable
nsIWebBrowserPersistDocumentReceiver aRecv);
};
enum PrintPreviewOrientation {
"landscape",
"portrait",
"unspecified"
};
/**
* Interface for the object that's used to resolve the Promise returned from
* FrameLoader.printPreview() if that method successfully creates the print
@ -238,6 +244,11 @@ dictionary PrintPreviewSuccessInfo {
* Whether the previewed document has a selection itself.
*/
boolean hasSelfSelection = false;
/**
* Specified orientation of the document, or "unspecified".
*/
PrintPreviewOrientation orientation = "unspecified";
};
FrameLoader includes WebBrowserPersistable;

View File

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

View File

@ -168,6 +168,9 @@ struct PrintPreviewResultInfo
bool hasSelection;
// Whether there's a selection in the previewed page, excluding its subframes.
bool hasSelfSelection;
// If present, indicates if the page should be printed landscape when true or
// portrait when false;
bool? printLandscape;
};
/**

View File

@ -23,6 +23,8 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/PresShell.h"
#include "mozilla/PresShellInlines.h"
#include "mozilla/StaticPrefs_print.h"
#include "mozilla/Telemetry.h"
#include "nsIBrowserChild.h"
@ -872,8 +874,9 @@ nsresult nsPrintJob::PrintPreview(Document* aSourceDoc,
CommonPrint(true, aPrintSettings, aWebProgressListener, aSourceDoc);
if (NS_FAILED(rv)) {
if (mPrintPreviewCallback) {
// signal error
mPrintPreviewCallback(
PrintPreviewResultInfo(0, 0, false, false, false)); // signal error
PrintPreviewResultInfo(0, 0, false, false, false, {}));
mPrintPreviewCallback = nullptr;
}
}
@ -1088,8 +1091,9 @@ nsresult nsPrintJob::CleanupOnFailure(nsresult aResult, bool aIsPrinting) {
//---------------------------------------------------------------------
void nsPrintJob::FirePrintingErrorEvent(nsresult aPrintError) {
if (mPrintPreviewCallback) {
// signal error
mPrintPreviewCallback(
PrintPreviewResultInfo(0, 0, false, false, false)); // signal error
PrintPreviewResultInfo(0, 0, false, false, false, {}));
mPrintPreviewCallback = nullptr;
}
@ -2629,9 +2633,18 @@ nsresult nsPrintJob::FinishPrintPreview() {
if (mPrintPreviewCallback) {
const bool hasSelection =
!mDisallowSelectionPrint && printData->mSelectionRoot;
// Determine if there is a specified page size, and if we should set the
// paper orientation to match it.
const Maybe<bool> maybeLandscape =
printData->mPrintObject->mPresShell->StyleSet()
->GetDefaultPageOrientation()
.map([](StyleOrientation o) -> bool {
return o == StyleOrientation::Landscape;
});
mPrintPreviewCallback(PrintPreviewResultInfo(
GetPrintPreviewNumSheets(), GetRawNumPages(), GetIsEmpty(),
hasSelection, hasSelection && printData->mPrintObject->HasSelection()));
hasSelection, hasSelection && printData->mPrintObject->HasSelection(),
maybeLandscape));
mPrintPreviewCallback = nullptr;
}