1 // Copyright 2017 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_CSSSTYLESELECTOR_H_ 8 #define CORE_FXCRT_CSS_CFX_CSSSTYLESELECTOR_H_ 9 10 #include <stdint.h> 11 12 #include <memory> 13 #include <vector> 14 15 #include "core/fxcrt/css/cfx_css.h" 16 #include "core/fxcrt/css/cfx_cssrulecollection.h" 17 #include "core/fxcrt/css/cfx_cssvalue.h" 18 #include "core/fxcrt/mask.h" 19 #include "core/fxcrt/retain_ptr.h" 20 21 class CFX_CSSComputedStyle; 22 class CFX_CSSCustomProperty; 23 class CFX_CSSDeclaration; 24 class CFX_CSSPropertyHolder; 25 class CFX_CSSSelector; 26 class CFX_CSSStyleSheet; 27 class CFX_CSSValueList; 28 29 class CFX_CSSStyleSelector { 30 public: 31 CFX_CSSStyleSelector(); 32 ~CFX_CSSStyleSelector(); 33 34 void SetDefaultFontSize(float fFontSize); 35 void SetUAStyleSheet(std::unique_ptr<CFX_CSSStyleSheet> pSheet); 36 void UpdateStyleIndex(); 37 38 RetainPtr<CFX_CSSComputedStyle> CreateComputedStyle( 39 const CFX_CSSComputedStyle* pParentStyle); 40 41 // Note, the dest style has to be an out param because the CXFA_TextParser 42 // adds non-inherited data from the parent style. Attempting to copy 43 // internally will fail as you'll lose the non-inherited data. 44 void ComputeStyle(const std::vector<const CFX_CSSDeclaration*>& declArray, 45 const WideString& styleString, 46 const WideString& alignString, 47 CFX_CSSComputedStyle* pDestStyle); 48 49 std::vector<const CFX_CSSDeclaration*> MatchDeclarations( 50 const WideString& tagname); 51 52 private: 53 bool MatchSelector(const WideString& tagname, CFX_CSSSelector* pSel); 54 55 void AppendInlineStyle(CFX_CSSDeclaration* pDecl, const WideString& style); 56 void ApplyDeclarations( 57 const std::vector<const CFX_CSSDeclaration*>& declArray, 58 const CFX_CSSDeclaration* extraDecl, 59 CFX_CSSComputedStyle* pDestStyle); 60 void ApplyProperty(CFX_CSSProperty eProperty, 61 const RetainPtr<CFX_CSSValue>& pValue, 62 CFX_CSSComputedStyle* pComputedStyle); 63 void ExtractValues(const CFX_CSSDeclaration* decl, 64 std::vector<const CFX_CSSPropertyHolder*>* importants, 65 std::vector<const CFX_CSSPropertyHolder*>* normals, 66 std::vector<const CFX_CSSCustomProperty*>* custom); 67 68 bool SetLengthWithPercent(CFX_CSSLength& width, 69 CFX_CSSValue::PrimitiveType eType, 70 const RetainPtr<CFX_CSSValue>& pValue, 71 float fFontSize); 72 float ToFontSize(CFX_CSSPropertyValue eValue, float fCurFontSize); 73 CFX_CSSDisplay ToDisplay(CFX_CSSPropertyValue eValue); 74 CFX_CSSTextAlign ToTextAlign(CFX_CSSPropertyValue eValue); 75 uint16_t ToFontWeight(CFX_CSSPropertyValue eValue); 76 CFX_CSSFontStyle ToFontStyle(CFX_CSSPropertyValue eValue); 77 CFX_CSSVerticalAlign ToVerticalAlign(CFX_CSSPropertyValue eValue); 78 Mask<CFX_CSSTEXTDECORATION> ToTextDecoration( 79 const RetainPtr<CFX_CSSValueList>& pList); 80 CFX_CSSFontVariant ToFontVariant(CFX_CSSPropertyValue eValue); 81 82 float m_fDefaultFontSize = 12.0f; 83 std::unique_ptr<CFX_CSSStyleSheet> m_UAStyles; 84 CFX_CSSRuleCollection m_UARules; 85 }; 86 87 #endif // CORE_FXCRT_CSS_CFX_CSSSTYLESELECTOR_H_ 88