summaryrefslogtreecommitdiff
path: root/xfa/fde/css
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-04 15:43:59 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-04 15:43:59 -0700
commitcddf8253692d3beaa97a502c8b60c1d18f81664a (patch)
treebaa5b2456a1bdfec97fa97be2ef07eb3295a82d7 /xfa/fde/css
parent32e693fe13105fab5baf81b334e932fce62d89b5 (diff)
downloadpdfium-cddf8253692d3beaa97a502c8b60c1d18f81664a.tar.xz
Use smart pointers for class owned pointers under xfa/fde
Use smart pointer to replace raw pointer type for class owned member variables so that memory management will be easier. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2208423002
Diffstat (limited to 'xfa/fde/css')
-rw-r--r--xfa/fde/css/fde_cssstyleselector.cpp81
-rw-r--r--xfa/fde/css/fde_cssstyleselector.h20
-rw-r--r--xfa/fde/css/fde_cssstylesheet.cpp23
-rw-r--r--xfa/fde/css/fde_cssstylesheet.h3
4 files changed, 80 insertions, 47 deletions
diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp
index 6a1a0b0c56..b68ace8dce 100644
--- a/xfa/fde/css/fde_cssstyleselector.cpp
+++ b/xfa/fde/css/fde_cssstyleselector.cpp
@@ -27,6 +27,7 @@ int32_t CFDE_CSSCounterStyle::FindIndex(const FX_WCHAR* pszIdentifier) {
}
return -1;
}
+
void CFDE_CSSCounterStyle::DoUpdateIndex(IFDE_CSSValueList* pList) {
if (!pList)
return;
@@ -105,13 +106,8 @@ FDE_CSSRuleData::FDE_CSSRuleData(CFDE_CSSSelector* pSel,
}
}
-CFDE_CSSStyleSelector::CFDE_CSSStyleSelector()
- : m_pFontMgr(nullptr),
- m_fDefFontSize(12.0f),
- m_pRuleDataStore(nullptr),
- m_pInlineStyleStore(nullptr),
- m_pFixedStyleStore(nullptr),
- m_pAccelerator(nullptr) {
+CFDE_CSSStyleSelector::CFDE_CSSStyleSelector(IFGAS_FontMgr* pFontMgr)
+ : m_pFontMgr(pFontMgr), m_fDefFontSize(12.0f) {
m_ePriorities[FDE_CSSSTYLESHEETPRIORITY_High] = FDE_CSSSTYLESHEETGROUP_Author;
m_ePriorities[FDE_CSSSTYLESHEETPRIORITY_Mid] = FDE_CSSSTYLESHEETGROUP_User;
m_ePriorities[FDE_CSSSTYLESHEETPRIORITY_Low] =
@@ -120,14 +116,8 @@ CFDE_CSSStyleSelector::CFDE_CSSStyleSelector()
CFDE_CSSStyleSelector::~CFDE_CSSStyleSelector() {
Reset();
- delete m_pInlineStyleStore;
- delete m_pFixedStyleStore;
- delete m_pAccelerator;
}
-void CFDE_CSSStyleSelector::SetFontMgr(IFGAS_FontMgr* pFontMgr) {
- m_pFontMgr = pFontMgr;
-}
void CFDE_CSSStyleSelector::SetDefFontSize(FX_FLOAT fFontSize) {
ASSERT(fFontSize > 0);
m_fDefFontSize = fFontSize;
@@ -135,9 +125,9 @@ void CFDE_CSSStyleSelector::SetDefFontSize(FX_FLOAT fFontSize) {
CFDE_CSSAccelerator* CFDE_CSSStyleSelector::InitAccelerator() {
if (!m_pAccelerator)
- m_pAccelerator = new CFDE_CSSAccelerator;
+ m_pAccelerator.reset(new CFDE_CSSAccelerator);
m_pAccelerator->Clear();
- return m_pAccelerator;
+ return m_pAccelerator.get();
}
IFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle(
@@ -146,8 +136,8 @@ IFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle(
m_pFixedStyleStore = IFX_MemoryAllocator::Create(
FX_ALLOCTYPE_Fixed, 16, sizeof(CFDE_CSSComputedStyle));
}
- CFDE_CSSComputedStyle* pStyle = FXTARGET_NewWith(m_pFixedStyleStore)
- CFDE_CSSComputedStyle(m_pFixedStyleStore);
+ CFDE_CSSComputedStyle* pStyle = FXTARGET_NewWith(m_pFixedStyleStore.get())
+ CFDE_CSSComputedStyle(m_pFixedStyleStore.get());
if (pParentStyle) {
pStyle->m_InheritedData =
static_cast<CFDE_CSSComputedStyle*>(pParentStyle)->m_InheritedData;
@@ -157,6 +147,7 @@ IFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle(
pStyle->m_NonInheritedData.Reset();
return pStyle;
}
+
FX_BOOL CFDE_CSSStyleSelector::SetStyleSheet(FDE_CSSSTYLESHEETGROUP eType,
IFDE_CSSStyleSheet* pSheet) {
ASSERT(eType < FDE_CSSSTYLESHEETGROUP_MAX);
@@ -166,6 +157,7 @@ FX_BOOL CFDE_CSSStyleSelector::SetStyleSheet(FDE_CSSSTYLESHEETGROUP eType,
dest.Add(pSheet);
return TRUE;
}
+
FX_BOOL CFDE_CSSStyleSelector::SetStyleSheets(
FDE_CSSSTYLESHEETGROUP eType,
const CFDE_CSSStyleSheetArray* pArray) {
@@ -177,27 +169,30 @@ FX_BOOL CFDE_CSSStyleSelector::SetStyleSheets(
dest.RemoveAt(0, dest.GetSize());
return TRUE;
}
+
void CFDE_CSSStyleSelector::SetStylePriority(
FDE_CSSSTYLESHEETGROUP eType,
FDE_CSSSTYLESHEETPRIORITY ePriority) {
m_ePriorities[ePriority] = eType;
}
+
void CFDE_CSSStyleSelector::UpdateStyleIndex(uint32_t dwMediaList) {
Reset();
m_pRuleDataStore = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Static, 1024, 0);
for (int32_t iGroup = 0; iGroup < FDE_CSSSTYLESHEETGROUP_MAX; ++iGroup) {
CFDE_CSSRuleCollection& rules = m_RuleCollection[iGroup];
- rules.m_pStaticStore = m_pRuleDataStore;
+ rules.m_pStaticStore = m_pRuleDataStore.get();
rules.AddRulesFrom(m_SheetGroups[iGroup], dwMediaList, m_pFontMgr);
}
}
+
void CFDE_CSSStyleSelector::Reset() {
for (int32_t iGroup = 0; iGroup < FDE_CSSSTYLESHEETGROUP_MAX; ++iGroup) {
m_RuleCollection[iGroup].Clear();
}
- delete m_pRuleDataStore;
- m_pRuleDataStore = nullptr;
+ m_pRuleDataStore.reset();
}
+
int32_t CFDE_CSSStyleSelector::MatchDeclarations(
CXFA_CSSTagProvider* pTag,
CFDE_CSSDeclarationArray& matchedDecls,
@@ -325,16 +320,18 @@ void CFDE_CSSStyleSelector::ComputeStyle(
uint32_t dwAttriHash = FX_HashCode_GetW(wsAttri.AsStringC(), true);
if (dwAttriHash == s_dwStyleHash) {
if (!pDecl)
- pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration;
+ pDecl =
+ FXTARGET_NewWith(m_pInlineStyleStore.get()) CFDE_CSSDeclaration;
AppendInlineStyle(pDecl, wsValue.c_str(), wsValue.GetLength());
} else if (dwAttriHash == s_dwAlignHash) {
if (!pDecl)
- pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration;
+ pDecl =
+ FXTARGET_NewWith(m_pInlineStyleStore.get()) CFDE_CSSDeclaration;
FDE_CSSPROPERTYARGS args;
args.pStringCache = nullptr;
- args.pStaticStore = m_pInlineStyleStore;
+ args.pStaticStore = m_pInlineStyleStore.get();
args.pProperty = FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY_TextAlign);
pDecl->AddProperty(&args, wsValue.c_str(), wsValue.GetLength());
}
@@ -431,6 +428,7 @@ void CFDE_CSSStyleSelector::ApplyDeclarations(
}
}
}
+
void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl,
const FX_WCHAR* psz,
int32_t iLen) {
@@ -443,7 +441,7 @@ void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl,
const FX_WCHAR* psz2;
FDE_CSSPROPERTYARGS args;
args.pStringCache = nullptr;
- args.pStaticStore = m_pInlineStyleStore;
+ args.pStaticStore = m_pInlineStyleStore.get();
args.pProperty = nullptr;
CFX_WideString wsName;
while (1) {
@@ -1016,6 +1014,7 @@ void CFDE_CSSStyleSelector::ApplyProperty(
ASSERT(FALSE);
}
}
+
FX_FLOAT CFDE_CSSStyleSelector::ApplyNumber(FDE_CSSPRIMITIVETYPE eUnit,
FX_FLOAT fValue,
FX_FLOAT fPercentBase) {
@@ -1042,6 +1041,7 @@ FX_FLOAT CFDE_CSSStyleSelector::ApplyNumber(FDE_CSSPRIMITIVETYPE eUnit,
return fValue;
}
}
+
FDE_CSSRUBYSPAN CFDE_CSSStyleSelector::ToRubySpan(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_None:
@@ -1049,6 +1049,7 @@ FDE_CSSRUBYSPAN CFDE_CSSStyleSelector::ToRubySpan(FDE_CSSPROPERTYVALUE eValue) {
return FDE_CSSRUBYSPAN_None;
}
}
+
FDE_CSSRUBYPOSITION CFDE_CSSStyleSelector::ToRubyPosition(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1064,6 +1065,7 @@ FDE_CSSRUBYPOSITION CFDE_CSSStyleSelector::ToRubyPosition(
return FDE_CSSRUBYPOSITION_Before;
}
}
+
FDE_CSSRUBYOVERHANG CFDE_CSSStyleSelector::ToRubyOverhang(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1078,6 +1080,7 @@ FDE_CSSRUBYOVERHANG CFDE_CSSStyleSelector::ToRubyOverhang(
return FDE_CSSRUBYOVERHANG_None;
}
}
+
FDE_CSSRUBYALIGN CFDE_CSSStyleSelector::ToRubyAlign(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1103,6 +1106,7 @@ FDE_CSSRUBYALIGN CFDE_CSSStyleSelector::ToRubyAlign(
return FDE_CSSRUBYALIGN_Auto;
}
}
+
FX_BOOL CFDE_CSSStyleSelector::ToTextEmphasisMark(
FDE_CSSPROPERTYVALUE eValue,
FDE_CSSTEXTEMPHASISMARK& eMark) {
@@ -1129,6 +1133,7 @@ FX_BOOL CFDE_CSSStyleSelector::ToTextEmphasisMark(
return FALSE;
}
}
+
FX_BOOL CFDE_CSSStyleSelector::ToTextEmphasisFill(
FDE_CSSPROPERTYVALUE eValue,
FDE_CSSTEXTEMPHASISFILL& eFill) {
@@ -1143,6 +1148,7 @@ FX_BOOL CFDE_CSSStyleSelector::ToTextEmphasisFill(
return FALSE;
}
}
+
FDE_CSSBKGATTACHMENT CFDE_CSSStyleSelector::ToBKGAttachment(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1154,6 +1160,7 @@ FDE_CSSBKGATTACHMENT CFDE_CSSStyleSelector::ToBKGAttachment(
return FDE_CSSBKGATTACHMENT_Fixed;
}
}
+
FDE_CSSCAPTIONSIDE CFDE_CSSStyleSelector::ToCaptionSide(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1173,6 +1180,7 @@ FDE_CSSCAPTIONSIDE CFDE_CSSStyleSelector::ToCaptionSide(
return FDE_CSSCAPTIONSIDE_Top;
}
}
+
FDE_CSSPOSITION CFDE_CSSStyleSelector::ToPosition(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_Static:
@@ -1187,6 +1195,7 @@ FDE_CSSPOSITION CFDE_CSSStyleSelector::ToPosition(FDE_CSSPROPERTYVALUE eValue) {
return FDE_CSSPOSITION_Static;
}
}
+
FDE_CSSCURSOR CFDE_CSSStyleSelector::ToCursor(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_Auto:
@@ -1215,6 +1224,7 @@ FDE_CSSCURSOR CFDE_CSSStyleSelector::ToCursor(FDE_CSSPROPERTYVALUE eValue) {
return FDE_CSSCURSOR_Auto;
}
}
+
FDE_CSSBKGREPEAT CFDE_CSSStyleSelector::ToBKGRepeat(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1230,6 +1240,7 @@ FDE_CSSBKGREPEAT CFDE_CSSStyleSelector::ToBKGRepeat(
return FDE_CSSBKGREPEAT_Repeat;
}
}
+
FDE_CSSTEXTCOMBINE CFDE_CSSStyleSelector::ToTextCombine(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1240,6 +1251,7 @@ FDE_CSSTEXTCOMBINE CFDE_CSSStyleSelector::ToTextCombine(
return FDE_CSSTEXTCOMBINE_None;
}
}
+
FDE_CSSLINEBREAK CFDE_CSSStyleSelector::ToLineBreak(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1255,6 +1267,7 @@ FDE_CSSLINEBREAK CFDE_CSSStyleSelector::ToLineBreak(
return FDE_CSSLINEBREAK_Auto;
}
}
+
FDE_CSSOVERFLOW CFDE_CSSStyleSelector::ToOverflow(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_Visible:
@@ -1273,6 +1286,7 @@ FDE_CSSOVERFLOW CFDE_CSSStyleSelector::ToOverflow(FDE_CSSPROPERTYVALUE eValue) {
return FDE_CSSOVERFLOW_Visible;
}
}
+
FDE_CSSWRITINGMODE CFDE_CSSStyleSelector::ToWritingMode(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1286,6 +1300,7 @@ FDE_CSSWRITINGMODE CFDE_CSSStyleSelector::ToWritingMode(
return FDE_CSSWRITINGMODE_HorizontalTb;
}
}
+
FDE_CSSWORDBREAK CFDE_CSSStyleSelector::ToWordBreak(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1301,6 +1316,7 @@ FDE_CSSWORDBREAK CFDE_CSSStyleSelector::ToWordBreak(
return FDE_CSSWORDBREAK_Normal;
}
}
+
FDE_CSSFLOAT CFDE_CSSStyleSelector::ToFloat(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_Left:
@@ -1313,6 +1329,7 @@ FDE_CSSFLOAT CFDE_CSSStyleSelector::ToFloat(FDE_CSSPROPERTYVALUE eValue) {
return FDE_CSSFLOAT_None;
}
}
+
FDE_CSSCLEAR CFDE_CSSStyleSelector::ToClear(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_None:
@@ -1327,6 +1344,7 @@ FDE_CSSCLEAR CFDE_CSSStyleSelector::ToClear(FDE_CSSPROPERTYVALUE eValue) {
return FDE_CSSCLEAR_None;
}
}
+
FDE_CSSPAGEBREAK CFDE_CSSStyleSelector::ToPageBreak(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1344,6 +1362,7 @@ FDE_CSSPAGEBREAK CFDE_CSSStyleSelector::ToPageBreak(
return FDE_CSSPAGEBREAK_Auto;
}
}
+
FDE_CSSDISPLAY CFDE_CSSStyleSelector::ToDisplay(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_Inline:
@@ -1392,6 +1411,7 @@ FDE_CSSDISPLAY CFDE_CSSStyleSelector::ToDisplay(FDE_CSSPROPERTYVALUE eValue) {
return FDE_CSSDISPLAY_Inline;
}
}
+
FDE_CSSTEXTALIGN CFDE_CSSStyleSelector::ToTextAlign(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1407,6 +1427,7 @@ FDE_CSSTEXTALIGN CFDE_CSSStyleSelector::ToTextAlign(
return FDE_CSSTEXTALIGN_Left;
}
}
+
uint16_t CFDE_CSSStyleSelector::ToFontWeight(FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
case FDE_CSSPROPERTYVALUE_Normal:
@@ -1421,6 +1442,7 @@ uint16_t CFDE_CSSStyleSelector::ToFontWeight(FDE_CSSPROPERTYVALUE eValue) {
return 400;
}
}
+
FDE_CSSFONTSTYLE CFDE_CSSStyleSelector::ToFontStyle(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1431,6 +1453,7 @@ FDE_CSSFONTSTYLE CFDE_CSSStyleSelector::ToFontStyle(
return FDE_CSSFONTSTYLE_Normal;
}
}
+
FDE_CSSBORDERSTYLE CFDE_CSSStyleSelector::ToBorderStyle(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1458,6 +1481,7 @@ FDE_CSSBORDERSTYLE CFDE_CSSStyleSelector::ToBorderStyle(
return FDE_CSSBORDERSTYLE_None;
}
}
+
FX_BOOL CFDE_CSSStyleSelector::SetLengthWithPercent(
FDE_CSSLENGTH& width,
FDE_CSSPRIMITIVETYPE eType,
@@ -1494,6 +1518,7 @@ FX_BOOL CFDE_CSSStyleSelector::SetLengthWithPercent(
}
return FALSE;
}
+
FX_FLOAT CFDE_CSSStyleSelector::ToFontSize(FDE_CSSPROPERTYVALUE eValue,
FX_FLOAT fCurFontSize) {
switch (eValue) {
@@ -1519,6 +1544,7 @@ FX_FLOAT CFDE_CSSStyleSelector::ToFontSize(FDE_CSSPROPERTYVALUE eValue,
return fCurFontSize;
}
}
+
FDE_CSSVERTICALALIGN CFDE_CSSStyleSelector::ToVerticalAlign(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1542,6 +1568,7 @@ FDE_CSSVERTICALALIGN CFDE_CSSStyleSelector::ToVerticalAlign(
return FDE_CSSVERTICALALIGN_Baseline;
}
}
+
FDE_CSSLISTSTYLETYPE CFDE_CSSStyleSelector::ToListStyleType(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1591,12 +1618,14 @@ FDE_CSSLISTSTYLETYPE CFDE_CSSStyleSelector::ToListStyleType(
return FDE_CSSLISTSTYLETYPE_Disc;
}
}
+
FDE_CSSLISTSTYLEPOSITION CFDE_CSSStyleSelector::ToListStylePosition(
FDE_CSSPROPERTYVALUE eValue) {
return eValue == FDE_CSSPROPERTYVALUE_Inside
? FDE_CSSLISTSTYLEPOSITION_Inside
: FDE_CSSLISTSTYLEPOSITION_Outside;
}
+
FDE_CSSVISIBILITY CFDE_CSSStyleSelector::ToVisibility(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1610,6 +1639,7 @@ FDE_CSSVISIBILITY CFDE_CSSStyleSelector::ToVisibility(
return FDE_CSSVISIBILITY_Visible;
}
}
+
FDE_CSSWHITESPACE CFDE_CSSStyleSelector::ToWhiteSpace(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1627,6 +1657,7 @@ FDE_CSSWHITESPACE CFDE_CSSStyleSelector::ToWhiteSpace(
return FDE_CSSWHITESPACE_Normal;
}
}
+
uint32_t CFDE_CSSStyleSelector::ToTextDecoration(IFDE_CSSValueList* pValue) {
uint32_t dwDecoration = 0;
for (int32_t i = pValue->CountValues() - 1; i >= 0; --i) {
@@ -1656,6 +1687,7 @@ uint32_t CFDE_CSSStyleSelector::ToTextDecoration(IFDE_CSSValueList* pValue) {
}
return dwDecoration;
}
+
FDE_CSSTEXTTRANSFORM CFDE_CSSStyleSelector::ToTextTransform(
FDE_CSSPROPERTYVALUE eValue) {
switch (eValue) {
@@ -1671,6 +1703,7 @@ FDE_CSSTEXTTRANSFORM CFDE_CSSStyleSelector::ToTextTransform(
return FDE_CSSTEXTTRANSFORM_None;
}
}
+
FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant(
FDE_CSSPROPERTYVALUE eValue) {
return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps
diff --git a/xfa/fde/css/fde_cssstyleselector.h b/xfa/fde/css/fde_cssstyleselector.h
index 042e989242..469712fb5d 100644
--- a/xfa/fde/css/fde_cssstyleselector.h
+++ b/xfa/fde/css/fde_cssstyleselector.h
@@ -7,6 +7,7 @@
#ifndef XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_
#define XFA_FDE_CSS_FDE_CSSSTYLESELECTOR_H_
+#include <memory>
#include <vector>
#include "core/fxcrt/include/fx_ext.h"
@@ -26,8 +27,8 @@ class FDE_CSSRuleData : public CFX_Target {
CFDE_CSSDeclaration* pDecl,
uint32_t dwPos);
- CFDE_CSSSelector* pSelector;
- CFDE_CSSDeclaration* pDeclaration;
+ CFDE_CSSSelector* const pSelector;
+ CFDE_CSSDeclaration* const pDeclaration;
uint32_t dwPriority;
FDE_CSSRuleData* pNext;
};
@@ -88,10 +89,9 @@ class CFDE_CSSRuleCollection : public CFX_Target {
class CFDE_CSSStyleSelector : public CFX_Target {
public:
- CFDE_CSSStyleSelector();
+ explicit CFDE_CSSStyleSelector(IFGAS_FontMgr* pFontMgr);
~CFDE_CSSStyleSelector() override;
- void SetFontMgr(IFGAS_FontMgr* pFontMgr);
void SetDefFontSize(FX_FLOAT fFontSize);
FX_BOOL SetStyleSheet(FDE_CSSSTYLESHEETGROUP eType,
@@ -174,15 +174,15 @@ class CFDE_CSSStyleSelector : public CFX_Target {
FDE_CSSRUBYPOSITION ToRubyPosition(FDE_CSSPROPERTYVALUE eValue);
FDE_CSSRUBYSPAN ToRubySpan(FDE_CSSPROPERTYVALUE eValue);
- IFGAS_FontMgr* m_pFontMgr;
+ IFGAS_FontMgr* const m_pFontMgr;
FX_FLOAT m_fDefFontSize;
- IFX_MemoryAllocator* m_pRuleDataStore;
+ std::unique_ptr<IFX_MemoryAllocator> m_pRuleDataStore;
CFDE_CSSStyleSheetArray m_SheetGroups[FDE_CSSSTYLESHEETGROUP_MAX];
CFDE_CSSRuleCollection m_RuleCollection[FDE_CSSSTYLESHEETGROUP_MAX];
FDE_CSSSTYLESHEETGROUP m_ePriorities[FDE_CSSSTYLESHEETPRIORITY_MAX];
- IFX_MemoryAllocator* m_pInlineStyleStore;
- IFX_MemoryAllocator* m_pFixedStyleStore;
- CFDE_CSSAccelerator* m_pAccelerator;
+ std::unique_ptr<IFX_MemoryAllocator> m_pInlineStyleStore;
+ std::unique_ptr<IFX_MemoryAllocator> m_pFixedStyleStore;
+ std::unique_ptr<CFDE_CSSAccelerator> m_pAccelerator;
std::vector<FDE_CSSRuleData*> m_MatchedRules;
};
@@ -413,7 +413,7 @@ class CFDE_CSSComputedStyle : public IFDE_CSSComputedStyle,
const CFX_WideString& wsValue);
uint32_t m_dwRefCount;
- IFX_MemoryAllocator* m_pAllocator;
+ IFX_MemoryAllocator* const m_pAllocator;
CFDE_CSSInheritedData m_InheritedData;
CFDE_CSSNonInheritedData m_NonInheritedData;
CFX_WideStringArray m_CustomProperties;
diff --git a/xfa/fde/css/fde_cssstylesheet.cpp b/xfa/fde/css/fde_cssstylesheet.cpp
index 99beab8cf6..bc94cc2f70 100644
--- a/xfa/fde/css/fde_cssstylesheet.cpp
+++ b/xfa/fde/css/fde_cssstylesheet.cpp
@@ -78,7 +78,6 @@ CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList)
: m_wCodePage(FX_CODEPAGE_UTF8),
m_wRefCount(1),
m_dwMediaList(dwMediaList),
- m_pAllocator(nullptr),
m_RuleArray(100) {
ASSERT(m_dwMediaList > 0);
}
@@ -108,8 +107,7 @@ void CFDE_CSSStyleSheet::Reset() {
m_RuleArray.RemoveAll(FALSE);
m_Selectors.RemoveAll();
m_StringCache.clear();
- delete m_pAllocator;
- m_pAllocator = nullptr;
+ m_pAllocator.reset();
}
uint32_t CFDE_CSSStyleSheet::Retain() {
@@ -228,8 +226,8 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule(
break;
case FDE_CSSSYNTAXSTATUS_DeclOpen:
if ((dwMediaList & m_dwMediaList) > 0 && !pMediaRule) {
- pMediaRule =
- FXTARGET_NewWith(m_pAllocator) CFDE_CSSMediaRule(dwMediaList);
+ pMediaRule = FXTARGET_NewWith(m_pAllocator.get())
+ CFDE_CSSMediaRule(dwMediaList);
m_RuleArray.Add(pMediaRule);
}
break;
@@ -248,7 +246,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule(
const FX_WCHAR* pszValue = nullptr;
int32_t iValueLen = 0;
FDE_CSSPROPERTYARGS propertyArgs;
- propertyArgs.pStaticStore = m_pAllocator;
+ propertyArgs.pStaticStore = m_pAllocator.get();
propertyArgs.pStringCache = &m_StringCache;
propertyArgs.pProperty = nullptr;
CFX_WideString wsName;
@@ -256,8 +254,8 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule(
switch (pSyntax->DoSyntaxParse()) {
case FDE_CSSSYNTAXSTATUS_Selector: {
pszValue = pSyntax->GetCurrentString(iValueLen);
- CFDE_CSSSelector* pSelector =
- CFDE_CSSSelector::FromString(m_pAllocator, pszValue, iValueLen);
+ CFDE_CSSSelector* pSelector = CFDE_CSSSelector::FromString(
+ m_pAllocator.get(), pszValue, iValueLen);
if (pSelector)
m_Selectors.Add(pSelector);
} break;
@@ -286,8 +284,8 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule(
break;
case FDE_CSSSYNTAXSTATUS_DeclOpen:
if (!pStyleRule && m_Selectors.GetSize() > 0) {
- pStyleRule = FXTARGET_NewWith(m_pAllocator) CFDE_CSSStyleRule;
- pStyleRule->SetSelector(m_pAllocator, m_Selectors);
+ pStyleRule = FXTARGET_NewWith(m_pAllocator.get()) CFDE_CSSStyleRule;
+ pStyleRule->SetSelector(m_pAllocator.get(), m_Selectors);
ruleArray.Add(pStyleRule);
} else {
SkipRuleSet(pSyntax);
@@ -312,7 +310,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule(
const FX_WCHAR* pszValue = nullptr;
int32_t iValueLen = 0;
FDE_CSSPROPERTYARGS propertyArgs;
- propertyArgs.pStaticStore = m_pAllocator;
+ propertyArgs.pStaticStore = m_pAllocator.get();
propertyArgs.pStringCache = &m_StringCache;
propertyArgs.pProperty = nullptr;
for (;;) {
@@ -333,7 +331,8 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule(
break;
case FDE_CSSSYNTAXSTATUS_DeclOpen:
if (!pFontFaceRule) {
- pFontFaceRule = FXTARGET_NewWith(m_pAllocator) CFDE_CSSFontFaceRule;
+ pFontFaceRule =
+ FXTARGET_NewWith(m_pAllocator.get()) CFDE_CSSFontFaceRule;
ruleArray.Add(pFontFaceRule);
}
break;
diff --git a/xfa/fde/css/fde_cssstylesheet.h b/xfa/fde/css/fde_cssstylesheet.h
index d4781f8a8d..b013e2d2bd 100644
--- a/xfa/fde/css/fde_cssstylesheet.h
+++ b/xfa/fde/css/fde_cssstylesheet.h
@@ -7,6 +7,7 @@
#ifndef XFA_FDE_CSS_FDE_CSSSTYLESHEET_H_
#define XFA_FDE_CSS_FDE_CSSSTYLESHEET_H_
+#include <memory>
#include <unordered_map>
#include "core/fxcrt/include/fx_ext.h"
@@ -133,7 +134,7 @@ class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet, public CFX_Target {
uint16_t m_wCodePage;
uint16_t m_wRefCount;
uint32_t m_dwMediaList;
- IFX_MemoryAllocator* m_pAllocator;
+ std::unique_ptr<IFX_MemoryAllocator> m_pAllocator;
CFX_MassArrayTemplate<IFDE_CSSRule*> m_RuleArray;
CFX_WideString m_szUrl;
CFX_ArrayTemplate<CFDE_CSSSelector*> m_Selectors;