diff --git a/embedding/components/printingui/ipc/PPrintingTypes.ipdlh b/embedding/components/printingui/ipc/PPrintingTypes.ipdlh index 8be8b2509360..084047bafe4c 100644 --- a/embedding/components/printingui/ipc/PPrintingTypes.ipdlh +++ b/embedding/components/printingui/ipc/PPrintingTypes.ipdlh @@ -118,6 +118,8 @@ struct PrintData { */ float widthScale; float heightScale; + double adjustedPaperWidth; + double adjustedPaperHeight; }; } // namespace embedding diff --git a/widget/cocoa/nsPrintDialogX.mm b/widget/cocoa/nsPrintDialogX.mm index 949899a0e3ce..a6d58d5bfb4b 100644 --- a/widget/cocoa/nsPrintDialogX.mm +++ b/widget/cocoa/nsPrintDialogX.mm @@ -145,7 +145,18 @@ nsPrintDialogServiceX::Show(nsPIDOMWindowOuter *aParent, nsIPrintSettings *aSett [dict setObject: [NSNumber numberWithFloat: 1] forKey: NSPrintScalingFactor]; } + // Set the scaling factor to 100% in the NSPrintInfo + // object so that it will not affect the paper size + // retrieved from the PMPageFormat routines. + [copy setScalingFactor:1.0]; + } else { + aSettings->SetScaling([copy scalingFactor]); } + + // Set the adjusted paper size now that we've updated + // the scaling factor. + settingsX->InitAdjustedPaperSize(); + [copy release]; int16_t pageRange; diff --git a/widget/cocoa/nsPrintOptionsX.mm b/widget/cocoa/nsPrintOptionsX.mm index a044ed422bc2..d9aa17b42ec1 100644 --- a/widget/cocoa/nsPrintOptionsX.mm +++ b/widget/cocoa/nsPrintOptionsX.mm @@ -71,6 +71,11 @@ nsPrintOptionsX::SerializeToPrintData(nsIPrintSettings* aSettings, return NS_ERROR_FAILURE; } + double adjustedWidth, adjustedHeight; + settingsX->GetAdjustedPaperSize(&adjustedWidth, &adjustedHeight); + data->adjustedPaperWidth() = adjustedWidth; + data->adjustedPaperHeight() = adjustedHeight; + NSDictionary* dict = [printInfo dictionary]; if (NS_WARN_IF(!dict)) { return NS_ERROR_FAILURE; @@ -285,6 +290,9 @@ nsPrintOptionsX::DeserializeToPrintSettings(const PrintData& data, settingsX->SetCocoaPrintInfo(newPrintInfo); [newPrintInfo release]; + settingsX->SetAdjustedPaperSize(data.adjustedPaperWidth(), + data.adjustedPaperHeight()); + return NS_OK; } diff --git a/widget/cocoa/nsPrintSettingsX.h b/widget/cocoa/nsPrintSettingsX.h index 9ab776126980..1d755b25057d 100644 --- a/widget/cocoa/nsPrintSettingsX.h +++ b/widget/cocoa/nsPrintSettingsX.h @@ -25,6 +25,15 @@ public: void SetCocoaPrintInfo(NSPrintInfo* aPrintInfo); virtual nsresult ReadPageFormatFromPrefs(); virtual nsresult WritePageFormatToPrefs(); + virtual nsresult GetEffectivePageSize(double *aWidth, + double *aHeight) override; + + // In addition to setting the paper width and height, these + // overrides set the adjusted width and height returned from + // GetEffectivePageSize. This is needed when a paper size is + // set manually without using a print dialog a la reftest-print. + virtual nsresult SetPaperWidth(double aPaperWidth) override; + virtual nsresult SetPaperHeight(double aPaperWidth) override; PMPrintSettings GetPMPrintSettings(); PMPrintSession GetPMPrintSession(); @@ -35,9 +44,16 @@ public: // Should be called whenever mPageFormat is initialized or overwritten. nsresult InitUnwriteableMargin(); + // Re-initialize mAdjustedPaper{Width,Height} with values from mPageFormat. + // Should be called whenever mPageFormat is initialized or overwritten. + nsresult InitAdjustedPaperSize(); + void SetInchesScale(float aWidthScale, float aHeightScale); void GetInchesScale(float *aWidthScale, float *aHeightScale); + void SetAdjustedPaperSize(double aWidth, double aHeight); + void GetAdjustedPaperSize(double *aWidth, double *aHeight); + protected: virtual ~nsPrintSettingsX(); @@ -57,6 +73,8 @@ protected: // paper size units to inches float mWidthScale; float mHeightScale; + double mAdjustedPaperWidth; + double mAdjustedPaperHeight; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsX, NS_PRINTSETTINGSX_IID) diff --git a/widget/cocoa/nsPrintSettingsX.mm b/widget/cocoa/nsPrintSettingsX.mm index bf2302161204..73a8e78d2b1c 100644 --- a/widget/cocoa/nsPrintSettingsX.mm +++ b/widget/cocoa/nsPrintSettingsX.mm @@ -68,6 +68,7 @@ nsresult nsPrintSettingsX::Init() NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; InitUnwriteableMargin(); + InitAdjustedPaperSize(); return NS_OK; @@ -94,6 +95,23 @@ NS_IMETHODIMP nsPrintSettingsX::InitUnwriteableMargin() NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; } +NS_IMETHODIMP nsPrintSettingsX::InitAdjustedPaperSize() +{ + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; + + PMPageFormat pageFormat = GetPMPageFormat(); + + PMRect paperRect; + ::PMGetAdjustedPaperRect(pageFormat, &paperRect); + + mAdjustedPaperWidth = paperRect.right - paperRect.left; + mAdjustedPaperHeight = paperRect.bottom - paperRect.top; + + return NS_OK; + + NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; +} + void nsPrintSettingsX::SetCocoaPrintInfo(NSPrintInfo* aPrintInfo) { @@ -206,8 +224,10 @@ nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPageFormat) void nsPrintSettingsX::SetInchesScale(float aWidthScale, float aHeightScale) { - mWidthScale = aWidthScale; - mHeightScale = aHeightScale; + if (aWidthScale > 0 && aHeightScale > 0) { + mWidthScale = aWidthScale; + mHeightScale = aHeightScale; + } } void @@ -216,3 +236,37 @@ nsPrintSettingsX::GetInchesScale(float *aWidthScale, float *aHeightScale) *aWidthScale = mWidthScale; *aHeightScale = mHeightScale; } + +NS_IMETHODIMP nsPrintSettingsX::SetPaperWidth(double aPaperWidth) +{ + mPaperWidth = aPaperWidth; + mAdjustedPaperWidth = aPaperWidth * mWidthScale; + return NS_OK; +} + +NS_IMETHODIMP nsPrintSettingsX::SetPaperHeight(double aPaperHeight) +{ + mPaperHeight = aPaperHeight; + mAdjustedPaperHeight = aPaperHeight * mHeightScale; + return NS_OK; +} + +NS_IMETHODIMP +nsPrintSettingsX::GetEffectivePageSize(double *aWidth, double *aHeight) +{ + *aWidth = NS_INCHES_TO_TWIPS(mAdjustedPaperWidth / mWidthScale); + *aHeight = NS_INCHES_TO_TWIPS(mAdjustedPaperHeight / mHeightScale); + return NS_OK; +} + +void nsPrintSettingsX::SetAdjustedPaperSize(double aWidth, double aHeight) +{ + mAdjustedPaperWidth = aWidth; + mAdjustedPaperHeight = aHeight; +} + +void nsPrintSettingsX::GetAdjustedPaperSize(double *aWidth, double *aHeight) +{ + *aWidth = mAdjustedPaperWidth; + *aHeight = mAdjustedPaperHeight; +}