Move Script_Som_{Fill|Font}Color 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_{Fill|Font}Color from CJX_Node to
CJX_Object.

Change-Id: I681d2c09a7560eb96967bbbbcb050246f4b879c0
Reviewed-on: https://pdfium-review.googlesource.com/20991
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 c0a7f37..ff65c38 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -7,7 +7,6 @@
 #include "fxjs/xfa/cjx_node.h"
 
 #include <map>
-#include <tuple>
 #include <vector>
 
 #include "core/fxcrt/cfx_decimal.h"
@@ -32,37 +31,6 @@
 
 namespace {
 
-std::tuple<int32_t, int32_t, int32_t> StrToRGB(const WideString& strRGB) {
-  int32_t r = 0;
-  int32_t g = 0;
-  int32_t b = 0;
-
-  size_t iIndex = 0;
-  for (size_t i = 0; i < strRGB.GetLength(); ++i) {
-    wchar_t ch = strRGB[i];
-    if (ch == L',')
-      ++iIndex;
-    if (iIndex > 2)
-      break;
-
-    int32_t iValue = ch - L'0';
-    if (iValue >= 0 && iValue <= 9) {
-      switch (iIndex) {
-        case 0:
-          r = r * 10 + iValue;
-          break;
-        case 1:
-          g = g * 10 + iValue;
-          break;
-        default:
-          b = b * 10 + iValue;
-          break;
-      }
-    }
-  }
-  return {r, g, b};
-}
-
 enum class EventAppliesToo {
   kNone = 0,
   kAll = 1,
@@ -789,39 +757,6 @@
   SetContent(wsNewValue, wsFormatValue, true, true, true);
 }
 
-void CJX_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
-                                    bool bSetting,
-                                    XFA_Attribute eAttribute) {
-  CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
-  if (!pWidgetData)
-    return;
-
-  CXFA_BorderData borderData = pWidgetData->GetBorderData(true);
-  CXFA_FillData borderfillData = borderData.GetFillData(true);
-  CXFA_Node* pNode = borderfillData.GetNode();
-  if (!pNode)
-    return;
-
-  if (bSetting) {
-    int32_t r;
-    int32_t g;
-    int32_t b;
-    std::tie(r, g, b) = StrToRGB(pValue->ToWideString());
-    FX_ARGB color = ArgbEncode(0xff, r, g, b);
-    borderfillData.SetColor(color);
-    return;
-  }
-
-  FX_ARGB color = borderfillData.GetColor(false);
-  int32_t a;
-  int32_t r;
-  int32_t g;
-  int32_t b;
-  std::tie(a, r, g, b) = ArgbDecode(color);
-  pValue->SetString(
-      WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView());
-}
-
 void CJX_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
                                    bool bSetting,
                                    XFA_Attribute eAttribute) {
@@ -943,36 +878,6 @@
       pWidgetData->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView());
 }
 
-void CJX_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
-                                    bool bSetting,
-                                    XFA_Attribute eAttribute) {
-  CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
-  if (!pWidgetData)
-    return;
-
-  CXFA_FontData fontData = pWidgetData->GetFontData(true);
-  CXFA_Node* pNode = fontData.GetNode();
-  if (!pNode)
-    return;
-
-  if (bSetting) {
-    int32_t r;
-    int32_t g;
-    int32_t b;
-    std::tie(r, g, b) = StrToRGB(pValue->ToWideString());
-    FX_ARGB color = ArgbEncode(0xff, r, g, b);
-    fontData.SetColor(color);
-    return;
-  }
-
-  int32_t a;
-  int32_t r;
-  int32_t g;
-  int32_t b;
-  std::tie(a, r, g, b) = ArgbDecode(fontData.GetColor());
-  pValue->SetString(ByteString::Format("%d,%d,%d", r, g, b).AsStringView());
-}
-
 void CJX_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
                                           bool bSetting,
                                           XFA_Attribute eAttribute) {
diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h
index 8c42b34..bfc0fa4 100644
--- a/fxjs/xfa/cjx_node.h
+++ b/fxjs/xfa/cjx_node.h
@@ -122,15 +122,9 @@
   void Script_Som_Message(CFXJSE_Value* pValue,
                           bool bSetting,
                           XFA_SOM_MESSAGETYPE iMessageType);
-  void Script_Som_FillColor(CFXJSE_Value* pValue,
-                            bool bSetting,
-                            XFA_Attribute eAttribute);
   void Script_Som_DataNode(CFXJSE_Value* pValue,
                            bool bSetting,
                            XFA_Attribute eAttribute);
-  void Script_Som_FontColor(CFXJSE_Value* pValue,
-                            bool bSetting,
-                            XFA_Attribute eAttribute);
   void Script_Som_Mandatory(CFXJSE_Value* pValue,
                             bool bSetting,
                             XFA_Attribute eAttribute);
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 5b21730..1d94b55 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -925,6 +925,67 @@
   pValue->SetInteger(GetInteger(eAttribute));
 }
 
