Add more CXFA_*::FromNode() static methods.

Remove some knowledge of class to enum mappings from callers.

Change-Id: I576e03324042f804d009d784c57fc9132deafbef
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/94013
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp
index e12c5cb..6263cf5 100644
--- a/xfa/fxfa/cxfa_ffnotify.cpp
+++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -104,33 +104,30 @@
   CXFA_FFWidget* pWidget = nullptr;
   switch (pNode->GetFFWidgetType()) {
     case XFA_FFWidgetType::kBarcode: {
-      CXFA_Node* child = pNode->GetUIChildNode();
-      if (child->GetElementType() != XFA_Element::Barcode)
+      auto* child = CXFA_Barcode::FromNode(pNode->GetUIChildNode());
+      if (!child)
         return nullptr;
 
       pWidget = cppgc::MakeGarbageCollected<CXFA_FFBarcode>(
-          m_pDoc->GetHeap()->GetAllocationHandle(), pNode,
-          static_cast<CXFA_Barcode*>(child));
+          m_pDoc->GetHeap()->GetAllocationHandle(), pNode, child);
       break;
     }
     case XFA_FFWidgetType::kButton: {
-      CXFA_Node* child = pNode->GetUIChildNode();
-      if (child->GetElementType() != XFA_Element::Button)
+      auto* child = CXFA_Button::FromNode(pNode->GetUIChildNode());
+      if (!child)
         return nullptr;
 
       pWidget = cppgc::MakeGarbageCollected<CXFA_FFPushButton>(
-          m_pDoc->GetHeap()->GetAllocationHandle(), pNode,
-          static_cast<CXFA_Button*>(child));
+          m_pDoc->GetHeap()->GetAllocationHandle(), pNode, child);
       break;
     }
     case XFA_FFWidgetType::kCheckButton: {
-      CXFA_Node* child = pNode->GetUIChildNode();
-      if (child->GetElementType() != XFA_Element::CheckButton)
+      auto* child = CXFA_CheckButton::FromNode(pNode->GetUIChildNode());
+      if (!child)
         return nullptr;
 
       pWidget = cppgc::MakeGarbageCollected<CXFA_FFCheckButton>(
-          m_pDoc->GetHeap()->GetAllocationHandle(), pNode,
-          static_cast<CXFA_CheckButton*>(child));
+          m_pDoc->GetHeap()->GetAllocationHandle(), pNode, child);
       break;
     }
     case XFA_FFWidgetType::kChoiceList: {
@@ -156,13 +153,12 @@
           m_pDoc->GetHeap()->GetAllocationHandle(), pNode);
       break;
     case XFA_FFWidgetType::kPasswordEdit: {
-      CXFA_Node* child = pNode->GetUIChildNode();
-      if (child->GetElementType() != XFA_Element::PasswordEdit)
+      auto* child = CXFA_PasswordEdit::FromNode(pNode->GetUIChildNode());
+      if (!child)
         return nullptr;
 
       pWidget = cppgc::MakeGarbageCollected<CXFA_FFPasswordEdit>(
-          m_pDoc->GetHeap()->GetAllocationHandle(), pNode,
-          static_cast<CXFA_PasswordEdit*>(child));
+          m_pDoc->GetHeap()->GetAllocationHandle(), pNode, child);
       break;
     }
     case XFA_FFWidgetType::kSignature:
diff --git a/xfa/fxfa/parser/cxfa_barcode.cpp b/xfa/fxfa/parser/cxfa_barcode.cpp
index 0b3636f..8e98115 100644
--- a/xfa/fxfa/parser/cxfa_barcode.cpp
+++ b/xfa/fxfa/parser/cxfa_barcode.cpp
@@ -42,6 +42,13 @@
 
 }  // namespace
 
