Line data Source code
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 :
6 : #ifndef mozilla_dom_XPathEvaluator_h
7 : #define mozilla_dom_XPathEvaluator_h
8 :
9 : #include "nsIDOMXPathEvaluator.h"
10 : #include "nsIWeakReference.h"
11 : #include "nsAutoPtr.h"
12 : #include "nsString.h"
13 : #include "mozilla/Attributes.h"
14 : #include "mozilla/ErrorResult.h"
15 : #include "nsIDocument.h"
16 :
17 : class nsINode;
18 : class txIParseContext;
19 : class txResultRecycler;
20 :
21 : namespace mozilla {
22 : namespace dom {
23 :
24 : class GlobalObject;
25 : class XPathExpression;
26 : class XPathNSResolver;
27 : class XPathResult;
28 :
29 : /**
30 : * A class for evaluating an XPath expression string
31 : */
32 : class XPathEvaluator final : public nsIDOMXPathEvaluator
33 : {
34 : ~XPathEvaluator();
35 :
36 : public:
37 : explicit XPathEvaluator(nsIDocument* aDocument = nullptr);
38 :
39 : NS_DECL_ISUPPORTS
40 :
41 : // nsIDOMXPathEvaluator interface
42 : NS_DECL_NSIDOMXPATHEVALUATOR
43 :
44 : // WebIDL API
45 : bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
46 0 : nsIDocument* GetParentObject()
47 : {
48 0 : nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
49 0 : return doc;
50 : }
51 : static already_AddRefed<XPathEvaluator>
52 : Constructor(const GlobalObject& aGlobal, ErrorResult& rv);
53 : XPathExpression*
54 : CreateExpression(const nsAString& aExpression,
55 : XPathNSResolver* aResolver,
56 : ErrorResult& rv);
57 : XPathExpression*
58 : CreateExpression(const nsAString& aExpression,
59 : nsINode* aResolver,
60 : ErrorResult& aRv);
61 0 : nsINode* CreateNSResolver(nsINode& aNodeResolver)
62 : {
63 0 : return &aNodeResolver;
64 : }
65 : already_AddRefed<XPathResult>
66 : Evaluate(JSContext* aCx, const nsAString& aExpression,
67 : nsINode& aContextNode, XPathNSResolver* aResolver,
68 : uint16_t aType, JS::Handle<JSObject*> aResult,
69 : ErrorResult& rv);
70 : private:
71 : XPathExpression*
72 : CreateExpression(const nsAString& aExpression,
73 : txIParseContext* aContext,
74 : nsIDocument* aDocument,
75 : ErrorResult& aRv);
76 :
77 : nsWeakPtr mDocument;
78 : RefPtr<txResultRecycler> mRecycler;
79 : };
80 :
81 : inline nsISupports*
82 15 : ToSupports(XPathEvaluator* e)
83 : {
84 15 : return static_cast<nsIDOMXPathEvaluator*>(e);
85 : }
86 :
87 : /* d0a75e02-b5e7-11d5-a7f2-df109fb8a1fc */
88 : #define TRANSFORMIIX_XPATH_EVALUATOR_CID \
89 : { 0xd0a75e02, 0xb5e7, 0x11d5, { 0xa7, 0xf2, 0xdf, 0x10, 0x9f, 0xb8, 0xa1, 0xfc } }
90 :
91 : } // namespace dom
92 : } // namespace mozilla
93 :
94 : #endif /* mozilla_dom_XPathEvaluator_h */
|