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_cssstylesheet.h | |
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_cssstylesheet.h')
-rw-r--r-- | xfa/fde/css/fde_cssstylesheet.h | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/xfa/fde/css/fde_cssstylesheet.h b/xfa/fde/css/fde_cssstylesheet.h index 8cedb76526..7acccd5776 100644 --- a/xfa/fde/css/fde_cssstylesheet.h +++ b/xfa/fde/css/fde_cssstylesheet.h @@ -9,6 +9,8 @@ #include <memory> #include <unordered_map> +#include <utility> +#include <vector> #include "core/fxcrt/fx_ext.h" #include "xfa/fde/css/cfde_cssrule.h" @@ -18,40 +20,46 @@ class CFDE_CSSSyntaxParser; class CFDE_CSSSelector { public: + static std::unique_ptr<CFDE_CSSSelector> FromString(const FX_WCHAR* psz, + int32_t iLen); + CFDE_CSSSelector(FDE_CSSSelectorType eType, const FX_WCHAR* psz, int32_t iLen, bool bIgnoreCase); + ~CFDE_CSSSelector(); - virtual FDE_CSSSelectorType GetType() const; - virtual uint32_t GetNameHash() const; - virtual CFDE_CSSSelector* GetNextSelector() const; - - static CFDE_CSSSelector* FromString(const FX_WCHAR* psz, int32_t iLen); + FDE_CSSSelectorType GetType() const; + uint32_t GetNameHash() const; + CFDE_CSSSelector* GetNextSelector() const; + std::unique_ptr<CFDE_CSSSelector> ReleaseNextSelector(); - void SetNext(CFDE_CSSSelector* pNext) { m_pNext = pNext; } + void SetNext(std::unique_ptr<CFDE_CSSSelector> pNext) { + m_pNext = std::move(pNext); + } protected: void SetType(FDE_CSSSelectorType eType) { m_eType = eType; } FDE_CSSSelectorType m_eType; uint32_t m_dwHash; - CFDE_CSSSelector* m_pNext; + std::unique_ptr<CFDE_CSSSelector> m_pNext; }; class CFDE_CSSStyleRule : public CFDE_CSSRule { public: CFDE_CSSStyleRule(); + ~CFDE_CSSStyleRule() override; int32_t CountSelectorLists() const; CFDE_CSSSelector* GetSelectorList(int32_t index) const; CFDE_CSSDeclaration* GetDeclaration(); CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } - void SetSelector(const CFX_ArrayTemplate<CFDE_CSSSelector*>& list); + void SetSelector(const std::vector<std::unique_ptr<CFDE_CSSSelector>>& list); private: CFDE_CSSDeclaration m_Declaration; - CFDE_CSSSelector** m_ppSelector; + std::vector<CFDE_CSSSelector*> m_ppSelector; // Owned by the stylessheet. int32_t m_iSelectors; }; @@ -64,11 +72,11 @@ class CFDE_CSSMediaRule : public CFDE_CSSRule { int32_t CountRules() const; CFDE_CSSRule* GetRule(int32_t index); - CFX_MassArrayTemplate<CFDE_CSSRule*>& GetArray() { return m_RuleArray; } + std::vector<std::unique_ptr<CFDE_CSSRule>>& GetArray() { return m_RuleArray; } protected: uint32_t m_dwMediaList; - CFX_MassArrayTemplate<CFDE_CSSRule*> m_RuleArray; + std::vector<std::unique_ptr<CFDE_CSSRule>> m_RuleArray; }; class CFDE_CSSFontFaceRule : public CFDE_CSSRule { @@ -104,21 +112,21 @@ class CFDE_CSSStyleSheet : public IFX_Retainable { bool LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax); FDE_CSSSyntaxStatus LoadStyleRule( CFDE_CSSSyntaxParser* pSyntax, - CFX_MassArrayTemplate<CFDE_CSSRule*>& ruleArray); + std::vector<std::unique_ptr<CFDE_CSSRule>>* ruleArray); FDE_CSSSyntaxStatus LoadImportRule(CFDE_CSSSyntaxParser* pSyntax); FDE_CSSSyntaxStatus LoadPageRule(CFDE_CSSSyntaxParser* pSyntax); FDE_CSSSyntaxStatus LoadMediaRule(CFDE_CSSSyntaxParser* pSyntax); FDE_CSSSyntaxStatus LoadFontFaceRule( CFDE_CSSSyntaxParser* pSyntax, - CFX_MassArrayTemplate<CFDE_CSSRule*>& ruleArray); + std::vector<std::unique_ptr<CFDE_CSSRule>>* ruleArray); FDE_CSSSyntaxStatus SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax); uint16_t m_wCodePage; uint16_t m_wRefCount; uint32_t m_dwMediaList; - CFX_MassArrayTemplate<CFDE_CSSRule*> m_RuleArray; + std::vector<std::unique_ptr<CFDE_CSSRule>> m_RuleArray; CFX_WideString m_szUrl; - CFX_ArrayTemplate<CFDE_CSSSelector*> m_Selectors; + std::vector<std::unique_ptr<CFDE_CSSSelector>> m_Selectors; std::unordered_map<uint32_t, FX_WCHAR*> m_StringCache; }; |