1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/nsNodeInfo.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* 1.11 + * Class that represents a prefix/namespace/localName triple; a single 1.12 + * nodeinfo is shared by all elements in a document that have that 1.13 + * prefix, namespace, and localName. 1.14 + */ 1.15 + 1.16 +#ifndef nsNodeInfo_h___ 1.17 +#define nsNodeInfo_h___ 1.18 + 1.19 +#include "mozilla/Attributes.h" 1.20 +#include "nsINodeInfo.h" 1.21 +#include "nsNodeInfoManager.h" 1.22 +#include "plhash.h" 1.23 +#include "nsIAtom.h" 1.24 +#include "nsCOMPtr.h" 1.25 +#include "nsIDOMNode.h" 1.26 +#include "nsGkAtoms.h" 1.27 + 1.28 +class nsNodeInfo : public nsINodeInfo 1.29 +{ 1.30 +public: 1.31 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.32 + NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS(nsNodeInfo) 1.33 + 1.34 + // nsINodeInfo 1.35 + virtual void GetNamespaceURI(nsAString& aNameSpaceURI) const; 1.36 + virtual bool NamespaceEquals(const nsAString& aNamespaceURI) const MOZ_OVERRIDE; 1.37 + 1.38 + // nsNodeInfo 1.39 +public: 1.40 + /* 1.41 + * aName and aOwnerManager may not be null. 1.42 + */ 1.43 + nsNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, int32_t aNamespaceID, 1.44 + uint16_t aNodeType, nsIAtom *aExtraName, 1.45 + nsNodeInfoManager *aOwnerManager); 1.46 + 1.47 +private: 1.48 + nsNodeInfo(); // Unimplemented 1.49 + nsNodeInfo(const nsNodeInfo& aOther); // Unimplemented 1.50 +protected: 1.51 + virtual ~nsNodeInfo(); 1.52 + 1.53 +public: 1.54 + bool CanSkip(); 1.55 + 1.56 +private: 1.57 + /** 1.58 + * This method gets called by Release() when it's time to delete 1.59 + * this object. 1.60 + */ 1.61 + void LastRelease(); 1.62 +}; 1.63 + 1.64 +inline void 1.65 +CheckValidNodeInfo(uint16_t aNodeType, nsIAtom *aName, int32_t aNamespaceID, 1.66 + nsIAtom* aExtraName) 1.67 +{ 1.68 + NS_ABORT_IF_FALSE(aNodeType == nsIDOMNode::ELEMENT_NODE || 1.69 + aNodeType == nsIDOMNode::ATTRIBUTE_NODE || 1.70 + aNodeType == nsIDOMNode::TEXT_NODE || 1.71 + aNodeType == nsIDOMNode::CDATA_SECTION_NODE || 1.72 + aNodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE || 1.73 + aNodeType == nsIDOMNode::COMMENT_NODE || 1.74 + aNodeType == nsIDOMNode::DOCUMENT_NODE || 1.75 + aNodeType == nsIDOMNode::DOCUMENT_TYPE_NODE || 1.76 + aNodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE || 1.77 + aNodeType == UINT16_MAX, 1.78 + "Invalid nodeType"); 1.79 + NS_ABORT_IF_FALSE((aNodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE || 1.80 + aNodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) == 1.81 + !!aExtraName, 1.82 + "Supply aExtraName for and only for PIs and doctypes"); 1.83 + NS_ABORT_IF_FALSE(aNodeType == nsIDOMNode::ELEMENT_NODE || 1.84 + aNodeType == nsIDOMNode::ATTRIBUTE_NODE || 1.85 + aNodeType == UINT16_MAX || 1.86 + aNamespaceID == kNameSpaceID_None, 1.87 + "Only attributes and elements can be in a namespace"); 1.88 + NS_ABORT_IF_FALSE(aName && aName != nsGkAtoms::_empty, "Invalid localName"); 1.89 + NS_ABORT_IF_FALSE(((aNodeType == nsIDOMNode::TEXT_NODE) == 1.90 + (aName == nsGkAtoms::textTagName)) && 1.91 + ((aNodeType == nsIDOMNode::CDATA_SECTION_NODE) == 1.92 + (aName == nsGkAtoms::cdataTagName)) && 1.93 + ((aNodeType == nsIDOMNode::COMMENT_NODE) == 1.94 + (aName == nsGkAtoms::commentTagName)) && 1.95 + ((aNodeType == nsIDOMNode::DOCUMENT_NODE) == 1.96 + (aName == nsGkAtoms::documentNodeName)) && 1.97 + ((aNodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) == 1.98 + (aName == nsGkAtoms::documentFragmentNodeName)) && 1.99 + ((aNodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) == 1.100 + (aName == nsGkAtoms::documentTypeNodeName)) && 1.101 + ((aNodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE) == 1.102 + (aName == nsGkAtoms::processingInstructionTagName)), 1.103 + "Wrong localName for nodeType"); 1.104 +} 1.105 + 1.106 +#endif /* nsNodeInfo_h___ */