+// static
+CXFA_Barcode* CXFA_Barcode::FromNode(CXFA_Node* pNode) {
+  return pNode && pNode->GetElementType() == XFA_Element::Barcode
+             ? static_cast<CXFA_Barcode*>(pNode)
+             : nullptr;
+}
+
 CXFA_Barcode::CXFA_Barcode(CXFA_Document* doc, XFA_PacketType packet)
     : CXFA_Node(doc,
                 packet,
diff --git a/xfa/fxfa/parser/cxfa_barcode.h b/xfa/fxfa/parser/cxfa_barcode.h
index d0f7e16..7fbcfa3 100644
--- a/xfa/fxfa/parser/cxfa_barcode.h
+++ b/xfa/fxfa/parser/cxfa_barcode.h
@@ -12,6 +12,8 @@
 
 class CXFA_Barcode final : public CXFA_Node {
  public:
+  static CXFA_Barcode* FromNode(CXFA_Node* pNode);
+
   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
   ~CXFA_Barcode() override;
 
diff --git a/xfa/fxfa/parser/cxfa_button.cpp b/xfa/fxfa/parser/cxfa_button.cpp
index f6e7f40..d906b07 100644
--- a/xfa/fxfa/parser/cxfa_button.cpp
+++ b/xfa/fxfa/parser/cxfa_button.cpp
@@ -25,6 +25,13 @@
 
 }  // namespace
 
+// static
+CXFA_Button* CXFA_Button::FromNode(CXFA_Node* pNode) {
+  return pNode && pNode->GetElementType() == XFA_Element::Button
+             ? static_cast<CXFA_Button*>(pNode)
+             : nullptr;
+}
+
 CXFA_Button::CXFA_Button(CXFA_Document* doc, XFA_PacketType packet)
     : CXFA_Node(doc,
                 packet,
diff --git a/xfa/fxfa/parser/cxfa_button.h b/xfa/fxfa/parser/cxfa_button.h
index 56f25b6..b4e19f3 100644
--- a/xfa/fxfa/parser/cxfa_button.h
+++ b/xfa/fxfa/parser/cxfa_button.h
@@ -11,6 +11,8 @@
 
 class CXFA_Button final : public CXFA_Node {
  public:
+  static CXFA_Button* FromNode(CXFA_Node* pNode);
+
   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
   ~CXFA_Button() override;
 
diff --git a/xfa/fxfa/parser/cxfa_checkbutton.cpp b/xfa/fxfa/parser/cxfa_checkbutton.cpp
index 850fd40..90c6468 100644
--- a/xfa/fxfa/parser/cxfa_checkbutton.cpp
+++ b/xfa/fxfa/parser/cxfa_checkbutton.cpp
@@ -31,6 +31,13 @@
 
 }  // namespace
 
+// static
+CXFA_CheckButton* CXFA_CheckButton::FromNode(CXFA_Node* pNode) {
+  return pNode && pNode->GetElementType() == XFA_Element::CheckButton
+             ? static_cast<CXFA_CheckButton*>(pNode)
+             : nullptr;
+}
+
 CXFA_CheckButton::CXFA_CheckButton(CXFA_Document* doc, XFA_PacketType packet)
     : CXFA_Node(doc,
                 packet,
diff --git a/xfa/fxfa/parser/cxfa_checkbutton.h b/xfa/fxfa/parser/cxfa_checkbutton.h
index e2eb482..9f2a8fc 100644
--- a/xfa/fxfa/parser/cxfa_checkbutton.h
+++ b/xfa/fxfa/parser/cxfa_checkbutton.h
@@ -11,6 +11,8 @@
 
 class CXFA_CheckButton final : public CXFA_Node {
  public:
+  static CXFA_CheckButton* FromNode(CXFA_Node* pNode);
+
   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
   ~CXFA_CheckButton() override;
 
diff --git a/xfa/fxfa/parser/cxfa_passwordedit.cpp b/xfa/fxfa/parser/cxfa_passwordedit.cpp
index f793b8d..24a2a6c 100644
--- a/xfa/fxfa/parser/cxfa_passwordedit.cpp
+++ b/xfa/fxfa/parser/cxfa_passwordedit.cpp
@@ -28,6 +28,13 @@
 
 }  // namespace
 
+// static
+CXFA_PasswordEdit* CXFA_PasswordEdit::FromNode(CXFA_Node* pNode) {
+  return pNode && pNode->GetElementType() == XFA_Element::PasswordEdit
+             ? static_cast<CXFA_PasswordEdit*>(pNode)
+             : nullptr;
+}
+
 CXFA_PasswordEdit::CXFA_PasswordEdit(CXFA_Document* doc, XFA_PacketType packet)
     : CXFA_Node(doc,
                 packet,
diff --git a/xfa/fxfa/parser/cxfa_passwordedit.h b/xfa/fxfa/parser/cxfa_passwordedit.h
index 4ac090c..259bfdd 100644
--- a/xfa/fxfa/parser/cxfa_passwordedit.h
+++ b/xfa/fxfa/parser/cxfa_passwordedit.h
@@ -11,6 +11,8 @@
 
 class CXFA_PasswordEdit final : public CXFA_Node {
  public:
+  static CXFA_PasswordEdit* FromNode(CXFA_Node* pNode);
+
   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
   ~CXFA_PasswordEdit() override;