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