Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / dom / base / DocumentFragment.cpp
blob4cf5aac2296fb8e22eb596772b28f07688ba0f1a
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 /*
8 * Implementation of DOM Core's DocumentFragment.
9 */
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"
15 #include "nsError.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);
31 bool DocumentFragment::IsNodeOfType(uint32_t aFlags) const { return false; }
33 #ifdef MOZ_DOM_LIST
34 void DocumentFragment::List(FILE* out, int32_t aIndent) const {
35 int32_t indent;
36 for (indent = aIndent; --indent >= 0;) {
37 fputs(" ", out);
40 fprintf(out, "DocumentFragment@%p", (void*)this);
42 fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
43 fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
45 nsIContent* child = GetFirstChild();
46 if (child) {
47 fputs("\n", out);
49 for (; child; child = child->GetNextSibling()) {
50 child->List(out, aIndent + 1);
53 for (indent = aIndent; --indent >= 0;) {
54 fputs(" ", out);
58 fputs(">\n", out);
61 void DocumentFragment::DumpContent(FILE* out, int32_t aIndent,
62 bool aDumpAll) const {
63 int32_t indent;
64 for (indent = aIndent; --indent >= 0;) {
65 fputs(" ", out);
68 fputs("<DocumentFragment>", out);
70 if (aIndent) {
71 fputs("\n", out);
74 for (nsIContent* child = GetFirstChild(); child;
75 child = child->GetNextSibling()) {
76 int32_t indent = aIndent ? aIndent + 1 : 0;
77 child->DumpContent(out, indent, aDumpAll);
79 for (indent = aIndent; --indent >= 0;) {
80 fputs(" ", out);
82 fputs("</DocumentFragment>", out);
84 if (aIndent) {
85 fputs("\n", out);
88 #endif
90 /* static */
91 already_AddRefed<DocumentFragment> DocumentFragment::Constructor(
92 const GlobalObject& aGlobal, ErrorResult& aRv) {
93 nsCOMPtr<nsPIDOMWindowInner> window =
94 do_QueryInterface(aGlobal.GetAsSupports());
95 if (!window || !window->GetDoc()) {
96 aRv.Throw(NS_ERROR_FAILURE);
97 return nullptr;
100 return window->GetDoc()->CreateDocumentFragment();
103 NS_IMPL_CYCLE_COLLECTION_INHERITED(DocumentFragment, FragmentOrElement, mHost)
105 // QueryInterface implementation for DocumentFragment
106 NS_INTERFACE_MAP_BEGIN(DocumentFragment)
107 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
108 NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment)
109 NS_INTERFACE_MAP_ENTRY(nsIContent)
110 NS_INTERFACE_MAP_ENTRY(nsINode)
111 NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
112 NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
113 new nsNodeSupportsWeakRefTearoff(this))
114 // DOM bindings depend on the identity pointer being the
115 // same as nsINode (which nsIContent inherits).
116 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
117 NS_INTERFACE_MAP_END
119 NS_IMPL_ADDREF_INHERITED(DocumentFragment, FragmentOrElement)
120 NS_IMPL_RELEASE_INHERITED(DocumentFragment, FragmentOrElement)
122 NS_IMPL_ELEMENT_CLONE(DocumentFragment)
124 } // namespace mozilla::dom