1 // Copyright 2017 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_CSSSTYLESELECTOR_H_ 8 #define XFA_FDE_CSS_CFDE_CSSSTYLESELECTOR_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcrt/fx_basic.h" 14 #include "core/fxcrt/fx_system.h" 15 #include "xfa/fde/css/cfde_cssrulecollection.h" 16 #include "xfa/fde/css/fde_css.h" 17 18 class CFDE_CSSComputedStyle; 19 class CFDE_CSSCustomProperty; 20 class CFDE_CSSDeclaration; 21 class CFDE_CSSPropertyHolder; 22 class CFDE_CSSSelector; 23 class CFDE_CSSStyleSheet; 24 class CFDE_CSSValue; 25 class CFDE_CSSValueList; 26 class CFGAS_FontMgr; 27 28 class CFDE_CSSStyleSelector { 29 public: 30 explicit CFDE_CSSStyleSelector(CFGAS_FontMgr* pFontMgr); 31 ~CFDE_CSSStyleSelector(); 32 33 void SetDefFontSize(FX_FLOAT fFontSize); 34 void SetUAStyleSheet(std::unique_ptr<CFDE_CSSStyleSheet> pSheet); 35 void UpdateStyleIndex(); 36 37 CFX_RetainPtr<CFDE_CSSComputedStyle> CreateComputedStyle( 38 CFDE_CSSComputedStyle* pParentStyle); 39 40 // Note, the dest style has to be an out param because the CXFA_TextParser 41 // adds non-inherited data from the parent style. Attempting to copy 42 // internally will fail as you'll lose the non-inherited data. 43 void ComputeStyle(const std::vector<const CFDE_CSSDeclaration*>& declArray, 44 const CFX_WideString& styleString, 45 const CFX_WideString& alignString, 46 CFDE_CSSComputedStyle* pDestStyle); 47 48 std::vector<const CFDE_CSSDeclaration*> MatchDeclarations( 49 const CFX_WideString& tagname); 50 51 private: 52 bool MatchSelector(const CFX_WideString& tagname, CFDE_CSSSelector* pSel); 53 54 void AppendInlineStyle(CFDE_CSSDeclaration* pDecl, 55 const CFX_WideString& style); 56 void ApplyDeclarations( 57 const std::vector<const CFDE_CSSDeclaration*>& declArray, 58 const CFDE_CSSDeclaration* extraDecl, 59 CFDE_CSSComputedStyle* pDestStyle); 60 void ApplyProperty(FDE_CSSProperty eProperty, 61 const CFX_RetainPtr<CFDE_CSSValue>& pValue, 62 CFDE_CSSComputedStyle* pComputedStyle); 63 void ExtractValues(const CFDE_CSSDeclaration* decl, 64 std::vector<const CFDE_CSSPropertyHolder*>* importants, 65 std::vector<const CFDE_CSSPropertyHolder*>* normals, 66 std::vector<const CFDE_CSSCustomProperty*>* custom); 67 68 bool SetLengthWithPercent(FDE_CSSLength& width, 69 FDE_CSSPrimitiveType eType, 70 const CFX_RetainPtr<CFDE_CSSValue>& pValue, 71 FX_FLOAT fFontSize); 72 FX_FLOAT ToFontSize(FDE_CSSPropertyValue eValue, FX_FLOAT fCurFontSize); 73 FDE_CSSDisplay ToDisplay(FDE_CSSPropertyValue eValue); 74 FDE_CSSTextAlign ToTextAlign(FDE_CSSPropertyValue eValue); 75 uint16_t ToFontWeight(FDE_CSSPropertyValue eValue); 76 FDE_CSSFontStyle ToFontStyle(FDE_CSSPropertyValue eValue); 77 FDE_CSSVerticalAlign ToVerticalAlign(FDE_CSSPropertyValue eValue); 78 uint32_t ToTextDecoration(const CFX_RetainPtr<CFDE_CSSValueList>& pList); 79 FDE_CSSFontVariant ToFontVariant(FDE_CSSPropertyValue eValue); 80 81 CFGAS_FontMgr* const m_pFontMgr; 82 FX_FLOAT m_fDefFontSize; 83 std::unique_ptr<CFDE_CSSStyleSheet> m_UAStyles; 84 CFDE_CSSRuleCollection m_UARules; 85 }; 86 87 #endif // XFA_FDE_CSS_CFDE_CSSSTYLESELECTOR_H_ 88