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