Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/xslt/xpath/txXPathNode.h
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
#ifndef txXPathNode_h__
7
#define txXPathNode_h__
8
9
#include "nsAutoPtr.h"
10
#include "nsIContent.h"
11
#include "nsIDocument.h"
12
#include "nsINode.h"
13
#include "nsNameSpaceManager.h"
14
#include "nsContentUtils.h" // For NameSpaceManager().
15
16
typedef nsINode txXPathNodeType;
17
18
class txXPathNode
19
{
20
public:
21
    bool operator==(const txXPathNode& aNode) const;
22
    bool operator!=(const txXPathNode& aNode) const
23
0
    {
24
0
        return !(*this == aNode);
25
0
    }
26
    ~txXPathNode();
27
28
private:
29
    friend class txNodeSet;
30
    friend class txXPathNativeNode;
31
    friend class txXPathNodeUtils;
32
    friend class txXPathTreeWalker;
33
34
    txXPathNode(const txXPathNode& aNode);
35
36
    explicit txXPathNode(nsIDocument* aDocument) : mNode(aDocument),
37
                                                   mRefCountRoot(0),
38
                                                   mIndex(eDocument)
39
0
    {
40
0
        MOZ_COUNT_CTOR(txXPathNode);
41
0
    }
42
    txXPathNode(nsINode *aNode, uint32_t aIndex, nsINode *aRoot)
43
        : mNode(aNode),
44
          mRefCountRoot(aRoot ? 1 : 0),
45
          mIndex(aIndex)
46
0
    {
47
0
        MOZ_COUNT_CTOR(txXPathNode);
48
0
        if (aRoot) {
49
0
            NS_ADDREF(aRoot);
50
0
        }
51
0
    }
52
53
    static nsINode *RootOf(nsINode *aNode)
54
0
    {
55
0
        nsINode *ancestor, *root = aNode;
56
0
        while ((ancestor = root->GetParentNode())) {
57
0
            root = ancestor;
58
0
        }
59
0
        return root;
60
0
    }
61
    nsINode *Root() const
62
0
    {
63
0
        return RootOf(mNode);
64
0
    }
65
    nsINode *GetRootToAddRef() const
66
0
    {
67
0
        return mRefCountRoot ? Root() : nullptr;
68
0
    }
69
70
    bool isDocument() const
71
0
    {
72
0
        return mIndex == eDocument;
73
0
    }
74
    bool isContent() const
75
0
    {
76
0
        return mIndex == eContent;
77
0
    }
78
    bool isAttribute() const
79
0
    {
80
0
        return mIndex != eDocument && mIndex != eContent;
81
0
    }
82
83
    nsIContent* Content() const
84
0
    {
85
0
        NS_ASSERTION(isContent() || isAttribute(), "wrong type");
86
0
        return static_cast<nsIContent*>(mNode);
87
0
    }
88
    nsIDocument* Document() const
89
0
    {
90
0
        NS_ASSERTION(isDocument(), "wrong type");
91
0
        return static_cast<nsIDocument*>(mNode);
92
0
    }
93
94
    enum PositionType
95
    {
96
        eDocument = (1 << 30),
97
        eContent = eDocument - 1
98
    };
99
100
    nsINode* mNode;
101
    uint32_t mRefCountRoot : 1;
102
    uint32_t mIndex : 31;
103
};
104
105
class txNamespaceManager
106
{
107
public:
108
    static int32_t getNamespaceID(const nsAString& aNamespaceURI);
109
    static nsresult getNamespaceURI(const int32_t aID, nsAString& aResult);
110
};
111
112
/* static */
113
inline int32_t
114
txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI)
115
18
{
116
18
    int32_t namespaceID = kNameSpaceID_Unknown;
117
18
    nsContentUtils::NameSpaceManager()->
118
18
        RegisterNameSpace(aNamespaceURI, namespaceID);
119
18
    return namespaceID;
120
18
}
121
122
/* static */
123
inline nsresult
124
txNamespaceManager::getNamespaceURI(const int32_t aID, nsAString& aResult)
125
0
{
126
0
    return nsContentUtils::NameSpaceManager()->
127
0
        GetNameSpaceURI(aID, aResult);
128
0
}
129
130
inline bool
131
txXPathNode::operator==(const txXPathNode& aNode) const
132
0
{
133
0
    return mIndex == aNode.mIndex && mNode == aNode.mNode;
134
0
}
135
136
#endif /* txXPathNode_h__ */