Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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_FDE_CSS_FDE_CSSSTYLESHEET_H_ |
| 8 | #define XFA_FDE_CSS_FDE_CSSSTYLESHEET_H_ |
| 9 | |
weili | cddf825 | 2016-08-04 15:43:59 -0700 | [diff] [blame] | 10 | #include <memory> |
tsepez | 788ac38 | 2016-05-19 21:06:16 -0700 | [diff] [blame] | 11 | #include <unordered_map> |
| 12 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 13 | #include "core/fxcrt/fx_ext.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 14 | #include "xfa/fde/css/fde_cssdeclaration.h" |
| 15 | |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 16 | class CFDE_CSSSyntaxParser; |
| 17 | |
| 18 | class CFDE_CSSSelector : public CFX_Target { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 19 | public: |
| 20 | CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, |
| 21 | const FX_WCHAR* psz, |
| 22 | int32_t iLen, |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 23 | bool bIgnoreCase); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 24 | |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 25 | virtual FDE_CSSSELECTORTYPE GetType() const; |
| 26 | virtual uint32_t GetNameHash() const; |
| 27 | virtual CFDE_CSSSelector* GetNextSelector() const; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 28 | |
tsepez | 4d06f83 | 2016-05-03 14:13:29 -0700 | [diff] [blame] | 29 | static CFDE_CSSSelector* FromString(IFX_MemoryAllocator* pStaticStore, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 30 | const FX_WCHAR* psz, |
| 31 | int32_t iLen); |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 32 | |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 33 | void SetNext(CFDE_CSSSelector* pNext) { m_pNext = pNext; } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 34 | |
| 35 | protected: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 36 | void SetType(FDE_CSSSELECTORTYPE eType) { m_eType = eType; } |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 37 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 38 | FDE_CSSSELECTORTYPE m_eType; |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 39 | uint32_t m_dwHash; |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 40 | CFDE_CSSSelector* m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 41 | }; |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 42 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 43 | class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target { |
| 44 | public: |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 45 | CFDE_CSSStyleRule(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 47 | // IFDE_CSSStyleRule |
| 48 | int32_t CountSelectorLists() const override; |
| 49 | CFDE_CSSSelector* GetSelectorList(int32_t index) const override; |
| 50 | CFDE_CSSDeclaration* GetDeclaration() override; |
| 51 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 52 | CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } |
tsepez | 4d06f83 | 2016-05-03 14:13:29 -0700 | [diff] [blame] | 53 | void SetSelector(IFX_MemoryAllocator* pStaticStore, |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 54 | const CFX_ArrayTemplate<CFDE_CSSSelector*>& list); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 55 | |
| 56 | protected: |
| 57 | CFDE_CSSDeclaration m_Declaration; |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 58 | CFDE_CSSSelector** m_ppSelector; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 59 | int32_t m_iSelectors; |
| 60 | }; |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 61 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 62 | class CFDE_CSSMediaRule : public IFDE_CSSMediaRule, public CFX_Target { |
| 63 | public: |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 64 | explicit CFDE_CSSMediaRule(uint32_t dwMediaList); |
| 65 | ~CFDE_CSSMediaRule() override; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 66 | |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 67 | // IFDE_CSSMediaRule |
| 68 | uint32_t GetMediaList() const override; |
| 69 | int32_t CountRules() const override; |
| 70 | IFDE_CSSRule* GetRule(int32_t index) override; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 71 | |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 72 | CFX_MassArrayTemplate<IFDE_CSSRule*>& GetArray() { return m_RuleArray; } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 73 | |
| 74 | protected: |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 75 | uint32_t m_dwMediaList; |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 76 | CFX_MassArrayTemplate<IFDE_CSSRule*> m_RuleArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 77 | }; |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 78 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 79 | class CFDE_CSSFontFaceRule : public IFDE_CSSFontFaceRule, public CFX_Target { |
| 80 | public: |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 81 | // IFDE_CSSFontFaceRule |
| 82 | CFDE_CSSDeclaration* GetDeclaration() override; |
| 83 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 84 | CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } |
| 85 | |
| 86 | protected: |
| 87 | CFDE_CSSDeclaration m_Declaration; |
| 88 | }; |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 89 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 90 | #define FDE_CSSSWITCHDEFAULTS() \ |
| 91 | case FDE_CSSSYNTAXSTATUS_EOS: \ |
| 92 | return FDE_CSSSYNTAXSTATUS_EOS; \ |
| 93 | case FDE_CSSSYNTAXSTATUS_Error: \ |
| 94 | default: \ |
| 95 | return FDE_CSSSYNTAXSTATUS_Error; |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 96 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 97 | class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet, public CFX_Target { |
| 98 | public: |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 99 | CFDE_CSSStyleSheet(uint32_t dwMediaList); |
tsepez | a2d699f | 2016-05-23 17:19:20 -0700 | [diff] [blame] | 100 | ~CFDE_CSSStyleSheet() override; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 101 | |
tsepez | a2d699f | 2016-05-23 17:19:20 -0700 | [diff] [blame] | 102 | // IFX_Retainable: |
| 103 | uint32_t Retain() override; |
| 104 | uint32_t Release() override; |
| 105 | |
| 106 | // IFDE_CSSStyleSheet: |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 107 | bool GetUrl(CFX_WideString& szUrl) override; |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 108 | uint32_t GetMediaList() const override; |
| 109 | uint16_t GetCodePage() const override; |
tsepez | a2d699f | 2016-05-23 17:19:20 -0700 | [diff] [blame] | 110 | int32_t CountRules() const override; |
| 111 | IFDE_CSSRule* GetRule(int32_t index) override; |
| 112 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 113 | bool LoadFromStream(const CFX_WideString& szUrl, |
| 114 | IFX_Stream* pStream, |
| 115 | uint16_t wCodePage); |
| 116 | bool LoadFromBuffer(const CFX_WideString& szUrl, |
| 117 | const FX_WCHAR* pBuffer, |
| 118 | int32_t iBufSize, |
| 119 | uint16_t wCodePage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 120 | |
| 121 | protected: |
| 122 | void Reset(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 123 | bool LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax); |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 124 | FDE_CSSSYNTAXSTATUS LoadStyleRule( |
| 125 | CFDE_CSSSyntaxParser* pSyntax, |
| 126 | CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray); |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 127 | FDE_CSSSYNTAXSTATUS LoadImportRule(CFDE_CSSSyntaxParser* pSyntax); |
| 128 | FDE_CSSSYNTAXSTATUS LoadPageRule(CFDE_CSSSyntaxParser* pSyntax); |
| 129 | FDE_CSSSYNTAXSTATUS LoadMediaRule(CFDE_CSSSyntaxParser* pSyntax); |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 130 | FDE_CSSSYNTAXSTATUS LoadFontFaceRule( |
| 131 | CFDE_CSSSyntaxParser* pSyntax, |
| 132 | CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray); |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 133 | FDE_CSSSYNTAXSTATUS SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax); |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 134 | uint16_t m_wCodePage; |
| 135 | uint16_t m_wRefCount; |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 136 | uint32_t m_dwMediaList; |
weili | cddf825 | 2016-08-04 15:43:59 -0700 | [diff] [blame] | 137 | std::unique_ptr<IFX_MemoryAllocator> m_pAllocator; |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 138 | CFX_MassArrayTemplate<IFDE_CSSRule*> m_RuleArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 139 | CFX_WideString m_szUrl; |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 140 | CFX_ArrayTemplate<CFDE_CSSSelector*> m_Selectors; |
tsepez | 788ac38 | 2016-05-19 21:06:16 -0700 | [diff] [blame] | 141 | std::unordered_map<uint32_t, FX_WCHAR*> m_StringCache; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | #endif // XFA_FDE_CSS_FDE_CSSSTYLESHEET_H_ |