1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/xpath/txNamedAttributeStep.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 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 +#include "nsIAtom.h" 1.10 +#include "txIXPathContext.h" 1.11 +#include "txNodeSet.h" 1.12 +#include "txExpr.h" 1.13 +#include "txXPathTreeWalker.h" 1.14 + 1.15 +txNamedAttributeStep::txNamedAttributeStep(int32_t aNsID, 1.16 + nsIAtom* aPrefix, 1.17 + nsIAtom* aLocalName) 1.18 + : mNamespace(aNsID), 1.19 + mPrefix(aPrefix), 1.20 + mLocalName(aLocalName) 1.21 +{ 1.22 +} 1.23 + 1.24 +nsresult 1.25 +txNamedAttributeStep::evaluate(txIEvalContext* aContext, 1.26 + txAExprResult** aResult) 1.27 +{ 1.28 + *aResult = nullptr; 1.29 + 1.30 + nsRefPtr<txNodeSet> nodes; 1.31 + nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); 1.32 + NS_ENSURE_SUCCESS(rv, rv); 1.33 + 1.34 + txXPathTreeWalker walker(aContext->getContextNode()); 1.35 + if (walker.moveToNamedAttribute(mLocalName, mNamespace)) { 1.36 + rv = nodes->append(walker.getCurrentPosition()); 1.37 + NS_ENSURE_SUCCESS(rv, rv); 1.38 + } 1.39 + NS_ADDREF(*aResult = nodes); 1.40 + 1.41 + return NS_OK; 1.42 +} 1.43 + 1.44 +TX_IMPL_EXPR_STUBS_0(txNamedAttributeStep, NODESET_RESULT) 1.45 + 1.46 +bool 1.47 +txNamedAttributeStep::isSensitiveTo(ContextSensitivity aContext) 1.48 +{ 1.49 + return !!(aContext & NODE_CONTEXT); 1.50 +} 1.51 + 1.52 +#ifdef TX_TO_STRING 1.53 +void 1.54 +txNamedAttributeStep::toString(nsAString& aDest) 1.55 +{ 1.56 + aDest.Append(char16_t('@')); 1.57 + if (mPrefix) { 1.58 + nsAutoString prefix; 1.59 + mPrefix->ToString(prefix); 1.60 + aDest.Append(prefix); 1.61 + aDest.Append(char16_t(':')); 1.62 + } 1.63 + nsAutoString localName; 1.64 + mLocalName->ToString(localName); 1.65 + aDest.Append(localName); 1.66 +} 1.67 +#endif