/src/mozilla-central/dom/base/DocumentFragment.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | /* |
8 | | * Implementation of DOM Core's DocumentFragment. |
9 | | */ |
10 | | |
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 "nsIDocument.h" |
22 | | #include "mozilla/IntegerPrintfMacros.h" |
23 | | |
24 | | namespace mozilla { |
25 | | namespace dom { |
26 | | |
27 | | JSObject* |
28 | | DocumentFragment::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) |
29 | 0 | { |
30 | 0 | return DocumentFragment_Binding::Wrap(aCx, this, aGivenProto); |
31 | 0 | } |
32 | | |
33 | | bool |
34 | | DocumentFragment::IsNodeOfType(uint32_t aFlags) const |
35 | 0 | { |
36 | 0 | return false; |
37 | 0 | } |
38 | | |
39 | | #ifdef DEBUG |
40 | | void |
41 | | DocumentFragment::List(FILE* out, int32_t aIndent) const |
42 | | { |
43 | | int32_t indent; |
44 | | for (indent = aIndent; --indent >= 0; ) { |
45 | | fputs(" ", out); |
46 | | } |
47 | | |
48 | | fprintf(out, "DocumentFragment@%p", (void *)this); |
49 | | |
50 | | fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags())); |
51 | | fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get()); |
52 | | |
53 | | nsIContent* child = GetFirstChild(); |
54 | | if (child) { |
55 | | fputs("\n", out); |
56 | | |
57 | | for (; child; child = child->GetNextSibling()) { |
58 | | child->List(out, aIndent + 1); |
59 | | } |
60 | | |
61 | | for (indent = aIndent; --indent >= 0; ) { |
62 | | fputs(" ", out); |
63 | | } |
64 | | } |
65 | | |
66 | | fputs(">\n", out); |
67 | | } |
68 | | |
69 | | void |
70 | | DocumentFragment::DumpContent(FILE* out, int32_t aIndent, |
71 | | bool aDumpAll) const |
72 | | { |
73 | | int32_t indent; |
74 | | for (indent = aIndent; --indent >= 0; ) { |
75 | | fputs(" ", out); |
76 | | } |
77 | | |
78 | | fputs("<DocumentFragment>", out); |
79 | | |
80 | | if(aIndent) { |
81 | | fputs("\n", out); |
82 | | } |
83 | | |
84 | | for (nsIContent* child = GetFirstChild(); |
85 | | child; |
86 | | child = child->GetNextSibling()) { |
87 | | int32_t indent = aIndent ? aIndent + 1 : 0; |
88 | | child->DumpContent(out, indent, aDumpAll); |
89 | | } |
90 | | for (indent = aIndent; --indent >= 0; ) { |
91 | | fputs(" ", out); |
92 | | } |
93 | | fputs("</DocumentFragment>", out); |
94 | | |
95 | | if(aIndent) { |
96 | | fputs("\n", out); |
97 | | } |
98 | | } |
99 | | #endif |
100 | | |
101 | | /* static */ already_AddRefed<DocumentFragment> |
102 | | DocumentFragment::Constructor(const GlobalObject& aGlobal, |
103 | | ErrorResult& aRv) |
104 | 0 | { |
105 | 0 | nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports()); |
106 | 0 | if (!window || !window->GetDoc()) { |
107 | 0 | aRv.Throw(NS_ERROR_FAILURE); |
108 | 0 | return nullptr; |
109 | 0 | } |
110 | 0 | |
111 | 0 | return window->GetDoc()->CreateDocumentFragment(); |
112 | 0 | } |
113 | | |
114 | | NS_IMPL_CYCLE_COLLECTION_INHERITED(DocumentFragment, FragmentOrElement, mHost) |
115 | | |
116 | | // QueryInterface implementation for DocumentFragment |
117 | 0 | NS_INTERFACE_MAP_BEGIN(DocumentFragment) |
118 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
119 | 0 | NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment) |
120 | 0 | NS_INTERFACE_MAP_ENTRY(nsIContent) |
121 | 0 | NS_INTERFACE_MAP_ENTRY(nsINode) |
122 | 0 | NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget) |
123 | 0 | NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference, |
124 | 0 | new nsNodeSupportsWeakRefTearoff(this)) |
125 | 0 | // DOM bindings depend on the identity pointer being the |
126 | 0 | // same as nsINode (which nsIContent inherits). |
127 | 0 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) |
128 | 0 | NS_INTERFACE_MAP_END |
129 | | |
130 | | NS_IMPL_ADDREF_INHERITED(DocumentFragment, FragmentOrElement) |
131 | | NS_IMPL_RELEASE_INHERITED(DocumentFragment, FragmentOrElement) |
132 | | |
133 | | NS_IMPL_ELEMENT_CLONE(DocumentFragment) |
134 | | |
135 | | } // namespace dom |
136 | | } // namespace mozilla |