--- a/layout/base/nsLayoutUtils.cpp+++ b/layout/base/nsLayoutUtils.cpp@@ -3529,44 +3529,16 @@ nsLayoutUtils::PaintFrame(nsRenderingCon canvasArea.UnionRect(canvasArea, canvasFrame->CanvasArea() + builder.ToReferenceFrame(canvasFrame)); } } builder.EnterPresShell(aFrame); nsRect dirtyRect = visibleRegion.GetBounds(); {- // If a scrollable container layer is created in nsDisplayList::PaintForFrame,- // it will be the scroll parent for display items that are built in the- // BuildDisplayListForStackingContext call below. We need to set the scroll- // parent on the display list builder while we build those items, so that they- // can pick up their scroll parent's id.- ViewID id = FrameMetrics::NULL_SCROLL_ID;- if (ignoreViewportScrolling && presContext->IsRootContentDocument()) {- if (nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame()) {- if (nsIContent* content = rootScrollFrame->GetContent()) {- id = nsLayoutUtils::FindOrCreateIDFor(content);- }- }- }-#if !defined(MOZ_WIDGET_ANDROID) || defined(MOZ_ANDROID_APZ)- else if (presShell->GetDocument() && presShell->GetDocument()->IsRootDisplayDocument()- && !presShell->GetRootScrollFrame()) {- // In cases where the root document is a XUL document, we want to take- // the ViewID from the root element, as that will be the ViewID of the- // root APZC in the tree. Skip doing this in cases where we know- // nsGfxScrollFrame::BuilDisplayList will do it instead.- if (dom::Element* element = presShell->GetDocument()->GetDocumentElement()) {- id = nsLayoutUtils::FindOrCreateIDFor(element);- }- }-#endif-- nsDisplayListBuilder::AutoCurrentScrollParentIdSetter idSetter(&builder, id);- PROFILER_LABEL("nsLayoutUtils", "PaintFrame::BuildDisplayList", js::ProfileEntry::Category::GRAPHICS); aFrame->BuildDisplayListForStackingContext(&builder, dirtyRect, &list); #ifdef DEBUG if (builder.IsForGenerateGlyphMask() || builder.IsForPaintingSelectionBG()) { // PaintFrame is called to generate text glyph by // nsDisplayBackgroundImage::Paint or nsDisplayBackgroundColor::Paint.

--- a/layout/generic/nsFrame.cpp+++ b/layout/generic/nsFrame.cpp@@ -2777,21 +2777,27 @@ nsIFrame::BuildDisplayListForChild(nsDis NS_ASSERTION(!isStackingContext || pseudoStackingContext, "Stacking contexts must also be pseudo-stacking-contexts"); nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(aBuilder, child, dirty, pseudoStackingContext); DisplayListClipState::AutoClipMultiple clipState(aBuilder); CheckForApzAwareEventHandlers(aBuilder, child);+ Maybe<nsDisplayListBuilder::AutoCurrentScrollParentIdSetter> idSetter; if (savedOutOfFlowData) { clipState.SetClipForContainingBlockDescendants( &savedOutOfFlowData->mContainingBlockClip); clipState.SetScrollClipForContainingBlockDescendants( savedOutOfFlowData->mContainingBlockScrollClip);++ // For out-of-flow frames, the current scroll parent is wrong, because it's+ // the scroll parent for the placeholder frame rather than the actual+ // out-of-flow frame, so we need to update the current scroll parent.+ idSetter.emplace(aBuilder, savedOutOfFlowData); } else if (GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO && isPlaceholder) { // If we have nested out-of-flow frames and the outer one isn't visible // then we won't have stored clip data for it. We can just clear the clip // instead since we know we won't render anything, and the inner out-of-flow // frame will setup the correct clip for itself. clipState.Clear(); }