Home | History | Annotate | Download | only in css
      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:
     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) {}
     19   virtual FDE_CSSSELECTORTYPE GetType() const { return m_eType; }
     20 
     21   virtual FX_DWORD GetNameHash() const { return m_dwHash; }
     22 
     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);
     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);
     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:
     43   CFDE_CSSStyleRule() : m_ppSelector(NULL), m_iSelectors(0) {}
     44   virtual int32_t CountSelectorLists() const { return m_iSelectors; }
     45   virtual IFDE_CSSSelector* GetSelectorList(int32_t index) const {
     46     return m_ppSelector[index];
     47   }
     48 
     49   virtual IFDE_CSSDeclaration* GetDeclaration() const {
     50     return (IFDE_CSSDeclaration*)&m_Declaration;
     51   }
     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:
     63   CFDE_CSSMediaRule(FX_DWORD dwMediaList) : m_dwMediaList(dwMediaList) {}
     64   ~CFDE_CSSMediaRule();
     65 
     66   virtual FX_DWORD GetMediaList() const { return m_dwMediaList; }
     67 
     68   virtual int32_t CountRules() const { return m_RuleArray.GetSize(); }
     69   virtual IFDE_CSSRule* GetRule(int32_t index) {
     70     return m_RuleArray.GetAt(index);
     71   }
     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:
     80   virtual IFDE_CSSDeclaration* GetDeclaration() const {
     81     return (IFDE_CSSDeclaration*)&m_Declaration;
     82   }
     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 
    101   virtual FX_BOOL GetUrl(CFX_WideString& szUrl) {
    102     szUrl = m_szUrl;
    103     return szUrl.GetLength() > 0;
    104   }
    105   virtual FX_DWORD GetMediaList() const { return m_dwMediaList; }
    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