OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fde/css/fde_cssstylesheet.h" | 7 #include "xfa/fde/css/fde_cssstylesheet.h" |
8 | 8 |
9 #include "xfa/fde/css/fde_cssdatatable.h" | 9 #include "xfa/fde/css/fde_cssdatatable.h" |
10 #include "xfa/fde/css/fde_csssyntax.h" | 10 #include "xfa/fde/css/fde_csssyntax.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 L"q:before{content:open-quote}q:after{content:close-quote}" | 42 L"q:before{content:open-quote}q:after{content:close-quote}" |
43 L"rp{display:none}"; | 43 L"rp{display:none}"; |
44 return IFDE_CSSStyleSheet::LoadFromBuffer( | 44 return IFDE_CSSStyleSheet::LoadFromBuffer( |
45 CFX_WideString(), s_pStyle, FXSYS_wcslen(s_pStyle), FX_CODEPAGE_UTF8); | 45 CFX_WideString(), s_pStyle, FXSYS_wcslen(s_pStyle), FX_CODEPAGE_UTF8); |
46 } | 46 } |
47 | 47 |
48 IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromStream( | 48 IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromStream( |
49 const CFX_WideString& szUrl, | 49 const CFX_WideString& szUrl, |
50 IFX_Stream* pStream, | 50 IFX_Stream* pStream, |
51 uint16_t wCodePage, | 51 uint16_t wCodePage, |
52 FX_DWORD dwMediaList) { | 52 uint32_t dwMediaList) { |
53 CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(dwMediaList); | 53 CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(dwMediaList); |
54 if (!pStyleSheet->LoadFromStream(szUrl, pStream, wCodePage)) { | 54 if (!pStyleSheet->LoadFromStream(szUrl, pStream, wCodePage)) { |
55 pStyleSheet->Release(); | 55 pStyleSheet->Release(); |
56 pStyleSheet = NULL; | 56 pStyleSheet = NULL; |
57 } | 57 } |
58 return pStyleSheet; | 58 return pStyleSheet; |
59 } | 59 } |
60 IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromBuffer( | 60 IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromBuffer( |
61 const CFX_WideString& szUrl, | 61 const CFX_WideString& szUrl, |
62 const FX_WCHAR* pBuffer, | 62 const FX_WCHAR* pBuffer, |
63 int32_t iBufSize, | 63 int32_t iBufSize, |
64 uint16_t wCodePage, | 64 uint16_t wCodePage, |
65 FX_DWORD dwMediaList) { | 65 uint32_t dwMediaList) { |
66 CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(dwMediaList); | 66 CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(dwMediaList); |
67 if (!pStyleSheet->LoadFromBuffer(szUrl, pBuffer, iBufSize, wCodePage)) { | 67 if (!pStyleSheet->LoadFromBuffer(szUrl, pBuffer, iBufSize, wCodePage)) { |
68 pStyleSheet->Release(); | 68 pStyleSheet->Release(); |
69 pStyleSheet = NULL; | 69 pStyleSheet = NULL; |
70 } | 70 } |
71 return pStyleSheet; | 71 return pStyleSheet; |
72 } | 72 } |
73 CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(FX_DWORD dwMediaList) | 73 CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList) |
74 : m_wCodePage(FX_CODEPAGE_UTF8), | 74 : m_wCodePage(FX_CODEPAGE_UTF8), |
75 m_wRefCount(1), | 75 m_wRefCount(1), |
76 m_dwMediaList(dwMediaList), | 76 m_dwMediaList(dwMediaList), |
77 m_pAllocator(NULL) { | 77 m_pAllocator(NULL) { |
78 FXSYS_assert(m_dwMediaList > 0); | 78 FXSYS_assert(m_dwMediaList > 0); |
79 } | 79 } |
80 CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() { | 80 CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() { |
81 Reset(); | 81 Reset(); |
82 } | 82 } |
83 void CFDE_CSSStyleSheet::Reset() { | 83 void CFDE_CSSStyleSheet::Reset() { |
(...skipping 15 matching lines...) Expand all Loading... |
99 } | 99 } |
100 } | 100 } |
101 m_RuleArray.RemoveAll(); | 101 m_RuleArray.RemoveAll(); |
102 m_Selectors.RemoveAll(); | 102 m_Selectors.RemoveAll(); |
103 m_StringCache.RemoveAll(); | 103 m_StringCache.RemoveAll(); |
104 if (m_pAllocator) { | 104 if (m_pAllocator) { |
105 m_pAllocator->Release(); | 105 m_pAllocator->Release(); |
106 m_pAllocator = NULL; | 106 m_pAllocator = NULL; |
107 } | 107 } |
108 } | 108 } |
109 FX_DWORD CFDE_CSSStyleSheet::AddRef() { | 109 uint32_t CFDE_CSSStyleSheet::AddRef() { |
110 return ++m_wRefCount; | 110 return ++m_wRefCount; |
111 } | 111 } |
112 FX_DWORD CFDE_CSSStyleSheet::Release() { | 112 uint32_t CFDE_CSSStyleSheet::Release() { |
113 FX_DWORD dwRefCount = --m_wRefCount; | 113 uint32_t dwRefCount = --m_wRefCount; |
114 if (dwRefCount == 0) { | 114 if (dwRefCount == 0) { |
115 delete this; | 115 delete this; |
116 } | 116 } |
117 return dwRefCount; | 117 return dwRefCount; |
118 } | 118 } |
119 int32_t CFDE_CSSStyleSheet::CountRules() const { | 119 int32_t CFDE_CSSStyleSheet::CountRules() const { |
120 return m_RuleArray.GetSize(); | 120 return m_RuleArray.GetSize(); |
121 } | 121 } |
122 IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { | 122 IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { |
123 return m_RuleArray.GetAt(index); | 123 return m_RuleArray.GetAt(index); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 default: | 181 default: |
182 break; | 182 break; |
183 } | 183 } |
184 } while (eStatus >= FDE_CSSSYNTAXSTATUS_None); | 184 } while (eStatus >= FDE_CSSSYNTAXSTATUS_None); |
185 m_Selectors.RemoveAll(); | 185 m_Selectors.RemoveAll(); |
186 m_StringCache.RemoveAll(); | 186 m_StringCache.RemoveAll(); |
187 return eStatus != FDE_CSSSYNTAXSTATUS_Error; | 187 return eStatus != FDE_CSSSYNTAXSTATUS_Error; |
188 } | 188 } |
189 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( | 189 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( |
190 IFDE_CSSSyntaxParser* pSyntax) { | 190 IFDE_CSSSyntaxParser* pSyntax) { |
191 FX_DWORD dwMediaList = 0; | 191 uint32_t dwMediaList = 0; |
192 CFDE_CSSMediaRule* pMediaRule = NULL; | 192 CFDE_CSSMediaRule* pMediaRule = NULL; |
193 for (;;) { | 193 for (;;) { |
194 switch (pSyntax->DoSyntaxParse()) { | 194 switch (pSyntax->DoSyntaxParse()) { |
195 case FDE_CSSSYNTAXSTATUS_MediaType: { | 195 case FDE_CSSSYNTAXSTATUS_MediaType: { |
196 int32_t iLen; | 196 int32_t iLen; |
197 const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); | 197 const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); |
198 FDE_LPCCSSMEDIATYPETABLE pMediaType = | 198 FDE_LPCCSSMEDIATYPETABLE pMediaType = |
199 FDE_GetCSSMediaTypeByName(psz, iLen); | 199 FDE_GetCSSMediaTypeByName(psz, iLen); |
200 if (pMediaType != NULL) { | 200 if (pMediaType != NULL) { |
201 dwMediaList |= pMediaType->wValue; | 201 dwMediaList |= pMediaType->wValue; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 return NULL; | 500 return NULL; |
501 } | 501 } |
502 } | 502 } |
503 if (pPersudoFirst == NULL) { | 503 if (pPersudoFirst == NULL) { |
504 return pFirst; | 504 return pFirst; |
505 } else { | 505 } else { |
506 pPersudoLast->SetNext(pFirst); | 506 pPersudoLast->SetNext(pFirst); |
507 return pPersudoFirst; | 507 return pPersudoFirst; |
508 } | 508 } |
509 } | 509 } |
OLD | NEW |