Shuffle more code out of CXFA_Node

This CL moves more code out of the CXFA_Node class and into specific
subclasses.

Change-Id: Idca36f251431bf7efd4da045aeabf097ab23f0ce
Reviewed-on: https://pdfium-review.googlesource.com/24714
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/xfa/fxfa/cxfa_ffbarcode.h b/xfa/fxfa/cxfa_ffbarcode.h
index df62b8e..7804ce3 100644
--- a/xfa/fxfa/cxfa_ffbarcode.h
+++ b/xfa/fxfa/cxfa_ffbarcode.h
@@ -90,7 +90,7 @@
  public:
   static const BarCodeInfo* GetBarcodeTypeByName(const WideString& wsName);
 
-  explicit CXFA_FFBarcode(CXFA_Node* pNode, CXFA_Barcode* barcode);
+  CXFA_FFBarcode(CXFA_Node* pNode, CXFA_Barcode* barcode);
   ~CXFA_FFBarcode() override;
 
   // CXFA_FFTextEdit
diff --git a/xfa/fxfa/cxfa_ffcheckbutton.cpp b/xfa/fxfa/cxfa_ffcheckbutton.cpp
index 57233a0..f5f8408 100644
--- a/xfa/fxfa/cxfa_ffcheckbutton.cpp
+++ b/xfa/fxfa/cxfa_ffcheckbutton.cpp
@@ -82,7 +82,7 @@
         dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle;
     } break;
   }
