Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / xml / XPathStep.h
blob8bd423ca8521a898ca6441150fd53acc07c5db3f
1 /*
2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org>
3 * Copyright (C) 2006, 2009 Apple Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
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.
27 #ifndef XPathStep_h
28 #define XPathStep_h
30 #include "core/xml/XPathExpressionNode.h"
31 #include "core/xml/XPathNodeSet.h"
33 namespace blink {
35 class Node;
37 namespace XPath {
39 class Predicate;
41 class Step final : public ParseNode {
42 WTF_MAKE_NONCOPYABLE(Step);
43 public:
44 enum Axis {
45 AncestorAxis, AncestorOrSelfAxis, AttributeAxis,
46 ChildAxis, DescendantAxis, DescendantOrSelfAxis,
47 FollowingAxis, FollowingSiblingAxis, NamespaceAxis,
48 ParentAxis, PrecedingAxis, PrecedingSiblingAxis,
49 SelfAxis
52 class NodeTest : public GarbageCollectedFinalized<NodeTest> {
53 public:
54 enum Kind {
55 TextNodeTest, CommentNodeTest, ProcessingInstructionNodeTest, AnyNodeTest, NameTest
58 NodeTest(Kind kind) : m_kind(kind) { }
59 NodeTest(Kind kind, const String& data) : m_kind(kind), m_data(data) { }
60 NodeTest(Kind kind, const AtomicString& data, const AtomicString& namespaceURI) : m_kind(kind), m_data(data), m_namespaceURI(namespaceURI) { }
62 NodeTest(const NodeTest& o)
63 : m_kind(o.m_kind)
64 , m_data(o.m_data)
65 , m_namespaceURI(o.m_namespaceURI)
67 ASSERT(o.m_mergedPredicates.isEmpty());
69 NodeTest& operator=(const NodeTest& o)
71 m_kind = o.m_kind;
72 m_data = o.m_data;
73 m_namespaceURI = o.m_namespaceURI;
74 ASSERT(o.m_mergedPredicates.isEmpty());
75 return *this;
77 DEFINE_INLINE_TRACE() { visitor->trace(m_mergedPredicates); }
79 Kind kind() const { return m_kind; }
80 const AtomicString& data() const { return m_data; }
81 const AtomicString& namespaceURI() const { return m_namespaceURI; }
82 HeapVector<Member<Predicate>>& mergedPredicates() { return m_mergedPredicates; }
83 const HeapVector<Member<Predicate>>& mergedPredicates() const { return m_mergedPredicates; }
85 private:
86 Kind m_kind;
87 AtomicString m_data;
88 AtomicString m_namespaceURI;
90 // When possible, we merge some or all predicates with node test for better performance.
91 HeapVector<Member<Predicate>> m_mergedPredicates;
94 Step(Axis, const NodeTest&);
95 Step(Axis, const NodeTest&, HeapVector<Member<Predicate>>&);
96 ~Step() override;
97 DECLARE_VIRTUAL_TRACE();
99 void optimize();
101 void evaluate(EvaluationContext&, Node* context, NodeSet&) const;
103 Axis axis() const { return m_axis; }
104 const NodeTest& nodeTest() const { return *m_nodeTest; }
106 private:
107 friend bool optimizeStepPair(Step*, Step*);
108 bool predicatesAreContextListInsensitive() const;
109 NodeTest& nodeTest() { return *m_nodeTest; }
111 void parseNodeTest(const String&);
112 void nodesInAxis(EvaluationContext&, Node* context, NodeSet&) const;
113 String namespaceFromNodetest(const String& nodeTest) const;
115 Axis m_axis;
116 Member<NodeTest> m_nodeTest;
117 HeapVector<Member<Predicate>> m_predicates;
120 bool optimizeStepPair(Step*, Step*);
122 } // namespace XPath
124 } // namespace blink
126 #endif // XPathStep_h