2013-05-01 15:50:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=79: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsXBLChildrenElement_h___
|
|
|
|
#define nsXBLChildrenElement_h___
|
|
|
|
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsINodeList.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
#include "mozilla/dom/nsXMLElement.h"
|
|
|
|
|
2013-07-01 15:09:37 -07:00
|
|
|
class nsAnonymousContentList;
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class ExplicitChildIterator;
|
|
|
|
|
2013-07-01 15:09:37 -07:00
|
|
|
class XBLChildrenElement : public nsXMLElement
|
2013-05-01 15:50:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2014-03-15 12:00:17 -07:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2013-05-01 15:50:08 -07:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsINode interface methods
|
2014-06-19 19:01:40 -07:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const;
|
2013-05-01 15:50:08 -07:00
|
|
|
|
|
|
|
virtual nsXPCClassInfo* GetClassInfo() { return nullptr; }
|
|
|
|
|
|
|
|
virtual nsIDOMNode* AsDOMNode() { return this; }
|
|
|
|
|
|
|
|
// nsIContent interface methods
|
|
|
|
virtual nsIAtom *GetIDAttributeName() const;
|
|
|
|
virtual nsIAtom* DoGetID() const;
|
|
|
|
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
bool aNotify);
|
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult);
|
|
|
|
|
2013-07-17 09:05:06 -07:00
|
|
|
void AppendInsertedChild(nsIContent* aChild)
|
2013-05-01 15:50:08 -07:00
|
|
|
{
|
|
|
|
mInsertedChildren.AppendElement(aChild);
|
2013-07-17 09:05:06 -07:00
|
|
|
aChild->SetXBLInsertionParent(GetParent());
|
2014-11-14 17:02:29 -08:00
|
|
|
|
|
|
|
// Appending an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
|
|
|
MaybeRemoveDefaultContent();
|
2013-05-01 15:50:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-17 09:05:06 -07:00
|
|
|
void InsertInsertedChildAt(nsIContent* aChild, uint32_t aIndex)
|
2013-05-01 15:50:08 -07:00
|
|
|
{
|
|
|
|
mInsertedChildren.InsertElementAt(aIndex, aChild);
|
2013-07-17 09:05:06 -07:00
|
|
|
aChild->SetXBLInsertionParent(GetParent());
|
2014-11-14 17:02:29 -08:00
|
|
|
|
|
|
|
// Inserting an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
|
|
|
MaybeRemoveDefaultContent();
|
2013-05-01 15:50:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveInsertedChild(nsIContent* aChild)
|
|
|
|
{
|
|
|
|
// Can't use this assertion as we cheat for dynamic insertions and
|
|
|
|
// only insert in the innermost insertion point.
|
|
|
|
//NS_ASSERTION(mInsertedChildren.Contains(aChild),
|
|
|
|
// "Removing child that's not there");
|
|
|
|
mInsertedChildren.RemoveElement(aChild);
|
2014-11-14 17:02:29 -08:00
|
|
|
|
|
|
|
// After removing the inserted child, default content
|
|
|
|
// may be projected into this insertion point.
|
|
|
|
MaybeSetupDefaultContent();
|
2013-05-01 15:50:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearInsertedChildren()
|
|
|
|
{
|
|
|
|
for (uint32_t c = 0; c < mInsertedChildren.Length(); ++c) {
|
2013-07-17 09:05:06 -07:00
|
|
|
mInsertedChildren[c]->SetXBLInsertionParent(nullptr);
|
2013-05-01 15:50:08 -07:00
|
|
|
}
|
|
|
|
mInsertedChildren.Clear();
|
2014-11-14 17:02:29 -08:00
|
|
|
|
|
|
|
// After clearing inserted children, default content
|
|
|
|
// will be projected into this insertion point.
|
|
|
|
MaybeSetupDefaultContent();
|
2013-05-01 15:50:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-17 09:05:06 -07:00
|
|
|
void MaybeSetupDefaultContent()
|
2013-05-01 15:50:08 -07:00
|
|
|
{
|
|
|
|
if (!HasInsertedChildren()) {
|
|
|
|
for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2013-07-17 09:05:06 -07:00
|
|
|
child->SetXBLInsertionParent(GetParent());
|
2013-05-01 15:50:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:05:06 -07:00
|
|
|
void MaybeRemoveDefaultContent()
|
2013-05-01 15:50:08 -07:00
|
|
|
{
|
|
|
|
if (!HasInsertedChildren()) {
|
|
|
|
for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2013-07-17 09:05:06 -07:00
|
|
|
child->SetXBLInsertionParent(nullptr);
|
2013-05-01 15:50:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t InsertedChildrenLength()
|
|
|
|
{
|
|
|
|
return mInsertedChildren.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasInsertedChildren()
|
|
|
|
{
|
|
|
|
return !mInsertedChildren.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-06-22 04:53:01 -07:00
|
|
|
int32_t IndexOfInsertedChild(nsIContent* aChild)
|
2013-05-01 15:50:08 -07:00
|
|
|
{
|
|
|
|
return mInsertedChildren.IndexOf(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Includes(nsIContent* aChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mIncludes.IsEmpty(),
|
|
|
|
"Shouldn't check for includes on default insertion point");
|
|
|
|
return mIncludes.Contains(aChild->Tag());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDefaultInsertion()
|
|
|
|
{
|
|
|
|
return mIncludes.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-06-22 04:53:01 -07:00
|
|
|
nsIContent* InsertedChild(uint32_t aIndex)
|
|
|
|
{
|
|
|
|
return mInsertedChildren[aIndex];
|
|
|
|
}
|
2013-05-01 15:50:08 -07:00
|
|
|
|
2014-07-08 14:23:17 -07:00
|
|
|
protected:
|
|
|
|
~XBLChildrenElement();
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
private:
|
2014-06-22 04:53:01 -07:00
|
|
|
nsTArray<nsIContent*> mInsertedChildren; // WEAK
|
2013-05-01 15:50:08 -07:00
|
|
|
nsTArray<nsCOMPtr<nsIAtom> > mIncludes;
|
|
|
|
};
|
|
|
|
|
2013-07-01 15:09:37 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
class nsAnonymousContentList : public nsINodeList
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit nsAnonymousContentList(nsIContent* aParent)
|
2013-05-01 15:50:08 -07:00
|
|
|
: mParent(aParent)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAnonymousContentList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList)
|
|
|
|
// nsIDOMNodeList interface
|
|
|
|
NS_DECL_NSIDOMNODELIST
|
|
|
|
|
|
|
|
// nsINodeList interface
|
|
|
|
virtual int32_t IndexOf(nsIContent* aContent);
|
|
|
|
virtual nsINode* GetParentObject() { return mParent; }
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex);
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
|
2013-05-01 15:50:08 -07:00
|
|
|
|
|
|
|
bool IsListFor(nsIContent* aContent) {
|
|
|
|
return mParent == aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-23 12:56:07 -07:00
|
|
|
virtual ~nsAnonymousContentList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsAnonymousContentList);
|
|
|
|
}
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
nsCOMPtr<nsIContent> mParent;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXBLChildrenElement_h___
|