• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
3  * Description: Implementation for Css style parser.
4  * Create: 2023/4/25
5  */
6 #ifndef SkDOMPARSER_DEFINED
7 #define SkDOMPARSER_DEFINED
8 
9 #include "include/private/SkTDArray.h"
10 #include "src/core/SkArenaAlloc.h"
11 #include "src/xml/SkXMLParser.h"
12 
13 class SkDOMParser : public SkXMLParser {
14 public:
SkDOMParser(SkArenaAllocWithReset * chunk)15     SkDOMParser(SkArenaAllocWithReset* chunk) : SkXMLParser(&fParserError), fAlloc(chunk) {
16         fAlloc->reset();
17         fRoot = nullptr;
18         fLevel = 0;
19         fNeedToFlush = true;
20     }
21     SkDOM::Node* getRoot() const;
22 
23     static char* dupstr(SkArenaAlloc* chunk, const char src[], size_t srcLen);
24 
25     SkXMLParserError fParserError;
26 
27 protected:
28     void flushAttributes();
29     bool onStartElement(const char elem[]) override;
30     bool onAddAttribute(const char name[], const char value[]) override;
31     bool onEndElement(const char elem[]) override;
32     bool onText(const char text[], int len) override;
33     void startCommon(const char elem[], size_t elemSize, SkDOM::Type type);
34 
35     SkTDArray<SkDOM::Node*> fParentStack;
36     SkArenaAllocWithReset*  fAlloc;
37     SkDOM::Node*            fRoot;
38     bool                    fNeedToFlush;
39 
40     // state needed for flushAttributes()
41     SkTDArray<SkDOM::Attr>  fAttrs;
42     char*                   fElemName;
43     SkDOM::Type             fElemType;
44     int                     fLevel;
45 };
46 #endif
47