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 "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)
|
2018-09-21 23:45:49 +03:00
|
|
|
: nsXMLElement(std::move(aNodeInfo)) {}
|
2013-05-02 02:50:08 +04:00
|
|
|
|
|
|
|
// nsISupports
|
2018-05-30 05:58:51 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(XBLChildrenElement, nsXMLElement)
|
2013-05-02 02:50:08 +04:00
|
|
|
|
|
|
|
// nsINode interface methods
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2013-05-02 02:50:08 +04:00
|
|
|
|
2018-04-14 16:04:53 +03:00
|
|
|
void AppendInsertedChild(nsIContent* aChild, bool aNotify) {
|
2014-11-15 04:02:29 +03:00
|
|
|
// Appending an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
2018-04-14 16:04:53 +03:00
|
|
|
MaybeRemoveDefaultContent(aNotify);
|
2018-04-14 16:02:38 +03:00
|
|
|
|
|
|
|
mInsertedChildren.AppendElement(aChild);
|
|
|
|
aChild->SetXBLInsertionPoint(this);
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
|
2013-07-17 20:05:06 +04:00
|
|
|
void InsertInsertedChildAt(nsIContent* aChild, uint32_t aIndex) {
|
2014-11-15 04:02:29 +03:00
|
|
|
// Inserting an inserted child causes the inserted
|
|
|
|
// children to be projected instead of default content.
|
2018-04-14 16:04:53 +03:00
|
|
|
MaybeRemoveDefaultContent(true);
|
2018-04-14 16:02:38 +03:00
|
|
|
|
|
|
|
mInsertedChildren.InsertElementAt(aIndex, aChild);
|
|
|
|
aChild->SetXBLInsertionPoint(this);
|
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.
|
2018-04-14 16:04:53 +03:00
|
|
|
//
|
|
|
|
// FIXME: Layout should be told about this before clearing
|
|
|
|
// mInsertedChildren, this leaves stale styles and frames in the frame tree.
|
2014-11-15 04:02:29 +03:00
|
|
|
MaybeSetupDefaultContent();
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearInsertedChildren() {
|
2017-10-23 16:52:08 +03:00
|
|
|
for (auto* child : mInsertedChildren) {
|
2018-08-12 21:17:48 +03:00
|
|
|
if (child->GetXBLInsertionPoint() == this) {
|
|
|
|
child->SetXBLInsertionPoint(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.
|
2018-04-14 16:04:53 +03:00
|
|
|
//
|
|
|
|
// FIXME: Layout should be told about this before clearing
|
|
|
|
// mInsertedChildren, this leaves stale styles and frames in the frame tree.
|
2014-11-15 04:02:29 +03:00
|
|
|
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()) {
|
2017-10-23 16:52:08 +03:00
|
|
|
child->SetXBLInsertionPoint(this);
|
2013-05-02 02:50:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:04:53 +03:00
|
|
|
void MaybeRemoveDefaultContent(bool aNotify) {
|
|
|
|
if (!HasInsertedChildren() && HasChildren()) {
|
|
|
|
DoRemoveDefaultContent(aNotify);
|
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();
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 20:28:20 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify) override;
|
2014-07-09 01:23:17 +04:00
|
|
|
|
2018-04-14 16:04:53 +03:00
|
|
|
void DoRemoveDefaultContent(bool aNotify);
|
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
private:
|
2014-06-22 15:53:01 +04:00
|
|
|
nsTArray<nsIContent*> mInsertedChildren; // WEAK
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<RefPtr<nsAtom> > mIncludes;
|
2013-05-02 02:50:08 +04:00
|
|
|
};
|
|
|
|
|
2013-07-02 02:09:37 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-03-20 21:02:08 +03:00
|
|
|
class nsAnonymousContentList final : public nsINodeList {
|
2013-05-02 02:50:08 +04:00
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsAnonymousContentList(nsIContent* aParent) : mParent(aParent) {}
|
2013-05-02 02:50:08 +04:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList)
|
|
|
|
|
|
|
|
// 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;
|
2018-03-20 21:02:08 +03:00
|
|
|
uint32_t Length() 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___
|