1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/xpath/txPredicatedNodeTest.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 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 "txExpr.h" 1.10 +#include "txExprResult.h" 1.11 +#include "txSingleNodeContext.h" 1.12 + 1.13 +txPredicatedNodeTest::txPredicatedNodeTest(txNodeTest* aNodeTest, 1.14 + Expr* aPredicate) 1.15 + : mNodeTest(aNodeTest), 1.16 + mPredicate(aPredicate) 1.17 +{ 1.18 + NS_ASSERTION(!mPredicate->isSensitiveTo(Expr::NODESET_CONTEXT), 1.19 + "predicate must not be context-nodeset-sensitive"); 1.20 +} 1.21 + 1.22 +bool 1.23 +txPredicatedNodeTest::matches(const txXPathNode& aNode, 1.24 + txIMatchContext* aContext) 1.25 +{ 1.26 + if (!mNodeTest->matches(aNode, aContext)) { 1.27 + return false; 1.28 + } 1.29 + 1.30 + txSingleNodeContext context(aNode, aContext); 1.31 + nsRefPtr<txAExprResult> res; 1.32 + nsresult rv = mPredicate->evaluate(&context, getter_AddRefs(res)); 1.33 + NS_ENSURE_SUCCESS(rv, false); 1.34 + 1.35 + return res->booleanValue(); 1.36 +} 1.37 + 1.38 +double 1.39 +txPredicatedNodeTest::getDefaultPriority() 1.40 +{ 1.41 + return 0.5; 1.42 +} 1.43 + 1.44 +bool 1.45 +txPredicatedNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext) 1.46 +{ 1.47 + return mNodeTest->isSensitiveTo(aContext) || 1.48 + mPredicate->isSensitiveTo(aContext); 1.49 +} 1.50 + 1.51 +#ifdef TX_TO_STRING 1.52 +void 1.53 +txPredicatedNodeTest::toString(nsAString& aDest) 1.54 +{ 1.55 + mNodeTest->toString(aDest); 1.56 + aDest.Append(char16_t('[')); 1.57 + mPredicate->toString(aDest); 1.58 + aDest.Append(char16_t(']')); 1.59 +} 1.60 +#endif