7#include "fxjs/cjs_field.h"
13#include "constants/access_permissions.h"
14#include "constants/annotation_flags.h"
15#include "constants/form_flags.h"
16#include "core/fpdfapi/parser/cpdf_stream.h"
17#include "core/fpdfdoc/cpdf_formcontrol.h"
18#include "core/fpdfdoc/cpdf_formfield.h"
19#include "core/fpdfdoc/cpdf_interactiveform.h"
20#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
21#include "fpdfsdk/cpdfsdk_interactiveform.h"
22#include "fpdfsdk/cpdfsdk_pageview.h"
23#include "fpdfsdk/cpdfsdk_widget.h"
24#include "fxjs/cjs_color.h"
25#include "fxjs/cjs_delaydata.h"
26#include "fxjs/cjs_document.h"
27#include "fxjs/cjs_icon.h"
29#include "fxjs/js_resources.h"
30#include "third_party/abseil-cpp/absl/types/optional.h"
31#include "third_party/base/check.h"
32#include "third_party/base/containers/span.h"
33#include "third_party/base/notreached.h"
34#include "v8/include/v8-container.h"
38constexpr wchar_t kCheckSelector = L'4';
39constexpr wchar_t kCircleSelector = L'l';
40constexpr wchar_t kCrossSelector = L'8';
41constexpr wchar_t kDiamondSelector = L'u';
42constexpr wchar_t kSquareSelector = L'n';
43constexpr wchar_t kStarSelector = L'H';
60void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
65 std::vector<ObservedPtr<CPDFSDK_Widget>> widgets;
66 pForm->GetWidgets(pFormField, &widgets);
68 if (IsComboBoxOrTextField(pFormField)) {
69 for (
auto& pWidget : widgets) {
71 absl::optional<WideString> sValue = pWidget->OnFormat();
73 pWidget->ResetAppearance(sValue, CPDFSDK_Widget::kValueUnchanged);
78 for (
auto& pWidget : widgets) {
80 pWidget->ResetAppearance(absl::nullopt,
81 CPDFSDK_Widget::kValueUnchanged);
90 std::vector<ObservedPtr<CPDFSDK_Widget>> widgets;
91 pForm->GetWidgets(pFormField, &widgets);
92 for (
auto& pWidget : widgets) {
94 pFormFillEnv->UpdateAllViews(pWidget.Get());
99void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
102 DCHECK(pFormControl);
106 ObservedPtr<CPDFSDK_Widget> observed_widget(pWidget);
111 absl::optional<WideString> sValue = pWidget->OnFormat();
112 if (!observed_widget)
114 pWidget->ResetAppearance(sValue, CPDFSDK_Widget::kValueUnchanged);
116 pWidget->ResetAppearance(absl::nullopt,
117 CPDFSDK_Widget::kValueUnchanged);
119 if (!observed_widget)
127struct FieldNameData {
128 FieldNameData(WideString field_name_in,
int control_index_in)
129 : field_name(field_name_in), control_index(control_index_in) {}
131 WideString field_name;
135absl::optional<FieldNameData> ParseFieldName(
const WideString& field_name) {
136 auto reverse_it = field_name.rbegin();
137 while (reverse_it != field_name.rend()) {
138 if (*reverse_it == L'.')
142 if (reverse_it == field_name.rend()) {
143 return absl::nullopt;
145 WideString suffixal = field_name.Last(reverse_it - field_name.rbegin());
147 if (control_index == 0) {
149 if (suffixal
!= L"0") {
150 return absl::nullopt;
153 return FieldNameData(field_name.First(field_name.rend() - reverse_it - 1),
157std::vector<CPDF_FormField*> GetFormFieldsForName(
158 CPDFSDK_FormFillEnvironment* pFormFillEnv,
159 const WideString& csFieldName) {
160 std::vector<CPDF_FormField*> fields;
163 const size_t sz = pForm->CountFields(csFieldName);
164 for (size_t i = 0; i < sz; ++i) {
167 fields.push_back(pFormField);
173 const ByteString& entry) {
194bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget,
int value) {
233void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
234 const WideString& swFieldName,
236 const ByteString& bsString) {
237 DCHECK(pFormFillEnv);
240 if (bsString
== "solid")
242 else if (bsString
== "beveled")
244 else if (bsString
== "dashed")
246 else if (bsString
== "inset")
248 else if (bsString
== "underline")
253 std::vector<CPDF_FormField*> FieldArray =
254 GetFormFieldsForName(pFormFillEnv, swFieldName);
256 for (CPDF_FormField* pFormField : FieldArray) {
257 if (nControlIndex < 0) {
259 for (
int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
260 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormField->GetControl(i));
262 if (pWidget->GetBorderStyle() != nBorderStyle) {
263 pWidget->SetBorderStyle(nBorderStyle);
269 UpdateFormField(pFormFillEnv, pFormField,
true);
271 if (nControlIndex >= pFormField->CountControls())
273 if (CPDF_FormControl* pFormControl =
274 pFormField->GetControl(nControlIndex)) {
275 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
277 if (pWidget->GetBorderStyle() != nBorderStyle) {
278 pWidget->SetBorderStyle(nBorderStyle);
279 UpdateFormControl(pFormFillEnv, pFormControl,
true);
287void SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
288 const WideString& swFieldName,
290 const std::vector<uint32_t>& array) {
291 DCHECK(pFormFillEnv);
292 std::vector<CPDF_FormField*> FieldArray =
293 GetFormFieldsForName(pFormFillEnv, swFieldName);
295 for (CPDF_FormField* pFormField : FieldArray) {
296 if (!IsComboBoxOrListBox(pFormField))
299 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
300 pFormField->ClearSelection(NotificationOption::kNotify);
301 for (size_t i = 0; i < array.size(); ++i) {
302 if (i != 0 && !(dwFieldFlags & pdfium::form_flags::kChoiceMultiSelect))
304 if (array[i] <
static_cast<uint32_t>(pFormField->CountOptions()) &&
305 !pFormField->IsItemSelected(array[i])) {
306 pFormField->SetItemSelection(array[i],
307 NotificationOption::kDoNotNotify);
310 UpdateFormField(pFormFillEnv, pFormField,
true);
314void SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
315 const WideString& swFieldName,
319 std::vector<CPDF_FormField*> FieldArray =
320 GetFormFieldsForName(pFormFillEnv, swFieldName);
321 for (CPDF_FormField* pFormField : FieldArray) {
322 if (nControlIndex < 0) {
323 bool bAnySet =
false;
324 for (
int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
325 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
326 DCHECK(pFormControl);
328 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
329 if (SetWidgetDisplayStatus(pWidget, number))
334 UpdateFormField(pFormFillEnv, pFormField,
false);
336 if (nControlIndex >= pFormField->CountControls())
339 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
343 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
344 if (SetWidgetDisplayStatus(pWidget, number))
345 UpdateFormControl(pFormFillEnv, pFormControl,
false);
350void SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
351 const WideString& swFieldName,
354 int display = b ? 1 : 0 ;
355 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
358void SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
359 const WideString& swFieldName,
363 std::vector<CPDF_FormField*> FieldArray =
364 GetFormFieldsForName(pFormFillEnv, swFieldName);
365 for (CPDF_FormField* pFormField : FieldArray) {
366 if (nControlIndex < 0) {
368 for (
int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
369 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
370 DCHECK(pFormControl);
372 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
373 if (number != pWidget->GetBorderWidth()) {
374 pWidget->SetBorderWidth(number);
380 UpdateFormField(pFormFillEnv, pFormField,
true);
382 if (nControlIndex >= pFormField->CountControls())
384 if (CPDF_FormControl* pFormControl =
385 pFormField->GetControl(nControlIndex)) {
386 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
387 if (number != pWidget->GetBorderWidth()) {
388 pWidget->SetBorderWidth(number);
389 UpdateFormControl(pFormFillEnv, pFormControl,
true);
397void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
398 const WideString& swFieldName,
402 std::vector<CPDF_FormField*> FieldArray =
403 GetFormFieldsForName(pFormFillEnv, swFieldName);
404 for (CPDF_FormField* pFormField : FieldArray) {
405 if (nControlIndex < 0) {
407 for (
int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
408 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
409 DCHECK(pFormControl);
411 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
412 CFX_FloatRect crRect = rect;
414 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
415 crRect.Intersect(pPDFPage->GetBBox());
417 if (!crRect.IsEmpty()) {
418 CFX_FloatRect rcOld = pWidget->GetRect();
419 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
420 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
421 pWidget->SetRect(crRect);
429 UpdateFormField(pFormFillEnv, pFormField,
true);
434 if (nControlIndex >= pFormField->CountControls())
436 if (CPDF_FormControl* pFormControl =
437 pFormField->GetControl(nControlIndex)) {
438 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
439 CFX_FloatRect crRect = rect;
440 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
441 crRect.Intersect(pPDFPage->GetBBox());
442 if (!crRect.IsEmpty()) {
443 CFX_FloatRect rcOld = pWidget->GetRect();
444 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
445 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
446 pWidget->SetRect(crRect);
447 UpdateFormControl(pFormFillEnv, pFormControl,
true);
455void SetFieldValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
456 const WideString& swFieldName,
458 const std::vector<WideString>& strArray) {
459 DCHECK(pFormFillEnv);
460 if (strArray.empty())
463 std::vector<CPDF_FormField*> FieldArray =
464 GetFormFieldsForName(pFormFillEnv, swFieldName);
466 for (CPDF_FormField* pFormField : FieldArray) {
467 if (pFormField->GetFullName() != swFieldName)
470 switch (pFormField->GetFieldType()) {
471 case FormFieldType::kTextField:
472 case FormFieldType::kComboBox:
473 if (pFormField->GetValue() != strArray[0]) {
474 pFormField->SetValue(strArray[0], NotificationOption::kNotify);
475 UpdateFormField(pFormFillEnv, pFormField,
false);
478 case FormFieldType::kCheckBox:
479 case FormFieldType::kRadioButton:
480 if (pFormField->GetValue() != strArray[0]) {
481 pFormField->SetValue(strArray[0], NotificationOption::kNotify);
482 UpdateFormField(pFormFillEnv, pFormField,
false);
485 case FormFieldType::kListBox: {
486 bool bModified =
false;
487 for (
const auto& str : strArray) {
488 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
494 pFormField->ClearSelection(NotificationOption::kNotify);
495 for (
const auto& str : strArray) {
496 int index = pFormField->FindOption(str);
497 if (!pFormField->IsItemSelected(index))
498 pFormField->SetItemSelection(index, NotificationOption::kNotify);
500 UpdateFormField(pFormFillEnv, pFormField,
false);
510wchar_t GetSelectorFromCaptionForFieldType(
const WideString& caption,
517 return kCircleSelector;
519 return kCheckSelector;
526 {
"alignment", get_alignment_static, set_alignment_static},
527 {
"borderStyle", get_border_style_static, set_border_style_static},
528 {
"buttonAlignX", get_button_align_x_static, set_button_align_x_static},
529 {
"buttonAlignY", get_button_align_y_static, set_button_align_y_static},
530 {
"buttonFitBounds", get_button_fit_bounds_static,
531 set_button_fit_bounds_static},
532 {
"buttonPosition", get_button_position_static, set_button_position_static},
533 {
"buttonScaleHow", get_button_scale_how_static,
534 set_button_scale_how_static},
535 {
"buttonScaleWhen", get_button_scale_when_static,
536 set_button_scale_when_static},
537 {
"calcOrderIndex", get_calc_order_index_static,
538 set_calc_order_index_static},
539 {
"charLimit", get_char_limit_static, set_char_limit_static},
540 {
"comb", get_comb_static, set_comb_static},
541 {
"commitOnSelChange", get_commit_on_sel_change_static,
542 set_commit_on_sel_change_static},
543 {
"currentValueIndices", get_current_value_indices_static,
544 set_current_value_indices_static},
545 {
"defaultStyle", get_default_style_static, set_default_style_static},
546 {
"defaultValue", get_default_value_static, set_default_value_static},
547 {
"doNotScroll", get_do_not_scroll_static, set_do_not_scroll_static},
548 {
"doNotSpellCheck", get_do_not_spell_check_static,
549 set_do_not_spell_check_static},
550 {
"delay", get_delay_static, set_delay_static},
551 {
"display", get_display_static, set_display_static},
552 {
"doc", get_doc_static, set_doc_static},
553 {
"editable", get_editable_static, set_editable_static},
554 {
"exportValues", get_export_values_static, set_export_values_static},
555 {
"hidden", get_hidden_static, set_hidden_static},
556 {
"fileSelect", get_file_select_static, set_file_select_static},
557 {
"fillColor", get_fill_color_static, set_fill_color_static},
558 {
"lineWidth", get_line_width_static, set_line_width_static},
559 {
"highlight", get_highlight_static, set_highlight_static},
560 {
"multiline", get_multiline_static, set_multiline_static},
561 {
"multipleSelection", get_multiple_selection_static,
562 set_multiple_selection_static},
563 {
"name", get_name_static, set_name_static},
564 {
"numItems", get_num_items_static, set_num_items_static},
565 {
"page", get_page_static, set_page_static},
566 {
"password", get_password_static, set_password_static},
567 {
"print", get_print_static, set_print_static},
568 {
"radiosInUnison", get_radios_in_unison_static,
569 set_radios_in_unison_static},
570 {
"readonly", get_readonly_static, set_readonly_static},
571 {
"rect", get_rect_static, set_rect_static},
572 {
"required", get_required_static, set_required_static},
573 {
"richText", get_rich_text_static, set_rich_text_static},
574 {
"richValue", get_rich_value_static, set_rich_value_static},
575 {
"rotation", get_rotation_static, set_rotation_static},
576 {
"source", get_source_static, set_source_static},
577 {
"strokeColor", get_stroke_color_static, set_stroke_color_static},
578 {
"style", get_style_static, set_style_static},
579 {
"submitName", get_submit_name_static, set_submit_name_static},
580 {
"textColor", get_text_color_static, set_text_color_static},
581 {
"textFont", get_text_font_static, set_text_font_static},
582 {
"textSize", get_text_size_static, set_text_size_static},
583 {
"type", get_type_static, set_type_static},
584 {
"userName", get_user_name_static, set_user_name_static},
585 {
"value", get_value_static, set_value_static},
586 {
"valueAsString", get_value_as_string_static, set_value_as_string_static}};
589 {
"browseForFileToSubmit", browseForFileToSubmit_static},
590 {
"buttonGetCaption", buttonGetCaption_static},
591 {
"buttonGetIcon", buttonGetIcon_static},
592 {
"buttonImportIcon", buttonImportIcon_static},
593 {
"buttonSetCaption", buttonSetCaption_static},
594 {
"buttonSetIcon", buttonSetIcon_static},
595 {
"checkThisBox", checkThisBox_static},
596 {
"clearItems", clearItems_static},
597 {
"defaultIsChecked", defaultIsChecked_static},
598 {
"deleteItemAt", deleteItemAt_static},
599 {
"getArray", getArray_static},
600 {
"getItemAt", getItemAt_static},
601 {
"getLock", getLock_static},
602 {
"insertItemAt", insertItemAt_static},
603 {
"isBoxChecked", isBoxChecked_static},
604 {
"isDefaultChecked", isDefaultChecked_static},
605 {
"setAction", setAction_static},
606 {
"setFocus", setFocus_static},
607 {
"setItems", setItems_static},
608 {
"setLock", setLock_static},
609 {
"signatureGetModifications", signatureGetModifications_static},
610 {
"signatureGetSeedValue", signatureGetSeedValue_static},
611 {
"signatureInfo", signatureInfo_static},
612 {
"signatureSetSeedValue", signatureSetSeedValue_static},
613 {
"signatureSign", signatureSign_static},
614 {
"signatureValidate", signatureValidate_static}};
616uint32_t CJS_Field::ObjDefnID = 0;
617const char CJS_Field::kName[] =
"Field";
627 JSConstructor<CJS_Field>, JSDestructor);
632CJS_Field::
CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
638 const WideString& csFieldName) {
639 m_pJSDoc.Reset(pDocument);
640 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
641 m_bCanSet = m_pFormFillEnv->HasPermissions(
642 pdfium::access_permissions::kFillForm |
643 pdfium::access_permissions::kModifyAnnotation |
644 pdfium::access_permissions::kModifyContent);
646 CPDFSDK_InteractiveForm* pRDForm = m_pFormFillEnv->GetInteractiveForm();
648 WideString swFieldNameTemp = csFieldName;
649 swFieldNameTemp.Replace(L"..", L".");
651 if (pForm->CountFields(swFieldNameTemp) <= 0) {
652 absl::optional<FieldNameData> parsed_data = ParseFieldName(swFieldNameTemp);
653 if (!parsed_data.has_value())
656 m_FieldName = parsed_data.value().field_name;
657 m_nFormControlIndex = parsed_data.value().control_index;
661 m_FieldName = swFieldNameTemp;
662 m_nFormControlIndex = -1;
667std::vector<CPDF_FormField*> CJS_Field::GetFormFields()
const {
668 return GetFormFieldsForName(m_pFormFillEnv.Get(), m_FieldName);
672 std::vector<CPDF_FormField*> fields = GetFormFields();
673 return fields.empty() ?
nullptr : fields[0];
680 if (m_nFormControlIndex < 0)
685CJS_Result CJS_Field::get_alignment(CJS_Runtime* pRuntime) {
686 DCHECK(m_pFormFillEnv);
710CJS_Result CJS_Field::set_alignment(CJS_Runtime* pRuntime,
711 v8::Local<v8::Value> vp) {
712 DCHECK(m_pFormFillEnv);
719CJS_Result CJS_Field::get_border_style(CJS_Runtime* pRuntime) {
720 DCHECK(m_pFormFillEnv);
726 CPDFSDK_Widget* pWidget = m_pFormFillEnv->GetInteractiveForm()->GetWidget(
727 GetSmartFieldControl(pFormField));
746CJS_Result CJS_Field::set_border_style(CJS_Runtime* pRuntime,
747 v8::Local<v8::Value> vp) {
748 DCHECK(m_pFormFillEnv);
752 ByteString byte_str = pRuntime->ToByteString(vp);
756 SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
762CJS_Result CJS_Field::get_button_align_x(CJS_Runtime* pRuntime) {
763 DCHECK(m_pFormFillEnv);
777 CFX_PointF pos = IconFit.GetIconBottomLeftPosition();
781CJS_Result CJS_Field::set_button_align_x(CJS_Runtime* pRuntime,
782 v8::Local<v8::Value> vp) {
783 DCHECK(m_pFormFillEnv);
789CJS_Result CJS_Field::get_button_align_y(CJS_Runtime* pRuntime) {
790 DCHECK(m_pFormFillEnv);
804 CFX_PointF pos = IconFit.GetIconBottomLeftPosition();
808CJS_Result CJS_Field::set_button_align_y(CJS_Runtime* pRuntime,
809 v8::Local<v8::Value> vp) {
810 DCHECK(m_pFormFillEnv);
816CJS_Result CJS_Field::get_button_fit_bounds(CJS_Runtime* pRuntime) {
817 DCHECK(m_pFormFillEnv);
834CJS_Result CJS_Field::set_button_fit_bounds(CJS_Runtime* pRuntime,
835 v8::Local<v8::Value> vp) {
836 DCHECK(m_pFormFillEnv);
842CJS_Result CJS_Field::get_button_position(CJS_Runtime* pRuntime) {
843 DCHECK(m_pFormFillEnv);
860CJS_Result CJS_Field::set_button_position(CJS_Runtime* pRuntime,
861 v8::Local<v8::Value> vp) {
862 DCHECK(m_pFormFillEnv);
868CJS_Result CJS_Field::get_button_scale_how(CJS_Runtime* pRuntime) {
869 DCHECK(m_pFormFillEnv);
886CJS_Result CJS_Field::set_button_scale_how(CJS_Runtime* pRuntime,
887 v8::Local<v8::Value> vp) {
888 DCHECK(m_pFormFillEnv);
894CJS_Result CJS_Field::get_button_scale_when(CJS_Runtime* pRuntime) {
895 DCHECK(m_pFormFillEnv);
910 switch (scale_method) {
916 pRuntime->NewNumber(
static_cast<
int>(scale_method))
);
920CJS_Result CJS_Field::set_button_scale_when(CJS_Runtime* pRuntime,
921 v8::Local<v8::Value> vp) {
922 DCHECK(m_pFormFillEnv);
928CJS_Result CJS_Field::get_calc_order_index(CJS_Runtime* pRuntime) {
929 DCHECK(m_pFormFillEnv);
935 if (!IsComboBoxOrTextField(pFormField))
938 CPDFSDK_InteractiveForm* pRDForm = m_pFormFillEnv->GetInteractiveForm();
944CJS_Result CJS_Field::set_calc_order_index(CJS_Runtime* pRuntime,
945 v8::Local<v8::Value> vp) {
946 DCHECK(m_pFormFillEnv);
952CJS_Result CJS_Field::get_char_limit(CJS_Runtime* pRuntime) {
953 DCHECK(m_pFormFillEnv);
962 pRuntime->NewNumber(
static_cast<int32_t>(pFormField
->GetMaxLen()))
);
965CJS_Result CJS_Field::set_char_limit(CJS_Runtime* pRuntime,
966 v8::Local<v8::Value> vp) {
967 DCHECK(m_pFormFillEnv);
973CJS_Result CJS_Field::get_comb(CJS_Runtime* pRuntime) {
974 DCHECK(m_pFormFillEnv);
987CJS_Result CJS_Field::set_comb(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
988 DCHECK(m_pFormFillEnv);
994CJS_Result CJS_Field::get_commit_on_sel_change(CJS_Runtime* pRuntime) {
995 DCHECK(m_pFormFillEnv);
1001 if (!IsComboBoxOrListBox(pFormField))
1009CJS_Result CJS_Field::set_commit_on_sel_change(CJS_Runtime* pRuntime,
1010 v8::Local<v8::Value> vp) {
1011 DCHECK(m_pFormFillEnv);
1017CJS_Result CJS_Field::get_current_value_indices(CJS_Runtime* pRuntime) {
1022 if (!IsComboBoxOrListBox(pFormField))
1032 v8::Local<v8::Array> SelArray = pRuntime->NewArray();
1033 for (
int i = 0; i < count; i++) {
1034 pRuntime->PutArrayElement(
1035 SelArray, i, pRuntime->NewNumber(pFormField->GetSelectedIndex(i)));
1037 if (SelArray.IsEmpty())
1039 return CJS_Result::Success(SelArray);
1042CJS_Result CJS_Field::set_current_value_indices(CJS_Runtime* pRuntime,
1043 v8::Local<v8::Value> vp) {
1047 std::vector<uint32_t> array;
1048 if (vp->IsNumber()) {
1049 array.push_back(pRuntime->ToInt32(vp));
1051 v8::Local<v8::Array> SelArray = pRuntime->ToArray(vp);
1052 for (size_t i = 0; i < pRuntime->GetArrayLength(SelArray); i++) {
1054 pRuntime->ToInt32(pRuntime->GetArrayElement(SelArray, i)));
1059 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1061 SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
1062 m_nFormControlIndex, array);
1067CJS_Result CJS_Field::get_default_style(CJS_Runtime* pRuntime) {
1071CJS_Result CJS_Field::set_default_style(CJS_Runtime* pRuntime,
1072 v8::Local<v8::Value> vp) {
1076CJS_Result CJS_Field::get_default_value(CJS_Runtime* pRuntime) {
1077 DCHECK(m_pFormFillEnv);
1092CJS_Result CJS_Field::set_default_value(CJS_Runtime* pRuntime,
1093 v8::Local<v8::Value> vp) {
1094 DCHECK(m_pFormFillEnv);
1100CJS_Result CJS_Field::get_do_not_scroll(CJS_Runtime* pRuntime) {
1101 DCHECK(m_pFormFillEnv);
1114CJS_Result CJS_Field::set_do_not_scroll(CJS_Runtime* pRuntime,
1115 v8::Local<v8::Value> vp) {
1116 DCHECK(m_pFormFillEnv);
1122CJS_Result CJS_Field::get_do_not_spell_check(CJS_Runtime* pRuntime) {
1123 DCHECK(m_pFormFillEnv);
1129 if (!IsComboBoxOrTextField(pFormField))
1137CJS_Result CJS_Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
1138 v8::Local<v8::Value> vp) {
1139 DCHECK(m_pFormFillEnv);
1145CJS_Result CJS_Field::get_delay(CJS_Runtime* pRuntime) {
1149CJS_Result CJS_Field::set_delay(CJS_Runtime* pRuntime,
1150 v8::Local<v8::Value> vp) {
1154 SetDelay(pRuntime->ToBoolean(vp));
1158CJS_Result CJS_Field::get_display(CJS_Runtime* pRuntime) {
1163 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1164 CPDFSDK_Widget* pWidget = pForm
->GetWidget(GetSmartFieldControl(pFormField)
);
1182CJS_Result CJS_Field::set_display(CJS_Runtime* pRuntime,
1183 v8::Local<v8::Value> vp) {
1188 AddDelay_Int(
FP_DISPLAY, pRuntime->ToInt32(vp));
1190 SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1191 pRuntime->ToInt32(vp));
1196CJS_Result CJS_Field::get_doc(CJS_Runtime* pRuntime) {
1197 return CJS_Result::Success(m_pJSDoc->ToV8Object());
1200CJS_Result CJS_Field::set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1204CJS_Result CJS_Field::get_editable(CJS_Runtime* pRuntime) {
1216CJS_Result CJS_Field::set_editable(CJS_Runtime* pRuntime,
1217 v8::Local<v8::Value> vp) {
1223CJS_Result CJS_Field::get_export_values(CJS_Runtime* pRuntime) {
1228 if (!IsCheckBoxOrRadioButton(pFormField))
1231 v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray();
1232 if (m_nFormControlIndex < 0) {
1235 pRuntime->PutArrayElement(
1236 ExportValuesArray, i,
1237 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
1248 pRuntime->PutArrayElement(
1249 ExportValuesArray, 0,
1250 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
1252 return CJS_Result::Success(ExportValuesArray);
1255CJS_Result CJS_Field::set_export_values(CJS_Runtime* pRuntime,
1256 v8::Local<v8::Value> vp) {
1261 if (!IsCheckBoxOrRadioButton(pFormField))
1273CJS_Result CJS_Field::get_file_select(CJS_Runtime* pRuntime) {
1285CJS_Result CJS_Field::set_file_select(CJS_Runtime* pRuntime,
1286 v8::Local<v8::Value> vp) {
1300CJS_Result CJS_Field::get_fill_color(CJS_Runtime* pRuntime) {
1310 v8::Local<v8::Value> array =
1311 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
1312 if (array.IsEmpty())
1314 return CJS_Result::Success(array);
1317CJS_Result CJS_Field::set_fill_color(CJS_Runtime* pRuntime,
1318 v8::Local<v8::Value> vp) {
1319 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
1320 if (FieldArray.empty())
1329CJS_Result CJS_Field::get_hidden(CJS_Runtime* pRuntime) {
1334 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1335 CPDFSDK_Widget* pWidget = pForm
->GetWidget(GetSmartFieldControl(pFormField)
);
1345CJS_Result CJS_Field::set_hidden(CJS_Runtime* pRuntime,
1346 v8::Local<v8::Value> vp) {
1351 AddDelay_Bool(
FP_HIDDEN, pRuntime->ToBoolean(vp));
1353 SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1354 pRuntime->ToBoolean(vp));
1359CJS_Result CJS_Field::get_highlight(CJS_Runtime* pRuntime) {
1360 DCHECK(m_pFormFillEnv);
1389CJS_Result CJS_Field::set_highlight(CJS_Runtime* pRuntime,
1390 v8::Local<v8::Value> vp) {
1391 DCHECK(m_pFormFillEnv);
1397CJS_Result CJS_Field::get_line_width(CJS_Runtime* pRuntime) {
1406 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1417CJS_Result CJS_Field::set_line_width(CJS_Runtime* pRuntime,
1418 v8::Local<v8::Value> vp) {
1425 SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1426 pRuntime->ToInt32(vp));
1431CJS_Result CJS_Field::get_multiline(CJS_Runtime* pRuntime) {
1432 DCHECK(m_pFormFillEnv);
1445CJS_Result CJS_Field::set_multiline(CJS_Runtime* pRuntime,
1446 v8::Local<v8::Value> vp) {
1447 DCHECK(m_pFormFillEnv);
1453CJS_Result CJS_Field::get_multiple_selection(CJS_Runtime* pRuntime) {
1454 DCHECK(m_pFormFillEnv);
1467CJS_Result CJS_Field::set_multiple_selection(CJS_Runtime* pRuntime,
1468 v8::Local<v8::Value> vp) {
1469 DCHECK(m_pFormFillEnv);
1475CJS_Result CJS_Field::get_name(CJS_Runtime* pRuntime) {
1476 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
1477 if (FieldArray.empty())
1480 return CJS_Result::Success(pRuntime->NewString(m_FieldName.AsStringView()));
1483CJS_Result CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1487CJS_Result CJS_Field::get_num_items(CJS_Runtime* pRuntime) {
1492 if (!IsComboBoxOrListBox(pFormField))
1498CJS_Result CJS_Field::set_num_items(CJS_Runtime* pRuntime,
1499 v8::Local<v8::Value> vp) {
1503CJS_Result CJS_Field::get_page(CJS_Runtime* pRuntime) {
1508 std::vector<ObservedPtr<CPDFSDK_Widget>> widgets;
1509 m_pFormFillEnv->GetInteractiveForm()->GetWidgets(pFormField, &widgets);
1510 if (widgets.empty())
1513 v8::Local<v8::Array> PageArray = pRuntime->NewArray();
1515 for (
const auto& pWidget : widgets) {
1517 return CJS_Result::Failure(JSMessage::kBadObjectError);
1519 pRuntime->PutArrayElement(
1521 pRuntime->NewNumber(pWidget->GetPageView()->GetPageIndex()));
1524 return CJS_Result::Success(PageArray);
1527CJS_Result CJS_Field::set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1531CJS_Result CJS_Field::get_password(CJS_Runtime* pRuntime) {
1532 DCHECK(m_pFormFillEnv);
1545CJS_Result CJS_Field::set_password(CJS_Runtime* pRuntime,
1546 v8::Local<v8::Value> vp) {
1547 DCHECK(m_pFormFillEnv);
1553CJS_Result CJS_Field::get_print(CJS_Runtime* pRuntime) {
1554 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1559 CPDFSDK_Widget* pWidget = pForm
->GetWidget(GetSmartFieldControl(pFormField)
);
1567CJS_Result CJS_Field::set_print(CJS_Runtime* pRuntime,
1568 v8::Local<v8::Value> vp) {
1569 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1570 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
1571 if (FieldArray.empty())
1577 for (CPDF_FormField* pFormField : FieldArray) {
1578 if (m_nFormControlIndex < 0) {
1580 for (
int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1581 if (CPDFSDK_Widget* pWidget =
1582 pForm->GetWidget(pFormField->GetControl(i))) {
1583 uint32_t dwFlags = pWidget->GetFlags();
1584 if (pRuntime->ToBoolean(vp))
1585 dwFlags |= pdfium::annotation_flags::kPrint;
1587 dwFlags &= ~pdfium::annotation_flags::kPrint;
1589 if (dwFlags != pWidget->GetFlags()) {
1590 pWidget->SetFlags(dwFlags);
1597 UpdateFormField(m_pFormFillEnv.Get(), pFormField,
false);
1602 if (m_nFormControlIndex >= pFormField->CountControls())
1603 return CJS_Result::Failure(JSMessage::kValueError);
1605 if (CPDF_FormControl* pFormControl =
1606 pFormField->GetControl(m_nFormControlIndex)) {
1607 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
1608 uint32_t dwFlags = pWidget->GetFlags();
1609 if (pRuntime->ToBoolean(vp))
1610 dwFlags |= pdfium::annotation_flags::kPrint;
1612 dwFlags &= ~pdfium::annotation_flags::kPrint;
1614 if (dwFlags != pWidget->GetFlags()) {
1615 pWidget->SetFlags(dwFlags);
1616 UpdateFormControl(m_pFormFillEnv.Get(),
1617 pFormField->GetControl(m_nFormControlIndex),
false);
1625CJS_Result CJS_Field::get_radios_in_unison(CJS_Runtime* pRuntime) {
1638CJS_Result CJS_Field::set_radios_in_unison(CJS_Runtime* pRuntime,
1639 v8::Local<v8::Value> vp) {
1640 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
1641 if (FieldArray.empty())
1648CJS_Result CJS_Field::get_readonly(CJS_Runtime* pRuntime) {
1657CJS_Result CJS_Field::set_readonly(CJS_Runtime* pRuntime,
1658 v8::Local<v8::Value> vp) {
1666 const bool bReadOnly = pRuntime->ToBoolean(vp);
1668 const uint32_t dwNewFlags = bReadOnly
1671 if (dwNewFlags != dwFlags)
1677CJS_Result CJS_Field::get_rect(CJS_Runtime* pRuntime) {
1682 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1683 CPDFSDK_Widget* pWidget = pForm
->GetWidget(GetSmartFieldControl(pFormField)
);
1688 v8::Local<v8::Array> rcArray = pRuntime->NewArray();
1689 pRuntime->PutArrayElement(
1690 rcArray, 0, pRuntime->NewNumber(
static_cast<int32_t>(crRect.left)));
1691 pRuntime->PutArrayElement(
1692 rcArray, 1, pRuntime->NewNumber(
static_cast<int32_t>(crRect.top)));
1693 pRuntime->PutArrayElement(
1694 rcArray, 2, pRuntime->NewNumber(
static_cast<int32_t>(crRect.right)));
1695 pRuntime->PutArrayElement(
1696 rcArray, 3, pRuntime->NewNumber(
static_cast<int32_t>(crRect.bottom)));
1698 return CJS_Result::Success(rcArray);
1701CJS_Result CJS_Field::set_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1707 v8::Local<v8::Array> rcArray = pRuntime->ToArray(vp);
1708 if (pRuntime->GetArrayLength(rcArray) < 4)
1711 float f0 =
static_cast<
float>(
1712 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 0)));
1713 float f1 =
static_cast<
float>(
1714 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 1)));
1715 float f2 =
static_cast<
float>(
1716 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 2)));
1717 float f3 =
static_cast<
float>(
1718 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 3)));
1722 AddDelay_Rect(
FP_RECT, crRect);
1724 SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, crRect);
1729CJS_Result CJS_Field::get_required(CJS_Runtime* pRuntime) {
1741CJS_Result CJS_Field::set_required(CJS_Runtime* pRuntime,
1742 v8::Local<v8::Value> vp) {
1743 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
1744 if (FieldArray.empty())
1751CJS_Result CJS_Field::get_rich_text(CJS_Runtime* pRuntime) {
1752 DCHECK(m_pFormFillEnv);
1765CJS_Result CJS_Field::set_rich_text(CJS_Runtime* pRuntime,
1766 v8::Local<v8::Value> vp) {
1767 DCHECK(m_pFormFillEnv);
1773CJS_Result CJS_Field::get_rich_value(CJS_Runtime* pRuntime) {
1777CJS_Result CJS_Field::set_rich_value(CJS_Runtime* pRuntime,
1778 v8::Local<v8::Value> vp) {
1782CJS_Result CJS_Field::get_rotation(CJS_Runtime* pRuntime) {
1783 DCHECK(m_pFormFillEnv);
1796CJS_Result CJS_Field::set_rotation(CJS_Runtime* pRuntime,
1797 v8::Local<v8::Value> vp) {
1798 DCHECK(m_pFormFillEnv);
1804CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) {
1808CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime,
1809 v8::Local<v8::Value> vp) {
1813CJS_Result CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) {
1823 v8::Local<v8::Value> array =
1824 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
1825 if (array.IsEmpty())
1827 return CJS_Result::Success(array);
1830CJS_Result CJS_Field::set_stroke_color(CJS_Runtime* pRuntime,
1831 v8::Local<v8::Value> vp) {
1839CJS_Result CJS_Field::get_style(CJS_Runtime* pRuntime) {
1840 DCHECK(m_pFormFillEnv);
1846 if (!IsCheckBoxOrRadioButton(pFormField))
1853 wchar_t selector = GetSelectorFromCaptionForFieldType(
1856 ByteString csBCaption;
1858 case kCircleSelector:
1859 csBCaption
= "circle";
1861 case kCrossSelector:
1862 csBCaption
= "cross";
1864 case kDiamondSelector:
1865 csBCaption
= "diamond";
1867 case kSquareSelector:
1868 csBCaption
= "square";
1871 csBCaption
= "star";
1873 case kCheckSelector:
1875 csBCaption
= "check";
1881CJS_Result CJS_Field::set_style(CJS_Runtime* pRuntime,
1882 v8::Local<v8::Value> vp) {
1883 DCHECK(m_pFormFillEnv);
1889CJS_Result CJS_Field::get_submit_name(CJS_Runtime* pRuntime) {
1893CJS_Result CJS_Field::set_submit_name(CJS_Runtime* pRuntime,
1894 v8::Local<v8::Value> vp) {
1908 absl::optional<CFX_Color::TypeAndARGB> maybe_type_argb_pair =
1909 FieldAppearance.GetColorARGB();
1912 if (maybe_type_argb_pair.has_value() &&
1913 maybe_type_argb_pair.value().color_type !=
1914 CFX_Color::Type::kTransparent) {
1919 std::tie(a, r, g, b) = ArgbDecode(maybe_type_argb_pair.value().argb);
1924 v8::Local<v8::Value> array =
1925 CJS_Color::ConvertPWLColorToArray(pRuntime, crRet);
1926 if (array.IsEmpty())
1928 return CJS_Result::Success(array);
1932 v8::Local<v8::Value> vp) {
1940CJS_Result CJS_Field::get_text_font(CJS_Runtime* pRuntime) {
1941 DCHECK(m_pFormFillEnv);
1959 absl::optional<WideString> wsFontName =
1960 pFormControl->GetDefaultControlFontName();
1961 if (!wsFontName.has_value())
1964 return CJS_Result::Success(
1965 pRuntime->NewString(wsFontName.value().AsStringView()));
1968CJS_Result CJS_Field::set_text_font(CJS_Runtime* pRuntime,
1969 v8::Local<v8::Value> vp) {
1970 DCHECK(m_pFormFillEnv);
1974 if (pRuntime->ToByteString(vp).IsEmpty())
1979CJS_Result CJS_Field::get_text_size(CJS_Runtime* pRuntime) {
1980 DCHECK(m_pFormFillEnv);
1992 FieldAppearance.GetFont(&fFontSize);
1996CJS_Result CJS_Field::set_text_size(CJS_Runtime* pRuntime,
1997 v8::Local<v8::Value> vp) {
1998 DCHECK(m_pFormFillEnv);
2004CJS_Result CJS_Field::get_type(CJS_Runtime* pRuntime) {
2026#ifdef PDF_ENABLE_XFA
2028 return CJS_Result::Success(pRuntime->NewString(
"unknown"));
2033CJS_Result CJS_Field::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
2037CJS_Result CJS_Field::get_user_name(CJS_Runtime* pRuntime) {
2038 DCHECK(m_pFormFillEnv);
2048CJS_Result CJS_Field::set_user_name(CJS_Runtime* pRuntime,
2049 v8::Local<v8::Value> vp) {
2050 DCHECK(m_pFormFillEnv);
2056CJS_Result CJS_Field::get_value(CJS_Runtime* pRuntime) {
2061 v8::Local<v8::Value> ret;
2065 case FormFieldType::kComboBox:
2066 case FormFieldType::kTextField:
2067 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
2071 v8::Local<v8::Array> ValueArray = pRuntime->NewArray();
2072 v8::Local<v8::Value> ElementValue;
2076 ElementValue = pRuntime->NewString(
2077 pFormField->GetOptionValue(iIndex).AsStringView());
2078 if (pRuntime->ToWideString(ElementValue).IsEmpty()) {
2079 ElementValue = pRuntime->NewString(
2080 pFormField->GetOptionLabel(iIndex).AsStringView());
2082 pRuntime->PutArrayElement(ValueArray, i, ElementValue);
2086 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
2095 ret = pRuntime->NewString(
2096 pFormField->GetControl(i)->GetExportValue().AsStringView());
2102 ret = pRuntime->NewString(
"Off");
2107 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
2110 return CJS_Result::Success(pRuntime->MaybeCoerceToNumber(ret));
2113CJS_Result CJS_Field::set_value(CJS_Runtime* pRuntime,
2114 v8::Local<v8::Value> vp) {
2118 std::vector<WideString> strArray;
2120 v8::Local<v8::Array> ValueArray = pRuntime->ToArray(vp);
2121 for (size_t i = 0; i < pRuntime->GetArrayLength(ValueArray); i++) {
2123 pRuntime->ToWideString(pRuntime->GetArrayElement(ValueArray, i)));
2126 strArray.push_back(pRuntime->ToWideString(vp));
2130 AddDelay_WideStringArray(FP_VALUE, strArray);
2132 SetFieldValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
2138CJS_Result CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) {
2170 pRuntime->NewString(pFormField
->GetValue().AsStringView())
);
2173CJS_Result CJS_Field::set_value_as_string(CJS_Runtime* pRuntime,
2174 v8::Local<v8::Value> vp) {
2179 CJS_Runtime* pRuntime,
2180 pdfium::span<v8::Local<v8::Value>> params) {
2187 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
2190 UpdateFormField(m_pFormFillEnv.Get(), pFormField,
true);
2198 CJS_Runtime* pRuntime,
2199 pdfium::span<v8::Local<v8::Value>> params) {
2201 if (params.size() >= 1)
2202 nface = pRuntime->ToInt32(params[0]);
2230CJS_Result CJS_Field::buttonGetIcon(CJS_Runtime* pRuntime,
2231 pdfium::span<v8::Local<v8::Value>> params) {
2232 if (params.size() >= 1) {
2233 int nFace = pRuntime->ToInt32(params[0]);
2234 if (nFace < 0 || nFace > 2)
2249 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2250 CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
2254 auto* pJS_Icon =
static_cast<CJS_Icon*>(
2255 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
2261 CJS_Runtime* pRuntime,
2262 pdfium::span<v8::Local<v8::Value>> params) {
2267 CJS_Runtime* pRuntime,
2268 pdfium::span<v8::Local<v8::Value>> params) {
2272CJS_Result CJS_Field::buttonSetIcon(CJS_Runtime* pRuntime,
2273 pdfium::span<v8::Local<v8::Value>> params) {
2277CJS_Result CJS_Field::checkThisBox(CJS_Runtime* pRuntime,
2278 pdfium::span<v8::Local<v8::Value>> params) {
2279 const size_t nSize = params.size();
2286 int nWidget = pRuntime->ToInt32(params[0]);
2287 bool bCheckit =
true;
2289 bCheckit = pRuntime->ToBoolean(params[1]);
2295 if (!IsCheckBoxOrRadioButton(pFormField))
2304 UpdateFormField(m_pFormFillEnv.Get(), pFormField,
true);
2308CJS_Result CJS_Field::clearItems(CJS_Runtime* pRuntime,
2309 pdfium::span<v8::Local<v8::Value>> params) {
2314 CJS_Runtime* pRuntime,
2315 pdfium::span<v8::Local<v8::Value>> params) {
2326 int nWidget = pRuntime->ToInt32(params[0]);
2331 pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField))
);
2334CJS_Result CJS_Field::deleteItemAt(CJS_Runtime* pRuntime,
2335 pdfium::span<v8::Local<v8::Value>> params) {
2339CJS_Result CJS_Field::getArray(CJS_Runtime* pRuntime,
2340 pdfium::span<v8::Local<v8::Value>> params) {
2341 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
2342 if (FieldArray.empty())
2345 std::vector<std::unique_ptr<WideString>> swSort;
2346 for (CPDF_FormField* pFormField : FieldArray) {
2347 swSort.push_back(std::make_unique<WideString>(pFormField->GetFullName()));
2350 std::sort(swSort.begin(), swSort.end(),
2351 [](
const std::unique_ptr<WideString>& p1,
2352 const std::unique_ptr<WideString>& p2) {
return *p1 < *p2; });
2354 v8::Local<v8::Array> FormFieldArray = pRuntime->NewArray();
2356 for (
const auto& pStr : swSort) {
2357 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2358 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
2360 return CJS_Result::Failure(JSMessage::kBadObjectError);
2362 auto* pJSField =
static_cast<CJS_Field*>(
2363 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
2364 pJSField->AttachField(m_pJSDoc.Get(), *pStr);
2365 pRuntime->PutArrayElement(FormFieldArray, j++,
2367 ? v8::Local<v8::Value>(pJSField->ToV8Object())
2368 : v8::Local<v8::Value>());
2370 return CJS_Result::Success(FormFieldArray);
2373CJS_Result CJS_Field::getItemAt(CJS_Runtime* pRuntime,
2374 pdfium::span<v8::Local<v8::Value>> params) {
2375 const size_t nSize = params.size();
2378 nIdx = pRuntime->ToInt32(params[0]);
2380 bool bExport =
true;
2382 bExport = pRuntime->ToBoolean(params[1]);
2388 if (!IsComboBoxOrListBox(pFormField))
2406CJS_Result CJS_Field::getLock(CJS_Runtime* pRuntime,
2407 pdfium::span<v8::Local<v8::Value>> params) {
2411CJS_Result CJS_Field::insertItemAt(CJS_Runtime* pRuntime,
2412 pdfium::span<v8::Local<v8::Value>> params) {
2416CJS_Result CJS_Field::isBoxChecked(CJS_Runtime* pRuntime,
2417 pdfium::span<v8::Local<v8::Value>> params) {
2419 if (params.size() >= 1)
2420 nIndex = pRuntime->ToInt32(params[0]);
2430 pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) &&
2435 CJS_Runtime* pRuntime,
2436 pdfium::span<v8::Local<v8::Value>> params) {
2438 if (params.size() >= 1)
2439 nIndex = pRuntime->ToInt32(params[0]);
2449 (IsCheckBoxOrRadioButton(pFormField) &&
2453CJS_Result CJS_Field::setAction(CJS_Runtime* pRuntime,
2454 pdfium::span<v8::Local<v8::Value>> params) {
2458CJS_Result CJS_Field::setFocus(CJS_Runtime* pRuntime,
2459 pdfium::span<v8::Local<v8::Value>> params) {
2468 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
2469 CPDFSDK_Widget* pWidget =
nullptr;
2473 IPDF_Page* pPage = m_pFormFillEnv->GetCurrentPage();
2476 CPDFSDK_PageView* pCurPageView = m_pFormFillEnv->GetOrCreatePageView(pPage);
2477 for (int32_t i = 0; i < nCount; i++) {
2478 if (CPDFSDK_Widget* pTempWidget =
2481 pWidget = pTempWidget;
2490 m_pFormFillEnv->SetFocusAnnot(pObserved);
2496CJS_Result CJS_Field::setItems(CJS_Runtime* pRuntime,
2497 pdfium::span<v8::Local<v8::Value>> params) {
2501CJS_Result CJS_Field::setLock(CJS_Runtime* pRuntime,
2502 pdfium::span<v8::Local<v8::Value>> params) {
2506CJS_Result CJS_Field::signatureGetModifications(
2507 CJS_Runtime* pRuntime,
2508 pdfium::span<v8::Local<v8::Value>> params) {
2513 CJS_Runtime* pRuntime,
2514 pdfium::span<v8::Local<v8::Value>> params) {
2518CJS_Result CJS_Field::signatureInfo(CJS_Runtime* pRuntime,
2519 pdfium::span<v8::Local<v8::Value>> params) {
2524 CJS_Runtime* pRuntime,
2525 pdfium::span<v8::Local<v8::Value>> params) {
2529CJS_Result CJS_Field::signatureSign(CJS_Runtime* pRuntime,
2530 pdfium::span<v8::Local<v8::Value>> params) {
2535 CJS_Runtime* pRuntime,
2536 pdfium::span<v8::Local<v8::Value>> params) {
2540void CJS_Field::SetDelay(
bool bDelay) {
2546 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
2549void CJS_Field::AddDelay_Int(
FIELD_PROP prop, int32_t n) {
2551 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2553 m_pJSDoc->AddDelayData(std::move(pNewData));
2556void CJS_Field::AddDelay_Bool(
FIELD_PROP prop,
bool b) {
2558 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2560 m_pJSDoc->AddDelayData(std::move(pNewData));
2563void CJS_Field::AddDelay_String(
FIELD_PROP prop,
const ByteString& str) {
2565 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2566 pNewData->bytestring = str;
2567 m_pJSDoc->AddDelayData(std::move(pNewData));
2572 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2573 pNewData->rect = rect;
2574 m_pJSDoc->AddDelayData(std::move(pNewData));
2577void CJS_Field::AddDelay_WordArray(
FIELD_PROP prop,
2578 const std::vector<uint32_t>& array) {
2580 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2581 pNewData->wordarray = array;
2582 m_pJSDoc->AddDelayData(std::move(pNewData));
2585void CJS_Field::AddDelay_WideStringArray(
FIELD_PROP prop,
2586 const std::vector<WideString>& array) {
2588 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2589 pNewData->widestringarray = array;
2590 m_pJSDoc->AddDelayData(std::move(pNewData));
2593void CJS_Field::
DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2595 DCHECK(pFormFillEnv);
2602 SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
2623 pData->widestringarray);
constexpr CFX_FloatRect(float l, float b, float r, float t)
CJS_Result get_text_color(CJS_Runtime *pRuntime)
CJS_Result set_text_color(CJS_Runtime *pRuntime, v8::Local< v8::Value > vp)
static void DefineJSObjects(CFXJS_Engine *pEngine)
static uint32_t GetObjDefnID()
bool AttachField(CJS_Document *pDocument, const WideString &csFieldName)
CJS_Field(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
static void DoDelay(CPDFSDK_FormFillEnvironment *pFormFillEnv, CJS_DelayData *pData)
static void DefineProps(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSPropertySpec > consts)
static void DefineMethods(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSMethodSpec > consts)
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
BorderStyle GetBorderStyle() const
int GetBorderWidth() const
void SetFlags(uint32_t nFlags)
CFX_FloatRect GetRect() const override
uint32_t GetFlags() const
CPDF_Page * GetPDFPage() const
ScaleMethod GetScaleMethod() const
bool GetFittingBounds() const
bool IsProportionalScale() const
bool operator==(const char *ptr) const
ByteString & operator=(const char *str)
CharType operator[](const size_t index) const
const wchar_t * c_str() const
void TrimRight(wchar_t target)
bool operator!=(const wchar_t *ptr) const
int32_t FXSYS_wtoi(const wchar_t *str)
bool IsArray(v8::Local< v8::Value > value)
constexpr uint32_t kNoView
constexpr uint32_t kHidden
constexpr uint32_t kPrint
constexpr uint32_t kInvisible
CFX_Color::Type color_type
CFX_Color & operator=(const CFX_Color &that)=default
constexpr CFX_Color(Type type=CFX_Color::Type::kTransparent, float color1=0.0f, float color2=0.0f, float color3=0.0f, float color4=0.0f)