Simplify CXFA_NodeHelper::GetParent() and callers.

- Most callers become calls with CXFA_Node::GetParent(), possibly with a
  nullptr check.
- Remaining use case for CXFA_NodeHelper::GetParent() is simplified, so
  it can become GetTransparentParent() in an anonymous namespace.

Change-Id: I65fd52b18e5b207d6fc239f833ed5177222fdf7c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52370
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/xfa/cfxjse_resolveprocessor.cpp b/fxjs/xfa/cfxjse_resolveprocessor.cpp
index c8eeb77..92de697 100644
--- a/fxjs/xfa/cfxjse_resolveprocessor.cpp
+++ b/fxjs/xfa/cfxjse_resolveprocessor.cpp
@@ -374,8 +374,7 @@
     CXFA_Node* pProp = nullptr;
     if (XFA_Element::Subform == curNode->GetElementType() &&
         XFA_HASHCODE_Occur == uNameHash) {
-      CXFA_Node* pInstanceManager =
-          curNode->AsNode()->GetInstanceMgrOfSubform();
+      CXFA_Node* pInstanceManager = curNode->GetInstanceMgrOfSubform();
       if (pInstanceManager) {
         pProp = pInstanceManager->JSObject()->GetOrCreateProperty<CXFA_Occur>(
             0, XFA_Element::Occur);
@@ -383,10 +382,9 @@
     } else {
       XFA_Element eType = XFA_GetElementByName(wsName.AsStringView());
       if (eType == XFA_Element::PageSet) {
-        pProp = curNode->AsNode()->JSObject()->GetProperty<CXFA_Node>(0, eType);
+        pProp = curNode->JSObject()->GetProperty<CXFA_Node>(0, eType);
       } else if (eType != XFA_Element::Unknown) {
-        pProp = curNode->AsNode()->JSObject()->GetOrCreateProperty<CXFA_Node>(
-            0, eType);
+        pProp = curNode->JSObject()->GetOrCreateProperty<CXFA_Node>(0, eType);
       }
     }
     if (pProp) {
@@ -395,12 +393,11 @@
     }
   }
 
-  CXFA_Node* parentNode =
-      CXFA_NodeHelper::GetParent(curNode->AsNode(), XFA_LOGIC_NoTransparent);
+  CXFA_Node* parentNode = curNode->GetParent();
   uint32_t uCurClassHash = curNode->GetClassHashCode();
   if (!parentNode) {
     if (uCurClassHash == uNameHash) {
-      rnd.m_Objects.emplace_back(curNode->AsNode());
+      rnd.m_Objects.emplace_back(curNode);
       FilterCondition(wsCondition, &rnd);
       if (!rnd.m_Objects.empty())
         return true;
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.cpp b/xfa/fxfa/parser/cxfa_nodehelper.cpp
index 167aa02..c9aba3d 100644
--- a/xfa/fxfa/parser/cxfa_nodehelper.cpp
+++ b/xfa/fxfa/parser/cxfa_nodehelper.cpp
@@ -151,6 +151,24 @@
                                 false));
 }
 
+CXFA_Node* GetTransparentParent(CXFA_Node* pNode) {
+  CXFA_Node* parent;
+  CXFA_Node* node = pNode;
+  while (true) {
+    parent = node ? node->GetParent() : nullptr;
+    if (!parent)
+      return nullptr;
+
+    XFA_Element parentType = parent->GetElementType();
+    if ((!parent->IsUnnamed() && parentType != XFA_Element::SubformSet) ||
+        parentType == XFA_Element::Variables) {
+      break;
+    }
+    node = parent;
+  }
+  return parent;
+}
+
 }  // namespace
 
 CXFA_NodeHelper::CXFA_NodeHelper() = default;
