LCOV - app.info - content/base/src/nsCommentNode.cpp

LCOV - code coverage report
| Current view: | directory - content/base/src - nsCommentNode.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 42 | 32 | 76.2 %
| Date: | 2012-06-02 | Functions: | 56 | 21 | 37.5 %

           1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is Mozilla Communicator client code.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  * Netscape Communications Corporation.
          19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : /*
          39                 :  * Implementations of DOM Core's nsIDOMComment node.
          40                 :  */
          41                 :
          42                 : #include "nsIDOMComment.h"
          43                 : #include "nsGenericDOMDataNode.h"
          44                 :
          45                 : #include "nsCOMPtr.h"
          46                 : #include "nsIDocument.h"
          47                 : #include "nsGenericElement.h" // DOMCI_NODE_DATA
          48                 :
          49                 : class nsCommentNode : public nsGenericDOMDataNode,
          50                 :                       public nsIDOMComment
          51                 : {
          52                 : public:
          53                 :   nsCommentNode(already_AddRefed<nsINodeInfo> aNodeInfo);
          54                 :   virtual ~nsCommentNode();
          55                 :
          56                 :   // nsISupports
          57                 :   NS_DECL_ISUPPORTS_INHERITED
          58                 :
          59                 :   // nsIDOMNode
          60             120 :   NS_FORWARD_NSIDOMNODE(nsGenericDOMDataNode::)
          61                 :
          62                 :   // nsIDOMCharacterData
          63              29 :   NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::)
          64                 :
          65                 :   // nsIDOMComment
          66                 :   // Empty interface
          67                 :
          68                 :   // nsINode
          69                 :   virtual bool IsNodeOfType(PRUint32 aFlags) const;
          70                 :
          71                 :   virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo,
          72                 :                                               bool aCloneText) const;
          73                 :
          74                 :   virtual nsXPCClassInfo* GetClassInfo();
          75                 : #ifdef DEBUG
          76                 :   virtual void List(FILE* out, PRInt32 aIndent) const;
          77               0 :   virtual void DumpContent(FILE* out = stdout, PRInt32 aIndent = 0,
          78                 :                            bool aDumpAll = true) const
          79                 :   {
          80                 :     return;
          81                 :   }
          82                 : #endif
          83                 : };
          84                 :
          85                 : nsresult
          86            1638 : NS_NewCommentNode(nsIContent** aInstancePtrResult,
          87                 :                   nsNodeInfoManager *aNodeInfoManager)
          88                 : {
          89            1638 :   NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
          90                 :
          91            1638 :   *aInstancePtrResult = nsnull;
          92                 :
          93            3276 :   nsCOMPtr<nsINodeInfo> ni = aNodeInfoManager->GetCommentNodeInfo();
          94            1638 :   NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
          95                 :
          96            3276 :   nsCommentNode *instance = new nsCommentNode(ni.forget());
          97            1638 :   if (!instance) {
          98               0 :     return NS_ERROR_OUT_OF_MEMORY;
          99                 :   }
         100                 :
         101            1638 :   NS_ADDREF(*aInstancePtrResult = instance);
         102                 :
         103            1638 :   return NS_OK;
         104                 : }
         105                 :
         106            1695 : nsCommentNode::nsCommentNode(already_AddRefed<nsINodeInfo> aNodeInfo)
         107            1695 :   : nsGenericDOMDataNode(aNodeInfo)
         108                 : {
         109            1695 :   NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE,
         110                 :                     "Bad NodeType in aNodeInfo");
         111            1695 : }
         112                 :
         113            3390 : nsCommentNode::~nsCommentNode()
         114                 : {
         115            6780 : }
         116                 :
         117             191 : DOMCI_NODE_DATA(Comment, nsCommentNode)
         118                 :
         119                 : // QueryInterface implementation for nsCommentNode
         120           40925 : NS_INTERFACE_TABLE_HEAD(nsCommentNode)
         121           40925 :   NS_NODE_INTERFACE_TABLE3(nsCommentNode, nsIDOMNode, nsIDOMCharacterData,
         122                 :                            nsIDOMComment)
         123           39121 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Comment)
         124           39102 : NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
         125                 :
         126                 :
         127           10871 : NS_IMPL_ADDREF_INHERITED(nsCommentNode, nsGenericDOMDataNode)
         128           10871 : NS_IMPL_RELEASE_INHERITED(nsCommentNode, nsGenericDOMDataNode)
         129                 :
         130                 :
         131                 : bool
         132            4399 : nsCommentNode::IsNodeOfType(PRUint32 aFlags) const
         133                 : {
         134            4399 :   return !(aFlags & ~(eCONTENT | eCOMMENT | eDATA_NODE));
         135                 : }
         136                 :
         137                 : nsGenericDOMDataNode*
         138              57 : nsCommentNode::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const
         139                 : {
         140             114 :   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
         141             114 :   nsCommentNode *it = new nsCommentNode(ni.forget());
         142              57 :   if (it && aCloneText) {
         143              55 :     it->mText = mText;
         144                 :   }
         145                 :
         146              57 :   return it;
         147                 : }
         148                 :
         149                 : #ifdef DEBUG
         150                 : void
         151               0 : nsCommentNode::List(FILE* out, PRInt32 aIndent) const
         152                 : {
         153                 :   PRInt32 indx;
         154               0 :   for (indx = aIndent; --indx >= 0; ) fputs("  ", out);
         155                 :
         156               0 :   fprintf(out, "Comment@%p refcount=%d<!--", (void*)this, mRefCnt.get());
         157                 :
         158               0 :   nsAutoString tmp;
         159               0 :   ToCString(tmp, 0, mText.GetLength());
         160               0 :   fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
         161                 :
         162               0 :   fputs("-->\n", out);
         163               0 : }
         164                 : #endif

Generated by: LCOV version 1.7