1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_DocumentFragment_h__
8 #define mozilla_dom_DocumentFragment_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/BorrowedAttrInfo.h"
12 #include "mozilla/dom/FragmentOrElement.h"
13 #include "nsStringFwd.h"
15 // XXX Avoid including this here by moving function bodies to the cpp file.
16 #include "mozilla/dom/Element.h"
21 namespace mozilla::dom
{
26 class DocumentFragment
: public FragmentOrElement
{
29 MOZ_ASSERT(mNodeInfo
->NodeType() == DOCUMENT_FRAGMENT_NODE
&&
30 mNodeInfo
->Equals(nsGkAtoms::documentFragmentNodeName
,
32 "Bad NodeType in aNodeInfo");
36 using FragmentOrElement::GetFirstChild
;
37 using nsINode::QuerySelector
;
38 using nsINode::QuerySelectorAll
;
39 // Make sure bindings can see our superclass' protected GetElementById method.
40 using nsINode::GetElementById
;
43 NS_DECL_ISUPPORTS_INHERITED
44 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentFragment
, FragmentOrElement
)
46 explicit DocumentFragment(already_AddRefed
<dom::NodeInfo
>&& aNodeInfo
)
47 : FragmentOrElement(std::move(aNodeInfo
)), mHost(nullptr) {
51 explicit DocumentFragment(nsNodeInfoManager
* aNodeInfoManager
)
52 : FragmentOrElement(aNodeInfoManager
->GetNodeInfo(
53 nsGkAtoms::documentFragmentNodeName
, nullptr, kNameSpaceID_None
,
54 DOCUMENT_FRAGMENT_NODE
)),
59 NS_IMPL_FROMNODE_HELPER(DocumentFragment
, IsDocumentFragment());
61 JSObject
* WrapNode(JSContext
* aCx
,
62 JS::Handle
<JSObject
*> aGivenProto
) override
;
64 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
{
65 NS_ASSERTION(false, "Trying to bind a fragment to a tree");
66 return NS_ERROR_NOT_IMPLEMENTED
;
69 virtual void UnbindFromTree(UnbindContext
&) override
{
70 NS_ASSERTION(false, "Trying to unbind a fragment from a tree");
73 Element
* GetNameSpaceElement() override
{ return nullptr; }
75 Element
* GetHost() const { return mHost
; }
77 void SetHost(Element
* aHost
) { mHost
= aHost
; }
79 void GetInnerHTML(nsAString
& aInnerHTML
) { GetMarkup(false, aInnerHTML
); }
80 void SetInnerHTML(const nsAString
& aInnerHTML
, ErrorResult
& aError
) {
81 SetInnerHTMLInternal(aInnerHTML
, aError
);
84 static already_AddRefed
<DocumentFragment
> Constructor(
85 const GlobalObject
& aGlobal
, ErrorResult
& aRv
);
88 virtual void List(FILE* out
, int32_t aIndent
) const override
;
89 virtual void DumpContent(FILE* out
, int32_t aIndent
,
90 bool aDumpAll
) const override
;
94 virtual ~DocumentFragment() = default;
96 nsresult
Clone(dom::NodeInfo
* aNodeInfo
, nsINode
** aResult
) const override
;
97 RefPtr
<Element
> mHost
;
100 } // namespace mozilla::dom
102 inline mozilla::dom::DocumentFragment
* nsINode::AsDocumentFragment() {
103 MOZ_ASSERT(IsDocumentFragment());
104 return static_cast<mozilla::dom::DocumentFragment
*>(this);
107 inline const mozilla::dom::DocumentFragment
* nsINode::AsDocumentFragment()
109 MOZ_ASSERT(IsDocumentFragment());
110 return static_cast<const mozilla::dom::DocumentFragment
*>(this);
113 #endif // mozilla_dom_DocumentFragment_h__