2015-05-03 22:32:37 +03: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-02 02:50:08 +04: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-02 02:09:37 +04:00
|
|
|
class nsAnonymousContentList;
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
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
|
2017-04-20 22:57:48 +03:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult,
|
|
|
|
bool aPreallocateChildren) const override;
|
2013-05-02 02:50:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsIDOMNode* AsDOMNode() override { return this; }
|
2013-05-02 02:50:08 +04:00
|
|
|
|
|
|
|
// nsIContent interface methods
|
|
|
|
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2013-05-02 02:50:08 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2013-05-02 02:50:08 +04:00
|
|
|
|
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());
|
2014-11-15 04:02:29 +03:00
|
|
|
|
|
|
|
// Appending an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
|
|
|
MaybeRemoveDefaultContent();
|
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());
|
2014-11-15 04:02:29 +03:00
|
|
|
|
|
|
|
// Inserting an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
|
|
|
MaybeRemoveDefaultContent();
|
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);
|
2014-11-15 04:02:29 +03:00
|
|
|
|
|
|
|
// After removing the inserted child, default content
|
|
|
|
// may be projected into this insertion point.
|
|
|
|
MaybeSetupDefaultContent();
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2014-11-15 04:02:29 +03:00
|
|
|
|
|
|
|
// After clearing inserted children, default content
|
|
|
|
// will be projected into this insertion point.
|
|
|
|
MaybeSetupDefaultContent();
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
|
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");
|
2015-03-03 14:09:00 +03:00
|
|
|
return mIncludes.Contains(aChild->NodeInfo()->NameAtom());
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList)
|
|
|
|
// nsIDOMNodeList interface
|
|
|
|
NS_DECL_NSIDOMNODELIST
|
|
|
|
|
|
|
|
// nsINodeList interface
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsINode* GetParentObject() override { return mParent; }
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
2013-05-02 02:50:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) 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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
nsCOMPtr<nsIContent> mParent;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXBLChildrenElement_h___
|