2007-06-15 19:03:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
#ifndef nsXMLBinding_h__
|
|
|
|
#define nsXMLBinding_h__
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIAtom.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-06-27 23:39:50 +04:00
|
|
|
#include "mozilla/dom/XPathExpression.h"
|
2007-06-15 19:03:44 +04:00
|
|
|
|
2013-07-04 19:40:10 +04:00
|
|
|
class nsINode;
|
2007-06-15 19:03:44 +04:00
|
|
|
class nsXULTemplateResultXML;
|
|
|
|
class nsXMLBindingValues;
|
2013-07-04 19:40:06 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class XPathResult;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Classes related to storing bindings for XML handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a <binding> description
|
|
|
|
*/
|
|
|
|
struct nsXMLBinding {
|
|
|
|
nsCOMPtr<nsIAtom> mVar;
|
2014-06-27 23:39:50 +04:00
|
|
|
nsAutoPtr<mozilla::dom::XPathExpression> mExpr;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
nsAutoPtr<nsXMLBinding> mNext;
|
|
|
|
|
2014-06-27 23:39:50 +04:00
|
|
|
nsXMLBinding(nsIAtom* aVar, nsAutoPtr<mozilla::dom::XPathExpression>&& aExpr)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mVar(aVar), mExpr(aExpr), mNext(nullptr)
|
2007-06-15 19:03:44 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXMLBinding);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsXMLBinding()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsXMLBinding);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a collection of <binding> descriptors. This object is refcounted by
|
|
|
|
* nsXMLBindingValues objects and the query processor.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXMLBindingSet final
|
2007-06-15 19:03:44 +04:00
|
|
|
{
|
2014-06-25 06:09:15 +04:00
|
|
|
~nsXMLBindingSet();
|
|
|
|
|
2007-06-15 19:03:44 +04:00
|
|
|
public:
|
|
|
|
// pointer to the first binding in a linked list
|
|
|
|
nsAutoPtr<nsXMLBinding> mFirst;
|
|
|
|
|
2014-06-26 17:32:20 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsXMLBindingSet);
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a binding to the set
|
|
|
|
*/
|
2013-07-04 19:40:10 +04:00
|
|
|
void
|
2014-06-27 23:39:50 +04:00
|
|
|
AddBinding(nsIAtom* aVar, nsAutoPtr<mozilla::dom::XPathExpression>&& aExpr);
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The nsXMLBindingValues class stores an array of values, one for each
|
|
|
|
* target symbol that could be set by the bindings in the set.
|
|
|
|
* LookupTargetIndex determines the index into the array for a given
|
|
|
|
* target symbol.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2007-06-15 19:03:44 +04:00
|
|
|
LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a set of values of bindings. This object is used once per result.
|
|
|
|
*/
|
|
|
|
class nsXMLBindingValues
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// the binding set
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXMLBindingSet> mBindings;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A set of values for variable bindings. To look up a binding value,
|
|
|
|
* scan through the binding set in mBindings for the right target atom.
|
|
|
|
* Its index will correspond to the index in this array.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<mozilla::dom::XPathResult> > mValues;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsXMLBindingValues() { MOZ_COUNT_CTOR(nsXMLBindingValues); }
|
|
|
|
~nsXMLBindingValues() { MOZ_COUNT_DTOR(nsXMLBindingValues); }
|
|
|
|
|
|
|
|
nsXMLBindingSet* GetBindingSet() { return mBindings; }
|
|
|
|
|
|
|
|
void SetBindingSet(nsXMLBindingSet* aBindings) { mBindings = aBindings; }
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2007-06-15 19:03:44 +04:00
|
|
|
LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding)
|
|
|
|
{
|
|
|
|
return mBindings ?
|
|
|
|
mBindings->LookupTargetIndex(aTargetVariable, aBinding) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the assignment for a particular variable
|
|
|
|
*
|
|
|
|
* aResult the result generated from the template
|
|
|
|
* aBinding the binding looked up using LookupTargetIndex
|
|
|
|
* aIndex the index of the assignment to retrieve
|
|
|
|
* aType the type of result expected
|
|
|
|
*/
|
2013-07-04 19:40:06 +04:00
|
|
|
mozilla::dom::XPathResult*
|
2007-06-15 19:03:44 +04:00
|
|
|
GetAssignmentFor(nsXULTemplateResultXML* aResult,
|
|
|
|
nsXMLBinding* aBinding,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t idx,
|
2013-07-04 19:40:06 +04:00
|
|
|
uint16_t type);
|
2007-06-15 19:03:44 +04:00
|
|
|
|
2013-07-04 19:40:10 +04:00
|
|
|
nsINode*
|
2007-06-15 19:03:44 +04:00
|
|
|
GetNodeAssignmentFor(nsXULTemplateResultXML* aResult,
|
|
|
|
nsXMLBinding* aBinding,
|
2013-07-04 19:40:10 +04:00
|
|
|
int32_t idx);
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
GetStringAssignmentFor(nsXULTemplateResultXML* aResult,
|
|
|
|
nsXMLBinding* aBinding,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t idx,
|
2007-06-15 19:03:44 +04:00
|
|
|
nsAString& aValue);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXMLBinding_h__
|