Bumping manifests a=b2g-bump
[gecko.git] / dom / xbl / XBLChildrenElement.h
blobfa07c248ce9ff8c0b1f450510c97f2a405f0539d
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;
17 namespace mozilla {
18 namespace dom {
20 class ExplicitChildIterator;
22 class XBLChildrenElement : public nsXMLElement
24 public:
25 explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
26 : nsXMLElement(aNodeInfo)
29 explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
30 : nsXMLElement(aNodeInfo)
34 // nsISupports
35 NS_DECL_ISUPPORTS_INHERITED
37 // nsINode interface methods
38 virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const MOZ_OVERRIDE;
40 virtual nsIDOMNode* AsDOMNode() MOZ_OVERRIDE { return this; }
42 // nsIContent interface methods
43 virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
44 bool aNotify) MOZ_OVERRIDE;
45 virtual bool ParseAttribute(int32_t aNamespaceID,
46 nsIAtom* aAttribute,
47 const nsAString& aValue,
48 nsAttrValue& aResult) MOZ_OVERRIDE;
50 void AppendInsertedChild(nsIContent* aChild)
52 mInsertedChildren.AppendElement(aChild);
53 aChild->SetXBLInsertionParent(GetParent());
55 // Appending an inserted child causes the inserted
56 // children to be projected instead of default content.
57 MaybeRemoveDefaultContent();
60 void InsertInsertedChildAt(nsIContent* aChild, uint32_t aIndex)
62 mInsertedChildren.InsertElementAt(aIndex, aChild);
63 aChild->SetXBLInsertionParent(GetParent());
65 // Inserting an inserted child causes the inserted
66 // children to be projected instead of default content.
67 MaybeRemoveDefaultContent();
70 void RemoveInsertedChild(nsIContent* aChild)
72 // Can't use this assertion as we cheat for dynamic insertions and
73 // only insert in the innermost insertion point.
74 //NS_ASSERTION(mInsertedChildren.Contains(aChild),
75 // "Removing child that's not there");
76 mInsertedChildren.RemoveElement(aChild);
78 // After removing the inserted child, default content
79 // may be projected into this insertion point.
80 MaybeSetupDefaultContent();
83 void ClearInsertedChildren()
85 for (uint32_t c = 0; c < mInsertedChildren.Length(); ++c) {
86 mInsertedChildren[c]->SetXBLInsertionParent(nullptr);
88 mInsertedChildren.Clear();
90 // After clearing inserted children, default content
91 // will be projected into this insertion point.
92 MaybeSetupDefaultContent();
95 void MaybeSetupDefaultContent()
97 if (!HasInsertedChildren()) {
98 for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
99 child;
100 child = child->GetNextSibling()) {
101 child->SetXBLInsertionParent(GetParent());
106 void MaybeRemoveDefaultContent()
108 if (!HasInsertedChildren()) {
109 for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
110 child;
111 child = child->GetNextSibling()) {
112 child->SetXBLInsertionParent(nullptr);
117 uint32_t InsertedChildrenLength()
119 return mInsertedChildren.Length();
122 bool HasInsertedChildren()
124 return !mInsertedChildren.IsEmpty();
127 int32_t IndexOfInsertedChild(nsIContent* aChild)
129 return mInsertedChildren.IndexOf(aChild);
132 bool Includes(nsIContent* aChild)
134 NS_ASSERTION(!mIncludes.IsEmpty(),
135 "Shouldn't check for includes on default insertion point");
136 return mIncludes.Contains(aChild->Tag());
139 bool IsDefaultInsertion()
141 return mIncludes.IsEmpty();
144 nsIContent* InsertedChild(uint32_t aIndex)
146 return mInsertedChildren[aIndex];
149 protected:
150 ~XBLChildrenElement();
152 private:
153 nsTArray<nsIContent*> mInsertedChildren; // WEAK
154 nsTArray<nsCOMPtr<nsIAtom> > mIncludes;
157 } // namespace dom
158 } // namespace mozilla
160 class nsAnonymousContentList : public nsINodeList
162 public:
163 explicit nsAnonymousContentList(nsIContent* aParent)
164 : mParent(aParent)
166 MOZ_COUNT_CTOR(nsAnonymousContentList);
169 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
170 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList)
171 // nsIDOMNodeList interface
172 NS_DECL_NSIDOMNODELIST
174 // nsINodeList interface
175 virtual int32_t IndexOf(nsIContent* aContent) MOZ_OVERRIDE;
176 virtual nsINode* GetParentObject() MOZ_OVERRIDE { return mParent; }
177 virtual nsIContent* Item(uint32_t aIndex) MOZ_OVERRIDE;
179 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
181 bool IsListFor(nsIContent* aContent) {
182 return mParent == aContent;
185 private:
186 virtual ~nsAnonymousContentList()
188 MOZ_COUNT_DTOR(nsAnonymousContentList);
191 nsCOMPtr<nsIContent> mParent;
194 #endif // nsXBLChildrenElement_h___