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