dom/xslt/xpath/txXPathNode.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef txXPathNode_h__
michael@0 7 #define txXPathNode_h__
michael@0 8
michael@0 9 #include "nsAutoPtr.h"
michael@0 10 #include "nsIContent.h"
michael@0 11 #include "nsIDocument.h"
michael@0 12 #include "nsIDOMNode.h"
michael@0 13 #include "nsNameSpaceManager.h"
michael@0 14 #include "nsContentUtils.h" // For NameSpaceManager().
michael@0 15
michael@0 16 typedef nsIDOMNode txXPathNodeType;
michael@0 17
michael@0 18 class txXPathNode
michael@0 19 {
michael@0 20 public:
michael@0 21 bool operator==(const txXPathNode& aNode) const;
michael@0 22 bool operator!=(const txXPathNode& aNode) const
michael@0 23 {
michael@0 24 return !(*this == aNode);
michael@0 25 }
michael@0 26 ~txXPathNode();
michael@0 27
michael@0 28 private:
michael@0 29 friend class txNodeSet;
michael@0 30 friend class txXPathNativeNode;
michael@0 31 friend class txXPathNodeUtils;
michael@0 32 friend class txXPathTreeWalker;
michael@0 33
michael@0 34 txXPathNode(const txXPathNode& aNode);
michael@0 35
michael@0 36 txXPathNode(nsIDocument* aDocument) : mNode(aDocument),
michael@0 37 mRefCountRoot(0),
michael@0 38 mIndex(eDocument)
michael@0 39 {
michael@0 40 MOZ_COUNT_CTOR(txXPathNode);
michael@0 41 }
michael@0 42 txXPathNode(nsINode *aNode, uint32_t aIndex, nsINode *aRoot)
michael@0 43 : mNode(aNode),
michael@0 44 mRefCountRoot(aRoot ? 1 : 0),
michael@0 45 mIndex(aIndex)
michael@0 46 {
michael@0 47 MOZ_COUNT_CTOR(txXPathNode);
michael@0 48 if (aRoot) {
michael@0 49 NS_ADDREF(aRoot);
michael@0 50 }
michael@0 51 }
michael@0 52
michael@0 53 static nsINode *RootOf(nsINode *aNode)
michael@0 54 {
michael@0 55 nsINode *ancestor, *root = aNode;
michael@0 56 while ((ancestor = root->GetParentNode())) {
michael@0 57 root = ancestor;
michael@0 58 }
michael@0 59 return root;
michael@0 60 }
michael@0 61 nsINode *Root() const
michael@0 62 {
michael@0 63 return RootOf(mNode);
michael@0 64 }
michael@0 65 nsINode *GetRootToAddRef() const
michael@0 66 {
michael@0 67 return mRefCountRoot ? Root() : nullptr;
michael@0 68 }
michael@0 69
michael@0 70 bool isDocument() const
michael@0 71 {
michael@0 72 return mIndex == eDocument;
michael@0 73 }
michael@0 74 bool isContent() const
michael@0 75 {
michael@0 76 return mIndex == eContent;
michael@0 77 }
michael@0 78 bool isAttribute() const
michael@0 79 {
michael@0 80 return mIndex != eDocument && mIndex != eContent;
michael@0 81 }
michael@0 82
michael@0 83 nsIContent* Content() const
michael@0 84 {
michael@0 85 NS_ASSERTION(isContent() || isAttribute(), "wrong type");
michael@0 86 return static_cast<nsIContent*>(mNode);
michael@0 87 }
michael@0 88 nsIDocument* Document() const
michael@0 89 {
michael@0 90 NS_ASSERTION(isDocument(), "wrong type");
michael@0 91 return static_cast<nsIDocument*>(mNode);
michael@0 92 }
michael@0 93
michael@0 94 enum PositionType
michael@0 95 {
michael@0 96 eDocument = (1 << 30),
michael@0 97 eContent = eDocument - 1
michael@0 98 };
michael@0 99
michael@0 100 nsINode* mNode;
michael@0 101 uint32_t mRefCountRoot : 1;
michael@0 102 uint32_t mIndex : 31;
michael@0 103 };
michael@0 104
michael@0 105 class txNamespaceManager
michael@0 106 {
michael@0 107 public:
michael@0 108 static int32_t getNamespaceID(const nsAString& aNamespaceURI);
michael@0 109 static nsresult getNamespaceURI(const int32_t aID, nsAString& aResult);
michael@0 110 };
michael@0 111
michael@0 112 /* static */
michael@0 113 inline int32_t
michael@0 114 txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI)
michael@0 115 {
michael@0 116 int32_t namespaceID = kNameSpaceID_Unknown;
michael@0 117 nsContentUtils::NameSpaceManager()->
michael@0 118 RegisterNameSpace(aNamespaceURI, namespaceID);
michael@0 119 return namespaceID;
michael@0 120 }
michael@0 121
michael@0 122 /* static */
michael@0 123 inline nsresult
michael@0 124 txNamespaceManager::getNamespaceURI(const int32_t aID, nsAString& aResult)
michael@0 125 {
michael@0 126 return nsContentUtils::NameSpaceManager()->
michael@0 127 GetNameSpaceURI(aID, aResult);
michael@0 128 }
michael@0 129
michael@0 130 inline bool
michael@0 131 txXPathNode::operator==(const txXPathNode& aNode) const
michael@0 132 {
michael@0 133 return mIndex == aNode.mIndex && mNode == aNode.mNode;
michael@0 134 }
michael@0 135
michael@0 136 #endif /* txXPathNode_h__ */

mercurial