From 14bc521edaf1fdd652fb0ef80cc57d50ca786bb8 Mon Sep 17 00:00:00 2001 From: manas Date: Tue, 23 Jun 2020 18:51:32 +0000 Subject: [PATCH] Bug 1639893 Part 1 - Partial Imlementation of GetOverflowingChildrenOfElement. r=bradwerth,emilio Differential Revision: https://phabricator.services.mozilla.com/D80216 --- dom/chrome-webidl/InspectorUtils.webidl | 2 ++ layout/inspector/InspectorUtils.cpp | 27 +++++++++++++++++++++++++ layout/inspector/InspectorUtils.h | 3 +++ 3 files changed, 32 insertions(+) diff --git a/dom/chrome-webidl/InspectorUtils.webidl b/dom/chrome-webidl/InspectorUtils.webidl index 437f53629250..8af0f2752dd5 100644 --- a/dom/chrome-webidl/InspectorUtils.webidl +++ b/dom/chrome-webidl/InspectorUtils.webidl @@ -80,6 +80,8 @@ namespace InspectorUtils { boolean isElementThemed(Element element); Element? containingBlockOf(Element element); + + [NewObject] NodeList getOverflowingChildrenOfElement(Element element); }; dictionary PropertyNamesOptions { diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index 0cdc005238b3..329bdc137449 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -703,5 +703,32 @@ Element* InspectorUtils::ContainingBlockOf(GlobalObject&, Element& aElement) { return Element::FromNodeOrNull(cb->GetContent()); } +already_AddRefed InspectorUtils::GetOverflowingChildrenOfElement( + GlobalObject& aGlobal, Element& aElement) { + RefPtr list = new nsSimpleContentList(&aElement); + nsIFrame* scrollableFrame = aElement.GetPrimaryFrame(); + + std::function GetOverflowingElement = + [&](const nsIFrame* aFrame) { + MOZ_ASSERT(aFrame, "we assume the passed-in frame is non-null"); + for (const auto& childList : aFrame->ChildLists()) { + for (const nsIFrame* child : childList.mList) { + bool isBlameElem = true; // change this so that it becomes true iff + // child is causing overflow. + if (!isBlameElem) { + GetOverflowingElement(child); + } else { + list->AppendElement(child->GetContent()); + } + } + } + }; + + if (scrollableFrame) { + GetOverflowingElement(scrollableFrame); + } + return list.forget(); +} + } // namespace dom } // namespace mozilla diff --git a/layout/inspector/InspectorUtils.h b/layout/inspector/InspectorUtils.h index 1463f1448b2c..87d8ec5e70b1 100644 --- a/layout/inspector/InspectorUtils.h +++ b/layout/inspector/InspectorUtils.h @@ -238,6 +238,9 @@ class InspectorUtils { static Element* ContainingBlockOf(GlobalObject&, Element&); + static already_AddRefed GetOverflowingChildrenOfElement( + GlobalObject& aGlobal, Element& element); + /** * Parse CSS and update the style sheet in place. *