michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsIAtom.h" michael@0: #include "txIXPathContext.h" michael@0: #include "txNodeSet.h" michael@0: #include "txExpr.h" michael@0: #include "txXPathTreeWalker.h" michael@0: michael@0: txNamedAttributeStep::txNamedAttributeStep(int32_t aNsID, michael@0: nsIAtom* aPrefix, michael@0: nsIAtom* aLocalName) michael@0: : mNamespace(aNsID), michael@0: mPrefix(aPrefix), michael@0: mLocalName(aLocalName) michael@0: { michael@0: } michael@0: michael@0: nsresult michael@0: txNamedAttributeStep::evaluate(txIEvalContext* aContext, michael@0: txAExprResult** aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: michael@0: nsRefPtr nodes; michael@0: nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: txXPathTreeWalker walker(aContext->getContextNode()); michael@0: if (walker.moveToNamedAttribute(mLocalName, mNamespace)) { michael@0: rv = nodes->append(walker.getCurrentPosition()); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: } michael@0: NS_ADDREF(*aResult = nodes); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: TX_IMPL_EXPR_STUBS_0(txNamedAttributeStep, NODESET_RESULT) michael@0: michael@0: bool michael@0: txNamedAttributeStep::isSensitiveTo(ContextSensitivity aContext) michael@0: { michael@0: return !!(aContext & NODE_CONTEXT); michael@0: } michael@0: michael@0: #ifdef TX_TO_STRING michael@0: void michael@0: txNamedAttributeStep::toString(nsAString& aDest) michael@0: { michael@0: aDest.Append(char16_t('@')); michael@0: if (mPrefix) { michael@0: nsAutoString prefix; michael@0: mPrefix->ToString(prefix); michael@0: aDest.Append(prefix); michael@0: aDest.Append(char16_t(':')); michael@0: } michael@0: nsAutoString localName; michael@0: mLocalName->ToString(localName); michael@0: aDest.Append(localName); michael@0: } michael@0: #endif