From 6cbe892f865f5871f5cec8ac97dc496ea91a5eb7 Mon Sep 17 00:00:00 2001 From: "reed%reedloden.com" Date: Tue, 13 Nov 2007 19:14:08 +0000 Subject: [PATCH] Bug 396278 - "should take edge values from print settings instead of prefs" [p=chpe r+sr=roc r=gavin a1.9=schrep] --- layout/generic/nsSimplePageSequence.cpp | 31 +++----- layout/generic/nsSimplePageSequence.h | 1 - .../printing/content/printdialog.js | 1 + .../printing/content/printjoboptions.js | 44 +++--------- widget/public/nsIPrintSettings.idl | 22 +++++- widget/src/xpwidgets/nsPrintOptionsImpl.cpp | 72 ++++++++++++++++++- widget/src/xpwidgets/nsPrintOptionsImpl.h | 3 + widget/src/xpwidgets/nsPrintSettingsImpl.cpp | 68 ++++++++++++++++++ widget/src/xpwidgets/nsPrintSettingsImpl.h | 1 + xpfe/global/resources/content/printdialog.js | 1 + .../resources/content/unix/printjoboptions.js | 44 +++--------- 11 files changed, 190 insertions(+), 98 deletions(-) diff --git a/layout/generic/nsSimplePageSequence.cpp b/layout/generic/nsSimplePageSequence.cpp index 57d90c89582..9b3f0085670 100644 --- a/layout/generic/nsSimplePageSequence.cpp +++ b/layout/generic/nsSimplePageSequence.cpp @@ -161,30 +161,19 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsPresContext* aPresContext CreateContinuingFrame(aPresContext, aPageFrame, this, aContinuingPage); } -void -nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(const char* aPrefName, - nscoord& aCoord) -{ - nsresult rv = mPageData->mPrintOptions-> - GetPrinterPrefInt(mPageData->mPrintSettings, - NS_ConvertASCIItoUTF16(aPrefName).get(), - &aCoord); - - if (NS_SUCCEEDED(rv)) { - nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0); - aCoord = PR_MAX(NS_INCHES_TO_TWIPS(float(aCoord)/100.0f), 0); - aCoord = PR_MIN(aCoord, inchInTwips); // an inch is still probably excessive - } -} - void nsSimplePageSequenceFrame::GetEdgePaperMargin(nsMargin& aMargin) { - aMargin.SizeTo(0,0,0,0); - GetEdgePaperMarginCoord("print_edge_top", aMargin.top); - GetEdgePaperMarginCoord("print_edge_left", aMargin.left); - GetEdgePaperMarginCoord("print_edge_bottom", aMargin.bottom); - GetEdgePaperMarginCoord("print_edge_right", aMargin.right); + if (NS_SUCCEEDED(mPageData->mPrintSettings->GetEdgeInTwips(aMargin))) { + nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0); + // sanity check the values. an inch is still probably excessive + aMargin.top = PR_MIN(PR_MAX(aMargin.top, 0), inchInTwips); + aMargin.bottom = PR_MIN(PR_MAX(aMargin.bottom, 0), inchInTwips); + aMargin.left = PR_MIN(PR_MAX(aMargin.left, 0), inchInTwips); + aMargin.right = PR_MIN(PR_MAX(aMargin.right, 0), inchInTwips); + } else { + aMargin.SizeTo(0, 0, 0, 0); + } } NS_IMETHODIMP diff --git a/layout/generic/nsSimplePageSequence.h b/layout/generic/nsSimplePageSequence.h index 535e6e24c2b..5348ec93820 100644 --- a/layout/generic/nsSimplePageSequence.h +++ b/layout/generic/nsSimplePageSequence.h @@ -149,7 +149,6 @@ protected: void SetDateTimeStr(PRUnichar * aDateTimeStr); void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly); - void GetEdgePaperMarginCoord(const char* aPrefName, nscoord& aCoord); void GetEdgePaperMargin(nsMargin& aMargin); NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();} diff --git a/toolkit/components/printing/content/printdialog.js b/toolkit/components/printing/content/printdialog.js index f3fc8b55b7b..3e674af3b42 100644 --- a/toolkit/components/printing/content/printdialog.js +++ b/toolkit/components/printing/content/printdialog.js @@ -408,6 +408,7 @@ function onAccept() if (saveToPrefs && printService != null) { var flags = gPrintSetInterface.kInitSavePaperSize | gPrintSetInterface.kInitSaveColorSpace | + gPrintSetInterface.kInitSaveEdges | gPrintSetInterface.kInitSaveInColor | gPrintSetInterface.kInitSaveResolutionName | gPrintSetInterface.kInitSaveDownloadFonts | diff --git a/toolkit/components/printing/content/printjoboptions.js b/toolkit/components/printing/content/printjoboptions.js index ab990171197..798ec595089 100644 --- a/toolkit/components/printing/content/printjoboptions.js +++ b/toolkit/components/printing/content/printjoboptions.js @@ -836,26 +836,10 @@ function loadDialog() dialog.cmdInput.value = print_command; dialog.jobTitleInput.value = print_jobtitle; - /* First initialize with the hardcoded defaults... */ - dialog.topInput.value = "0.04"; - dialog.bottomInput.value = "0.04"; - dialog.leftInput.value = "0.04"; - dialog.rightInput.value = "0.04"; - - try { - /* ... then try to get the generic settings ... */ - dialog.topInput.value = gPrefs.getIntPref("print.print_edge_top") / 100.0; - dialog.bottomInput.value = gPrefs.getIntPref("print.print_edge_bottom") / 100.0; - dialog.leftInput.value = gPrefs.getIntPref("print.print_edge_left") / 100.0; - dialog.rightInput.value = gPrefs.getIntPref("print.print_edge_right") / 100.0; - - /* ... and then the printer specific settings. */ - var printername = gPrintSettings.printerName; - dialog.topInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_top") / 100.0; - dialog.bottomInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_bottom") / 100.0; - dialog.leftInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_left") / 100.0; - dialog.rightInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_right") / 100.0; - } catch (e) { } + dialog.topInput.value = gPrintSettings.edgeTop.toFixed(2); + dialog.bottomInput.value = gPrintSettings.edgeBottom.toFixed(2); + dialog.leftInput.value = gPrintSettings.edgeLeft.toFixed(2); + dialog.rightInput.value = gPrintSettings.edgeRight.toFixed(2); } //--------------------------------------------------- @@ -922,22 +906,10 @@ function onAccept() gPrintSettings.printCommand = dialog.cmdInput.value; gPrintSettings.title = dialog.jobTitleInput.value; - // - try { - var printerName = gPrintSettings.printerName; - var i = dialog.topInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_top", i); - - i = dialog.bottomInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_bottom", i); - - i = dialog.leftInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_left", i); - - i = dialog.rightInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_right", i); - } catch (e) { - } + gPrintSettings.edgeTop = dialog.topInput.value; + gPrintSettings.edgeBottom = dialog.bottomInput.value; + gPrintSettings.edgeLeft = dialog.leftInput.value; + gPrintSettings.edgeRight = dialog.rightInput.value; if (doDebug) { dump("onAccept******************************\n"); diff --git a/widget/public/nsIPrintSettings.idl b/widget/public/nsIPrintSettings.idl index 9735b980d5b..52dac49b36c 100644 --- a/widget/public/nsIPrintSettings.idl +++ b/widget/public/nsIPrintSettings.idl @@ -58,7 +58,7 @@ interface nsIPrintSession; * * @status UNDER_REVIEW */ -[scriptable, uuid(b1b5e3cc-a52c-4325-a7f6-e1ac6fac19a5)] +[scriptable, uuid(81b8dfee-25cc-479c-ad2c-a5e3875650cb)] interface nsIPrintSettings : nsISupports { @@ -80,7 +80,7 @@ interface nsIPrintSettings : nsISupports /* Flag 0x00001000 is unused */ const unsigned long kInitSavePaperData = 0x00002000; /* Flag 0x00004000 is unused */ - /* Flag 0x00008000 is unused */ + const unsigned long kInitSaveEdges = 0x00008000; const unsigned long kInitSaveReversed = 0x00010000; const unsigned long kInitSaveInColor = 0x00020000; @@ -201,6 +201,21 @@ interface nsIPrintSettings : nsISupports attribute long startPageRange; attribute long endPageRange; + /** + * The edge defines the area at the border of the paper + * outside of which the printer cannot print. The headers and footers + * will be placed inside. + */ + attribute double edgeTop; /* these are in inches */ + attribute double edgeLeft; + attribute double edgeBottom; + attribute double edgeRight; + + /** + * The margins define the area of the paper to print the content to. + * The headers and footers are placed outside, but still inside the border + * defined by the edge attributes above. + */ attribute double marginTop; /* these are in inches */ attribute double marginLeft; attribute double marginBottom; @@ -282,7 +297,8 @@ interface nsIPrintSettings : nsISupports /* C++ Helper Functions */ [noscript] void SetMarginInTwips(in nsNativeMarginRef aMargin); + [noscript] void SetEdgeInTwips(in nsNativeMarginRef aEdge); /* Purposely made this an "in" arg */ [noscript] void GetMarginInTwips(in nsNativeMarginRef aMargin); - + [noscript] void GetEdgeInTwips(in nsNativeMarginRef aEdge); }; diff --git a/widget/src/xpwidgets/nsPrintOptionsImpl.cpp b/widget/src/xpwidgets/nsPrintOptionsImpl.cpp index a38b9fbeb7c..2dfe8324b2d 100644 --- a/widget/src/xpwidgets/nsPrintOptionsImpl.cpp +++ b/widget/src/xpwidgets/nsPrintOptionsImpl.cpp @@ -67,10 +67,14 @@ NS_IMPL_ISUPPORTS2(nsPrintOptions, nsIPrintOptions, nsIPrintSettingsService) // Pref Constants - static const char kMarginTop[] = "print_margin_top"; +static const char kMarginTop[] = "print_margin_top"; static const char kMarginLeft[] = "print_margin_left"; static const char kMarginBottom[] = "print_margin_bottom"; static const char kMarginRight[] = "print_margin_right"; +static const char kEdgeTop[] = "print_edge_top"; +static const char kEdgeLeft[] = "print_edge_left"; +static const char kEdgeBottom[] = "print_edge_bottom"; +static const char kEdgeRight[] = "print_edge_right"; // Prefs for Print Options static const char kPrintEvenPages[] = "print_evenpages"; @@ -263,6 +267,24 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName, aPS->SetMarginInTwips(margin); } + if (aFlags & nsIPrintSettings::kInitSaveEdges) { + nsMargin margin; + margin.SizeTo(0,0,0,0); + ReadInchesIntToTwipsPref(GetPrefName(kEdgeTop, aPrinterName), margin.top, + kEdgeTop); + DUMP_INT(kReadStr, kEdgeTop, margin.top); + ReadInchesIntToTwipsPref(GetPrefName(kEdgeLeft, aPrinterName), margin.left, + kEdgeLeft); + DUMP_INT(kReadStr, kEdgeLeft, margin.left); + ReadInchesIntToTwipsPref(GetPrefName(kEdgeBottom, aPrinterName), + margin.bottom, kEdgeBottom); + DUMP_INT(kReadStr, kEdgeBottom, margin.bottom); + ReadInchesIntToTwipsPref(GetPrefName(kEdgeRight, aPrinterName), margin.right, + kEdgeRight); + DUMP_INT(kReadStr, kEdgeRight, margin.right); + aPS->SetEdgeInTwips(margin); + } + PRBool b; nsAutoString str; PRInt32 iVal; @@ -533,6 +555,24 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName, } } + nsMargin edge; + if (aFlags & nsIPrintSettings::kInitSaveEdges) { + if (NS_SUCCEEDED(aPS->GetEdgeInTwips(edge))) { + WriteInchesIntFromTwipsPref(GetPrefName(kEdgeTop, aPrinterName), + edge.top); + DUMP_INT(kWriteStr, kEdgeTop, edge.top); + WriteInchesIntFromTwipsPref(GetPrefName(kEdgeLeft, aPrinterName), + edge.left); + DUMP_INT(kWriteStr, kEdgeLeft, edge.top); + WriteInchesIntFromTwipsPref(GetPrefName(kEdgeBottom, aPrinterName), + edge.bottom); + DUMP_INT(kWriteStr, kEdgeBottom, edge.top); + WriteInchesIntFromTwipsPref(GetPrefName(kEdgeRight, aPrinterName), + edge.right); + DUMP_INT(kWriteStr, kEdgeRight, edge.top); + } + } + // Paper size prefs are saved as a group if (aFlags & nsIPrintSettings::kInitSavePaperSize) { PRInt16 sizeUnit, sizeType; @@ -1130,6 +1170,36 @@ nsPrintOptions::WriteInchesFromTwipsPref(const char * aPrefId, nscoord aTwips) mPrefBranch->SetCharPref(aPrefId, inchesStr.get()); } +void +nsPrintOptions::ReadInchesIntToTwipsPref(const char * aPrefId, nscoord& aTwips, + const char * aMarginPref) +{ + if (!mPrefBranch) { + return; + } + + PRInt32 value; + nsresult rv = mPrefBranch->GetIntPref(aPrefId, &value); + if (NS_FAILED(rv)) { + rv = mPrefBranch->GetIntPref(aMarginPref, &value); + } + if (NS_SUCCEEDED(rv)) { + aTwips = NS_INCHES_TO_TWIPS(float(value)/100.0f); + } else { + aTwips = 0; + } +} + +void +nsPrintOptions::WriteInchesIntFromTwipsPref(const char * aPrefId, nscoord aTwips) +{ + if (!mPrefBranch) { + return; + } + + mPrefBranch->SetIntPref(aPrefId, PRInt32(NS_TWIPS_TO_INCHES(aTwips)*100.0f + 0.5f)); +} + void nsPrintOptions::ReadJustification(const char * aPrefId, PRInt16& aJust, PRInt16 aInitValue) diff --git a/widget/src/xpwidgets/nsPrintOptionsImpl.h b/widget/src/xpwidgets/nsPrintOptionsImpl.h index e9bd345e00f..15c07367a58 100644 --- a/widget/src/xpwidgets/nsPrintOptionsImpl.h +++ b/widget/src/xpwidgets/nsPrintOptionsImpl.h @@ -79,6 +79,9 @@ protected: void ReadInchesToTwipsPref(const char * aPrefId, nscoord& aTwips, const char * aMarginPref); void WriteInchesFromTwipsPref(const char * aPrefId, nscoord aTwips); + void ReadInchesIntToTwipsPref(const char * aPrefId, nscoord& aTwips, + const char * aMarginPref); + void WriteInchesIntFromTwipsPref(const char * aPrefId, nscoord aTwips); nsresult ReadPrefString(const char * aPrefId, nsAString& aString); /** diff --git a/widget/src/xpwidgets/nsPrintSettingsImpl.cpp b/widget/src/xpwidgets/nsPrintSettingsImpl.cpp index 497894a8870..b072d46fd6c 100644 --- a/widget/src/xpwidgets/nsPrintSettingsImpl.cpp +++ b/widget/src/xpwidgets/nsPrintSettingsImpl.cpp @@ -82,6 +82,7 @@ nsPrintSettings::nsPrintSettings() : /* member initializers and constructor code */ nscoord halfInch = NS_INCHES_TO_TWIPS(0.5); mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch); + mEdge.SizeTo(0, 0, 0, 0); mPrintOptions = kPrintOddPages | kPrintEvenPages; @@ -444,6 +445,58 @@ NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight) return NS_OK; } +/* attribute double edgeTop; */ +NS_IMETHODIMP nsPrintSettings::GetEdgeTop(double *aEdgeTop) +{ + NS_ENSURE_ARG_POINTER(aEdgeTop); + *aEdgeTop = NS_TWIPS_TO_INCHES(mEdge.top); + return NS_OK; +} +NS_IMETHODIMP nsPrintSettings::SetEdgeTop(double aEdgeTop) +{ + mEdge.top = NS_INCHES_TO_TWIPS(float(aEdgeTop)); + return NS_OK; +} + +/* attribute double edgeLeft; */ +NS_IMETHODIMP nsPrintSettings::GetEdgeLeft(double *aEdgeLeft) +{ + NS_ENSURE_ARG_POINTER(aEdgeLeft); + *aEdgeLeft = NS_TWIPS_TO_INCHES(mEdge.left); + return NS_OK; +} +NS_IMETHODIMP nsPrintSettings::SetEdgeLeft(double aEdgeLeft) +{ + mEdge.left = NS_INCHES_TO_TWIPS(float(aEdgeLeft)); + return NS_OK; +} + +/* attribute double edgeBottom; */ +NS_IMETHODIMP nsPrintSettings::GetEdgeBottom(double *aEdgeBottom) +{ + NS_ENSURE_ARG_POINTER(aEdgeBottom); + *aEdgeBottom = NS_TWIPS_TO_INCHES(mEdge.bottom); + return NS_OK; +} +NS_IMETHODIMP nsPrintSettings::SetEdgeBottom(double aEdgeBottom) +{ + mEdge.bottom = NS_INCHES_TO_TWIPS(float(aEdgeBottom)); + return NS_OK; +} + +/* attribute double edgeRight; */ +NS_IMETHODIMP nsPrintSettings::GetEdgeRight(double *aEdgeRight) +{ + NS_ENSURE_ARG_POINTER(aEdgeRight); + *aEdgeRight = NS_TWIPS_TO_INCHES(mEdge.right); + return NS_OK; +} +NS_IMETHODIMP nsPrintSettings::SetEdgeRight(double aEdgeRight) +{ + mEdge.right = NS_INCHES_TO_TWIPS(float(aEdgeRight)); + return NS_OK; +} + /* attribute double scaling; */ NS_IMETHODIMP nsPrintSettings::GetScaling(double *aScaling) { @@ -894,6 +947,13 @@ nsPrintSettings::SetMarginInTwips(nsMargin& aMargin) return NS_OK; } +NS_IMETHODIMP +nsPrintSettings::SetEdgeInTwips(nsMargin& aEdge) +{ + mEdge = aEdge; + return NS_OK; +} + /** --------------------------------------------------- * See documentation in nsPrintOptionsImpl.h * @update 6/21/00 dwc @@ -905,6 +965,13 @@ nsPrintSettings::GetMarginInTwips(nsMargin& aMargin) return NS_OK; } +NS_IMETHODIMP +nsPrintSettings::GetEdgeInTwips(nsMargin& aEdge) +{ + aEdge = mEdge; + return NS_OK; +} + /** --------------------------------------------------- * See documentation in nsPrintOptionsImpl.h */ @@ -968,6 +1035,7 @@ nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs) mStartPageNum = rhs.mStartPageNum; mEndPageNum = rhs.mEndPageNum; mMargin = rhs.mMargin; + mEdge = rhs.mEdge; mScaling = rhs.mScaling; mPrintBGColors = rhs.mPrintBGColors; mPrintBGImages = rhs.mPrintBGImages; diff --git a/widget/src/xpwidgets/nsPrintSettingsImpl.h b/widget/src/xpwidgets/nsPrintSettingsImpl.h index 7f447927f0b..51ea61d4ea0 100644 --- a/widget/src/xpwidgets/nsPrintSettingsImpl.h +++ b/widget/src/xpwidgets/nsPrintSettingsImpl.h @@ -82,6 +82,7 @@ protected: nsWeakPtr mSession; // Should never be touched by Clone or Assign nsMargin mMargin; + nsMargin mEdge; PRInt32 mPrintOptions; // scriptable data members diff --git a/xpfe/global/resources/content/printdialog.js b/xpfe/global/resources/content/printdialog.js index 32ff0e5eb41..23d86e910fa 100644 --- a/xpfe/global/resources/content/printdialog.js +++ b/xpfe/global/resources/content/printdialog.js @@ -407,6 +407,7 @@ function onAccept() if (saveToPrefs && printService != null) { var flags = gPrintSetInterface.kInitSavePaperSize | gPrintSetInterface.kInitSaveColorSpace | + gPrintSetInterface.kInitSaveEdges | gPrintSetInterface.kInitSaveInColor | gPrintSetInterface.kInitSaveResolutionName | gPrintSetInterface.kInitSaveDownloadFonts | diff --git a/xpfe/global/resources/content/unix/printjoboptions.js b/xpfe/global/resources/content/unix/printjoboptions.js index d77235c1c85..cbb7e579df3 100644 --- a/xpfe/global/resources/content/unix/printjoboptions.js +++ b/xpfe/global/resources/content/unix/printjoboptions.js @@ -835,26 +835,10 @@ function loadDialog() dialog.cmdInput.value = print_command; dialog.jobTitleInput.value = print_jobtitle; - /* First initialize with the hardcoded defaults... */ - dialog.topInput.value = "0.04"; - dialog.bottomInput.value = "0.04"; - dialog.leftInput.value = "0.04"; - dialog.rightInput.value = "0.04"; - - try { - /* ... then try to get the generic settings ... */ - dialog.topInput.value = gPrefs.getIntPref("print.print_edge_top") / 100.0; - dialog.bottomInput.value = gPrefs.getIntPref("print.print_edge_bottom") / 100.0; - dialog.leftInput.value = gPrefs.getIntPref("print.print_edge_left") / 100.0; - dialog.rightInput.value = gPrefs.getIntPref("print.print_edge_right") / 100.0; - - /* ... and then the printer specific settings. */ - var printername = gPrintSettings.printerName; - dialog.topInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_top") / 100.0; - dialog.bottomInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_bottom") / 100.0; - dialog.leftInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_left") / 100.0; - dialog.rightInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_right") / 100.0; - } catch (e) { } + dialog.topInput.value = gPrintSettings.edgeTop.toFixed(2); + dialog.bottomInput.value = gPrintSettings.edgeBottom.toFixed(2); + dialog.leftInput.value = gPrintSettings.edgeLeft.toFixed(2); + dialog.rightInput.value = gPrintSettings.edgeRight.toFixed(2); } //--------------------------------------------------- @@ -921,22 +905,10 @@ function onAccept() gPrintSettings.printCommand = dialog.cmdInput.value; gPrintSettings.title = dialog.jobTitleInput.value; - // - try { - var printerName = gPrintSettings.printerName; - var i = dialog.topInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_top", i); - - i = dialog.bottomInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_bottom", i); - - i = dialog.leftInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_left", i); - - i = dialog.rightInput.value * 100; - gPrefs.setIntPref("print.printer_"+printerName+".print_edge_right", i); - } catch (e) { - } + gPrintSettings.edgeTop = dialog.topInput.value; + gPrintSettings.edgeBottom = dialog.bottomInput.value; + gPrintSettings.edgeLeft = dialog.leftInput.value; + gPrintSettings.edgeRight = dialog.rightInput.value; if (doDebug) { dump("onAccept******************************\n");