Bug 1371130: Expose AllChildrenIterator::AppendNativeAnonymousChildren. r?heycam
MozReview-Commit-ID: E5kfdxEWTuf
--- a/dom/base/ChildIterator.cpp
+++ b/dom/base/ChildIterator.cpp
@@ -365,45 +365,18 @@ AllChildrenIterator::Seek(nsIContent* aC
} while (child && child != aChildToFind);
return child == aChildToFind;
}
void
AllChildrenIterator::AppendNativeAnonymousChildren()
{
- if (nsIFrame* primaryFrame = mOriginalContent->GetPrimaryFrame()) {
- // NAC created by the element's primary frame.
- AppendNativeAnonymousChildrenFromFrame(primaryFrame);
-
- // NAC created by any other non-primary frames for the element.
- AutoTArray<nsIFrame::OwnedAnonBox,8> ownedAnonBoxes;
- primaryFrame->AppendOwnedAnonBoxes(ownedAnonBoxes);
- for (nsIFrame::OwnedAnonBox& box : ownedAnonBoxes) {
- MOZ_ASSERT(box.mAnonBoxFrame->GetContent() == mOriginalContent);
- AppendNativeAnonymousChildrenFromFrame(box.mAnonBoxFrame);
- }
- }
-
- // The root scroll frame is not the primary frame of the root element.
- // Detect and handle this case.
- if (!(mFlags & nsIContent::eSkipDocumentLevelNativeAnonymousContent) &&
- mOriginalContent == mOriginalContent->OwnerDoc()->GetRootElement()) {
- nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(
- mOriginalContent->OwnerDoc(), mAnonKids);
- }
-}
-
-void
-AllChildrenIterator::AppendNativeAnonymousChildrenFromFrame(nsIFrame* aFrame)
-{
- nsIAnonymousContentCreator* ac = do_QueryFrame(aFrame);
- if (ac) {
- ac->AppendAnonymousContentTo(mAnonKids, mFlags);
- }
+ nsContentUtils::AppendNativeAnonymousChildren(
+ mOriginalContent, mAnonKids, mFlags);
}
nsIContent*
AllChildrenIterator::GetNextChild()
{
if (mPhase == eAtBegin) {
mPhase = eAtExplicitKids;
Element* beforeContent = nsLayoutUtils::GetBeforePseudo(mOriginalContent);
@@ -537,17 +510,16 @@ StyleChildrenIterator::IsNeeded(const El
nsIAnonymousContentCreator* ac = do_QueryFrame(aElement->GetPrimaryFrame());
if (ac) {
return true;
}
return false;
}
-
nsIContent*
StyleChildrenIterator::GetNextChild()
{
return AllChildrenIterator::GetNextChild();
}
} // namespace dom
} // namespace mozilla
--- a/dom/base/ChildIterator.h
+++ b/dom/base/ChildIterator.h
@@ -226,18 +226,16 @@ public:
eAtAfterKid,
eAtEnd
};
IteratorPhase Phase() const { return mPhase; }
private:
// Helpers.
void AppendNativeAnonymousChildren();
- void AppendNativeAnonymousChildrenFromFrame(nsIFrame* aFrame);
-
const nsIContent* mOriginalContent;
// mAnonKids is an array of native anonymous children, mAnonKidsIdx is index
// in the array. If mAnonKidsIdx < mAnonKids.Length() and mPhase is
// eAtAnonKids then the iterator points at a child at mAnonKidsIdx index. If
// mAnonKidsIdx == mAnonKids.Length() then the iterator is somewhere after
// the last native anon child. If mAnonKidsIdx == UINT32_MAX then the iterator
// is somewhere before the first native anon child.
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -10183,16 +10183,55 @@ nsContentUtils::AppendDocumentLevelNativ
if (nsCanvasFrame* canvasFrame = presShell->GetCanvasFrame()) {
if (Element* container = canvasFrame->GetCustomContentContainer()) {
aElements.AppendElement(container);
}
}
}
}
+static void
+AppendNativeAnonymousChildrenFromFrame(
+ nsIFrame* aFrame,
+ nsTArray<nsIContent*>& aKids,
+ uint32_t aFlags)
+{
+ if (nsIAnonymousContentCreator* ac = do_QueryFrame(aFrame)) {
+ ac->AppendAnonymousContentTo(aKids, aFlags);
+ }
+}
+
+/* static */ void
+nsContentUtils::AppendNativeAnonymousChildren(
+ const nsIContent* aContent,
+ nsTArray<nsIContent*>& aKids,
+ uint32_t aFlags)
+{
+ if (nsIFrame* primaryFrame = aContent->GetPrimaryFrame()) {
+ // NAC created by the element's primary frame.
+ AppendNativeAnonymousChildrenFromFrame(primaryFrame, aKids, aFlags);
+
+ // NAC created by any other non-primary frames for the element.
+ AutoTArray<nsIFrame::OwnedAnonBox, 8> ownedAnonBoxes;
+ primaryFrame->AppendOwnedAnonBoxes(ownedAnonBoxes);
+ for (nsIFrame::OwnedAnonBox& box : ownedAnonBoxes) {
+ MOZ_ASSERT(box.mAnonBoxFrame->GetContent() == aContent);
+ AppendNativeAnonymousChildrenFromFrame(box.mAnonBoxFrame, aKids, aFlags);
+ }
+ }
+
+ // The root scroll frame is not the primary frame of the root element.
+ // Detect and handle this case.
+ if (!(aFlags & nsIContent::eSkipDocumentLevelNativeAnonymousContent) &&
+ aContent == aContent->OwnerDoc()->GetRootElement()) {
+ AppendDocumentLevelNativeAnonymousContentTo(aContent->OwnerDoc(), aKids);
+ }
+}
+
+
/* static */ void
nsContentUtils::GetContentPolicyTypeForUIImageLoading(nsIContent* aLoadingNode,
nsIPrincipal** aLoadingPrincipal,
nsContentPolicyType& aContentPolicyType)
{
// Use the serialized loadingPrincipal from the image element. Fall back
// to mContent's principal (SystemPrincipal) if not available.
aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2871,16 +2871,26 @@ public:
* by ancestor frames of the document element's primary frame, such as
* the scrollbar elements created by the root scroll frame.
*/
static void AppendDocumentLevelNativeAnonymousContentTo(
nsIDocument* aDocument,
nsTArray<nsIContent*>& aElements);
/**
+ * Appends all native anonymous content subtree roots generated by `aContent`
+ * to `aKids`.
+ *
+ * See `AllChildrenIterator` for the description of the `aFlags` parameter.
+ */
+ static void AppendNativeAnonymousChildren(const nsIContent* aContent,
+ nsTArray<nsIContent*>& aKids,
+ uint32_t aFlags);
+
+ /**
* Returns the content policy type that should be used for loading images
* for displaying in the UI. The sources of such images can be <xul:image>,
* <xul:menuitem> on OSX where we load the image through nsMenuItemIconX, etc.
*/
static void
GetContentPolicyTypeForUIImageLoading(nsIContent* aLoadingNode,
nsIPrincipal** aLoadingPrincipal,
nsContentPolicyType& aContentPolicyType);