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 "txExpr.h" michael@0: #include "txExprResult.h" michael@0: #include "txSingleNodeContext.h" michael@0: michael@0: txPredicatedNodeTest::txPredicatedNodeTest(txNodeTest* aNodeTest, michael@0: Expr* aPredicate) michael@0: : mNodeTest(aNodeTest), michael@0: mPredicate(aPredicate) michael@0: { michael@0: NS_ASSERTION(!mPredicate->isSensitiveTo(Expr::NODESET_CONTEXT), michael@0: "predicate must not be context-nodeset-sensitive"); michael@0: } michael@0: michael@0: bool michael@0: txPredicatedNodeTest::matches(const txXPathNode& aNode, michael@0: txIMatchContext* aContext) michael@0: { michael@0: if (!mNodeTest->matches(aNode, aContext)) { michael@0: return false; michael@0: } michael@0: michael@0: txSingleNodeContext context(aNode, aContext); michael@0: nsRefPtr res; michael@0: nsresult rv = mPredicate->evaluate(&context, getter_AddRefs(res)); michael@0: NS_ENSURE_SUCCESS(rv, false); michael@0: michael@0: return res->booleanValue(); michael@0: } michael@0: michael@0: double michael@0: txPredicatedNodeTest::getDefaultPriority() michael@0: { michael@0: return 0.5; michael@0: } michael@0: michael@0: bool michael@0: txPredicatedNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext) michael@0: { michael@0: return mNodeTest->isSensitiveTo(aContext) || michael@0: mPredicate->isSensitiveTo(aContext); michael@0: } michael@0: michael@0: #ifdef TX_TO_STRING michael@0: void michael@0: txPredicatedNodeTest::toString(nsAString& aDest) michael@0: { michael@0: mNodeTest->toString(aDest); michael@0: aDest.Append(char16_t('[')); michael@0: mPredicate->toString(aDest); michael@0: aDest.Append(char16_t(']')); michael@0: } michael@0: #endif