+void CJX_Object::Script_Som_FontColor(CFXJSE_Value* pValue,
+                                      bool bSetting,
+                                      XFA_Attribute eAttribute) {
+  if (!widget_data_)
+    return;
+
+  CXFA_FontData fontData = widget_data_->GetFontData(true);
+  CXFA_Node* pNode = fontData.GetNode();
+  if (!pNode)
+    return;
+
+  if (bSetting) {
+    int32_t r;
+    int32_t g;
+    int32_t b;
+    std::tie(r, g, b) = StrToRGB(pValue->ToWideString());
+    FX_ARGB color = ArgbEncode(0xff, r, g, b);
+    fontData.SetColor(color);
+    return;
+  }
+
+  int32_t a;
+  int32_t r;
+  int32_t g;
+  int32_t b;
+  std::tie(a, r, g, b) = ArgbDecode(fontData.GetColor());
+  pValue->SetString(ByteString::Format("%d,%d,%d", r, g, b).AsStringView());
+}
+
+void CJX_Object::Script_Som_FillColor(CFXJSE_Value* pValue,
+                                      bool bSetting,
+                                      XFA_Attribute eAttribute) {
+  if (!widget_data_)
+    return;
+
+  CXFA_BorderData borderData = widget_data_->GetBorderData(true);
+  CXFA_FillData borderfillData = borderData.GetFillData(true);
+  CXFA_Node* pNode = borderfillData.GetNode();
+  if (!pNode)
+    return;
+
+  if (bSetting) {
+    int32_t r;
+    int32_t g;
+    int32_t b;
+    std::tie(r, g, b) = StrToRGB(pValue->ToWideString());
+    FX_ARGB color = ArgbEncode(0xff, r, g, b);
+    borderfillData.SetColor(color);
+    return;
+  }
+
+  FX_ARGB color = borderfillData.GetColor(false);
+  int32_t a;
+  int32_t r;
+  int32_t g;
+  int32_t b;
+  std::tie(a, r, g, b) = ArgbDecode(color);
+  pValue->SetString(
+      WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView());
+}
+
 void CJX_Object::Script_Som_BorderColor(CFXJSE_Value* pValue,
                                         bool bSetting,
                                         XFA_Attribute eAttribute) {
diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h
index dfd2bbc..e29081c 100644
--- a/fxjs/xfa/cjx_object.h
+++ b/fxjs/xfa/cjx_object.h
@@ -92,6 +92,12 @@
                                 bool bSetting,
                                 XFA_Attribute eAttribute);
 
+  void Script_Som_FontColor(CFXJSE_Value* pValue,
+                            bool bSetting,
+                            XFA_Attribute eAttribute);
+  void Script_Som_FillColor(CFXJSE_Value* pValue,
+                            bool bSetting,
+                            XFA_Attribute eAttribute);
   void Script_Som_BorderColor(CFXJSE_Value* pValue,
                               bool bSetting,
                               XFA_Attribute eAttribute);
diff --git a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp
index 071612e..88fdfdc 100644
--- a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp
+++ b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp
@@ -1044,7 +1044,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
      XFA_Attribute::Rotate, XFA_ScriptType::Basic},
     {0x3b1ddd06, L"fillColor",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_FillColor,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_FillColor,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0x54c399e3, L"formattedValue",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_FormattedValue,
@@ -1302,7 +1302,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
      XFA_Attribute::Access, XFA_ScriptType::Basic},
     {0x3b1ddd06, L"fillColor",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_FillColor,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_FillColor,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0x570ce835, L"presence",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
@@ -1532,7 +1532,7 @@
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,
      XFA_Attribute::Access, XFA_ScriptType::Basic},
     {0x3b1ddd06, L"fillColor",
-     (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Som_FillColor,
+     (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_FillColor,
      XFA_Attribute::Unknown, XFA_ScriptType::Basic},
     {0x570ce835, L"presence",
      (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String,