michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef txXPathNode_h__ michael@0: #define txXPathNode_h__ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsIContent.h" michael@0: #include "nsIDocument.h" michael@0: #include "nsIDOMNode.h" michael@0: #include "nsNameSpaceManager.h" michael@0: #include "nsContentUtils.h" // For NameSpaceManager(). michael@0: michael@0: typedef nsIDOMNode txXPathNodeType; michael@0: michael@0: class txXPathNode michael@0: { michael@0: public: michael@0: bool operator==(const txXPathNode& aNode) const; michael@0: bool operator!=(const txXPathNode& aNode) const michael@0: { michael@0: return !(*this == aNode); michael@0: } michael@0: ~txXPathNode(); michael@0: michael@0: private: michael@0: friend class txNodeSet; michael@0: friend class txXPathNativeNode; michael@0: friend class txXPathNodeUtils; michael@0: friend class txXPathTreeWalker; michael@0: michael@0: txXPathNode(const txXPathNode& aNode); michael@0: michael@0: txXPathNode(nsIDocument* aDocument) : mNode(aDocument), michael@0: mRefCountRoot(0), michael@0: mIndex(eDocument) michael@0: { michael@0: MOZ_COUNT_CTOR(txXPathNode); michael@0: } michael@0: txXPathNode(nsINode *aNode, uint32_t aIndex, nsINode *aRoot) michael@0: : mNode(aNode), michael@0: mRefCountRoot(aRoot ? 1 : 0), michael@0: mIndex(aIndex) michael@0: { michael@0: MOZ_COUNT_CTOR(txXPathNode); michael@0: if (aRoot) { michael@0: NS_ADDREF(aRoot); michael@0: } michael@0: } michael@0: michael@0: static nsINode *RootOf(nsINode *aNode) michael@0: { michael@0: nsINode *ancestor, *root = aNode; michael@0: while ((ancestor = root->GetParentNode())) { michael@0: root = ancestor; michael@0: } michael@0: return root; michael@0: } michael@0: nsINode *Root() const michael@0: { michael@0: return RootOf(mNode); michael@0: } michael@0: nsINode *GetRootToAddRef() const michael@0: { michael@0: return mRefCountRoot ? Root() : nullptr; michael@0: } michael@0: michael@0: bool isDocument() const michael@0: { michael@0: return mIndex == eDocument; michael@0: } michael@0: bool isContent() const michael@0: { michael@0: return mIndex == eContent; michael@0: } michael@0: bool isAttribute() const michael@0: { michael@0: return mIndex != eDocument && mIndex != eContent; michael@0: } michael@0: michael@0: nsIContent* Content() const michael@0: { michael@0: NS_ASSERTION(isContent() || isAttribute(), "wrong type"); michael@0: return static_cast(mNode); michael@0: } michael@0: nsIDocument* Document() const michael@0: { michael@0: NS_ASSERTION(isDocument(), "wrong type"); michael@0: return static_cast(mNode); michael@0: } michael@0: michael@0: enum PositionType michael@0: { michael@0: eDocument = (1 << 30), michael@0: eContent = eDocument - 1 michael@0: }; michael@0: michael@0: nsINode* mNode; michael@0: uint32_t mRefCountRoot : 1; michael@0: uint32_t mIndex : 31; michael@0: }; michael@0: michael@0: class txNamespaceManager michael@0: { michael@0: public: michael@0: static int32_t getNamespaceID(const nsAString& aNamespaceURI); michael@0: static nsresult getNamespaceURI(const int32_t aID, nsAString& aResult); michael@0: }; michael@0: michael@0: /* static */ michael@0: inline int32_t michael@0: txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI) michael@0: { michael@0: int32_t namespaceID = kNameSpaceID_Unknown; michael@0: nsContentUtils::NameSpaceManager()-> michael@0: RegisterNameSpace(aNamespaceURI, namespaceID); michael@0: return namespaceID; michael@0: } michael@0: michael@0: /* static */ michael@0: inline nsresult michael@0: txNamespaceManager::getNamespaceURI(const int32_t aID, nsAString& aResult) michael@0: { michael@0: return nsContentUtils::NameSpaceManager()-> michael@0: GetNameSpaceURI(aID, aResult); michael@0: } michael@0: michael@0: inline bool michael@0: txXPathNode::operator==(const txXPathNode& aNode) const michael@0: { michael@0: return mIndex == aNode.mIndex && mNode == aNode.mNode; michael@0: } michael@0: michael@0: #endif /* txXPathNode_h__ */