txPredicatedNodeTest.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "txExpr.h"
  6. #include "txExprResult.h"
  7. #include "txSingleNodeContext.h"
  8. txPredicatedNodeTest::txPredicatedNodeTest(txNodeTest* aNodeTest,
  9. Expr* aPredicate)
  10. : mNodeTest(aNodeTest),
  11. mPredicate(aPredicate)
  12. {
  13. NS_ASSERTION(!mPredicate->isSensitiveTo(Expr::NODESET_CONTEXT),
  14. "predicate must not be context-nodeset-sensitive");
  15. }
  16. bool
  17. txPredicatedNodeTest::matches(const txXPathNode& aNode,
  18. txIMatchContext* aContext)
  19. {
  20. if (!mNodeTest->matches(aNode, aContext)) {
  21. return false;
  22. }
  23. txSingleNodeContext context(aNode, aContext);
  24. RefPtr<txAExprResult> res;
  25. nsresult rv = mPredicate->evaluate(&context, getter_AddRefs(res));
  26. NS_ENSURE_SUCCESS(rv, false);
  27. return res->booleanValue();
  28. }
  29. double
  30. txPredicatedNodeTest::getDefaultPriority()
  31. {
  32. return 0.5;
  33. }
  34. bool
  35. txPredicatedNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext)
  36. {
  37. return mNodeTest->isSensitiveTo(aContext) ||
  38. mPredicate->isSensitiveTo(aContext);
  39. }
  40. #ifdef TX_TO_STRING
  41. void
  42. txPredicatedNodeTest::toString(nsAString& aDest)
  43. {
  44. mNodeTest->toString(aDest);
  45. aDest.Append(char16_t('['));
  46. mPredicate->toString(aDest);
  47. aDest.Append(char16_t(']'));
  48. }
  49. #endif