summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-23 16:24:26 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-24 15:05:29 +0000
commit7e5fdd0b1a2ce17e89723fee3e58ae472e32461f (patch)
treee8e14a43410d3d159cef27a0140c4fa8a633f8db
parentaee2d80f628ba02d0561c921b7bb1939b3480fca (diff)
downloadpdfium-7e5fdd0b1a2ce17e89723fee3e58ae472e32461f.tar.xz
Track CFDE_CSSComputedStyle with retained ptrs
Remove the bare new and use CFX_RetainPtr to keep track of the computed styles. Change-Id: Icf235623529797176707482c78676814b7a81b9e Reviewed-on: https://pdfium-review.googlesource.com/2292 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--xfa/fde/css/cfde_csscomputedstyle.cpp13
-rw-r--r--xfa/fde/css/cfde_csscomputedstyle.h16
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.cpp5
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.h2
-rw-r--r--xfa/fxfa/app/cxfa_loadercontext.cpp1
-rw-r--r--xfa/fxfa/app/cxfa_loadercontext.h4
-rw-r--r--xfa/fxfa/app/cxfa_textlayout.cpp74
-rw-r--r--xfa/fxfa/app/cxfa_textlayout.h2
-rw-r--r--xfa/fxfa/app/cxfa_textparsecontext.cpp2
-rw-r--r--xfa/fxfa/app/cxfa_textparsecontext.h2
-rw-r--r--xfa/fxfa/app/cxfa_textparser.cpp31
-rw-r--r--xfa/fxfa/app/cxfa_textparser.h11
-rw-r--r--xfa/fxfa/app/cxfa_textuserdata.cpp20
-rw-r--r--xfa/fxfa/app/cxfa_textuserdata.h7
14 files changed, 79 insertions, 111 deletions
diff --git a/xfa/fde/css/cfde_csscomputedstyle.cpp b/xfa/fde/css/cfde_csscomputedstyle.cpp
index 010f573c04..b563bbf445 100644
--- a/xfa/fde/css/cfde_csscomputedstyle.cpp
+++ b/xfa/fde/css/cfde_csscomputedstyle.cpp
@@ -10,21 +10,10 @@
#include "xfa/fde/css/cfde_cssstringvalue.h"
#include "xfa/fde/css/cfde_cssvaluelist.h"
-CFDE_CSSComputedStyle::CFDE_CSSComputedStyle() : m_dwRefCount(1) {}
+CFDE_CSSComputedStyle::CFDE_CSSComputedStyle() {}
CFDE_CSSComputedStyle::~CFDE_CSSComputedStyle() {}
-uint32_t CFDE_CSSComputedStyle::Retain() {
- return ++m_dwRefCount;
-}
-
-uint32_t CFDE_CSSComputedStyle::Release() {
- uint32_t dwRefCount = --m_dwRefCount;
- if (dwRefCount == 0)
- delete this;
- return dwRefCount;
-}
-
bool CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideStringC& wsName,
CFX_WideString& wsValue) const {
for (int32_t i = pdfium::CollectionSize<int32_t>(m_CustomProperties) - 2;
diff --git a/xfa/fde/css/cfde_csscomputedstyle.h b/xfa/fde/css/cfde_csscomputedstyle.h
index 73eb996f0d..1f73d87631 100644
--- a/xfa/fde/css/cfde_csscomputedstyle.h
+++ b/xfa/fde/css/cfde_csscomputedstyle.h
@@ -15,7 +15,7 @@
class CFDE_CSSValueList;
-class CFDE_CSSComputedStyle : public IFX_Retainable {
+class CFDE_CSSComputedStyle : public CFX_Retainable {
public:
class InheritedData {
public:
@@ -54,13 +54,6 @@ class CFDE_CSSComputedStyle : public IFX_Retainable {
bool m_bHasPadding;
};
- CFDE_CSSComputedStyle();
- ~CFDE_CSSComputedStyle() override;
-
- // IFX_Retainable
- uint32_t Retain() override;
- uint32_t Release() override;
-
int32_t CountFontFamilies() const;
const CFX_WideString GetFontFamily(int32_t index) const;
uint16_t GetFontWeight() const;
@@ -105,7 +98,12 @@ class CFDE_CSSComputedStyle : public IFX_Retainable {
NonInheritedData m_NonInheritedData;
private:
- uint32_t m_dwRefCount;
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
+ CFDE_CSSComputedStyle();
+ ~CFDE_CSSComputedStyle() override;
+
std::vector<CFX_WideString> m_CustomProperties;
};
diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp
index 63d8e0986b..1b4aa0e13b 100644
--- a/xfa/fde/css/cfde_cssstyleselector.cpp
+++ b/xfa/fde/css/cfde_cssstyleselector.cpp
@@ -55,9 +55,9 @@ CFDE_CSSAccelerator* CFDE_CSSStyleSelector::InitAccelerator() {
return m_pAccelerator.get();
}
-CFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle(
+CFX_RetainPtr<CFDE_CSSComputedStyle> CFDE_CSSStyleSelector::CreateComputedStyle(
CFDE_CSSComputedStyle* pParentStyle) {
- CFDE_CSSComputedStyle* pStyle = new CFDE_CSSComputedStyle();
+ auto pStyle = pdfium::MakeRetain<CFDE_CSSComputedStyle>();
if (pParentStyle)
pStyle->m_InheritedData = pParentStyle->m_InheritedData;
return pStyle;
@@ -77,6 +77,7 @@ int32_t CFDE_CSSStyleSelector::MatchDeclarations(
CXFA_CSSTagProvider* pTag,
CFX_ArrayTemplate<CFDE_CSSDeclaration*>& matchedDecls) {
ASSERT(pTag);
+
CFDE_CSSTagCache* pCache = m_pAccelerator->top();
ASSERT(pCache && pCache->GetTag() == pTag);
diff --git a/xfa/fde/css/cfde_cssstyleselector.h b/xfa/fde/css/cfde_cssstyleselector.h
index 2b03d7e961..c2262d7aa7 100644
--- a/xfa/fde/css/cfde_cssstyleselector.h
+++ b/xfa/fde/css/cfde_cssstyleselector.h
@@ -37,7 +37,7 @@ class CFDE_CSSStyleSelector {
void UpdateStyleIndex();
CFDE_CSSAccelerator* InitAccelerator();
- CFDE_CSSComputedStyle* CreateComputedStyle(
+ CFX_RetainPtr<CFDE_CSSComputedStyle> CreateComputedStyle(
CFDE_CSSComputedStyle* pParentStyle);
int32_t MatchDeclarations(
CXFA_CSSTagProvider* pTag,
diff --git a/xfa/fxfa/app/cxfa_loadercontext.cpp b/xfa/fxfa/app/cxfa_loadercontext.cpp
index 56ac71bfb4..0733c52dfc 100644
--- a/xfa/fxfa/app/cxfa_loadercontext.cpp
+++ b/xfa/fxfa/app/cxfa_loadercontext.cpp
@@ -16,7 +16,6 @@ CXFA_LoaderContext::CXFA_LoaderContext()
m_iTotalLines(-1),
m_pXMLNode(nullptr),
m_pNode(nullptr),
- m_pParentStyle(nullptr),
m_dwFlags(0) {}
CXFA_LoaderContext::~CXFA_LoaderContext() {}
diff --git a/xfa/fxfa/app/cxfa_loadercontext.h b/xfa/fxfa/app/cxfa_loadercontext.h
index c647f62a33..d8ccdbe7e2 100644
--- a/xfa/fxfa/app/cxfa_loadercontext.h
+++ b/xfa/fxfa/app/cxfa_loadercontext.h
@@ -11,10 +11,10 @@
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_system.h"
+#include "xfa/fde/css/cfde_csscomputedstyle.h"
class CFDE_XMLNode;
class CXFA_Node;
-class CFDE_CSSComputedStyle;
class CXFA_LoaderContext {
public:
@@ -31,7 +31,7 @@ class CXFA_LoaderContext {
int32_t m_iTotalLines;
CFDE_XMLNode* m_pXMLNode;
CXFA_Node* m_pNode;
- CFDE_CSSComputedStyle* m_pParentStyle;
+ CFX_RetainPtr<CFDE_CSSComputedStyle> m_pParentStyle;
CFX_ArrayTemplate<FX_FLOAT> m_lineHeights;
uint32_t m_dwFlags;
std::vector<FX_FLOAT> m_BlocksHeight;
diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp
index 788fea2e7d..cc9c653a39 100644
--- a/xfa/fxfa/app/cxfa_textlayout.cpp
+++ b/xfa/fxfa/app/cxfa_textlayout.cpp
@@ -654,10 +654,8 @@ bool CXFA_TextLayout::Loader(const CFX_SizeF& szText,
if (!m_textParser.IsParsed())
m_textParser.DoParse(pXMLContainer, m_pTextProvider);
- CFDE_CSSComputedStyle* pRootStyle =
- m_textParser.CreateRootStyle(m_pTextProvider);
+ auto pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider);
LoadRichText(pXMLContainer, szText, fLinePos, pRootStyle, bSavePieces);
- pRootStyle->Release();
}
} else {
LoadText(m_pTextDataNode, szText, fLinePos, bSavePieces);
@@ -698,15 +696,16 @@ void CXFA_TextLayout::LoadText(CXFA_Node* pNode,
EndBreak(FX_RTFBREAK_ParagraphBreak, fLinePos, bSavePieces);
}
-bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode,
- const CFX_SizeF& szText,
- FX_FLOAT& fLinePos,
- CFDE_CSSComputedStyle* pParentStyle,
- bool bSavePieces,
- CXFA_LinkUserData* pLinkData,
- bool bEndBreak,
- bool bIsOl,
- int32_t iLiCount) {
+bool CXFA_TextLayout::LoadRichText(
+ CFDE_XMLNode* pXMLNode,
+ const CFX_SizeF& szText,
+ FX_FLOAT& fLinePos,
+ const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle,
+ bool bSavePieces,
+ CXFA_LinkUserData* pLinkData,
+ bool bEndBreak,
+ bool bIsOl,
+ int32_t iLiCount) {
if (!pXMLNode)
return false;
@@ -715,7 +714,7 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode,
FDE_CSSDisplay eDisplay = FDE_CSSDisplay::None;
bool bContentNode = false;
FX_FLOAT fSpaceBelow = 0;
- CFDE_CSSComputedStyle* pStyle = nullptr;
+ CFX_RetainPtr<CFDE_CSSComputedStyle> pStyle;
CFX_WideString wsName;
if (bEndBreak) {
bool bCurOl = false;
@@ -744,9 +743,9 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode,
return true;
}
- pStyle = m_textParser.ComputeStyle(pXMLNode, pParentStyle);
- InitBreak(bContentNode ? pParentStyle : pStyle, eDisplay, szText.x,
- pXMLNode, pParentStyle);
+ pStyle = m_textParser.ComputeStyle(pXMLNode, pParentStyle.Get());
+ InitBreak(bContentNode ? pParentStyle.Get() : pStyle.Get(), eDisplay,
+ szText.x, pXMLNode, pParentStyle.Get());
if ((eDisplay == FDE_CSSDisplay::Block ||
eDisplay == FDE_CSSDisplay::ListItem) &&
pStyle &&
@@ -771,10 +770,10 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode,
}
}
- int32_t iTabCount =
- m_textParser.CountTabs(bContentNode ? pParentStyle : pStyle);
- bool bSpaceRun =
- m_textParser.IsSpaceRun(bContentNode ? pParentStyle : pStyle);
+ int32_t iTabCount = m_textParser.CountTabs(
+ bContentNode ? pParentStyle.Get() : pStyle.Get());
+ bool bSpaceRun = m_textParser.IsSpaceRun(
+ bContentNode ? pParentStyle.Get() : pStyle.Get());
CFX_WideString wsText;
if (bContentNode && iTabCount == 0) {
static_cast<CFDE_XMLText*>(pXMLNode)->GetText(wsText);
@@ -835,8 +834,6 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode,
m_pLoader->m_pXMLNode = pXMLNode;
m_pLoader->m_pParentStyle = pParentStyle;
}
- if (pStyle)
- pStyle->Release();
return false;
}
return true;
@@ -887,9 +884,6 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode,
}
}
if (IsEnd(bSavePieces)) {
- if (pStyle)
- pStyle->Release();
-
if (m_pLoader && m_pLoader->m_iTotalLines > -1) {
m_pLoader->m_pXMLNode =
pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling);
@@ -899,9 +893,6 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode,
}
}
}
- if (pStyle)
- pStyle->Release();
-
return true;
}
@@ -1039,7 +1030,7 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
if (iPieces < 1)
return;
- CFDE_CSSComputedStyle* pStyle = nullptr;
+ CFX_RetainPtr<CFDE_CSSComputedStyle> pStyle;
if (bSavePieces) {
auto pNew = pdfium::MakeUnique<CXFA_PieceLine>();
CXFA_PieceLine* pPieceLine = pNew.get();
@@ -1065,21 +1056,22 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
pTP->iBidiLevel = pPiece->m_iBidiLevel;
pTP->iHorScale = pPiece->m_iHorizontalScale;
pTP->iVerScale = pPiece->m_iVerticalScale;
- m_textParser.GetUnderline(m_pTextProvider, pStyle, pTP->iUnderline,
+ m_textParser.GetUnderline(m_pTextProvider, pStyle.Get(), pTP->iUnderline,
pTP->iPeriod);
- m_textParser.GetLinethrough(m_pTextProvider, pStyle, pTP->iLineThrough);
- pTP->dwColor = m_textParser.GetColor(m_pTextProvider, pStyle);
- pTP->pFont = m_textParser.GetFont(m_pTextProvider, pStyle);
- pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle);
+ m_textParser.GetLinethrough(m_pTextProvider, pStyle.Get(),
+ pTP->iLineThrough);
+ pTP->dwColor = m_textParser.GetColor(m_pTextProvider, pStyle.Get());
+ pTP->pFont = m_textParser.GetFont(m_pTextProvider, pStyle.Get());
+ pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle.Get());
pTP->rtPiece.left = pPiece->m_iStartPos / 20000.0f;
pTP->rtPiece.width = pPiece->m_iWidth / 20000.0f;
pTP->rtPiece.height = (FX_FLOAT)pPiece->m_iFontSize * fVerScale / 20.0f;
FX_FLOAT fBaseLineTemp =
- m_textParser.GetBaseline(m_pTextProvider, pStyle);
+ m_textParser.GetBaseline(m_pTextProvider, pStyle.Get());
pTP->rtPiece.top = fBaseLineTemp;
FX_FLOAT fLineHeight = m_textParser.GetLineHeight(
- m_pTextProvider, pStyle, m_iLines == 0, fVerScale);
+ m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale);
if (fBaseLineTemp > 0) {
FX_FLOAT fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height;
if (fLineHeight < fLineHeightTmp)
@@ -1097,7 +1089,7 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
pTP->pLinkData = nullptr;
}
pPieceLine->m_textPieces.push_back(std::move(pTP));
- DoTabstops(pStyle, pPieceLine);
+ DoTabstops(pStyle.Get(), pPieceLine);
}
for (const auto& pTP : pPieceLine->m_textPieces) {
FX_FLOAT& fTop = pTP->rtPiece.top;
@@ -1115,9 +1107,10 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
if (pUserData)
pStyle = pUserData->m_pStyle;
FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f;
- FX_FLOAT fBaseLine = m_textParser.GetBaseline(m_pTextProvider, pStyle);
+ FX_FLOAT fBaseLine =
+ m_textParser.GetBaseline(m_pTextProvider, pStyle.Get());
FX_FLOAT fLineHeight = m_textParser.GetLineHeight(
- m_pTextProvider, pStyle, m_iLines == 0, fVerScale);
+ m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale);
if (fBaseLine > 0) {
FX_FLOAT fLineHeightTmp =
fBaseLine + (FX_FLOAT)pPiece->m_iFontSize * fVerScale / 20.0f;
@@ -1136,8 +1129,6 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
m_pLoader->m_lineHeights.Add(fHeight);
}
}
- if (pStyle)
- pStyle->Retain();
m_pBreak->ClearBreakPieces();
if (dwStatus == FX_RTFBREAK_ParagraphBreak) {
@@ -1171,7 +1162,6 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
fStart -= fTextIndent;
m_pBreak->SetLineStartPos(fStart);
- pStyle->Release();
}
m_iLines++;
}
diff --git a/xfa/fxfa/app/cxfa_textlayout.h b/xfa/fxfa/app/cxfa_textlayout.h
index cb0ad136a0..a9d45f2ec3 100644
--- a/xfa/fxfa/app/cxfa_textlayout.h
+++ b/xfa/fxfa/app/cxfa_textlayout.h
@@ -82,7 +82,7 @@ class CXFA_TextLayout {
bool LoadRichText(CFDE_XMLNode* pXMLNode,
const CFX_SizeF& szText,
FX_FLOAT& fLinePos,
- CFDE_CSSComputedStyle* pParentStyle,
+ const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle,
bool bSavePieces,
CXFA_LinkUserData* pLinkData = nullptr,
bool bEndBreak = true,
diff --git a/xfa/fxfa/app/cxfa_textparsecontext.cpp b/xfa/fxfa/app/cxfa_textparsecontext.cpp
index c0c226c4ac..e4beb1fcb0 100644
--- a/xfa/fxfa/app/cxfa_textparsecontext.cpp
+++ b/xfa/fxfa/app/cxfa_textparsecontext.cpp
@@ -17,8 +17,6 @@ CXFA_TextParseContext::CXFA_TextParseContext()
m_eDisplay(FDE_CSSDisplay::None) {}
CXFA_TextParseContext::~CXFA_TextParseContext() {
- if (m_pParentStyle)
- m_pParentStyle->Release();
FX_Free(m_ppMatchedDecls);
}
diff --git a/xfa/fxfa/app/cxfa_textparsecontext.h b/xfa/fxfa/app/cxfa_textparsecontext.h
index 2faaadb440..d13f35b6df 100644
--- a/xfa/fxfa/app/cxfa_textparsecontext.h
+++ b/xfa/fxfa/app/cxfa_textparsecontext.h
@@ -26,7 +26,7 @@ class CXFA_TextParseContext {
}
uint32_t CountDecls() const { return m_dwMatchedDecls; }
- CFDE_CSSComputedStyle* m_pParentStyle;
+ CFX_RetainPtr<CFDE_CSSComputedStyle> m_pParentStyle;
protected:
CFDE_CSSDeclaration** m_ppMatchedDecls;
diff --git a/xfa/fxfa/app/cxfa_textparser.cpp b/xfa/fxfa/app/cxfa_textparser.cpp
index 6386edfad8..9bf033f9b0 100644
--- a/xfa/fxfa/app/cxfa_textparser.cpp
+++ b/xfa/fxfa/app/cxfa_textparser.cpp
@@ -101,11 +101,11 @@ std::unique_ptr<CFDE_CSSStyleSheet> CXFA_TextParser::LoadDefaultSheetStyle() {
: nullptr;
}
-CFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle(
+CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateRootStyle(
CXFA_TextProvider* pTextProvider) {
CXFA_Font font = pTextProvider->GetFontNode();
CXFA_Para para = pTextProvider->GetParaNode();
- CFDE_CSSComputedStyle* pStyle = m_pSelector->CreateComputedStyle(nullptr);
+ auto pStyle = m_pSelector->CreateComputedStyle(nullptr);
FX_FLOAT fLineHeight = 0;
FX_FLOAT fFontSize = 10;
@@ -163,10 +163,9 @@ CFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle(
return pStyle;
}
-CFDE_CSSComputedStyle* CXFA_TextParser::CreateStyle(
+CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateStyle(
CFDE_CSSComputedStyle* pParentStyle) {
- CFDE_CSSComputedStyle* pNewStyle =
- m_pSelector->CreateComputedStyle(pParentStyle);
+ auto pNewStyle = m_pSelector->CreateComputedStyle(pParentStyle);
ASSERT(pNewStyle);
if (!pParentStyle)
return pNewStyle;
@@ -185,7 +184,7 @@ CFDE_CSSComputedStyle* CXFA_TextParser::CreateStyle(
return pNewStyle;
}
-CFDE_CSSComputedStyle* CXFA_TextParser::ComputeStyle(
+CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::ComputeStyle(
CFDE_XMLNode* pXMLNode,
CFDE_CSSComputedStyle* pParentStyle) {
auto it = m_mapXMLNodeToParseContext.find(pXMLNode);
@@ -196,19 +195,18 @@ CFDE_CSSComputedStyle* CXFA_TextParser::ComputeStyle(
if (!pContext)
return nullptr;
- pContext->m_pParentStyle = pParentStyle;
- pParentStyle->Retain();
+ pContext->m_pParentStyle.Reset(pParentStyle);
CXFA_CSSTagProvider tagProvider;
ParseTagInfo(pXMLNode, tagProvider);
if (tagProvider.m_bContent)
return nullptr;
- CFDE_CSSComputedStyle* pStyle = CreateStyle(pParentStyle);
+ auto pStyle = CreateStyle(pParentStyle);
CFDE_CSSAccelerator* pCSSAccel = m_pSelector->InitAccelerator();
pCSSAccel->OnEnterTag(&tagProvider);
m_pSelector->ComputeStyle(&tagProvider, pContext->GetDecls(),
- pContext->CountDecls(), pStyle);
+ pContext->CountDecls(), pStyle.Get());
pCSSAccel->OnLeaveTag(&tagProvider);
return pStyle;
}
@@ -220,9 +218,8 @@ void CXFA_TextParser::DoParse(CFDE_XMLNode* pXMLContainer,
m_bParsed = true;
InitCSSData(pTextProvider);
- CFDE_CSSComputedStyle* pRootStyle = CreateRootStyle(pTextProvider);
- ParseRichText(pXMLContainer, pRootStyle);
- pRootStyle->Release();
+ auto pRootStyle = CreateRootStyle(pTextProvider);
+ ParseRichText(pXMLContainer, pRootStyle.Get());
}
void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode,
@@ -235,7 +232,7 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode,
if (!tagProvider.m_bTagAvailable)
return;
- CFDE_CSSComputedStyle* pNewStyle = nullptr;
+ CFX_RetainPtr<CFDE_CSSComputedStyle> pNewStyle;
if ((tagProvider.GetTagName() != FX_WSTRC(L"body")) ||
(tagProvider.GetTagName() != FX_WSTRC(L"html"))) {
CXFA_TextParseContext* pTextContext = new CXFA_TextParseContext;
@@ -250,7 +247,7 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode,
const CFDE_CSSDeclaration** ppMatchDecls =
const_cast<const CFDE_CSSDeclaration**>(DeclArray.GetData());
m_pSelector->ComputeStyle(&tagProvider, ppMatchDecls, iMatchedDecls,
- pNewStyle);
+ pNewStyle.Get());
pCSSAccel->OnLeaveTag(&tagProvider);
if (iMatchedDecls > 0)
pTextContext->SetDecls(ppMatchDecls, iMatchedDecls);
@@ -265,10 +262,8 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode,
pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
pXMLChild;
pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) {
- ParseRichText(pXMLChild, pNewStyle);
+ ParseRichText(pXMLChild, pNewStyle.Get());
}
- if (pNewStyle)
- pNewStyle->Release();
}
bool CXFA_TextParser::TagValidate(const CFX_WideString& wsName) const {
diff --git a/xfa/fxfa/app/cxfa_textparser.h b/xfa/fxfa/app/cxfa_textparser.h
index 7a94f83aeb..9332dfc9e1 100644
--- a/xfa/fxfa/app/cxfa_textparser.h
+++ b/xfa/fxfa/app/cxfa_textparser.h
@@ -33,9 +33,11 @@ class CXFA_TextParser {
void Reset();
void DoParse(CFDE_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider);
- CFDE_CSSComputedStyle* CreateRootStyle(CXFA_TextProvider* pTextProvider);
- CFDE_CSSComputedStyle* ComputeStyle(CFDE_XMLNode* pXMLNode,
- CFDE_CSSComputedStyle* pParentStyle);
+ CFX_RetainPtr<CFDE_CSSComputedStyle> CreateRootStyle(
+ CXFA_TextProvider* pTextProvider);
+ CFX_RetainPtr<CFDE_CSSComputedStyle> ComputeStyle(
+ CFDE_XMLNode* pXMLNode,
+ CFDE_CSSComputedStyle* pParentStyle);
bool IsParsed() const { return m_bParsed; }
@@ -89,7 +91,8 @@ class CXFA_TextParser {
CFDE_CSSComputedStyle* pParentStyle);
void ParseTagInfo(CFDE_XMLNode* pXMLNode, CXFA_CSSTagProvider& tagProvider);
std::unique_ptr<CFDE_CSSStyleSheet> LoadDefaultSheetStyle();
- CFDE_CSSComputedStyle* CreateStyle(CFDE_CSSComputedStyle* pParentStyle);
+ CFX_RetainPtr<CFDE_CSSComputedStyle> CreateStyle(
+ CFDE_CSSComputedStyle* pParentStyle);
std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector;
std::map<CFDE_XMLNode*, CXFA_TextParseContext*> m_mapXMLNodeToParseContext;
diff --git a/xfa/fxfa/app/cxfa_textuserdata.cpp b/xfa/fxfa/app/cxfa_textuserdata.cpp
index 4fdabd6bb3..e436ab2ae9 100644
--- a/xfa/fxfa/app/cxfa_textuserdata.cpp
+++ b/xfa/fxfa/app/cxfa_textuserdata.cpp
@@ -11,22 +11,16 @@
#include "xfa/fde/css/fde_css.h"
#include "xfa/fxfa/app/cxfa_linkuserdata.h"
-CXFA_TextUserData::CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle)
- : m_pStyle(pStyle), m_pLinkData(nullptr), m_dwRefCount(0) {
- if (m_pStyle)
- m_pStyle->Retain();
-}
+CXFA_TextUserData::CXFA_TextUserData(
+ const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle)
+ : m_pStyle(pStyle), m_pLinkData(nullptr), m_dwRefCount(0) {}
-CXFA_TextUserData::CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle,
- CXFA_LinkUserData* pLinkData)
- : m_pStyle(pStyle), m_pLinkData(pLinkData), m_dwRefCount(0) {
- if (m_pStyle)
- m_pStyle->Retain();
-}
+CXFA_TextUserData::CXFA_TextUserData(
+ const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle,
+ CXFA_LinkUserData* pLinkData)
+ : m_pStyle(pStyle), m_pLinkData(pLinkData), m_dwRefCount(0) {}
CXFA_TextUserData::~CXFA_TextUserData() {
- if (m_pStyle)
- m_pStyle->Release();
if (m_pLinkData)
m_pLinkData->Release();
}
diff --git a/xfa/fxfa/app/cxfa_textuserdata.h b/xfa/fxfa/app/cxfa_textuserdata.h
index 83f762ddbe..1eb3b8acb3 100644
--- a/xfa/fxfa/app/cxfa_textuserdata.h
+++ b/xfa/fxfa/app/cxfa_textuserdata.h
@@ -14,8 +14,9 @@ class CXFA_LinkUserData;
class CXFA_TextUserData : public IFX_Retainable {
public:
- explicit CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle);
- CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle,
+ explicit CXFA_TextUserData(
+ const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle);
+ CXFA_TextUserData(const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle,
CXFA_LinkUserData* pLinkData);
~CXFA_TextUserData() override;
@@ -23,7 +24,7 @@ class CXFA_TextUserData : public IFX_Retainable {
uint32_t Retain() override;
uint32_t Release() override;
- CFDE_CSSComputedStyle* m_pStyle;
+ CFX_RetainPtr<CFDE_CSSComputedStyle> m_pStyle;
CXFA_LinkUserData* m_pLinkData;
protected: