|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Implementations of DOM Core's nsIDOMComment node. |
|
8 */ |
|
9 |
|
10 #include "nsCOMPtr.h" |
|
11 #include "mozilla/dom/Comment.h" |
|
12 #include "mozilla/dom/CommentBinding.h" |
|
13 #include "mozilla/IntegerPrintfMacros.h" |
|
14 |
|
15 using namespace mozilla; |
|
16 using namespace dom; |
|
17 |
|
18 namespace mozilla { |
|
19 namespace dom { |
|
20 |
|
21 Comment::~Comment() |
|
22 { |
|
23 } |
|
24 |
|
25 NS_IMPL_ISUPPORTS_INHERITED(Comment, nsGenericDOMDataNode, nsIDOMNode, |
|
26 nsIDOMCharacterData, nsIDOMComment) |
|
27 |
|
28 bool |
|
29 Comment::IsNodeOfType(uint32_t aFlags) const |
|
30 { |
|
31 return !(aFlags & ~(eCONTENT | eCOMMENT | eDATA_NODE)); |
|
32 } |
|
33 |
|
34 nsGenericDOMDataNode* |
|
35 Comment::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const |
|
36 { |
|
37 nsCOMPtr<nsINodeInfo> ni = aNodeInfo; |
|
38 Comment *it = new Comment(ni.forget()); |
|
39 if (it && aCloneText) { |
|
40 it->mText = mText; |
|
41 } |
|
42 |
|
43 return it; |
|
44 } |
|
45 |
|
46 #ifdef DEBUG |
|
47 void |
|
48 Comment::List(FILE* out, int32_t aIndent) const |
|
49 { |
|
50 int32_t indx; |
|
51 for (indx = aIndent; --indx >= 0; ) fputs(" ", out); |
|
52 |
|
53 fprintf(out, "Comment@%p refcount=%" PRIuPTR "<!--", (void*)this, mRefCnt.get()); |
|
54 |
|
55 nsAutoString tmp; |
|
56 ToCString(tmp, 0, mText.GetLength()); |
|
57 fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); |
|
58 |
|
59 fputs("-->\n", out); |
|
60 } |
|
61 #endif |
|
62 |
|
63 /* static */ already_AddRefed<Comment> |
|
64 Comment::Constructor(const GlobalObject& aGlobal, |
|
65 const nsAString& aData, ErrorResult& aRv) |
|
66 { |
|
67 nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports()); |
|
68 if (!window || !window->GetDoc()) { |
|
69 aRv.Throw(NS_ERROR_FAILURE); |
|
70 return nullptr; |
|
71 } |
|
72 |
|
73 return window->GetDoc()->CreateComment(aData); |
|
74 } |
|
75 |
|
76 JSObject* |
|
77 Comment::WrapNode(JSContext *aCx) |
|
78 { |
|
79 return CommentBinding::Wrap(aCx, this); |
|
80 } |
|
81 |
|
82 } // namespace dom |
|
83 } // namespace mozilla |