content/xul/templates/src/nsXMLBinding.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/templates/src/nsXMLBinding.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,142 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     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 nsXMLBinding_h__
    1.10 +#define nsXMLBinding_h__
    1.11 +
    1.12 +#include "nsAutoPtr.h"
    1.13 +#include "nsIAtom.h"
    1.14 +#include "nsCycleCollectionParticipant.h"
    1.15 +#include "mozilla/Attributes.h"
    1.16 +
    1.17 +class nsXULTemplateResultXML;
    1.18 +class nsXMLBindingValues;
    1.19 +
    1.20 +/**
    1.21 + * Classes related to storing bindings for XML handling.
    1.22 + */
    1.23 +
    1.24 +/**
    1.25 + * a <binding> description
    1.26 + */
    1.27 +struct nsXMLBinding {
    1.28 +  nsCOMPtr<nsIAtom> mVar;
    1.29 +  nsCOMPtr<nsIDOMXPathExpression> mExpr;
    1.30 +
    1.31 +  nsAutoPtr<nsXMLBinding> mNext;
    1.32 +
    1.33 +  nsXMLBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr)
    1.34 +    : mVar(aVar), mExpr(aExpr), mNext(nullptr)
    1.35 +  {
    1.36 +    MOZ_COUNT_CTOR(nsXMLBinding);
    1.37 +  }
    1.38 +
    1.39 +  ~nsXMLBinding()
    1.40 +  {
    1.41 +    MOZ_COUNT_DTOR(nsXMLBinding);
    1.42 +  }
    1.43 +};
    1.44 +
    1.45 +/**
    1.46 + * a collection of <binding> descriptors. This object is refcounted by
    1.47 + * nsXMLBindingValues objects and the query processor.
    1.48 + */
    1.49 +class nsXMLBindingSet MOZ_FINAL
    1.50 +{
    1.51 +public:
    1.52 +
    1.53 +  // results hold a reference to a binding set in their
    1.54 +  // nsXMLBindingValues fields
    1.55 +  nsCycleCollectingAutoRefCnt mRefCnt;
    1.56 +
    1.57 +  // pointer to the first binding in a linked list
    1.58 +  nsAutoPtr<nsXMLBinding> mFirst;
    1.59 +
    1.60 +public:
    1.61 +
    1.62 +  NS_METHOD_(MozExternalRefCountType) AddRef();
    1.63 +  NS_METHOD_(MozExternalRefCountType) Release();
    1.64 +  NS_DECL_OWNINGTHREAD
    1.65 +  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXMLBindingSet)
    1.66 +
    1.67 +  /**
    1.68 +   * Add a binding to the set
    1.69 +   */
    1.70 +  nsresult
    1.71 +  AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr);
    1.72 +
    1.73 +  /**
    1.74 +   * The nsXMLBindingValues class stores an array of values, one for each
    1.75 +   * target symbol that could be set by the bindings in the set.
    1.76 +   * LookupTargetIndex determines the index into the array for a given
    1.77 +   * target symbol.
    1.78 +   */
    1.79 +  int32_t
    1.80 +  LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding);
    1.81 +};
    1.82 +
    1.83 +/**
    1.84 + * a set of values of bindings. This object is used once per result.
    1.85 + */
    1.86 +class nsXMLBindingValues
    1.87 +{
    1.88 +protected:
    1.89 +
    1.90 +  // the binding set
    1.91 +  nsRefPtr<nsXMLBindingSet> mBindings;
    1.92 +
    1.93 +  /**
    1.94 +   * A set of values for variable bindings. To look up a binding value,
    1.95 +   * scan through the binding set in mBindings for the right target atom.
    1.96 +   * Its index will correspond to the index in this array.
    1.97 +   */
    1.98 +  nsCOMArray<nsIDOMXPathResult> mValues;
    1.99 +
   1.100 +public:
   1.101 +
   1.102 +  nsXMLBindingValues() { MOZ_COUNT_CTOR(nsXMLBindingValues); }
   1.103 +  ~nsXMLBindingValues() { MOZ_COUNT_DTOR(nsXMLBindingValues); }
   1.104 +
   1.105 +  nsXMLBindingSet* GetBindingSet() { return mBindings; }
   1.106 +
   1.107 +  void SetBindingSet(nsXMLBindingSet* aBindings) { mBindings = aBindings; }
   1.108 +
   1.109 +  int32_t
   1.110 +  LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding)
   1.111 +  {
   1.112 +    return mBindings ?
   1.113 +           mBindings->LookupTargetIndex(aTargetVariable, aBinding) : -1;
   1.114 +  }
   1.115 +
   1.116 +  /**
   1.117 +   * Retrieve the assignment for a particular variable
   1.118 +   *
   1.119 +   * aResult the result generated from the template
   1.120 +   * aBinding the binding looked up using LookupTargetIndex
   1.121 +   * aIndex the index of the assignment to retrieve
   1.122 +   * aType the type of result expected
   1.123 +   * aValue the value of the assignment
   1.124 +   */
   1.125 +  void
   1.126 +  GetAssignmentFor(nsXULTemplateResultXML* aResult,
   1.127 +                   nsXMLBinding* aBinding,
   1.128 +                   int32_t idx,
   1.129 +                   uint16_t type,
   1.130 +                   nsIDOMXPathResult** aValue);
   1.131 +
   1.132 +  void
   1.133 +  GetNodeAssignmentFor(nsXULTemplateResultXML* aResult,
   1.134 +                       nsXMLBinding* aBinding,
   1.135 +                       int32_t idx,
   1.136 +                       nsIDOMNode** aValue);
   1.137 +
   1.138 +  void
   1.139 +  GetStringAssignmentFor(nsXULTemplateResultXML* aResult,
   1.140 +                         nsXMLBinding* aBinding,
   1.141 +                         int32_t idx,
   1.142 +                         nsAString& aValue);
   1.143 +};
   1.144 +
   1.145 +#endif // nsXMLBinding_h__

mercurial