From 03fdf3a2b5ee0974be13a9594a897003df412306 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 22 Aug 2018 16:14:49 +0000 Subject: Mark CFX_XMLNode pointers as const in various places. Change-Id: I86c6f7526e2ef4c3e8de30ebaff223095ee70fc4 Reviewed-on: https://pdfium-review.googlesource.com/40811 Commit-Queue: Lei Zhang Reviewed-by: Ryan Harrison --- core/fxcrt/xml/cfx_xmltext.h | 7 ++++++- xfa/fxfa/cxfa_loadercontext.h | 2 +- xfa/fxfa/cxfa_textlayout.cpp | 41 +++++++++++++++++++++-------------------- xfa/fxfa/cxfa_textlayout.h | 6 +++--- xfa/fxfa/cxfa_textparser.cpp | 15 ++++++++------- xfa/fxfa/cxfa_textparser.h | 18 +++++++++++------- 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(pNode) : nullptr; } +inline const CFX_XMLText* ToXMLText(const CFX_XMLNode* pNode) { + return pNode && IsXMLText(pNode) ? static_cast(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 m_pXMLNode; + UnownedPtr m_pXMLNode; UnownedPtr m_pNode; RetainPtr m_pParentStyle; std::vector 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& 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(pXMLNode); + pElement = static_cast(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& 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 CXFA_TextParser::CreateStyle( } RetainPtr 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 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::ParseTagInfo( - CFX_XMLNode* pXMLNode) { + const CFX_XMLNode* pXMLNode) { auto tagProvider = pdfium::MakeUnique(); - 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 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 CreateRootStyle( CXFA_TextProvider* pTextProvider); RetainPtr 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 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 m_Attributes; }; + // static + std::unique_ptr ParseTagInfo(const CFX_XMLNode* pXMLNode); + void InitCSSData(CXFA_TextProvider* pTextProvider); - void ParseRichText(CFX_XMLNode* pXMLNode, CFX_CSSComputedStyle* pParentStyle); - std::unique_ptr ParseTagInfo(CFX_XMLNode* pXMLNode); + void ParseRichText(const CFX_XMLNode* pXMLNode, + CFX_CSSComputedStyle* pParentStyle); std::unique_ptr LoadDefaultSheetStyle(); RetainPtr CreateStyle( CFX_CSSComputedStyle* pParentStyle); @@ -122,7 +126,7 @@ class CXFA_TextParser { bool m_bParsed; bool m_cssInitialized; std::unique_ptr m_pSelector; - std::map> + std::map> m_mapXMLNodeToParseContext; }; -- cgit v1.2.3