dom/xslt/xpath/txXPathNode.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txXPathNode.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,136 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef txXPathNode_h__
    1.10 +#define txXPathNode_h__
    1.11 +
    1.12 +#include "nsAutoPtr.h"
    1.13 +#include "nsIContent.h"
    1.14 +#include "nsIDocument.h"
    1.15 +#include "nsIDOMNode.h"
    1.16 +#include "nsNameSpaceManager.h"
    1.17 +#include "nsContentUtils.h" // For NameSpaceManager().
    1.18 +
    1.19 +typedef nsIDOMNode txXPathNodeType;
    1.20 +
    1.21 +class txXPathNode
    1.22 +{
    1.23 +public:
    1.24 +    bool operator==(const txXPathNode& aNode) const;
    1.25 +    bool operator!=(const txXPathNode& aNode) const
    1.26 +    {
    1.27 +        return !(*this == aNode);
    1.28 +    }
    1.29 +    ~txXPathNode();
    1.30 +
    1.31 +private:
    1.32 +    friend class txNodeSet;
    1.33 +    friend class txXPathNativeNode;
    1.34 +    friend class txXPathNodeUtils;
    1.35 +    friend class txXPathTreeWalker;
    1.36 +
    1.37 +    txXPathNode(const txXPathNode& aNode);
    1.38 +
    1.39 +    txXPathNode(nsIDocument* aDocument) : mNode(aDocument),
    1.40 +                                          mRefCountRoot(0),
    1.41 +                                          mIndex(eDocument)
    1.42 +    {
    1.43 +        MOZ_COUNT_CTOR(txXPathNode);
    1.44 +    }
    1.45 +    txXPathNode(nsINode *aNode, uint32_t aIndex, nsINode *aRoot)
    1.46 +        : mNode(aNode),
    1.47 +          mRefCountRoot(aRoot ? 1 : 0),
    1.48 +          mIndex(aIndex)
    1.49 +    {
    1.50 +        MOZ_COUNT_CTOR(txXPathNode);
    1.51 +        if (aRoot) {
    1.52 +            NS_ADDREF(aRoot);
    1.53 +        }
    1.54 +    }
    1.55 +
    1.56 +    static nsINode *RootOf(nsINode *aNode)
    1.57 +    {
    1.58 +        nsINode *ancestor, *root = aNode;
    1.59 +        while ((ancestor = root->GetParentNode())) {
    1.60 +            root = ancestor;
    1.61 +        }
    1.62 +        return root;
    1.63 +    }
    1.64 +    nsINode *Root() const
    1.65 +    {
    1.66 +        return RootOf(mNode);
    1.67 +    }
    1.68 +    nsINode *GetRootToAddRef() const
    1.69 +    {
    1.70 +        return mRefCountRoot ? Root() : nullptr;
    1.71 +    }
    1.72 +
    1.73 +    bool isDocument() const
    1.74 +    {
    1.75 +        return mIndex == eDocument;
    1.76 +    }
    1.77 +    bool isContent() const
    1.78 +    {
    1.79 +        return mIndex == eContent;
    1.80 +    }
    1.81 +    bool isAttribute() const
    1.82 +    {
    1.83 +        return mIndex != eDocument && mIndex != eContent;
    1.84 +    }
    1.85 +
    1.86 +    nsIContent* Content() const
    1.87 +    {
    1.88 +        NS_ASSERTION(isContent() || isAttribute(), "wrong type");
    1.89 +        return static_cast<nsIContent*>(mNode);
    1.90 +    }
    1.91 +    nsIDocument* Document() const
    1.92 +    {
    1.93 +        NS_ASSERTION(isDocument(), "wrong type");
    1.94 +        return static_cast<nsIDocument*>(mNode);
    1.95 +    }
    1.96 +
    1.97 +    enum PositionType
    1.98 +    {
    1.99 +        eDocument = (1 << 30),
   1.100 +        eContent = eDocument - 1
   1.101 +    };
   1.102 +
   1.103 +    nsINode* mNode;
   1.104 +    uint32_t mRefCountRoot : 1;
   1.105 +    uint32_t mIndex : 31;
   1.106 +};
   1.107 +
   1.108 +class txNamespaceManager
   1.109 +{
   1.110 +public:
   1.111 +    static int32_t getNamespaceID(const nsAString& aNamespaceURI);
   1.112 +    static nsresult getNamespaceURI(const int32_t aID, nsAString& aResult);
   1.113 +};
   1.114 +
   1.115 +/* static */
   1.116 +inline int32_t
   1.117 +txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI)
   1.118 +{
   1.119 +    int32_t namespaceID = kNameSpaceID_Unknown;
   1.120 +    nsContentUtils::NameSpaceManager()->
   1.121 +        RegisterNameSpace(aNamespaceURI, namespaceID);
   1.122 +    return namespaceID;
   1.123 +}
   1.124 +
   1.125 +/* static */
   1.126 +inline nsresult
   1.127 +txNamespaceManager::getNamespaceURI(const int32_t aID, nsAString& aResult)
   1.128 +{
   1.129 +    return nsContentUtils::NameSpaceManager()->
   1.130 +        GetNameSpaceURI(aID, aResult);
   1.131 +}
   1.132 +
   1.133 +inline bool
   1.134 +txXPathNode::operator==(const txXPathNode& aNode) const
   1.135 +{
   1.136 +    return mIndex == aNode.mIndex && mNode == aNode.mNode;
   1.137 +}
   1.138 +
   1.139 +#endif /* txXPathNode_h__ */

mercurial