Split off code from CXFA_ItemLayoutProcessor::GotoNextContainerNode().
Move a couple blocks into their own handler methods. Get rid of a goto
statement as a result.
Change-Id: I2658899f2b251547d832abd82f5af1d37b83c454
Reviewed-on: https://pdfium-review.googlesource.com/c/50652
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
index 7327010..d61db05 100644
--- a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
+++ b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
@@ -871,22 +871,9 @@
FALLTHROUGH;
case Stage::kBreakBefore:
- if (*pCurActionNode) {
- CXFA_Node* pBreakBeforeNode = (*pCurActionNode)->GetNextSibling();
- if (!m_bKeepBreakFinish) {
- ret = FindBreakNode(pBreakBeforeNode, true, pCurActionNode);
- if (ret.has_value())
- return ret.value();
- }
- if (m_bIsProcessKeep) {
- ret = ProcessKeepNodesForBreakBefore(pCurActionNode, pChildContainer);
- if (ret.has_value())
- return ret.value();
- goto CheckNextChildContainer;
- }
- *pCurActionNode = pChildContainer;
- return Stage::kContainer;
- }
+ ret = HandleBreakBefore(pChildContainer, pCurActionNode);
+ if (ret.has_value())
+ return ret.value();
goto CheckNextChildContainer;
case Stage::kContainer:
@@ -899,35 +886,11 @@
return ret.value();
CheckNextChildContainer : {
- CXFA_Node* pNextChildContainer =
- pChildContainer ? pChildContainer->GetNextContainerSibling()
- : pParentContainer->GetFirstContainerChild();
- while (pNextChildContainer &&
- pNextChildContainer->IsLayoutGeneratedNode()) {
- CXFA_Node* pSaveNode = pNextChildContainer;
- pNextChildContainer = pNextChildContainer->GetNextContainerSibling();
- if (pSaveNode->IsUnusedNode())
- DeleteLayoutGeneratedNode(pSaveNode);
- }
- if (!pNextChildContainer)
- goto NoMoreChildContainer;
-
- bool bLastKeep = false;
- ret = ProcessKeepNodesForCheckNext(pCurActionNode, &pNextChildContainer,
- &bLastKeep);
+ ret = HandleCheckNextChildContainer(pParentContainer, pChildContainer,
+ pCurActionNode);
if (ret.has_value())
return ret.value();
- if (!m_bKeepBreakFinish && !bLastKeep) {
- ret = FindBreakNode(pNextChildContainer->GetFirstChild(), true,
- pCurActionNode);
- if (ret.has_value())
- return ret.value();
- }
- *pCurActionNode = pNextChildContainer;
- return m_bIsProcessKeep ? Stage::kKeep : Stage::kContainer;
- }
- NoMoreChildContainer : {
*pCurActionNode = nullptr;
FALLTHROUGH;
case Stage::kBookendTrailer:
@@ -936,6 +899,7 @@
return ret.value();
}
FALLTHROUGH;
+
default:
*pCurActionNode = nullptr;
return Stage::kDone;
@@ -2759,6 +2723,25 @@
}
Optional<CXFA_ItemLayoutProcessor::Stage>
+CXFA_ItemLayoutProcessor::HandleBreakBefore(CXFA_Node* pChildContainer,
+ CXFA_Node** pCurActionNode) {
+ if (!*pCurActionNode)
+ return {};
+
+ CXFA_Node* pBreakBeforeNode = (*pCurActionNode)->GetNextSibling();
+ if (!m_bKeepBreakFinish) {
+ Optional<Stage> ret = FindBreakNode(pBreakBeforeNode, true, pCurActionNode);
+ if (ret.has_value())
+ return ret.value();
+ }
+ if (m_bIsProcessKeep)
+ return ProcessKeepNodesForBreakBefore(pCurActionNode, pChildContainer);
+
+ *pCurActionNode = pChildContainer;
+ return Stage::kContainer;
+}
+
+Optional<CXFA_ItemLayoutProcessor::Stage>
CXFA_ItemLayoutProcessor::HandleBreakAfter(CXFA_Node* pChildContainer,
CXFA_Node** pCurActionNode) {
if (*pCurActionNode) {
@@ -2771,6 +2754,39 @@
}
Optional<CXFA_ItemLayoutProcessor::Stage>
+CXFA_ItemLayoutProcessor::HandleCheckNextChildContainer(
+ CXFA_Node* pParentContainer,
+ CXFA_Node* pChildContainer,
+ CXFA_Node** pCurActionNode) {
+ CXFA_Node* pNextChildContainer =
+ pChildContainer ? pChildContainer->GetNextContainerSibling()
+ : pParentContainer->GetFirstContainerChild();
+ while (pNextChildContainer && pNextChildContainer->IsLayoutGeneratedNode()) {
+ CXFA_Node* pSaveNode = pNextChildContainer;
+ pNextChildContainer = pNextChildContainer->GetNextContainerSibling();
+ if (pSaveNode->IsUnusedNode())
+ DeleteLayoutGeneratedNode(pSaveNode);
+ }
+ if (!pNextChildContainer)
+ return {};
+
+ bool bLastKeep = false;
+ Optional<Stage> ret = ProcessKeepNodesForCheckNext(
+ pCurActionNode, &pNextChildContainer, &bLastKeep);
+ if (ret.has_value())
+ return ret.value();
+
+ if (!m_bKeepBreakFinish && !bLastKeep) {
+ ret = FindBreakNode(pNextChildContainer->GetFirstChild(), true,
+ pCurActionNode);
+ if (ret.has_value())
+ return ret.value();
+ }
+ *pCurActionNode = pNextChildContainer;
+ return m_bIsProcessKeep ? Stage::kKeep : Stage::kContainer;
+}
+
+Optional<CXFA_ItemLayoutProcessor::Stage>
CXFA_ItemLayoutProcessor::HandleBookendTrailer(CXFA_Node* pParentContainer,
CXFA_Node** pCurActionNode) {
for (CXFA_Node* pBookendNode = *pCurActionNode
diff --git a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.h b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.h
index 53cd71d..539b205 100644
--- a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.h
+++ b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.h
@@ -166,8 +166,13 @@
CXFA_Node** pCurActionNode);
Optional<Stage> HandleBookendLeader(CXFA_Node* pParentContainer,
CXFA_Node** pCurActionNode);
+ Optional<Stage> HandleBreakBefore(CXFA_Node* pChildContainer,
+ CXFA_Node** pCurActionNode);
Optional<Stage> HandleBreakAfter(CXFA_Node* pChildContainer,
CXFA_Node** pCurActionNode);
+ Optional<Stage> HandleCheckNextChildContainer(CXFA_Node* pParentContainer,
+ CXFA_Node* pChildContainer,
+ CXFA_Node** pCurActionNode);
Optional<Stage> HandleBookendTrailer(CXFA_Node* pParentContainer,
CXFA_Node** pCurActionNode);
void ProcessKeepNodesEnd();