1 2 /* 3 * Copyright 2006 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #ifndef SkDisplayXMLParser_DEFINED 11 #define SkDisplayXMLParser_DEFINED 12 13 #include "SkIntArray.h" 14 #include "SkTDict.h" 15 #include "SkDisplayType.h" 16 #include "SkXMLParser.h" 17 18 class SkAnimateMaker; 19 class SkDisplayable; 20 21 class SkDisplayXMLParserError : public SkXMLParserError { 22 public: 23 enum ErrorCode { 24 kApplyScopesItself = kUnknownError + 1, 25 kDisplayTreeTooDeep, 26 kElementMissingParent, 27 kElementTypeNotAllowedInParent, 28 kErrorAddingDataToPost, 29 kErrorAddingToMatrix, 30 kErrorAddingToPaint, 31 kErrorAddingToPath, 32 kErrorInAttributeValue, 33 kErrorInScript, 34 kExpectedMovie, 35 kFieldNotInTarget, 36 kGradientOffsetsDontMatchColors, 37 kGradientOffsetsMustBeNoMoreThanOne, 38 kGradientOffsetsMustEndWithOne, 39 kGradientOffsetsMustIncrease, 40 kGradientOffsetsMustStartWithZero, 41 kGradientPointsLengthMustBeFour, 42 kInInclude, 43 kInMovie, 44 kIncludeNameUnknownOrMissing, 45 kIndexOutOfRange, 46 kMovieNameUnknownOrMissing, 47 kNoParentAvailable, 48 kParentElementCantContain, 49 kSaveLayerNeedsBounds, 50 kTargetIDNotFound, 51 kUnexpectedType 52 }; 53 virtual ~SkDisplayXMLParserError(); 54 virtual void getErrorString(SkString* str) const; 55 void setCode(ErrorCode code) { INHERITED::setCode((INHERITED::ErrorCode) code); } 56 void setInnerError(SkAnimateMaker* maker, const SkString& str); 57 typedef SkXMLParserError INHERITED; 58 friend class SkDisplayXMLParser; 59 }; 60 61 class SkDisplayXMLParser : public SkXMLParser { 62 public: 63 SkDisplayXMLParser(SkAnimateMaker& maker); 64 virtual ~SkDisplayXMLParser(); 65 protected: 66 virtual bool onAddAttribute(const char name[], const char value[]); 67 bool onAddAttributeLen(const char name[], const char value[], size_t len); 68 virtual bool onEndElement(const char elem[]); 69 virtual bool onStartElement(const char elem[]); 70 bool onStartElementLen(const char elem[], size_t len); 71 private: 72 struct Parent { 73 SkDisplayable* fDisplayable; 74 SkDisplayTypes fType; 75 }; 76 SkTDArray<Parent> fParents; 77 SkDisplayXMLParser& operator= (const SkDisplayXMLParser& ); 78 SkDisplayXMLParserError* getError() { return (SkDisplayXMLParserError*) fError; } 79 const SkMemberInfo* searchContainer(const SkMemberInfo* , 80 int infoCount); 81 SkAnimateMaker& fMaker; 82 SkBool fInInclude; 83 SkBool fInSkia; 84 // local state between onStartElement and onAddAttribute 85 SkDisplayable* fCurrDisplayable; 86 SkDisplayTypes fCurrType; 87 friend class SkXMLAnimatorWriter; 88 typedef SkXMLParser INHERITED; 89 }; 90 91 #endif // SkDisplayXMLParser_DEFINED 92