Bumping manifests a=b2g-bump
[gecko.git] / dom / xslt / xpath / txXPathNode.h
blob53b6b6d84c5b3edb95f88a8c087540c4111db3c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef txXPathNode_h__
7 #define txXPathNode_h__
9 #include "nsAutoPtr.h"
10 #include "nsIContent.h"
11 #include "nsIDocument.h"
12 #include "nsIDOMNode.h"
13 #include "nsNameSpaceManager.h"
14 #include "nsContentUtils.h" // For NameSpaceManager().
16 typedef nsIDOMNode txXPathNodeType;
18 class txXPathNode
20 public:
21 bool operator==(const txXPathNode& aNode) const;
22 bool operator!=(const txXPathNode& aNode) const
24 return !(*this == aNode);
26 ~txXPathNode();
28 private:
29 friend class txNodeSet;
30 friend class txXPathNativeNode;
31 friend class txXPathNodeUtils;
32 friend class txXPathTreeWalker;
34 txXPathNode(const txXPathNode& aNode);
36 explicit txXPathNode(nsIDocument* aDocument) : mNode(aDocument),
37 mRefCountRoot(0),
38 mIndex(eDocument)
40 MOZ_COUNT_CTOR(txXPathNode);
42 txXPathNode(nsINode *aNode, uint32_t aIndex, nsINode *aRoot)
43 : mNode(aNode),
44 mRefCountRoot(aRoot ? 1 : 0),
45 mIndex(aIndex)
47 MOZ_COUNT_CTOR(txXPathNode);
48 if (aRoot) {
49 NS_ADDREF(aRoot);
53 static nsINode *RootOf(nsINode *aNode)
55 nsINode *ancestor, *root = aNode;
56 while ((ancestor = root->GetParentNode())) {
57 root = ancestor;
59 return root;
61 nsINode *Root() const
63 return RootOf(mNode);
65 nsINode *GetRootToAddRef() const
67 return mRefCountRoot ? Root() : nullptr;
70 bool isDocument() const
72 return mIndex == eDocument;
74 bool isContent() const
76 return mIndex == eContent;
78 bool isAttribute() const
80 return mIndex != eDocument && mIndex != eContent;
83 nsIContent* Content() const
85 NS_ASSERTION(isContent() || isAttribute(), "wrong type");
86 return static_cast<nsIContent*>(mNode);
88 nsIDocument* Document() const
90 NS_ASSERTION(isDocument(), "wrong type");
91 return static_cast<nsIDocument*>(mNode);
94 enum PositionType
96 eDocument = (1 << 30),
97 eContent = eDocument - 1
100 nsINode* mNode;
101 uint32_t mRefCountRoot : 1;
102 uint32_t mIndex : 31;
105 class txNamespaceManager
107 public:
108 static int32_t getNamespaceID(const nsAString& aNamespaceURI);
109 static nsresult getNamespaceURI(const int32_t aID, nsAString& aResult);
112 /* static */
113 inline int32_t
114 txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI)
116 int32_t namespaceID = kNameSpaceID_Unknown;
117 nsContentUtils::NameSpaceManager()->
118 RegisterNameSpace(aNamespaceURI, namespaceID);
119 return namespaceID;
122 /* static */
123 inline nsresult
124 txNamespaceManager::getNamespaceURI(const int32_t aID, nsAString& aResult)
126 return nsContentUtils::NameSpaceManager()->
127 GetNameSpaceURI(aID, aResult);
130 inline bool
131 txXPathNode::operator==(const txXPathNode& aNode) const
133 return mIndex == aNode.mIndex && mNode == aNode.mNode;
136 #endif /* txXPathNode_h__ */