-  if (m_pNode->IsAllowNeutral())
+  if (button_->IsAllowNeutral())
     dwStyleEx |= FWL_STYLEEXT_CKB_3State;
 
   pCheckBox->ModifyStylesEx(
diff --git a/xfa/fxfa/cxfa_ffcheckbutton.h b/xfa/fxfa/cxfa_ffcheckbutton.h
index d1fb21c..12519a9 100644
--- a/xfa/fxfa/cxfa_ffcheckbutton.h
+++ b/xfa/fxfa/cxfa_ffcheckbutton.h
@@ -16,7 +16,7 @@
 
 class CXFA_FFCheckButton : public CXFA_FFField {
  public:
-  explicit CXFA_FFCheckButton(CXFA_Node* pNode, CXFA_CheckButton* button);
+  CXFA_FFCheckButton(CXFA_Node* pNode, CXFA_CheckButton* button);
   ~CXFA_FFCheckButton() override;
 
   // CXFA_FFField
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp
index a929e1a..6802fd3 100644
--- a/xfa/fxfa/cxfa_ffnotify.cpp
+++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -37,8 +37,10 @@
 #include "xfa/fxfa/cxfa_textprovider.h"
 #include "xfa/fxfa/parser/cxfa_barcode.h"
 #include "xfa/fxfa/parser/cxfa_binditems.h"
+#include "xfa/fxfa/parser/cxfa_button.h"
 #include "xfa/fxfa/parser/cxfa_checkbutton.h"
 #include "xfa/fxfa/parser/cxfa_node.h"
+#include "xfa/fxfa/parser/cxfa_passwordedit.h"
 
 namespace {
 
@@ -118,9 +120,12 @@
       pWidget = new CXFA_FFBarcode(pNode, static_cast<CXFA_Barcode*>(child));
       break;
     }
-    case XFA_FFWidgetType::kButton:
-      pWidget = new CXFA_FFPushButton(pNode);
+    case XFA_FFWidgetType::kButton: {
+      CXFA_Node* child = pNode->GetUIChildNode();
+      ASSERT(child->GetElementType() == XFA_Element::Button);
+      pWidget = new CXFA_FFPushButton(pNode, static_cast<CXFA_Button*>(child));
       break;
+    }
     case XFA_FFWidgetType::kCheckButton: {
       CXFA_Node* child = pNode->GetUIChildNode();
       ASSERT(child->GetElementType() == XFA_Element::CheckButton);
@@ -143,9 +148,13 @@
     case XFA_FFWidgetType::kNumericEdit:
       pWidget = new CXFA_FFNumericEdit(pNode);
       break;
-    case XFA_FFWidgetType::kPasswordEdit:
-      pWidget = new CXFA_FFPasswordEdit(pNode);
+    case XFA_FFWidgetType::kPasswordEdit: {
+      CXFA_Node* child = pNode->GetUIChildNode();
+      ASSERT(child->GetElementType() == XFA_Element::PasswordEdit);
+      pWidget = new CXFA_FFPasswordEdit(pNode,
+                                        static_cast<CXFA_PasswordEdit*>(child));
       break;
+    }
     case XFA_FFWidgetType::kSignature:
       pWidget = new CXFA_FFSignature(pNode);
       break;
diff --git a/xfa/fxfa/cxfa_ffpasswordedit.cpp b/xfa/fxfa/cxfa_ffpasswordedit.cpp
index 4dc46c6..f49a990 100644
--- a/xfa/fxfa/cxfa_ffpasswordedit.cpp
+++ b/xfa/fxfa/cxfa_ffpasswordedit.cpp
@@ -12,9 +12,11 @@
 #include "xfa/fwl/cfwl_notedriver.h"
 #include "xfa/fxfa/cxfa_ffdoc.h"
 #include "xfa/fxfa/parser/cxfa_node.h"
+#include "xfa/fxfa/parser/cxfa_passwordedit.h"
 
-CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_Node* pNode)
-    : CXFA_FFTextEdit(pNode) {}
+CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_Node* pNode,
+                                         CXFA_PasswordEdit* password_node)
+    : CXFA_FFTextEdit(pNode), password_node_(password_node) {}
 
 CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {}
 
@@ -49,7 +51,7 @@
                              FWL_STYLEEXT_EDT_Password;
   dwExtendedStyle |= UpdateUIProperty();
 
-  WideString password = m_pNode->GetPasswordChar();
+  WideString password = password_node_->GetPasswordChar();
   if (!password.IsEmpty())
     pWidget->SetAliasChar(password[0]);
   if (!m_pNode->IsHorizontalScrollPolicyOff())
diff --git a/xfa/fxfa/cxfa_ffpasswordedit.h b/xfa/fxfa/cxfa_ffpasswordedit.h
index 28528cd..8f5093f 100644
--- a/xfa/fxfa/cxfa_ffpasswordedit.h
+++ b/xfa/fxfa/cxfa_ffpasswordedit.h
@@ -7,16 +7,22 @@
 #ifndef XFA_FXFA_CXFA_FFPASSWORDEDIT_H_
 #define XFA_FXFA_CXFA_FFPASSWORDEDIT_H_
 
+#include "core/fxcrt/unowned_ptr.h"
 #include "xfa/fxfa/cxfa_fftextedit.h"
 
+class CXFA_PasswordEdit;
+
 class CXFA_FFPasswordEdit : public CXFA_FFTextEdit {
  public:
-  explicit CXFA_FFPasswordEdit(CXFA_Node* pNode);
+  CXFA_FFPasswordEdit(CXFA_Node* pNode, CXFA_PasswordEdit* password_node);
   ~CXFA_FFPasswordEdit() override;
 
   // CXFA_FFTextEdit
   bool LoadWidget() override;
   void UpdateWidgetProperty() override;
+
+ private:
+  UnownedPtr<CXFA_PasswordEdit> password_node_;
 };
 
 #endif  // XFA_FXFA_CXFA_FFPASSWORDEDIT_H_
diff --git a/xfa/fxfa/cxfa_ffpushbutton.cpp b/xfa/fxfa/cxfa_ffpushbutton.cpp
index d0611bb..7c556b8 100644
--- a/xfa/fxfa/cxfa_ffpushbutton.cpp
+++ b/xfa/fxfa/cxfa_ffpushbutton.cpp
@@ -19,13 +19,14 @@
 #include "xfa/fxfa/cxfa_textlayout.h"
 #include "xfa/fxfa/cxfa_textprovider.h"
 #include "xfa/fxfa/parser/cxfa_border.h"
+#include "xfa/fxfa/parser/cxfa_button.h"
 #include "xfa/fxfa/parser/cxfa_caption.h"
 #include "xfa/fxfa/parser/cxfa_edge.h"
 #include "xfa/fxgraphics/cxfa_gecolor.h"
 #include "xfa/fxgraphics/cxfa_gepath.h"
 
-CXFA_FFPushButton::CXFA_FFPushButton(CXFA_Node* pNode)
-    : CXFA_FFField(pNode), m_pOldDelegate(nullptr) {}
+CXFA_FFPushButton::CXFA_FFPushButton(CXFA_Node* pNode, CXFA_Button* button)
+    : CXFA_FFField(pNode), button_(button) {}
 
 CXFA_FFPushButton::~CXFA_FFPushButton() {
   CXFA_FFPushButton::UnloadWidget();
@@ -71,7 +72,7 @@
 
 void CXFA_FFPushButton::UpdateWidgetProperty() {
   uint32_t dwStyleEx = 0;
-  switch (m_pNode->GetButtonHighlight()) {
+  switch (button_->GetHighlight()) {
     case XFA_AttributeEnum::Inverted:
       dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteInverted;
       break;
diff --git a/xfa/fxfa/cxfa_ffpushbutton.h b/xfa/fxfa/cxfa_ffpushbutton.h
index d0b0b88..e247ee5 100644
--- a/xfa/fxfa/cxfa_ffpushbutton.h
+++ b/xfa/fxfa/cxfa_ffpushbutton.h
@@ -9,18 +9,20 @@
 
 #include <memory>
 
+#include "core/fxcrt/unowned_ptr.h"
 #include "xfa/fxfa/cxfa_fffield.h"
 
 #define XFA_FWL_PSBSTYLEEXT_HiliteInverted (1L << 0)
 #define XFA_FWL_PSBSTYLEEXT_HilitePush (1L << 1)
 #define XFA_FWL_PSBSTYLEEXT_HiliteOutLine (1L << 2)
 
+class CXFA_Button;
 class CXFA_TextLayout;
 class CXFA_TextProvider;
 
 class CXFA_FFPushButton : public CXFA_FFField {
  public:
-  explicit CXFA_FFPushButton(CXFA_Node* pNode);
+  CXFA_FFPushButton(CXFA_Node* pNode, CXFA_Button* button);
   ~CXFA_FFPushButton() override;
 
   // CXFA_FFField
@@ -49,7 +51,8 @@
   std::unique_ptr<CXFA_TextLayout> m_pDownTextLayout;
   std::unique_ptr<CXFA_TextProvider> m_pRollProvider;
   std::unique_ptr<CXFA_TextProvider> m_pDownProvider;
-  IFWL_WidgetDelegate* m_pOldDelegate;
+  IFWL_WidgetDelegate* m_pOldDelegate = nullptr;
+  UnownedPtr<CXFA_Button> button_;
 };
 
 #endif  // XFA_FXFA_CXFA_FFPUSHBUTTON_H_
diff --git a/xfa/fxfa/parser/cxfa_button.cpp b/xfa/fxfa/parser/cxfa_button.cpp
index 7b56d2b..4a951b3 100644
--- a/xfa/fxfa/parser/cxfa_button.cpp
+++ b/xfa/fxfa/parser/cxfa_button.cpp
@@ -41,3 +41,7 @@
 XFA_FFWidgetType CXFA_Button::GetDefaultFFWidgetType() const {
   return XFA_FFWidgetType::kButton;
 }
+
+XFA_AttributeEnum CXFA_Button::GetHighlight() {
+  return JSObject()->GetEnum(XFA_Attribute::Highlight);
+}
diff --git a/xfa/fxfa/parser/cxfa_button.h b/xfa/fxfa/parser/cxfa_button.h
index 75d62a6..cea685f 100644
--- a/xfa/fxfa/parser/cxfa_button.h
+++ b/xfa/fxfa/parser/cxfa_button.h
@@ -15,6 +15,8 @@
   ~CXFA_Button() override;
 
   XFA_FFWidgetType GetDefaultFFWidgetType() const override;
+
+  XFA_AttributeEnum GetHighlight();
 };
 
 #endif  // XFA_FXFA_PARSER_CXFA_BUTTON_H_
diff --git a/xfa/fxfa/parser/cxfa_checkbutton.cpp b/xfa/fxfa/parser/cxfa_checkbutton.cpp
index 59afe5a..6b5fa8f 100644
--- a/xfa/fxfa/parser/cxfa_checkbutton.cpp
+++ b/xfa/fxfa/parser/cxfa_checkbutton.cpp
@@ -55,3 +55,7 @@
 XFA_AttributeEnum CXFA_CheckButton::GetMark() {
   return JSObject()->GetEnum(XFA_Attribute::Mark);
 }
+
+bool CXFA_CheckButton::IsAllowNeutral() {
+  return JSObject()->GetBoolean(XFA_Attribute::AllowNeutral);
+}
diff --git a/xfa/fxfa/parser/cxfa_checkbutton.h b/xfa/fxfa/parser/cxfa_checkbutton.h
index b603dd0..e239a46 100644
--- a/xfa/fxfa/parser/cxfa_checkbutton.h
+++ b/xfa/fxfa/parser/cxfa_checkbutton.h
@@ -17,6 +17,7 @@
   XFA_FFWidgetType GetDefaultFFWidgetType() const override;
 
   bool IsRound();
+  bool IsAllowNeutral();
   XFA_AttributeEnum GetMark();
 };
 
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 0c28f4b..451c98f 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -3523,13 +3523,6 @@
                                                  dwFontStyle);
 }
 
-XFA_AttributeEnum CXFA_Node::GetButtonHighlight() {
-  CXFA_Node* pUIChild = GetUIChildNode();
-  if (pUIChild)
-    return pUIChild->JSObject()->GetEnum(XFA_Attribute::Highlight);
-  return XFA_AttributeEnum::Inverted;
-}
-
 bool CXFA_Node::HasButtonRollover() {
   CXFA_Items* pItems = GetChild<CXFA_Items>(0, XFA_Element::Items, false);
   if (!pItems)
@@ -3571,12 +3564,6 @@
   return CXFA_Measurement(10, XFA_Unit::Pt).ToUnit(XFA_Unit::Pt);
 }
 
-bool CXFA_Node::IsAllowNeutral() {
-  CXFA_Node* pUIChild = GetUIChildNode();
-  return pUIChild &&
-         pUIChild->JSObject()->GetBoolean(XFA_Attribute::AllowNeutral);
-}
-
 XFA_CHECKSTATE CXFA_Node::GetCheckState() {
   WideString wsValue = GetRawValue();
   if (wsValue.IsEmpty())
@@ -4232,12 +4219,6 @@
   return {};
 }
 
-WideString CXFA_Node::GetPasswordChar() {
-  CXFA_Node* pUIChild = GetUIChildNode();
-  return pUIChild ? pUIChild->JSObject()->GetCData(XFA_Attribute::PasswordChar)
-                  : L"*";
-}
-
 bool CXFA_Node::IsMultiLine() {
   CXFA_Node* pUIChild = GetUIChildNode();
   return pUIChild && pUIChild->JSObject()->GetBoolean(XFA_Attribute::MultiLine);
@@ -4327,13 +4308,11 @@
 
       bSyncData = true;
     }
-  } else {
-    if (eType == XFA_Element::NumericEdit) {
-      if (wsNewText != L"0")
-        wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits());
+  } else if (eType == XFA_Element::NumericEdit) {
+    if (wsNewText != L"0")
+      wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits());
 
