XPathExpression.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef mozilla_dom_XPathExpression_h
  6. #define mozilla_dom_XPathExpression_h
  7. #include "nsAutoPtr.h"
  8. #include "nsCycleCollectionParticipant.h"
  9. #include "nsIWeakReferenceUtils.h"
  10. #include "mozilla/Attributes.h"
  11. #include "mozilla/dom/NonRefcountedDOMObject.h"
  12. #include "mozilla/dom/XPathExpressionBinding.h"
  13. class Expr;
  14. class nsIDocument;
  15. class nsINode;
  16. class txResultRecycler;
  17. namespace mozilla {
  18. namespace dom {
  19. class XPathResult;
  20. /**
  21. * A class for evaluating an XPath expression string
  22. */
  23. class XPathExpression final : public NonRefcountedDOMObject
  24. {
  25. public:
  26. XPathExpression(nsAutoPtr<Expr>&& aExpression, txResultRecycler* aRecycler,
  27. nsIDocument *aDocument);
  28. ~XPathExpression();
  29. bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
  30. {
  31. return XPathExpressionBinding::Wrap(aCx, this, aGivenProto, aReflector);
  32. }
  33. already_AddRefed<XPathResult>
  34. Evaluate(JSContext* aCx, nsINode& aContextNode, uint16_t aType,
  35. JS::Handle<JSObject*> aInResult, ErrorResult& aRv)
  36. {
  37. return EvaluateWithContext(aCx, aContextNode, 1, 1, aType, aInResult,
  38. aRv);
  39. }
  40. already_AddRefed<XPathResult>
  41. EvaluateWithContext(JSContext* aCx, nsINode& aContextNode,
  42. uint32_t aContextPosition, uint32_t aContextSize,
  43. uint16_t aType, JS::Handle<JSObject*> aInResult,
  44. ErrorResult& aRv);
  45. already_AddRefed<XPathResult>
  46. Evaluate(nsINode& aContextNode, uint16_t aType, XPathResult* aInResult,
  47. ErrorResult& aRv)
  48. {
  49. return EvaluateWithContext(aContextNode, 1, 1, aType, aInResult, aRv);
  50. }
  51. already_AddRefed<XPathResult>
  52. EvaluateWithContext(nsINode& aContextNode, uint32_t aContextPosition,
  53. uint32_t aContextSize, uint16_t aType,
  54. XPathResult* aInResult, ErrorResult& aRv);
  55. private:
  56. nsAutoPtr<Expr> mExpression;
  57. RefPtr<txResultRecycler> mRecycler;
  58. nsWeakPtr mDocument;
  59. bool mCheckDocument;
  60. };
  61. } // namespace dom
  62. } // namespace mozilla
  63. #endif /* mozilla_dom_XPathExpression_h */