1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/Comment.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * Implementations of DOM Core's nsIDOMComment node. 1.11 + */ 1.12 + 1.13 +#include "nsCOMPtr.h" 1.14 +#include "mozilla/dom/Comment.h" 1.15 +#include "mozilla/dom/CommentBinding.h" 1.16 +#include "mozilla/IntegerPrintfMacros.h" 1.17 + 1.18 +using namespace mozilla; 1.19 +using namespace dom; 1.20 + 1.21 +namespace mozilla { 1.22 +namespace dom { 1.23 + 1.24 +Comment::~Comment() 1.25 +{ 1.26 +} 1.27 + 1.28 +NS_IMPL_ISUPPORTS_INHERITED(Comment, nsGenericDOMDataNode, nsIDOMNode, 1.29 + nsIDOMCharacterData, nsIDOMComment) 1.30 + 1.31 +bool 1.32 +Comment::IsNodeOfType(uint32_t aFlags) const 1.33 +{ 1.34 + return !(aFlags & ~(eCONTENT | eCOMMENT | eDATA_NODE)); 1.35 +} 1.36 + 1.37 +nsGenericDOMDataNode* 1.38 +Comment::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const 1.39 +{ 1.40 + nsCOMPtr<nsINodeInfo> ni = aNodeInfo; 1.41 + Comment *it = new Comment(ni.forget()); 1.42 + if (it && aCloneText) { 1.43 + it->mText = mText; 1.44 + } 1.45 + 1.46 + return it; 1.47 +} 1.48 + 1.49 +#ifdef DEBUG 1.50 +void 1.51 +Comment::List(FILE* out, int32_t aIndent) const 1.52 +{ 1.53 + int32_t indx; 1.54 + for (indx = aIndent; --indx >= 0; ) fputs(" ", out); 1.55 + 1.56 + fprintf(out, "Comment@%p refcount=%" PRIuPTR "<!--", (void*)this, mRefCnt.get()); 1.57 + 1.58 + nsAutoString tmp; 1.59 + ToCString(tmp, 0, mText.GetLength()); 1.60 + fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); 1.61 + 1.62 + fputs("-->\n", out); 1.63 +} 1.64 +#endif 1.65 + 1.66 +/* static */ already_AddRefed<Comment> 1.67 +Comment::Constructor(const GlobalObject& aGlobal, 1.68 + const nsAString& aData, ErrorResult& aRv) 1.69 +{ 1.70 + nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports()); 1.71 + if (!window || !window->GetDoc()) { 1.72 + aRv.Throw(NS_ERROR_FAILURE); 1.73 + return nullptr; 1.74 + } 1.75 + 1.76 + return window->GetDoc()->CreateComment(aData); 1.77 +} 1.78 + 1.79 +JSObject* 1.80 +Comment::WrapNode(JSContext *aCx) 1.81 +{ 1.82 + return CommentBinding::Wrap(aCx, this); 1.83 +} 1.84 + 1.85 +} // namespace dom 1.86 +} // namespace mozilla