• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 
15 class CFX_CSSPropertyHolder;
16 class CFX_CSSCustomProperty;
17 
18 class CFX_CSSDeclaration {
19  public:
20   using const_prop_iterator =
21       std::vector<std::unique_ptr<CFX_CSSPropertyHolder>>::const_iterator;
22   using const_custom_iterator =
23       std::vector<std::unique_ptr<CFX_CSSCustomProperty>>::const_iterator;
24 
25   static bool ParseCSSString(const wchar_t* pszValue,
26                              int32_t iValueLen,
27                              int32_t* iOffset,
28                              int32_t* iLength);
29   static bool ParseCSSColor(const wchar_t* pszValue,
30                             int32_t iValueLen,
31                             FX_ARGB* dwColor);
32 
33   CFX_CSSDeclaration();
34   ~CFX_CSSDeclaration();
35 
36   RetainPtr<CFX_CSSValue> GetProperty(CFX_CSSProperty eProperty,
37                                       bool* bImportant) const;
38 
begin()39   const_prop_iterator begin() const { return properties_.begin(); }
end()40   const_prop_iterator end() const { return properties_.end(); }
41 
custom_begin()42   const_custom_iterator custom_begin() const {
43     return custom_properties_.begin();
44   }
custom_end()45   const_custom_iterator custom_end() const { return custom_properties_.end(); }
46 
empty()47   bool empty() const { return properties_.empty(); }
48 
49   void AddProperty(const CFX_CSSData::Property* property, WideStringView value);
50   void AddProperty(const WideString& prop, const WideString& value);
51 
52   size_t PropertyCountForTesting() const;
53 
54   FX_ARGB ParseColorForTest(const wchar_t* pszValue,
55                             int32_t iValueLen,
56                             FX_ARGB* dwColor) const;
57 
58  private:
59   void ParseFontProperty(const wchar_t* pszValue,
60                          int32_t iValueLen,
61                          bool bImportant);
62   bool ParseBorderProperty(const wchar_t* pszValue,
63                            int32_t iValueLen,
64                            RetainPtr<CFX_CSSValue>& pWidth) const;
65   void ParseValueListProperty(const CFX_CSSData::Property* pProperty,
66                               const wchar_t* pszValue,
67                               int32_t iValueLen,
68                               bool bImportant);
69   void Add4ValuesProperty(const std::vector<RetainPtr<CFX_CSSValue>>& list,
70                           bool bImportant,
71                           CFX_CSSProperty eLeft,
72                           CFX_CSSProperty eTop,
73                           CFX_CSSProperty eRight,
74                           CFX_CSSProperty eBottom);
75   RetainPtr<CFX_CSSValue> ParseNumber(const wchar_t* pszValue,
76                                       int32_t iValueLen);
77   RetainPtr<CFX_CSSValue> ParseEnum(const wchar_t* pszValue, int32_t iValueLen);
78   RetainPtr<CFX_CSSValue> ParseColor(const wchar_t* pszValue,
79                                      int32_t iValueLen);
80   RetainPtr<CFX_CSSValue> ParseString(const wchar_t* pszValue,
81                                       int32_t iValueLen);
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