OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_ | 7 #ifndef XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_ |
8 #define XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_ | 8 #define XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_ |
9 | 9 |
| 10 #include <map> |
10 #include <memory> | 11 #include <memory> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "core/fxcrt/fx_ext.h" | 14 #include "core/fxcrt/fx_ext.h" |
14 #include "xfa/fde/css/fde_css.h" | 15 #include "xfa/fde/css/fde_css.h" |
15 #include "xfa/fde/css/fde_csscache.h" | 16 #include "xfa/fde/css/fde_csscache.h" |
16 #include "xfa/fde/css/fde_cssdeclaration.h" | 17 #include "xfa/fde/css/fde_cssdeclaration.h" |
17 #include "xfa/fgas/crt/fgas_memory.h" | 18 #include "xfa/fgas/crt/fgas_memory.h" |
18 | 19 |
19 class CFDE_CSSAccelerator; | 20 class CFDE_CSSAccelerator; |
(...skipping 14 matching lines...) Expand all Loading... |
34 | 35 |
35 class CFDE_CSSRuleCollection : public CFX_Target { | 36 class CFDE_CSSRuleCollection : public CFX_Target { |
36 public: | 37 public: |
37 CFDE_CSSRuleCollection(); | 38 CFDE_CSSRuleCollection(); |
38 ~CFDE_CSSRuleCollection() override; | 39 ~CFDE_CSSRuleCollection() override; |
39 | 40 |
40 void AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, | 41 void AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, |
41 uint32_t dwMediaList, | 42 uint32_t dwMediaList, |
42 CFGAS_FontMgr* pFontMgr); | 43 CFGAS_FontMgr* pFontMgr); |
43 void Clear(); | 44 void Clear(); |
| 45 int32_t CountSelectors() const { return m_iSelectors; } |
44 | 46 |
45 int32_t CountSelectors() const { return m_iSelectors; } | |
46 FDE_CSSRuleData* GetIDRuleData(uint32_t dwIDHash) { | 47 FDE_CSSRuleData* GetIDRuleData(uint32_t dwIDHash) { |
47 void* pData; | 48 auto it = m_IDRules.find(dwIDHash); |
48 return m_IDRules.Lookup((void*)(uintptr_t)dwIDHash, pData) | 49 return it != m_IDRules.end() ? it->second : nullptr; |
49 ? (FDE_CSSRuleData*)pData | |
50 : nullptr; | |
51 } | 50 } |
52 FDE_CSSRuleData* GetTagRuleData(uint32_t dwTagHasn) { | 51 |
53 void* pData; | 52 FDE_CSSRuleData* GetTagRuleData(uint32_t dwTagHash) { |
54 return m_TagRules.Lookup((void*)(uintptr_t)dwTagHasn, pData) | 53 auto it = m_TagRules.find(dwTagHash); |
55 ? (FDE_CSSRuleData*)pData | 54 return it != m_TagRules.end() ? it->second : nullptr; |
56 : nullptr; | |
57 } | 55 } |
| 56 |
58 FDE_CSSRuleData* GetClassRuleData(uint32_t dwIDHash) { | 57 FDE_CSSRuleData* GetClassRuleData(uint32_t dwIDHash) { |
59 void* pData; | 58 auto it = m_ClassRules.find(dwIDHash); |
60 return m_ClassRules.Lookup((void*)(uintptr_t)dwIDHash, pData) | 59 return it != m_ClassRules.end() ? it->second : nullptr; |
61 ? (FDE_CSSRuleData*)pData | |
62 : nullptr; | |
63 } | 60 } |
| 61 |
64 FDE_CSSRuleData* GetUniversalRuleData() { return m_pUniversalRules; } | 62 FDE_CSSRuleData* GetUniversalRuleData() { return m_pUniversalRules; } |
65 FDE_CSSRuleData* GetPersudoRuleData() { return m_pPersudoRules; } | 63 FDE_CSSRuleData* GetPseudoRuleData() { return m_pPseudoRules; } |
66 | 64 |
67 IFX_MemoryAllocator* m_pStaticStore; | 65 IFX_MemoryAllocator* m_pStaticStore; |
68 | 66 |
69 protected: | 67 protected: |
70 void AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, | 68 void AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, |
71 IFDE_CSSRule* pRule, | 69 IFDE_CSSRule* pRule, |
72 uint32_t dwMediaList, | 70 uint32_t dwMediaList, |
73 CFGAS_FontMgr* pFontMgr); | 71 CFGAS_FontMgr* pFontMgr); |
74 void AddRuleTo(CFX_MapPtrToPtr& map, | 72 void AddRuleTo(std::map<uint32_t, FDE_CSSRuleData*>* pMap, |
75 uint32_t dwKey, | 73 uint32_t dwKey, |
76 CFDE_CSSSelector* pSel, | 74 CFDE_CSSSelector* pSel, |
77 CFDE_CSSDeclaration* pDecl); | 75 CFDE_CSSDeclaration* pDecl); |
78 bool AddRuleTo(FDE_CSSRuleData*& pList, FDE_CSSRuleData* pData); | 76 bool AddRuleTo(FDE_CSSRuleData** pList, FDE_CSSRuleData* pData); |
79 FDE_CSSRuleData* NewRuleData(CFDE_CSSSelector* pSel, | 77 FDE_CSSRuleData* NewRuleData(CFDE_CSSSelector* pSel, |
80 CFDE_CSSDeclaration* pDecl); | 78 CFDE_CSSDeclaration* pDecl); |
81 CFX_MapPtrToPtr m_IDRules; | 79 |
82 CFX_MapPtrToPtr m_TagRules; | 80 std::map<uint32_t, FDE_CSSRuleData*> m_IDRules; |
83 CFX_MapPtrToPtr m_ClassRules; | 81 std::map<uint32_t, FDE_CSSRuleData*> m_TagRules; |
| 82 std::map<uint32_t, FDE_CSSRuleData*> m_ClassRules; |
84 FDE_CSSRuleData* m_pUniversalRules; | 83 FDE_CSSRuleData* m_pUniversalRules; |
85 FDE_CSSRuleData* m_pPersudoRules; | 84 FDE_CSSRuleData* m_pPseudoRules; |
86 int32_t m_iSelectors; | 85 int32_t m_iSelectors; |
87 }; | 86 }; |
88 | 87 |
89 class CFDE_CSSStyleSelector : public CFX_Target { | 88 class CFDE_CSSStyleSelector : public CFX_Target { |
90 public: | 89 public: |
91 explicit CFDE_CSSStyleSelector(CFGAS_FontMgr* pFontMgr); | 90 explicit CFDE_CSSStyleSelector(CFGAS_FontMgr* pFontMgr); |
92 ~CFDE_CSSStyleSelector() override; | 91 ~CFDE_CSSStyleSelector() override; |
93 | 92 |
94 void SetDefFontSize(FX_FLOAT fFontSize); | 93 void SetDefFontSize(FX_FLOAT fFontSize); |
95 | 94 |
96 bool SetStyleSheet(FDE_CSSSTYLESHEETGROUP eType, IFDE_CSSStyleSheet* pSheet); | 95 bool SetStyleSheet(FDE_CSSSTYLESHEETGROUP eType, IFDE_CSSStyleSheet* pSheet); |
97 bool SetStyleSheets(FDE_CSSSTYLESHEETGROUP eType, | 96 bool SetStyleSheets(FDE_CSSSTYLESHEETGROUP eType, |
98 const CFDE_CSSStyleSheetArray* pArray); | 97 const CFDE_CSSStyleSheetArray* pArray); |
99 void SetStylePriority(FDE_CSSSTYLESHEETGROUP eType, | 98 void SetStylePriority(FDE_CSSSTYLESHEETGROUP eType, |
100 FDE_CSSSTYLESHEETPRIORITY ePriority); | 99 FDE_CSSSTYLESHEETPRIORITY ePriority); |
101 void UpdateStyleIndex(uint32_t dwMediaList); | 100 void UpdateStyleIndex(uint32_t dwMediaList); |
102 CFDE_CSSAccelerator* InitAccelerator(); | 101 CFDE_CSSAccelerator* InitAccelerator(); |
103 IFDE_CSSComputedStyle* CreateComputedStyle( | 102 IFDE_CSSComputedStyle* CreateComputedStyle( |
104 IFDE_CSSComputedStyle* pParentStyle); | 103 IFDE_CSSComputedStyle* pParentStyle); |
105 int32_t MatchDeclarations(CXFA_CSSTagProvider* pTag, | 104 int32_t MatchDeclarations(CXFA_CSSTagProvider* pTag, |
106 CFDE_CSSDeclarationArray& matchedDecls, | 105 CFDE_CSSDeclarationArray& matchedDecls, |
107 FDE_CSSPERSUDO ePersudoType = FDE_CSSPERSUDO_NONE); | 106 FDE_CSSPSEUDO ePseudoType = FDE_CSSPSEUDO_NONE); |
108 void ComputeStyle(CXFA_CSSTagProvider* pTag, | 107 void ComputeStyle(CXFA_CSSTagProvider* pTag, |
109 const CFDE_CSSDeclaration** ppDeclArray, | 108 const CFDE_CSSDeclaration** ppDeclArray, |
110 int32_t iDeclCount, | 109 int32_t iDeclCount, |
111 IFDE_CSSComputedStyle* pDestStyle); | 110 IFDE_CSSComputedStyle* pDestStyle); |
112 | 111 |
113 protected: | 112 protected: |
114 void Reset(); | 113 void Reset(); |
115 void MatchRules(FDE_CSSTagCache* pCache, | 114 void MatchRules(FDE_CSSTagCache* pCache, |
116 FDE_CSSRuleData* pList, | 115 FDE_CSSRuleData* pList, |
117 FDE_CSSPERSUDO ePersudoType); | 116 FDE_CSSPSEUDO ePseudoType); |
118 bool MatchSelector(FDE_CSSTagCache* pCache, | 117 bool MatchSelector(FDE_CSSTagCache* pCache, |
119 CFDE_CSSSelector* pSel, | 118 CFDE_CSSSelector* pSel, |
120 FDE_CSSPERSUDO ePersudoType); | 119 FDE_CSSPSEUDO ePseudoType); |
121 void AppendInlineStyle(CFDE_CSSDeclaration* pDecl, | 120 void AppendInlineStyle(CFDE_CSSDeclaration* pDecl, |
122 const FX_WCHAR* psz, | 121 const FX_WCHAR* psz, |
123 int32_t iLen); | 122 int32_t iLen); |
124 void ApplyDeclarations(bool bPriority, | 123 void ApplyDeclarations(bool bPriority, |
125 const CFDE_CSSDeclaration** ppDeclArray, | 124 const CFDE_CSSDeclaration** ppDeclArray, |
126 int32_t iDeclCount, | 125 int32_t iDeclCount, |
127 IFDE_CSSComputedStyle* pDestStyle); | 126 IFDE_CSSComputedStyle* pDestStyle); |
128 void ApplyProperty(FDE_CSSPROPERTY eProperty, | 127 void ApplyProperty(FDE_CSSPROPERTY eProperty, |
129 IFDE_CSSValue* pValue, | 128 IFDE_CSSValue* pValue, |
130 CFDE_CSSComputedStyle* pComputedStyle); | 129 CFDE_CSSComputedStyle* pComputedStyle); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 const CFX_WideString& wsValue); | 410 const CFX_WideString& wsValue); |
412 | 411 |
413 uint32_t m_dwRefCount; | 412 uint32_t m_dwRefCount; |
414 IFX_MemoryAllocator* const m_pAllocator; | 413 IFX_MemoryAllocator* const m_pAllocator; |
415 CFDE_CSSInheritedData m_InheritedData; | 414 CFDE_CSSInheritedData m_InheritedData; |
416 CFDE_CSSNonInheritedData m_NonInheritedData; | 415 CFDE_CSSNonInheritedData m_NonInheritedData; |
417 std::vector<CFX_WideString> m_CustomProperties; | 416 std::vector<CFX_WideString> m_CustomProperties; |
418 }; | 417 }; |
419 | 418 |
420 #endif // XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_ | 419 #endif // XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_ |
OLD | NEW |