1 /* libs/graphics/animator/SkDisplayXMLParser.h 2 ** 3 ** Copyright 2006, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #ifndef SkDisplayXMLParser_DEFINED 19 #define SkDisplayXMLParser_DEFINED 20 21 #include "SkIntArray.h" 22 #include "SkTDict.h" 23 #include "SkDisplayType.h" 24 #include "SkXMLParser.h" 25 26 class SkAnimateMaker; 27 class SkDisplayable; 28 29 class SkDisplayXMLParserError : public SkXMLParserError { 30 public: 31 enum ErrorCode { 32 kApplyScopesItself = kUnknownError + 1, 33 kDisplayTreeTooDeep, 34 kElementMissingParent, 35 kElementTypeNotAllowedInParent, 36 kErrorAddingDataToPost, 37 kErrorAddingToMatrix, 38 kErrorAddingToPaint, 39 kErrorAddingToPath, 40 kErrorInAttributeValue, 41 kErrorInScript, 42 kExpectedMovie, 43 kFieldNotInTarget, 44 kGradientOffsetsDontMatchColors, 45 kGradientOffsetsMustBeNoMoreThanOne, 46 kGradientOffsetsMustEndWithOne, 47 kGradientOffsetsMustIncrease, 48 kGradientOffsetsMustStartWithZero, 49 kGradientPointsLengthMustBeFour, 50 kInInclude, 51 kInMovie, 52 kIncludeNameUnknownOrMissing, 53 kIndexOutOfRange, 54 kMovieNameUnknownOrMissing, 55 kNoParentAvailable, 56 kParentElementCantContain, 57 kSaveLayerNeedsBounds, 58 kTargetIDNotFound, 59 kUnexpectedType 60 }; 61 virtual ~SkDisplayXMLParserError(); 62 virtual void getErrorString(SkString* str) const; setCode(ErrorCode code)63 void setCode(ErrorCode code) { INHERITED::setCode((INHERITED::ErrorCode) code); } 64 void setInnerError(SkAnimateMaker* maker, const SkString& str); 65 typedef SkXMLParserError INHERITED; 66 friend class SkDisplayXMLParser; 67 }; 68 69 class SkDisplayXMLParser : public SkXMLParser { 70 public: 71 SkDisplayXMLParser(SkAnimateMaker& maker); 72 virtual ~SkDisplayXMLParser(); 73 protected: 74 virtual bool onAddAttribute(const char name[], const char value[]); 75 bool onAddAttributeLen(const char name[], const char value[], size_t len); 76 virtual bool onEndElement(const char elem[]); 77 virtual bool onStartElement(const char elem[]); 78 bool onStartElementLen(const char elem[], size_t len); 79 private: 80 struct Parent { 81 SkDisplayable* fDisplayable; 82 SkDisplayTypes fType; 83 }; 84 SkTDArray<Parent> fParents; 85 SkDisplayXMLParser& operator= (const SkDisplayXMLParser& ); getError()86 SkDisplayXMLParserError* getError() { return (SkDisplayXMLParserError*) fError; } 87 const SkMemberInfo* searchContainer(const SkMemberInfo* , 88 int infoCount); 89 SkAnimateMaker& fMaker; 90 SkBool fInInclude; 91 SkBool fInSkia; 92 // local state between onStartElement and onAddAttribute 93 SkDisplayable* fCurrDisplayable; 94 SkDisplayTypes fCurrType; 95 friend class SkXMLAnimatorWriter; 96 typedef SkXMLParser INHERITED; 97 }; 98 99 #endif // SkDisplayXMLParser_DEFINED 100 101 102