diff --git a/layout/generic/ScrollAnchorContainer.cpp b/layout/generic/ScrollAnchorContainer.cpp index 19de19a801a1..c9a40e490910 100644 --- a/layout/generic/ScrollAnchorContainer.cpp +++ b/layout/generic/ScrollAnchorContainer.cpp @@ -63,6 +63,14 @@ static void SetAnchorFlags(const nsIFrame* aScrolledFrame, } MOZ_ASSERT(frame, "The anchor node should be a descendant of the scroll frame"); + // If needed, invalidate the frame so that we start/stop highlighting the + // anchor + if (StaticPrefs::layout_css_scroll_anchoring_highlight()) { + for (nsIFrame* frame = aAnchorNode->FirstContinuation(); !!frame; + frame = frame->GetNextContinuation()) { + frame->InvalidateFrame(); + } + } } /** diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 3c434a97ee7e..033d77174319 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -22,6 +22,7 @@ #include "mozilla/gfx/gfxVars.h" #include "mozilla/gfx/PathHelpers.h" #include "mozilla/Sprintf.h" +#include "mozilla/StaticPrefs.h" #include "nsCOMPtr.h" #include "nsFlexContainerFrame.h" @@ -3517,6 +3518,17 @@ void nsIFrame::BuildDisplayListForChild(nsDisplayListBuilder* aBuilder, // Animations may change the stacking context state. !(child->MayHaveTransformAnimation() || child->MayHaveOpacityAnimation()); + if (StaticPrefs::layout_css_scroll_anchoring_highlight()) { + if (child->FirstContinuation()->IsScrollAnchor()) { + nsRect bounds = child->GetContentRectRelativeToSelf() + + aBuilder->ToReferenceFrame(child); + nsDisplaySolidColor* color = MakeDisplayItem( + aBuilder, child, bounds, NS_RGBA(255, 0, 255, 64)); + color->SetOverrideZIndex(INT32_MAX); + aLists.PositionedDescendants()->AppendToTop(color); + } + } + if (doingShortcut) { BuildDisplayListForSimpleChild(aBuilder, child, aLists); return; diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index 4240efb559bd..616cb4c3f65d 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -896,6 +896,12 @@ VARCACHE_PREF( ) #undef PREF_VALUE +VARCACHE_PREF( + "layout.css.scroll-anchoring.highlight", + layout_css_scroll_anchoring_highlight, + bool, false +) + //--------------------------------------------------------------------------- // JavaScript prefs //---------------------------------------------------------------------------