2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-05-01 22:50:08 +00:00
|
|
|
/* 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 22:09:37 +00:00
|
|
|
class nsAnonymousContentList;
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-07-01 22:09:37 +00:00
|
|
|
class XBLChildrenElement : public nsXMLElement
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2014-03-15 19:00:17 +00:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit XBLChildrenElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2013-05-01 22:50:08 +00:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsINode interface methods
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsIDOMNode* AsDOMNode() override { return this; }
|
2013-05-01 22:50:08 +00:00
|
|
|
|
|
|
|
// nsIContent interface methods
|
|
|
|
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aNotify) override;
|
2013-05-01 22:50:08 +00:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsAttrValue& aResult) override;
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2013-07-17 16:05:06 +00:00
|
|
|
void AppendInsertedChild(nsIContent* aChild)
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
mInsertedChildren.AppendElement(aChild);
|
2013-07-17 16:05:06 +00:00
|
|
|
aChild->SetXBLInsertionParent(GetParent());
|
2014-11-15 01:02:29 +00:00
|
|
|
|
|
|
|
// Appending an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
|
|
|
MaybeRemoveDefaultContent();
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:05:06 +00:00
|
|
|
void InsertInsertedChildAt(nsIContent* aChild, uint32_t aIndex)
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
mInsertedChildren.InsertElementAt(aIndex, aChild);
|
2013-07-17 16:05:06 +00:00
|
|
|
aChild->SetXBLInsertionParent(GetParent());
|
2014-11-15 01:02:29 +00:00
|
|
|
|
|
|
|
// Inserting an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
|
|
|
MaybeRemoveDefaultContent();
|
2013-05-01 22:50:08 +00: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-15 01:02:29 +00:00
|
|
|
|
|
|
|
// After removing the inserted child, default content
|
|
|
|
// may be projected into this insertion point.
|
|
|
|
MaybeSetupDefaultContent();
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearInsertedChildren()
|
|
|
|
{
|
|
|
|
for (uint32_t c = 0; c < mInsertedChildren.Length(); ++c) {
|
2013-07-17 16:05:06 +00:00
|
|
|
mInsertedChildren[c]->SetXBLInsertionParent(nullptr);
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
mInsertedChildren.Clear();
|
2014-11-15 01:02:29 +00:00
|
|
|
|
|
|
|
// After clearing inserted children, default content
|
|
|
|
// will be projected into this insertion point.
|
|
|
|
MaybeSetupDefaultContent();
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:05:06 +00:00
|
|
|
void MaybeSetupDefaultContent()
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
if (!HasInsertedChildren()) {
|
|
|
|
for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2013-07-17 16:05:06 +00:00
|
|
|
child->SetXBLInsertionParent(GetParent());
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:05:06 +00:00
|
|
|
void MaybeRemoveDefaultContent()
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
if (!HasInsertedChildren()) {
|
|
|
|
for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2013-07-17 16:05:06 +00:00
|
|
|
child->SetXBLInsertionParent(nullptr);
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t InsertedChildrenLength()
|
|
|
|
{
|
|
|
|
return mInsertedChildren.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasInsertedChildren()
|
|
|
|
{
|
|
|
|
return !mInsertedChildren.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-06-22 11:53:01 +00:00
|
|
|
int32_t IndexOfInsertedChild(nsIContent* aChild)
|
2013-05-01 22:50:08 +00:00
|
|
|
{
|
|
|
|
return mInsertedChildren.IndexOf(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Includes(nsIContent* aChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mIncludes.IsEmpty(),
|
|
|
|
"Shouldn't check for includes on default insertion point");
|
2015-03-03 11:09:00 +00:00
|
|
|
return mIncludes.Contains(aChild->NodeInfo()->NameAtom());
|
2013-05-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDefaultInsertion()
|
|
|
|
{
|
|
|
|
return mIncludes.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-06-22 11:53:01 +00:00
|
|
|
nsIContent* InsertedChild(uint32_t aIndex)
|
|
|
|
{
|
|
|
|
return mInsertedChildren[aIndex];
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2014-07-08 21:23:17 +00:00
|
|
|
protected:
|
|
|
|
~XBLChildrenElement();
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
private:
|
2014-06-22 11:53:01 +00:00
|
|
|
nsTArray<nsIContent*> mInsertedChildren; // WEAK
|
2013-05-01 22:50:08 +00:00
|
|
|
nsTArray<nsCOMPtr<nsIAtom> > mIncludes;
|
|
|
|
};
|
|
|
|
|
2013-07-01 22:09:37 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
class nsAnonymousContentList : public nsINodeList
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit nsAnonymousContentList(nsIContent* aParent)
|
2013-05-01 22:50:08 +00: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
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsINode* GetParentObject() override { return mParent; }
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
2013-05-01 22:50:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-05-01 22:50:08 +00:00
|
|
|
|
|
|
|
bool IsListFor(nsIContent* aContent) {
|
|
|
|
return mParent == aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-23 19:56:07 +00:00
|
|
|
virtual ~nsAnonymousContentList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsAnonymousContentList);
|
|
|
|
}
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
nsCOMPtr<nsIContent> mParent;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXBLChildrenElement_h___
|