1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 6 #ifndef mozilla_dom_XPathEvaluator_h 7 #define mozilla_dom_XPathEvaluator_h 8 9 #include "mozilla/dom/NonRefcountedDOMObject.h" 10 #include "nsString.h" 11 #include "mozilla/Attributes.h" 12 #include "mozilla/dom/Document.h" 13 14 class nsINode; 15 class txIParseContext; 16 class txResultRecycler; 17 18 namespace mozilla { 19 class ErrorResult; 20 21 namespace dom { 22 23 class GlobalObject; 24 class XPathExpression; 25 class XPathNSResolver; 26 class XPathResult; 27 28 /** 29 * A class for evaluating an XPath expression string 30 */ 31 class XPathEvaluator final : public NonRefcountedDOMObject { 32 public: 33 explicit XPathEvaluator(Document* aDocument = nullptr); 34 ~XPathEvaluator(); 35 36 // WebIDL API 37 bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, 38 JS::MutableHandle<JSObject*> aReflector); GetParentObject()39 Document* GetParentObject() { 40 nsCOMPtr<Document> doc = do_QueryReferent(mDocument); 41 return doc; 42 } 43 static XPathEvaluator* Constructor(const GlobalObject& aGlobal); 44 XPathExpression* CreateExpression(const nsAString& aExpression, 45 XPathNSResolver* aResolver, 46 ErrorResult& rv); 47 XPathExpression* CreateExpression(const nsAString& aExpression, 48 nsINode* aResolver, ErrorResult& aRv); 49 XPathExpression* CreateExpression(const nsAString& aExpression, 50 txIParseContext* aContext, 51 Document* aDocument, ErrorResult& aRv); CreateNSResolver(nsINode & aNodeResolver)52 nsINode* CreateNSResolver(nsINode& aNodeResolver) { return &aNodeResolver; } 53 already_AddRefed<XPathResult> Evaluate( 54 JSContext* aCx, const nsAString& aExpression, nsINode& aContextNode, 55 XPathNSResolver* aResolver, uint16_t aType, JS::Handle<JSObject*> aResult, 56 ErrorResult& rv); 57 58 private: 59 nsWeakPtr mDocument; 60 RefPtr<txResultRecycler> mRecycler; 61 }; 62 63 } // namespace dom 64 } // namespace mozilla 65 66 #endif /* mozilla_dom_XPathEvaluator_h */ 67