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_CSSDECLARATION_H_ |
| 8 | #define XFA_FDE_CSS_FDE_CSSDECLARATION_H_ |
| 9 | |
tsepez | 788ac38 | 2016-05-19 21:06:16 -0700 | [diff] [blame] | 10 | #include <unordered_map> |
| 11 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 12 | #include "xfa/fde/css/fde_cssdatatable.h" |
| 13 | |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 14 | class FDE_CSSPropertyHolder { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 15 | public: |
| 16 | int16_t eProperty; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 17 | bool bImportant; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 18 | IFDE_CSSValue* pValue; |
| 19 | FDE_CSSPropertyHolder* pNext; |
| 20 | }; |
| 21 | |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 22 | class FDE_CSSCustomProperty { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 23 | public: |
| 24 | const FX_WCHAR* pwsName; |
| 25 | const FX_WCHAR* pwsValue; |
| 26 | FDE_CSSCustomProperty* pNext; |
| 27 | }; |
| 28 | |
| 29 | struct FDE_CSSPROPERTYARGS { |
tsepez | 788ac38 | 2016-05-19 21:06:16 -0700 | [diff] [blame] | 30 | std::unordered_map<uint32_t, FX_WCHAR*>* pStringCache; |
| 31 | const FDE_CSSPROPERTYTABLE* pProperty; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 32 | }; |
| 33 | |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 34 | class CFDE_CSSDeclaration { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 35 | public: |
| 36 | CFDE_CSSDeclaration() |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 37 | : m_pFirstProperty(nullptr), |
| 38 | m_pLastProperty(nullptr), |
| 39 | m_pFirstCustom(nullptr), |
| 40 | m_pLastCustom(nullptr) {} |
| 41 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 42 | IFDE_CSSValue* GetProperty(FDE_CSSPROPERTY eProperty, bool& bImportant) const; |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 43 | FX_POSITION GetStartPosition() const; |
| 44 | void GetNextProperty(FX_POSITION& pos, |
| 45 | FDE_CSSPROPERTY& eProperty, |
| 46 | IFDE_CSSValue*& pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 47 | bool& bImportant) const; |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 48 | FX_POSITION GetStartCustom() const; |
| 49 | void GetNextCustom(FX_POSITION& pos, |
| 50 | CFX_WideString& wsName, |
| 51 | CFX_WideString& wsValue) const; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 52 | bool AddProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 53 | const FX_WCHAR* pszValue, |
| 54 | int32_t iValueLen); |
| 55 | bool AddProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 56 | const FX_WCHAR* pszName, |
| 57 | int32_t iNameLen, |
| 58 | const FX_WCHAR* pszValue, |
| 59 | int32_t iValueLen); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 60 | |
| 61 | protected: |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 62 | bool ParseTextEmphasisProperty(FDE_CSSPROPERTYARGS* pArgs, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 63 | const FX_WCHAR* pszValue, |
| 64 | int32_t iValueLen, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 65 | bool bImportant); |
| 66 | bool ParseColumnsProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 67 | const FX_WCHAR* pszValue, |
| 68 | int32_t iValueLen, |
| 69 | bool bImportant); |
| 70 | bool ParseColumnRuleProperty(const FDE_CSSPROPERTYARGS* pArgs, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 71 | const FX_WCHAR* pszValue, |
| 72 | int32_t iValueLen, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 73 | bool bImportant); |
| 74 | bool ParseOverflowProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 75 | const FX_WCHAR* pszValue, |
| 76 | int32_t iValueLen, |
| 77 | bool bImportant); |
| 78 | bool ParseFontProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 79 | const FX_WCHAR* pszValue, |
| 80 | int32_t iValueLen, |
| 81 | bool bImportant); |
| 82 | bool ParseBackgroundProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 83 | const FX_WCHAR* pszValue, |
| 84 | int32_t iValueLen, |
| 85 | bool bImportant); |
| 86 | bool ParseListStyleProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 87 | const FX_WCHAR* pszValue, |
| 88 | int32_t iValueLen, |
| 89 | bool bImportant); |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 90 | bool ParseBorderPropoerty(const FX_WCHAR* pszValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 91 | int32_t iValueLen, |
| 92 | IFDE_CSSValue*& pColor, |
| 93 | IFDE_CSSValue*& pStyle, |
| 94 | IFDE_CSSValue*& pWidth) const; |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 95 | void AddBorderProperty(IFDE_CSSValue* pColor, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 96 | IFDE_CSSValue* pStyle, |
| 97 | IFDE_CSSValue* pWidth, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 98 | bool bImportant, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 99 | FDE_CSSPROPERTY eColor, |
| 100 | FDE_CSSPROPERTY eStyle, |
| 101 | FDE_CSSPROPERTY eWidth); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 102 | bool ParseContentProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 103 | const FX_WCHAR* pszValue, |
| 104 | int32_t iValueLen, |
| 105 | bool bImportant); |
| 106 | bool ParseCounterProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 107 | const FX_WCHAR* pszValue, |
| 108 | int32_t iValueLen, |
| 109 | bool bImportant); |
| 110 | bool ParseValueListProperty(const FDE_CSSPROPERTYARGS* pArgs, |
| 111 | const FX_WCHAR* pszValue, |
| 112 | int32_t iValueLen, |
| 113 | bool bImportant); |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 114 | bool Add4ValuesProperty(const CFDE_CSSValueArray& list, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 115 | bool bImportant, |
| 116 | FDE_CSSPROPERTY eLeft, |
| 117 | FDE_CSSPROPERTY eTop, |
| 118 | FDE_CSSPROPERTY eRight, |
| 119 | FDE_CSSPROPERTY eBottom); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 120 | IFDE_CSSValue* ParseNumber(const FDE_CSSPROPERTYARGS* pArgs, |
| 121 | const FX_WCHAR* pszValue, |
| 122 | int32_t iValueLen); |
| 123 | IFDE_CSSValue* ParseEnum(const FDE_CSSPROPERTYARGS* pArgs, |
| 124 | const FX_WCHAR* pszValue, |
| 125 | int32_t iValueLen); |
| 126 | IFDE_CSSValue* ParseColor(const FDE_CSSPROPERTYARGS* pArgs, |
| 127 | const FX_WCHAR* pszValue, |
| 128 | int32_t iValueLen); |
| 129 | IFDE_CSSValue* ParseURI(const FDE_CSSPROPERTYARGS* pArgs, |
| 130 | const FX_WCHAR* pszValue, |
| 131 | int32_t iValueLen); |
| 132 | IFDE_CSSValue* ParseString(const FDE_CSSPROPERTYARGS* pArgs, |
| 133 | const FX_WCHAR* pszValue, |
| 134 | int32_t iValueLen); |
| 135 | IFDE_CSSValue* ParseFunction(const FDE_CSSPROPERTYARGS* pArgs, |
| 136 | const FX_WCHAR* pszValue, |
| 137 | int32_t iValueLen); |
| 138 | const FX_WCHAR* CopyToLocal(const FDE_CSSPROPERTYARGS* pArgs, |
| 139 | const FX_WCHAR* pszValue, |
| 140 | int32_t iValueLen); |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 141 | void AddPropertyHolder(FDE_CSSPROPERTY eProperty, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 142 | IFDE_CSSValue* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 143 | bool bImportant); |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 144 | IFDE_CSSPrimitiveValue* NewNumberValue(FDE_CSSPRIMITIVETYPE eUnit, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 145 | FX_FLOAT fValue) const; |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame^] | 146 | IFDE_CSSPrimitiveValue* NewEnumValue(FDE_CSSPROPERTYVALUE eValue) const; |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 147 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 148 | FDE_CSSPropertyHolder* m_pFirstProperty; |
| 149 | FDE_CSSPropertyHolder* m_pLastProperty; |
| 150 | FDE_CSSCustomProperty* m_pFirstCustom; |
| 151 | FDE_CSSCustomProperty* m_pLastCustom; |
| 152 | }; |
dsinclair | e6ebf7a | 2016-04-28 06:34:24 -0700 | [diff] [blame] | 153 | using CFDE_CSSDeclarationArray = CFX_ArrayTemplate<CFDE_CSSDeclaration*>; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 154 | |
| 155 | #endif // XFA_FDE_CSS_FDE_CSSDECLARATION_H_ |