1 /*
2  * Copyright (C) 2005 Frerich Raabe <raabe@kde.org>
3  * Copyright (C) 2006, 2009 Apple Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_XML_XPATH_PATH_H_
28 #define THIRD_PARTY_BLINK_RENDERER_CORE_XML_XPATH_PATH_H_
29 
30 #include "third_party/blink/renderer/core/xml/xpath_expression_node.h"
31 #include "third_party/blink/renderer/core/xml/xpath_node_set.h"
32 
33 namespace blink {
34 
35 namespace xpath {
36 
37 class Predicate;
38 class Step;
39 
40 class Filter final : public Expression {
41  public:
42   Filter(Expression*, HeapVector<Member<Predicate>>&);
43   ~Filter() override;
44   void Trace(Visitor*) override;
45 
46   Value Evaluate(EvaluationContext&) const override;
47 
48  private:
ResultType()49   Value::Type ResultType() const override { return Value::kNodeSetValue; }
50 
51   Member<Expression> expr_;
52   HeapVector<Member<Predicate>> predicates_;
53 };
54 
55 class LocationPath final : public Expression {
56  public:
57   LocationPath();
58   ~LocationPath() override;
59   void Trace(Visitor*) override;
60 
61   Value Evaluate(EvaluationContext&) const override;
SetAbsolute(bool value)62   void SetAbsolute(bool value) {
63     absolute_ = value;
64     SetIsContextNodeSensitive(!absolute_);
65   }
66   void Evaluate(EvaluationContext&,
67                 NodeSet&) const;  // nodes is an input/output parameter
68   void AppendStep(Step*);
69   void InsertFirstStep(Step*);
70 
71  private:
ResultType()72   Value::Type ResultType() const override { return Value::kNodeSetValue; }
73 
74   HeapVector<Member<Step>> steps_;
75   bool absolute_;
76 };
77 
78 class Path final : public Expression {
79  public:
80   Path(Expression*, LocationPath*);
81   ~Path() override;
82   void Trace(Visitor*) override;
83 
84   Value Evaluate(EvaluationContext&) const override;
85 
86  private:
ResultType()87   Value::Type ResultType() const override { return Value::kNodeSetValue; }
88 
89   Member<Expression> filter_;
90   Member<LocationPath> path_;
91 };
92 
93 }  // namespace xpath
94 
95 }  // namespace blink
96 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_XML_XPATH_PATH_H_
97