| 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> |
| 10 |
| 9 #include "xfa/fde/css/fde_cssdatatable.h" | 11 #include "xfa/fde/css/fde_cssdatatable.h" |
| 10 #include "xfa/fde/css/fde_csssyntax.h" | 12 #include "xfa/fde/css/fde_csssyntax.h" |
| 11 #include "xfa/fgas/crt/fgas_codepage.h" | 13 #include "xfa/fgas/crt/fgas_codepage.h" |
| 12 | 14 |
| 13 IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadHTMLStandardStyleSheet() { | 15 IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadHTMLStandardStyleSheet() { |
| 14 static const FX_WCHAR s_pStyle[] = | 16 static const FX_WCHAR s_pStyle[] = |
| 15 L"html,address,blockquote,body,dd,div,dl,dt,fieldset,form,frame,frameset," | 17 L"html,address,blockquote,body,dd,div,dl,dt,fieldset,form,frame,frameset," |
| 16 L"h1,h2,h3,h4,h5,h6,noframes,ol,p,ul,center,dir,hr,menu,pre{display:" | 18 L"h1,h2,h3,h4,h5,h6,noframes,ol,p,ul,center,dir,hr,menu,pre{display:" |
| 17 L"block}" | 19 L"block}" |
| 18 L"li{display:list-item}head{display:none}table{display:table}tr{display:" | 20 L"li{display:list-item}head{display:none}table{display:table}tr{display:" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 delete this; | 115 delete this; |
| 114 } | 116 } |
| 115 return dwRefCount; | 117 return dwRefCount; |
| 116 } | 118 } |
| 117 int32_t CFDE_CSSStyleSheet::CountRules() const { | 119 int32_t CFDE_CSSStyleSheet::CountRules() const { |
| 118 return m_RuleArray.GetSize(); | 120 return m_RuleArray.GetSize(); |
| 119 } | 121 } |
| 120 IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { | 122 IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { |
| 121 return m_RuleArray.GetAt(index); | 123 return m_RuleArray.GetAt(index); |
| 122 } | 124 } |
| 125 |
| 123 FX_BOOL CFDE_CSSStyleSheet::LoadFromStream(const CFX_WideString& szUrl, | 126 FX_BOOL CFDE_CSSStyleSheet::LoadFromStream(const CFX_WideString& szUrl, |
| 124 IFX_Stream* pStream, | 127 IFX_Stream* pStream, |
| 125 uint16_t wCodePage) { | 128 uint16_t wCodePage) { |
| 126 CFDE_CSSSyntaxParser* pSyntax = new CFDE_CSSSyntaxParser; | 129 std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser); |
| 127 if (pStream->GetCodePage() != wCodePage) { | 130 if (pStream->GetCodePage() != wCodePage) |
| 128 pStream->SetCodePage(wCodePage); | 131 pStream->SetCodePage(wCodePage); |
| 129 } | 132 |
| 130 FX_BOOL bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax); | 133 FX_BOOL bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax.get()); |
| 131 pSyntax->Release(); | |
| 132 m_wCodePage = wCodePage; | 134 m_wCodePage = wCodePage; |
| 133 m_szUrl = szUrl; | 135 m_szUrl = szUrl; |
| 134 return bRet; | 136 return bRet; |
| 135 } | 137 } |
| 138 |
| 136 FX_BOOL CFDE_CSSStyleSheet::LoadFromBuffer(const CFX_WideString& szUrl, | 139 FX_BOOL CFDE_CSSStyleSheet::LoadFromBuffer(const CFX_WideString& szUrl, |
| 137 const FX_WCHAR* pBuffer, | 140 const FX_WCHAR* pBuffer, |
| 138 int32_t iBufSize, | 141 int32_t iBufSize, |
| 139 uint16_t wCodePage) { | 142 uint16_t wCodePage) { |
| 140 ASSERT(pBuffer && iBufSize > 0); | 143 ASSERT(pBuffer && iBufSize > 0); |
| 141 | 144 std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser); |
| 142 CFDE_CSSSyntaxParser* pSyntax = new CFDE_CSSSyntaxParser; | 145 FX_BOOL bRet = |
| 143 FX_BOOL bRet = pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax); | 146 pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get()); |
| 144 pSyntax->Release(); | |
| 145 m_wCodePage = wCodePage; | 147 m_wCodePage = wCodePage; |
| 146 m_szUrl = szUrl; | 148 m_szUrl = szUrl; |
| 147 return bRet; | 149 return bRet; |
| 148 } | 150 } |
| 151 |
| 149 FX_BOOL CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { | 152 FX_BOOL CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { |
| 150 Reset(); | 153 Reset(); |
| 151 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Static, 1024, 0); | 154 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Static, 1024, 0); |
| 152 FDE_CSSSYNTAXSTATUS eStatus; | 155 FDE_CSSSYNTAXSTATUS eStatus; |
| 153 do { | 156 do { |
| 154 switch (eStatus = pSyntax->DoSyntaxParse()) { | 157 switch (eStatus = pSyntax->DoSyntaxParse()) { |
| 155 case FDE_CSSSYNTAXSTATUS_StyleRule: | 158 case FDE_CSSSYNTAXSTATUS_StyleRule: |
| 156 eStatus = LoadStyleRule(pSyntax, m_RuleArray); | 159 eStatus = LoadStyleRule(pSyntax, m_RuleArray); |
| 157 break; | 160 break; |
| 158 case FDE_CSSSYNTAXSTATUS_MediaRule: | 161 case FDE_CSSSYNTAXSTATUS_MediaRule: |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 return NULL; | 496 return NULL; |
| 494 } | 497 } |
| 495 } | 498 } |
| 496 if (pPersudoFirst == NULL) { | 499 if (pPersudoFirst == NULL) { |
| 497 return pFirst; | 500 return pFirst; |
| 498 } else { | 501 } else { |
| 499 pPersudoLast->SetNext(pFirst); | 502 pPersudoLast->SetNext(pFirst); |
| 500 return pPersudoFirst; | 503 return pPersudoFirst; |
| 501 } | 504 } |
| 502 } | 505 } |
| OLD | NEW |