mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1704178. Remove platform print.tab_modal.enabled=false code. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D136736
This commit is contained in:
parent
b564f8c7b1
commit
dff729bc6d
@ -5201,12 +5201,6 @@ void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool print_tab_modal_enabled = true;
|
||||
if (!print_tab_modal_enabled && ShouldPromptToBlockDialogs() &&
|
||||
!ConfirmDialogIfNeeded()) {
|
||||
return aError.ThrowNotAllowedError("Prompt was canceled by the user");
|
||||
}
|
||||
|
||||
// If we're loading, queue the print for later. This is a special-case that
|
||||
// only applies to the window.print() call, for compat with other engines and
|
||||
// pre-existing behavior.
|
||||
@ -5233,9 +5227,8 @@ void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) {
|
||||
}
|
||||
});
|
||||
|
||||
const bool isPreview =
|
||||
print_tab_modal_enabled && !StaticPrefs::print_always_print_silent();
|
||||
Print(nullptr, nullptr, nullptr, IsPreview(isPreview),
|
||||
const bool forPreview = !StaticPrefs::print_always_print_silent();
|
||||
Print(nullptr, nullptr, nullptr, IsPreview(forPreview),
|
||||
IsForWindowDotPrint::Yes, nullptr, aError);
|
||||
#endif
|
||||
}
|
||||
@ -5293,9 +5286,7 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
RefPtr<BrowsingContext> bc;
|
||||
bool hasPrintCallbacks = false;
|
||||
bool print_tab_modal_enabled = true;
|
||||
if (docToPrint->IsStaticDocument() &&
|
||||
(aIsPreview == IsPreview::Yes || print_tab_modal_enabled)) {
|
||||
if (docToPrint->IsStaticDocument()) {
|
||||
if (aForWindowDotPrint == IsForWindowDotPrint::Yes) {
|
||||
aError.ThrowNotSupportedError(
|
||||
"Calling print() from a print preview is unsupported, did you intend "
|
||||
|
@ -398,8 +398,6 @@ class nsDocumentViewer final : public nsIContentViewer,
|
||||
// child widgets.
|
||||
bool ShouldAttachToTopLevel();
|
||||
|
||||
nsresult PrintPreviewScrollToPageForOldUI(int16_t aType, int32_t aPageNum);
|
||||
|
||||
std::tuple<const nsIFrame*, int32_t> GetCurrentSheetFrameAndNumber() const;
|
||||
|
||||
protected:
|
||||
@ -2965,10 +2963,6 @@ nsDocumentViewer::PrintPreview(nsIPrintSettings* aPrintSettings,
|
||||
NS_ENSURE_STATE(mContainer);
|
||||
NS_ENSURE_STATE(mDeviceContext);
|
||||
|
||||
// Our call to nsPrintJob::PrintPreview() may cause mPrintJob to be
|
||||
// Release()'d in Destroy(). Therefore, we need to grab the instance with
|
||||
// a local variable, so that it won't be deleted during its own method.
|
||||
const bool hadPrintJob = !!mPrintJob;
|
||||
OnDonePrinting();
|
||||
|
||||
RefPtr<nsPrintJob> printJob = new nsPrintJob();
|
||||
@ -2983,10 +2977,6 @@ nsDocumentViewer::PrintPreview(nsIPrintSettings* aPrintSettings,
|
||||
}
|
||||
mPrintJob = printJob;
|
||||
|
||||
bool print_tab_modal_enabled = true;
|
||||
if (!hadPrintJob && !print_tab_modal_enabled) {
|
||||
Telemetry::ScalarAdd(Telemetry::ScalarID::PRINTING_PREVIEW_OPENED, 1);
|
||||
}
|
||||
rv = printJob->PrintPreview(doc, aPrintSettings, aWebProgressListener,
|
||||
std::move(aCallback));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
@ -2998,90 +2988,6 @@ nsDocumentViewer::PrintPreview(nsIPrintSettings* aPrintSettings,
|
||||
# endif // NS_PRINT_PREVIEW
|
||||
}
|
||||
|
||||
nsresult nsDocumentViewer::PrintPreviewScrollToPageForOldUI(int16_t aType,
|
||||
int32_t aPageNum) {
|
||||
MOZ_ASSERT(GetIsPrintPreview() && !mPrintJob->GetIsCreatingPrintPreview());
|
||||
|
||||
nsIScrollableFrame* sf =
|
||||
mPrintJob->GetPrintPreviewPresShell()->GetRootScrollFrameAsScrollable();
|
||||
if (!sf) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Check to see if we can short circut scrolling to the top
|
||||
if (aType == nsIWebBrowserPrint::PRINTPREVIEW_HOME ||
|
||||
(aType == nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM &&
|
||||
aPageNum == 1)) {
|
||||
sf->ScrollTo(nsPoint(0, 0), ScrollMode::Instant);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// in PP mPrtPreview->mPrintObject->mSeqFrame is null
|
||||
auto [seqFrame, sheetCount] = mPrintJob->GetSeqFrameAndCountSheets();
|
||||
if (!seqFrame) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Figure where we are currently scrolled to
|
||||
nsPoint currentScrollPosition = sf->GetScrollPosition();
|
||||
|
||||
int32_t pageNum = 1;
|
||||
nsIFrame* fndPageFrame = nullptr;
|
||||
nsIFrame* currentPage = nullptr;
|
||||
|
||||
// If it is "End" then just do a "goto" to the last page
|
||||
if (aType == nsIWebBrowserPrint::PRINTPREVIEW_END) {
|
||||
aType = nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM;
|
||||
aPageNum = sheetCount;
|
||||
}
|
||||
|
||||
// Now, locate the current page we are on and
|
||||
// and the page of the page number
|
||||
for (nsIFrame* sheetFrame : seqFrame->PrincipalChildList()) {
|
||||
nsRect sheetRect = sheetFrame->GetRect();
|
||||
if (sheetRect.Contains(sheetRect.x, currentScrollPosition.y)) {
|
||||
currentPage = sheetFrame;
|
||||
}
|
||||
if (pageNum == aPageNum) {
|
||||
fndPageFrame = sheetFrame;
|
||||
break;
|
||||
}
|
||||
pageNum++;
|
||||
}
|
||||
|
||||
if (aType == nsIWebBrowserPrint::PRINTPREVIEW_PREV_PAGE) {
|
||||
if (currentPage) {
|
||||
fndPageFrame = currentPage->GetPrevInFlow();
|
||||
if (!fndPageFrame) {
|
||||
return NS_OK;
|
||||
}
|
||||
} else {
|
||||
return NS_OK;
|
||||
}
|
||||
} else if (aType == nsIWebBrowserPrint::PRINTPREVIEW_NEXT_PAGE) {
|
||||
if (currentPage) {
|
||||
fndPageFrame = currentPage->GetNextInFlow();
|
||||
if (!fndPageFrame) {
|
||||
return NS_OK;
|
||||
}
|
||||
} else {
|
||||
return NS_OK;
|
||||
}
|
||||
} else { // If we get here we are doing "GoTo"
|
||||
if (aPageNum < 0 || aPageNum > sheetCount) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (fndPageFrame) {
|
||||
nscoord newYPosn = nscoord(seqFrame->GetPrintPreviewScale() *
|
||||
fndPageFrame->GetPosition().y);
|
||||
sf->ScrollTo(nsPoint(currentScrollPosition.x, newYPosn),
|
||||
ScrollMode::Instant);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static const nsIFrame* GetTargetPageFrame(int32_t aTargetPageNum,
|
||||
nsPageSequenceFrame* aSequenceFrame) {
|
||||
MOZ_ASSERT(aTargetPageNum > 0 &&
|
||||
@ -3111,11 +3017,6 @@ nsDocumentViewer::PrintPreviewScrollToPage(int16_t aType, int32_t aPageNum) {
|
||||
if (!GetIsPrintPreview() || mPrintJob->GetIsCreatingPrintPreview())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
bool print_tab_modal_enabled = true;
|
||||
if (!print_tab_modal_enabled) {
|
||||
return PrintPreviewScrollToPageForOldUI(aType, aPageNum);
|
||||
}
|
||||
|
||||
nsIScrollableFrame* sf =
|
||||
mPrintJob->GetPrintPreviewPresShell()->GetRootScrollFrameAsScrollable();
|
||||
if (!sf) return NS_OK;
|
||||
@ -3317,11 +3218,6 @@ nsDocumentViewer::ExitPrintPreview() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool print_tab_modal_enabled = true;
|
||||
if (!mPrintJob->HasEverPrinted() && !print_tab_modal_enabled) {
|
||||
Telemetry::ScalarAdd(Telemetry::ScalarID::PRINTING_PREVIEW_CANCELLED, 1);
|
||||
}
|
||||
|
||||
# ifdef NS_PRINT_PREVIEW
|
||||
mPrintJob->Destroy();
|
||||
mPrintJob = nullptr;
|
||||
|
@ -577,7 +577,6 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
|
||||
// need to be cleared from the settings at the end of the job.
|
||||
// XXX What lifetime does the printSession need to have?
|
||||
nsCOMPtr<nsIPrintSession> printSession;
|
||||
bool remotePrintJobListening = false;
|
||||
if (!mIsCreatingPrintPreview) {
|
||||
rv = printData->mPrintSettings->GetPrintSession(
|
||||
getter_AddRefs(printSession));
|
||||
@ -592,7 +591,6 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
|
||||
// If we have a RemotePrintJob add it to the print progress listeners,
|
||||
// so it can forward to the parent.
|
||||
printData->mPrintProgressListeners.AppendElement(remotePrintJob);
|
||||
remotePrintJobListening = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -621,112 +619,6 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
|
||||
Telemetry::ScalarAdd(Telemetry::ScalarID::PRINTING_SILENT_PRINT, 1);
|
||||
}
|
||||
|
||||
// If printing via parent we still call ShowPrintDialog even for print preview
|
||||
// because we use that to retrieve the print settings from the printer.
|
||||
// The dialog is not shown, but this means we don't need to access the printer
|
||||
// driver from the child, which causes sandboxing issues.
|
||||
if (!mIsCreatingPrintPreview || printingViaParent) {
|
||||
// Ask dialog to be Print Shown via the Plugable Printing Dialog Service
|
||||
// This service is for the Print Dialog and the Print Progress Dialog
|
||||
// If printing silently or you can't get the service continue on
|
||||
// If printing via the parent then we need to confirm that the pref is set
|
||||
// and get a remote print job, but the parent won't display a prompt.
|
||||
// Note: The new print UI does not need to enter ShowPrintDialog below to
|
||||
// spin the event loop and fetch real printer settings from the parent.
|
||||
bool print_tab_modal_enabled = true;
|
||||
if (!print_tab_modal_enabled && (!printSilently || printingViaParent)) {
|
||||
nsCOMPtr<nsIPrintingPromptService> printPromptService(
|
||||
do_GetService(kPrintingPromptService));
|
||||
if (printPromptService) {
|
||||
nsPIDOMWindowOuter* domWin = nullptr;
|
||||
// We leave domWin as nullptr to indicate a call for print preview.
|
||||
if (!mIsCreatingPrintPreview) {
|
||||
domWin = aDoc->GetOriginalDocument()->GetWindow();
|
||||
NS_ENSURE_TRUE(domWin, NS_ERROR_FAILURE);
|
||||
|
||||
if (!printSilently) {
|
||||
if (mCreatedForPrintPreview) {
|
||||
Telemetry::ScalarAdd(
|
||||
Telemetry::ScalarID::PRINTING_DIALOG_OPENED_VIA_PREVIEW, 1);
|
||||
} else {
|
||||
Telemetry::ScalarAdd(
|
||||
Telemetry::ScalarID::PRINTING_DIALOG_OPENED_WITHOUT_PREVIEW,
|
||||
1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Platforms not implementing a given dialog for the service may
|
||||
// return NS_ERROR_NOT_IMPLEMENTED or an error code.
|
||||
//
|
||||
// NS_ERROR_NOT_IMPLEMENTED indicates they want default behavior
|
||||
// Any other error code means we must bail out
|
||||
//
|
||||
rv = printPromptService->ShowPrintDialog(domWin,
|
||||
printData->mPrintSettings);
|
||||
|
||||
if (!mIsCreatingPrintPreview) {
|
||||
if (rv == NS_ERROR_ABORT) {
|
||||
// When printing silently we can't get here since the user doesn't
|
||||
// have the opportunity to cancel printing.
|
||||
if (mCreatedForPrintPreview) {
|
||||
Telemetry::ScalarAdd(
|
||||
Telemetry::ScalarID::PRINTING_DIALOG_VIA_PREVIEW_CANCELLED,
|
||||
1);
|
||||
} else {
|
||||
Telemetry::ScalarAdd(
|
||||
Telemetry::ScalarID::
|
||||
PRINTING_DIALOG_WITHOUT_PREVIEW_CANCELLED,
|
||||
1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ShowPrintDialog triggers an event loop which means we can't assume
|
||||
// that the state of this->{anything} matches the state we've checked
|
||||
// above. Including that a given {thing} is non null.
|
||||
if (NS_WARN_IF(mPrt != printData)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// since we got the dialog and it worked then make sure we
|
||||
// are telling GFX we want to print silent
|
||||
printSilently = true;
|
||||
|
||||
if (printData->mPrintSettings && !mIsCreatingPrintPreview) {
|
||||
// The user might have changed shrink-to-fit in the print dialog, so
|
||||
// update our copy of its state
|
||||
printData->mPrintSettings->GetShrinkToFit(&printData->mShrinkToFit);
|
||||
|
||||
// If we haven't already added the RemotePrintJob as a listener,
|
||||
// add it now if there is one.
|
||||
if (!remotePrintJobListening) {
|
||||
RefPtr<layout::RemotePrintJobChild> remotePrintJob =
|
||||
printSession->GetRemotePrintJob();
|
||||
if (remotePrintJob) {
|
||||
printData->mPrintProgressListeners.AppendElement(
|
||||
remotePrintJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (rv == NS_ERROR_NOT_IMPLEMENTED) {
|
||||
// This means the Dialog service was there,
|
||||
// but they choose not to implement this dialog and
|
||||
// are looking for default behavior from the toolkit
|
||||
rv = NS_OK;
|
||||
}
|
||||
} else {
|
||||
// No dialog service available
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
// Check explicitly for abort because it's expected
|
||||
if (rv == NS_ERROR_ABORT) return rv;
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
MOZ_TRY(devspec->Init(nullptr, printData->mPrintSettings,
|
||||
mIsCreatingPrintPreview));
|
||||
|
||||
@ -739,14 +631,6 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
|
||||
[self](nsresult aResult) { self->PageDone(aResult); });
|
||||
}
|
||||
|
||||
bool print_tab_modal_enabled = true;
|
||||
if (!print_tab_modal_enabled && mIsCreatingPrintPreview) {
|
||||
// In legacy print-preview mode, override any UI that wants to PrintPreview
|
||||
// any selection or page range. The legacy print-preview intends to view
|
||||
// every page in PrintPreview each time.
|
||||
printData->mPrintSettings->SetPageRanges({});
|
||||
}
|
||||
|
||||
MOZ_TRY(EnablePOsForPrinting());
|
||||
|
||||
if (!mIsCreatingPrintPreview) {
|
||||
|
Loading…
Reference in New Issue
Block a user