Bug 1552785. Remove internal code for various frameset printing behaviors. r=bobowen

Differential Revision: https://phabricator.services.mozilla.com/D33624

--HG--
extra : rebase_source : 336e87a05970895684602c9db3e5222918f861c8
extra : source : 98fbf1ed617549496036099b5aee333aa6b29925
This commit is contained in:
Jonathan Watt 2019-05-21 16:01:34 +01:00
parent 83558018e6
commit 098392f093
15 changed files with 21 additions and 206 deletions

View File

@ -1163,7 +1163,6 @@ this.tabs = class extends ExtensionAPI {
printSettings.printSilent = true;
printSettings.showPrintProgress = false;
printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs;
printSettings.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF;
if (pageSettings.paperSizeUnit !== null) {

View File

@ -35,7 +35,6 @@ nsPrintData::nsPrintData(ePrintDataType aType)
mPreparingForPrint(false),
mDocWasToBeDestroyed(false),
mShrinkToFit(false),
mPrintFrameType(nsIPrintSettings::kFramesAsIs),
mNumPrintablePages(0),
mNumPagesPrinted(0),
mShrinkRatio(1.0) {

View File

@ -81,7 +81,6 @@ class nsPrintData {
bool mPreparingForPrint; // see comments above
bool mDocWasToBeDestroyed; // see comments above
bool mShrinkToFit;
int16_t mPrintFrameType;
int32_t mNumPrintablePages;
int32_t mNumPagesPrinted;
float mShrinkRatio;

View File

@ -149,10 +149,6 @@ static uint32_t gDumpLOFileNameCnt = 0;
#define PRT_YESNO(_p) ((_p) ? "YES" : "NO")
static const char* gFrameTypesStr[] = {"eDoc", "eFrame", "eIFrame",
"eFrameSet"};
static const char* gPrintFrameTypeStr[] = {"kNoFrames", "kFramesAsIs",
"kSelectedFrame", "kEachFrameSep"};
static const char* gFrameHowToEnableStr[] = {
"kFrameEnableNone", "kFrameEnableAll", "kFrameEnableAsIsAndEach"};
static const char* gPrintRangeStr[] = {
"kRangeAllPages", "kRangeSpecifiedPageRange", "kRangeSelection"};
@ -850,19 +846,6 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
printData->mIsIFrameSelected = IsThereAnIFrameSelected(
docShell, printData->mCurrentFocusWin, printData->mIsParentAFrameSet);
// Setup print options for UI
if (printData->mIsParentAFrameSet) {
if (printData->mCurrentFocusWin) {
printData->mPrintSettings->SetHowToEnableFrameUI(
nsIPrintSettings::kFrameEnableAll);
} else {
printData->mPrintSettings->SetHowToEnableFrameUI(
nsIPrintSettings::kFrameEnableAsIsAndEach);
}
} else {
printData->mPrintSettings->SetHowToEnableFrameUI(
nsIPrintSettings::kFrameEnableNone);
}
// Now determine how to set up the Frame print UI
printData->mPrintSettings->SetPrintOptions(
nsIPrintSettings::kEnableSelectionRB,
@ -980,17 +963,9 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
}
if (aIsPrintPreview) {
printData->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
// override any UI that wants to PrintPreview any selection or page range
// we want to view every page in PrintPreview each time
printData->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
} else {
printData->mPrintSettings->GetPrintFrameType(&printData->mPrintFrameType);
}
if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {
CheckForChildFrameSets(printData->mPrintObject);
}
if (NS_FAILED(EnablePOsForPrinting())) {
@ -1315,37 +1290,6 @@ void nsPrintJob::BuildDocTree(nsIDocShell* aParentNode,
}
}
//-------------------------------------------------------
// A Frame's sub-doc may contain content or a FrameSet
// When it contains a FrameSet the mFrameType for the PrintObject
// is always set to an eFrame. Which is fine when printing "AsIs"
// but is incorrect when when printing "Each Frame Separately".
// When printing "Each Frame Separately" the Frame really acts like
// a frameset.
//
// This method walks the PO tree and checks to see if the PrintObject is
// an eFrame and has children that are eFrames (meaning it's a Frame containing
// a FrameSet) If so, then the mFrameType need to be changed to eFrameSet
//
// Also note: We only want to call this we are printing "Each Frame Separately"
// when printing "As Is" leave it as an eFrame
void nsPrintJob::CheckForChildFrameSets(const UniquePtr<nsPrintObject>& aPO) {
NS_ASSERTION(aPO, "Pointer is null!");
// Continue recursively walking the chilren of this PO
bool hasChildFrames = false;
for (const UniquePtr<nsPrintObject>& po : aPO->mKids) {
if (po->mFrameType == eFrame) {
hasChildFrames = true;
CheckForChildFrameSets(po);
}
}
if (hasChildFrames && aPO->mFrameType == eFrame) {
aPO->mFrameType = eFrameSet;
}
}
//---------------------------------------------------------------------
bool nsPrintJob::IsThereAnIFrameSelected(nsIDocShell* aDocShell,
nsPIDOMWindowOuter* aDOMWin,
@ -1438,19 +1382,7 @@ void nsPrintJob::GetDisplayTitleAndURL(const UniquePtr<nsPrintObject>& aPO,
//---------------------------------------------------------------------
nsresult nsPrintJob::DocumentReadyForPrinting() {
int16_t printRangeType = nsIPrintSettings::kRangeAllPages;
mPrt->mPrintSettings->GetPrintRange(&printRangeType);
if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep &&
printRangeType != nsIPrintSettings::kRangeSelection) {
// Guarantee that mPrt->mPrintObject won't be deleted during a call of
// CheckForChildFrameSets().
RefPtr<nsPrintData> printData = mPrt;
CheckForChildFrameSets(printData->mPrintObject);
}
//
// Send the document to the printer...
//
nsresult rv = SetupToPrintContent();
if (NS_FAILED(rv)) {
// The print job was canceled or there was a problem
@ -2002,9 +1934,7 @@ void nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale) {
mPrt->mPrintSettings->GetPrintRange(&printRangeType);
float ratio;
if ((mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs ||
mPrt->mPrintFrameType == nsIPrintSettings::kNoFrames) &&
printRangeType != nsIPrintSettings::kRangeSelection) {
if (printRangeType != nsIPrintSettings::kRangeSelection) {
ratio = mPrt->mShrinkRatio - 0.005f; // round down
} else {
ratio = aPO->mShrinkRatio - 0.005f; // round down
@ -2684,15 +2614,6 @@ bool nsPrintJob::PrintPage(nsPrintObject* aPO, bool& aInRange) {
aInRange = true;
}
// XXX This is wrong, but the actual behavior in the presence of a print
// range sucks.
int16_t printRangeType = nsIPrintSettings::kRangeAllPages;
printData->mPrintSettings->GetPrintRange(&printRangeType);
if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep &&
printRangeType != nsIPrintSettings::kRangeSelection) {
endPage = printData->mNumPrintablePages;
}
printData->DoOnProgressChange(++printData->mNumPagesPrinted, endPage, false,
0);
if (NS_WARN_IF(mPrt != printData)) {
@ -2894,20 +2815,11 @@ nsresult nsPrintJob::EnablePOsForPrinting() {
return NS_ERROR_FAILURE;
}
printData->mPrintFrameType = nsIPrintSettings::kNoFrames;
printData->mPrintSettings->GetPrintFrameType(&printData->mPrintFrameType);
int16_t printHowEnable = nsIPrintSettings::kFrameEnableNone;
printData->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable);
int16_t printRangeType = nsIPrintSettings::kRangeAllPages;
printData->mPrintSettings->GetPrintRange(&printRangeType);
PR_PL(("\n"));
PR_PL(("********* nsPrintJob::EnablePOsForPrinting *********\n"));
PR_PL(("PrintFrameType: %s \n",
gPrintFrameTypeStr[printData->mPrintFrameType]));
PR_PL(("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]));
PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType]));
PR_PL(("----\n"));
@ -2927,13 +2839,7 @@ nsresult nsPrintJob::EnablePOsForPrinting() {
NS_ASSERTION(po, "nsPrintObject can't be null!");
SetPrintAsIs(po.get());
}
// ***** Another override *****
printData->mPrintFrameType = nsIPrintSettings::kFramesAsIs;
}
PR_PL(("PrintFrameType: %s \n",
gPrintFrameTypeStr[printData->mPrintFrameType]));
PR_PL(("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]));
PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType]));
return NS_OK;
}
@ -2966,10 +2872,6 @@ nsresult nsPrintJob::EnablePOsForPrinting() {
printRangeType = nsIPrintSettings::kRangeAllPages;
printData->mPrintSettings->SetPrintRange(printRangeType);
}
PR_PL(("PrintFrameType: %s \n",
gPrintFrameTypeStr[printData->mPrintFrameType]));
PR_PL(("HowToEnableFrameUI: %s \n",
gFrameHowToEnableStr[printHowEnable]));
PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType]));
return NS_OK;
}
@ -2988,51 +2890,27 @@ nsresult nsPrintJob::EnablePOsForPrinting() {
}
}
// If we are printing "AsIs" then sets all the POs to be printed as is
if (printData->mPrintFrameType == nsIPrintSettings::kFramesAsIs &&
printRangeType != nsIPrintSettings::kRangeSelection) {
if (printRangeType != nsIPrintSettings::kRangeSelection) {
SetPrintAsIs(printData->mPrintObject.get());
SetPrintPO(printData->mPrintObject.get(), true);
return NS_OK;
}
// If we are printing the selected Frame then
// find that PO for that selected DOMWin and set it all of its
// children to be printed
if (printData->mPrintFrameType == nsIPrintSettings::kSelectedFrame ||
printRangeType == nsIPrintSettings::kRangeSelection) {
if ((printData->mIsParentAFrameSet && printData->mCurrentFocusWin) ||
printData->mIsIFrameSelected) {
nsPrintObject* po = FindPrintObjectByDOMWin(printData->mPrintObject.get(),
printData->mCurrentFocusWin);
if (po) {
// NOTE: Calling this sets the "po" and
// we don't want to do this for documents that have no children,
// because then the "DoEndPage" gets called and it shouldn't
if (po->mKids.Length() > 0) {
// Makes sure that itself, and all of its children are printed "AsIs"
SetPrintAsIs(po);
}
// Now, only enable this POs (the selected PO) and all of its children
SetPrintPO(po, true);
if ((printData->mIsParentAFrameSet && printData->mCurrentFocusWin) ||
printData->mIsIFrameSelected) {
nsPrintObject* po = FindPrintObjectByDOMWin(printData->mPrintObject.get(),
printData->mCurrentFocusWin);
if (po) {
// NOTE: Calling this sets the "po" and
// we don't want to do this for documents that have no children,
// because then the "DoEndPage" gets called and it shouldn't
if (po->mKids.Length() > 0) {
// Makes sure that itself, and all of its children are printed "AsIs"
SetPrintAsIs(po);
}
}
return NS_OK;
}
// If we are print each subdoc separately,
// then don't print any of the FraneSet Docs
if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep &&
printRangeType != nsIPrintSettings::kRangeSelection) {
SetPrintPO(printData->mPrintObject.get(), true);
int32_t cnt = printData->mPrintDocList.Length();
for (int32_t i = 0; i < cnt; i++) {
nsPrintObject* po = printData->mPrintDocList.ElementAt(i);
NS_ASSERTION(po, "nsPrintObject can't be null!");
if (po->mFrameType == eFrameSet) {
po->mDontPrint = true;
}
// Now, only enable this POs (the selected PO) and all of its children
SetPrintPO(po, true);
}
}
@ -3520,9 +3398,8 @@ static void DumpPrintObjectsList(const nsTArray<nsPrintObject*>& aDocList) {
}
}
PR_PL(("%s %d %d %d %p %p %p\n", types[po->mFrameType], po->IsPrintable(),
po->mPrintAsIs, po->mHasBeenPrinted, po, po->mDocShell.get(),
rootFrame));
PR_PL(("%s %d %d %p %p %p\n", types[po->mFrameType], po->IsPrintable(),
po->mHasBeenPrinted, po, po->mDocShell.get(), rootFrame));
}
}

