Move Script_Som_*Message methods to CJX_Object

The CJX_Node isn't the root of the CJX hierarchy. This causes issues
now that CJX_Object has child objects which don't inherit from CJX_Node.
This CL moves Script_Som_*Message from CJX_Node to CJX_Object.

Change-Id: I04b7e03aa78d14d7d5dba1926a808cef852d5218
Reviewed-on: https://pdfium-review.googlesource.com/20992
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index ff65c38..7a0d132 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -575,67 +575,6 @@
                                    bool bSetting,
                                    XFA_Attribute eAttribute) {}
 
-void CJX_Node::Script_Som_Message(CFXJSE_Value* pValue,
-                                  bool bSetting,
-                                  XFA_SOM_MESSAGETYPE iMessageType) {
-  CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
-  if (!pWidgetData)
-    return;
-
-  bool bNew = false;
-  CXFA_ValidateData validateData = pWidgetData->GetValidateData(false);
-  if (!validateData.HasValidNode()) {
-    validateData = pWidgetData->GetValidateData(true);
-    bNew = true;
-  }
-
-  if (bSetting) {
-    switch (iMessageType) {
-      case XFA_SOM_ValidationMessage:
-        validateData.SetScriptMessageText(pValue->ToWideString());
-        break;
-      case XFA_SOM_FormatMessage:
-        validateData.SetFormatMessageText(pValue->ToWideString());
-        break;
-      case XFA_SOM_MandatoryMessage:
-        validateData.SetNullMessageText(pValue->ToWideString());
-        break;
-      default:
-        break;
-    }
-    if (!bNew) {
-      CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
-      if (!pNotify) {
-        return;
-      }
-      pNotify->AddCalcValidate(GetXFANode());
-    }
-    return;
-  }
-
-  WideString wsMessage;
-  switch (iMessageType) {
-    case XFA_SOM_ValidationMessage:
-      wsMessage = validateData.GetScriptMessageText();
-      break;
-    case XFA_SOM_FormatMessage:
-      wsMessage = validateData.GetFormatMessageText();
-      break;
-    case XFA_SOM_MandatoryMessage:
-      wsMessage = validateData.GetNullMessageText();
-      break;
-    default:
-      break;
-  }
-  pValue->SetString(wsMessage.UTF8Encode().AsStringView());
-}
-
-void CJX_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
-                                            bool bSetting,
-                                            XFA_Attribute eAttribute) {
-  Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
-}
-
 void CJX_Node::Script_Field_Length(CFXJSE_Value* pValue,
                                    bool bSetting,
                                    XFA_Attribute eAttribute) {
@@ -878,12 +817,6 @@
       pWidgetData->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView());
 }
 
-void CJX_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
-                                          bool bSetting,
-                                          XFA_Attribute eAttribute) {
-  Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
-}
-
 void CJX_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
                                            bool bSetting,
                                            XFA_Attribute eAttribute) {
@@ -917,12 +850,6 @@
   pValue->SetString(str.UTF8Encode().AsStringView());
 }
 
-void CJX_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
-                                           bool bSetting,
-                                           XFA_Attribute eAttribute) {
-  Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
-}
-
 void CJX_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
                                           bool bSetting,
                                           XFA_Attribute eAttribute) {
diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h
index bfc0fa4..3d8f4df 100644
--- a/fxjs/xfa/cjx_node.h
+++ b/fxjs/xfa/cjx_node.h
@@ -16,12 +16,6 @@
 #include "fxjs/xfa/cjx_tree.h"
 #include "xfa/fxfa/fxfa_basic.h"
 
-enum XFA_SOM_MESSAGETYPE {
-  XFA_SOM_ValidationMessage,
-  XFA_SOM_FormatMessage,
-  XFA_SOM_MandatoryMessage
-};
-
 class CXFA_LayoutItem;
 class CXFA_Node;
 class CXFA_WidgetData;
@@ -104,9 +98,6 @@
   void Script_Delta_Target(CFXJSE_Value* pValue,
                            bool bSetting,
                            XFA_Attribute eAttribute);
-  void Script_Som_ValidationMessage(CFXJSE_Value* pValue,
-                                    bool bSetting,
-                                    XFA_Attribute eAttribute);
   void Script_Field_Length(CFXJSE_Value* pValue,
                            bool bSetting,
                            XFA_Attribute eAttribute);
@@ -119,18 +110,12 @@
   void Script_Boolean_Value(CFXJSE_Value* pValue,
                             bool bSetting,
                             XFA_Attribute eAttribute);
-  void Script_Som_Message(CFXJSE_Value* pValue,
-                          bool bSetting,
-                          XFA_SOM_MESSAGETYPE iMessageType);
   void Script_Som_DataNode(CFXJSE_Value* pValue,
                            bool bSetting,
                            XFA_Attribute eAttribute);
   void Script_Som_Mandatory(CFXJSE_Value* pValue,
                             bool bSetting,
                             XFA_Attribute eAttribute);
-  void Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
-                                   bool bSetting,
-                                   XFA_Attribute eAttribute);
   void Script_Som_InstanceIndex(CFXJSE_Value* pValue,
                                 bool bSetting,
                                 XFA_Attribute eAttribute);
@@ -143,9 +128,6 @@
   void Script_Field_EditValue(CFXJSE_Value* pValue,
                               bool bSetting,
                               XFA_Attribute eAttribute);
