Loading layout/printing/nsPrintJob.cpp +38 −18 Original line number Diff line number Diff line Loading @@ -731,7 +731,7 @@ void nsPrintJob::FirePrintingErrorEvent(nsresult aPrintError) { //-- Section: Reflow Methods //----------------------------------------------------------------- nsresult nsPrintJob::ReconstructAndReflow() { nsresult nsPrintJob::ReconstructAndReflow(bool doSetPixelScale) { if (NS_WARN_IF(!mPrt)) { return NS_ERROR_FAILURE; } Loading Loading @@ -767,7 +767,7 @@ nsresult nsPrintJob::ReconstructAndReflow() { "print object " "has been marked as \"print the document\""); UpdateZoomRatio(po); UpdateZoomRatio(po, doSetPixelScale); po->mPresContext->SetPageScale(po->mZoomRatio); Loading Loading @@ -866,7 +866,7 @@ nsresult nsPrintJob::SetupToPrintContent() { // If some new content got loaded since the initial reflow rebuild // everything. if (mDidLoadDataForPrinting) { nsresult rv = ReconstructAndReflow(); nsresult rv = ReconstructAndReflow(DoSetPixelScale()); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } Loading @@ -886,7 +886,7 @@ nsresult nsPrintJob::SetupToPrintContent() { printData->mShrinkRatio = printData->mPrintObject->mShrinkRatio; if (printData->mShrinkRatio < 0.998f) { nsresult rv = ReconstructAndReflow(); nsresult rv = ReconstructAndReflow(true); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } Loading Loading @@ -1011,7 +1011,8 @@ nsresult nsPrintJob::SetupToPrintContent() { //------------------------------------------------------- // Recursively reflow each sub-doc and then calc // all the frame locations of the sub-docs nsresult nsPrintJob::ReflowDocList(const UniquePtr<nsPrintObject>& aPO) { nsresult nsPrintJob::ReflowDocList(const UniquePtr<nsPrintObject>& aPO, bool aSetPixelScale) { NS_ENSURE_ARG_POINTER(aPO); // Check to see if the subdocument's element has been hidden by the parent Loading @@ -1026,13 +1027,13 @@ nsresult nsPrintJob::ReflowDocList(const UniquePtr<nsPrintObject>& aPO) { } } UpdateZoomRatio(aPO.get()); UpdateZoomRatio(aPO.get(), aSetPixelScale); // Reflow the PO MOZ_TRY(ReflowPrintObject(aPO)); for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) { MOZ_TRY(ReflowDocList(kid)); MOZ_TRY(ReflowDocList(kid, aSetPixelScale)); } return NS_OK; } Loading Loading @@ -1069,7 +1070,7 @@ nsresult nsPrintJob::InitPrintDocConstruction(bool aHandleError) { webProgress->AddProgressListener(static_cast<nsIWebProgressListener*>(this), nsIWebProgress::NOTIFY_STATE_REQUEST); MOZ_TRY(ReflowDocList(printData->mPrintObject)); MOZ_TRY(ReflowDocList(printData->mPrintObject, DoSetPixelScale())); FirePrintPreviewUpdateEvent(); } Loading Loading @@ -1185,18 +1186,20 @@ nsPrintJob::OnContentBlockingEvent(nsIWebProgress* aWebProgress, //------------------------------------------------------- void nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO) { if (!aPO->mParent) { if (mPrt->mShrinkToFit) { // We reduce the scale factor slightly to avoid clipping due to rounding. aPO->mZoomRatio = mPrt->mShrinkRatio - 0.005f; } else { void nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale) { // Here is where we set the shrinkage value into the DC // and this is what actually makes it shrink if (aSetPixelScale && aPO->mFrameType != eIFrame) { // Round down aPO->mZoomRatio = mPrt->mPrintSettings->GetPrintSelectionOnly() ? aPO->mShrinkRatio - 0.005f : mPrt->mShrinkRatio - 0.005f; } else if (!mPrt->mShrinkToFit) { double scaling; mPrt->mPrintSettings->GetScaling(&scaling); aPO->mZoomRatio = float(scaling); } } } nsresult nsPrintJob::UpdateSelectionAndShrinkPrintObject( nsPrintObject* aPO, bool aDocumentIsTopLevel) { Loading Loading @@ -1249,6 +1252,23 @@ nsresult nsPrintJob::UpdateSelectionAndShrinkPrintObject( return NS_OK; } bool nsPrintJob::DoSetPixelScale() { // This is an Optimization // If we are in PP then we already know all the shrinkage information // so just transfer it to the PrintData and we will skip the extra shrinkage // reflow // // doSetPixelScale tells Reflow whether to set the shrinkage value into the DC // The first time we do not want to do this, the second time through we do bool doSetPixelScale = false; bool ppIsShrinkToFit = mPrtPreview && mPrtPreview->mShrinkToFit; if (ppIsShrinkToFit) { mPrt->mShrinkRatio = mPrtPreview->mShrinkRatio; doSetPixelScale = true; } return doSetPixelScale; } nsView* nsPrintJob::GetParentViewForRoot() { if (mIsCreatingPrintPreview) { if (nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint)) { Loading layout/printing/nsPrintJob.h +5 −3 Original line number Diff line number Diff line Loading @@ -166,7 +166,8 @@ class nsPrintJob final : public nsIWebProgressListener, nsresult& aStatus); nsresult DoPrint(const mozilla::UniquePtr<nsPrintObject>& aPO); nsresult ReflowDocList(const mozilla::UniquePtr<nsPrintObject>& aPO); nsresult ReflowDocList(const mozilla::UniquePtr<nsPrintObject>& aPO, bool aSetPixelScale); MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult ReflowPrintObject(const mozilla::UniquePtr<nsPrintObject>& aPO); Loading Loading @@ -222,8 +223,9 @@ class nsPrintJob final : public nsIWebProgressListener, nsresult SetRootView(nsPrintObject* aPO, bool& aDoReturn, bool& aDocumentIsTopLevel, nsSize& aAdjSize); nsView* GetParentViewForRoot(); void UpdateZoomRatio(nsPrintObject* aPO); MOZ_CAN_RUN_SCRIPT nsresult ReconstructAndReflow(); bool DoSetPixelScale(); void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale); MOZ_CAN_RUN_SCRIPT nsresult ReconstructAndReflow(bool aDoSetPixelScale); MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult UpdateSelectionAndShrinkPrintObject( nsPrintObject* aPO, bool aDocumentIsTopLevel); MOZ_CAN_RUN_SCRIPT nsresult InitPrintDocConstruction(bool aHandleError); Loading layout/printing/nsPrintObject.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,9 @@ nsPrintObject::nsPrintObject() mFrameType(eDoc), mParent(nullptr), mHasBeenPrinted(false), mInvisible(false) { mInvisible(false), mShrinkRatio(1.0), mZoomRatio(1.0) { MOZ_COUNT_CTOR(nsPrintObject); } Loading layout/printing/nsPrintObject.h +2 −11 Original line number Diff line number Diff line Loading @@ -72,17 +72,8 @@ class nsPrintObject { nsPrintObject* mParent; // This is a non-owning pointer. bool mHasBeenPrinted; bool mInvisible; // Indicates PO is set to not visible by CSS // The scale factor that sheets should be scaled by. This is either the // explicit scale chosen by the user or else the shrink-to-fit scale factor // if the user selects shrink-to-fit. Only set on the top-level nsPrintObject // since this is only used by nsPageFrame (via nsPresContext::GetPageScale()). float mZoomRatio = 1.0; // If the user selects the shrink-to-fit option, the shrink-to-fit scale // factor is calculated and stored here. Only set on the top-level // nsPrintObject. float mShrinkRatio = 1.0; float mShrinkRatio; float mZoomRatio; private: nsPrintObject& operator=(const nsPrintObject& aOther) = delete; Loading Loading
layout/printing/nsPrintJob.cpp +38 −18 Original line number Diff line number Diff line Loading @@ -731,7 +731,7 @@ void nsPrintJob::FirePrintingErrorEvent(nsresult aPrintError) { //-- Section: Reflow Methods //----------------------------------------------------------------- nsresult nsPrintJob::ReconstructAndReflow() { nsresult nsPrintJob::ReconstructAndReflow(bool doSetPixelScale) { if (NS_WARN_IF(!mPrt)) { return NS_ERROR_FAILURE; } Loading Loading @@ -767,7 +767,7 @@ nsresult nsPrintJob::ReconstructAndReflow() { "print object " "has been marked as \"print the document\""); UpdateZoomRatio(po); UpdateZoomRatio(po, doSetPixelScale); po->mPresContext->SetPageScale(po->mZoomRatio); Loading Loading @@ -866,7 +866,7 @@ nsresult nsPrintJob::SetupToPrintContent() { // If some new content got loaded since the initial reflow rebuild // everything. if (mDidLoadDataForPrinting) { nsresult rv = ReconstructAndReflow(); nsresult rv = ReconstructAndReflow(DoSetPixelScale()); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } Loading @@ -886,7 +886,7 @@ nsresult nsPrintJob::SetupToPrintContent() { printData->mShrinkRatio = printData->mPrintObject->mShrinkRatio; if (printData->mShrinkRatio < 0.998f) { nsresult rv = ReconstructAndReflow(); nsresult rv = ReconstructAndReflow(true); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } Loading Loading @@ -1011,7 +1011,8 @@ nsresult nsPrintJob::SetupToPrintContent() { //------------------------------------------------------- // Recursively reflow each sub-doc and then calc // all the frame locations of the sub-docs nsresult nsPrintJob::ReflowDocList(const UniquePtr<nsPrintObject>& aPO) { nsresult nsPrintJob::ReflowDocList(const UniquePtr<nsPrintObject>& aPO, bool aSetPixelScale) { NS_ENSURE_ARG_POINTER(aPO); // Check to see if the subdocument's element has been hidden by the parent Loading @@ -1026,13 +1027,13 @@ nsresult nsPrintJob::ReflowDocList(const UniquePtr<nsPrintObject>& aPO) { } } UpdateZoomRatio(aPO.get()); UpdateZoomRatio(aPO.get(), aSetPixelScale); // Reflow the PO MOZ_TRY(ReflowPrintObject(aPO)); for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) { MOZ_TRY(ReflowDocList(kid)); MOZ_TRY(ReflowDocList(kid, aSetPixelScale)); } return NS_OK; } Loading Loading @@ -1069,7 +1070,7 @@ nsresult nsPrintJob::InitPrintDocConstruction(bool aHandleError) { webProgress->AddProgressListener(static_cast<nsIWebProgressListener*>(this), nsIWebProgress::NOTIFY_STATE_REQUEST); MOZ_TRY(ReflowDocList(printData->mPrintObject)); MOZ_TRY(ReflowDocList(printData->mPrintObject, DoSetPixelScale())); FirePrintPreviewUpdateEvent(); } Loading Loading @@ -1185,18 +1186,20 @@ nsPrintJob::OnContentBlockingEvent(nsIWebProgress* aWebProgress, //------------------------------------------------------- void nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO) { if (!aPO->mParent) { if (mPrt->mShrinkToFit) { // We reduce the scale factor slightly to avoid clipping due to rounding. aPO->mZoomRatio = mPrt->mShrinkRatio - 0.005f; } else { void nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale) { // Here is where we set the shrinkage value into the DC // and this is what actually makes it shrink if (aSetPixelScale && aPO->mFrameType != eIFrame) { // Round down aPO->mZoomRatio = mPrt->mPrintSettings->GetPrintSelectionOnly() ? aPO->mShrinkRatio - 0.005f : mPrt->mShrinkRatio - 0.005f; } else if (!mPrt->mShrinkToFit) { double scaling; mPrt->mPrintSettings->GetScaling(&scaling); aPO->mZoomRatio = float(scaling); } } } nsresult nsPrintJob::UpdateSelectionAndShrinkPrintObject( nsPrintObject* aPO, bool aDocumentIsTopLevel) { Loading Loading @@ -1249,6 +1252,23 @@ nsresult nsPrintJob::UpdateSelectionAndShrinkPrintObject( return NS_OK; } bool nsPrintJob::DoSetPixelScale() { // This is an Optimization // If we are in PP then we already know all the shrinkage information // so just transfer it to the PrintData and we will skip the extra shrinkage // reflow // // doSetPixelScale tells Reflow whether to set the shrinkage value into the DC // The first time we do not want to do this, the second time through we do bool doSetPixelScale = false; bool ppIsShrinkToFit = mPrtPreview && mPrtPreview->mShrinkToFit; if (ppIsShrinkToFit) { mPrt->mShrinkRatio = mPrtPreview->mShrinkRatio; doSetPixelScale = true; } return doSetPixelScale; } nsView* nsPrintJob::GetParentViewForRoot() { if (mIsCreatingPrintPreview) { if (nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint)) { Loading
layout/printing/nsPrintJob.h +5 −3 Original line number Diff line number Diff line Loading @@ -166,7 +166,8 @@ class nsPrintJob final : public nsIWebProgressListener, nsresult& aStatus); nsresult DoPrint(const mozilla::UniquePtr<nsPrintObject>& aPO); nsresult ReflowDocList(const mozilla::UniquePtr<nsPrintObject>& aPO); nsresult ReflowDocList(const mozilla::UniquePtr<nsPrintObject>& aPO, bool aSetPixelScale); MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult ReflowPrintObject(const mozilla::UniquePtr<nsPrintObject>& aPO); Loading Loading @@ -222,8 +223,9 @@ class nsPrintJob final : public nsIWebProgressListener, nsresult SetRootView(nsPrintObject* aPO, bool& aDoReturn, bool& aDocumentIsTopLevel, nsSize& aAdjSize); nsView* GetParentViewForRoot(); void UpdateZoomRatio(nsPrintObject* aPO); MOZ_CAN_RUN_SCRIPT nsresult ReconstructAndReflow(); bool DoSetPixelScale(); void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale); MOZ_CAN_RUN_SCRIPT nsresult ReconstructAndReflow(bool aDoSetPixelScale); MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult UpdateSelectionAndShrinkPrintObject( nsPrintObject* aPO, bool aDocumentIsTopLevel); MOZ_CAN_RUN_SCRIPT nsresult InitPrintDocConstruction(bool aHandleError); Loading
layout/printing/nsPrintObject.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,9 @@ nsPrintObject::nsPrintObject() mFrameType(eDoc), mParent(nullptr), mHasBeenPrinted(false), mInvisible(false) { mInvisible(false), mShrinkRatio(1.0), mZoomRatio(1.0) { MOZ_COUNT_CTOR(nsPrintObject); } Loading
layout/printing/nsPrintObject.h +2 −11 Original line number Diff line number Diff line Loading @@ -72,17 +72,8 @@ class nsPrintObject { nsPrintObject* mParent; // This is a non-owning pointer. bool mHasBeenPrinted; bool mInvisible; // Indicates PO is set to not visible by CSS // The scale factor that sheets should be scaled by. This is either the // explicit scale chosen by the user or else the shrink-to-fit scale factor // if the user selects shrink-to-fit. Only set on the top-level nsPrintObject // since this is only used by nsPageFrame (via nsPresContext::GetPageScale()). float mZoomRatio = 1.0; // If the user selects the shrink-to-fit option, the shrink-to-fit scale // factor is calculated and stored here. Only set on the top-level // nsPrintObject. float mShrinkRatio = 1.0; float mShrinkRatio; float mZoomRatio; private: nsPrintObject& operator=(const nsPrintObject& aOther) = delete; Loading