diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-01-17 16:35:16 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-01-17 22:04:45 +0000 |
commit | 3285c56b0dd6b83c2fcc8b8f714324185a09c920 (patch) | |
tree | 1da61ece5e7ca7f8a99cdb00ad0f5f41e2020afb /xfa/fde/css/fde_cssstyleselector.cpp | |
parent | da489976371eb928d8b4d004744667fdf82b90d4 (diff) | |
download | pdfium-3285c56b0dd6b83c2fcc8b8f714324185a09c920.tar.xz |
Start CSS parser unit tests
Start adding unit tests for the css parser. Fixup memory
leaks that are exposed by the tests.
Change-Id: Id863d9cd5f13ab82626bc7b945de925253c88d43
Reviewed-on: https://pdfium-review.googlesource.com/2180
Reviewed-by: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde/css/fde_cssstyleselector.cpp')
-rw-r--r-- | xfa/fde/css/fde_cssstyleselector.cpp | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp index 5e981d96eb..e6ee18f245 100644 --- a/xfa/fde/css/fde_cssstyleselector.cpp +++ b/xfa/fde/css/fde_cssstyleselector.cpp @@ -280,14 +280,15 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( int32_t iDeclCount, CFDE_CSSComputedStyle* pDestStyle) { CFDE_CSSComputedStyle* pComputedStyle = pDestStyle; - CFDE_CSSValue* pVal; - bool bImportant; + int32_t i; if (bPriority) { CFDE_CSSValue* pLastest = nullptr; CFDE_CSSValue* pImportant = nullptr; for (i = 0; i < iDeclCount; ++i) { - pVal = ppDeclArray[i]->GetProperty(FDE_CSSProperty::FontSize, bImportant); + bool bImportant; + CFDE_CSSValue* pVal = + ppDeclArray[i]->GetProperty(FDE_CSSProperty::FontSize, bImportant); if (!pVal) continue; @@ -304,39 +305,33 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( } else { CFX_ArrayTemplate<CFDE_CSSDeclaration*> importants; const CFDE_CSSDeclaration* pDecl = nullptr; - FDE_CSSProperty eProp; - FX_POSITION pos; + for (i = 0; i < iDeclCount; ++i) { pDecl = ppDeclArray[i]; - pos = pDecl->GetStartPosition(); - while (pos) { - pDecl->GetNextProperty(pos, eProp, pVal, bImportant); - if (eProp == FDE_CSSProperty::FontSize) { + for (auto it = pDecl->begin(); it != pDecl->end(); it++) { + if ((*it)->eProperty == FDE_CSSProperty::FontSize) continue; - } else if (!bImportant) { - ApplyProperty(eProp, pVal, pComputedStyle); + if (!(*it)->bImportant) { + ApplyProperty((*it)->eProperty, (*it)->pValue.Get(), pComputedStyle); } else if (importants.GetSize() == 0 || importants[importants.GetUpperBound()] != pDecl) { importants.Add(const_cast<CFDE_CSSDeclaration*>(pDecl)); } } } + iDeclCount = importants.GetSize(); for (i = 0; i < iDeclCount; ++i) { pDecl = importants[i]; - pos = pDecl->GetStartPosition(); - while (pos) { - pDecl->GetNextProperty(pos, eProp, pVal, bImportant); - if (bImportant && eProp != FDE_CSSProperty::FontSize) { - ApplyProperty(eProp, pVal, pComputedStyle); - } + + for (auto it = pDecl->begin(); it != pDecl->end(); it++) { + if ((*it)->bImportant && (*it)->eProperty != FDE_CSSProperty::FontSize) + ApplyProperty((*it)->eProperty, (*it)->pValue.Get(), pComputedStyle); } } - CFX_WideString wsName, wsValue; - pos = pDecl->GetStartCustom(); - while (pos) { - pDecl->GetNextCustom(pos, wsName, wsValue); - pComputedStyle->AddCustomStyle(wsName, wsValue); + + for (auto it = pDecl->custom_begin(); it != pDecl->custom_end(); it++) { + pComputedStyle->AddCustomStyle((*it)->pwsName, (*it)->pwsValue); } } } |