Tidy cxfa_layoutpagemgr.cpp before adding more RemoveLayoutItem() calls.

- Pass some arguments as superclass.
- Move XFA_ReleaseLayoutItem_NoPageArea() to cxfa_layoutitem.cpp to be
  near nearly identical piece of logic.

Change-Id: I90d3fbbd1a3d08fe7144645bd6ac0c251f096819
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/54110
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/layout/cxfa_layoutitem.cpp b/xfa/fxfa/layout/cxfa_layoutitem.cpp
index 4677c34..00debb1 100644
--- a/xfa/fxfa/layout/cxfa_layoutitem.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutitem.cpp
@@ -34,6 +34,21 @@
   delete pLayoutItem;
 }
 
+void XFA_ReleaseLayoutItem_NoPageArea(CXFA_LayoutItem* pLayoutItem) {
+  CXFA_LayoutItem* pNode = pLayoutItem->GetFirstChild();
+  while (pNode) {
+    CXFA_LayoutItem* pNext = pNode->GetNextSibling();
+    XFA_ReleaseLayoutItem_NoPageArea(pNode);
+    pNode = pNext;
+  }
+  if (pLayoutItem->GetFormNode()->GetElementType() == XFA_Element::PageArea)
+    return;
+
+  if (pLayoutItem->GetParent())
+    pLayoutItem->GetParent()->RemoveChild(pLayoutItem);
+  delete pLayoutItem;
+}
+
 CXFA_LayoutItem::CXFA_LayoutItem(CXFA_Node* pNode, ItemType type)
     : m_ItemType(type), m_pFormNode(pNode) {}
 
diff --git a/xfa/fxfa/layout/cxfa_layoutitem.h b/xfa/fxfa/layout/cxfa_layoutitem.h
index 3dd6754..b735b66 100644
--- a/xfa/fxfa/layout/cxfa_layoutitem.h
+++ b/xfa/fxfa/layout/cxfa_layoutitem.h
@@ -63,5 +63,6 @@
 }
 
 void XFA_ReleaseLayoutItem(CXFA_LayoutItem* pLayoutItem);
+void XFA_ReleaseLayoutItem_NoPageArea(CXFA_LayoutItem* pLayoutItem);
 
 #endif  // XFA_FXFA_LAYOUT_CXFA_LAYOUTITEM_H_
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
index 917e748..7863e6e 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
@@ -158,9 +158,8 @@
   }
 }
 
-void ReorderLayoutItemToTail(CXFA_ViewLayoutItem* pLayoutItem) {
-  CXFA_ViewLayoutItem* pParentLayoutItem =
-      ToViewLayoutItem(pLayoutItem->GetParent());
+void ReorderLayoutItemToTail(CXFA_LayoutItem* pLayoutItem) {
+  CXFA_LayoutItem* pParentLayoutItem = pLayoutItem->GetParent();
   if (!pParentLayoutItem)
     return;
 
@@ -168,9 +167,8 @@
   pParentLayoutItem->AddChild(pLayoutItem);
 }
 
-void RemoveLayoutItem(CXFA_ViewLayoutItem* pLayoutItem) {
-  CXFA_ViewLayoutItem* pParentLayoutItem =
-      ToViewLayoutItem(pLayoutItem->GetParent());
+void RemoveLayoutItem(CXFA_LayoutItem* pLayoutItem) {
+  CXFA_LayoutItem* pParentLayoutItem = pLayoutItem->GetParent();
   if (!pParentLayoutItem)
     return;
 
@@ -1937,18 +1935,6 @@
   ClearData();
 }
 
-void XFA_ReleaseLayoutItem_NoPageArea(CXFA_LayoutItem* pLayoutItem) {
-  CXFA_LayoutItem* pNode = pLayoutItem->GetFirstChild();
-  while (pNode) {
-    CXFA_LayoutItem* pNext = pNode->GetNextSibling();
-    pNode->SetParent(nullptr);
-    XFA_ReleaseLayoutItem_NoPageArea(pNode);
-    pNode = pNext;
-  }
-  if (pLayoutItem->GetFormNode()->GetElementType() != XFA_Element::PageArea)
-    delete pLayoutItem;
-}
-
 void CXFA_LayoutPageMgr::PrepareLayout() {
   m_pPageSetCurRoot = nullptr;
   m_ePageSetMode = XFA_AttributeValue::OrderedOccurrence;