Mark CFX_XMLNode pointers as const in various places.
Change-Id: I86c6f7526e2ef4c3e8de30ebaff223095ee70fc4
Reviewed-on: https://pdfium-review.googlesource.com/40811
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fxcrt/xml/cfx_xmltext.h b/core/fxcrt/xml/cfx_xmltext.h
index f7feae6..a8a5f12 100644
--- a/core/fxcrt/xml/cfx_xmltext.h
+++ b/core/fxcrt/xml/cfx_xmltext.h
@@ -31,7 +31,7 @@
WideString m_wsText;
};
-inline bool IsXMLText(CFX_XMLNode* pNode) {
+inline bool IsXMLText(const CFX_XMLNode* pNode) {
FX_XMLNODETYPE type = pNode->GetType();
return type == FX_XMLNODE_Text || type == FX_XMLNODE_CharData;
}
@@ -40,4 +40,9 @@
return pNode && IsXMLText(pNode) ? static_cast<CFX_XMLText*>(pNode) : nullptr;
}
+inline const CFX_XMLText* ToXMLText(const CFX_XMLNode* pNode) {
+ return pNode && IsXMLText(pNode) ? static_cast<const CFX_XMLText*>(pNode)
+ : nullptr;
+}
+
#endif // CORE_FXCRT_XML_CFX_XMLTEXT_H_
diff --git a/xfa/fxfa/cxfa_loadercontext.h b/xfa/fxfa/cxfa_loadercontext.h
index ff7c603..a6d8fb0 100644
--- a/xfa/fxfa/cxfa_loadercontext.h
+++ b/xfa/fxfa/cxfa_loadercontext.h
@@ -30,7 +30,7 @@
int32_t m_iLines;
int32_t m_iTotalLines;
uint32_t m_dwFlags;
- UnownedPtr<CFX_XMLNode> m_pXMLNode;
+ UnownedPtr<const CFX_XMLNode> m_pXMLNode;
UnownedPtr<CXFA_Node> m_pNode;
RetainPtr<CFX_CSSComputedStyle> m_pParentStyle;
std::vector<float> m_lineHeights;
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index 976988e..49cb13a 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -167,7 +167,7 @@
void CXFA_TextLayout::InitBreak(CFX_CSSComputedStyle* pStyle,
CFX_CSSDisplay eDisplay,
float fLineWidth,
- CFX_XMLNode* pXMLNode,
+ const CFX_XMLNode* pXMLNode,
CFX_CSSComputedStyle* pParentStyle) {
if (!pStyle) {
InitBreak(fLineWidth);
@@ -457,11 +457,11 @@
if (!pContainerNode)
return true;
- CFX_XMLNode* pXMLNode = m_pLoader->m_pXMLNode.Get();
+ const CFX_XMLNode* pXMLNode = m_pLoader->m_pXMLNode.Get();
if (!pXMLNode)
return true;
- CFX_XMLNode* pSaveXMLNode = pXMLNode;
+ const CFX_XMLNode* pSaveXMLNode = pXMLNode;
for (; pXMLNode; pXMLNode = pXMLNode->GetNextSibling()) {
if (!LoadRichText(pXMLNode, szText.width, &fLinePos,
m_pLoader->m_pParentStyle, true, nullptr, true, false,
@@ -624,27 +624,28 @@
}
}
-bool CXFA_TextLayout::Loader(float textWidth,
+void CXFA_TextLayout::Loader(float textWidth,
float* pLinePos,
bool bSavePieces) {
GetTextDataNode();
if (!m_pTextDataNode)
- return true;
+ return;
- if (m_bRichText) {
- CFX_XMLNode* pXMLContainer = GetXMLContainerNode();
- if (pXMLContainer) {
- if (!m_textParser.IsParsed())
- m_textParser.DoParse(pXMLContainer, m_pTextProvider);
-
- auto pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider);
- LoadRichText(pXMLContainer, textWidth, pLinePos, pRootStyle, bSavePieces,
- nullptr, true, false, 0);
- }
- } else {
+ if (!m_bRichText) {
LoadText(m_pTextDataNode, textWidth, pLinePos, bSavePieces);
+ return;
}
- return true;
+
+ const CFX_XMLNode* pXMLContainer = GetXMLContainerNode();
+ if (!pXMLContainer)
+ return;
+
+ if (!m_textParser.IsParsed())
+ m_textParser.DoParse(pXMLContainer, m_pTextProvider);
+
+ auto pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider);
+ LoadRichText(pXMLContainer, textWidth, pLinePos, pRootStyle, bSavePieces,
+ nullptr, true, false, 0);
}
void CXFA_TextLayout::LoadText(CXFA_Node* pNode,
@@ -683,7 +684,7 @@
}
bool CXFA_TextLayout::LoadRichText(
- CFX_XMLNode* pXMLNode,
+ const CFX_XMLNode* pXMLNode,
float textWidth,
float* pLinePos,
const RetainPtr<CFX_CSSComputedStyle>& pParentStyle,
@@ -705,7 +706,7 @@
if (bEndBreak) {
bool bCurOl = false;
bool bCurLi = false;
- CFX_XMLElement* pElement = nullptr;
+ const CFX_XMLElement* pElement = nullptr;
if (pContext) {
if (m_bBlockContinue ||
(m_pLoader && pXMLNode == m_pLoader->m_pXMLNode)) {
@@ -714,7 +715,7 @@
if (pXMLNode->GetType() == FX_XMLNODE_Text) {
bContentNode = true;
} else if (pXMLNode->GetType() == FX_XMLNODE_Element) {
- pElement = static_cast<CFX_XMLElement*>(pXMLNode);
+ pElement = static_cast<const CFX_XMLElement*>(pXMLNode);
wsName = pElement->GetLocalTagName();
}
if (wsName == L"ol") {
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index e8c56fd..9baf5ec 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -65,14 +65,14 @@
void InitBreak(CFX_CSSComputedStyle* pStyle,
CFX_CSSDisplay eDisplay,
float fLineWidth,
- CFX_XMLNode* pXMLNode,
+ const CFX_XMLNode* pXMLNode,
CFX_CSSComputedStyle* pParentStyle);
- bool Loader(float textWidth, float* pLinePos, bool bSavePieces);
+ void Loader(float textWidth, float* pLinePos, bool bSavePieces);
void LoadText(CXFA_Node* pNode,
float textWidth,
float* pLinePos,
bool bSavePieces);
- bool LoadRichText(CFX_XMLNode* pXMLNode,
+ bool LoadRichText(const CFX_XMLNode* pXMLNode,
float textWidth,
float* pLinePos,
const RetainPtr<CFX_CSSComputedStyle>& pParentStyle,
diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp
index 3084783..484e862 100644
--- a/xfa/fxfa/cxfa_textparser.cpp
+++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -192,7 +192,7 @@
}
RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::ComputeStyle(
- CFX_XMLNode* pXMLNode,
+ const CFX_XMLNode* pXMLNode,
CFX_CSSComputedStyle* pParentStyle) {
auto it = m_mapXMLNodeToParseContext.find(pXMLNode);
if (it == m_mapXMLNodeToParseContext.end())
@@ -215,7 +215,7 @@
return pStyle;
}
-void CXFA_TextParser::DoParse(CFX_XMLNode* pXMLContainer,
+void CXFA_TextParser::DoParse(const CFX_XMLNode* pXMLContainer,
CXFA_TextProvider* pTextProvider) {
if (!pXMLContainer || !pTextProvider || m_bParsed)
return;
@@ -226,7 +226,7 @@
ParseRichText(pXMLContainer, pRootStyle.Get());
}
-void CXFA_TextParser::ParseRichText(CFX_XMLNode* pXMLNode,
+void CXFA_TextParser::ParseRichText(const CFX_XMLNode* pXMLNode,
CFX_CSSComputedStyle* pParentStyle) {
if (!pXMLNode)
return;
@@ -285,10 +285,11 @@
FX_HashCode_GetW(wsName.AsStringView(), true));
}
+// static
std::unique_ptr<CXFA_TextParser::TagProvider> CXFA_TextParser::ParseTagInfo(
- CFX_XMLNode* pXMLNode) {
+ const CFX_XMLNode* pXMLNode) {
auto tagProvider = pdfium::MakeUnique<TagProvider>();
- CFX_XMLElement* pXMLElement = ToXMLElement(pXMLNode);
+ const CFX_XMLElement* pXMLElement = ToXMLElement(pXMLNode);
if (pXMLElement) {
WideString wsName = pXMLElement->GetLocalTagName();
tagProvider->SetTagName(wsName);
@@ -377,7 +378,7 @@
int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider,
CFX_CSSComputedStyle* pStyle,
- CFX_XMLNode* pXMLNode) const {
+ const CFX_XMLNode* pXMLNode) const {
if (pStyle) {
WideString wsValue;
if (pStyle->GetCustomStyle(L"xfa-font-horizontal-scale", wsValue))
@@ -538,7 +539,7 @@
}
CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap(
- CFX_XMLNode* pXMLNode) {
+ const CFX_XMLNode* pXMLNode) {
auto it = m_mapXMLNodeToParseContext.find(pXMLNode);
return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr;
}
diff --git a/xfa/fxfa/cxfa_textparser.h b/xfa/fxfa/cxfa_textparser.h
index 70c153b..842eba7 100644
--- a/xfa/fxfa/cxfa_textparser.h
+++ b/xfa/fxfa/cxfa_textparser.h
@@ -33,12 +33,13 @@
virtual ~CXFA_TextParser();
void Reset();
- void DoParse(CFX_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider);
+ void DoParse(const CFX_XMLNode* pXMLContainer,
+ CXFA_TextProvider* pTextProvider);
RetainPtr<CFX_CSSComputedStyle> CreateRootStyle(
CXFA_TextProvider* pTextProvider);
RetainPtr<CFX_CSSComputedStyle> ComputeStyle(
- CFX_XMLNode* pXMLNode,
+ const CFX_XMLNode* pXMLNode,
CFX_CSSComputedStyle* pParentStyle);
bool IsParsed() const { return m_bParsed; }
@@ -60,7 +61,7 @@
int32_t GetHorScale(CXFA_TextProvider* pTextProvider,
CFX_CSSComputedStyle* pStyle,
- CFX_XMLNode* pXMLNode) const;
+ const CFX_XMLNode* pXMLNode) const;
int32_t GetVerScale(CXFA_TextProvider* pTextProvider,
CFX_CSSComputedStyle* pStyle) const;
@@ -82,7 +83,7 @@
Optional<WideString> GetEmbeddedObj(const CXFA_TextProvider* pTextProvider,
const CFX_XMLNode* pXMLNode);
- CXFA_TextParseContext* GetParseContextFromMap(CFX_XMLNode* pXMLNode);
+ CXFA_TextParseContext* GetParseContextFromMap(const CFX_XMLNode* pXMLNode);
protected:
bool TagValidate(const WideString& str) const;
@@ -112,9 +113,12 @@
std::map<WideString, WideString> m_Attributes;
};
+ // static
+ std::unique_ptr<TagProvider> ParseTagInfo(const CFX_XMLNode* pXMLNode);
+
void InitCSSData(CXFA_TextProvider* pTextProvider);
- void ParseRichText(CFX_XMLNode* pXMLNode, CFX_CSSComputedStyle* pParentStyle);
- std::unique_ptr<TagProvider> ParseTagInfo(CFX_XMLNode* pXMLNode);
+ void ParseRichText(const CFX_XMLNode* pXMLNode,
+ CFX_CSSComputedStyle* pParentStyle);
std::unique_ptr<CFX_CSSStyleSheet> LoadDefaultSheetStyle();
RetainPtr<CFX_CSSComputedStyle> CreateStyle(
CFX_CSSComputedStyle* pParentStyle);
@@ -122,7 +126,7 @@
bool m_bParsed;
bool m_cssInitialized;
std::unique_ptr<CFX_CSSStyleSelector> m_pSelector;
- std::map<CFX_XMLNode*, std::unique_ptr<CXFA_TextParseContext>>
+ std::map<const CFX_XMLNode*, std::unique_ptr<CXFA_TextParseContext>>
m_mapXMLNodeToParseContext;
};