cfde_cssdeclaration.h revision 5ae9d0c6fd838a2967cca72aa5751b51dadc2769
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_CFDE_CSSDECLARATION_H_ 8#define XFA_FDE_CSS_CFDE_CSSDECLARATION_H_ 9 10#include <memory> 11#include <utility> 12#include <vector> 13 14#include "xfa/fde/css/fde_cssdatatable.h" 15 16class CFDE_CSSPropertyHolder; 17class CFDE_CSSCustomProperty; 18 19class CFDE_CSSDeclaration { 20 public: 21 using const_prop_iterator = 22 std::vector<std::unique_ptr<CFDE_CSSPropertyHolder>>::const_iterator; 23 using const_custom_iterator = 24 std::vector<std::unique_ptr<CFDE_CSSCustomProperty>>::const_iterator; 25 26 static bool ParseCSSString(const FX_WCHAR* pszValue, 27 int32_t iValueLen, 28 int32_t* iOffset, 29 int32_t* iLength); 30 static bool ParseCSSColor(const FX_WCHAR* pszValue, 31 int32_t iValueLen, 32 FX_ARGB* dwColor); 33 34 CFDE_CSSDeclaration(); 35 ~CFDE_CSSDeclaration(); 36 37 CFX_RetainPtr<CFDE_CSSValue> GetProperty(FDE_CSSProperty eProperty, 38 bool* bImportant) const; 39 40 const_prop_iterator begin() const { return properties_.begin(); } 41 const_prop_iterator end() const { return properties_.end(); } 42 43 const_custom_iterator custom_begin() const { 44 return custom_properties_.begin(); 45 } 46 const_custom_iterator custom_end() const { return custom_properties_.end(); } 47 48 bool empty() const { return properties_.empty(); } 49 50 void AddProperty(const FDE_CSSPropertyTable* pTable, 51 const CFX_WideStringC& value); 52 void AddProperty(const CFX_WideString& prop, const CFX_WideString& value); 53 54 size_t PropertyCountForTesting() const; 55 56 FX_ARGB ParseColorForTest(const FX_WCHAR* pszValue, 57 int32_t iValueLen, 58 FX_ARGB* dwColor) const; 59 60 private: 61 void ParseFontProperty(const FX_WCHAR* pszValue, 62 int32_t iValueLen, 63 bool bImportant); 64 bool ParseBorderProperty(const FX_WCHAR* pszValue, 65 int32_t iValueLen, 66 CFX_RetainPtr<CFDE_CSSValue>& pWidth) const; 67 void ParseValueListProperty(const FDE_CSSPropertyTable* pTable, 68 const FX_WCHAR* pszValue, 69 int32_t iValueLen, 70 bool bImportant); 71 void Add4ValuesProperty(const std::vector<CFX_RetainPtr<CFDE_CSSValue>>& list, 72 bool bImportant, 73 FDE_CSSProperty eLeft, 74 FDE_CSSProperty eTop, 75 FDE_CSSProperty eRight, 76 FDE_CSSProperty eBottom); 77 CFX_RetainPtr<CFDE_CSSValue> ParseNumber(const FX_WCHAR* pszValue, 78 int32_t iValueLen); 79 CFX_RetainPtr<CFDE_CSSValue> ParseEnum(const FX_WCHAR* pszValue, 80 int32_t iValueLen); 81 CFX_RetainPtr<CFDE_CSSValue> ParseColor(const FX_WCHAR* pszValue, 82 int32_t iValueLen); 83 CFX_RetainPtr<CFDE_CSSValue> ParseString(const FX_WCHAR* pszValue, 84 int32_t iValueLen); 85 void AddPropertyHolder(FDE_CSSProperty eProperty, 86 CFX_RetainPtr<CFDE_CSSValue> pValue, 87 bool bImportant); 88 89 std::vector<std::unique_ptr<CFDE_CSSPropertyHolder>> properties_; 90 std::vector<std::unique_ptr<CFDE_CSSCustomProperty>> custom_properties_; 91}; 92 93#endif // XFA_FDE_CSS_CFDE_CSSDECLARATION_H_ 94