summaryrefslogtreecommitdiff
path: root/fxjs/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs/xfa')
-rw-r--r--fxjs/xfa/cjx_node.cpp571
-rw-r--r--fxjs/xfa/cjx_node.h37
-rw-r--r--fxjs/xfa/cjx_object.cpp581
-rw-r--r--fxjs/xfa/cjx_object.h37
4 files changed, 618 insertions, 608 deletions
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index 7a0d13235e..9d416ea4d1 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -119,19 +119,6 @@ const CXFA_Node* CJX_Node::GetXFANode() const {
return static_cast<const CXFA_Node*>(GetXFAObject());
}
-int32_t CJX_Node::Subform_and_SubformSet_InstanceIndex() {
- int32_t index = 0;
- for (CXFA_Node* pNode = GetXFANode()->GetNodeItem(XFA_NODEITEM_PrevSibling);
- pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
- if ((pNode->GetElementType() != XFA_Element::Subform) &&
- (pNode->GetElementType() != XFA_Element::SubformSet)) {
- break;
- }
- index++;
- }
- return index;
-}
-
int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) {
CXFA_OccurData occurData(GetXFANode()->GetOccurNode());
if (iDesired < occurData.GetMin()) {
@@ -591,217 +578,6 @@ void CJX_Node::Script_Field_Length(CFXJSE_Value* pValue,
pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
}
-void CJX_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute /* unused */) {
- XFA_Element eType = GetXFANode()->GetElementType();
- if (eType == XFA_Element::Field) {
- Script_Field_DefaultValue(pValue, bSetting, XFA_Attribute::Unknown);
- return;
- }
- if (eType == XFA_Element::Draw) {
- Script_Draw_DefaultValue(pValue, bSetting, XFA_Attribute::Unknown);
- return;
- }
- if (eType == XFA_Element::Boolean) {
- Script_Boolean_Value(pValue, bSetting, XFA_Attribute::Unknown);
- return;
- }
-
- if (bSetting) {
- WideString wsNewValue;
- if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
- wsNewValue = pValue->ToWideString();
-
- WideString wsFormatValue(wsNewValue);
- CXFA_WidgetData* pContainerWidgetData = nullptr;
- if (GetXFANode()->GetPacketType() == XFA_PacketType::Datasets) {
- WideString wsPicture;
- for (const auto& pFormNode : *(GetXFANode()->GetBindItems())) {
- if (!pFormNode || pFormNode->HasRemovedChildren())
- continue;
-
- pContainerWidgetData = pFormNode->GetContainerWidgetData();
- if (pContainerWidgetData) {
- wsPicture = pContainerWidgetData->GetPictureContent(
- XFA_VALUEPICTURE_DataBind);
- }
- if (!wsPicture.IsEmpty())
- break;
-
- pContainerWidgetData = nullptr;
- }
- } else if (GetXFANode()->GetPacketType() == XFA_PacketType::Form) {
- pContainerWidgetData = GetXFANode()->GetContainerWidgetData();
- }
-
- if (pContainerWidgetData)
- wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsNewValue);
-
- SetContent(wsNewValue, wsFormatValue, true, true, true);
- return;
- }
-
- WideString content = GetContent(true);
- if (content.IsEmpty() && eType != XFA_Element::Text &&
- eType != XFA_Element::SubmitUrl) {
- pValue->SetNull();
- } else if (eType == XFA_Element::Integer) {
- pValue->SetInteger(FXSYS_wtoi(content.c_str()));
- } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
- CFX_Decimal decimal(content.AsStringView());
- pValue->SetFloat((float)(double)decimal);
- } else {
- pValue->SetString(content.UTF8Encode().AsStringView());
- }
-}
-
-void CJX_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute) {
- if (bSetting) {
- ThrowInvalidPropertyException();
- return;
- }
-
- WideString content = GetContent(true);
- if (content.IsEmpty()) {
- pValue->SetNull();
- return;
- }
- pValue->SetString(content.UTF8Encode().AsStringView());
-}
-
-void CJX_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute) {
- if (!bSetting) {
- WideString wsValue = GetContent(true);
- pValue->SetBoolean(wsValue == L"1");
- return;
- }
-
- ByteString newValue;
- if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
- newValue = pValue->ToString();
-
- int32_t iValue = FXSYS_atoi(newValue.c_str());
- WideString wsNewValue(iValue == 0 ? L"0" : L"1");
- WideString wsFormatValue(wsNewValue);
- CXFA_WidgetData* pContainerWidgetData =
- GetXFANode()->GetContainerWidgetData();
- if (pContainerWidgetData)
- wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsNewValue);
-
- SetContent(wsNewValue, wsFormatValue, true, true, true);
-}
-
-void CJX_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute) {
- if (bSetting) {
- ThrowInvalidPropertyException();
- return;
- }
-
- CXFA_Node* pDataNode = GetXFANode()->GetBindData();
- if (!pDataNode) {
- pValue->SetNull();
- return;
- }
-
- pValue->Assign(
- GetDocument()->GetScriptContext()->GetJSValueFromMap(pDataNode));
-}
-
-void CJX_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute) {
- if (!bSetting) {
- WideString content = GetContent(true);
- if (content.IsEmpty())
- pValue->SetNull();
- else
- pValue->SetString(content.UTF8Encode().AsStringView());
-
- return;
- }
-
- if (!pValue || !pValue->IsString())
- return;
-
- CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
- XFA_Element uiType = pWidgetData->GetUIType();
- if (uiType != XFA_Element::Text)
- return;
-
- WideString wsNewValue = pValue->ToWideString();
- SetContent(wsNewValue, wsNewValue, true, true, true);
-}
-
-void CJX_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute) {
- CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
- if (!pWidgetData)
- return;
-
- if (bSetting) {
- if (pValue) {
- pWidgetData->SetPreNull(pWidgetData->IsNull());
- pWidgetData->SetIsNull(pValue->IsNull());
- }
-
- WideString wsNewText;
- if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
- wsNewText = pValue->ToWideString();
-
- CXFA_Node* pUIChild = pWidgetData->GetUIChild();
- if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
- wsNewText =
- pWidgetData->NumericLimit(wsNewText, pWidgetData->GetLeadDigits(),
- pWidgetData->GetFracDigits());
- }
-
- CXFA_WidgetData* pContainerWidgetData =
- GetXFANode()->GetContainerWidgetData();
- WideString wsFormatText(wsNewText);
- if (pContainerWidgetData)
- wsFormatText = pContainerWidgetData->GetFormatDataValue(wsNewText);
-
- SetContent(wsNewText, wsFormatText, true, true, true);
- return;
- }
-
- WideString content = GetContent(true);
- if (content.IsEmpty()) {
- pValue->SetNull();
- return;
- }
-
- CXFA_Node* pUIChild = pWidgetData->GetUIChild();
- CXFA_Node* pNode = pWidgetData->GetFormValueData().GetNode()->GetNodeItem(
- XFA_NODEITEM_FirstChild);
- if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
- if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
- (pNode->JSNode()->GetInteger(XFA_Attribute::FracDigits) == -1)) {
- pValue->SetString(content.UTF8Encode().AsStringView());
- } else {
- CFX_Decimal decimal(content.AsStringView());
- pValue->SetFloat((float)(double)decimal);
- }
- } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
- pValue->SetInteger(FXSYS_wtoi(content.c_str()));
- } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
- pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
- } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
- CFX_Decimal decimal(content.AsStringView());
- pValue->SetFloat((float)(double)decimal);
- } else {
- pValue->SetString(content.UTF8Encode().AsStringView());
- }
-}
-
void CJX_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {
@@ -833,23 +609,6 @@ void CJX_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
.AsStringView());
}
-void CJX_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute) {
- CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
- if (!pWidgetData)
- return;
-
- CXFA_ValidateData validateData = pWidgetData->GetValidateData(true);
- if (bSetting) {
- validateData.SetNullTest(pValue->ToWideString());
- return;
- }
-
- WideString str = CXFA_Node::AttributeEnumToName(validateData.GetNullTest());
- pValue->SetString(str.UTF8Encode().AsStringView());
-}
-
void CJX_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {
@@ -914,44 +673,6 @@ void CJX_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {}
-void CJX_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute) {
- if (!bSetting) {
- pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
- return;
- }
-
- int32_t iTo = pValue->ToInteger();
- int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
- CXFA_Node* pManagerNode = nullptr;
- for (CXFA_Node* pNode = GetXFANode()->GetNodeItem(XFA_NODEITEM_PrevSibling);
- pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
- if (pNode->GetElementType() == XFA_Element::InstanceManager) {
- pManagerNode = pNode;
- break;
- }
- }
- if (!pManagerNode)
- return;
-
- pManagerNode->JSNode()->InstanceManager_MoveInstance(iTo, iFrom);
- CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
- if (!pNotify)
- return;
-
- CXFA_Node* pToInstance = pManagerNode->GetItem(iTo);
- if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
- pNotify->RunSubformIndexChange(pToInstance);
- }
-
- CXFA_Node* pFromInstance = pManagerNode->GetItem(iFrom);
- if (pFromInstance &&
- pFromInstance->GetElementType() == XFA_Element::Subform) {
- pNotify->RunSubformIndexChange(pFromInstance);
- }
-}
-
void CJX_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {
@@ -1153,46 +874,6 @@ pdfium::Optional<WideString> CJX_Node::TryNamespace() {
return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()};
}
-CXFA_Node* CJX_Node::GetProperty(int32_t index,
- XFA_Element eProperty,
- bool bCreateProperty) {
- if (index < 0 || index >= GetXFANode()->PropertyOccuranceCount(eProperty))
- return nullptr;
-
- int32_t iCount = 0;
- for (CXFA_Node* pNode = GetXFANode()->GetChildNode(); pNode;
- pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
- if (pNode->GetElementType() == eProperty) {
- iCount++;
- if (iCount > index)
- return pNode;
- }
- }
- if (!bCreateProperty)
- return nullptr;
-
- if (GetXFANode()->HasPropertyFlags(eProperty, XFA_PROPERTYFLAG_OneOf)) {
- for (CXFA_Node* pNode = GetXFANode()->GetChildNode(); pNode;
- pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
- if (GetXFANode()->HasPropertyFlags(pNode->GetElementType(),
- XFA_PROPERTYFLAG_OneOf)) {
- return nullptr;
- }
- }
- }
-
- CXFA_Node* pNewNode = nullptr;
- for (; iCount <= index; ++iCount) {
- pNewNode =
- GetDocument()->CreateNode(GetXFANode()->GetPacketType(), eProperty);
- if (!pNewNode)
- return nullptr;
- GetXFANode()->InsertChild(pNewNode, nullptr);
- pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
- }
- return pNewNode;
-}
-
int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName,
XFA_Element eType) {
CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
@@ -1278,255 +959,3 @@ void CJX_Node::ThrowTooManyOccurancesException(const WideString& obj) const {
L"The element [%ls] has violated its allowable number of occurrences.",
obj.c_str());
}
-
-bool CJX_Node::SetContent(const WideString& wsContent,
- const WideString& wsXMLValue,
- bool bNotify,
- bool bScriptModify,
- bool bSyncData) {
- CXFA_Node* pNode = nullptr;
- CXFA_Node* pBindNode = nullptr;
- switch (GetXFANode()->GetObjectType()) {
- case XFA_ObjectType::ContainerNode: {
- if (XFA_FieldIsMultiListBox(GetXFANode())) {
- CXFA_Node* pValue = GetProperty(0, XFA_Element::Value, true);
- if (!pValue)
- break;
-
- CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
- ASSERT(pChildValue);
- pChildValue->JSNode()->SetCData(XFA_Attribute::ContentType, L"text/xml",
- false, false);
- pChildValue->JSNode()->SetContent(wsContent, wsContent, bNotify,
- bScriptModify, false);
- CXFA_Node* pBind = GetXFANode()->GetBindData();
- if (bSyncData && pBind) {
- std::vector<WideString> wsSaveTextArray;
- size_t iSize = 0;
- if (!wsContent.IsEmpty()) {
- size_t iStart = 0;
- size_t iLength = wsContent.GetLength();
- auto iEnd = wsContent.Find(L'\n', iStart);
- iEnd = !iEnd.has_value() ? iLength : iEnd;
- while (iEnd.value() >= iStart) {
- wsSaveTextArray.push_back(
- wsContent.Mid(iStart, iEnd.value() - iStart));
- iStart = iEnd.value() + 1;
- if (iStart >= iLength)
- break;
-
- iEnd = wsContent.Find(L'\n', iStart);
- if (!iEnd.has_value()) {
- wsSaveTextArray.push_back(
- wsContent.Mid(iStart, iLength - iStart));
- }
- }
- iSize = wsSaveTextArray.size();
- }
- if (iSize == 0) {
- while (CXFA_Node* pChildNode =
- pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
- pBind->RemoveChild(pChildNode, true);
- }
- } else {
- std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
- XFA_NODEFILTER_Children, XFA_Element::DataValue);
- size_t iDatas = valueNodes.size();
- if (iDatas < iSize) {
- size_t iAddNodes = iSize - iDatas;
- CXFA_Node* pValueNodes = nullptr;
- while (iAddNodes-- > 0) {
- pValueNodes =
- pBind->CreateSamePacketNode(XFA_Element::DataValue);
- pValueNodes->JSNode()->SetCData(XFA_Attribute::Name, L"value",
- false, false);
- pValueNodes->CreateXMLMappingNode();
- pBind->InsertChild(pValueNodes, nullptr);
- }
- pValueNodes = nullptr;
- } else if (iDatas > iSize) {
- size_t iDelNodes = iDatas - iSize;
- while (iDelNodes-- > 0) {
- pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild),
- true);
- }
- }
- int32_t i = 0;
- for (CXFA_Node* pValueNode =
- pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
- pValueNode; pValueNode = pValueNode->GetNodeItem(
- XFA_NODEITEM_NextSibling)) {
- pValueNode->JSNode()->SetAttributeValue(
- wsSaveTextArray[i], wsSaveTextArray[i], false, false);
- i++;
- }
- }
- for (const auto& pArrayNode : *(pBind->GetBindItems())) {
- if (pArrayNode.Get() != GetXFANode()) {
- pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify,
- bScriptModify, false);
- }
- }
- }
- break;
- }
- if (GetXFANode()->GetElementType() == XFA_Element::ExclGroup) {
- pNode = GetXFANode();
- } else {
- CXFA_Node* pValue = GetProperty(0, XFA_Element::Value, true);
- if (!pValue)
- break;
-
- CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
- ASSERT(pChildValue);
- pChildValue->JSNode()->SetContent(wsContent, wsContent, bNotify,
- bScriptModify, false);
- }
- pBindNode = GetXFANode()->GetBindData();
- if (pBindNode && bSyncData) {
- pBindNode->JSNode()->SetContent(wsContent, wsXMLValue, bNotify,
- bScriptModify, false);
- for (const auto& pArrayNode : *(pBindNode->GetBindItems())) {
- if (pArrayNode.Get() != GetXFANode()) {
- pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify,
- true, false);
- }
- }
- }
- pBindNode = nullptr;
- break;
- }
- case XFA_ObjectType::ContentNode: {
- WideString wsContentType;
- if (GetXFANode()->GetElementType() == XFA_Element::ExData) {
- pdfium::Optional<WideString> ret =
- TryAttribute(XFA_Attribute::ContentType, false);
- if (ret)
- wsContentType = *ret;
- if (wsContentType == L"text/html") {
- wsContentType = L"";
- SetAttribute(XFA_Attribute::ContentType, wsContentType.AsStringView(),
- false);
- }
- }
-
- CXFA_Node* pContentRawDataNode =
- GetXFANode()->GetNodeItem(XFA_NODEITEM_FirstChild);
- if (!pContentRawDataNode) {
- pContentRawDataNode = GetXFANode()->CreateSamePacketNode(
- (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
- : XFA_Element::Sharptext);
- GetXFANode()->InsertChild(pContentRawDataNode, nullptr);
- }
- return pContentRawDataNode->JSNode()->SetContent(
- wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
- }
- case XFA_ObjectType::NodeC:
- case XFA_ObjectType::TextNode:
- pNode = GetXFANode();
- break;
- case XFA_ObjectType::NodeV:
- pNode = GetXFANode();
- if (bSyncData && GetXFANode()->GetPacketType() == XFA_PacketType::Form) {
- CXFA_Node* pParent = GetXFANode()->GetNodeItem(XFA_NODEITEM_Parent);
- if (pParent) {
- pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
- }
- if (pParent && pParent->GetElementType() == XFA_Element::Value) {
- pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
- if (pParent && pParent->IsContainerNode()) {
- pBindNode = pParent->GetBindData();
- if (pBindNode) {
- pBindNode->JSNode()->SetContent(wsContent, wsXMLValue, bNotify,
- bScriptModify, false);
- }
- }
- }
- }
- break;
- default:
- if (GetXFANode()->GetElementType() == XFA_Element::DataValue) {
- pNode = GetXFANode();
- pBindNode = GetXFANode();
- }
- break;
- }
- if (!pNode)
- return false;
-
- SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
- if (pBindNode && bSyncData) {
- for (const auto& pArrayNode : *(pBindNode->GetBindItems())) {
- pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify,
- bScriptModify, false);
- }
- }
- return true;
-}
-
-WideString CJX_Node::GetContent(bool bScriptModify) {
- return TryContent(bScriptModify, true).value_or(WideString());
-}
-
-pdfium::Optional<WideString> CJX_Node::TryContent(bool bScriptModify,
- bool bProto) {
- CXFA_Node* pNode = nullptr;
- switch (GetXFANode()->GetObjectType()) {
- case XFA_ObjectType::ContainerNode:
- if (GetXFANode()->GetElementType() == XFA_Element::ExclGroup) {
- pNode = GetXFANode();
- } else {
- CXFA_Node* pValue =
- GetXFANode()->GetChild(0, XFA_Element::Value, false);
- if (!pValue)
- return {};
-
- CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
- if (pChildValue && XFA_FieldIsMultiListBox(GetXFANode())) {
- pChildValue->JSNode()->SetAttribute(XFA_Attribute::ContentType,
- L"text/xml", false);
- }
- if (pChildValue)
- return pChildValue->JSNode()->TryContent(bScriptModify, bProto);
- return {};
- }
- break;
- case XFA_ObjectType::ContentNode: {
- CXFA_Node* pContentRawDataNode =
- GetXFANode()->GetNodeItem(XFA_NODEITEM_FirstChild);
- if (!pContentRawDataNode) {
- XFA_Element element = XFA_Element::Sharptext;
- if (GetXFANode()->GetElementType() == XFA_Element::ExData) {
- pdfium::Optional<WideString> contentType =
- TryAttribute(XFA_Attribute::ContentType, false);
- if (contentType) {
- if (*contentType == L"text/html")
- element = XFA_Element::SharpxHTML;
- else if (*contentType == L"text/xml")
- element = XFA_Element::Sharpxml;
- }
- }
- pContentRawDataNode = GetXFANode()->CreateSamePacketNode(element);
- GetXFANode()->InsertChild(pContentRawDataNode, nullptr);
- }
- return pContentRawDataNode->JSNode()->TryContent(bScriptModify, true);
- }
- case XFA_ObjectType::NodeC:
- case XFA_ObjectType::NodeV:
- case XFA_ObjectType::TextNode:
- pNode = GetXFANode();
- default:
- if (GetXFANode()->GetElementType() == XFA_Element::DataValue)
- pNode = GetXFANode();
- break;
- }
- if (pNode) {
- if (bScriptModify) {
- CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (pScriptContext)
- GetDocument()->GetScriptContext()->AddNodesOfRunScript(GetXFANode());
- }
- return TryCData(XFA_Attribute::Value, false);
- }
- return {};
-}
diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h
index 3d8f4dff01..f2ff49217e 100644
--- a/fxjs/xfa/cjx_node.h
+++ b/fxjs/xfa/cjx_node.h
@@ -28,18 +28,6 @@ class CJX_Node : public CJX_Tree {
CXFA_Node* GetXFANode();
const CXFA_Node* GetXFANode() const;
- CXFA_Node* GetProperty(int32_t index,
- XFA_Element eType,
- bool bCreateProperty);
-
- pdfium::Optional<WideString> TryContent(bool bScriptModify, bool bProto);
- bool SetContent(const WideString& wsContent,
- const WideString& wsXMLValue,
- bool bNotify,
- bool bScriptModify,
- bool bSyncData);
- WideString GetContent(bool bScriptModify);
-
void SetLayoutItem(CXFA_LayoutItem* item) { layout_item_ = item; }
CXFA_LayoutItem* GetLayoutItem() const { return layout_item_.Get(); }
@@ -52,7 +40,6 @@ class CJX_Node : public CJX_Tree {
const WideString& prop) const;
void ThrowTooManyOccurancesException(const WideString& obj) const;
- int32_t Subform_and_SubformSet_InstanceIndex();
int32_t InstanceManager_SetInstances(int32_t iDesired);
int32_t InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom);
@@ -101,30 +88,6 @@ class CJX_Node : public CJX_Tree {
void Script_Field_Length(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
- void Script_Som_DefaultValue(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute);
- void Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute);
- void Script_Boolean_Value(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute);
- 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_InstanceIndex(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute);
- void Script_Draw_DefaultValue(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute);
- void Script_Field_DefaultValue(CFXJSE_Value* pValue,
- bool bSetting,
- XFA_Attribute eAttribute);
void Script_Field_EditValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 1f4f77aea1..2c6588824f 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -8,6 +8,7 @@
#include <tuple>
+#include "core/fxcrt/cfx_decimal.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
#include "fxjs/cfxjse_engine.h"
@@ -20,6 +21,7 @@
#include "xfa/fxfa/parser/cxfa_measurement.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_object.h"
+#include "xfa/fxfa/parser/xfa_utils.h"
namespace {
@@ -576,6 +578,308 @@ CFX_XMLElement* CJX_Object::SetValue(XFA_Attribute eAttr,
return elem;
}
+bool CJX_Object::SetContent(const WideString& wsContent,
+ const WideString& wsXMLValue,
+ bool bNotify,
+ bool bScriptModify,
+ bool bSyncData) {
+ CXFA_Node* pNode = nullptr;
+ CXFA_Node* pBindNode = nullptr;
+ switch (ToNode(GetXFAObject())->GetObjectType()) {
+ case XFA_ObjectType::ContainerNode: {
+ if (XFA_FieldIsMultiListBox(ToNode(GetXFAObject()))) {
+ CXFA_Node* pValue = GetProperty(0, XFA_Element::Value, true);
+ if (!pValue)
+ break;
+
+ CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
+ ASSERT(pChildValue);
+ pChildValue->JSNode()->SetCData(XFA_Attribute::ContentType, L"text/xml",
+ false, false);
+ pChildValue->JSNode()->SetContent(wsContent, wsContent, bNotify,
+ bScriptModify, false);
+ CXFA_Node* pBind = ToNode(GetXFAObject())->GetBindData();
+ if (bSyncData && pBind) {
+ std::vector<WideString> wsSaveTextArray;
+ size_t iSize = 0;
+ if (!wsContent.IsEmpty()) {
+ size_t iStart = 0;
+ size_t iLength = wsContent.GetLength();
+ auto iEnd = wsContent.Find(L'\n', iStart);
+ iEnd = !iEnd.has_value() ? iLength : iEnd;
+ while (iEnd.value() >= iStart) {
+ wsSaveTextArray.push_back(
+ wsContent.Mid(iStart, iEnd.value() - iStart));
+ iStart = iEnd.value() + 1;
+ if (iStart >= iLength)
+ break;
+
+ iEnd = wsContent.Find(L'\n', iStart);
+ if (!iEnd.has_value()) {
+ wsSaveTextArray.push_back(
+ wsContent.Mid(iStart, iLength - iStart));
+ }
+ }
+ iSize = wsSaveTextArray.size();
+ }
+ if (iSize == 0) {
+ while (CXFA_Node* pChildNode =
+ pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
+ pBind->RemoveChild(pChildNode, true);
+ }
+ } else {
+ std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
+ XFA_NODEFILTER_Children, XFA_Element::DataValue);
+ size_t iDatas = valueNodes.size();
+ if (iDatas < iSize) {
+ size_t iAddNodes = iSize - iDatas;
+ CXFA_Node* pValueNodes = nullptr;
+ while (iAddNodes-- > 0) {
+ pValueNodes =
+ pBind->CreateSamePacketNode(XFA_Element::DataValue);
+ pValueNodes->JSNode()->SetCData(XFA_Attribute::Name, L"value",
+ false, false);
+ pValueNodes->CreateXMLMappingNode();
+ pBind->InsertChild(pValueNodes, nullptr);
+ }
+ pValueNodes = nullptr;
+ } else if (iDatas > iSize) {
+ size_t iDelNodes = iDatas - iSize;
+ while (iDelNodes-- > 0) {
+ pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild),
+ true);
+ }
+ }
+ int32_t i = 0;
+ for (CXFA_Node* pValueNode =
+ pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
+ pValueNode; pValueNode = pValueNode->GetNodeItem(
+ XFA_NODEITEM_NextSibling)) {
+ pValueNode->JSNode()->SetAttributeValue(
+ wsSaveTextArray[i], wsSaveTextArray[i], false, false);
+ i++;
+ }
+ }
+ for (const auto& pArrayNode : *(pBind->GetBindItems())) {
+ if (pArrayNode.Get() != ToNode(GetXFAObject())) {
+ pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify,
+ bScriptModify, false);
+ }
+ }
+ }
+ break;
+ }
+ if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::ExclGroup) {
+ pNode = ToNode(GetXFAObject());
+ } else {
+ CXFA_Node* pValue = GetProperty(0, XFA_Element::Value, true);
+ if (!pValue)
+ break;
+
+ CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
+ ASSERT(pChildValue);
+ pChildValue->JSNode()->SetContent(wsContent, wsContent, bNotify,
+ bScriptModify, false);
+ }
+ pBindNode = ToNode(GetXFAObject())->GetBindData();
+ if (pBindNode && bSyncData) {
+ pBindNode->JSNode()->SetContent(wsContent, wsXMLValue, bNotify,
+ bScriptModify, false);
+ for (const auto& pArrayNode : *(pBindNode->GetBindItems())) {
+ if (pArrayNode.Get() != ToNode(GetXFAObject())) {
+ pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify,
+ true, false);
+ }
+ }
+ }
+ pBindNode = nullptr;
+ break;
+ }
+ case XFA_ObjectType::ContentNode: {
+ WideString wsContentType;
+ if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::ExData) {
+ pdfium::Optional<WideString> ret =
+ TryAttribute(XFA_Attribute::ContentType, false);
+ if (ret)
+ wsContentType = *ret;
+ if (wsContentType == L"text/html") {
+ wsContentType = L"";
+ SetAttribute(XFA_Attribute::ContentType, wsContentType.AsStringView(),
+ false);
+ }
+ }
+
+ CXFA_Node* pContentRawDataNode =
+ ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_FirstChild);
+ if (!pContentRawDataNode) {
+ pContentRawDataNode =
+ ToNode(GetXFAObject())
+ ->CreateSamePacketNode((wsContentType == L"text/xml")
+ ? XFA_Element::Sharpxml
+ : XFA_Element::Sharptext);
+ ToNode(GetXFAObject())->InsertChild(pContentRawDataNode, nullptr);
+ }
+ return pContentRawDataNode->JSNode()->SetContent(
+ wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
+ }
+ case XFA_ObjectType::NodeC:
+ case XFA_ObjectType::TextNode:
+ pNode = ToNode(GetXFAObject());
+ break;
+ case XFA_ObjectType::NodeV:
+ pNode = ToNode(GetXFAObject());
+ if (bSyncData &&
+ ToNode(GetXFAObject())->GetPacketType() == XFA_PacketType::Form) {
+ CXFA_Node* pParent =
+ ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_Parent);
+ if (pParent) {
+ pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
+ }
+ if (pParent && pParent->GetElementType() == XFA_Element::Value) {
+ pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
+ if (pParent && pParent->IsContainerNode()) {
+ pBindNode = pParent->GetBindData();
+ if (pBindNode) {
+ pBindNode->JSNode()->SetContent(wsContent, wsXMLValue, bNotify,
+ bScriptModify, false);
+ }
+ }
+ }
+ }
+ break;
+ default:
+ if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::DataValue) {
+ pNode = ToNode(GetXFAObject());
+ pBindNode = ToNode(GetXFAObject());
+ }
+ break;
+ }
+ if (!pNode)
+ return false;
+
+ SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
+ if (pBindNode && bSyncData) {
+ for (const auto& pArrayNode : *(pBindNode->GetBindItems())) {
+ pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify,
+ bScriptModify, false);
+ }
+ }
+ return true;
+}
+
+WideString CJX_Object::GetContent(bool bScriptModify) {
+ return TryContent(bScriptModify, true).value_or(WideString());
+}
+
+pdfium::Optional<WideString> CJX_Object::TryContent(bool bScriptModify,
+ bool bProto) {
+ CXFA_Node* pNode = nullptr;
+ switch (ToNode(GetXFAObject())->GetObjectType()) {
+ case XFA_ObjectType::ContainerNode:
+ if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::ExclGroup) {
+ pNode = ToNode(GetXFAObject());
+ } else {
+ CXFA_Node* pValue =
+ ToNode(GetXFAObject())->GetChild(0, XFA_Element::Value, false);
+ if (!pValue)
+ return {};
+
+ CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
+ if (pChildValue && XFA_FieldIsMultiListBox(ToNode(GetXFAObject()))) {
+ pChildValue->JSNode()->SetAttribute(XFA_Attribute::ContentType,
+ L"text/xml", false);
+ }
+ if (pChildValue)
+ return pChildValue->JSNode()->TryContent(bScriptModify, bProto);
+ return {};
+ }
+ break;
+ case XFA_ObjectType::ContentNode: {
+ CXFA_Node* pContentRawDataNode =
+ ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_FirstChild);
+ if (!pContentRawDataNode) {
+ XFA_Element element = XFA_Element::Sharptext;
+ if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::ExData) {
+ pdfium::Optional<WideString> contentType =
+ TryAttribute(XFA_Attribute::ContentType, false);
+ if (contentType) {
+ if (*contentType == L"text/html")
+ element = XFA_Element::SharpxHTML;
+ else if (*contentType == L"text/xml")
+ element = XFA_Element::Sharpxml;
+ }
+ }
+ pContentRawDataNode =
+ ToNode(GetXFAObject())->CreateSamePacketNode(element);
+ ToNode(GetXFAObject())->InsertChild(pContentRawDataNode, nullptr);
+ }
+ return pContentRawDataNode->JSNode()->TryContent(bScriptModify, true);
+ }
+ case XFA_ObjectType::NodeC:
+ case XFA_ObjectType::NodeV:
+ case XFA_ObjectType::TextNode:
+ pNode = ToNode(GetXFAObject());
+ default:
+ if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::DataValue)
+ pNode = ToNode(GetXFAObject());
+ break;
+ }
+ if (pNode) {
+ if (bScriptModify) {
+ CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
+ if (pScriptContext)
+ GetDocument()->GetScriptContext()->AddNodesOfRunScript(
+ ToNode(GetXFAObject()));
+ }
+ return TryCData(XFA_Attribute::Value, false);
+ }
+ return {};
+}
+
+CXFA_Node* CJX_Object::GetProperty(int32_t index,
+ XFA_Element eProperty,
+ bool bCreateProperty) {
+ if (index < 0 ||
+ index >= ToNode(GetXFAObject())->PropertyOccuranceCount(eProperty)) {
+ return nullptr;
+ }
+
+ int32_t iCount = 0;
+ for (CXFA_Node* pNode = ToNode(GetXFAObject())->GetChildNode(); pNode;
+ pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
+ if (pNode->GetElementType() == eProperty) {
+ iCount++;
+ if (iCount > index)
+ return pNode;
+ }
+ }
+ if (!bCreateProperty)
+ return nullptr;
+
+ if (ToNode(GetXFAObject())
+ ->HasPropertyFlags(eProperty, XFA_PROPERTYFLAG_OneOf)) {
+ for (CXFA_Node* pNode = ToNode(GetXFAObject())->GetChildNode(); pNode;
+ pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
+ if (ToNode(GetXFAObject())
+ ->HasPropertyFlags(pNode->GetElementType(),
+ XFA_PROPERTYFLAG_OneOf)) {
+ return nullptr;
+ }
+ }
+ }
+
+ CXFA_Node* pNewNode = nullptr;
+ for (; iCount <= index; ++iCount) {
+ pNewNode = GetDocument()->CreateNode(
+ ToNode(GetXFAObject())->GetPacketType(), eProperty);
+ if (!pNewNode)
+ return nullptr;
+ ToNode(GetXFAObject())->InsertChild(pNewNode, nullptr);
+ pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
+ }
+ return pNewNode;
+}
+
bool CJX_Object::SetUserData(void* pKey,
void* pData,
XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
@@ -1107,3 +1411,280 @@ void CJX_Object::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
XFA_Attribute eAttribute) {
Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
}
+
+void CJX_Object::Script_Som_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute /* unused */) {
+ XFA_Element eType = ToNode(GetXFAObject())->GetElementType();
+ if (eType == XFA_Element::Field) {
+ Script_Field_DefaultValue(pValue, bSetting, XFA_Attribute::Unknown);
+ return;
+ }
+ if (eType == XFA_Element::Draw) {
+ Script_Draw_DefaultValue(pValue, bSetting, XFA_Attribute::Unknown);
+ return;
+ }
+ if (eType == XFA_Element::Boolean) {
+ Script_Boolean_DefaultValue(pValue, bSetting, XFA_Attribute::Unknown);
+ return;
+ }
+
+ if (bSetting) {
+ WideString wsNewValue;
+ if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
+ wsNewValue = pValue->ToWideString();
+
+ WideString wsFormatValue(wsNewValue);
+ CXFA_WidgetData* pContainerWidgetData = nullptr;
+ if (ToNode(GetXFAObject())->GetPacketType() == XFA_PacketType::Datasets) {
+ WideString wsPicture;
+ for (const auto& pFormNode : *(ToNode(GetXFAObject())->GetBindItems())) {
+ if (!pFormNode || pFormNode->HasRemovedChildren())
+ continue;
+
+ pContainerWidgetData = pFormNode->GetContainerWidgetData();
+ if (pContainerWidgetData) {
+ wsPicture = pContainerWidgetData->GetPictureContent(
+ XFA_VALUEPICTURE_DataBind);
+ }
+ if (!wsPicture.IsEmpty())
+ break;
+
+ pContainerWidgetData = nullptr;
+ }
+ } else if (ToNode(GetXFAObject())->GetPacketType() ==
+ XFA_PacketType::Form) {
+ pContainerWidgetData = ToNode(GetXFAObject())->GetContainerWidgetData();
+ }
+
+ if (pContainerWidgetData)
+ wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsNewValue);
+
+ SetContent(wsNewValue, wsFormatValue, true, true, true);
+ return;
+ }
+
+ WideString content = GetContent(true);
+ if (content.IsEmpty() && eType != XFA_Element::Text &&
+ eType != XFA_Element::SubmitUrl) {
+ pValue->SetNull();
+ } else if (eType == XFA_Element::Integer) {
+ pValue->SetInteger(FXSYS_wtoi(content.c_str()));
+ } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
+ CFX_Decimal decimal(content.AsStringView());
+ pValue->SetFloat((float)(double)decimal);
+ } else {
+ pValue->SetString(content.UTF8Encode().AsStringView());
+ }
+}
+
+void CJX_Object::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (bSetting) {
+ ThrowInvalidPropertyException();
+ return;
+ }
+
+ WideString content = GetContent(true);
+ if (content.IsEmpty()) {
+ pValue->SetNull();
+ return;
+ }
+ pValue->SetString(content.UTF8Encode().AsStringView());
+}
+
+void CJX_Object::Script_Som_DataNode(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (bSetting) {
+ ThrowInvalidPropertyException();
+ return;
+ }
+
+ CXFA_Node* pDataNode = ToNode(GetXFAObject())->GetBindData();
+ if (!pDataNode) {
+ pValue->SetNull();
+ return;
+ }
+
+ pValue->Assign(
+ GetDocument()->GetScriptContext()->GetJSValueFromMap(pDataNode));
+}
+
+void CJX_Object::Script_Som_Mandatory(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (!widget_data_)
+ return;
+
+ CXFA_ValidateData validateData = widget_data_->GetValidateData(true);
+ if (bSetting) {
+ validateData.SetNullTest(pValue->ToWideString());
+ return;
+ }
+
+ WideString str = CXFA_Node::AttributeEnumToName(validateData.GetNullTest());
+ pValue->SetString(str.UTF8Encode().AsStringView());
+}
+
+void CJX_Object::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (!bSetting) {
+ pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
+ return;
+ }
+
+ int32_t iTo = pValue->ToInteger();
+ int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
+ CXFA_Node* pManagerNode = nullptr;
+ for (CXFA_Node* pNode =
+ ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_PrevSibling);
+ pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
+ if (pNode->GetElementType() == XFA_Element::InstanceManager) {
+ pManagerNode = pNode;
+ break;
+ }
+ }
+ if (!pManagerNode)
+ return;
+
+ pManagerNode->JSNode()->InstanceManager_MoveInstance(iTo, iFrom);
+ CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
+ if (!pNotify)
+ return;
+
+ CXFA_Node* pToInstance = pManagerNode->GetItem(iTo);
+ if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
+ pNotify->RunSubformIndexChange(pToInstance);
+ }
+
+ CXFA_Node* pFromInstance = pManagerNode->GetItem(iFrom);
+ if (pFromInstance &&
+ pFromInstance->GetElementType() == XFA_Element::Subform) {
+ pNotify->RunSubformIndexChange(pFromInstance);
+ }
+}
+
+void CJX_Object::Script_Field_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (!widget_data_)
+ return;
+
+ if (bSetting) {
+ if (pValue) {
+ widget_data_->SetPreNull(widget_data_->IsNull());
+ widget_data_->SetIsNull(pValue->IsNull());
+ }
+
+ WideString wsNewText;
+ if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
+ wsNewText = pValue->ToWideString();
+
+ CXFA_Node* pUIChild = widget_data_->GetUIChild();
+ if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
+ wsNewText =
+ widget_data_->NumericLimit(wsNewText, widget_data_->GetLeadDigits(),
+ widget_data_->GetFracDigits());
+ }
+
+ CXFA_WidgetData* pContainerWidgetData =
+ ToNode(GetXFAObject())->GetContainerWidgetData();
+ WideString wsFormatText(wsNewText);
+ if (pContainerWidgetData)
+ wsFormatText = pContainerWidgetData->GetFormatDataValue(wsNewText);
+
+ SetContent(wsNewText, wsFormatText, true, true, true);
+ return;
+ }
+
+ WideString content = GetContent(true);
+ if (content.IsEmpty()) {
+ pValue->SetNull();
+ return;
+ }
+
+ CXFA_Node* pUIChild = widget_data_->GetUIChild();
+ CXFA_Node* pNode = widget_data_->GetFormValueData().GetNode()->GetNodeItem(
+ XFA_NODEITEM_FirstChild);
+ if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
+ if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
+ (pNode->JSNode()->GetInteger(XFA_Attribute::FracDigits) == -1)) {
+ pValue->SetString(content.UTF8Encode().AsStringView());
+ } else {
+ CFX_Decimal decimal(content.AsStringView());
+ pValue->SetFloat((float)(double)decimal);
+ }
+ } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
+ pValue->SetInteger(FXSYS_wtoi(content.c_str()));
+ } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
+ pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
+ } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
+ CFX_Decimal decimal(content.AsStringView());
+ pValue->SetFloat((float)(double)decimal);
+ } else {
+ pValue->SetString(content.UTF8Encode().AsStringView());
+ }
+}
+
+void CJX_Object::Script_Boolean_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (!bSetting) {
+ WideString wsValue = GetContent(true);
+ pValue->SetBoolean(wsValue == L"1");
+ return;
+ }
+
+ ByteString newValue;
+ if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
+ newValue = pValue->ToString();
+
+ int32_t iValue = FXSYS_atoi(newValue.c_str());
+ WideString wsNewValue(iValue == 0 ? L"0" : L"1");
+ WideString wsFormatValue(wsNewValue);
+ CXFA_WidgetData* pContainerWidgetData =
+ ToNode(GetXFAObject())->GetContainerWidgetData();
+ if (pContainerWidgetData)
+ wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsNewValue);
+
+ SetContent(wsNewValue, wsFormatValue, true, true, true);
+}
+
+void CJX_Object::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (!bSetting) {
+ WideString content = GetContent(true);
+ if (content.IsEmpty())
+ pValue->SetNull();
+ else
+ pValue->SetString(content.UTF8Encode().AsStringView());
+
+ return;
+ }
+
+ if (!pValue || !pValue->IsString())
+ return;
+ if (widget_data_->GetUIType() != XFA_Element::Text)
+ return;
+
+ WideString wsNewValue = pValue->ToWideString();
+ SetContent(wsNewValue, wsNewValue, true, true, true);
+}
+
+int32_t CJX_Object::Subform_and_SubformSet_InstanceIndex() {
+ int32_t index = 0;
+ for (CXFA_Node* pNode =
+ ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_PrevSibling);
+ pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
+ if ((pNode->GetElementType() != XFA_Element::Subform) &&
+ (pNode->GetElementType() != XFA_Element::SubformSet)) {
+ break;
+ }
+ index++;
+ }
+ return index;
+}
diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h
index 1263bf82c5..10146f4ef9 100644
--- a/fxjs/xfa/cjx_object.h
+++ b/fxjs/xfa/cjx_object.h
@@ -77,6 +77,18 @@ class CJX_Object {
pdfium::Optional<WideString> TryAttribute(XFA_Attribute eAttr,
bool bUseDefault);
+ pdfium::Optional<WideString> TryContent(bool bScriptModify, bool bProto);
+ bool SetContent(const WideString& wsContent,
+ const WideString& wsXMLValue,
+ bool bNotify,
+ bool bScriptModify,
+ bool bSyncData);
+ WideString GetContent(bool bScriptModify);
+
+ CXFA_Node* GetProperty(int32_t index,
+ XFA_Element eType,
+ bool bCreateProperty);
+
void SetAttributeValue(const WideString& wsValue,
const WideString& wsXMLValue,
bool bNotify,
@@ -113,6 +125,21 @@ class CJX_Object {
void Script_Field_FormatMessage(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
+ void Script_Som_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute);
+ void Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute);
+ 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_InstanceIndex(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);
@@ -170,6 +197,16 @@ class CJX_Object {
void Script_Som_Message(CFXJSE_Value* pValue,
bool bSetting,
XFA_SOM_MESSAGETYPE iMessageType);
+ void Script_Boolean_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute);
+ void Script_Draw_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute);
+ void Script_Field_DefaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute);
+ int32_t Subform_and_SubformSet_InstanceIndex();
void OnChanged(XFA_Attribute eAttr, bool bNotify, bool bScriptModify);
void OnChanging(XFA_Attribute eAttr, bool bNotify);