7#include "fxjs/xfa/cjx_field.h"
11#include "fxjs/cfx_v8.h"
13#include "fxjs/js_resources.h"
14#include "third_party/base/containers/span.h"
15#include "third_party/base/numerics/safe_conversions.h"
16#include "v8/include/v8-primitive.h"
17#include "xfa/fgas/crt/cfgas_decimal.h"
18#include "xfa/fxfa/cxfa_eventparam.h"
19#include "xfa/fxfa/cxfa_ffnotify.h"
20#include "xfa/fxfa/fxfa.h"
21#include "xfa/fxfa/parser/cxfa_document.h"
22#include "xfa/fxfa/parser/cxfa_field.h"
23#include "xfa/fxfa/parser/cxfa_value.h"
26 {
"addItem", addItem_static},
27 {
"boundItem", boundItem_static},
28 {
"clearItems", clearItems_static},
29 {
"deleteItem", deleteItem_static},
30 {
"execCalculate", execCalculate_static},
31 {
"execEvent", execEvent_static},
32 {
"execInitialize", execInitialize_static},
33 {
"execValidate", execValidate_static},
34 {
"getDisplayItem", getDisplayItem_static},
35 {
"getItemState", getItemState_static},
36 {
"getSaveItem", getSaveItem_static},
37 {
"setItemState", setItemState_static}};
39CJX_Field::CJX_Field(CXFA_Field* field) :
CJX_Container(field) {
50 pdfium::span<v8::Local<v8::Value>> params) {
58 pdfium::span<v8::Local<v8::Value>> params) {
59 if (params.size() != 1)
62 WideString eventString = runtime->ToWideString(params[0]);
74 pdfium::span<v8::Local<v8::Value>> params) {
87 pdfium::span<v8::Local<v8::Value>> params) {
88 if (params.size() != 1)
95 bool bValue = node->DeleteItem(runtime->ToInt32(params[0]),
true,
true);
100 pdfium::span<v8::Local<v8::Value>> params) {
101 if (params.size() != 1)
104 int32_t iIndex = runtime->ToInt32(params[0]);
112 absl::optional<WideString> value = node->GetChoiceListItem(iIndex,
true);
113 if (!value.has_value())
116 return CJS_Result::Success(
117 runtime->NewString(value->ToUTF8().AsStringView()));
121 pdfium::span<v8::Local<v8::Value>> params) {
122 if (params.size() != 1)
129 WideString value = runtime->ToWideString(params[0]);
132 runtime->NewString(boundValue
.ToUTF8().AsStringView())
);
136 pdfium::span<v8::Local<v8::Value>> params) {
137 if (params.size() != 1)
144 int32_t state = node->GetItemState(runtime->ToInt32(params[0]));
149 pdfium::span<v8::Local<v8::Value>> params) {
163 pdfium::span<v8::Local<v8::Value>> params) {
164 if (params.size() != 1)
167 int32_t iIndex = runtime->ToInt32(params[0]);
175 absl::optional<WideString> value = node->GetChoiceListItem(iIndex,
false);
176 if (!value.has_value())
179 return CJS_Result::Success(
180 runtime->NewString(value->ToUTF8().AsStringView()));
184 pdfium::span<v8::Local<v8::Value>> params) {
185 if (params.size() != 2)
192 int32_t iIndex = runtime->ToInt32(params[0]);
193 if (runtime->ToInt32(params[1]) != 0) {
204 pdfium::span<v8::Local<v8::Value>> params) {
205 if (params.size() != 1 && params.size() != 2)
213 if (params.size() >= 1)
214 label = runtime->ToWideString(params[0]);
217 if (params.size() >= 2)
218 value = runtime->ToWideString(params[1]);
225 pdfium::span<v8::Local<v8::Value>> params) {
239void CJX_Field::defaultValue(
v8::Isolate* pIsolate,
240 v8::Local<v8::Value>* pValue,
253 WideString wsNewText;
255 wsNewText = fxv8::ReentrantToWideStringHelper(pIsolate, *pValue);
260 WideString wsFormatText
(wsNewText
);
264 SetContent(wsNewText, wsFormatText,
true,
true,
true);
270 *pValue = fxv8::NewNullHelper(pIsolate);
275 CXFA_Node* pNode = formValue ? formValue->GetFirstChild() :
nullptr;
279 (pNode->JSObject()->GetInteger(
XFA_Attribute::FracDigits) == -1)) {
281 fxv8::NewStringHelper(pIsolate, content
.ToUTF8().AsStringView());
284 *pValue = fxv8::NewNumberHelper(pIsolate, decimal
.ToFloat());
293 *pValue = fxv8::NewNumberHelper(pIsolate, decimal
.ToFloat());
295 *pValue = fxv8::NewStringHelper(pIsolate, content
.ToUTF8().AsStringView());
299void CJX_Field::editValue(
v8::Isolate* pIsolate,
300 v8::Local<v8::Value>* pValue,
309 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue)
);
312 *pValue = fxv8::NewStringHelper(
317void CJX_Field::formatMessage(
v8::Isolate* pIsolate,
318 v8::Local<v8::Value>* pValue,
321 ScriptSomMessage(pIsolate, pValue, bSetting, SOMMessageType::kFormatMessage);
324void CJX_Field::formattedValue(
v8::Isolate* pIsolate,
325 v8::Local<v8::Value>* pValue,
334 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue)
);
337 *pValue = fxv8::NewStringHelper(
342void CJX_Field::length(
v8::Isolate* pIsolate,
343 v8::Local<v8::Value>* pValue,
352 *pValue = fxv8::NewNumberHelper(
354 node->CountChoiceListItems(
true))
358void CJX_Field::parentSubform(
v8::Isolate* pIsolate,
359 v8::Local<v8::Value>* pValue,
366 *pValue = fxv8::NewNullHelper(pIsolate);
369void CJX_Field::selectedIndex(
v8::Isolate* pIsolate,
370 v8::Local<v8::Value>* pValue,
382 int32_t iIndex = fxv8::ReentrantToInt32Helper(pIsolate, *pValue);
391void CJX_Field::rawValue(
v8::Isolate* pIsolate,
392 v8::Local<v8::Value>* pValue,
395 defaultValue(pIsolate, pValue, bSetting, eAttribute);
friend class EventParamScope
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
bool DynamicTypeIs(TypeTag eType) const override
bool DynamicTypeIs(TypeTag eType) const override
XFA_EventError execSingleEventByName(WideStringView wsEventName, XFA_Element eType)
void DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
WideString GetContent(bool bScriptModify) const
void ThrowInvalidPropertyException(v8::Isolate *pIsolate) const
CXFA_Document * GetDocument() const
CXFA_Node * GetXFANode() const
void SetContent(const WideString &wsContent, const WideString &wsXMLValue, bool bNotify, bool bScriptModify, bool bSyncData)
XFA_EventError ExecEventByDeepFirst(CXFA_Node *pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady, bool bRecursive)
CXFA_Value * GetFormValueIfExists() const
WideString GetValue(XFA_ValuePicture eValueType)
bool SetValue(XFA_ValuePicture eValueType, const WideString &wsValue)
int32_t GetSelectedItem(int32_t nIndex)
void SetItemState(int32_t nIndex, bool bSelected, bool bNotify, bool bScriptModify)
WideString NumericLimit(const WideString &wsValue)
void InsertItem(const WideString &wsLabel, const WideString &wsValue, bool bNotify)
WideString GetFormatDataValue(const WideString &wsValue)
bool DeleteItem(int32_t nIndex, bool bNotify, bool bScriptModify)
void SetPreNull(bool val)
bool GetItemState(int32_t nIndex)
void ClearAllSelections()
CXFA_Node * GetContainerNode()
bool IsWidgetReady() const
CXFA_Node * GetUIChildNode()
WideString GetItemValue(WideStringView wsLabel)
XFA_Element GetElementType() const
ByteString ToUTF8() const
WideString & operator=(WideString &&that) noexcept
const wchar_t * c_str() const
WideString(const WideString &other)
bool EqualsASCII(ByteStringView that) const
int32_t FXSYS_wtoi(const wchar_t *str)
bool IsUndefined(v8::Local< v8::Value > value)
bool IsNull(v8::Local< v8::Value > value)