1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=79: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsXBLChildrenElement_h___
8 #define nsXBLChildrenElement_h___
10 #include "nsIDOMElement.h"
11 #include "nsINodeList.h"
12 #include "nsBindingManager.h"
13 #include "mozilla/dom/nsXMLElement.h"
15 class nsAnonymousContentList
;
20 class ExplicitChildIterator
;
22 class XBLChildrenElement
: public nsXMLElement
25 explicit XBLChildrenElement(already_AddRefed
<mozilla::dom::NodeInfo
>& aNodeInfo
)
26 : nsXMLElement(aNodeInfo
)
29 explicit XBLChildrenElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
30 : nsXMLElement(aNodeInfo
)
35 NS_DECL_ISUPPORTS_INHERITED
37 // nsINode interface methods
38 virtual nsresult
Clone(mozilla::dom::NodeInfo
*aNodeInfo
, nsINode
**aResult
) const;
40 virtual nsXPCClassInfo
* GetClassInfo() { return nullptr; }
42 virtual nsIDOMNode
* AsDOMNode() { return this; }
44 // nsIContent interface methods
45 virtual nsIAtom
*GetIDAttributeName() const;
46 virtual nsIAtom
* DoGetID() const;
47 virtual nsresult
UnsetAttr(int32_t aNameSpaceID
, nsIAtom
* aAttribute
,
49 virtual bool ParseAttribute(int32_t aNamespaceID
,
51 const nsAString
& aValue
,
52 nsAttrValue
& aResult
);
54 void AppendInsertedChild(nsIContent
* aChild
)
56 mInsertedChildren
.AppendElement(aChild
);
57 aChild
->SetXBLInsertionParent(GetParent());
60 void InsertInsertedChildAt(nsIContent
* aChild
, uint32_t aIndex
)
62 mInsertedChildren
.InsertElementAt(aIndex
, aChild
);
63 aChild
->SetXBLInsertionParent(GetParent());
66 void RemoveInsertedChild(nsIContent
* aChild
)
68 // Can't use this assertion as we cheat for dynamic insertions and
69 // only insert in the innermost insertion point.
70 //NS_ASSERTION(mInsertedChildren.Contains(aChild),
71 // "Removing child that's not there");
72 mInsertedChildren
.RemoveElement(aChild
);
75 void ClearInsertedChildren()
77 for (uint32_t c
= 0; c
< mInsertedChildren
.Length(); ++c
) {
78 mInsertedChildren
[c
]->SetXBLInsertionParent(nullptr);
80 mInsertedChildren
.Clear();
83 void MaybeSetupDefaultContent()
85 if (!HasInsertedChildren()) {
86 for (nsIContent
* child
= static_cast<nsINode
*>(this)->GetFirstChild();
88 child
= child
->GetNextSibling()) {
89 child
->SetXBLInsertionParent(GetParent());
94 void MaybeRemoveDefaultContent()
96 if (!HasInsertedChildren()) {
97 for (nsIContent
* child
= static_cast<nsINode
*>(this)->GetFirstChild();
99 child
= child
->GetNextSibling()) {
100 child
->SetXBLInsertionParent(nullptr);
105 uint32_t InsertedChildrenLength()
107 return mInsertedChildren
.Length();
110 bool HasInsertedChildren()
112 return !mInsertedChildren
.IsEmpty();
115 int32_t IndexOfInsertedChild(nsIContent
* aChild
)
117 return mInsertedChildren
.IndexOf(aChild
);
120 bool Includes(nsIContent
* aChild
)
122 NS_ASSERTION(!mIncludes
.IsEmpty(),
123 "Shouldn't check for includes on default insertion point");
124 return mIncludes
.Contains(aChild
->Tag());
127 bool IsDefaultInsertion()
129 return mIncludes
.IsEmpty();
132 nsIContent
* InsertedChild(uint32_t aIndex
)
134 return mInsertedChildren
[aIndex
];
138 ~XBLChildrenElement();
141 nsTArray
<nsIContent
*> mInsertedChildren
; // WEAK
142 nsTArray
<nsCOMPtr
<nsIAtom
> > mIncludes
;
146 } // namespace mozilla
148 class nsAnonymousContentList
: public nsINodeList
151 explicit nsAnonymousContentList(nsIContent
* aParent
)
154 MOZ_COUNT_CTOR(nsAnonymousContentList
);
158 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
159 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList
)
160 // nsIDOMNodeList interface
161 NS_DECL_NSIDOMNODELIST
163 // nsINodeList interface
164 virtual int32_t IndexOf(nsIContent
* aContent
);
165 virtual nsINode
* GetParentObject() { return mParent
; }
166 virtual nsIContent
* Item(uint32_t aIndex
);
168 virtual JSObject
* WrapObject(JSContext
*cx
) MOZ_OVERRIDE
;
170 bool IsListFor(nsIContent
* aContent
) {
171 return mParent
== aContent
;
175 virtual ~nsAnonymousContentList()
177 MOZ_COUNT_DTOR(nsAnonymousContentList
);
180 nsCOMPtr
<nsIContent
> mParent
;
183 #endif // nsXBLChildrenElement_h___