From e54839acce2d8c967765fe5a5a363f5e69cd55ab Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Tue, 27 Nov 2018 15:40:57 -0600 Subject: [PATCH] Bug 1305957 part 13 - Highlight scroll anchor when 'layout.scroll-anchoring.highlight' is enabled. r=mattwoodrow This commit adds a debug pref that will highlight the frames that are marked as anchor nodes. This is helpful to debug anchor selection. Differential Revision: https://phabricator.services.mozilla.com/D13276 --HG-- extra : rebase_source : 61109b3d967f0e4f8e5a260a71fecc01ebf22c73 extra : histedit_source : d2275fdb4edc3d7f6b006c8c7ab24fca1223998d --- layout/generic/ScrollAnchorContainer.cpp | 8 ++++++++ layout/generic/nsFrame.cpp | 12 ++++++++++++ modules/libpref/init/StaticPrefList.h | 6 ++++++ 3 files changed, 26 insertions(+) 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 //---------------------------------------------------------------------------