OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef XFA_SRC_FDE_CSS_FDE_CSSSTYLESHEET_H_ | |
8 #define XFA_SRC_FDE_CSS_FDE_CSSSTYLESHEET_H_ | |
9 | |
10 #include "core/include/fxcrt/fx_ext.h" | |
11 #include "xfa/src/fde/css/fde_cssdeclaration.h" | |
12 | |
13 class CFDE_CSSSelector : public IFDE_CSSSelector, public CFX_Target { | |
14 public: | |
15 CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, | |
16 const FX_WCHAR* psz, | |
17 int32_t iLen, | |
18 FX_BOOL bIgnoreCase) | |
19 : m_eType(eType), | |
20 m_dwHash(FX_HashCode_String_GetW(psz, iLen, bIgnoreCase)), | |
21 m_pNext(NULL) {} | |
22 virtual FDE_CSSSELECTORTYPE GetType() const { return m_eType; } | |
23 | |
24 virtual FX_DWORD GetNameHash() const { return m_dwHash; } | |
25 | |
26 virtual IFDE_CSSSelector* GetNextSelector() const { return m_pNext; } | |
27 static IFDE_CSSSelector* FromString(IFX_MEMAllocator* pStaticStore, | |
28 const FX_WCHAR* psz, | |
29 int32_t iLen); | |
30 void SetNext(IFDE_CSSSelector* pNext) { m_pNext = pNext; } | |
31 | |
32 protected: | |
33 static CFDE_CSSSelector* ParseSelector(IFX_MEMAllocator* pStaticStore, | |
34 const FX_WCHAR* psz, | |
35 int32_t& iOff, | |
36 int32_t iLen, | |
37 FDE_CSSSELECTORTYPE eType); | |
38 void SetType(FDE_CSSSELECTORTYPE eType) { m_eType = eType; } | |
39 FDE_CSSSELECTORTYPE m_eType; | |
40 FX_DWORD m_dwHash; | |
41 IFDE_CSSSelector* m_pNext; | |
42 }; | |
43 typedef CFX_ArrayTemplate<IFDE_CSSSelector*> CFDE_CSSSelectorArray; | |
44 class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target { | |
45 public: | |
46 CFDE_CSSStyleRule() : m_ppSelector(NULL), m_iSelectors(0) {} | |
47 virtual int32_t CountSelectorLists() const { return m_iSelectors; } | |
48 virtual IFDE_CSSSelector* GetSelectorList(int32_t index) const { | |
49 return m_ppSelector[index]; | |
50 } | |
51 | |
52 virtual IFDE_CSSDeclaration* GetDeclaration() const { | |
53 return (IFDE_CSSDeclaration*)&m_Declaration; | |
54 } | |
55 CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } | |
56 void SetSelector(IFX_MEMAllocator* pStaticStore, | |
57 const CFDE_CSSSelectorArray& list); | |
58 | |
59 protected: | |
60 CFDE_CSSDeclaration m_Declaration; | |
61 IFDE_CSSSelector** m_ppSelector; | |
62 int32_t m_iSelectors; | |
63 }; | |
64 class CFDE_CSSMediaRule : public IFDE_CSSMediaRule, public CFX_Target { | |
65 public: | |
66 CFDE_CSSMediaRule(FX_DWORD dwMediaList) : m_dwMediaList(dwMediaList) {} | |
67 ~CFDE_CSSMediaRule(); | |
68 | |
69 virtual FX_DWORD GetMediaList() const { return m_dwMediaList; } | |
70 | |
71 virtual int32_t CountRules() const { return m_RuleArray.GetSize(); } | |
72 virtual IFDE_CSSRule* GetRule(int32_t index) { | |
73 return m_RuleArray.GetAt(index); | |
74 } | |
75 CFDE_CSSRuleArray& GetArray() { return m_RuleArray; } | |
76 | |
77 protected: | |
78 FX_DWORD m_dwMediaList; | |
79 CFDE_CSSRuleArray m_RuleArray; | |
80 }; | |
81 class CFDE_CSSFontFaceRule : public IFDE_CSSFontFaceRule, public CFX_Target { | |
82 public: | |
83 virtual IFDE_CSSDeclaration* GetDeclaration() const { | |
84 return (IFDE_CSSDeclaration*)&m_Declaration; | |
85 } | |
86 CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } | |
87 | |
88 protected: | |
89 CFDE_CSSDeclaration m_Declaration; | |
90 }; | |
91 #define FDE_CSSSWITCHDEFAULTS() \ | |
92 case FDE_CSSSYNTAXSTATUS_EOS: \ | |
93 return FDE_CSSSYNTAXSTATUS_EOS; \ | |
94 case FDE_CSSSYNTAXSTATUS_Error: \ | |
95 default: \ | |
96 return FDE_CSSSYNTAXSTATUS_Error; | |
97 class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet, public CFX_Target { | |
98 public: | |
99 CFDE_CSSStyleSheet(FX_DWORD dwMediaList); | |
100 ~CFDE_CSSStyleSheet(); | |
101 virtual FX_DWORD AddRef(); | |
102 virtual FX_DWORD Release(); | |
103 | |
104 virtual FX_BOOL GetUrl(CFX_WideString& szUrl) { | |
105 szUrl = m_szUrl; | |
106 return szUrl.GetLength() > 0; | |
107 } | |
108 virtual FX_DWORD GetMediaList() const { return m_dwMediaList; } | |
109 virtual FX_WORD GetCodePage() const { return m_wCodePage; } | |
110 virtual int32_t CountRules() const; | |
111 virtual IFDE_CSSRule* GetRule(int32_t index); | |
112 FX_BOOL LoadFromStream(const CFX_WideString& szUrl, | |
113 IFX_Stream* pStream, | |
114 FX_WORD wCodePage); | |
115 FX_BOOL LoadFromBuffer(const CFX_WideString& szUrl, | |
116 const FX_WCHAR* pBuffer, | |
117 int32_t iBufSize, | |
118 FX_WORD wCodePage); | |
119 | |
120 protected: | |
121 void Reset(); | |
122 FX_BOOL LoadFromSyntax(IFDE_CSSSyntaxParser* pSyntax); | |
123 FDE_CSSSYNTAXSTATUS LoadStyleRule(IFDE_CSSSyntaxParser* pSyntax, | |
124 CFDE_CSSRuleArray& ruleArray); | |
125 FDE_CSSSYNTAXSTATUS LoadImportRule(IFDE_CSSSyntaxParser* pSyntax); | |
126 FDE_CSSSYNTAXSTATUS LoadPageRule(IFDE_CSSSyntaxParser* pSyntax); | |
127 FDE_CSSSYNTAXSTATUS LoadMediaRule(IFDE_CSSSyntaxParser* pSyntax); | |
128 FDE_CSSSYNTAXSTATUS LoadFontFaceRule(IFDE_CSSSyntaxParser* pSyntax, | |
129 CFDE_CSSRuleArray& ruleArray); | |
130 FDE_CSSSYNTAXSTATUS SkipRuleSet(IFDE_CSSSyntaxParser* pSyntax); | |
131 FX_WORD m_wCodePage; | |
132 FX_WORD m_wRefCount; | |
133 FX_DWORD m_dwMediaList; | |
134 IFX_MEMAllocator* m_pAllocator; | |
135 CFDE_CSSRuleArray m_RuleArray; | |
136 CFX_WideString m_szUrl; | |
137 CFDE_CSSSelectorArray m_Selectors; | |
138 CFX_MapPtrToPtr m_StringCache; | |
139 }; | |
140 | |
141 #endif // XFA_SRC_FDE_CSS_FDE_CSSSTYLESHEET_H_ | |
OLD | NEW |