1 // Copyright 2014 The PDFium Authors 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 CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_ 8 #define CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcrt/css/cfx_cssdata.h" 14 #include "core/fxcrt/retain_ptr.h" 15 16 class CFX_CSSPropertyHolder; 17 class CFX_CSSCustomProperty; 18 19 class CFX_CSSDeclaration { 20 public: 21 using const_prop_iterator = 22 std::vector<std::unique_ptr<CFX_CSSPropertyHolder>>::const_iterator; 23 using const_custom_iterator = 24 std::vector<std::unique_ptr<CFX_CSSCustomProperty>>::const_iterator; 25 26 static bool ParseCSSString(const wchar_t* pszValue, 27 size_t nValueLen, 28 size_t* nOffset, 29 size_t* nLength); 30 static bool ParseCSSColor(const wchar_t* pszValue, 31 size_t nValueLen, 32 FX_ARGB* dwColor); 33 34 CFX_CSSDeclaration(); 35 ~CFX_CSSDeclaration(); 36 37 RetainPtr<CFX_CSSValue> GetProperty(CFX_CSSProperty eProperty, 38 bool* bImportant) const; 39 begin()40 const_prop_iterator begin() const { return properties_.begin(); } end()41 const_prop_iterator end() const { return properties_.end(); } 42 custom_begin()43 const_custom_iterator custom_begin() const { 44 return custom_properties_.begin(); 45 } custom_end()46 const_custom_iterator custom_end() const { return custom_properties_.end(); } 47 empty()48 bool empty() const { return properties_.empty(); } 49 50 void AddProperty(const CFX_CSSData::Property* property, WideStringView value); 51 void AddProperty(const WideString& prop, const WideString& value); 52 53 size_t PropertyCountForTesting() const; 54 55 FX_ARGB ParseColorForTest(const wchar_t* pszValue, 56 size_t nValueLen, 57 FX_ARGB* dwColor) const; 58 59 private: 60 void ParseFontProperty(const wchar_t* pszValue, 61 size_t nValueLen, 62 bool bImportant); 63 bool ParseBorderProperty(const wchar_t* pszValue, 64 size_t nValueLen, 65 RetainPtr<CFX_CSSValue>& pWidth) const; 66 void ParseValueListProperty(const CFX_CSSData::Property* pProperty, 67 const wchar_t* pszValue, 68 size_t nValueLen, 69 bool bImportant); 70 void Add4ValuesProperty(const std::vector<RetainPtr<CFX_CSSValue>>& list, 71 bool bImportant, 72 CFX_CSSProperty eLeft, 73 CFX_CSSProperty eTop, 74 CFX_CSSProperty eRight, 75 CFX_CSSProperty eBottom); 76 RetainPtr<CFX_CSSValue> ParseNumber(const wchar_t* pszValue, 77 size_t nValueLen); 78 RetainPtr<CFX_CSSValue> ParseEnum(const wchar_t* pszValue, size_t nValueLen); 79 RetainPtr<CFX_CSSValue> ParseColor(const wchar_t* pszValue, size_t nValueLen); 80 RetainPtr<CFX_CSSValue> ParseString(const wchar_t* pszValue, 81 size_t nValueLen); 82 void AddPropertyHolder(CFX_CSSProperty eProperty, 83 RetainPtr<CFX_CSSValue> pValue, 84 bool bImportant); 85 86 std::vector<std::unique_ptr<CFX_CSSPropertyHolder>> properties_; 87 std::vector<std::unique_ptr<CFX_CSSCustomProperty>> custom_properties_; 88 }; 89 90 #endif // CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_ 91