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