From 640f58866c76a0836249eeaafa8e2dff94447345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 17 Sep 2024 16:03:30 +0000 Subject: [PATCH] Bug 1917356 - Update remote frame sizes for printing reliably. r=mstange Printing has a weird code-path which doesn't use the refresh driver. Update frame sizes explicitly, and remove the hack in nsDisplayRemote::Paint (which is what probably papered over this). Differential Revision: https://phabricator.services.mozilla.com/D222372 --- dom/base/Document.cpp | 9 +++++---- layout/generic/nsSubDocumentFrame.cpp | 10 ++-------- layout/printing/nsPrintJob.cpp | 5 +++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index a8cada37ed6c..a7a6cf1c14ff 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -16840,9 +16840,10 @@ static void UpdateEffectsOnBrowsingContext(BrowsingContext* aBc, // for example. return EffectsInfo::FullyHidden(); } - Maybe visibleRect; - gfx::MatrixScales rasterScale; - visibleRect = subDocFrame->GetVisibleRect(); + Maybe visibleRect = subDocFrame->GetVisibleRect(); + if (subDocFrame->PresContext()->IsPrintingOrPrintPreview()) { + visibleRect = Some(subDocFrame->GetDestRect()); + } if (!visibleRect) { // If we have no visible rect (e.g., because we are zero-sized) we // still want to provide the intersection rect in order to get the @@ -16850,7 +16851,7 @@ static void UpdateEffectsOnBrowsingContext(BrowsingContext* aBc, visibleRect.emplace(*output.mIntersectionRect - output.mTargetRect.TopLeft()); } - rasterScale = subDocFrame->GetRasterScale(); + gfx::MatrixScales rasterScale = subDocFrame->GetRasterScale(); ParentLayerToScreenScale2D transformToAncestorScale = ParentLayerToParentLayerScale( subDocFrame->PresShell()->GetCumulativeResolution()) * diff --git a/layout/generic/nsSubDocumentFrame.cpp b/layout/generic/nsSubDocumentFrame.cpp index 39882f063bdc..f4f92cd845a2 100644 --- a/layout/generic/nsSubDocumentFrame.cpp +++ b/layout/generic/nsSubDocumentFrame.cpp @@ -1252,13 +1252,6 @@ nsDisplayRemote::nsDisplayRemote(nsDisplayListBuilder* aBuilder, namespace mozilla { void nsDisplayRemote::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) { - nsPresContext* pc = mFrame->PresContext(); - nsFrameLoader* fl = GetFrameLoader(); - if (pc->GetPrintSettings() && fl->IsRemoteFrame()) { - // See the comment below in CreateWebRenderCommands() as for why doing this. - fl->UpdatePositionAndSize(static_cast(mFrame)); - } - DrawTarget* target = aCtx->GetDrawTarget(); if (!target->IsRecording() || mPaintData.mTabId == 0) { NS_WARNING("Remote iframe not rendered"); @@ -1273,7 +1266,8 @@ void nsDisplayRemote::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) { // // Similarly, rendering the inner document will scale up by the cross process // paint scale again, so we also need to account for that. - const int32_t appUnitsPerDevPixel = pc->AppUnitsPerDevPixel(); + const int32_t appUnitsPerDevPixel = + mFrame->PresContext()->AppUnitsPerDevPixel(); gfxContextMatrixAutoSaveRestore saveMatrix(aCtx); gfxFloat targetAuPerDev = diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index 79340a4adce7..c89e3d1e77c0 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -742,8 +742,8 @@ nsresult nsPrintJob::ReconstructAndReflow() { return NS_ERROR_FAILURE; } - nsresult rv = UpdateSelectionAndShrinkPrintObject(po, documentIsTopLevel); - NS_ENSURE_SUCCESS(rv, rv); + po->mDocument->UpdateRemoteFrameEffects(); + MOZ_TRY(UpdateSelectionAndShrinkPrintObject(po, documentIsTopLevel)); } return NS_OK; } @@ -1421,6 +1421,7 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr& aPO) { } // Process the reflow event Initialize posted presShell->FlushPendingNotifications(FlushType::Layout); + aPO->mDocument->UpdateRemoteFrameEffects(); MOZ_TRY(UpdateSelectionAndShrinkPrintObject(aPO.get(), documentIsTopLevel));