1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

Issue #2135 - Bug 1455891/Part 1: Improve StyleChildrenIterator

This commit is contained in:
FranklinDM
2023-03-04 11:02:56 +08:00
committed by roytam1
parent 588c2154a5
commit 263b719ef8
2 changed files with 51 additions and 34 deletions
-18
View File
@@ -536,23 +536,5 @@ StyleChildrenIterator::IsNeeded(const Element* aElement)
return false;
}
nsIContent*
StyleChildrenIterator::GetNextChild()
{
while (nsIContent* child = AllChildrenIterator::GetNextChild()) {
if (IsNativeAnonymousImplementationOfPseudoElement(child)) {
// Skip any native-anonymous children that are used to implement pseudo-
// elements. These match pseudo-element selectors instead of being
// considered a child of their host, and thus the style system needs to
// handle them separately.
} else {
return child;
}
}
return nullptr;
}
} // namespace dom
} // namespace mozilla
+51 -16
View File
@@ -7,6 +7,8 @@
#define ChildIterator_h
#include "nsIContent.h"
#include "nsIContentInlines.h"
#include <stdint.h>
/**
* Iterates over the children on a node. If a child is an insertion point,
@@ -17,9 +19,6 @@
* binding's <xbl:content> element.
*/
#include <stdint.h>
#include "nsAutoPtr.h"
class nsIContent;
namespace mozilla {
@@ -189,20 +188,33 @@ protected:
class AllChildrenIterator : private FlattenedChildIterator
{
public:
AllChildrenIterator(const nsIContent* aNode, uint32_t aFlags,
bool aStartAtBeginning = true) :
FlattenedChildIterator(aNode, aFlags, aStartAtBeginning),
mAnonKidsIdx(aStartAtBeginning ? UINT32_MAX : 0),
mFlags(aFlags), mPhase(aStartAtBeginning ? eAtBegin : eAtEnd) { }
AllChildrenIterator(const nsIContent* aNode,
uint32_t aFlags,
bool aStartAtBeginning = true)
: FlattenedChildIterator(aNode, aFlags, aStartAtBeginning)
, mAnonKidsIdx(aStartAtBeginning ? UINT32_MAX : 0)
, mFlags(aFlags), mPhase(aStartAtBeginning ? eAtBegin : eAtEnd)
{
}
AllChildrenIterator(AllChildrenIterator&& aOther)
: FlattenedChildIterator(Move(aOther)),
mAnonKids(Move(aOther.mAnonKids)), mAnonKidsIdx(aOther.mAnonKidsIdx),
mFlags(aOther.mFlags), mPhase(aOther.mPhase)
: FlattenedChildIterator(Move(aOther))
, mAnonKids(Move(aOther.mAnonKids))
, mAnonKidsIdx(aOther.mAnonKidsIdx)
, mFlags(aOther.mFlags)
, mPhase(aOther.mPhase)
#ifdef DEBUG
, mMutationGuard(aOther.mMutationGuard)
, mMutationGuard(aOther.mMutationGuard)
#endif
{}
{
}
AllChildrenIterator& operator=(AllChildrenIterator&& aOther)
{
this->~AllChildrenIterator();
new (this)AllChildrenIterator(Move(aOther));
return *this;
}
#ifdef DEBUG
~AllChildrenIterator() { MOZ_ASSERT(!mMutationGuard.Mutated(0)); }
@@ -268,20 +280,43 @@ private:
*/
class StyleChildrenIterator : private AllChildrenIterator {
public:
explicit StyleChildrenIterator(const nsIContent* aContent)
StyleChildrenIterator(const nsIContent* aContent,
bool aStartAtBeginning = true)
: AllChildrenIterator(aContent,
nsIContent::eAllChildren |
nsIContent::eSkipDocumentLevelNativeAnonymousContent)
nsIContent::eSkipDocumentLevelNativeAnonymousContent,
aStartAtBeginning)
{
MOZ_COUNT_CTOR(StyleChildrenIterator);
}
StyleChildrenIterator(StyleChildrenIterator&& aOther)
: AllChildrenIterator(Move(aOther))
{
MOZ_COUNT_CTOR(StyleChildrenIterator);
}
StyleChildrenIterator& operator=(StyleChildrenIterator&& aOther)
{
AllChildrenIterator::operator=(Move(aOther));
return *this;
}
~StyleChildrenIterator() { MOZ_COUNT_DTOR(StyleChildrenIterator); }
nsIContent* GetNextChild();
static nsIContent* GetParent(const nsIContent& aContent)
{
nsINode* node = aContent.GetFlattenedTreeParentNodeForStyle();
return node && node->IsContent() ? node->AsContent() : nullptr;
}
// Returns true if we cannot find all the children we need to style by
// traversing the siblings of the first child.
static bool IsNeeded(const Element* aParent);
using AllChildrenIterator::GetNextChild;
using AllChildrenIterator::GetPreviousChild;
using AllChildrenIterator::Seek;
};
} // namespace dom