dom/xslt/xpath/nsXPathResult.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/nsXPathResult.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     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 nsXPathResult_h__
    1.10 +#define nsXPathResult_h__
    1.11 +
    1.12 +#include "txExprResult.h"
    1.13 +#include "nsIDOMXPathResult.h"
    1.14 +#include "nsStubMutationObserver.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsCOMArray.h"
    1.17 +#include "nsWeakPtr.h"
    1.18 +#include "nsCycleCollectionParticipant.h"
    1.19 +#include "mozilla/Attributes.h"
    1.20 +
    1.21 +class nsIDocument;
    1.22 +
    1.23 +// {662f2c9a-c7cd-4cab-9349-e733df5a838c}
    1.24 +#define NS_IXPATHRESULT_IID \
    1.25 +{ 0x662f2c9a, 0xc7cd, 0x4cab, {0x93, 0x49, 0xe7, 0x33, 0xdf, 0x5a, 0x83, 0x8c }}
    1.26 +
    1.27 +class nsIXPathResult : public nsISupports
    1.28 +{
    1.29 +public:
    1.30 +    NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXPATHRESULT_IID)
    1.31 +    virtual nsresult SetExprResult(txAExprResult *aExprResult,
    1.32 +                                   uint16_t aResultType,
    1.33 +                                   nsINode* aContextNode) = 0;
    1.34 +    virtual nsresult GetExprResult(txAExprResult **aExprResult) = 0;
    1.35 +    virtual nsresult Clone(nsIXPathResult **aResult) = 0;
    1.36 +};
    1.37 +
    1.38 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIXPathResult, NS_IXPATHRESULT_IID)
    1.39 +
    1.40 +/**
    1.41 + * A class for evaluating an XPath expression string
    1.42 + */
    1.43 +class nsXPathResult MOZ_FINAL : public nsIDOMXPathResult,
    1.44 +                                public nsStubMutationObserver,
    1.45 +                                public nsIXPathResult
    1.46 +{
    1.47 +public:
    1.48 +    nsXPathResult();
    1.49 +    nsXPathResult(const nsXPathResult &aResult);
    1.50 +    ~nsXPathResult();
    1.51 +
    1.52 +    // nsISupports interface
    1.53 +    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.54 +    NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXPathResult, nsIDOMXPathResult)
    1.55 +
    1.56 +    // nsIDOMXPathResult interface
    1.57 +    NS_DECL_NSIDOMXPATHRESULT
    1.58 +
    1.59 +    // nsIMutationObserver interface
    1.60 +    NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
    1.61 +    NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
    1.62 +    NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
    1.63 +    NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
    1.64 +    NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
    1.65 +    NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
    1.66 +
    1.67 +    // nsIXPathResult interface
    1.68 +    nsresult SetExprResult(txAExprResult *aExprResult, uint16_t aResultType,
    1.69 +                           nsINode* aContextNode) MOZ_OVERRIDE;
    1.70 +    nsresult GetExprResult(txAExprResult **aExprResult) MOZ_OVERRIDE;
    1.71 +    nsresult Clone(nsIXPathResult **aResult) MOZ_OVERRIDE;
    1.72 +    void RemoveObserver();
    1.73 +private:
    1.74 +    static bool isSnapshot(uint16_t aResultType)
    1.75 +    {
    1.76 +        return aResultType == UNORDERED_NODE_SNAPSHOT_TYPE ||
    1.77 +               aResultType == ORDERED_NODE_SNAPSHOT_TYPE;
    1.78 +    }
    1.79 +    static bool isIterator(uint16_t aResultType)
    1.80 +    {
    1.81 +        return aResultType == UNORDERED_NODE_ITERATOR_TYPE ||
    1.82 +               aResultType == ORDERED_NODE_ITERATOR_TYPE;
    1.83 +    }
    1.84 +    static bool isNode(uint16_t aResultType)
    1.85 +    {
    1.86 +        return aResultType == FIRST_ORDERED_NODE_TYPE ||
    1.87 +               aResultType == ANY_UNORDERED_NODE_TYPE;
    1.88 +    }
    1.89 +    bool isSnapshot() const
    1.90 +    {
    1.91 +        return isSnapshot(mResultType);
    1.92 +    }
    1.93 +    bool isIterator() const
    1.94 +    {
    1.95 +        return isIterator(mResultType);
    1.96 +    }
    1.97 +    bool isNode() const
    1.98 +    {
    1.99 +        return isNode(mResultType);
   1.100 +    }
   1.101 +
   1.102 +    void Invalidate(const nsIContent* aChangeRoot);
   1.103 +
   1.104 +    nsRefPtr<txAExprResult> mResult;
   1.105 +    nsCOMArray<nsIDOMNode> mResultNodes;
   1.106 +    nsCOMPtr<nsIDocument> mDocument;
   1.107 +    uint32_t mCurrentPos;
   1.108 +    uint16_t mResultType;
   1.109 +    nsWeakPtr mContextNode;
   1.110 +    bool mInvalidIteratorState;
   1.111 +    bool mBooleanResult;
   1.112 +    double mNumberResult;
   1.113 +    nsString mStringResult;
   1.114 +};
   1.115 +
   1.116 +#endif

mercurial