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 <optional> 12 #include <vector> 13 14 #include "core/fxcrt/css/cfx_cssdata.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "core/fxcrt/widestring.h" 17 18 class CFX_CSSPropertyHolder; 19 class CFX_CSSCustomProperty; 20 21 class CFX_CSSDeclaration { 22 public: 23 using const_prop_iterator = 24 std::vector<std::unique_ptr<CFX_CSSPropertyHolder>>::const_iterator; 25 using const_custom_iterator = 26 std::vector<std::unique_ptr<CFX_CSSCustomProperty>>::const_iterator; 27 28 static std::optional<WideStringView> ParseCSSString(WideStringView value); 29 static std::optional<FX_ARGB> ParseCSSColor(WideStringView value); 30 31 CFX_CSSDeclaration(); 32 ~CFX_CSSDeclaration(); 33 34 RetainPtr<CFX_CSSValue> GetProperty(CFX_CSSProperty eProperty, 35 bool* bImportant) const; 36 empty()37 bool empty() const { return properties_.empty(); } begin()38 const_prop_iterator begin() const { return properties_.begin(); } end()39 const_prop_iterator end() const { return properties_.end(); } 40 custom_begin()41 const_custom_iterator custom_begin() const { 42 return custom_properties_.begin(); 43 } custom_end()44 const_custom_iterator custom_end() const { return custom_properties_.end(); } 45 46 void AddProperty(const CFX_CSSData::Property* property, WideStringView value); 47 void AddProperty(const WideString& prop, const WideString& value); 48 size_t PropertyCountForTesting() const; 49 50 std::optional<FX_ARGB> ParseColorForTest(WideStringView value); 51 52 private: 53 void ParseFontProperty(WideStringView value, bool bImportant); 54 55 // Never returns nullptr, instead returns a CSSValue representing zero 56 // if the input cannot be parsed. 57 RetainPtr<CFX_CSSValue> ParseBorderProperty(WideStringView value) const; 58 59 void ParseValueListProperty(const CFX_CSSData::Property* pProperty, 60 WideStringView value, 61 bool bImportant); 62 void Add4ValuesProperty(const std::vector<RetainPtr<CFX_CSSValue>>& list, 63 bool bImportant, 64 CFX_CSSProperty eLeft, 65 CFX_CSSProperty eTop, 66 CFX_CSSProperty eRight, 67 CFX_CSSProperty eBottom); 68 RetainPtr<CFX_CSSValue> ParseNumber(WideStringView value); 69 RetainPtr<CFX_CSSValue> ParseEnum(WideStringView value); 70 RetainPtr<CFX_CSSValue> ParseColor(WideStringView value); 71 RetainPtr<CFX_CSSValue> ParseString(WideStringView value); 72 void AddPropertyHolder(CFX_CSSProperty eProperty, 73 RetainPtr<CFX_CSSValue> pValue, 74 bool bImportant); 75 76 std::vector<std::unique_ptr<CFX_CSSPropertyHolder>> properties_; 77 std::vector<std::unique_ptr<CFX_CSSCustomProperty>> custom_properties_; 78 }; 79 80 #endif // CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_ 81