Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: third_party/WebKit/Source/core/xml/XPathResult.cpp

Issue 2068053002: Rename Blink constants generated from IDL files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org> 2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org>
3 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 25 matching lines...) Expand all
36 36
37 using namespace XPath; 37 using namespace XPath;
38 38
39 XPathResult::XPathResult(EvaluationContext& context, const Value& value) 39 XPathResult::XPathResult(EvaluationContext& context, const Value& value)
40 : m_value(value) 40 : m_value(value)
41 , m_nodeSetPosition(0) 41 , m_nodeSetPosition(0)
42 , m_domTreeVersion(0) 42 , m_domTreeVersion(0)
43 { 43 {
44 switch (m_value.getType()) { 44 switch (m_value.getType()) {
45 case Value::BooleanValue: 45 case Value::BooleanValue:
46 m_resultType = BOOLEAN_TYPE; 46 m_resultType = kBooleanType;
47 return; 47 return;
48 case Value::NumberValue: 48 case Value::NumberValue:
49 m_resultType = NUMBER_TYPE; 49 m_resultType = kNumberType;
50 return; 50 return;
51 case Value::StringValue: 51 case Value::StringValue:
52 m_resultType = STRING_TYPE; 52 m_resultType = kStringType;
53 return; 53 return;
54 case Value::NodeSetValue: 54 case Value::NodeSetValue:
55 m_resultType = UNORDERED_NODE_ITERATOR_TYPE; 55 m_resultType = kUnorderedNodeIteratorType;
56 m_nodeSetPosition = 0; 56 m_nodeSetPosition = 0;
57 m_nodeSet = NodeSet::create(m_value.toNodeSet(&context)); 57 m_nodeSet = NodeSet::create(m_value.toNodeSet(&context));
58 m_document = &context.node->document(); 58 m_document = &context.node->document();
59 m_domTreeVersion = m_document->domTreeVersion(); 59 m_domTreeVersion = m_document->domTreeVersion();
60 return; 60 return;
61 } 61 }
62 ASSERT_NOT_REACHED(); 62 ASSERT_NOT_REACHED();
63 } 63 }
64 64
65 DEFINE_TRACE(XPathResult) 65 DEFINE_TRACE(XPathResult)
66 { 66 {
67 visitor->trace(m_value); 67 visitor->trace(m_value);
68 visitor->trace(m_nodeSet); 68 visitor->trace(m_nodeSet);
69 visitor->trace(m_document); 69 visitor->trace(m_document);
70 } 70 }
71 71
72 void XPathResult::convertTo(unsigned short type, ExceptionState& exceptionState) 72 void XPathResult::convertTo(unsigned short type, ExceptionState& exceptionState)
73 { 73 {
74 switch (type) { 74 switch (type) {
75 case ANY_TYPE: 75 case kAnyType:
76 break; 76 break;
77 case NUMBER_TYPE: 77 case kNumberType:
78 m_resultType = type; 78 m_resultType = type;
79 m_value = m_value.toNumber(); 79 m_value = m_value.toNumber();
80 break; 80 break;
81 case STRING_TYPE: 81 case kStringType:
82 m_resultType = type; 82 m_resultType = type;
83 m_value = m_value.toString(); 83 m_value = m_value.toString();
84 break; 84 break;
85 case BOOLEAN_TYPE: 85 case kBooleanType:
86 m_resultType = type; 86 m_resultType = type;
87 m_value = m_value.toBoolean(); 87 m_value = m_value.toBoolean();
88 break; 88 break;
89 case UNORDERED_NODE_ITERATOR_TYPE: 89 case kUnorderedNodeIteratorType:
90 case UNORDERED_NODE_SNAPSHOT_TYPE: 90 case kUnorderedNodeSnapshotType:
91 case ANY_UNORDERED_NODE_TYPE: 91 case kAnyUnorderedNodeType:
92 // This is correct - singleNodeValue() will take care of ordering. 92 // This is correct - singleNodeValue() will take care of ordering.
93 case FIRST_ORDERED_NODE_TYPE: 93 case kFirstOrderedNodeType:
94 if (!m_value.isNodeSet()) { 94 if (!m_value.isNodeSet()) {
95 exceptionState.throwTypeError("The result is not a node set, and the refore cannot be converted to the desired type."); 95 exceptionState.throwTypeError("The result is not a node set, and the refore cannot be converted to the desired type.");
96 return; 96 return;
97 } 97 }
98 m_resultType = type; 98 m_resultType = type;
99 break; 99 break;
100 case ORDERED_NODE_ITERATOR_TYPE: 100 case kOrderedNodeIteratorType:
101 if (!m_value.isNodeSet()) { 101 if (!m_value.isNodeSet()) {
102 exceptionState.throwTypeError("The result is not a node set, and the refore cannot be converted to the desired type."); 102 exceptionState.throwTypeError("The result is not a node set, and the refore cannot be converted to the desired type.");
103 return; 103 return;
104 } 104 }
105 nodeSet().sort(); 105 nodeSet().sort();
106 m_resultType = type; 106 m_resultType = type;
107 break; 107 break;
108 case ORDERED_NODE_SNAPSHOT_TYPE: 108 case kOrderedNodeSnapshotType:
109 if (!m_value.isNodeSet()) { 109 if (!m_value.isNodeSet()) {
110 exceptionState.throwTypeError("The result is not a node set, and the refore cannot be converted to the desired type."); 110 exceptionState.throwTypeError("The result is not a node set, and the refore cannot be converted to the desired type.");
111 return; 111 return;
112 } 112 }
113 m_value.toNodeSet(0).sort(); 113 m_value.toNodeSet(0).sort();
114 m_resultType = type; 114 m_resultType = type;
115 break; 115 break;
116 } 116 }
117 } 117 }
118 118
119 unsigned short XPathResult::resultType() const 119 unsigned short XPathResult::resultType() const
120 { 120 {
121 return m_resultType; 121 return m_resultType;
122 } 122 }
123 123
124 double XPathResult::numberValue(ExceptionState& exceptionState) const 124 double XPathResult::numberValue(ExceptionState& exceptionState) const
125 { 125 {
126 if (resultType() != NUMBER_TYPE) { 126 if (resultType() != kNumberType) {
127 exceptionState.throwTypeError("The result type is not a number."); 127 exceptionState.throwTypeError("The result type is not a number.");
128 return 0.0; 128 return 0.0;
129 } 129 }
130 return m_value.toNumber(); 130 return m_value.toNumber();
131 } 131 }
132 132
133 String XPathResult::stringValue(ExceptionState& exceptionState) const 133 String XPathResult::stringValue(ExceptionState& exceptionState) const
134 { 134 {
135 if (resultType() != STRING_TYPE) { 135 if (resultType() != kStringType) {
136 exceptionState.throwTypeError("The result type is not a string."); 136 exceptionState.throwTypeError("The result type is not a string.");
137 return String(); 137 return String();
138 } 138 }
139 return m_value.toString(); 139 return m_value.toString();
140 } 140 }
141 141
142 bool XPathResult::booleanValue(ExceptionState& exceptionState) const 142 bool XPathResult::booleanValue(ExceptionState& exceptionState) const
143 { 143 {
144 if (resultType() != BOOLEAN_TYPE) { 144 if (resultType() != kBooleanType) {
145 exceptionState.throwTypeError("The result type is not a boolean."); 145 exceptionState.throwTypeError("The result type is not a boolean.");
146 return false; 146 return false;
147 } 147 }
148 return m_value.toBoolean(); 148 return m_value.toBoolean();
149 } 149 }
150 150
151 Node* XPathResult::singleNodeValue(ExceptionState& exceptionState) const 151 Node* XPathResult::singleNodeValue(ExceptionState& exceptionState) const
152 { 152 {
153 if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED _NODE_TYPE) { 153 if (resultType() != kAnyUnorderedNodeType && resultType() != kFirstOrderedNo deType) {
154 exceptionState.throwTypeError("The result type is not a single node."); 154 exceptionState.throwTypeError("The result type is not a single node.");
155 return nullptr; 155 return nullptr;
156 } 156 }
157 157
158 const NodeSet& nodes = m_value.toNodeSet(0); 158 const NodeSet& nodes = m_value.toNodeSet(0);
159 if (resultType() == FIRST_ORDERED_NODE_TYPE) 159 if (resultType() == kFirstOrderedNodeType)
160 return nodes.firstNode(); 160 return nodes.firstNode();
161 return nodes.anyNode(); 161 return nodes.anyNode();
162 } 162 }
163 163
164 bool XPathResult::invalidIteratorState() const 164 bool XPathResult::invalidIteratorState() const
165 { 165 {
166 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_ NODE_ITERATOR_TYPE) 166 if (resultType() != kUnorderedNodeIteratorType && resultType() != kOrderedNo deIteratorType)
167 return false; 167 return false;
168 168
169 ASSERT(m_document); 169 ASSERT(m_document);
170 return m_document->domTreeVersion() != m_domTreeVersion; 170 return m_document->domTreeVersion() != m_domTreeVersion;
171 } 171 }
172 172
173 unsigned XPathResult::snapshotLength(ExceptionState& exceptionState) const 173 unsigned XPathResult::snapshotLength(ExceptionState& exceptionState) const
174 { 174 {
175 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_ NODE_SNAPSHOT_TYPE) { 175 if (resultType() != kUnorderedNodeSnapshotType && resultType() != kOrderedNo deSnapshotType) {
176 exceptionState.throwTypeError("The result type is not a snapshot."); 176 exceptionState.throwTypeError("The result type is not a snapshot.");
177 return 0; 177 return 0;
178 } 178 }
179 179
180 return m_value.toNodeSet(0).size(); 180 return m_value.toNodeSet(0).size();
181 } 181 }
182 182
183 Node* XPathResult::iterateNext(ExceptionState& exceptionState) 183 Node* XPathResult::iterateNext(ExceptionState& exceptionState)
184 { 184 {
185 if (resultType() != UNORDERED_NODE_ITERATOR_TYPE && resultType() != ORDERED_ NODE_ITERATOR_TYPE) { 185 if (resultType() != kUnorderedNodeIteratorType && resultType() != kOrderedNo deIteratorType) {
186 exceptionState.throwTypeError("The result type is not an iterator."); 186 exceptionState.throwTypeError("The result type is not an iterator.");
187 return nullptr; 187 return nullptr;
188 } 188 }
189 189
190 if (invalidIteratorState()) { 190 if (invalidIteratorState()) {
191 exceptionState.throwDOMException(InvalidStateError, "The document has mu tated since the result was returned."); 191 exceptionState.throwDOMException(InvalidStateError, "The document has mu tated since the result was returned.");
192 return nullptr; 192 return nullptr;
193 } 193 }
194 194
195 if (m_nodeSetPosition + 1 > nodeSet().size()) 195 if (m_nodeSetPosition + 1 > nodeSet().size())
196 return nullptr; 196 return nullptr;
197 197
198 Node* node = nodeSet()[m_nodeSetPosition]; 198 Node* node = nodeSet()[m_nodeSetPosition];
199 199
200 m_nodeSetPosition++; 200 m_nodeSetPosition++;
201 201
202 return node; 202 return node;
203 } 203 }
204 204
205 Node* XPathResult::snapshotItem(unsigned index, ExceptionState& exceptionState) 205 Node* XPathResult::snapshotItem(unsigned index, ExceptionState& exceptionState)
206 { 206 {
207 if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_ NODE_SNAPSHOT_TYPE) { 207 if (resultType() != kUnorderedNodeSnapshotType && resultType() != kOrderedNo deSnapshotType) {
208 exceptionState.throwTypeError("The result type is not a snapshot."); 208 exceptionState.throwTypeError("The result type is not a snapshot.");
209 return nullptr; 209 return nullptr;
210 } 210 }
211 211
212 const NodeSet& nodes = m_value.toNodeSet(0); 212 const NodeSet& nodes = m_value.toNodeSet(0);
213 if (index >= nodes.size()) 213 if (index >= nodes.size())
214 return nullptr; 214 return nullptr;
215 215
216 return nodes[index]; 216 return nodes[index];
217 } 217 }
218 218
219 } // namespace blink 219 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/xml/XPathResult.h ('k') | third_party/WebKit/Source/core/xml/XPathStep.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698