2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-05-01 22:50:08 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ChildIterator.h"
|
2013-12-02 10:26:12 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-07-01 22:09:37 +00:00
|
|
|
#include "mozilla/dom/XBLChildrenElement.h"
|
2013-12-02 10:26:12 +00:00
|
|
|
#include "mozilla/dom/HTMLContentElement.h"
|
2013-12-21 06:43:58 +00:00
|
|
|
#include "mozilla/dom/HTMLShadowElement.h"
|
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2014-07-16 18:41:57 +00:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
|
|
|
#include "nsIFrame.h"
|
2013-05-01 22:50:08 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
class MatchedNodes {
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit MatchedNodes(HTMLContentElement* aInsertionPoint)
|
2013-12-02 10:26:12 +00:00
|
|
|
: mIsContentElement(true), mContentElement(aInsertionPoint) {}
|
|
|
|
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit MatchedNodes(XBLChildrenElement* aInsertionPoint)
|
2013-12-02 10:26:12 +00:00
|
|
|
: mIsContentElement(false), mChildrenElement(aInsertionPoint) {}
|
|
|
|
|
|
|
|
uint32_t Length() const
|
|
|
|
{
|
|
|
|
return mIsContentElement ? mContentElement->MatchedNodes().Length()
|
2014-06-22 11:53:01 +00:00
|
|
|
: mChildrenElement->InsertedChildrenLength();
|
2013-12-02 10:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* operator[](int32_t aIndex) const
|
|
|
|
{
|
|
|
|
return mIsContentElement ? mContentElement->MatchedNodes()[aIndex]
|
2014-06-22 11:53:01 +00:00
|
|
|
: mChildrenElement->InsertedChild(aIndex);
|
2013-12-02 10:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return mIsContentElement ? mContentElement->MatchedNodes().IsEmpty()
|
2014-06-22 11:53:01 +00:00
|
|
|
: !mChildrenElement->HasInsertedChildren();
|
2013-12-02 10:26:12 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
bool mIsContentElement;
|
|
|
|
union {
|
|
|
|
HTMLContentElement* mContentElement;
|
|
|
|
XBLChildrenElement* mChildrenElement;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline MatchedNodes
|
|
|
|
GetMatchedNodesForPoint(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
|
|
|
|
// XBL case
|
|
|
|
return MatchedNodes(static_cast<XBLChildrenElement*>(aContent));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Web components case
|
2015-03-03 11:08:59 +00:00
|
|
|
MOZ_ASSERT(aContent->IsHTMLElement(nsGkAtoms::content));
|
2013-12-02 10:26:12 +00:00
|
|
|
return MatchedNodes(static_cast<HTMLContentElement*>(aContent));
|
|
|
|
}
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
nsIContent*
|
|
|
|
ExplicitChildIterator::GetNextChild()
|
|
|
|
{
|
|
|
|
// If we're already in the inserted-children array, look there first
|
|
|
|
if (mIndexInInserted) {
|
|
|
|
MOZ_ASSERT(mChild);
|
2013-12-02 10:26:12 +00:00
|
|
|
MOZ_ASSERT(nsContentUtils::IsContentInsertionPoint(mChild));
|
2013-05-01 22:50:08 +00:00
|
|
|
MOZ_ASSERT(!mDefaultChild);
|
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
MatchedNodes assignedChildren = GetMatchedNodesForPoint(mChild);
|
|
|
|
if (mIndexInInserted < assignedChildren.Length()) {
|
|
|
|
return assignedChildren[mIndexInInserted++];
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
mIndexInInserted = 0;
|
|
|
|
mChild = mChild->GetNextSibling();
|
2013-12-21 06:43:58 +00:00
|
|
|
} else if (mShadowIterator) {
|
|
|
|
// If we're inside of a <shadow> element, look through the
|
|
|
|
// explicit children of the projected ShadowRoot via
|
|
|
|
// the mShadowIterator.
|
|
|
|
nsIContent* nextChild = mShadowIterator->GetNextChild();
|
|
|
|
if (nextChild) {
|
|
|
|
return nextChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
mShadowIterator = nullptr;
|
|
|
|
mChild = mChild->GetNextSibling();
|
2013-05-01 22:50:08 +00:00
|
|
|
} else if (mDefaultChild) {
|
|
|
|
// If we're already in default content, check if there are more nodes there
|
|
|
|
MOZ_ASSERT(mChild);
|
2013-12-02 10:26:12 +00:00
|
|
|
MOZ_ASSERT(nsContentUtils::IsContentInsertionPoint(mChild));
|
2013-05-01 22:50:08 +00:00
|
|
|
|
|
|
|
mDefaultChild = mDefaultChild->GetNextSibling();
|
|
|
|
if (mDefaultChild) {
|
|
|
|
return mDefaultChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
mChild = mChild->GetNextSibling();
|
|
|
|
} else if (mIsFirst) { // at the beginning of the child list
|
|
|
|
mChild = mParent->GetFirstChild();
|
|
|
|
mIsFirst = false;
|
|
|
|
} else if (mChild) { // in the middle of the child list
|
|
|
|
mChild = mChild->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
// Iterate until we find a non-insertion point, or an insertion point with
|
|
|
|
// content.
|
2013-12-21 06:43:58 +00:00
|
|
|
while (mChild) {
|
|
|
|
// If the current child being iterated is a shadow insertion point then
|
|
|
|
// the iterator needs to go into the projected ShadowRoot.
|
|
|
|
if (ShadowRoot::IsShadowInsertionPoint(mChild)) {
|
|
|
|
// Look for the next child in the projected ShadowRoot for the <shadow>
|
|
|
|
// element.
|
|
|
|
HTMLShadowElement* shadowElem = static_cast<HTMLShadowElement*>(mChild);
|
|
|
|
ShadowRoot* projectedShadow = shadowElem->GetOlderShadowRoot();
|
|
|
|
if (projectedShadow) {
|
|
|
|
mShadowIterator = new ExplicitChildIterator(projectedShadow);
|
|
|
|
nsIContent* nextChild = mShadowIterator->GetNextChild();
|
|
|
|
if (nextChild) {
|
|
|
|
return nextChild;
|
|
|
|
}
|
|
|
|
mShadowIterator = nullptr;
|
|
|
|
}
|
|
|
|
mChild = mChild->GetNextSibling();
|
|
|
|
} else if (nsContentUtils::IsContentInsertionPoint(mChild)) {
|
|
|
|
// If the current child being iterated is a content insertion point
|
|
|
|
// then the iterator needs to return the nodes distributed into
|
|
|
|
// the content insertion point.
|
|
|
|
MatchedNodes assignedChildren = GetMatchedNodesForPoint(mChild);
|
|
|
|
if (!assignedChildren.IsEmpty()) {
|
|
|
|
// Iterate through elements projected on insertion point.
|
|
|
|
mIndexInInserted = 1;
|
|
|
|
return assignedChildren[0];
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2013-12-21 06:43:58 +00:00
|
|
|
// Insertion points inside fallback/default content
|
|
|
|
// are considered inactive and do not get assigned nodes.
|
|
|
|
mDefaultChild = mChild->GetFirstChild();
|
|
|
|
if (mDefaultChild) {
|
|
|
|
return mDefaultChild;
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2013-12-21 06:43:58 +00:00
|
|
|
// If we have an insertion point with no assigned nodes and
|
|
|
|
// no default content, move on to the next node.
|
|
|
|
mChild = mChild->GetNextSibling();
|
|
|
|
} else {
|
|
|
|
// mChild is not an insertion point, thus it is the next node to
|
|
|
|
// return from this iterator.
|
|
|
|
break;
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mChild;
|
|
|
|
}
|
|
|
|
|
2014-07-16 18:41:57 +00:00
|
|
|
void
|
|
|
|
FlattenedChildIterator::Init(bool aIgnoreXBL)
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
2014-07-16 18:41:57 +00:00
|
|
|
if (aIgnoreXBL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
nsXBLBinding* binding =
|
2014-07-16 18:41:57 +00:00
|
|
|
mParent->OwnerDoc()->BindingManager()->GetBindingWithContent(mParent);
|
2013-05-01 22:50:08 +00:00
|
|
|
|
|
|
|
if (binding) {
|
|
|
|
nsIContent* anon = binding->GetAnonymousContent();
|
|
|
|
if (anon) {
|
|
|
|
mParent = anon;
|
|
|
|
mXBLInvolved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We set mXBLInvolved to true if either:
|
|
|
|
// - The node we're iterating has a binding with content attached to it.
|
|
|
|
// - The node is generated XBL content and has an <xbl:children> child.
|
2014-07-16 18:41:57 +00:00
|
|
|
if (!mXBLInvolved && mParent->GetBindingParent()) {
|
|
|
|
for (nsIContent* child = mParent->GetFirstChild();
|
2013-05-01 22:50:08 +00:00
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
|
2013-07-11 21:52:49 +00:00
|
|
|
MOZ_ASSERT(child->GetBindingParent());
|
2013-05-01 22:50:08 +00:00
|
|
|
mXBLInvolved = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 13:22:39 +00:00
|
|
|
bool
|
2015-09-09 01:23:55 +00:00
|
|
|
ExplicitChildIterator::Seek(nsIContent* aChildToFind)
|
|
|
|
{
|
|
|
|
if (aChildToFind->GetParent() == mParent &&
|
|
|
|
!aChildToFind->IsRootOfAnonymousSubtree()) {
|
|
|
|
// Fast path: just point ourselves to aChildToFind, which is a
|
|
|
|
// normal DOM child of ours.
|
|
|
|
MOZ_ASSERT(!ShadowRoot::IsShadowInsertionPoint(aChildToFind));
|
|
|
|
MOZ_ASSERT(!nsContentUtils::IsContentInsertionPoint(aChildToFind));
|
|
|
|
mChild = aChildToFind;
|
|
|
|
mIndexInInserted = 0;
|
|
|
|
mShadowIterator = nullptr;
|
|
|
|
mDefaultChild = nullptr;
|
|
|
|
mIsFirst = false;
|
2016-02-11 13:22:39 +00:00
|
|
|
return true;
|
2015-09-09 01:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can we add more fast paths here based on whether the parent of aChildToFind
|
|
|
|
// is a shadow insertion point or content insertion point?
|
|
|
|
|
|
|
|
// Slow path: just walk all our kids.
|
2016-02-11 13:22:39 +00:00
|
|
|
return Seek(aChildToFind, nullptr);
|
2015-09-09 01:23:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 06:43:58 +00:00
|
|
|
nsIContent*
|
2016-03-08 20:54:46 +00:00
|
|
|
ExplicitChildIterator::Get() const
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mIsFirst);
|
|
|
|
|
|
|
|
if (mIndexInInserted) {
|
2014-06-05 18:39:25 +00:00
|
|
|
MatchedNodes assignedChildren = GetMatchedNodesForPoint(mChild);
|
|
|
|
return assignedChildren[mIndexInInserted - 1];
|
2013-12-21 06:43:58 +00:00
|
|
|
} else if (mShadowIterator) {
|
|
|
|
return mShadowIterator->Get();
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
return mDefaultChild ? mDefaultChild : mChild;
|
|
|
|
}
|
|
|
|
|
2013-12-21 06:43:58 +00:00
|
|
|
nsIContent*
|
|
|
|
ExplicitChildIterator::GetPreviousChild()
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
// If we're already in the inserted-children array, look there first
|
|
|
|
if (mIndexInInserted) {
|
|
|
|
// NB: mIndexInInserted points one past the last returned child so we need
|
|
|
|
// to look *two* indices back in order to return the previous child.
|
2013-12-02 10:26:12 +00:00
|
|
|
MatchedNodes assignedChildren = GetMatchedNodesForPoint(mChild);
|
2013-05-01 22:50:08 +00:00
|
|
|
if (--mIndexInInserted) {
|
2013-12-02 10:26:12 +00:00
|
|
|
return assignedChildren[mIndexInInserted - 1];
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
mChild = mChild->GetPreviousSibling();
|
2013-12-21 06:43:58 +00:00
|
|
|
} else if (mShadowIterator) {
|
|
|
|
nsIContent* previousChild = mShadowIterator->GetPreviousChild();
|
|
|
|
if (previousChild) {
|
|
|
|
return previousChild;
|
|
|
|
}
|
|
|
|
mShadowIterator = nullptr;
|
|
|
|
mChild = mChild->GetPreviousSibling();
|
2013-05-01 22:50:08 +00:00
|
|
|
} else if (mDefaultChild) {
|
|
|
|
// If we're already in default content, check if there are more nodes there
|
|
|
|
mDefaultChild = mDefaultChild->GetPreviousSibling();
|
|
|
|
if (mDefaultChild) {
|
|
|
|
return mDefaultChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
mChild = mChild->GetPreviousSibling();
|
|
|
|
} else if (mIsFirst) { // at the beginning of the child list
|
|
|
|
return nullptr;
|
|
|
|
} else if (mChild) { // in the middle of the child list
|
|
|
|
mChild = mChild->GetPreviousSibling();
|
|
|
|
} else { // at the end of the child list
|
|
|
|
mChild = mParent->GetLastChild();
|
|
|
|
}
|
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
// Iterate until we find a non-insertion point, or an insertion point with
|
|
|
|
// content.
|
2013-12-21 06:43:58 +00:00
|
|
|
while (mChild) {
|
|
|
|
if (ShadowRoot::IsShadowInsertionPoint(mChild)) {
|
|
|
|
// If the current child being iterated is a shadow insertion point then
|
|
|
|
// the iterator needs to go into the projected ShadowRoot.
|
|
|
|
HTMLShadowElement* shadowElem = static_cast<HTMLShadowElement*>(mChild);
|
|
|
|
ShadowRoot* projectedShadow = shadowElem->GetOlderShadowRoot();
|
|
|
|
if (projectedShadow) {
|
|
|
|
// Create a ExplicitChildIterator that begins iterating from the end.
|
|
|
|
mShadowIterator = new ExplicitChildIterator(projectedShadow, false);
|
|
|
|
nsIContent* previousChild = mShadowIterator->GetPreviousChild();
|
|
|
|
if (previousChild) {
|
|
|
|
return previousChild;
|
|
|
|
}
|
|
|
|
mShadowIterator = nullptr;
|
|
|
|
}
|
|
|
|
mChild = mChild->GetPreviousSibling();
|
|
|
|
} else if (nsContentUtils::IsContentInsertionPoint(mChild)) {
|
|
|
|
// If the current child being iterated is a content insertion point
|
|
|
|
// then the iterator needs to return the nodes distributed into
|
|
|
|
// the content insertion point.
|
|
|
|
MatchedNodes assignedChildren = GetMatchedNodesForPoint(mChild);
|
|
|
|
if (!assignedChildren.IsEmpty()) {
|
|
|
|
mIndexInInserted = assignedChildren.Length();
|
|
|
|
return assignedChildren[mIndexInInserted - 1];
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2013-12-21 06:43:58 +00:00
|
|
|
mDefaultChild = mChild->GetLastChild();
|
|
|
|
if (mDefaultChild) {
|
|
|
|
return mDefaultChild;
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2013-12-21 06:43:58 +00:00
|
|
|
mChild = mChild->GetPreviousSibling();
|
|
|
|
} else {
|
|
|
|
// mChild is not an insertion point, thus it is the next node to
|
|
|
|
// return from this iterator.
|
|
|
|
break;
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mChild) {
|
|
|
|
mIsFirst = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mChild;
|
|
|
|
}
|
|
|
|
|
2016-03-08 20:54:46 +00:00
|
|
|
nsIContent*
|
|
|
|
AllChildrenIterator::Get() const
|
|
|
|
{
|
|
|
|
switch (mPhase) {
|
|
|
|
case eAtBeforeKid: {
|
|
|
|
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
|
|
|
|
MOZ_ASSERT(frame, "No frame at eAtBeforeKid phase");
|
|
|
|
nsIFrame* beforeFrame = nsLayoutUtils::GetBeforeFrame(frame);
|
|
|
|
MOZ_ASSERT(beforeFrame, "No content before frame at eAtBeforeKid phase");
|
|
|
|
return beforeFrame->GetContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
case eAtExplicitKids:
|
|
|
|
return ExplicitChildIterator::Get();
|
|
|
|
|
|
|
|
case eAtAnonKids:
|
|
|
|
return mAnonKids[mAnonKidsIdx];
|
|
|
|
|
|
|
|
case eAtAfterKid: {
|
|
|
|
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
|
|
|
|
MOZ_ASSERT(frame, "No frame at eAtAfterKid phase");
|
|
|
|
nsIFrame* afterFrame = nsLayoutUtils::GetAfterFrame(frame);
|
|
|
|
MOZ_ASSERT(afterFrame, "No content before frame at eAtBeforeKid phase");
|
|
|
|
return afterFrame->GetContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-11 13:22:39 +00:00
|
|
|
bool
|
|
|
|
AllChildrenIterator::Seek(nsIContent* aChildToFind)
|
|
|
|
{
|
2016-03-05 21:11:21 +00:00
|
|
|
if (mPhase == eAtBegin || mPhase == eAtBeforeKid) {
|
|
|
|
mPhase = eAtExplicitKids;
|
2016-02-11 13:22:39 +00:00
|
|
|
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIFrame* beforeFrame = nsLayoutUtils::GetBeforeFrame(frame);
|
|
|
|
if (beforeFrame) {
|
|
|
|
if (beforeFrame->GetContent() == aChildToFind) {
|
2016-03-05 21:11:21 +00:00
|
|
|
mPhase = eAtBeforeKid;
|
2016-02-11 13:22:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 21:11:21 +00:00
|
|
|
if (mPhase == eAtExplicitKids) {
|
2016-02-11 13:22:39 +00:00
|
|
|
if (ExplicitChildIterator::Seek(aChildToFind)) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-05 21:11:21 +00:00
|
|
|
mPhase = eAtAnonKids;
|
2016-02-11 13:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* child = nullptr;
|
|
|
|
do {
|
|
|
|
child = GetNextChild();
|
|
|
|
} while (child && child != aChildToFind);
|
|
|
|
|
|
|
|
return child == aChildToFind;
|
|
|
|
}
|
|
|
|
|
2014-07-16 18:41:57 +00:00
|
|
|
nsIContent*
|
|
|
|
AllChildrenIterator::GetNextChild()
|
|
|
|
{
|
2016-03-05 21:11:21 +00:00
|
|
|
if (mPhase == eAtBegin) {
|
|
|
|
mPhase = eAtExplicitKids;
|
2014-07-16 18:41:57 +00:00
|
|
|
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIFrame* beforeFrame = nsLayoutUtils::GetBeforeFrame(frame);
|
|
|
|
if (beforeFrame) {
|
2016-03-05 21:11:21 +00:00
|
|
|
mPhase = eAtBeforeKid;
|
2014-07-16 18:41:57 +00:00
|
|
|
return beforeFrame->GetContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 21:11:21 +00:00
|
|
|
if (mPhase == eAtBeforeKid) {
|
|
|
|
// Advance into our explicit kids.
|
|
|
|
mPhase = eAtExplicitKids;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPhase == eAtExplicitKids) {
|
2014-07-16 18:41:57 +00:00
|
|
|
nsIContent* kid = ExplicitChildIterator::GetNextChild();
|
|
|
|
if (kid) {
|
|
|
|
return kid;
|
|
|
|
}
|
2016-03-05 21:11:21 +00:00
|
|
|
mPhase = eAtAnonKids;
|
2014-07-16 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 21:11:21 +00:00
|
|
|
if (mPhase == eAtAnonKids) {
|
2014-07-16 18:41:57 +00:00
|
|
|
if (mAnonKids.IsEmpty()) {
|
2016-03-05 21:11:21 +00:00
|
|
|
MOZ_ASSERT(mAnonKidsIdx == UINT32_MAX);
|
2014-07-16 18:41:57 +00:00
|
|
|
nsIAnonymousContentCreator* ac =
|
|
|
|
do_QueryFrame(mOriginalContent->GetPrimaryFrame());
|
|
|
|
if (ac) {
|
|
|
|
ac->AppendAnonymousContentTo(mAnonKids, mFlags);
|
|
|
|
}
|
2016-03-05 21:11:21 +00:00
|
|
|
mAnonKidsIdx = 0;
|
2014-07-16 18:41:57 +00:00
|
|
|
}
|
2016-03-05 21:11:21 +00:00
|
|
|
else {
|
|
|
|
if (mAnonKidsIdx == UINT32_MAX) {
|
|
|
|
mAnonKidsIdx = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mAnonKidsIdx++;
|
2014-07-16 18:41:57 +00:00
|
|
|
}
|
2016-03-05 21:11:21 +00:00
|
|
|
}
|
2014-07-16 18:41:57 +00:00
|
|
|
|
2016-03-05 21:11:21 +00:00
|
|
|
if (mAnonKidsIdx < mAnonKids.Length()) {
|
|
|
|
return mAnonKids[mAnonKidsIdx];
|
2014-07-16 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 21:11:21 +00:00
|
|
|
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIFrame* afterFrame = nsLayoutUtils::GetAfterFrame(frame);
|
|
|
|
if (afterFrame) {
|
|
|
|
mPhase = eAtAfterKid;
|
|
|
|
return afterFrame->GetContent();
|
|
|
|
}
|
|
|
|
}
|
2014-07-16 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 21:11:21 +00:00
|
|
|
mPhase = eAtEnd;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
AllChildrenIterator::GetPreviousChild()
|
|
|
|
{
|
|
|
|
if (mPhase == eAtEnd) {
|
|
|
|
MOZ_ASSERT(mAnonKidsIdx == mAnonKids.Length());
|
|
|
|
mPhase = eAtAnonKids;
|
2014-07-16 18:41:57 +00:00
|
|
|
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIFrame* afterFrame = nsLayoutUtils::GetAfterFrame(frame);
|
|
|
|
if (afterFrame) {
|
2016-03-05 21:11:21 +00:00
|
|
|
mPhase = eAtAfterKid;
|
2014-07-16 18:41:57 +00:00
|
|
|
return afterFrame->GetContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 21:11:21 +00:00
|
|
|
if (mPhase == eAtAfterKid) {
|
|
|
|
mPhase = eAtAnonKids;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPhase == eAtAnonKids) {
|
|
|
|
if (mAnonKids.IsEmpty()) {
|
|
|
|
nsIAnonymousContentCreator* ac =
|
|
|
|
do_QueryFrame(mOriginalContent->GetPrimaryFrame());
|
|
|
|
if (ac) {
|
|
|
|
ac->AppendAnonymousContentTo(mAnonKids, mFlags);
|
|
|
|
mAnonKidsIdx = mAnonKids.Length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If 0 then it turns into UINT32_MAX, which indicates the iterator is
|
|
|
|
// before the anonymous children.
|
|
|
|
--mAnonKidsIdx;
|
|
|
|
if (mAnonKidsIdx < mAnonKids.Length()) {
|
|
|
|
return mAnonKids[mAnonKidsIdx];
|
|
|
|
}
|
|
|
|
mPhase = eAtExplicitKids;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPhase == eAtExplicitKids) {
|
|
|
|
nsIContent* kid = ExplicitChildIterator::GetPreviousChild();
|
|
|
|
if (kid) {
|
|
|
|
return kid;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIFrame* beforeFrame = nsLayoutUtils::GetBeforeFrame(frame);
|
|
|
|
if (beforeFrame) {
|
|
|
|
mPhase = eAtBeforeKid;
|
|
|
|
return beforeFrame->GetContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mPhase = eAtBegin;
|
2014-07-16 18:41:57 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-13 15:25:42 +00:00
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|