Return a CXFA_Node* from CXFA_LayoutPageMgr::ProcessBookendLeaderOrTrailer().
There is no need to return a bool and pass the CXFA_Node* via an out
parameter. Also:
- Make the in-parameter, as well as parts of CJX_Object, const.
- Make ProcessBookendLeaderOrTrailer() private, and add public
ProcessBookendLeader() / ProcessBookendTrailer() methods.
Change-Id: I862bd1ba408e62729a3eb9bedb2bb29546ecc434
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/49417
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 1ea2eb3..e69d5e5 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -432,7 +432,7 @@
return measure.ToUnit(unit);
}
-WideString CJX_Object::GetCData(XFA_Attribute eAttr) {
+WideString CJX_Object::GetCData(XFA_Attribute eAttr) const {
return TryCData(eAttr, true).value_or(WideString());
}
@@ -499,7 +499,7 @@
}
Optional<WideString> CJX_Object::TryCData(XFA_Attribute eAttr,
- bool bUseDefault) {
+ bool bUseDefault) const {
void* pKey = GetMapKey_Element(GetXFAObject()->GetElementType(), eAttr);
if (eAttr == XFA_Attribute::Value) {
void* pData;
@@ -911,7 +911,7 @@
return {};
}
-Optional<WideString> CJX_Object::GetMapModuleString(void* pKey) {
+Optional<WideString> CJX_Object::GetMapModuleString(void* pKey) const {
void* pRawValue;
int32_t iBytes;
if (!GetMapModuleBuffer(pKey, &pRawValue, &iBytes))
diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h
index 7b8ffbc..a348cb7 100644
--- a/fxjs/xfa/cjx_object.h
+++ b/fxjs/xfa/cjx_object.h
@@ -179,12 +179,12 @@
void SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify);
int32_t GetInteger(XFA_Attribute eAttr);
- Optional<WideString> TryCData(XFA_Attribute eAttr, bool bUseDefault);
+ Optional<WideString> TryCData(XFA_Attribute eAttr, bool bUseDefault) const;
void SetCData(XFA_Attribute eAttr,
const WideString& wsValue,
bool bNotify,
bool bScriptModify);
- WideString GetCData(XFA_Attribute eAttr);
+ WideString GetCData(XFA_Attribute eAttr) const;
Optional<XFA_AttributeValue> TryEnum(XFA_Attribute eAttr,
bool bUseDefault) const;
@@ -246,7 +246,7 @@
XFA_MAPMODULEDATA* GetMapModuleData() const;
void SetMapModuleValue(void* pKey, void* pValue);
Optional<void*> GetMapModuleValue(void* pKey) const;
- Optional<WideString> GetMapModuleString(void* pKey);
+ Optional<WideString> GetMapModuleString(void* pKey) const;
void SetMapModuleBuffer(void* pKey,
void* pValue,
int32_t iBytes,
diff --git a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
index 56c193b..cf49fff 100644
--- a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
+++ b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
@@ -1787,13 +1787,15 @@
goto SuspendAndCreateNewRow;
}
case Stage::kBookendLeader: {
- CXFA_Node* pLeaderNode = nullptr;
if (m_pCurChildPreprocessor) {
pProcessor = std::move(m_pCurChildPreprocessor);
- } else if (m_pPageMgr && m_pPageMgr->ProcessBookendLeaderOrTrailer(
- m_pCurChildNode, true, pLeaderNode)) {
- pProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(
- pLeaderNode, m_pPageMgr.Get());
+ } else if (m_pPageMgr) {
+ CXFA_Node* pLeaderNode =
+ m_pPageMgr->ProcessBookendLeader(m_pCurChildNode);
+ if (pLeaderNode) {
+ pProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(
+ pLeaderNode, m_pPageMgr.Get());
+ }
}
if (pProcessor) {
@@ -1813,13 +1815,15 @@
break;
}
case Stage::kBookendTrailer: {
- CXFA_Node* pTrailerNode = nullptr;
if (m_pCurChildPreprocessor) {
pProcessor = std::move(m_pCurChildPreprocessor);
- } else if (m_pPageMgr && m_pPageMgr->ProcessBookendLeaderOrTrailer(
- m_pCurChildNode, false, pTrailerNode)) {
- pProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(
- pTrailerNode, m_pPageMgr.Get());
+ } else if (m_pPageMgr) {
+ CXFA_Node* pTrailerNode =
+ m_pPageMgr->ProcessBookendTrailer(m_pCurChildNode);
+ if (pTrailerNode) {
+ pProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(
+ pTrailerNode, m_pPageMgr.Get());
+ }
}
if (pProcessor) {
if (InsertFlowedItem(pProcessor.get(), bContainerWidthAutoSize,
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
index 61303ca..2d6da94 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
@@ -882,27 +882,36 @@
return true;
}
-bool CXFA_LayoutPageMgr::ProcessBookendLeaderOrTrailer(
- CXFA_Node* pBookendNode,
- bool bLeader,
- CXFA_Node*& pBookendAppendNode) {
+CXFA_Node* CXFA_LayoutPageMgr::ProcessBookendLeader(
+ const CXFA_Node* pBookendNode) {
+ return ProcessBookendLeaderOrTrailer(pBookendNode, /*leader=*/true);
+}
+
+CXFA_Node* CXFA_LayoutPageMgr::ProcessBookendTrailer(
+ const CXFA_Node* pBookendNode) {
+ return ProcessBookendLeaderOrTrailer(pBookendNode, /*leader=*/false);
+}
+
+CXFA_Node* CXFA_LayoutPageMgr::ProcessBookendLeaderOrTrailer(
+ const CXFA_Node* pBookendNode,
+ bool bLeader) {
CXFA_Node* pLeaderTemplate = nullptr;
CXFA_Node* pFormNode = pBookendNode->GetContainerParent();
if (!ResolveBookendLeaderOrTrailer(pBookendNode, bLeader, pLeaderTemplate) ||
!pLeaderTemplate) {
- return false;
+ return nullptr;
}
CXFA_Document* pDocument = pBookendNode->GetDocument();
CXFA_Node* pDataScope = XFA_DataMerge_FindDataScope(pFormNode);
- pBookendAppendNode = pDocument->DataMerge_CopyContainer(
+ CXFA_Node* pBookendAppendNode = pDocument->DataMerge_CopyContainer(
pLeaderTemplate, pFormNode, pDataScope, true, true, true);
if (!pBookendAppendNode)
- return false;
+ return nullptr;
pDocument->DataMerge_UpdateBindingRelations(pBookendAppendNode);
SetLayoutGeneratedNodeFlag(pBookendAppendNode);
- return true;
+ return pBookendAppendNode;
}
CXFA_Node* CXFA_LayoutPageMgr::BreakOverflow(CXFA_Node* pOverflowNode,
@@ -1044,7 +1053,7 @@
}
bool CXFA_LayoutPageMgr::ResolveBookendLeaderOrTrailer(
- CXFA_Node* pBookendNode,
+ const CXFA_Node* pBookendNode,
bool bLeader,
CXFA_Node*& pBookendAppendTemplate) {
CXFA_Node* pContainer =
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.h b/xfa/fxfa/layout/cxfa_layoutpagemgr.h
index e41f73a..f54e2bb 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.h
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.h
@@ -48,9 +48,8 @@
bool bDataMerge,
bool bCreatePage);
CXFA_Node* QueryOverflow(CXFA_Node* pFormNode);
- bool ProcessBookendLeaderOrTrailer(CXFA_Node* pBookendNode,
- bool bLeader,
- CXFA_Node*& pBookendAppendNode);
+ CXFA_Node* ProcessBookendLeader(const CXFA_Node* pBookendNode);
+ CXFA_Node* ProcessBookendTrailer(const CXFA_Node* pBookendNode);
private:
bool AppendNewPage(bool bFirstTemPage);
@@ -79,7 +78,9 @@
CXFA_Node*& pLeaderTemplate,
CXFA_Node*& pTrailerTemplate,
bool bCreatePage);
- bool ResolveBookendLeaderOrTrailer(CXFA_Node* pBookendNode,
+ CXFA_Node* ProcessBookendLeaderOrTrailer(const CXFA_Node* pBookendNode,
+ bool bLeader);
+ bool ResolveBookendLeaderOrTrailer(const CXFA_Node* pBookendNode,
bool bLeader,
CXFA_Node*& pBookendAppendTemplate);
bool ExecuteBreakBeforeOrAfter(CXFA_Node* pCurNode,