-  void Script_Field_FormatMessage(CFXJSE_Value* pValue,
-                                  bool bSetting,
-                                  XFA_Attribute eAttribute);
   void Script_Field_FormattedValue(CFXJSE_Value* pValue,
                                    bool bSetting,
                                    XFA_Attribute eAttribute);
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 1d94b55..1f4f77a 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -1035,3 +1035,75 @@
         CXFA_Measurement(wsThickness.AsStringView()));
   }
 }
+
+void CJX_Object::Script_Som_Message(CFXJSE_Value* pValue,
+                                    bool bSetting,
+                                    XFA_SOM_MESSAGETYPE iMessageType) {
+  if (!widget_data_)
+    return;
+
+  bool bNew = false;
+  CXFA_ValidateData validateData = widget_data_->GetValidateData(false);
+  if (!validateData.HasValidNode()) {
+    validateData = widget_data_->GetValidateData(true);
+    bNew = true;
+  }
+
+  if (bSetting) {
+    switch (iMessageType) {
+      case XFA_SOM_ValidationMessage:
+        validateData.SetScriptMessageText(pValue->ToWideString());
+        break;
+      case XFA_SOM_FormatMessage:
+        validateData.SetFormatMessageText(pValue->ToWideString());
+        break;
+      case XFA_SOM_MandatoryMessage:
+        validateData.SetNullMessageText(pValue->ToWideString());
+        break;
+      default:
+        break;
+    }
+    if (!bNew) {
+      CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
+      if (!pNotify) {
+        return;
+      }
+      pNotify->AddCalcValidate(ToNode(GetXFAObject()));
+    }
+    return;
+  }
+
+  WideString wsMessage;
+  switch (iMessageType) {
+    case XFA_SOM_ValidationMessage:
+      wsMessage = validateData.GetScriptMessageText();
+      break;
+    case XFA_SOM_FormatMessage:
+      wsMessage = validateData.GetFormatMessageText();
+      break;
+    case XFA_SOM_MandatoryMessage:
+      wsMessage = validateData.GetNullMessageText();
+      break;
+    default:
+      break;
+  }
+  pValue->SetString(wsMessage.UTF8Encode().AsStringView());
+}
+
+void CJX_Object::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
+                                              bool bSetting,
+                                              XFA_Attribute eAttribute) {
+  Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
+}
+
+void CJX_Object::Script_Field_FormatMessage(CFXJSE_Value* pValue,
+                                            bool bSetting,
+                                            XFA_Attribute eAttribute) {
+  Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
+}
+
+void CJX_Object::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
+                                             bool bSetting,
+                                             XFA_Attribute eAttribute) {
+  Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
+}
diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h
index e29081c..1263bf8 100644
--- a/fxjs/xfa/cjx_object.h
+++ b/fxjs/xfa/cjx_object.h
@@ -104,6 +104,15 @@
   void Script_Som_BorderWidth(CFXJSE_Value* pValue,
                               bool bSetting,
                               XFA_Attribute eAttribute);
+  void Script_Som_ValidationMessage(CFXJSE_Value* pValue,
+                                    bool bSetting,
+                                    XFA_Attribute eAttribute);
+  void Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
+                                   bool bSetting,
+                                   XFA_Attribute eAttribute);
+  void Script_Field_FormatMessage(CFXJSE_Value* pValue,
+                                  bool bSetting,
+                                  XFA_Attribute eAttribute);
 
   pdfium::Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault);
   bool SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify);
@@ -153,6 +162,15 @@
   void ThrowException(const wchar_t* str, ...) const;
 
  private:
+  enum XFA_SOM_MESSAGETYPE {
+    XFA_SOM_ValidationMessage,
+    XFA_SOM_FormatMessage,
+    XFA_SOM_MandatoryMessage
+  };
+  void Script_Som_Message(CFXJSE_Value* pValue,
+                          bool bSetting,
+                          XFA_SOM_MESSAGETYPE iMessageType);
+
   void OnChanged(XFA_Attribute eAttr, bool bNotify, bool bScriptModify);
   void OnChanging(XFA_Attribute eAttr, bool bNotify);
   bool SetUserData(void* pKey,
diff --git a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp
index 88fdfdc..40ccae1 100644
--- a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp
+++ b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp
@@ -1062,7 +1062,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_ParentSubform,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0x79b67434, L"mandatoryMessage",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_MandatoryMessage,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_MandatoryMessage,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0x7a7cc341, L"vAlign",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
@@ -1086,7 +1086,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
      XFA_Attribute::Relevant, XFA_ScriptType::Basic},
     {0x964fb42e, L"formatMessage",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_FormatMessage,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Field_FormatMessage,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0xa03cf627, L"rawValue",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_DefaultValue,
@@ -1113,7 +1113,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
      XFA_Attribute::AccessKey, XFA_ScriptType::Basic},
     {0xcabfa3d0, L"validationMessage",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_ValidationMessage,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_ValidationMessage,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0xdcecd663, L"editValue",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_EditValue,
@@ -1311,7 +1311,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_BorderColor,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0x79b67434, L"mandatoryMessage",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_MandatoryMessage,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_MandatoryMessage,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0x7a7cc341, L"vAlign",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
@@ -1359,7 +1359,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
      XFA_Attribute::AccessKey, XFA_ScriptType::Basic},
     {0xcabfa3d0, L"validationMessage",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_ValidationMessage,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_ValidationMessage,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0xf65e34be, L"borderWidth",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_BorderWidth,
@@ -1580,7 +1580,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
      XFA_Attribute::AnchorType, XFA_ScriptType::Basic},
     {0xcabfa3d0, L"validationMessage",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_ValidationMessage,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_ValidationMessage,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0xe4c3a5e5, L"restoreState",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,