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 <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 case FDE_CSSRULETYPE_Style: | 93 case FDE_CSSRULETYPE_Style: |
94 static_cast<CFDE_CSSStyleRule*>(pRule)->~CFDE_CSSStyleRule(); | 94 static_cast<CFDE_CSSStyleRule*>(pRule)->~CFDE_CSSStyleRule(); |
95 break; | 95 break; |
96 case FDE_CSSRULETYPE_Media: | 96 case FDE_CSSRULETYPE_Media: |
97 static_cast<CFDE_CSSMediaRule*>(pRule)->~CFDE_CSSMediaRule(); | 97 static_cast<CFDE_CSSMediaRule*>(pRule)->~CFDE_CSSMediaRule(); |
98 break; | 98 break; |
99 case FDE_CSSRULETYPE_FontFace: | 99 case FDE_CSSRULETYPE_FontFace: |
100 static_cast<CFDE_CSSFontFaceRule*>(pRule)->~CFDE_CSSFontFaceRule(); | 100 static_cast<CFDE_CSSFontFaceRule*>(pRule)->~CFDE_CSSFontFaceRule(); |
101 break; | 101 break; |
102 default: | 102 default: |
103 ASSERT(FALSE); | 103 ASSERT(false); |
104 break; | 104 break; |
105 } | 105 } |
106 } | 106 } |
107 m_RuleArray.RemoveAll(FALSE); | 107 m_RuleArray.RemoveAll(false); |
108 m_Selectors.RemoveAll(); | 108 m_Selectors.RemoveAll(); |
109 m_StringCache.clear(); | 109 m_StringCache.clear(); |
110 m_pAllocator.reset(); | 110 m_pAllocator.reset(); |
111 } | 111 } |
112 | 112 |
113 uint32_t CFDE_CSSStyleSheet::Retain() { | 113 uint32_t CFDE_CSSStyleSheet::Retain() { |
114 return ++m_wRefCount; | 114 return ++m_wRefCount; |
115 } | 115 } |
116 | 116 |
117 uint32_t CFDE_CSSStyleSheet::Release() { | 117 uint32_t CFDE_CSSStyleSheet::Release() { |
118 uint32_t dwRefCount = --m_wRefCount; | 118 uint32_t dwRefCount = --m_wRefCount; |
119 if (dwRefCount == 0) { | 119 if (dwRefCount == 0) { |
120 delete this; | 120 delete this; |
121 } | 121 } |
122 return dwRefCount; | 122 return dwRefCount; |
123 } | 123 } |
124 | 124 |
125 FX_BOOL CFDE_CSSStyleSheet::GetUrl(CFX_WideString& szUrl) { | 125 bool CFDE_CSSStyleSheet::GetUrl(CFX_WideString& szUrl) { |
126 szUrl = m_szUrl; | 126 szUrl = m_szUrl; |
127 return szUrl.GetLength() > 0; | 127 return szUrl.GetLength() > 0; |
128 } | 128 } |
129 | 129 |
130 uint32_t CFDE_CSSStyleSheet::GetMediaList() const { | 130 uint32_t CFDE_CSSStyleSheet::GetMediaList() const { |
131 return m_dwMediaList; | 131 return m_dwMediaList; |
132 } | 132 } |
133 | 133 |
134 uint16_t CFDE_CSSStyleSheet::GetCodePage() const { | 134 uint16_t CFDE_CSSStyleSheet::GetCodePage() const { |
135 return m_wCodePage; | 135 return m_wCodePage; |
136 } | 136 } |
137 | 137 |
138 int32_t CFDE_CSSStyleSheet::CountRules() const { | 138 int32_t CFDE_CSSStyleSheet::CountRules() const { |
139 return m_RuleArray.GetSize(); | 139 return m_RuleArray.GetSize(); |
140 } | 140 } |
141 | 141 |
142 IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { | 142 IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { |
143 return m_RuleArray.GetAt(index); | 143 return m_RuleArray.GetAt(index); |
144 } | 144 } |
145 | 145 |
146 FX_BOOL CFDE_CSSStyleSheet::LoadFromStream(const CFX_WideString& szUrl, | 146 bool CFDE_CSSStyleSheet::LoadFromStream(const CFX_WideString& szUrl, |
147 IFX_Stream* pStream, | 147 IFX_Stream* pStream, |
148 uint16_t wCodePage) { | 148 uint16_t wCodePage) { |
149 std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser); | 149 std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser); |
150 if (pStream->GetCodePage() != wCodePage) | 150 if (pStream->GetCodePage() != wCodePage) |
151 pStream->SetCodePage(wCodePage); | 151 pStream->SetCodePage(wCodePage); |
152 | 152 |
153 FX_BOOL bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax.get()); | 153 bool bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax.get()); |
154 m_wCodePage = wCodePage; | 154 m_wCodePage = wCodePage; |
155 m_szUrl = szUrl; | 155 m_szUrl = szUrl; |
156 return bRet; | 156 return bRet; |
157 } | 157 } |
158 | 158 |
159 FX_BOOL CFDE_CSSStyleSheet::LoadFromBuffer(const CFX_WideString& szUrl, | 159 bool CFDE_CSSStyleSheet::LoadFromBuffer(const CFX_WideString& szUrl, |
160 const FX_WCHAR* pBuffer, | 160 const FX_WCHAR* pBuffer, |
161 int32_t iBufSize, | 161 int32_t iBufSize, |
162 uint16_t wCodePage) { | 162 uint16_t wCodePage) { |
163 ASSERT(pBuffer && iBufSize > 0); | 163 ASSERT(pBuffer && iBufSize > 0); |
164 std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser); | 164 std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser); |
165 FX_BOOL bRet = | 165 bool bRet = pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get()); |
166 pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get()); | |
167 m_wCodePage = wCodePage; | 166 m_wCodePage = wCodePage; |
168 m_szUrl = szUrl; | 167 m_szUrl = szUrl; |
169 return bRet; | 168 return bRet; |
170 } | 169 } |
171 | 170 |
172 FX_BOOL CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { | 171 bool CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { |
173 Reset(); | 172 Reset(); |
174 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Static, 1024, 0); | 173 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Static, 1024, 0); |
175 FDE_CSSSYNTAXSTATUS eStatus; | 174 FDE_CSSSYNTAXSTATUS eStatus; |
176 do { | 175 do { |
177 switch (eStatus = pSyntax->DoSyntaxParse()) { | 176 switch (eStatus = pSyntax->DoSyntaxParse()) { |
178 case FDE_CSSSYNTAXSTATUS_StyleRule: | 177 case FDE_CSSSYNTAXSTATUS_StyleRule: |
179 eStatus = LoadStyleRule(pSyntax, m_RuleArray); | 178 eStatus = LoadStyleRule(pSyntax, m_RuleArray); |
180 break; | 179 break; |
181 case FDE_CSSSYNTAXSTATUS_MediaRule: | 180 case FDE_CSSSYNTAXSTATUS_MediaRule: |
182 eStatus = LoadMediaRule(pSyntax); | 181 eStatus = LoadMediaRule(pSyntax); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 : m_dwMediaList(dwMediaList), m_RuleArray(100) {} | 407 : m_dwMediaList(dwMediaList), m_RuleArray(100) {} |
409 | 408 |
410 CFDE_CSSMediaRule::~CFDE_CSSMediaRule() { | 409 CFDE_CSSMediaRule::~CFDE_CSSMediaRule() { |
411 for (int32_t i = m_RuleArray.GetSize() - 1; i >= 0; --i) { | 410 for (int32_t i = m_RuleArray.GetSize() - 1; i >= 0; --i) { |
412 IFDE_CSSRule* pRule = m_RuleArray.GetAt(i); | 411 IFDE_CSSRule* pRule = m_RuleArray.GetAt(i); |
413 switch (pRule->GetType()) { | 412 switch (pRule->GetType()) { |
414 case FDE_CSSRULETYPE_Style: | 413 case FDE_CSSRULETYPE_Style: |
415 ((CFDE_CSSStyleRule*)pRule)->~CFDE_CSSStyleRule(); | 414 ((CFDE_CSSStyleRule*)pRule)->~CFDE_CSSStyleRule(); |
416 break; | 415 break; |
417 default: | 416 default: |
418 ASSERT(FALSE); | 417 ASSERT(false); |
419 break; | 418 break; |
420 } | 419 } |
421 } | 420 } |
422 } | 421 } |
423 | 422 |
424 uint32_t CFDE_CSSMediaRule::GetMediaList() const { | 423 uint32_t CFDE_CSSMediaRule::GetMediaList() const { |
425 return m_dwMediaList; | 424 return m_dwMediaList; |
426 } | 425 } |
427 | 426 |
428 int32_t CFDE_CSSMediaRule::CountRules() const { | 427 int32_t CFDE_CSSMediaRule::CountRules() const { |
429 return m_RuleArray.GetSize(); | 428 return m_RuleArray.GetSize(); |
430 } | 429 } |
431 | 430 |
432 IFDE_CSSRule* CFDE_CSSMediaRule::GetRule(int32_t index) { | 431 IFDE_CSSRule* CFDE_CSSMediaRule::GetRule(int32_t index) { |
433 return m_RuleArray.GetAt(index); | 432 return m_RuleArray.GetAt(index); |
434 } | 433 } |
435 | 434 |
436 FX_BOOL FDE_IsCSSChar(FX_WCHAR wch) { | 435 bool FDE_IsCSSChar(FX_WCHAR wch) { |
437 return (wch >= 'a' && wch <= 'z') || (wch >= 'A' && wch <= 'Z'); | 436 return (wch >= 'a' && wch <= 'z') || (wch >= 'A' && wch <= 'Z'); |
438 } | 437 } |
439 | 438 |
440 int32_t FDE_GetCSSPersudoLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { | 439 int32_t FDE_GetCSSPersudoLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { |
441 ASSERT(*psz == ':'); | 440 ASSERT(*psz == ':'); |
442 const FX_WCHAR* pStart = psz; | 441 const FX_WCHAR* pStart = psz; |
443 while (psz < pEnd) { | 442 while (psz < pEnd) { |
444 FX_WCHAR wch = *psz; | 443 FX_WCHAR wch = *psz; |
445 if (FDE_IsCSSChar(wch) || wch == ':') { | 444 if (FDE_IsCSSChar(wch) || wch == ':') { |
446 ++psz; | 445 ++psz; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 if (!pPersudoFirst) | 577 if (!pPersudoFirst) |
579 return pFirst; | 578 return pFirst; |
580 | 579 |
581 pPersudoLast->SetNext(pFirst); | 580 pPersudoLast->SetNext(pFirst); |
582 return pPersudoFirst; | 581 return pPersudoFirst; |
583 } | 582 } |
584 | 583 |
585 CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() { | 584 CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() { |
586 return &m_Declaration; | 585 return &m_Declaration; |
587 } | 586 } |
OLD | NEW |