OLD | NEW |
| (Empty) |
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_SRC_FDE_CSS_FDE_CSSCACHE_H_ | |
8 #define XFA_SRC_FDE_CSS_FDE_CSSCACHE_H_ | |
9 | |
10 #include <map> | |
11 | |
12 #include "xfa/src/fde/css/fde_css.h" | |
13 #include "xfa/src/fgas/crt/fgas_memory.h" | |
14 | |
15 class FDE_CSSCacheItem : public CFX_Target { | |
16 public: | |
17 explicit FDE_CSSCacheItem(IFDE_CSSStyleSheet* p); | |
18 ~FDE_CSSCacheItem(); | |
19 | |
20 IFDE_CSSStyleSheet* pStylesheet; | |
21 FX_DWORD dwActivity; | |
22 }; | |
23 | |
24 class CFDE_CSSStyleSheetCache : public IFDE_CSSStyleSheetCache, | |
25 public CFX_Target { | |
26 public: | |
27 CFDE_CSSStyleSheetCache(); | |
28 ~CFDE_CSSStyleSheetCache(); | |
29 virtual void Release() { delete this; } | |
30 | |
31 virtual void SetMaxItems(int32_t iMaxCount = 5) { | |
32 FXSYS_assert(iMaxCount >= 3); | |
33 m_iMaxItems = iMaxCount; | |
34 } | |
35 | |
36 virtual void AddStyleSheet(const CFX_ByteStringC& szKey, | |
37 IFDE_CSSStyleSheet* pStyleSheet); | |
38 virtual IFDE_CSSStyleSheet* GetStyleSheet(const CFX_ByteStringC& szKey) const; | |
39 virtual void RemoveStyleSheet(const CFX_ByteStringC& szKey); | |
40 | |
41 protected: | |
42 void RemoveLowestActivityItem(); | |
43 std::map<CFX_ByteString, FDE_CSSCacheItem*> m_Stylesheets; | |
44 IFX_MEMAllocator* m_pFixedStore; | |
45 int32_t m_iMaxItems; | |
46 }; | |
47 | |
48 class FDE_CSSTagCache : public CFX_Target { | |
49 public: | |
50 FDE_CSSTagCache(FDE_CSSTagCache* parent, IFDE_CSSTagProvider* tag); | |
51 FDE_CSSTagCache(const FDE_CSSTagCache& it); | |
52 FDE_CSSTagCache* GetParent() const { return pParent; } | |
53 IFDE_CSSTagProvider* GetTag() const { return pTag; } | |
54 FX_DWORD HashID() const { return dwIDHash; } | |
55 FX_DWORD HashTag() const { return dwTagHash; } | |
56 int32_t CountHashClass() const { return dwClassHashs.GetSize(); } | |
57 void SetClassIndex(int32_t index) { iClassIndex = index; } | |
58 FX_DWORD HashClass() const { | |
59 return iClassIndex < dwClassHashs.GetSize() | |
60 ? dwClassHashs.GetAt(iClassIndex) | |
61 : 0; | |
62 } | |
63 | |
64 protected: | |
65 IFDE_CSSTagProvider* pTag; | |
66 FDE_CSSTagCache* pParent; | |
67 FX_DWORD dwIDHash; | |
68 FX_DWORD dwTagHash; | |
69 int32_t iClassIndex; | |
70 CFDE_DWordArray dwClassHashs; | |
71 }; | |
72 typedef CFX_ObjectStackTemplate<FDE_CSSTagCache> CFDE_CSSTagStack; | |
73 | |
74 class CFDE_CSSAccelerator : public IFDE_CSSAccelerator, public CFX_Target { | |
75 public: | |
76 virtual void OnEnterTag(IFDE_CSSTagProvider* pTag); | |
77 virtual void OnLeaveTag(IFDE_CSSTagProvider* pTag); | |
78 void Clear() { m_Stack.RemoveAll(); } | |
79 FDE_CSSTagCache* GetTopElement() const { return m_Stack.GetTopElement(); } | |
80 | |
81 protected: | |
82 CFDE_CSSTagStack m_Stack; | |
83 }; | |
84 | |
85 #endif // XFA_SRC_FDE_CSS_FDE_CSSCACHE_H_ | |
OLD | NEW |