@@ -183,14 +201,12 @@
                                                      XFA_LOGIC_TYPE eLogicType,
                                                      bool bIsClassName) {
   std::vector<CXFA_Node*> siblings;
-  if (!pNode)
-    return siblings;
-  CXFA_Node* parent = GetParent(pNode, XFA_LOGIC_NoTransparent);
+  CXFA_Node* parent = pNode ? pNode->GetParent() : nullptr;
   if (!parent)
     return siblings;
   if (!parent->HasProperty(pNode->GetElementType()) &&
       eLogicType == XFA_LOGIC_Transparent) {
-    parent = GetParent(pNode, XFA_LOGIC_Transparent);
+    parent = GetTransparentParent(pNode);
     if (!parent)
       return siblings;
   }
@@ -203,42 +219,16 @@
 }
 
 // static
-CXFA_Node* CXFA_NodeHelper::GetParent(CXFA_Node* pNode,
-                                      XFA_LOGIC_TYPE eLogicType) {
-  if (!pNode)
-    return nullptr;
-
-  if (eLogicType == XFA_LOGIC_NoTransparent)
-    return pNode->GetParent();
-
-  CXFA_Node* parent;
-  CXFA_Node* node = pNode;
-  while (true) {
-    parent = GetParent(node, XFA_LOGIC_NoTransparent);
-    if (!parent)
-      return nullptr;
-
-    XFA_Element parentType = parent->GetElementType();
-    if ((!parent->IsUnnamed() && parentType != XFA_Element::SubformSet) ||
-        parentType == XFA_Element::Variables) {
-      break;
-    }
-    node = parent;
-  }
-  return parent;
-}
-
-// static
 size_t CXFA_NodeHelper::GetIndex(CXFA_Node* pNode,
                                  XFA_LOGIC_TYPE eLogicType,
                                  bool bIsProperty,
                                  bool bIsClassIndex) {
-  CXFA_Node* parent = GetParent(pNode, XFA_LOGIC_NoTransparent);
+  CXFA_Node* parent = pNode ? pNode->GetParent() : nullptr;
   if (!parent)
     return 0;
 
   if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) {
-    parent = GetParent(pNode, XFA_LOGIC_Transparent);
+    parent = GetTransparentParent(pNode);
     if (!parent)
       return 0;
   }
@@ -257,13 +247,13 @@
 // static
 WideString CXFA_NodeHelper::GetNameExpression(CXFA_Node* refNode) {
   WideString wsName = GetNameExpressionSinglePath(refNode);
-  CXFA_Node* parent = GetParent(refNode, XFA_LOGIC_NoTransparent);
+  CXFA_Node* parent = refNode ? refNode->GetParent() : nullptr;
   while (parent) {
     WideString wsParent = GetNameExpressionSinglePath(parent);
     wsParent += L".";
     wsParent += wsName;
     wsName = std::move(wsParent);
-    parent = GetParent(parent, XFA_LOGIC_NoTransparent);
+    parent = parent->GetParent();
   }
   return wsName;
 }
@@ -397,9 +387,6 @@
 
 // static
 bool CXFA_NodeHelper::NodeIsProperty(CXFA_Node* refNode) {
-  if (!refNode)
-    return false;
-
-  CXFA_Node* parent = GetParent(refNode, XFA_LOGIC_NoTransparent);
+  CXFA_Node* parent = refNode ? refNode->GetParent() : nullptr;
   return parent && parent->HasProperty(refNode->GetElementType());
 }
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.h b/xfa/fxfa/parser/cxfa_nodehelper.h
index c349d7e..c04178c 100644
--- a/xfa/fxfa/parser/cxfa_nodehelper.h
+++ b/xfa/fxfa/parser/cxfa_nodehelper.h
@@ -30,8 +30,6 @@
   static CXFA_Node* GetOneChildOfClass(CXFA_Node* parent,
                                        WideStringView wsClass);
 
-  static CXFA_Node* GetParent(CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType);
-
   static std::vector<CXFA_Node*> GetSiblings(CXFA_Node* pNode,
                                              XFA_LOGIC_TYPE eLogicType,
                                              bool bIsClassName);