Mark many params as const in CXFA_TextParser methods.
Adjust affected code elsewhere by adding more consts. Initialize
CXFA_TextParseContext members in the header along the way.
Change-Id: I92c9ba26a076e2ae289cd9d1c068cd92a0e517b6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70870
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp
index 48f573d..792722e 100644
--- a/core/fxcrt/css/cfx_cssstyleselector.cpp
+++ b/core/fxcrt/css/cfx_cssstyleselector.cpp
@@ -32,7 +32,7 @@
}
RetainPtr<CFX_CSSComputedStyle> CFX_CSSStyleSelector::CreateComputedStyle(
- CFX_CSSComputedStyle* pParentStyle) {
+ const CFX_CSSComputedStyle* pParentStyle) {
auto pStyle = pdfium::MakeRetain<CFX_CSSComputedStyle>();
if (pParentStyle)
pStyle->m_InheritedData = pParentStyle->m_InheritedData;
diff --git a/core/fxcrt/css/cfx_cssstyleselector.h b/core/fxcrt/css/cfx_cssstyleselector.h
index 17e3039..d3d04a0 100644
--- a/core/fxcrt/css/cfx_cssstyleselector.h
+++ b/core/fxcrt/css/cfx_cssstyleselector.h
@@ -33,7 +33,7 @@
void UpdateStyleIndex();
RetainPtr<CFX_CSSComputedStyle> CreateComputedStyle(
- CFX_CSSComputedStyle* pParentStyle);
+ const CFX_CSSComputedStyle* pParentStyle);
// Note, the dest style has to be an out param because the CXFA_TextParser
// adds non-inherited data from the parent style. Attempting to copy
diff --git a/xfa/fxfa/cxfa_textparsecontext.cpp b/xfa/fxfa/cxfa_textparsecontext.cpp
index 1893402..b21173a 100644
--- a/xfa/fxfa/cxfa_textparsecontext.cpp
+++ b/xfa/fxfa/cxfa_textparsecontext.cpp
@@ -10,7 +10,6 @@
#include "core/fxcrt/css/cfx_cssdeclaration.h"
#include "core/fxcrt/css/cfx_cssstyleselector.h"
-CXFA_TextParseContext::CXFA_TextParseContext()
- : m_pParentStyle(nullptr), m_eDisplay(CFX_CSSDisplay::None) {}
+CXFA_TextParseContext::CXFA_TextParseContext() = default;
CXFA_TextParseContext::~CXFA_TextParseContext() = default;
diff --git a/xfa/fxfa/cxfa_textparsecontext.h b/xfa/fxfa/cxfa_textparsecontext.h
index a146d40..985ba4e 100644
--- a/xfa/fxfa/cxfa_textparsecontext.h
+++ b/xfa/fxfa/cxfa_textparsecontext.h
@@ -28,11 +28,11 @@
}
const std::vector<const CFX_CSSDeclaration*>& GetDecls() { return decls_; }
- RetainPtr<CFX_CSSComputedStyle> m_pParentStyle;
+ RetainPtr<const CFX_CSSComputedStyle> m_pParentStyle;
private:
std::vector<const CFX_CSSDeclaration*> decls_;
- CFX_CSSDisplay m_eDisplay;
+ CFX_CSSDisplay m_eDisplay = CFX_CSSDisplay::None;
};
#endif // XFA_FXFA_CXFA_TEXTPARSECONTEXT_H_
diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp
index 15f56c7..eb01fa8 100644
--- a/xfa/fxfa/cxfa_textparser.cpp
+++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -173,7 +173,7 @@
}
RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::CreateStyle(
- CFX_CSSComputedStyle* pParentStyle) {
+ const CFX_CSSComputedStyle* pParentStyle) {
auto pNewStyle = m_pSelector->CreateComputedStyle(pParentStyle);
ASSERT(pNewStyle);
if (!pParentStyle)
@@ -195,7 +195,7 @@
RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::ComputeStyle(
const CFX_XMLNode* pXMLNode,
- CFX_CSSComputedStyle* pParentStyle) {
+ const CFX_CSSComputedStyle* pParentStyle) {
auto it = m_mapXMLNodeToParseContext.find(pXMLNode);
if (it == m_mapXMLNodeToParseContext.end())
return nullptr;
@@ -229,7 +229,7 @@
}
void CXFA_TextParser::ParseRichText(const CFX_XMLNode* pXMLNode,
- CFX_CSSComputedStyle* pParentStyle) {
+ const CFX_CSSComputedStyle* pParentStyle) {
if (!pXMLNode)
return;
@@ -313,21 +313,22 @@
return para ? para->GetVerticalAlign() : XFA_AttributeValue::Top;
}
-float CXFA_TextParser::GetTabInterval(CFX_CSSComputedStyle* pStyle) const {
+float CXFA_TextParser::GetTabInterval(
+ const CFX_CSSComputedStyle* pStyle) const {
WideString wsValue;
if (pStyle && pStyle->GetCustomStyle(L"tab-interval", &wsValue))
return CXFA_Measurement(wsValue.AsStringView()).ToUnit(XFA_Unit::Pt);
return 36;
}
-int32_t CXFA_TextParser::CountTabs(CFX_CSSComputedStyle* pStyle) const {
+int32_t CXFA_TextParser::CountTabs(const CFX_CSSComputedStyle* pStyle) const {
WideString wsValue;
if (pStyle && pStyle->GetCustomStyle(L"xfa-tab-count", &wsValue))
return wsValue.GetInteger();
return 0;
}
-bool CXFA_TextParser::IsSpaceRun(CFX_CSSComputedStyle* pStyle) const {
+bool CXFA_TextParser::IsSpaceRun(const CFX_CSSComputedStyle* pStyle) const {
WideString wsValue;
return pStyle && pStyle->GetCustomStyle(L"xfa-spacerun", &wsValue) &&
wsValue.EqualsASCIINoCase("yes");
@@ -336,7 +337,7 @@
RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont(
CXFA_FFDoc* doc,
CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const {
+ const CFX_CSSComputedStyle* pStyle) const {
WideString wsFamily = L"Courier";
uint32_t dwStyle = 0;
CXFA_Font* font = pTextProvider->GetFontIfExists();
@@ -365,7 +366,7 @@
}
float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const {
+ const CFX_CSSComputedStyle* pStyle) const {
if (pStyle)
return pStyle->GetFontSize();
@@ -374,7 +375,7 @@
}
int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
const CFX_XMLNode* pXMLNode) const {
if (pStyle) {
WideString wsValue;
@@ -400,7 +401,7 @@
}
int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const {
+ const CFX_CSSComputedStyle* pStyle) const {
if (pStyle) {
WideString wsValue;
if (pStyle->GetCustomStyle(L"xfa-font-vertical-scale", &wsValue))
@@ -412,7 +413,7 @@
}
void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
int32_t& iUnderline,
XFA_AttributeValue& iPeriod) const {
iUnderline = 0;
@@ -442,7 +443,7 @@
}
void CXFA_TextParser::GetLinethrough(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
int32_t& iLinethrough) const {
iLinethrough = 0;
if (pStyle) {
@@ -458,7 +459,7 @@
}
FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const {
+ const CFX_CSSComputedStyle* pStyle) const {
if (pStyle)
return pStyle->GetColor();
@@ -467,7 +468,7 @@
}
float CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const {
+ const CFX_CSSComputedStyle* pStyle) const {
if (pStyle) {
if (pStyle->GetVerticalAlign() == CFX_CSSVerticalAlign::Number)
return pStyle->GetNumberVerticalAlign();
@@ -480,7 +481,7 @@
}
float CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
bool bFirst,
float fVerScale) const {
float fLineHeight = 0;
@@ -541,7 +542,7 @@
return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr;
}
-bool CXFA_TextParser::GetTabstops(CFX_CSSComputedStyle* pStyle,
+bool CXFA_TextParser::GetTabstops(const CFX_CSSComputedStyle* pStyle,
CXFA_TextTabstopsContext* pTabstopContext) {
if (!pStyle || !pTabstopContext)
return false;
diff --git a/xfa/fxfa/cxfa_textparser.h b/xfa/fxfa/cxfa_textparser.h
index b1e5878..79753fa 100644
--- a/xfa/fxfa/cxfa_textparser.h
+++ b/xfa/fxfa/cxfa_textparser.h
@@ -40,44 +40,44 @@
CXFA_TextProvider* pTextProvider);
RetainPtr<CFX_CSSComputedStyle> ComputeStyle(
const CFX_XMLNode* pXMLNode,
- CFX_CSSComputedStyle* pParentStyle);
+ const CFX_CSSComputedStyle* pParentStyle);
bool IsParsed() const { return m_bParsed; }
XFA_AttributeValue GetVAlign(CXFA_TextProvider* pTextProvider) const;
- float GetTabInterval(CFX_CSSComputedStyle* pStyle) const;
- int32_t CountTabs(CFX_CSSComputedStyle* pStyle) const;
+ float GetTabInterval(const CFX_CSSComputedStyle* pStyle) const;
+ int32_t CountTabs(const CFX_CSSComputedStyle* pStyle) const;
- bool IsSpaceRun(CFX_CSSComputedStyle* pStyle) const;
- bool GetTabstops(CFX_CSSComputedStyle* pStyle,
+ bool IsSpaceRun(const CFX_CSSComputedStyle* pStyle) const;
+ bool GetTabstops(const CFX_CSSComputedStyle* pStyle,
CXFA_TextTabstopsContext* pTabstopContext);
RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* doc,
CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const;
+ const CFX_CSSComputedStyle* pStyle) const;
float GetFontSize(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const;
+ const CFX_CSSComputedStyle* pStyle) const;
int32_t GetHorScale(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
const CFX_XMLNode* pXMLNode) const;
int32_t GetVerScale(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const;
+ const CFX_CSSComputedStyle* pStyle) const;
void GetUnderline(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
int32_t& iUnderline,
XFA_AttributeValue& iPeriod) const;
void GetLinethrough(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
int32_t& iLinethrough) const;
FX_ARGB GetColor(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const;
+ const CFX_CSSComputedStyle* pStyle) const;
float GetBaseline(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle) const;
+ const CFX_CSSComputedStyle* pStyle) const;
float GetLineHeight(CXFA_TextProvider* pTextProvider,
- CFX_CSSComputedStyle* pStyle,
+ const CFX_CSSComputedStyle* pStyle,
bool bFirst,
float fVerScale) const;
@@ -118,10 +118,10 @@
void InitCSSData(CXFA_TextProvider* pTextProvider);
void ParseRichText(const CFX_XMLNode* pXMLNode,
- CFX_CSSComputedStyle* pParentStyle);
+ const CFX_CSSComputedStyle* pParentStyle);
std::unique_ptr<CFX_CSSStyleSheet> LoadDefaultSheetStyle();
RetainPtr<CFX_CSSComputedStyle> CreateStyle(
- CFX_CSSComputedStyle* pParentStyle);
+ const CFX_CSSComputedStyle* pParentStyle);
bool m_bParsed;
bool m_cssInitialized;