• 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 <utility>
12 #include <vector>
13 
14 #include "core/fxcrt/css/cfx_cssdatatable.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                              int32_t iValueLen,
28                              int32_t* iOffset,
29                              int32_t* iLength);
30   static bool ParseCSSColor(const wchar_t* pszValue,
31                             int32_t iValueLen,
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_CSSPropertyTable* pTable,
51                    const WideStringView& value);
52   void AddProperty(const WideString& prop, const WideString& value);
53 
54   size_t PropertyCountForTesting() const;
55 
56   FX_ARGB ParseColorForTest(const wchar_t* pszValue,
57                             int32_t iValueLen,
58                             FX_ARGB* dwColor) const;
59 
60  private:
61   void ParseFontProperty(const wchar_t* pszValue,
62                          int32_t iValueLen,
63                          bool bImportant);
64   bool ParseBorderProperty(const wchar_t* pszValue,
65                            int32_t iValueLen,
66                            RetainPtr<CFX_CSSValue>& pWidth) const;
67   void ParseValueListProperty(const CFX_CSSPropertyTable* pTable,
68                               const wchar_t* pszValue,
69                               int32_t iValueLen,
70                               bool bImportant);
71   void Add4ValuesProperty(const std::vector<RetainPtr<CFX_CSSValue>>& list,
72                           bool bImportant,
73                           CFX_CSSProperty eLeft,
74                           CFX_CSSProperty eTop,
75                           CFX_CSSProperty eRight,
76                           CFX_CSSProperty eBottom);
77   RetainPtr<CFX_CSSValue> ParseNumber(const wchar_t* pszValue,
78                                       int32_t iValueLen);
79   RetainPtr<CFX_CSSValue> ParseEnum(const wchar_t* pszValue, int32_t iValueLen);
80   RetainPtr<CFX_CSSValue> ParseColor(const wchar_t* pszValue,
81                                      int32_t iValueLen);
82   RetainPtr<CFX_CSSValue> ParseString(const wchar_t* pszValue,
83                                       int32_t iValueLen);
84   void AddPropertyHolder(CFX_CSSProperty eProperty,
85                          RetainPtr<CFX_CSSValue> pValue,
86                          bool bImportant);
87 
88   std::vector<std::unique_ptr<CFX_CSSPropertyHolder>> properties_;
89   std::vector<std::unique_ptr<CFX_CSSCustomProperty>> custom_properties_;
90 };
91 
92 #endif  // CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_
93