Simplify recursion in SyncRemoveLayoutItemChildren()

Avoid repeating the same logic in the caller as found in the body
of the function by operating on the item itself rather than just
its children. Rename to SyncRemoveLayoutItem() in the process.

Change-Id: I0a478cdf517035f605b4fa098ef34e05244dc7f2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56310
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
index 3e24bc3..5c3c385 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
@@ -243,19 +243,18 @@
   return nullptr;
 }
 
-void SyncRemoveLayoutItemChildren(CXFA_LayoutItem* pParentLayoutItem,
-                                  CXFA_FFNotify* pNotify,
-                                  CXFA_LayoutProcessor* pDocLayout) {
-  CXFA_LayoutItem* pNextLayoutItem;
-  CXFA_LayoutItem* pCurLayoutItem = pParentLayoutItem->GetFirstChild();
+void SyncRemoveLayoutItem(CXFA_LayoutItem* pLayoutItem,
+                          CXFA_FFNotify* pNotify,
+                          CXFA_LayoutProcessor* pDocLayout) {
+  CXFA_LayoutItem* pCurLayoutItem = pLayoutItem->GetFirstChild();
   while (pCurLayoutItem) {
-    pNextLayoutItem = pCurLayoutItem->GetNextSibling();
-    SyncRemoveLayoutItemChildren(pCurLayoutItem, pNotify, pDocLayout);
-    pNotify->OnLayoutItemRemoving(pDocLayout, pCurLayoutItem);
-    pCurLayoutItem->RemoveSelfIfParented();
-    delete pCurLayoutItem;
+    CXFA_LayoutItem* pNextLayoutItem = pCurLayoutItem->GetNextSibling();
+    SyncRemoveLayoutItem(pCurLayoutItem, pNotify, pDocLayout);
     pCurLayoutItem = pNextLayoutItem;
   }
+  pNotify->OnLayoutItemRemoving(pDocLayout, pLayoutItem);
+  pLayoutItem->RemoveSelfIfParented();
+  delete pLayoutItem;
 }
 
 bool RunBreakTestScript(CXFA_Script* pTestScript) {
@@ -1610,10 +1609,7 @@
             m_pTemplatePageSetRoot->GetDocument()->GetNotify();
         auto* pDocLayout = CXFA_LayoutProcessor::FromDocument(
             m_pTemplatePageSetRoot->GetDocument());
-        SyncRemoveLayoutItemChildren(pCurLayoutItem, pNotify, pDocLayout);
-        pNotify->OnLayoutItemRemoving(pDocLayout, pCurLayoutItem);
-        pCurLayoutItem->RemoveSelfIfParented();
-        delete pCurLayoutItem;
+        SyncRemoveLayoutItem(pCurLayoutItem, pNotify, pDocLayout);
         pCurLayoutItem = pNextLayoutItem;
         continue;
       }