1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 "nsIContent.h"
10 #include "mozilla/dom/Document.h"
12 #include "nsNameSpaceManager.h"
14 using txXPathNodeType
= nsINode
;
18 bool operator==(const txXPathNode
& aNode
) const;
19 bool operator!=(const txXPathNode
& aNode
) const { return !(*this == aNode
); }
23 friend class txNodeSet
;
24 friend class txXPathNativeNode
;
25 friend class txXPathNodeUtils
;
26 friend class txXPathTreeWalker
;
28 txXPathNode(const txXPathNode
& aNode
);
30 explicit txXPathNode(mozilla::dom::Document
* aDocument
)
31 : mNode(aDocument
), mRefCountRoot(0), mIndex(eDocument
) {
32 MOZ_COUNT_CTOR(txXPathNode
);
34 txXPathNode(nsINode
* aNode
, uint32_t aIndex
, nsINode
* aRoot
)
35 : mNode(aNode
), mRefCountRoot(aRoot
? 1 : 0), mIndex(aIndex
) {
36 MOZ_COUNT_CTOR(txXPathNode
);
42 static nsINode
* RootOf(nsINode
* aNode
) { return aNode
->SubtreeRoot(); }
43 nsINode
* Root() const { return RootOf(mNode
); }
44 nsINode
* GetRootToAddRef() const { return mRefCountRoot
? Root() : nullptr; }
46 bool isDocument() const { return mIndex
== eDocument
; }
47 bool isContent() const { return mIndex
== eContent
; }
48 bool isAttribute() const { return mIndex
!= eDocument
&& mIndex
!= eContent
; }
50 nsIContent
* Content() const {
51 NS_ASSERTION(isContent() || isAttribute(), "wrong type");
52 return static_cast<nsIContent
*>(mNode
);
54 mozilla::dom::Document
* Document() const {
55 NS_ASSERTION(isDocument(), "wrong type");
56 return static_cast<mozilla::dom::Document
*>(mNode
);
59 enum PositionType
{ eDocument
= (1 << 30), eContent
= eDocument
- 1 };
62 uint32_t mRefCountRoot
: 1;
66 class txNamespaceManager
{
68 static int32_t getNamespaceID(const nsAString
& aNamespaceURI
);
69 static nsresult
getNamespaceURI(const int32_t aID
, nsAString
& aResult
);
73 inline int32_t txNamespaceManager::getNamespaceID(
74 const nsAString
& aNamespaceURI
) {
75 int32_t namespaceID
= kNameSpaceID_Unknown
;
76 nsNameSpaceManager::GetInstance()->RegisterNameSpace(aNamespaceURI
,
82 inline nsresult
txNamespaceManager::getNamespaceURI(const int32_t aID
,
84 return nsNameSpaceManager::GetInstance()->GetNameSpaceURI(aID
, aResult
);
87 inline bool txXPathNode::operator==(const txXPathNode
& aNode
) const {
88 return mIndex
== aNode
.mIndex
&& mNode
== aNode
.mNode
;
91 #endif /* txXPathNode_h__ */