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_CSSSTYLESHEET 8 #define _FDE_CSSSTYLESHEET 9 #include "fde_cssdeclaration.h" 10 class CFDE_CSSSelector : public IFDE_CSSSelector, public CFX_Target { 11 public: CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType,const FX_WCHAR * psz,int32_t iLen,FX_BOOL bIgnoreCase)12 CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, 13 const FX_WCHAR* psz, 14 int32_t iLen, 15 FX_BOOL bIgnoreCase) 16 : m_eType(eType), 17 m_dwHash(FX_HashCode_String_GetW(psz, iLen, bIgnoreCase)), 18 m_pNext(NULL) {} GetType()19 virtual FDE_CSSSELECTORTYPE GetType() const { return m_eType; } 20 GetNameHash()21 virtual FX_DWORD GetNameHash() const { return m_dwHash; } 22 GetNextSelector()23 virtual IFDE_CSSSelector* GetNextSelector() const { return m_pNext; } 24 static IFDE_CSSSelector* FromString(IFX_MEMAllocator* pStaticStore, 25 const FX_WCHAR* psz, 26 int32_t iLen); SetNext(IFDE_CSSSelector * pNext)27 void SetNext(IFDE_CSSSelector* pNext) { m_pNext = pNext; } 28 29 protected: 30 static CFDE_CSSSelector* ParseSelector(IFX_MEMAllocator* pStaticStore, 31 const FX_WCHAR* psz, 32 int32_t& iOff, 33 int32_t iLen, 34 FDE_CSSSELECTORTYPE eType); SetType(FDE_CSSSELECTORTYPE eType)35 void SetType(FDE_CSSSELECTORTYPE eType) { m_eType = eType; } 36 FDE_CSSSELECTORTYPE m_eType; 37 FX_DWORD m_dwHash; 38 IFDE_CSSSelector* m_pNext; 39 }; 40 typedef CFX_ArrayTemplate<IFDE_CSSSelector*> CFDE_CSSSelectorArray; 41 class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target { 42 public: CFDE_CSSStyleRule()43 CFDE_CSSStyleRule() : m_ppSelector(NULL), m_iSelectors(0) {} CountSelectorLists()44 virtual int32_t CountSelectorLists() const { return m_iSelectors; } GetSelectorList(int32_t index)45 virtual IFDE_CSSSelector* GetSelectorList(int32_t index) const { 46 return m_ppSelector[index]; 47 } 48 GetDeclaration()49 virtual IFDE_CSSDeclaration* GetDeclaration() const { 50 return (IFDE_CSSDeclaration*)&m_Declaration; 51 } GetDeclImp()52 CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } 53 void SetSelector(IFX_MEMAllocator* pStaticStore, 54 const CFDE_CSSSelectorArray& list); 55 56 protected: 57 CFDE_CSSDeclaration m_Declaration; 58 IFDE_CSSSelector** m_ppSelector; 59 int32_t m_iSelectors; 60 }; 61 class CFDE_CSSMediaRule : public IFDE_CSSMediaRule, public CFX_Target { 62 public: CFDE_CSSMediaRule(FX_DWORD dwMediaList)63 CFDE_CSSMediaRule(FX_DWORD dwMediaList) : m_dwMediaList(dwMediaList) {} 64 ~CFDE_CSSMediaRule(); 65 GetMediaList()66 virtual FX_DWORD GetMediaList() const { return m_dwMediaList; } 67 CountRules()68 virtual int32_t CountRules() const { return m_RuleArray.GetSize(); } GetRule(int32_t index)69 virtual IFDE_CSSRule* GetRule(int32_t index) { 70 return m_RuleArray.GetAt(index); 71 } GetArray()72 CFDE_CSSRuleArray& GetArray() { return m_RuleArray; } 73 74 protected: 75 FX_DWORD m_dwMediaList; 76 CFDE_CSSRuleArray m_RuleArray; 77 }; 78 class CFDE_CSSFontFaceRule : public IFDE_CSSFontFaceRule, public CFX_Target { 79 public: GetDeclaration()80 virtual IFDE_CSSDeclaration* GetDeclaration() const { 81 return (IFDE_CSSDeclaration*)&m_Declaration; 82 } GetDeclImp()83 CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } 84 85 protected: 86 CFDE_CSSDeclaration m_Declaration; 87 }; 88 #define FDE_CSSSWITCHDEFAULTS() \ 89 case FDE_CSSSYNTAXSTATUS_EOS: \ 90 return FDE_CSSSYNTAXSTATUS_EOS; \ 91 case FDE_CSSSYNTAXSTATUS_Error: \ 92 default: \ 93 return FDE_CSSSYNTAXSTATUS_Error; 94 class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet, public CFX_Target { 95 public: 96 CFDE_CSSStyleSheet(FX_DWORD dwMediaList); 97 ~CFDE_CSSStyleSheet(); 98 virtual FX_DWORD AddRef(); 99 virtual FX_DWORD Release(); 100 GetUrl(CFX_WideString & szUrl)101 virtual FX_BOOL GetUrl(CFX_WideString& szUrl) { 102 szUrl = m_szUrl; 103 return szUrl.GetLength() > 0; 104 } GetMediaList()105 virtual FX_DWORD GetMediaList() const { return m_dwMediaList; } GetCodePage()106 virtual FX_WORD GetCodePage() const { return m_wCodePage; } 107 virtual int32_t CountRules() const; 108 virtual IFDE_CSSRule* GetRule(int32_t index); 109 FX_BOOL LoadFromStream(const CFX_WideString& szUrl, 110 IFX_Stream* pStream, 111 FX_WORD wCodePage); 112 FX_BOOL LoadFromBuffer(const CFX_WideString& szUrl, 113 const FX_WCHAR* pBuffer, 114 int32_t iBufSize, 115 FX_WORD wCodePage); 116 117 protected: 118 void Reset(); 119 FX_BOOL LoadFromSyntax(IFDE_CSSSyntaxParser* pSyntax); 120 FDE_CSSSYNTAXSTATUS LoadStyleRule(IFDE_CSSSyntaxParser* pSyntax, 121 CFDE_CSSRuleArray& ruleArray); 122 FDE_CSSSYNTAXSTATUS LoadImportRule(IFDE_CSSSyntaxParser* pSyntax); 123 FDE_CSSSYNTAXSTATUS LoadPageRule(IFDE_CSSSyntaxParser* pSyntax); 124 FDE_CSSSYNTAXSTATUS LoadMediaRule(IFDE_CSSSyntaxParser* pSyntax); 125 FDE_CSSSYNTAXSTATUS LoadFontFaceRule(IFDE_CSSSyntaxParser* pSyntax, 126 CFDE_CSSRuleArray& ruleArray); 127 FDE_CSSSYNTAXSTATUS SkipRuleSet(IFDE_CSSSyntaxParser* pSyntax); 128 FX_WORD m_wCodePage; 129 FX_WORD m_wRefCount; 130 FX_DWORD m_dwMediaList; 131 IFX_MEMAllocator* m_pAllocator; 132 CFDE_CSSRuleArray m_RuleArray; 133 CFX_WideString m_szUrl; 134 CFDE_CSSSelectorArray m_Selectors; 135 CFX_MapPtrToPtr m_StringCache; 136 }; 137 #endif 138