OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkDisplayXMLParser.h" | 10 #include "SkDisplayXMLParser.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 inner.prepend(": "); | 64 inner.prepend(": "); |
65 inner.prependS32(getLineNumber()); | 65 inner.prependS32(getLineNumber()); |
66 inner.prepend(", line "); | 66 inner.prepend(", line "); |
67 inner.prepend(src); | 67 inner.prepend(src); |
68 parent->setErrorNoun(inner); | 68 parent->setErrorNoun(inner); |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 SkDisplayXMLParser::SkDisplayXMLParser(SkAnimateMaker& maker) | 72 SkDisplayXMLParser::SkDisplayXMLParser(SkAnimateMaker& maker) |
73 : INHERITED(&maker.fError), fMaker(maker), fInInclude(maker.fInInclude), | 73 : INHERITED(&maker.fError), fMaker(maker), fInInclude(maker.fInInclude), |
74 fInSkia(maker.fInInclude), fCurrDisplayable(NULL) | 74 fInSkia(maker.fInInclude), fCurrDisplayable(nullptr) |
75 { | 75 { |
76 } | 76 } |
77 | 77 |
78 SkDisplayXMLParser::~SkDisplayXMLParser() { | 78 SkDisplayXMLParser::~SkDisplayXMLParser() { |
79 if (fCurrDisplayable && fMaker.fChildren.find(fCurrDisplayable) < 0) | 79 if (fCurrDisplayable && fMaker.fChildren.find(fCurrDisplayable) < 0) |
80 delete fCurrDisplayable; | 80 delete fCurrDisplayable; |
81 for (Parent* parPtr = fParents.begin() + 1; parPtr < fParents.end(); parPtr+
+) { | 81 for (Parent* parPtr = fParents.begin() + 1; parPtr < fParents.end(); parPtr+
+) { |
82 SkDisplayable* displayable = parPtr->fDisplayable; | 82 SkDisplayable* displayable = parPtr->fDisplayable; |
83 if (displayable == fCurrDisplayable) | 83 if (displayable == fCurrDisplayable) |
84 continue; | 84 continue; |
85 SkASSERT(fMaker.fChildren.find(displayable) < 0); | 85 SkASSERT(fMaker.fChildren.find(displayable) < 0); |
86 if (fMaker.fHelpers.find(displayable) < 0) | 86 if (fMaker.fHelpers.find(displayable) < 0) |
87 delete displayable; | 87 delete displayable; |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 | 92 |
93 bool SkDisplayXMLParser::onAddAttribute(const char name[], const char value[]) { | 93 bool SkDisplayXMLParser::onAddAttribute(const char name[], const char value[]) { |
94 return onAddAttributeLen(name, value, strlen(value)); | 94 return onAddAttributeLen(name, value, strlen(value)); |
95 } | 95 } |
96 | 96 |
97 bool SkDisplayXMLParser::onAddAttributeLen(const char attrName[], const char att
rValue[], | 97 bool SkDisplayXMLParser::onAddAttributeLen(const char attrName[], const char att
rValue[], |
98 size_t attrValueLen) | 98 size_t attrValueLen) |
99 { | 99 { |
100 if (fCurrDisplayable == NULL) // this signals we should ignore attributes
for this element | 100 if (fCurrDisplayable == nullptr) // this signals we should ignore attribu
tes for this element |
101 return strncmp(attrName, "xmlns", sizeof("xmlns") - 1) != 0; | 101 return strncmp(attrName, "xmlns", sizeof("xmlns") - 1) != 0; |
102 SkDisplayable* displayable = fCurrDisplayable; | 102 SkDisplayable* displayable = fCurrDisplayable; |
103 SkDisplayTypes type = fCurrType; | 103 SkDisplayTypes type = fCurrType; |
104 | 104 |
105 if (strcmp(attrName, "id") == 0) { | 105 if (strcmp(attrName, "id") == 0) { |
106 if (fMaker.find(attrValue, attrValueLen, NULL)) { | 106 if (fMaker.find(attrValue, attrValueLen, nullptr)) { |
107 fError->setNoun(attrValue, attrValueLen); | 107 fError->setNoun(attrValue, attrValueLen); |
108 fError->setCode(SkXMLParserError::kDuplicateIDs); | 108 fError->setCode(SkXMLParserError::kDuplicateIDs); |
109 return true; | 109 return true; |
110 } | 110 } |
111 #ifdef SK_DEBUG | 111 #ifdef SK_DEBUG |
112 displayable->_id.set(attrValue, attrValueLen); | 112 displayable->_id.set(attrValue, attrValueLen); |
113 displayable->id = displayable->_id.c_str(); | 113 displayable->id = displayable->_id.c_str(); |
114 #endif | 114 #endif |
115 fMaker.idsSet(attrValue, attrValueLen, displayable); | 115 fMaker.idsSet(attrValue, attrValueLen, displayable); |
116 int parentIndex = fParents.count() - 1; | 116 int parentIndex = fParents.count() - 1; |
117 if (parentIndex > 0) { | 117 if (parentIndex > 0) { |
118 SkDisplayable* parent = fParents[parentIndex - 1].fDisplayable; | 118 SkDisplayable* parent = fParents[parentIndex - 1].fDisplayable; |
119 parent->setChildHasID(); | 119 parent->setChildHasID(); |
120 } | 120 } |
121 return false; | 121 return false; |
122 } | 122 } |
123 const char* name = attrName; | 123 const char* name = attrName; |
124 const SkMemberInfo* info = SkDisplayType::GetMember(&fMaker, type, &name); | 124 const SkMemberInfo* info = SkDisplayType::GetMember(&fMaker, type, &name); |
125 if (info == NULL) { | 125 if (info == nullptr) { |
126 fError->setNoun(name); | 126 fError->setNoun(name); |
127 fError->setCode(SkXMLParserError::kUnknownAttributeName); | 127 fError->setCode(SkXMLParserError::kUnknownAttributeName); |
128 return true; | 128 return true; |
129 } | 129 } |
130 if (info->setValue(fMaker, NULL, 0, info->getCount(), displayable, info->get
Type(), attrValue, | 130 if (info->setValue(fMaker, nullptr, 0, info->getCount(), displayable, info->
getType(), attrValue, |
131 attrValueLen)) | 131 attrValueLen)) |
132 return false; | 132 return false; |
133 if (fMaker.fError.hasError()) { | 133 if (fMaker.fError.hasError()) { |
134 fError->setNoun(attrValue, attrValueLen); | 134 fError->setNoun(attrValue, attrValueLen); |
135 return true; | 135 return true; |
136 } | 136 } |
137 SkDisplayable* ref = NULL; | 137 SkDisplayable* ref = nullptr; |
138 if (fMaker.find(attrValue, attrValueLen, &ref) == false) { | 138 if (fMaker.find(attrValue, attrValueLen, &ref) == false) { |
139 ref = fMaker.createInstance(attrValue, attrValueLen); | 139 ref = fMaker.createInstance(attrValue, attrValueLen); |
140 if (ref == NULL) { | 140 if (ref == nullptr) { |
141 fError->setNoun(attrValue, attrValueLen); | 141 fError->setNoun(attrValue, attrValueLen); |
142 fError->setCode(SkXMLParserError::kErrorInAttributeValue); | 142 fError->setCode(SkXMLParserError::kErrorInAttributeValue); |
143 return true; | 143 return true; |
144 } else | 144 } else |
145 fMaker.helperAdd(ref); | 145 fMaker.helperAdd(ref); |
146 } | 146 } |
147 if (info->fType != SkType_MemberProperty) { | 147 if (info->fType != SkType_MemberProperty) { |
148 fError->setNoun(name); | 148 fError->setNoun(name); |
149 fError->setCode(SkXMLParserError::kUnknownAttributeName); | 149 fError->setCode(SkXMLParserError::kUnknownAttributeName); |
150 return true; | 150 return true; |
(...skipping 26 matching lines...) Expand all Loading... |
177 if (parentIndex > 0) { | 177 if (parentIndex > 0) { |
178 SkDisplayable* parent = fParents[parentIndex - 1].fDisplayable; | 178 SkDisplayable* parent = fParents[parentIndex - 1].fDisplayable; |
179 bool result = parent->addChild(fMaker, displayable); | 179 bool result = parent->addChild(fMaker, displayable); |
180 if (fMaker.hasError()) | 180 if (fMaker.hasError()) |
181 return true; | 181 return true; |
182 if (result == false) { | 182 if (result == false) { |
183 int infoCount; | 183 int infoCount; |
184 const SkMemberInfo* info = | 184 const SkMemberInfo* info = |
185 SkDisplayType::GetMembers(&fMaker, fParents[parentIndex - 1]
.fType, &infoCount); | 185 SkDisplayType::GetMembers(&fMaker, fParents[parentIndex - 1]
.fType, &infoCount); |
186 const SkMemberInfo* foundInfo; | 186 const SkMemberInfo* foundInfo; |
187 if ((foundInfo = searchContainer(info, infoCount)) != NULL) { | 187 if ((foundInfo = searchContainer(info, infoCount)) != nullptr) { |
188 parent->setReference(foundInfo, displayable); | 188 parent->setReference(foundInfo, displayable); |
189 // if (displayable->isHelper() == false) | 189 // if (displayable->isHelper() == false) |
190 fMaker.helperAdd(displayable); | 190 fMaker.helperAdd(displayable); |
191 } else { | 191 } else { |
192 fMaker.setErrorCode(SkDisplayXMLParserError::kElementTypeNot
AllowedInParent); | 192 fMaker.setErrorCode(SkDisplayXMLParserError::kElementTypeNot
AllowedInParent); |
193 return true; | 193 return true; |
194 } | 194 } |
195 } | 195 } |
196 if (parent->childrenNeedDisposing()) | 196 if (parent->childrenNeedDisposing()) |
197 delete displayable; | 197 delete displayable; |
198 } | 198 } |
199 fParents.remove(parentIndex); | 199 fParents.remove(parentIndex); |
200 } | 200 } |
201 fCurrDisplayable = NULL; | 201 fCurrDisplayable = nullptr; |
202 if (fInInclude == false && SK_strcasecmp(elem, "screenplay") == 0) { | 202 if (fInInclude == false && SK_strcasecmp(elem, "screenplay") == 0) { |
203 if (fMaker.fInMovie == false) { | 203 if (fMaker.fInMovie == false) { |
204 fMaker.fEnableTime = fMaker.getAppTime(); | 204 fMaker.fEnableTime = fMaker.getAppTime(); |
205 #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING | 205 #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING |
206 if (fMaker.fDebugTimeBase == (SkMSec) -1) | 206 if (fMaker.fDebugTimeBase == (SkMSec) -1) |
207 fMaker.fDebugTimeBase = fMaker.fEnableTime; | 207 fMaker.fDebugTimeBase = fMaker.fEnableTime; |
208 SkString debugOut; | 208 SkString debugOut; |
209 SkMSec time = fMaker.getAppTime(); | 209 SkMSec time = fMaker.getAppTime(); |
210 debugOut.appendS32(time - fMaker.fDebugTimeBase); | 210 debugOut.appendS32(time - fMaker.fDebugTimeBase); |
211 debugOut.append(" onLoad enable="); | 211 debugOut.append(" onLoad enable="); |
212 debugOut.appendS32(fMaker.fEnableTime - fMaker.fDebugTimeBase); | 212 debugOut.appendS32(fMaker.fEnableTime - fMaker.fDebugTimeBase); |
213 SkDebugf("%s\n", debugOut.c_str()); | 213 SkDebugf("%s\n", debugOut.c_str()); |
214 #endif | 214 #endif |
215 fMaker.fEvents.doEvent(fMaker, SkDisplayEvent::kOnload, NULL); | 215 fMaker.fEvents.doEvent(fMaker, SkDisplayEvent::kOnload, nullptr); |
216 if (fMaker.fError.hasError()) | 216 if (fMaker.fError.hasError()) |
217 return true; | 217 return true; |
218 fMaker.fEvents.removeEvent(SkDisplayEvent::kOnload, NULL); | 218 fMaker.fEvents.removeEvent(SkDisplayEvent::kOnload, nullptr); |
219 | 219 |
220 } | 220 } |
221 fInSkia = false; | 221 fInSkia = false; |
222 } | 222 } |
223 return false; | 223 return false; |
224 } | 224 } |
225 | 225 |
226 bool SkDisplayXMLParser::onStartElement(const char name[]) | 226 bool SkDisplayXMLParser::onStartElement(const char name[]) |
227 { | 227 { |
228 return onStartElementLen(name, strlen(name)); | 228 return onStartElementLen(name, strlen(name)); |
229 } | 229 } |
230 | 230 |
231 bool SkDisplayXMLParser::onStartElementLen(const char name[], size_t len) { | 231 bool SkDisplayXMLParser::onStartElementLen(const char name[], size_t len) { |
232 fCurrDisplayable = NULL; // init so we'll ignore attributes if we exit early | 232 fCurrDisplayable = nullptr; // init so we'll ignore attributes if we exit ea
rly |
233 | 233 |
234 if (SK_strncasecmp(name, "screenplay", len) == 0) { | 234 if (SK_strncasecmp(name, "screenplay", len) == 0) { |
235 fInSkia = true; | 235 fInSkia = true; |
236 if (fInInclude == false) | 236 if (fInInclude == false) |
237 fMaker.idsSet(name, len, &fMaker.fScreenplay); | 237 fMaker.idsSet(name, len, &fMaker.fScreenplay); |
238 return false; | 238 return false; |
239 } | 239 } |
240 if (fInSkia == false) | 240 if (fInSkia == false) |
241 return false; | 241 return false; |
242 | 242 |
243 SkDisplayable* displayable = fMaker.createInstance(name, len); | 243 SkDisplayable* displayable = fMaker.createInstance(name, len); |
244 if (displayable == NULL) { | 244 if (displayable == nullptr) { |
245 fError->setNoun(name, len); | 245 fError->setNoun(name, len); |
246 fError->setCode(SkXMLParserError::kUnknownElement); | 246 fError->setCode(SkXMLParserError::kUnknownElement); |
247 return true; | 247 return true; |
248 } | 248 } |
249 SkDisplayTypes type = displayable->getType(); | 249 SkDisplayTypes type = displayable->getType(); |
250 Parent record = { displayable, type }; | 250 Parent record = { displayable, type }; |
251 *fParents.append() = record; | 251 *fParents.append() = record; |
252 if (fParents.count() == 1) | 252 if (fParents.count() == 1) |
253 fMaker.childrenAdd(displayable); | 253 fMaker.childrenAdd(displayable); |
254 else { | 254 else { |
255 Parent* parent = fParents.end() - 2; | 255 Parent* parent = fParents.end() - 2; |
256 if (displayable->setParent(parent->fDisplayable)) { | 256 if (displayable->setParent(parent->fDisplayable)) { |
257 fError->setNoun(name, len); | 257 fError->setNoun(name, len); |
258 getError()->setCode(SkDisplayXMLParserError::kParentElementCantConta
in); | 258 getError()->setCode(SkDisplayXMLParserError::kParentElementCantConta
in); |
259 return true; | 259 return true; |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 // set these for subsequent calls to addAttribute() | 263 // set these for subsequent calls to addAttribute() |
264 fCurrDisplayable = displayable; | 264 fCurrDisplayable = displayable; |
265 fCurrType = type; | 265 fCurrType = type; |
266 return false; | 266 return false; |
267 } | 267 } |
268 | 268 |
269 const SkMemberInfo* SkDisplayXMLParser::searchContainer(const SkMemberInfo* info
Base, | 269 const SkMemberInfo* SkDisplayXMLParser::searchContainer(const SkMemberInfo* info
Base, |
270 int infoCount) { | 270 int infoCount) { |
271 const SkMemberInfo* bestDisplayable = NULL; | 271 const SkMemberInfo* bestDisplayable = nullptr; |
272 const SkMemberInfo* lastResort = NULL; | 272 const SkMemberInfo* lastResort = nullptr; |
273 for (int index = 0; index < infoCount; index++) { | 273 for (int index = 0; index < infoCount; index++) { |
274 const SkMemberInfo* info = &infoBase[index]; | 274 const SkMemberInfo* info = &infoBase[index]; |
275 if (info->fType == SkType_BaseClassInfo) { | 275 if (info->fType == SkType_BaseClassInfo) { |
276 const SkMemberInfo* inherited = info->getInherited(); | 276 const SkMemberInfo* inherited = info->getInherited(); |
277 const SkMemberInfo* result = searchContainer(inherited, info->fCount
); | 277 const SkMemberInfo* result = searchContainer(inherited, info->fCount
); |
278 if (result != NULL) | 278 if (result != nullptr) |
279 return result; | 279 return result; |
280 continue; | 280 continue; |
281 } | 281 } |
282 Parent* container = fParents.end() - 1; | 282 Parent* container = fParents.end() - 1; |
283 SkDisplayTypes type = (SkDisplayTypes) info->fType; | 283 SkDisplayTypes type = (SkDisplayTypes) info->fType; |
284 if (type == SkType_MemberProperty) | 284 if (type == SkType_MemberProperty) |
285 type = info->propertyType(); | 285 type = info->propertyType(); |
286 SkDisplayTypes containerType = container->fType; | 286 SkDisplayTypes containerType = container->fType; |
287 if (type == containerType && (type == SkType_Rect || type == SkType_Poly
gon || | 287 if (type == containerType && (type == SkType_Rect || type == SkType_Poly
gon || |
288 type == SkType_Array || type == SkType_Int || type == SkType_Bitmap)
) | 288 type == SkType_Array || type == SkType_Int || type == SkType_Bitmap)
) |
(...skipping 16 matching lines...) Expand all Loading... |
305 bestDisplayable = info; | 305 bestDisplayable = info; |
306 else | 306 else |
307 lastResort = info; | 307 lastResort = info; |
308 } | 308 } |
309 } | 309 } |
310 } | 310 } |
311 if (bestDisplayable) | 311 if (bestDisplayable) |
312 return bestDisplayable; | 312 return bestDisplayable; |
313 if (lastResort) | 313 if (lastResort) |
314 return lastResort; | 314 return lastResort; |
315 return NULL; | 315 return nullptr; |
316 } | 316 } |
OLD | NEW |