Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 #ifndef nsXPathResult_h__
7 #define nsXPathResult_h__
9 #include "txExprResult.h"
10 #include "nsIDOMXPathResult.h"
11 #include "nsStubMutationObserver.h"
12 #include "nsCOMPtr.h"
13 #include "nsCOMArray.h"
14 #include "nsWeakPtr.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "mozilla/Attributes.h"
18 class nsIDocument;
20 // {662f2c9a-c7cd-4cab-9349-e733df5a838c}
21 #define NS_IXPATHRESULT_IID \
22 { 0x662f2c9a, 0xc7cd, 0x4cab, {0x93, 0x49, 0xe7, 0x33, 0xdf, 0x5a, 0x83, 0x8c }}
24 class nsIXPathResult : public nsISupports
25 {
26 public:
27 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXPATHRESULT_IID)
28 virtual nsresult SetExprResult(txAExprResult *aExprResult,
29 uint16_t aResultType,
30 nsINode* aContextNode) = 0;
31 virtual nsresult GetExprResult(txAExprResult **aExprResult) = 0;
32 virtual nsresult Clone(nsIXPathResult **aResult) = 0;
33 };
35 NS_DEFINE_STATIC_IID_ACCESSOR(nsIXPathResult, NS_IXPATHRESULT_IID)
37 /**
38 * A class for evaluating an XPath expression string
39 */
40 class nsXPathResult MOZ_FINAL : public nsIDOMXPathResult,
41 public nsStubMutationObserver,
42 public nsIXPathResult
43 {
44 public:
45 nsXPathResult();
46 nsXPathResult(const nsXPathResult &aResult);
47 ~nsXPathResult();
49 // nsISupports interface
50 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
51 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXPathResult, nsIDOMXPathResult)
53 // nsIDOMXPathResult interface
54 NS_DECL_NSIDOMXPATHRESULT
56 // nsIMutationObserver interface
57 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
58 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
59 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
60 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
61 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
62 NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
64 // nsIXPathResult interface
65 nsresult SetExprResult(txAExprResult *aExprResult, uint16_t aResultType,
66 nsINode* aContextNode) MOZ_OVERRIDE;
67 nsresult GetExprResult(txAExprResult **aExprResult) MOZ_OVERRIDE;
68 nsresult Clone(nsIXPathResult **aResult) MOZ_OVERRIDE;
69 void RemoveObserver();
70 private:
71 static bool isSnapshot(uint16_t aResultType)
72 {
73 return aResultType == UNORDERED_NODE_SNAPSHOT_TYPE ||
74 aResultType == ORDERED_NODE_SNAPSHOT_TYPE;
75 }
76 static bool isIterator(uint16_t aResultType)
77 {
78 return aResultType == UNORDERED_NODE_ITERATOR_TYPE ||
79 aResultType == ORDERED_NODE_ITERATOR_TYPE;
80 }
81 static bool isNode(uint16_t aResultType)
82 {
83 return aResultType == FIRST_ORDERED_NODE_TYPE ||
84 aResultType == ANY_UNORDERED_NODE_TYPE;
85 }
86 bool isSnapshot() const
87 {
88 return isSnapshot(mResultType);
89 }
90 bool isIterator() const
91 {
92 return isIterator(mResultType);
93 }
94 bool isNode() const
95 {
96 return isNode(mResultType);
97 }
99 void Invalidate(const nsIContent* aChangeRoot);
101 nsRefPtr<txAExprResult> mResult;
102 nsCOMArray<nsIDOMNode> mResultNodes;
103 nsCOMPtr<nsIDocument> mDocument;
104 uint32_t mCurrentPos;
105 uint16_t mResultType;
106 nsWeakPtr mContextNode;
107 bool mInvalidIteratorState;
108 bool mBooleanResult;
109 double mNumberResult;
110 nsString mStringResult;
111 };
113 #endif