Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Side by Side Diff: xfa/fde/css/fde_cssstylesheet.cpp

Issue 2208423002: Use smart pointers for class owned pointers under xfa/fde (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: one more change Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/css/fde_cssstylesheet.h ('k') | xfa/fde/fde_gedevice.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 pStyleSheet->Release(); 71 pStyleSheet->Release();
72 pStyleSheet = nullptr; 72 pStyleSheet = nullptr;
73 } 73 }
74 return pStyleSheet; 74 return pStyleSheet;
75 } 75 }
76 76
77 CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList) 77 CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList)
78 : m_wCodePage(FX_CODEPAGE_UTF8), 78 : m_wCodePage(FX_CODEPAGE_UTF8),
79 m_wRefCount(1), 79 m_wRefCount(1),
80 m_dwMediaList(dwMediaList), 80 m_dwMediaList(dwMediaList),
81 m_pAllocator(nullptr),
82 m_RuleArray(100) { 81 m_RuleArray(100) {
83 ASSERT(m_dwMediaList > 0); 82 ASSERT(m_dwMediaList > 0);
84 } 83 }
85 84
86 CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() { 85 CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() {
87 Reset(); 86 Reset();
88 } 87 }
89 88
90 void CFDE_CSSStyleSheet::Reset() { 89 void CFDE_CSSStyleSheet::Reset() {
91 for (int32_t i = m_RuleArray.GetSize() - 1; i >= 0; --i) { 90 for (int32_t i = m_RuleArray.GetSize() - 1; i >= 0; --i) {
92 IFDE_CSSRule* pRule = m_RuleArray.GetAt(i); 91 IFDE_CSSRule* pRule = m_RuleArray.GetAt(i);
93 switch (pRule->GetType()) { 92 switch (pRule->GetType()) {
94 case FDE_CSSRULETYPE_Style: 93 case FDE_CSSRULETYPE_Style:
95 static_cast<CFDE_CSSStyleRule*>(pRule)->~CFDE_CSSStyleRule(); 94 static_cast<CFDE_CSSStyleRule*>(pRule)->~CFDE_CSSStyleRule();
96 break; 95 break;
97 case FDE_CSSRULETYPE_Media: 96 case FDE_CSSRULETYPE_Media:
98 static_cast<CFDE_CSSMediaRule*>(pRule)->~CFDE_CSSMediaRule(); 97 static_cast<CFDE_CSSMediaRule*>(pRule)->~CFDE_CSSMediaRule();
99 break; 98 break;
100 case FDE_CSSRULETYPE_FontFace: 99 case FDE_CSSRULETYPE_FontFace:
101 static_cast<CFDE_CSSFontFaceRule*>(pRule)->~CFDE_CSSFontFaceRule(); 100 static_cast<CFDE_CSSFontFaceRule*>(pRule)->~CFDE_CSSFontFaceRule();
102 break; 101 break;
103 default: 102 default:
104 ASSERT(FALSE); 103 ASSERT(FALSE);
105 break; 104 break;
106 } 105 }
107 } 106 }
108 m_RuleArray.RemoveAll(FALSE); 107 m_RuleArray.RemoveAll(FALSE);
109 m_Selectors.RemoveAll(); 108 m_Selectors.RemoveAll();
110 m_StringCache.clear(); 109 m_StringCache.clear();
111 delete m_pAllocator; 110 m_pAllocator.reset();
112 m_pAllocator = nullptr;
113 } 111 }
114 112
115 uint32_t CFDE_CSSStyleSheet::Retain() { 113 uint32_t CFDE_CSSStyleSheet::Retain() {
116 return ++m_wRefCount; 114 return ++m_wRefCount;
117 } 115 }
118 116
119 uint32_t CFDE_CSSStyleSheet::Release() { 117 uint32_t CFDE_CSSStyleSheet::Release() {
120 uint32_t dwRefCount = --m_wRefCount; 118 uint32_t dwRefCount = --m_wRefCount;
121 if (dwRefCount == 0) { 119 if (dwRefCount == 0) {
122 delete this; 120 delete this;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 LoadStyleRule(pSyntax, pMediaRule->GetArray()); 219 LoadStyleRule(pSyntax, pMediaRule->GetArray());
222 if (eStatus < FDE_CSSSYNTAXSTATUS_None) { 220 if (eStatus < FDE_CSSSYNTAXSTATUS_None) {
223 return eStatus; 221 return eStatus;
224 } 222 }
225 } else { 223 } else {
226 SkipRuleSet(pSyntax); 224 SkipRuleSet(pSyntax);
227 } 225 }
228 break; 226 break;
229 case FDE_CSSSYNTAXSTATUS_DeclOpen: 227 case FDE_CSSSYNTAXSTATUS_DeclOpen:
230 if ((dwMediaList & m_dwMediaList) > 0 && !pMediaRule) { 228 if ((dwMediaList & m_dwMediaList) > 0 && !pMediaRule) {
231 pMediaRule = 229 pMediaRule = FXTARGET_NewWith(m_pAllocator.get())
232 FXTARGET_NewWith(m_pAllocator) CFDE_CSSMediaRule(dwMediaList); 230 CFDE_CSSMediaRule(dwMediaList);
233 m_RuleArray.Add(pMediaRule); 231 m_RuleArray.Add(pMediaRule);
234 } 232 }
235 break; 233 break;
236 case FDE_CSSSYNTAXSTATUS_DeclClose: 234 case FDE_CSSSYNTAXSTATUS_DeclClose:
237 return FDE_CSSSYNTAXSTATUS_None; 235 return FDE_CSSSYNTAXSTATUS_None;
238 FDE_CSSSWITCHDEFAULTS(); 236 FDE_CSSSWITCHDEFAULTS();
239 } 237 }
240 } 238 }
241 } 239 }
242 240
243 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( 241 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule(
244 CFDE_CSSSyntaxParser* pSyntax, 242 CFDE_CSSSyntaxParser* pSyntax,
245 CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray) { 243 CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray) {
246 m_Selectors.RemoveAt(0, m_Selectors.GetSize()); 244 m_Selectors.RemoveAt(0, m_Selectors.GetSize());
247 CFDE_CSSStyleRule* pStyleRule = nullptr; 245 CFDE_CSSStyleRule* pStyleRule = nullptr;
248 const FX_WCHAR* pszValue = nullptr; 246 const FX_WCHAR* pszValue = nullptr;
249 int32_t iValueLen = 0; 247 int32_t iValueLen = 0;
250 FDE_CSSPROPERTYARGS propertyArgs; 248 FDE_CSSPROPERTYARGS propertyArgs;
251 propertyArgs.pStaticStore = m_pAllocator; 249 propertyArgs.pStaticStore = m_pAllocator.get();
252 propertyArgs.pStringCache = &m_StringCache; 250 propertyArgs.pStringCache = &m_StringCache;
253 propertyArgs.pProperty = nullptr; 251 propertyArgs.pProperty = nullptr;
254 CFX_WideString wsName; 252 CFX_WideString wsName;
255 for (;;) { 253 for (;;) {
256 switch (pSyntax->DoSyntaxParse()) { 254 switch (pSyntax->DoSyntaxParse()) {
257 case FDE_CSSSYNTAXSTATUS_Selector: { 255 case FDE_CSSSYNTAXSTATUS_Selector: {
258 pszValue = pSyntax->GetCurrentString(iValueLen); 256 pszValue = pSyntax->GetCurrentString(iValueLen);
259 CFDE_CSSSelector* pSelector = 257 CFDE_CSSSelector* pSelector = CFDE_CSSSelector::FromString(
260 CFDE_CSSSelector::FromString(m_pAllocator, pszValue, iValueLen); 258 m_pAllocator.get(), pszValue, iValueLen);
261 if (pSelector) 259 if (pSelector)
262 m_Selectors.Add(pSelector); 260 m_Selectors.Add(pSelector);
263 } break; 261 } break;
264 case FDE_CSSSYNTAXSTATUS_PropertyName: 262 case FDE_CSSSYNTAXSTATUS_PropertyName:
265 pszValue = pSyntax->GetCurrentString(iValueLen); 263 pszValue = pSyntax->GetCurrentString(iValueLen);
266 propertyArgs.pProperty = 264 propertyArgs.pProperty =
267 FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); 265 FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen));
268 if (!propertyArgs.pProperty) 266 if (!propertyArgs.pProperty)
269 wsName = CFX_WideStringC(pszValue, iValueLen); 267 wsName = CFX_WideStringC(pszValue, iValueLen);
270 break; 268 break;
271 case FDE_CSSSYNTAXSTATUS_PropertyValue: 269 case FDE_CSSSYNTAXSTATUS_PropertyValue:
272 if (propertyArgs.pProperty) { 270 if (propertyArgs.pProperty) {
273 pszValue = pSyntax->GetCurrentString(iValueLen); 271 pszValue = pSyntax->GetCurrentString(iValueLen);
274 if (iValueLen > 0) { 272 if (iValueLen > 0) {
275 pStyleRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, 273 pStyleRule->GetDeclImp().AddProperty(&propertyArgs, pszValue,
276 iValueLen); 274 iValueLen);
277 } 275 }
278 } else if (iValueLen > 0) { 276 } else if (iValueLen > 0) {
279 pszValue = pSyntax->GetCurrentString(iValueLen); 277 pszValue = pSyntax->GetCurrentString(iValueLen);
280 if (iValueLen > 0) { 278 if (iValueLen > 0) {
281 pStyleRule->GetDeclImp().AddProperty(&propertyArgs, wsName.c_str(), 279 pStyleRule->GetDeclImp().AddProperty(&propertyArgs, wsName.c_str(),
282 wsName.GetLength(), pszValue, 280 wsName.GetLength(), pszValue,
283 iValueLen); 281 iValueLen);
284 } 282 }
285 } 283 }
286 break; 284 break;
287 case FDE_CSSSYNTAXSTATUS_DeclOpen: 285 case FDE_CSSSYNTAXSTATUS_DeclOpen:
288 if (!pStyleRule && m_Selectors.GetSize() > 0) { 286 if (!pStyleRule && m_Selectors.GetSize() > 0) {
289 pStyleRule = FXTARGET_NewWith(m_pAllocator) CFDE_CSSStyleRule; 287 pStyleRule = FXTARGET_NewWith(m_pAllocator.get()) CFDE_CSSStyleRule;
290 pStyleRule->SetSelector(m_pAllocator, m_Selectors); 288 pStyleRule->SetSelector(m_pAllocator.get(), m_Selectors);
291 ruleArray.Add(pStyleRule); 289 ruleArray.Add(pStyleRule);
292 } else { 290 } else {
293 SkipRuleSet(pSyntax); 291 SkipRuleSet(pSyntax);
294 return FDE_CSSSYNTAXSTATUS_None; 292 return FDE_CSSSYNTAXSTATUS_None;
295 } 293 }
296 break; 294 break;
297 case FDE_CSSSYNTAXSTATUS_DeclClose: 295 case FDE_CSSSYNTAXSTATUS_DeclClose:
298 if (pStyleRule && !pStyleRule->GetDeclImp().GetStartPosition()) { 296 if (pStyleRule && !pStyleRule->GetDeclImp().GetStartPosition()) {
299 pStyleRule->~CFDE_CSSStyleRule(); 297 pStyleRule->~CFDE_CSSStyleRule();
300 ruleArray.RemoveLast(1); 298 ruleArray.RemoveLast(1);
301 } 299 }
302 return FDE_CSSSYNTAXSTATUS_None; 300 return FDE_CSSSYNTAXSTATUS_None;
303 FDE_CSSSWITCHDEFAULTS(); 301 FDE_CSSSWITCHDEFAULTS();
304 } 302 }
305 } 303 }
306 } 304 }
307 305
308 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( 306 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule(
309 CFDE_CSSSyntaxParser* pSyntax, 307 CFDE_CSSSyntaxParser* pSyntax,
310 CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray) { 308 CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray) {
311 CFDE_CSSFontFaceRule* pFontFaceRule = nullptr; 309 CFDE_CSSFontFaceRule* pFontFaceRule = nullptr;
312 const FX_WCHAR* pszValue = nullptr; 310 const FX_WCHAR* pszValue = nullptr;
313 int32_t iValueLen = 0; 311 int32_t iValueLen = 0;
314 FDE_CSSPROPERTYARGS propertyArgs; 312 FDE_CSSPROPERTYARGS propertyArgs;
315 propertyArgs.pStaticStore = m_pAllocator; 313 propertyArgs.pStaticStore = m_pAllocator.get();
316 propertyArgs.pStringCache = &m_StringCache; 314 propertyArgs.pStringCache = &m_StringCache;
317 propertyArgs.pProperty = nullptr; 315 propertyArgs.pProperty = nullptr;
318 for (;;) { 316 for (;;) {
319 switch (pSyntax->DoSyntaxParse()) { 317 switch (pSyntax->DoSyntaxParse()) {
320 case FDE_CSSSYNTAXSTATUS_PropertyName: 318 case FDE_CSSSYNTAXSTATUS_PropertyName:
321 pszValue = pSyntax->GetCurrentString(iValueLen); 319 pszValue = pSyntax->GetCurrentString(iValueLen);
322 propertyArgs.pProperty = 320 propertyArgs.pProperty =
323 FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); 321 FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen));
324 break; 322 break;
325 case FDE_CSSSYNTAXSTATUS_PropertyValue: 323 case FDE_CSSSYNTAXSTATUS_PropertyValue:
326 if (propertyArgs.pProperty) { 324 if (propertyArgs.pProperty) {
327 pszValue = pSyntax->GetCurrentString(iValueLen); 325 pszValue = pSyntax->GetCurrentString(iValueLen);
328 if (iValueLen > 0) { 326 if (iValueLen > 0) {
329 pFontFaceRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, 327 pFontFaceRule->GetDeclImp().AddProperty(&propertyArgs, pszValue,
330 iValueLen); 328 iValueLen);
331 } 329 }
332 } 330 }
333 break; 331 break;
334 case FDE_CSSSYNTAXSTATUS_DeclOpen: 332 case FDE_CSSSYNTAXSTATUS_DeclOpen:
335 if (!pFontFaceRule) { 333 if (!pFontFaceRule) {
336 pFontFaceRule = FXTARGET_NewWith(m_pAllocator) CFDE_CSSFontFaceRule; 334 pFontFaceRule =
335 FXTARGET_NewWith(m_pAllocator.get()) CFDE_CSSFontFaceRule;
337 ruleArray.Add(pFontFaceRule); 336 ruleArray.Add(pFontFaceRule);
338 } 337 }
339 break; 338 break;
340 case FDE_CSSSYNTAXSTATUS_DeclClose: 339 case FDE_CSSSYNTAXSTATUS_DeclClose:
341 return FDE_CSSSYNTAXSTATUS_None; 340 return FDE_CSSSYNTAXSTATUS_None;
342 FDE_CSSSWITCHDEFAULTS(); 341 FDE_CSSSWITCHDEFAULTS();
343 } 342 }
344 } 343 }
345 } 344 }
346 345
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if (!pPersudoFirst) 578 if (!pPersudoFirst)
580 return pFirst; 579 return pFirst;
581 580
582 pPersudoLast->SetNext(pFirst); 581 pPersudoLast->SetNext(pFirst);
583 return pPersudoFirst; 582 return pPersudoFirst;
584 } 583 }
585 584
586 CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() { 585 CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() {
587 return &m_Declaration; 586 return &m_Declaration;
588 } 587 }
OLDNEW
« no previous file with comments | « xfa/fde/css/fde_cssstylesheet.h ('k') | xfa/fde/fde_gedevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698