-      bSyncData = true;
-    }
+    bSyncData = true;
   }
   if (eType != XFA_Element::NumericEdit || bSyncData)
     SyncValue(wsNewText, true);
@@ -4432,7 +4411,7 @@
   if (!pNode)
     return wsValue;
 
-  switch (GetUIChildNode()->GetElementType()) {
+  switch (pNode->GetElementType()) {
     case XFA_Element::ChoiceList: {
       if (eValueType == XFA_VALUEPICTURE_Display) {
         int32_t iSelItemIndex = GetSelectedItem(0);
@@ -4441,7 +4420,8 @@
           wsPicture.clear();
         }
       }
-    } break;
+      break;
+    }
     case XFA_Element::NumericEdit:
       if (eValueType != XFA_VALUEPICTURE_Raw && wsPicture.IsEmpty()) {
         IFX_Locale* pLocale = GetLocale();
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 819b2f9..dfe5ab0 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -310,11 +310,9 @@
   RetainPtr<CFGAS_GEFont> GetFDEFont(CXFA_FFDoc* doc);
 
   bool IsListBox();
-  bool IsAllowNeutral();
   bool IsRadioButton();
   bool IsMultiLine();
 
-  XFA_AttributeEnum GetButtonHighlight();
   bool HasButtonRollover();
   bool HasButtonDown();
 
@@ -375,7 +373,6 @@
   WideString GetFormatDataValue(const WideString& wsValue);
   WideString NormalizeNumStr(const WideString& wsValue);
 
-  WideString GetPasswordChar();
   std::pair<XFA_Element, int32_t> GetMaxChars();
   int32_t GetFracDigits();
   int32_t GetLeadDigits();
diff --git a/xfa/fxfa/parser/cxfa_passwordedit.cpp b/xfa/fxfa/parser/cxfa_passwordedit.cpp
index 68267af..6d38c34 100644
--- a/xfa/fxfa/parser/cxfa_passwordedit.cpp
+++ b/xfa/fxfa/parser/cxfa_passwordedit.cpp
@@ -43,3 +43,7 @@
 XFA_FFWidgetType CXFA_PasswordEdit::GetDefaultFFWidgetType() const {
   return XFA_FFWidgetType::kPasswordEdit;
 }
+
+WideString CXFA_PasswordEdit::GetPasswordChar() {
+  return JSObject()->GetCData(XFA_Attribute::PasswordChar);
+}
diff --git a/xfa/fxfa/parser/cxfa_passwordedit.h b/xfa/fxfa/parser/cxfa_passwordedit.h
index e390aaa..6c8e8e5 100644
--- a/xfa/fxfa/parser/cxfa_passwordedit.h
+++ b/xfa/fxfa/parser/cxfa_passwordedit.h
@@ -15,6 +15,7 @@
   ~CXFA_PasswordEdit() override;
 
   XFA_FFWidgetType GetDefaultFFWidgetType() const override;
+  WideString GetPasswordChar();
 };
 
 #endif  // XFA_FXFA_PARSER_CXFA_PASSWORDEDIT_H_