michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsXPathResult_h__ michael@0: #define nsXPathResult_h__ michael@0: michael@0: #include "txExprResult.h" michael@0: #include "nsIDOMXPathResult.h" michael@0: #include "nsStubMutationObserver.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsWeakPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsIDocument; michael@0: michael@0: // {662f2c9a-c7cd-4cab-9349-e733df5a838c} michael@0: #define NS_IXPATHRESULT_IID \ michael@0: { 0x662f2c9a, 0xc7cd, 0x4cab, {0x93, 0x49, 0xe7, 0x33, 0xdf, 0x5a, 0x83, 0x8c }} michael@0: michael@0: class nsIXPathResult : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXPATHRESULT_IID) michael@0: virtual nsresult SetExprResult(txAExprResult *aExprResult, michael@0: uint16_t aResultType, michael@0: nsINode* aContextNode) = 0; michael@0: virtual nsresult GetExprResult(txAExprResult **aExprResult) = 0; michael@0: virtual nsresult Clone(nsIXPathResult **aResult) = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIXPathResult, NS_IXPATHRESULT_IID) michael@0: michael@0: /** michael@0: * A class for evaluating an XPath expression string michael@0: */ michael@0: class nsXPathResult MOZ_FINAL : public nsIDOMXPathResult, michael@0: public nsStubMutationObserver, michael@0: public nsIXPathResult michael@0: { michael@0: public: michael@0: nsXPathResult(); michael@0: nsXPathResult(const nsXPathResult &aResult); michael@0: ~nsXPathResult(); michael@0: michael@0: // nsISupports interface michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXPathResult, nsIDOMXPathResult) michael@0: michael@0: // nsIDOMXPathResult interface michael@0: NS_DECL_NSIDOMXPATHRESULT michael@0: michael@0: // nsIMutationObserver interface michael@0: NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED michael@0: NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED michael@0: NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED michael@0: michael@0: // nsIXPathResult interface michael@0: nsresult SetExprResult(txAExprResult *aExprResult, uint16_t aResultType, michael@0: nsINode* aContextNode) MOZ_OVERRIDE; michael@0: nsresult GetExprResult(txAExprResult **aExprResult) MOZ_OVERRIDE; michael@0: nsresult Clone(nsIXPathResult **aResult) MOZ_OVERRIDE; michael@0: void RemoveObserver(); michael@0: private: michael@0: static bool isSnapshot(uint16_t aResultType) michael@0: { michael@0: return aResultType == UNORDERED_NODE_SNAPSHOT_TYPE || michael@0: aResultType == ORDERED_NODE_SNAPSHOT_TYPE; michael@0: } michael@0: static bool isIterator(uint16_t aResultType) michael@0: { michael@0: return aResultType == UNORDERED_NODE_ITERATOR_TYPE || michael@0: aResultType == ORDERED_NODE_ITERATOR_TYPE; michael@0: } michael@0: static bool isNode(uint16_t aResultType) michael@0: { michael@0: return aResultType == FIRST_ORDERED_NODE_TYPE || michael@0: aResultType == ANY_UNORDERED_NODE_TYPE; michael@0: } michael@0: bool isSnapshot() const michael@0: { michael@0: return isSnapshot(mResultType); michael@0: } michael@0: bool isIterator() const michael@0: { michael@0: return isIterator(mResultType); michael@0: } michael@0: bool isNode() const michael@0: { michael@0: return isNode(mResultType); michael@0: } michael@0: michael@0: void Invalidate(const nsIContent* aChangeRoot); michael@0: michael@0: nsRefPtr mResult; michael@0: nsCOMArray mResultNodes; michael@0: nsCOMPtr mDocument; michael@0: uint32_t mCurrentPos; michael@0: uint16_t mResultType; michael@0: nsWeakPtr mContextNode; michael@0: bool mInvalidIteratorState; michael@0: bool mBooleanResult; michael@0: double mNumberResult; michael@0: nsString mStringResult; michael@0: }; michael@0: michael@0: #endif