View File

@ -181,8 +181,6 @@ class nsPrintJob final : public nsIObserver,
MOZ_CAN_RUN_SCRIPT_BOUNDARY
nsresult ReflowPrintObject(const mozilla::UniquePtr<nsPrintObject>& aPO);
void CheckForChildFrameSets(const mozilla::UniquePtr<nsPrintObject>& aPO);
void CalcNumPrintablePages(int32_t& aNumPages);
void ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify);
nsresult CleanupOnFailure(nsresult aResult, bool aIsPrinting);

View File

@ -256,7 +256,6 @@ function printToPdf(callback) {
ps.printBGColors = true;
ps.printToFile = true;
ps.toFileName = file.path;
ps.printFrameType = Ci.nsIPrintSettings.kFramesAsIs;
ps.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF;
if (isPrintSelection) {

View File

@ -34,7 +34,6 @@ var PrintHelper = {
printSettings.printBGColors = false;
printSettings.printToFile = true;
printSettings.toFileName = file.path;
printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs;
printSettings.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF;
let webBrowserPrint = aBrowser.contentWindow.getInterface(Ci.nsIWebBrowserPrint);

View File

@ -3867,9 +3867,6 @@ pref("layout.word_select.eat_space_to_next_word", true);
// scrollbar snapping region
pref("slider.snapMultiplier", 6);
// Whether to extend the native dialog with information on printing frames.
pref("print.extend_native_print_dialog", true);
// Locate plugins by the directories specified in the Windows registry for PLIDs
// Which is currently HKLM\Software\MozillaPlugins\xxxPLIDxxx\Path
pref("plugin.scan.plid.all", true);

View File

@ -2653,7 +2653,6 @@ this.DownloadPDFSaver.prototype = {
printSettings.printBGImages = true;
printSettings.printBGColors = true;
printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs;
printSettings.headerStrCenter = "";
printSettings.headerStrLeft = "";
printSettings.headerStrRight = "";

View File

@ -42,9 +42,7 @@ struct PrintData {
nsString footerStrCenter;
nsString footerStrRight;
short howToEnableFrameUI;
bool isCancelled;
short printFrameType;
bool printSilent;
bool shrinkToFit;
bool showPrintProgress;

View File

@ -94,21 +94,6 @@ interface nsIPrintSettings : nsISupports
const short kPortraitOrientation = 0;
const short kLandscapeOrientation = 1;
/**
* Print Frame Constants
*/
const short kNoFrames = 0;
const short kFramesAsIs = 1;
const short kSelectedFrame = 2;
const short kEachFrameSep = 3;
/**
* How to Enable Frame Set Printing Constants
*/
const short kFrameEnableNone = 0;
const short kFrameEnableAll = 1;
const short kFrameEnableAsIsAndEach = 2;
/**
* Output file format
*/
@ -205,10 +190,8 @@ interface nsIPrintSettings : nsISupports
attribute AString footerStrCenter;
attribute AString footerStrRight;
attribute short howToEnableFrameUI; /* indicates how to enable the frameset UI */
attribute boolean isCancelled; /* indicates whether the print job has been cancelled */
readonly attribute boolean saveOnCancel; /* indicates whether the print settings should be saved after a cancel */
attribute short printFrameType;
attribute boolean printSilent; /* print without putting up the dialog */
attribute boolean shrinkToFit; /* shrinks content to fit on page */
attribute boolean showPrintProgress; /* indicates whether the progress dialog should be shown */

View File

@ -87,8 +87,8 @@ interface nsIPrintSettingsService : nsISupports
*
* Items not read:
* startPageRange, endPageRange, scaling, printRange, title
* docURL, howToEnableFrameUI, isCancelled,
* printFrameType, printSilent, shrinkToFit, numCopies,
* docURL, isCancelled,
* printSilent, shrinkToFit, numCopies,
* printerName
*
*/
@ -108,8 +108,8 @@ interface nsIPrintSettingsService : nsISupports
*
* Items not written:
* startPageRange, endPageRange, scaling, printRange, title
* docURL, howToEnableFrameUI, isCancelled,
* printFrameType, printSilent, shrinkToFit, numCopies
* docURL, isCancelled,
* printSilent, shrinkToFit, numCopies
*
*/
void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);

View File

@ -20,8 +20,6 @@ nsPrintSettings::nsPrintSettings()
mScaling(1.0),
mPrintBGColors(false),
mPrintBGImages(false),
mPrintFrameType(kFramesAsIs),
mHowToEnableFrameUI(kFrameEnableNone),
mIsCancelled(false),
mSaveOnCancel(true),
mPrintSilent(false),
@ -536,16 +534,6 @@ NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const nsAString& aTitle) {
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(int16_t* aPrintFrameType) {
NS_ENSURE_ARG_POINTER(aPrintFrameType);
*aPrintFrameType = (int32_t)mPrintFrameType;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(int16_t aPrintFrameType) {
mPrintFrameType = aPrintFrameType;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::GetPrintSilent(bool* aPrintSilent) {
NS_ENSURE_ARG_POINTER(aPrintSilent);
*aPrintSilent = mPrintSilent;
@ -585,18 +573,6 @@ NS_IMETHODIMP nsPrintSettings::SetPaperName(const nsAString& aPaperName) {
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::GetHowToEnableFrameUI(
int16_t* aHowToEnableFrameUI) {
NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI);
*aHowToEnableFrameUI = mHowToEnableFrameUI;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetHowToEnableFrameUI(
int16_t aHowToEnableFrameUI) {
mHowToEnableFrameUI = aHowToEnableFrameUI;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::GetIsCancelled(bool* aIsCancelled) {
NS_ENSURE_ARG_POINTER(aIsCancelled);
*aIsCancelled = mIsCancelled;
@ -784,9 +760,7 @@ nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs) {
mPrintRange = rhs.mPrintRange;
mTitle = rhs.mTitle;
mURL = rhs.mURL;
mHowToEnableFrameUI = rhs.mHowToEnableFrameUI;
mIsCancelled = rhs.mIsCancelled;
mPrintFrameType = rhs.mPrintFrameType;
mPrintSilent = rhs.mPrintSilent;
mShrinkToFit = rhs.mShrinkToFit;
mShowPrintProgress = rhs.mShowPrintProgress;

View File

@ -55,8 +55,6 @@ class nsPrintSettings : public nsIPrintSettings {
bool mPrintBGColors; // print background colors
bool mPrintBGImages; // print background images
int16_t mPrintFrameType;
int16_t mHowToEnableFrameUI;
bool mIsCancelled;
bool mSaveOnCancel;
bool mPrintSilent;

View File

@ -133,9 +133,7 @@ nsPrintSettingsService::SerializeToPrintData(nsIPrintSettings* aSettings,
aSettings->GetFooterStrCenter(data->footerStrCenter());
aSettings->GetFooterStrRight(data->footerStrRight());
aSettings->GetHowToEnableFrameUI(&data->howToEnableFrameUI());
aSettings->GetIsCancelled(&data->isCancelled());
aSettings->GetPrintFrameType(&data->printFrameType());
aSettings->GetPrintSilent(&data->printSilent());
aSettings->GetShrinkToFit(&data->shrinkToFit());
aSettings->GetShowPrintProgress(&data->showPrintProgress());
@ -240,9 +238,7 @@ nsPrintSettingsService::DeserializeToPrintSettings(const PrintData& data,
settings->SetFooterStrCenter(data.footerStrCenter());
settings->SetFooterStrRight(data.footerStrRight());
settings->SetHowToEnableFrameUI(data.howToEnableFrameUI());
settings->SetIsCancelled(data.isCancelled());
settings->SetPrintFrameType(data.printFrameType());
settings->SetPrintSilent(data.printSilent());
settings->SetShrinkToFit(data.shrinkToFit());
settings->SetShowPrintProgress(data.showPrintProgress());