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/. */
8 * Implementation of DOM Core's DocumentFragment.
11 #include "mozilla/dom/DocumentFragment.h"
12 #include "mozilla/dom/Element.h" // for NS_IMPL_ELEMENT_CLONE
13 #include "mozilla/dom/NodeInfo.h"
14 #include "nsNodeInfoManager.h"
16 #include "nsGkAtoms.h"
17 #include "nsDOMString.h"
18 #include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_TEAROFF
19 #include "mozilla/dom/DocumentFragmentBinding.h"
20 #include "nsPIDOMWindow.h"
21 #include "mozilla/dom/Document.h"
22 #include "mozilla/IntegerPrintfMacros.h"
24 namespace mozilla::dom
{
26 JSObject
* DocumentFragment::WrapNode(JSContext
* aCx
,
27 JS::Handle
<JSObject
*> aGivenProto
) {
28 return DocumentFragment_Binding::Wrap(aCx
, this, aGivenProto
);
32 void DocumentFragment::List(FILE* out
, int32_t aIndent
) const {
34 for (indent
= aIndent
; --indent
>= 0;) {
38 fprintf(out
, "DocumentFragment@%p", (void*)this);
40 fprintf(out
, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
41 fprintf(out
, " refcount=%" PRIuPTR
"<", mRefCnt
.get());
43 nsIContent
* child
= GetFirstChild();
47 for (; child
; child
= child
->GetNextSibling()) {
48 child
->List(out
, aIndent
+ 1);
51 for (indent
= aIndent
; --indent
>= 0;) {
59 void DocumentFragment::DumpContent(FILE* out
, int32_t aIndent
,
60 bool aDumpAll
) const {
62 for (indent
= aIndent
; --indent
>= 0;) {
66 fputs("<DocumentFragment>", out
);
72 for (nsIContent
* child
= GetFirstChild(); child
;
73 child
= child
->GetNextSibling()) {
74 int32_t indent
= aIndent
? aIndent
+ 1 : 0;
75 child
->DumpContent(out
, indent
, aDumpAll
);
77 for (indent
= aIndent
; --indent
>= 0;) {
80 fputs("</DocumentFragment>", out
);
89 already_AddRefed
<DocumentFragment
> DocumentFragment::Constructor(
90 const GlobalObject
& aGlobal
, ErrorResult
& aRv
) {
91 nsCOMPtr
<nsPIDOMWindowInner
> window
=
92 do_QueryInterface(aGlobal
.GetAsSupports());
93 if (!window
|| !window
->GetDoc()) {
94 aRv
.Throw(NS_ERROR_FAILURE
);
98 return window
->GetDoc()->CreateDocumentFragment();
101 NS_IMPL_CYCLE_COLLECTION_INHERITED(DocumentFragment
, FragmentOrElement
, mHost
)
103 // QueryInterface implementation for DocumentFragment
104 NS_INTERFACE_MAP_BEGIN(DocumentFragment
)
105 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
106 NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment
)
107 NS_INTERFACE_MAP_ENTRY(nsIContent
)
108 NS_INTERFACE_MAP_ENTRY(nsINode
)
109 NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget
)
110 NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference
,
111 new nsNodeSupportsWeakRefTearoff(this))
112 // DOM bindings depend on the identity pointer being the
113 // same as nsINode (which nsIContent inherits).
114 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIContent
)
117 NS_IMPL_ADDREF_INHERITED(DocumentFragment
, FragmentOrElement
)
118 NS_IMPL_RELEASE_INHERITED(DocumentFragment
, FragmentOrElement
)
120 NS_IMPL_ELEMENT_CLONE(DocumentFragment
)
122 } // namespace mozilla::dom