summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-22 16:14:49 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-22 16:14:49 +0000
commit03fdf3a2b5ee0974be13a9594a897003df412306 (patch)
tree3ba4cb34ef92e4245c6e81835760a76dc34418c7
parentb9509d740966e16a94dc456c634b3f1005e8be95 (diff)
downloadpdfium-03fdf3a2b5ee0974be13a9594a897003df412306.tar.xz
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>
-rw-r--r--core/fxcrt/xml/cfx_xmltext.h7
-rw-r--r--xfa/fxfa/cxfa_loadercontext.h2
-rw-r--r--xfa/fxfa/cxfa_textlayout.cpp41
-rw-r--r--xfa/fxfa/cxfa_textlayout.h6
-rw-r--r--xfa/fxfa/cxfa_textparser.cpp15
-rw-r--r--xfa/fxfa/cxfa_textparser.h18
6 files changed, 50 insertions, 39 deletions
diff --git a/core/fxcrt/xml/cfx_xmltext.h b/core/fxcrt/xml/cfx_xmltext.h
index f7feae669e..a8a5f12a53 100644
--- a/core/fxcrt/xml/cfx_xmltext.h
+++ b/core/fxcrt/xml/cfx_xmltext.h
@@ -31,7 +31,7 @@ class CFX_XMLText : public CFX_XMLNode {
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 @@ inline CFX_XMLText* ToXMLText(CFX_XMLNode* pNode) {
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 ff7c6032a8..a6d8fb0eeb 100644
--- a/xfa/fxfa/cxfa_loadercontext.h
+++ b/xfa/fxfa/cxfa_loadercontext.h
@@ -30,7 +30,7 @@ class CXFA_LoaderContext {
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 976988ee32..49cb13a714 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -167,7 +167,7 @@ void CXFA_TextLayout::InitBreak(float fLineWidth) {
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 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) {
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 @@ void CXFA_TextLayout::UpdateAlign(float fHeight, float fBottom) {
}
}
-bool CXFA_TextLayout::Loader(float textWidth,
+void CXFA_TextLayout::Loader(float textWidth,
float* pLinePos,
bool bSavePieces) {
GetTextDataNode();
if (!m_pTextDataNode)
- return true;
-
- if (m_bRichText) {
- CFX_XMLNode* pXMLContainer = GetXMLContainerNode();
- if (pXMLContainer) {
- if (!m_textParser.IsParsed())
- m_textParser.DoParse(pXMLContainer, m_pTextProvider);
+ return;
- 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 @@ void CXFA_TextLayout::LoadText(CXFA_Node* pNode,
}
bool CXFA_TextLayout::LoadRichText(
- CFX_XMLNode* pXMLNode,
+ const CFX_XMLNode* pXMLNode,
float textWidth,
float* pLinePos,
const RetainPtr<CFX_CSSComputedStyle>& pParentStyle,
@@ -705,7 +706,7 @@ bool CXFA_TextLayout::LoadRichText(
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 @@ bool CXFA_TextLayout::LoadRichText(
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 e8c56fd1fc..9baf5ec76d 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -65,14 +65,14 @@ class CXFA_TextLayout {
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 3084783a83..484e862510 100644
--- a/xfa/fxfa/cxfa_textparser.cpp
+++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -192,7 +192,7 @@ RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::CreateStyle(
}
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 @@ RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::ComputeStyle(
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 @@ void CXFA_TextParser::DoParse(CFX_XMLNode* pXMLContainer,
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 @@ bool CXFA_TextParser::TagValidate(const WideString& wsName) const {
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 @@ float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider,
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 @@ Optional<WideString> CXFA_TextParser::GetEmbeddedObj(
}
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 70c153bfab..842eba74fa 100644
--- a/xfa/fxfa/cxfa_textparser.h
+++ b/xfa/fxfa/cxfa_textparser.h
@@ -33,12 +33,13 @@ class CXFA_TextParser {
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 @@ class CXFA_TextParser {
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 @@ class CXFA_TextParser {
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 @@ class CXFA_TextParser {
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 @@ class CXFA_TextParser {
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;
};