From 8d8da66f9400e8929e7bd6051d785bbdd02c6340 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Mon, 18 Apr 2022 23:11:06 +0800 Subject: Issue #1873 - Part 1: Introduce ParentForUndisplayedMap helper method This introduces the `ParentForUndisplayedMap` helper method to reduce duplication in terms of getting the parent and asserting parent existence. Partially based on parts of https://bugzilla.mozilla.org/show_bug.cgi?id=1341083 --- layout/base/nsFrameManager.cpp | 21 +++++++++++++++------ layout/base/nsFrameManager.h | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'layout') diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index d6a6cb46b5..df91e65fae 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -131,6 +131,17 @@ nsFrameManager::Destroy() //---------------------------------------------------------------------- +/* static */ nsIContent* +nsFrameManager::ParentForUndisplayedMap(const nsIContent* aContent) +{ + MOZ_ASSERT(aContent); + + nsIContent* parent = aContent->GetParentElementCrossingShadowRoot(); + MOZ_ASSERT(parent || !aContent->GetParent(), "no non-elements"); + + return parent; +} + /* static */ nsStyleContext* nsFrameManager::GetStyleContextInMap(UndisplayedMap* aMap, const nsIContent* aContent) @@ -138,8 +149,8 @@ nsFrameManager::GetStyleContextInMap(UndisplayedMap* aMap, if (!aContent) { return nullptr; } - nsIContent* parent = aContent->GetParentElementCrossingShadowRoot(); - MOZ_ASSERT(parent || !aContent->GetParent(), "no non-elements"); + + nsIContent* parent = ParentForUndisplayedMap(aContent); for (UndisplayedNode* node = aMap->GetFirstNode(parent); node; node = node->getNext()) { if (node->mContent == aContent) @@ -178,8 +189,7 @@ nsFrameManager::SetStyleContextInMap(UndisplayedMap* aMap, MOZ_ASSERT(!GetStyleContextInMap(aMap, aContent), "Already have an entry for aContent"); - nsIContent* parent = aContent->GetParentElementCrossingShadowRoot(); - MOZ_ASSERT(parent || !aContent->GetParent(), "no non-elements"); + nsIContent* parent = ParentForUndisplayedMap(aContent); #ifdef DEBUG nsIPresShell* shell = aStyleContext->PresContext()->PresShell(); NS_ASSERTION(parent || (shell && shell->GetDocument() && @@ -223,8 +233,7 @@ nsFrameManager::ChangeStyleContextInMap(UndisplayedMap* aMap, printf("ChangeStyleContextInMap(%d): p=%p \n", i++, (void *)aContent); #endif - nsIContent* parent = aContent->GetParentElementCrossingShadowRoot(); - MOZ_ASSERT(parent || !aContent->GetParent(), "no non-elements"); + nsIContent* parent = ParentForUndisplayedMap(aContent); for (UndisplayedNode* node = aMap->GetFirstNode(parent); node; node = node->getNext()) { diff --git a/layout/base/nsFrameManager.h b/layout/base/nsFrameManager.h index 7537888605..77484fe3f0 100644 --- a/layout/base/nsFrameManager.h +++ b/layout/base/nsFrameManager.h @@ -182,6 +182,8 @@ public: void RestoreFrameStateFor(nsIFrame* aFrame, nsILayoutHistoryState* aState); protected: + static nsIContent* ParentForUndisplayedMap(const nsIContent* aContent); + void ClearAllMapsFor(nsIContent* aParentContent); static nsStyleContext* GetStyleContextInMap(UndisplayedMap* aMap, -- cgit v1.2.3