2013-05-02 02:50:08 +04: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-02 02:09:37 +04:00
|
|
|
class nsAnonymousContentList;
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class ExplicitChildIterator;
|
|
|
|
|
2013-07-02 02:09:37 +04:00
|
|
|
class XBLChildrenElement : public nsXMLElement
|
2013-05-02 02:50:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2014-03-15 23:00:17 +04:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2013-05-02 02:50:08 +04:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsINode interface methods
|
2014-06-20 06:01:40 +04:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const;
|
2013-05-02 02:50:08 +04: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 20:05:06 +04:00
|
|
|
void AppendInsertedChild(nsIContent* aChild)
|
2013-05-02 02:50:08 +04:00
|
|
|
{
|
|
|
|
mInsertedChildren.AppendElement(aChild);
|
2013-07-17 20:05:06 +04:00
|
|
|
aChild->SetXBLInsertionParent(GetParent());
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
|
2013-07-17 20:05:06 +04:00
|
|
|
void InsertInsertedChildAt(nsIContent* aChild, uint32_t aIndex)
|
2013-05-02 02:50:08 +04:00
|
|
|
{
|
|
|
|
mInsertedChildren.InsertElementAt(aIndex, aChild);
|
2013-07-17 20:05:06 +04:00
|
|
|
aChild->SetXBLInsertionParent(GetParent());
|
2013-05-02 02:50:08 +04: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearInsertedChildren()
|
|
|
|
{
|
|
|
|
for (uint32_t c = 0; c < mInsertedChildren.Length(); ++c) {
|
2013-07-17 20:05:06 +04:00
|
|
|
mInsertedChildren[c]->SetXBLInsertionParent(nullptr);
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
mInsertedChildren.Clear();
|
|
|
|
}
|
|
|
|
|
2013-07-17 20:05:06 +04:00
|
|
|
void MaybeSetupDefaultContent()
|
2013-05-02 02:50:08 +04:00
|
|
|
{
|
|
|
|
if (!HasInsertedChildren()) {
|
|
|
|
for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2013-07-17 20:05:06 +04:00
|
|
|
child->SetXBLInsertionParent(GetParent());
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 20:05:06 +04:00
|
|
|
void MaybeRemoveDefaultContent()
|
2013-05-02 02:50:08 +04:00
|
|
|
{
|
|
|
|
if (!HasInsertedChildren()) {
|
|
|
|
for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2013-07-17 20:05:06 +04:00
|
|
|
child->SetXBLInsertionParent(nullptr);
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t InsertedChildrenLength()
|
|
|
|
{
|
|
|
|
return mInsertedChildren.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasInsertedChildren()
|
|
|
|
{
|
|
|
|
return !mInsertedChildren.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-06-22 15:53:01 +04:00
|
|
|
int32_t IndexOfInsertedChild(nsIContent* aChild)
|
2013-05-02 02:50:08 +04: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 15:53:01 +04:00
|
|
|
nsIContent* InsertedChild(uint32_t aIndex)
|
|
|
|
{
|
|
|
|
return mInsertedChildren[aIndex];
|
|
|
|
}
|
2013-05-02 02:50:08 +04:00
|
|
|
|
2014-07-09 01:23:17 +04:00
|
|
|
protected:
|
|
|
|
~XBLChildrenElement();
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
private:
|
2014-06-22 15:53:01 +04:00
|
|
|
nsTArray<nsIContent*> mInsertedChildren; // WEAK
|
2013-05-02 02:50:08 +04:00
|
|
|
nsTArray<nsCOMPtr<nsIAtom> > mIncludes;
|
|
|
|
};
|
|
|
|
|
2013-07-02 02:09:37 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
class nsAnonymousContentList : public nsINodeList
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsAnonymousContentList(nsIContent* aParent)
|
2013-05-02 02:50:08 +04:00
|
|
|
: mParent(aParent)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAnonymousContentList);
|
|
|
|
SetIsDOMBinding();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09 02:27:18 +04:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
|
2013-05-02 02:50:08 +04:00
|
|
|
|
|
|
|
bool IsListFor(nsIContent* aContent) {
|
|
|
|
return mParent == aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~nsAnonymousContentList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsAnonymousContentList);
|
|
|
|
}
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
nsCOMPtr<nsIContent> mParent;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXBLChildrenElement_h___
|