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