blob: 0fe63477d36a75f38694974a1fa8314f0237b216 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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_FDE_CSS_FDE_CSSSTYLESHEET_H_
8#define XFA_FDE_CSS_FDE_CSSSTYLESHEET_H_
9
weilicddf8252016-08-04 15:43:59 -070010#include <memory>
tsepez788ac382016-05-19 21:06:16 -070011#include <unordered_map>
12
dsinclaira52ab742016-09-29 13:59:29 -070013#include "core/fxcrt/fx_ext.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040014#include "xfa/fde/css/fde_cssdeclaration.h"
15
dsinclaire6ebf7a2016-04-28 06:34:24 -070016class CFDE_CSSSyntaxParser;
17
18class CFDE_CSSSelector : public CFX_Target {
Dan Sinclair1770c022016-03-14 14:14:16 -040019 public:
20 CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType,
21 const FX_WCHAR* psz,
22 int32_t iLen,
weilieec3a362016-06-18 06:25:37 -070023 bool bIgnoreCase);
Dan Sinclair1770c022016-03-14 14:14:16 -040024
weilieec3a362016-06-18 06:25:37 -070025 virtual FDE_CSSSELECTORTYPE GetType() const;
26 virtual uint32_t GetNameHash() const;
27 virtual CFDE_CSSSelector* GetNextSelector() const;
Dan Sinclair1770c022016-03-14 14:14:16 -040028
tsepez4d06f832016-05-03 14:13:29 -070029 static CFDE_CSSSelector* FromString(IFX_MemoryAllocator* pStaticStore,
Dan Sinclair1770c022016-03-14 14:14:16 -040030 const FX_WCHAR* psz,
31 int32_t iLen);
weilieec3a362016-06-18 06:25:37 -070032
dsinclaire6ebf7a2016-04-28 06:34:24 -070033 void SetNext(CFDE_CSSSelector* pNext) { m_pNext = pNext; }
Dan Sinclair1770c022016-03-14 14:14:16 -040034
35 protected:
Dan Sinclair1770c022016-03-14 14:14:16 -040036 void SetType(FDE_CSSSELECTORTYPE eType) { m_eType = eType; }
weilieec3a362016-06-18 06:25:37 -070037
Dan Sinclair1770c022016-03-14 14:14:16 -040038 FDE_CSSSELECTORTYPE m_eType;
tsepezdeee3d22016-03-25 14:38:58 -070039 uint32_t m_dwHash;
dsinclaire6ebf7a2016-04-28 06:34:24 -070040 CFDE_CSSSelector* m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -040041};
weilieec3a362016-06-18 06:25:37 -070042
Dan Sinclair1770c022016-03-14 14:14:16 -040043class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target {
44 public:
weilieec3a362016-06-18 06:25:37 -070045 CFDE_CSSStyleRule();
Dan Sinclair1770c022016-03-14 14:14:16 -040046
weilieec3a362016-06-18 06:25:37 -070047 // IFDE_CSSStyleRule
48 int32_t CountSelectorLists() const override;
49 CFDE_CSSSelector* GetSelectorList(int32_t index) const override;
50 CFDE_CSSDeclaration* GetDeclaration() override;
51
Dan Sinclair1770c022016-03-14 14:14:16 -040052 CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; }
tsepez4d06f832016-05-03 14:13:29 -070053 void SetSelector(IFX_MemoryAllocator* pStaticStore,
dsinclair34965452016-07-18 13:14:49 -070054 const CFX_ArrayTemplate<CFDE_CSSSelector*>& list);
Dan Sinclair1770c022016-03-14 14:14:16 -040055
56 protected:
57 CFDE_CSSDeclaration m_Declaration;
dsinclaire6ebf7a2016-04-28 06:34:24 -070058 CFDE_CSSSelector** m_ppSelector;
Dan Sinclair1770c022016-03-14 14:14:16 -040059 int32_t m_iSelectors;
60};
weilieec3a362016-06-18 06:25:37 -070061
Dan Sinclair1770c022016-03-14 14:14:16 -040062class CFDE_CSSMediaRule : public IFDE_CSSMediaRule, public CFX_Target {
63 public:
weilieec3a362016-06-18 06:25:37 -070064 explicit CFDE_CSSMediaRule(uint32_t dwMediaList);
65 ~CFDE_CSSMediaRule() override;
Dan Sinclair1770c022016-03-14 14:14:16 -040066
weilieec3a362016-06-18 06:25:37 -070067 // IFDE_CSSMediaRule
68 uint32_t GetMediaList() const override;
69 int32_t CountRules() const override;
70 IFDE_CSSRule* GetRule(int32_t index) override;
Dan Sinclair1770c022016-03-14 14:14:16 -040071
dsinclair34965452016-07-18 13:14:49 -070072 CFX_MassArrayTemplate<IFDE_CSSRule*>& GetArray() { return m_RuleArray; }
Dan Sinclair1770c022016-03-14 14:14:16 -040073
74 protected:
tsepezdeee3d22016-03-25 14:38:58 -070075 uint32_t m_dwMediaList;
dsinclair34965452016-07-18 13:14:49 -070076 CFX_MassArrayTemplate<IFDE_CSSRule*> m_RuleArray;
Dan Sinclair1770c022016-03-14 14:14:16 -040077};
weilieec3a362016-06-18 06:25:37 -070078
Dan Sinclair1770c022016-03-14 14:14:16 -040079class CFDE_CSSFontFaceRule : public IFDE_CSSFontFaceRule, public CFX_Target {
80 public:
weilieec3a362016-06-18 06:25:37 -070081 // IFDE_CSSFontFaceRule
82 CFDE_CSSDeclaration* GetDeclaration() override;
83
Dan Sinclair1770c022016-03-14 14:14:16 -040084 CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; }
85
86 protected:
87 CFDE_CSSDeclaration m_Declaration;
88};
weilieec3a362016-06-18 06:25:37 -070089
Dan Sinclair1770c022016-03-14 14:14:16 -040090#define FDE_CSSSWITCHDEFAULTS() \
91 case FDE_CSSSYNTAXSTATUS_EOS: \
92 return FDE_CSSSYNTAXSTATUS_EOS; \
93 case FDE_CSSSYNTAXSTATUS_Error: \
94 default: \
95 return FDE_CSSSYNTAXSTATUS_Error;
weilieec3a362016-06-18 06:25:37 -070096
Dan Sinclair1770c022016-03-14 14:14:16 -040097class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet, public CFX_Target {
98 public:
tsepezdeee3d22016-03-25 14:38:58 -070099 CFDE_CSSStyleSheet(uint32_t dwMediaList);
tsepeza2d699f2016-05-23 17:19:20 -0700100 ~CFDE_CSSStyleSheet() override;
Dan Sinclair1770c022016-03-14 14:14:16 -0400101
tsepeza2d699f2016-05-23 17:19:20 -0700102 // IFX_Retainable:
103 uint32_t Retain() override;
104 uint32_t Release() override;
105
106 // IFDE_CSSStyleSheet:
tsepezd19e9122016-11-02 15:43:18 -0700107 bool GetUrl(CFX_WideString& szUrl) override;
weilieec3a362016-06-18 06:25:37 -0700108 uint32_t GetMediaList() const override;
109 uint16_t GetCodePage() const override;
tsepeza2d699f2016-05-23 17:19:20 -0700110 int32_t CountRules() const override;
111 IFDE_CSSRule* GetRule(int32_t index) override;
112
tsepezd19e9122016-11-02 15:43:18 -0700113 bool LoadFromStream(const CFX_WideString& szUrl,
114 IFX_Stream* pStream,
115 uint16_t wCodePage);
116 bool LoadFromBuffer(const CFX_WideString& szUrl,
117 const FX_WCHAR* pBuffer,
118 int32_t iBufSize,
119 uint16_t wCodePage);
Dan Sinclair1770c022016-03-14 14:14:16 -0400120
121 protected:
122 void Reset();
tsepezd19e9122016-11-02 15:43:18 -0700123 bool LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax);
dsinclair34965452016-07-18 13:14:49 -0700124 FDE_CSSSYNTAXSTATUS LoadStyleRule(
125 CFDE_CSSSyntaxParser* pSyntax,
126 CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray);
dsinclaire6ebf7a2016-04-28 06:34:24 -0700127 FDE_CSSSYNTAXSTATUS LoadImportRule(CFDE_CSSSyntaxParser* pSyntax);
128 FDE_CSSSYNTAXSTATUS LoadPageRule(CFDE_CSSSyntaxParser* pSyntax);
129 FDE_CSSSYNTAXSTATUS LoadMediaRule(CFDE_CSSSyntaxParser* pSyntax);
dsinclair34965452016-07-18 13:14:49 -0700130 FDE_CSSSYNTAXSTATUS LoadFontFaceRule(
131 CFDE_CSSSyntaxParser* pSyntax,
132 CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray);
dsinclaire6ebf7a2016-04-28 06:34:24 -0700133 FDE_CSSSYNTAXSTATUS SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax);
Tom Sepez62a70f92016-03-21 15:00:20 -0700134 uint16_t m_wCodePage;
135 uint16_t m_wRefCount;
tsepezdeee3d22016-03-25 14:38:58 -0700136 uint32_t m_dwMediaList;
weilicddf8252016-08-04 15:43:59 -0700137 std::unique_ptr<IFX_MemoryAllocator> m_pAllocator;
dsinclair34965452016-07-18 13:14:49 -0700138 CFX_MassArrayTemplate<IFDE_CSSRule*> m_RuleArray;
Dan Sinclair1770c022016-03-14 14:14:16 -0400139 CFX_WideString m_szUrl;
dsinclair34965452016-07-18 13:14:49 -0700140 CFX_ArrayTemplate<CFDE_CSSSelector*> m_Selectors;
tsepez788ac382016-05-19 21:06:16 -0700141 std::unordered_map<uint32_t, FX_WCHAR*> m_StringCache;
Dan Sinclair1770c022016-03-14 14:14:16 -0400142};
143
144#endif // XFA_FDE_CSS_FDE_CSSSTYLESHEET_H_