content/xul/templates/src/nsXULTemplateQueryProcessorXML.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/templates/src/nsXULTemplateQueryProcessorXML.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,163 @@
     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 nsXULTemplateQueryProcessorXML_h__
    1.10 +#define nsXULTemplateQueryProcessorXML_h__
    1.11 +
    1.12 +#include "nsIXULTemplateBuilder.h"
    1.13 +#include "nsIXULTemplateQueryProcessor.h"
    1.14 +
    1.15 +#include "nsISimpleEnumerator.h"
    1.16 +#include "nsString.h"
    1.17 +#include "nsCOMArray.h"
    1.18 +#include "nsRefPtrHashtable.h"
    1.19 +#include "nsIDOMElement.h"
    1.20 +#include "nsIDOMEventListener.h"
    1.21 +#include "nsIDOMXPathExpression.h"
    1.22 +#include "nsIDOMXPathEvaluator.h"
    1.23 +#include "nsIDOMXPathResult.h"
    1.24 +#include "nsXMLBinding.h"
    1.25 +#include "nsCycleCollectionParticipant.h"
    1.26 +#include "nsIXMLHttpRequest.h"
    1.27 +#include "mozilla/Attributes.h"
    1.28 +
    1.29 +class nsXULTemplateQueryProcessorXML;
    1.30 +
    1.31 +#define NS_IXMLQUERY_IID \
    1.32 +  {0x0358d692, 0xccce, 0x4a97, \
    1.33 +    { 0xb2, 0x51, 0xba, 0x8f, 0x17, 0x0f, 0x3b, 0x6f }}
    1.34 + 
    1.35 +class nsXMLQuery MOZ_FINAL : public nsISupports
    1.36 +{
    1.37 +  public:
    1.38 +    NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXMLQUERY_IID)
    1.39 +
    1.40 +    NS_DECL_ISUPPORTS
    1.41 +
    1.42 +    // return a weak reference to the processor the query was created from
    1.43 +    nsXULTemplateQueryProcessorXML* Processor() { return mProcessor; }
    1.44 +
    1.45 +    // return a weak reference t the member variable for the query
    1.46 +    nsIAtom* GetMemberVariable() { return mMemberVariable; }
    1.47 +
    1.48 +    // return a weak reference to the expression used to generate results
    1.49 +    nsIDOMXPathExpression* GetResultsExpression() { return mResultsExpr; }
    1.50 +
    1.51 +    // return a weak reference to the additional required bindings
    1.52 +    nsXMLBindingSet* GetBindingSet() { return mRequiredBindings; }
    1.53 +
    1.54 +    // add a required binding for the query
    1.55 +    nsresult
    1.56 +    AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr)
    1.57 +    {
    1.58 +        if (!mRequiredBindings) {
    1.59 +            mRequiredBindings = new nsXMLBindingSet();
    1.60 +            NS_ENSURE_TRUE(mRequiredBindings, NS_ERROR_OUT_OF_MEMORY);
    1.61 +        }
    1.62 +
    1.63 +        return mRequiredBindings->AddBinding(aVar, aExpr);
    1.64 +    }
    1.65 +
    1.66 +    nsXMLQuery(nsXULTemplateQueryProcessorXML* aProcessor,
    1.67 +                        nsIAtom* aMemberVariable,
    1.68 +                        nsIDOMXPathExpression* aResultsExpr)
    1.69 +        : mProcessor(aProcessor),
    1.70 +          mMemberVariable(aMemberVariable),
    1.71 +          mResultsExpr(aResultsExpr)
    1.72 +    { }
    1.73 +
    1.74 +  protected:
    1.75 +    nsXULTemplateQueryProcessorXML* mProcessor;
    1.76 +
    1.77 +    nsCOMPtr<nsIAtom> mMemberVariable;
    1.78 +
    1.79 +    nsCOMPtr<nsIDOMXPathExpression> mResultsExpr;
    1.80 +
    1.81 +    nsRefPtr<nsXMLBindingSet> mRequiredBindings;
    1.82 +};
    1.83 +
    1.84 +NS_DEFINE_STATIC_IID_ACCESSOR(nsXMLQuery, NS_IXMLQUERY_IID)
    1.85 +
    1.86 +class nsXULTemplateResultSetXML MOZ_FINAL : public nsISimpleEnumerator
    1.87 +{
    1.88 +private:
    1.89 +
    1.90 +    // reference back to the query
    1.91 +    nsCOMPtr<nsXMLQuery> mQuery;
    1.92 +
    1.93 +    // the binding set created from <assign> nodes
    1.94 +    nsRefPtr<nsXMLBindingSet> mBindingSet;
    1.95 +
    1.96 +    // set of results contained in this enumerator
    1.97 +    nsCOMPtr<nsIDOMXPathResult> mResults;
    1.98 +
    1.99 +    // current position within the list of results
   1.100 +    uint32_t mPosition;
   1.101 +
   1.102 +public:
   1.103 +
   1.104 +    // nsISupports interface
   1.105 +    NS_DECL_ISUPPORTS
   1.106 +
   1.107 +    // nsISimpleEnumerator interface
   1.108 +    NS_DECL_NSISIMPLEENUMERATOR
   1.109 +
   1.110 +    nsXULTemplateResultSetXML(nsXMLQuery* aQuery,
   1.111 +                              nsIDOMXPathResult* aResults,
   1.112 +                              nsXMLBindingSet* aBindingSet)
   1.113 +        : mQuery(aQuery),
   1.114 +          mBindingSet(aBindingSet),
   1.115 +          mResults(aResults),
   1.116 +          mPosition(0)
   1.117 +    {}
   1.118 +};
   1.119 +
   1.120 +class nsXULTemplateQueryProcessorXML MOZ_FINAL : public nsIXULTemplateQueryProcessor,
   1.121 +                                                 public nsIDOMEventListener
   1.122 +{
   1.123 +public:
   1.124 +
   1.125 +    nsXULTemplateQueryProcessorXML()
   1.126 +        : mGenerationStarted(false)
   1.127 +    {}
   1.128 +
   1.129 +    // nsISupports interface
   1.130 +    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   1.131 +    NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateQueryProcessorXML,
   1.132 +                                             nsIXULTemplateQueryProcessor)
   1.133 +
   1.134 +    // nsIXULTemplateQueryProcessor interface
   1.135 +    NS_DECL_NSIXULTEMPLATEQUERYPROCESSOR
   1.136 +
   1.137 +    // nsIDOMEventListener interface
   1.138 +    NS_DECL_NSIDOMEVENTLISTENER
   1.139 +
   1.140 +    nsXMLBindingSet*
   1.141 +    GetOptionalBindingsForRule(nsIDOMNode* aRuleNode);
   1.142 +
   1.143 +    // create an XPath expression from aExpr, using aNode for
   1.144 +    // resolving namespaces
   1.145 +    nsresult
   1.146 +    CreateExpression(const nsAString& aExpr,
   1.147 +                     nsIDOMNode* aNode,
   1.148 +                     nsIDOMXPathExpression** aCompiledExpr);
   1.149 +
   1.150 +private:
   1.151 +
   1.152 +    bool mGenerationStarted;
   1.153 +
   1.154 +    nsRefPtrHashtable<nsISupportsHashKey, nsXMLBindingSet> mRuleToBindingsMap;
   1.155 +
   1.156 +    nsCOMPtr<nsIDOMElement> mRoot;
   1.157 +
   1.158 +    nsCOMPtr<nsIDOMXPathEvaluator> mEvaluator;
   1.159 +
   1.160 +    nsCOMPtr<nsIXULTemplateBuilder> mTemplateBuilder;
   1.161 +
   1.162 +    nsCOMPtr<nsIXMLHttpRequest> mRequest;
   1.163 +};
   1.164 +
   1.165 +
   1.166 +#endif // nsXULTemplateQueryProcessorXML_h__

mercurial