Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjs_field.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fxjs/cjs_field.h"
8
9#include <algorithm>
10#include <memory>
11#include <utility>
12
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"
28#include "fxjs/fxv8.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"
35
36namespace {
37
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';
44
45bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) {
46 return pFormField->GetFieldType() == FormFieldType::kCheckBox ||
48}
49
50bool IsComboBoxOrListBox(const CPDF_FormField* pFormField) {
51 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
53}
54
55bool IsComboBoxOrTextField(const CPDF_FormField* pFormField) {
56 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
58}
59
60void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
61 CPDF_FormField* pFormField,
62 bool bResetAP) {
63 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
64 if (bResetAP) {
65 std::vector<ObservedPtr<CPDFSDK_Widget>> widgets;
66 pForm->GetWidgets(pFormField, &widgets);
67
68 if (IsComboBoxOrTextField(pFormField)) {
69 for (auto& pWidget : widgets) {
70 if (pWidget) {
71 absl::optional<WideString> sValue = pWidget->OnFormat();
72 if (pWidget) { // Not redundant, may be clobbered by OnFormat.
73 pWidget->ResetAppearance(sValue, CPDFSDK_Widget::kValueUnchanged);
74 }
75 }
76 }
77 } else {
78 for (auto& pWidget : widgets) {
79 if (pWidget) {
80 pWidget->ResetAppearance(absl::nullopt,
81 CPDFSDK_Widget::kValueUnchanged);
82 }
83 }
84 }
85 }
86
87 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
88 // to be removed from the list. We need to call |GetWidgets| again to be
89 // sure none of the widgets have been deleted.
90 std::vector<ObservedPtr<CPDFSDK_Widget>> widgets;
91 pForm->GetWidgets(pFormField, &widgets);
92 for (auto& pWidget : widgets) {
93 if (pWidget)
94 pFormFillEnv->UpdateAllViews(pWidget.Get());
95 }
96 pFormFillEnv->SetChangeMark();
97}
98
99void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
100 CPDF_FormControl* pFormControl,
101 bool bResetAP) {
102 DCHECK(pFormControl);
103 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
104 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
105 if (pWidget) {
106 ObservedPtr<CPDFSDK_Widget> observed_widget(pWidget);
107 if (bResetAP) {
108 FormFieldType fieldType = pWidget->GetFieldType();
109 if (fieldType == FormFieldType::kComboBox ||
110 fieldType == FormFieldType::kTextField) {
111 absl::optional<WideString> sValue = pWidget->OnFormat();
112 if (!observed_widget)
113 return;
114 pWidget->ResetAppearance(sValue, CPDFSDK_Widget::kValueUnchanged);
115 } else {
116 pWidget->ResetAppearance(absl::nullopt,
117 CPDFSDK_Widget::kValueUnchanged);
118 }
119 if (!observed_widget)
120 return;
121 }
122 pFormFillEnv->UpdateAllViews(pWidget);
123 }
124 pFormFillEnv->SetChangeMark();
125}
126
127struct FieldNameData {
128 FieldNameData(WideString field_name_in, int control_index_in)
129 : field_name(field_name_in), control_index(control_index_in) {}
130
131 WideString field_name;
132 int control_index;
133};
134
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'.')
139 break;
140 ++reverse_it;
141 }
142 if (reverse_it == field_name.rend()) {
143 return absl::nullopt;
144 }
145 WideString suffixal = field_name.Last(reverse_it - field_name.rbegin());
146 int control_index = FXSYS_wtoi(suffixal.c_str());
147 if (control_index == 0) {
148 suffixal.TrimRight(L' ');
149 if (suffixal != L"0") {
150 return absl::nullopt;
151 }
152 }
153 return FieldNameData(field_name.First(field_name.rend() - reverse_it - 1),
154 control_index);
155}
156
157std::vector<CPDF_FormField*> GetFormFieldsForName(
158 CPDFSDK_FormFillEnvironment* pFormFillEnv,
159 const WideString& csFieldName) {
160 std::vector<CPDF_FormField*> fields;
161 CPDFSDK_InteractiveForm* pReaderForm = pFormFillEnv->GetInteractiveForm();
163 const size_t sz = pForm->CountFields(csFieldName);
164 for (size_t i = 0; i < sz; ++i) {
165 CPDF_FormField* pFormField = pForm->GetField(i, csFieldName);
166 if (pFormField)
167 fields.push_back(pFormField);
168 }
169 return fields;
170}
171
172CFX_Color GetFormControlColor(CPDF_FormControl* pFormControl,
173 const ByteString& entry) {
174 switch (pFormControl->GetColorARGB(entry).color_type) {
179 pFormControl->GetOriginalColorComponent(0, entry));
182 pFormControl->GetOriginalColorComponent(0, entry),
183 pFormControl->GetOriginalColorComponent(1, entry),
184 pFormControl->GetOriginalColorComponent(2, entry));
187 pFormControl->GetOriginalColorComponent(0, entry),
188 pFormControl->GetOriginalColorComponent(1, entry),
189 pFormControl->GetOriginalColorComponent(2, entry),
190 pFormControl->GetOriginalColorComponent(3, entry));
191 }
192}
193
194bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
195 if (!pWidget)
196 return false;
197
198 uint32_t dwFlag = pWidget->GetFlags();
199 switch (value) {
200 case 0:
201 dwFlag &= ~pdfium::annotation_flags::kInvisible;
202 dwFlag &= ~pdfium::annotation_flags::kHidden;
203 dwFlag &= ~pdfium::annotation_flags::kNoView;
204 dwFlag |= pdfium::annotation_flags::kPrint;
205 break;
206 case 1:
207 dwFlag &= ~pdfium::annotation_flags::kInvisible;
208 dwFlag &= ~pdfium::annotation_flags::kNoView;
209 dwFlag |= (pdfium::annotation_flags::kHidden |
211 break;
212 case 2:
213 dwFlag &= ~pdfium::annotation_flags::kInvisible;
214 dwFlag &= ~pdfium::annotation_flags::kPrint;
215 dwFlag &= ~pdfium::annotation_flags::kHidden;
216 dwFlag &= ~pdfium::annotation_flags::kNoView;
217 break;
218 case 3:
219 dwFlag |= pdfium::annotation_flags::kNoView;
220 dwFlag |= pdfium::annotation_flags::kPrint;
221 dwFlag &= ~pdfium::annotation_flags::kHidden;
222 break;
223 }
224
225 if (dwFlag != pWidget->GetFlags()) {
226 pWidget->SetFlags(dwFlag);
227 return true;
228 }
229
230 return false;
231}
232
233void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
234 const WideString& swFieldName,
235 int nControlIndex,
236 const ByteString& bsString) {
237 DCHECK(pFormFillEnv);
238
239 BorderStyle nBorderStyle;
240 if (bsString == "solid")
241 nBorderStyle = BorderStyle::kSolid;
242 else if (bsString == "beveled")
243 nBorderStyle = BorderStyle::kBeveled;
244 else if (bsString == "dashed")
245 nBorderStyle = BorderStyle::kDash;
246 else if (bsString == "inset")
247 nBorderStyle = BorderStyle::kInset;
248 else if (bsString == "underline")
249 nBorderStyle = BorderStyle::kUnderline;
250 else
251 return;
252
253 std::vector<CPDF_FormField*> FieldArray =
254 GetFormFieldsForName(pFormFillEnv, swFieldName);
255 auto* pForm = pFormFillEnv->GetInteractiveForm();
256 for (CPDF_FormField* pFormField : FieldArray) {
257 if (nControlIndex < 0) {
258 bool bSet = false;
259 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
260 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormField->GetControl(i));
261 if (pWidget) {
262 if (pWidget->GetBorderStyle() != nBorderStyle) {
263 pWidget->SetBorderStyle(nBorderStyle);
264 bSet = true;
265 }
266 }
267 }
268 if (bSet)
269 UpdateFormField(pFormFillEnv, pFormField, true);
270 } else {
271 if (nControlIndex >= pFormField->CountControls())
272 return;
273 if (CPDF_FormControl* pFormControl =
274 pFormField->GetControl(nControlIndex)) {
275 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
276 if (pWidget) {
277 if (pWidget->GetBorderStyle() != nBorderStyle) {
278 pWidget->SetBorderStyle(nBorderStyle);
279 UpdateFormControl(pFormFillEnv, pFormControl, true);
280 }
281 }
282 }
283 }
284 }
285}
286
287void SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
288 const WideString& swFieldName,
289 int nControlIndex,
290 const std::vector<uint32_t>& array) {
291 DCHECK(pFormFillEnv);
292 std::vector<CPDF_FormField*> FieldArray =
293 GetFormFieldsForName(pFormFillEnv, swFieldName);
294
295 for (CPDF_FormField* pFormField : FieldArray) {
296 if (!IsComboBoxOrListBox(pFormField))
297 continue;
298
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))
303 break;
304 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
305 !pFormField->IsItemSelected(array[i])) {
306 pFormField->SetItemSelection(array[i],
307 NotificationOption::kDoNotNotify);
308 }
309 }
310 UpdateFormField(pFormFillEnv, pFormField, true);
311 }
312}
313
314void SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
315 const WideString& swFieldName,
316 int nControlIndex,
317 int number) {
318 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
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);
327
328 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
329 if (SetWidgetDisplayStatus(pWidget, number))
330 bAnySet = true;
331 }
332
333 if (bAnySet)
334 UpdateFormField(pFormFillEnv, pFormField, false);
335 } else {
336 if (nControlIndex >= pFormField->CountControls())
337 return;
338
339 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
340 if (!pFormControl)
341 return;
342
343 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
344 if (SetWidgetDisplayStatus(pWidget, number))
345 UpdateFormControl(pFormFillEnv, pFormControl, false);
346 }
347 }
348}
349
350void SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
351 const WideString& swFieldName,
352 int nControlIndex,
353 bool b) {
354 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
355 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
356}
357
358void SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
359 const WideString& swFieldName,
360 int nControlIndex,
361 int number) {
362 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
363 std::vector<CPDF_FormField*> FieldArray =
364 GetFormFieldsForName(pFormFillEnv, swFieldName);
365 for (CPDF_FormField* pFormField : FieldArray) {
366 if (nControlIndex < 0) {
367 bool bSet = false;
368 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
369 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
370 DCHECK(pFormControl);
371
372 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
373 if (number != pWidget->GetBorderWidth()) {
374 pWidget->SetBorderWidth(number);
375 bSet = true;
376 }
377 }
378 }
379 if (bSet)
380 UpdateFormField(pFormFillEnv, pFormField, true);
381 } else {
382 if (nControlIndex >= pFormField->CountControls())
383 return;
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);
390 }
391 }
392 }
393 }
394 }
395}
396
397void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
398 const WideString& swFieldName,
399 int nControlIndex,
400 const CFX_FloatRect& rect) {
401 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
402 std::vector<CPDF_FormField*> FieldArray =
403 GetFormFieldsForName(pFormFillEnv, swFieldName);
404 for (CPDF_FormField* pFormField : FieldArray) {
405 if (nControlIndex < 0) {
406 bool bSet = false;
407 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
408 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
409 DCHECK(pFormControl);
410
411 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
412 CFX_FloatRect crRect = rect;
413
414 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
415 crRect.Intersect(pPDFPage->GetBBox());
416
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);
422 bSet = true;
423 }
424 }
425 }
426 }
427
428 if (bSet)
429 UpdateFormField(pFormFillEnv, pFormField, true);
430
431 continue;
432 }
433
434 if (nControlIndex >= pFormField->CountControls())
435 return;
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);
448 }
449 }
450 }
451 }
452 }
453}
454
455void SetFieldValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
456 const WideString& swFieldName,
457 int nControlIndex,
458 const std::vector<WideString>& strArray) {
459 DCHECK(pFormFillEnv);
460 if (strArray.empty())
461 return;
462
463 std::vector<CPDF_FormField*> FieldArray =
464 GetFormFieldsForName(pFormFillEnv, swFieldName);
465
466 for (CPDF_FormField* pFormField : FieldArray) {
467 if (pFormField->GetFullName() != swFieldName)
468 continue;
469
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);
476 }
477 break;
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);
483 }
484 break;
485 case FormFieldType::kListBox: {
486 bool bModified = false;
487 for (const auto& str : strArray) {
488 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
489 bModified = true;
490 break;
491 }
492 }
493 if (bModified) {
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);
499 }
500 UpdateFormField(pFormFillEnv, pFormField, false);
501 }
502 break;
503 }
504 default:
505 break;
506 }
507 }
508}
509
510wchar_t GetSelectorFromCaptionForFieldType(const WideString& caption,
511 CPDF_FormField::Type type) {
512 if (!caption.IsEmpty())
513 return caption[0];
514
515 switch (type) {
517 return kCircleSelector;
518 default:
519 return kCheckSelector;
520 }
521}
522
523} // namespace
524
525const JSPropertySpec CJS_Field::PropertySpecs[] = {
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}};
587
588const JSMethodSpec CJS_Field::MethodSpecs[] = {
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}};
615
616uint32_t CJS_Field::ObjDefnID = 0;
617const char CJS_Field::kName[] = "Field";
618
619// static
620uint32_t CJS_Field::GetObjDefnID() {
621 return ObjDefnID;
622}
623
624// static
625void CJS_Field::DefineJSObjects(CFXJS_Engine* pEngine) {
626 ObjDefnID = pEngine->DefineObj(CJS_Field::kName, FXJSOBJTYPE_DYNAMIC,
627 JSConstructor<CJS_Field>, JSDestructor);
628 DefineProps(pEngine, ObjDefnID, PropertySpecs);
629 DefineMethods(pEngine, ObjDefnID, MethodSpecs);
630}
631
632CJS_Field::CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
633 : CJS_Object(pObject, pRuntime) {}
634
635CJS_Field::~CJS_Field() = default;
636
637bool CJS_Field::AttachField(CJS_Document* pDocument,
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);
645
646 CPDFSDK_InteractiveForm* pRDForm = m_pFormFillEnv->GetInteractiveForm();
648 WideString swFieldNameTemp = csFieldName;
649 swFieldNameTemp.Replace(L"..", L".");
650
651 if (pForm->CountFields(swFieldNameTemp) <= 0) {
652 absl::optional<FieldNameData> parsed_data = ParseFieldName(swFieldNameTemp);
653 if (!parsed_data.has_value())
654 return false;
655
656 m_FieldName = parsed_data.value().field_name;
657 m_nFormControlIndex = parsed_data.value().control_index;
658 return true;
659 }
660
661 m_FieldName = swFieldNameTemp;
662 m_nFormControlIndex = -1;
663
664 return true;
665}
666
667std::vector<CPDF_FormField*> CJS_Field::GetFormFields() const {
668 return GetFormFieldsForName(m_pFormFillEnv.Get(), m_FieldName);
669}
670
671CPDF_FormField* CJS_Field::GetFirstFormField() const {
672 std::vector<CPDF_FormField*> fields = GetFormFields();
673 return fields.empty() ? nullptr : fields[0];
674}
675
676CPDF_FormControl* CJS_Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
677 if (!pFormField->CountControls() ||
678 m_nFormControlIndex >= pFormField->CountControls())
679 return nullptr;
680 if (m_nFormControlIndex < 0)
681 return pFormField->GetControl(0);
682 return pFormField->GetControl(m_nFormControlIndex);
683}
684
685CJS_Result CJS_Field::get_alignment(CJS_Runtime* pRuntime) {
686 DCHECK(m_pFormFillEnv);
687
688 CPDF_FormField* pFormField = GetFirstFormField();
689 if (!pFormField)
691
694
695 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
696 if (!pFormControl)
698
699 switch (pFormControl->GetControlAlignment()) {
700 case 0:
701 return CJS_Result::Success(pRuntime->NewString("left"));
702 case 1:
703 return CJS_Result::Success(pRuntime->NewString("center"));
704 case 2:
705 return CJS_Result::Success(pRuntime->NewString("right"));
706 }
707 return CJS_Result::Success(pRuntime->NewString(""));
708}
709
710CJS_Result CJS_Field::set_alignment(CJS_Runtime* pRuntime,
711 v8::Local<v8::Value> vp) {
712 DCHECK(m_pFormFillEnv);
713 if (!m_bCanSet)
715
717}
718
719CJS_Result CJS_Field::get_border_style(CJS_Runtime* pRuntime) {
720 DCHECK(m_pFormFillEnv);
721
722 CPDF_FormField* pFormField = GetFirstFormField();
723 if (!pFormField)
725
726 CPDFSDK_Widget* pWidget = m_pFormFillEnv->GetInteractiveForm()->GetWidget(
727 GetSmartFieldControl(pFormField));
728 if (!pWidget)
730
731 switch (pWidget->GetBorderStyle()) {
733 return CJS_Result::Success(pRuntime->NewString("solid"));
735 return CJS_Result::Success(pRuntime->NewString("dashed"));
737 return CJS_Result::Success(pRuntime->NewString("beveled"));
739 return CJS_Result::Success(pRuntime->NewString("inset"));
741 return CJS_Result::Success(pRuntime->NewString("underline"));
742 }
743 return CJS_Result::Success(pRuntime->NewString(""));
744}
745
746CJS_Result CJS_Field::set_border_style(CJS_Runtime* pRuntime,
747 v8::Local<v8::Value> vp) {
748 DCHECK(m_pFormFillEnv);
749 if (!m_bCanSet)
751
752 ByteString byte_str = pRuntime->ToByteString(vp);
753 if (m_bDelay) {
754 AddDelay_String(FP_BORDERSTYLE, byte_str);
755 } else {
756 SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
757 byte_str);
758 }
760}
761
762CJS_Result CJS_Field::get_button_align_x(CJS_Runtime* pRuntime) {
763 DCHECK(m_pFormFillEnv);
764
765 CPDF_FormField* pFormField = GetFirstFormField();
766 if (!pFormField)
768
771
772 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
773 if (!pFormControl)
775
776 CPDF_IconFit IconFit = pFormControl->GetIconFit();
777 CFX_PointF pos = IconFit.GetIconBottomLeftPosition();
778 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>(pos.x)));
779}
780
781CJS_Result CJS_Field::set_button_align_x(CJS_Runtime* pRuntime,
782 v8::Local<v8::Value> vp) {
783 DCHECK(m_pFormFillEnv);
784 if (!m_bCanSet)
787}
788
789CJS_Result CJS_Field::get_button_align_y(CJS_Runtime* pRuntime) {
790 DCHECK(m_pFormFillEnv);
791
792 CPDF_FormField* pFormField = GetFirstFormField();
793 if (!pFormField)
795
798
799 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
800 if (!pFormControl)
802
803 CPDF_IconFit IconFit = pFormControl->GetIconFit();
804 CFX_PointF pos = IconFit.GetIconBottomLeftPosition();
805 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>(pos.y)));
806}
807
808CJS_Result CJS_Field::set_button_align_y(CJS_Runtime* pRuntime,
809 v8::Local<v8::Value> vp) {
810 DCHECK(m_pFormFillEnv);
811 if (!m_bCanSet)
814}
815
816CJS_Result CJS_Field::get_button_fit_bounds(CJS_Runtime* pRuntime) {
817 DCHECK(m_pFormFillEnv);
818
819 CPDF_FormField* pFormField = GetFirstFormField();
820 if (!pFormField)
822
825
826 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
827 if (!pFormControl)
829
831 pRuntime->NewBoolean(pFormControl->GetIconFit().GetFittingBounds()));
832}
833
834CJS_Result CJS_Field::set_button_fit_bounds(CJS_Runtime* pRuntime,
835 v8::Local<v8::Value> vp) {
836 DCHECK(m_pFormFillEnv);
837 if (!m_bCanSet)
840}
841
842CJS_Result CJS_Field::get_button_position(CJS_Runtime* pRuntime) {
843 DCHECK(m_pFormFillEnv);
844
845 CPDF_FormField* pFormField = GetFirstFormField();
846 if (!pFormField)
848
851
852 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
853 if (!pFormControl)
855
857 pRuntime->NewNumber(pFormControl->GetTextPosition()));
858}
859
860CJS_Result CJS_Field::set_button_position(CJS_Runtime* pRuntime,
861 v8::Local<v8::Value> vp) {
862 DCHECK(m_pFormFillEnv);
863 if (!m_bCanSet)
866}
867
868CJS_Result CJS_Field::get_button_scale_how(CJS_Runtime* pRuntime) {
869 DCHECK(m_pFormFillEnv);
870
871 CPDF_FormField* pFormField = GetFirstFormField();
872 if (!pFormField)
874
877
878 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
879 if (!pFormControl)
881
883 pRuntime->NewBoolean(!pFormControl->GetIconFit().IsProportionalScale()));
884}
885
886CJS_Result CJS_Field::set_button_scale_how(CJS_Runtime* pRuntime,
887 v8::Local<v8::Value> vp) {
888 DCHECK(m_pFormFillEnv);
889 if (!m_bCanSet)
892}
893
894CJS_Result CJS_Field::get_button_scale_when(CJS_Runtime* pRuntime) {
895 DCHECK(m_pFormFillEnv);
896
897 CPDF_FormField* pFormField = GetFirstFormField();
898 if (!pFormField)
900
903
904 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
905 if (!pFormControl)
907
908 CPDF_IconFit IconFit = pFormControl->GetIconFit();
909 CPDF_IconFit::ScaleMethod scale_method = IconFit.GetScaleMethod();
910 switch (scale_method) {
916 pRuntime->NewNumber(static_cast<int>(scale_method)));
917 }
918}
919
920CJS_Result CJS_Field::set_button_scale_when(CJS_Runtime* pRuntime,
921 v8::Local<v8::Value> vp) {
922 DCHECK(m_pFormFillEnv);
923 if (!m_bCanSet)
926}
927
928CJS_Result CJS_Field::get_calc_order_index(CJS_Runtime* pRuntime) {
929 DCHECK(m_pFormFillEnv);
930
931 CPDF_FormField* pFormField = GetFirstFormField();
932 if (!pFormField)
934
935 if (!IsComboBoxOrTextField(pFormField))
937
938 CPDFSDK_InteractiveForm* pRDForm = m_pFormFillEnv->GetInteractiveForm();
941 pRuntime->NewNumber(pForm->FindFieldInCalculationOrder(pFormField)));
942}
943
944CJS_Result CJS_Field::set_calc_order_index(CJS_Runtime* pRuntime,
945 v8::Local<v8::Value> vp) {
946 DCHECK(m_pFormFillEnv);
947 if (!m_bCanSet)
950}
951
952CJS_Result CJS_Field::get_char_limit(CJS_Runtime* pRuntime) {
953 DCHECK(m_pFormFillEnv);
954
955 CPDF_FormField* pFormField = GetFirstFormField();
956 if (!pFormField)
958
962 pRuntime->NewNumber(static_cast<int32_t>(pFormField->GetMaxLen())));
963}
964
965CJS_Result CJS_Field::set_char_limit(CJS_Runtime* pRuntime,
966 v8::Local<v8::Value> vp) {
967 DCHECK(m_pFormFillEnv);
968 if (!m_bCanSet)
971}
972
973CJS_Result CJS_Field::get_comb(CJS_Runtime* pRuntime) {
974 DCHECK(m_pFormFillEnv);
975
976 CPDF_FormField* pFormField = GetFirstFormField();
977 if (!pFormField)
979
982
983 return CJS_Result::Success(pRuntime->NewBoolean(
984 !!(pFormField->GetFieldFlags() & pdfium::form_flags::kTextComb)));
985}
986
987CJS_Result CJS_Field::set_comb(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
988 DCHECK(m_pFormFillEnv);
989 if (!m_bCanSet)
992}
993
994CJS_Result CJS_Field::get_commit_on_sel_change(CJS_Runtime* pRuntime) {
995 DCHECK(m_pFormFillEnv);
996
997 CPDF_FormField* pFormField = GetFirstFormField();
998 if (!pFormField)
1000
1001 if (!IsComboBoxOrListBox(pFormField))
1003
1004 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
1005 return CJS_Result::Success(pRuntime->NewBoolean(
1006 !!(dwFieldFlags & pdfium::form_flags::kChoiceCommitOnSelChange)));
1007}
1008
1009CJS_Result CJS_Field::set_commit_on_sel_change(CJS_Runtime* pRuntime,
1010 v8::Local<v8::Value> vp) {
1011 DCHECK(m_pFormFillEnv);
1012 if (!m_bCanSet)
1014 return CJS_Result::Success();
1015}
1016
1017CJS_Result CJS_Field::get_current_value_indices(CJS_Runtime* pRuntime) {
1018 CPDF_FormField* pFormField = GetFirstFormField();
1019 if (!pFormField)
1021
1022 if (!IsComboBoxOrListBox(pFormField))
1024
1025 int count = pFormField->CountSelectedItems();
1026 if (count <= 0)
1027 return CJS_Result::Success(pRuntime->NewNumber(-1));
1028 if (count == 1)
1030 pRuntime->NewNumber(pFormField->GetSelectedIndex(0)));
1031
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)));
1036 }
1037 if (SelArray.IsEmpty())
1038 return CJS_Result::Success(pRuntime->NewArray());
1039 return CJS_Result::Success(SelArray);
1040}
1041
1042CJS_Result CJS_Field::set_current_value_indices(CJS_Runtime* pRuntime,
1043 v8::Local<v8::Value> vp) {
1044 if (!m_bCanSet)
1046
1047 std::vector<uint32_t> array;
1048 if (vp->IsNumber()) {
1049 array.push_back(pRuntime->ToInt32(vp));
1050 } else if (fxv8::IsArray(vp)) {
1051 v8::Local<v8::Array> SelArray = pRuntime->ToArray(vp);
1052 for (size_t i = 0; i < pRuntime->GetArrayLength(SelArray); i++) {
1053 array.push_back(
1054 pRuntime->ToInt32(pRuntime->GetArrayElement(SelArray, i)));
1055 }
1056 }
1057
1058 if (m_bDelay) {
1059 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1060 } else {
1061 SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
1062 m_nFormControlIndex, array);
1063 }
1064 return CJS_Result::Success();
1065}
1066
1067CJS_Result CJS_Field::get_default_style(CJS_Runtime* pRuntime) {
1069}
1070
1071CJS_Result CJS_Field::set_default_style(CJS_Runtime* pRuntime,
1072 v8::Local<v8::Value> vp) {
1074}
1075
1076CJS_Result CJS_Field::get_default_value(CJS_Runtime* pRuntime) {
1077 DCHECK(m_pFormFillEnv);
1078
1079 CPDF_FormField* pFormField = GetFirstFormField();
1080 if (!pFormField)
1082
1086 }
1087
1089 pRuntime->NewString(pFormField->GetDefaultValue().AsStringView()));
1090}
1091
1092CJS_Result CJS_Field::set_default_value(CJS_Runtime* pRuntime,
1093 v8::Local<v8::Value> vp) {
1094 DCHECK(m_pFormFillEnv);
1095 if (!m_bCanSet)
1097 return CJS_Result::Success();
1098}
1099
1100CJS_Result CJS_Field::get_do_not_scroll(CJS_Runtime* pRuntime) {
1101 DCHECK(m_pFormFillEnv);
1102
1103 CPDF_FormField* pFormField = GetFirstFormField();
1104 if (!pFormField)
1106
1109
1110 return CJS_Result::Success(pRuntime->NewBoolean(
1112}
1113
1114CJS_Result CJS_Field::set_do_not_scroll(CJS_Runtime* pRuntime,
1115 v8::Local<v8::Value> vp) {
1116 DCHECK(m_pFormFillEnv);
1117 if (!m_bCanSet)
1119 return CJS_Result::Success();
1120}
1121
1122CJS_Result CJS_Field::get_do_not_spell_check(CJS_Runtime* pRuntime) {
1123 DCHECK(m_pFormFillEnv);
1124
1125 CPDF_FormField* pFormField = GetFirstFormField();
1126 if (!pFormField)
1128
1129 if (!IsComboBoxOrTextField(pFormField))
1131
1132 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
1133 return CJS_Result::Success(pRuntime->NewBoolean(
1134 !!(dwFieldFlags & pdfium::form_flags::kTextDoNotSpellCheck)));
1135}
1136
1137CJS_Result CJS_Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
1138 v8::Local<v8::Value> vp) {
1139 DCHECK(m_pFormFillEnv);
1140 if (!m_bCanSet)
1142 return CJS_Result::Success();
1143}
1144
1145CJS_Result CJS_Field::get_delay(CJS_Runtime* pRuntime) {
1146 return CJS_Result::Success(pRuntime->NewBoolean(m_bDelay));
1147}
1148
1149CJS_Result CJS_Field::set_delay(CJS_Runtime* pRuntime,
1150 v8::Local<v8::Value> vp) {
1151 if (!m_bCanSet)
1153
1154 SetDelay(pRuntime->ToBoolean(vp));
1155 return CJS_Result::Success();
1156}
1157
1158CJS_Result CJS_Field::get_display(CJS_Runtime* pRuntime) {
1159 CPDF_FormField* pFormField = GetFirstFormField();
1160 if (!pFormField)
1162
1163 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1164 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
1165 if (!pWidget)
1167
1168 uint32_t dwFlag = pWidget->GetFlags();
1169 if (pdfium::annotation_flags::kInvisible & dwFlag ||
1170 pdfium::annotation_flags::kHidden & dwFlag) {
1171 return CJS_Result::Success(pRuntime->NewNumber(1));
1172 }
1173
1174 if (pdfium::annotation_flags::kPrint & dwFlag) {
1175 if (pdfium::annotation_flags::kNoView & dwFlag)
1176 return CJS_Result::Success(pRuntime->NewNumber(3));
1177 return CJS_Result::Success(pRuntime->NewNumber(0));
1178 }
1179 return CJS_Result::Success(pRuntime->NewNumber(2));
1180}
1181
1182CJS_Result CJS_Field::set_display(CJS_Runtime* pRuntime,
1183 v8::Local<v8::Value> vp) {
1184 if (!m_bCanSet)
1186
1187 if (m_bDelay) {
1188 AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp));
1189 } else {
1190 SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1191 pRuntime->ToInt32(vp));
1192 }
1193 return CJS_Result::Success();
1194}
1195
1196CJS_Result CJS_Field::get_doc(CJS_Runtime* pRuntime) {
1197 return CJS_Result::Success(m_pJSDoc->ToV8Object());
1198}
1199
1200CJS_Result CJS_Field::set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1202}
1203
1204CJS_Result CJS_Field::get_editable(CJS_Runtime* pRuntime) {
1205 CPDF_FormField* pFormField = GetFirstFormField();
1206 if (!pFormField)
1208
1211
1212 return CJS_Result::Success(pRuntime->NewBoolean(
1213 !!(pFormField->GetFieldFlags() & pdfium::form_flags::kChoiceEdit)));
1214}
1215
1216CJS_Result CJS_Field::set_editable(CJS_Runtime* pRuntime,
1217 v8::Local<v8::Value> vp) {
1218 if (!m_bCanSet)
1220 return CJS_Result::Success();
1221}
1222
1223CJS_Result CJS_Field::get_export_values(CJS_Runtime* pRuntime) {
1224 CPDF_FormField* pFormField = GetFirstFormField();
1225 if (!pFormField)
1227
1228 if (!IsCheckBoxOrRadioButton(pFormField))
1230
1231 v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray();
1232 if (m_nFormControlIndex < 0) {
1233 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1234 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1235 pRuntime->PutArrayElement(
1236 ExportValuesArray, i,
1237 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
1238 }
1239 } else {
1240 if (m_nFormControlIndex >= pFormField->CountControls())
1242
1243 CPDF_FormControl* pFormControl =
1244 pFormField->GetControl(m_nFormControlIndex);
1245 if (!pFormControl)
1247
1248 pRuntime->PutArrayElement(
1249 ExportValuesArray, 0,
1250 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
1251 }
1252 return CJS_Result::Success(ExportValuesArray);
1253}
1254
1255CJS_Result CJS_Field::set_export_values(CJS_Runtime* pRuntime,
1256 v8::Local<v8::Value> vp) {
1257 CPDF_FormField* pFormField = GetFirstFormField();
1258 if (!pFormField)
1260
1261 if (!IsCheckBoxOrRadioButton(pFormField))
1263
1264 if (!m_bCanSet)
1266
1267 if (!fxv8::IsArray(vp))
1269
1270 return CJS_Result::Success();
1271}
1272
1273CJS_Result CJS_Field::get_file_select(CJS_Runtime* pRuntime) {
1274 CPDF_FormField* pFormField = GetFirstFormField();
1275 if (!pFormField)
1277
1280
1281 return CJS_Result::Success(pRuntime->NewBoolean(
1283}
1284
1285CJS_Result CJS_Field::set_file_select(CJS_Runtime* pRuntime,
1286 v8::Local<v8::Value> vp) {
1287 CPDF_FormField* pFormField = GetFirstFormField();
1288 if (!pFormField)
1290
1293
1294 if (!m_bCanSet)
1296
1297 return CJS_Result::Success();
1298}
1299
1300CJS_Result CJS_Field::get_fill_color(CJS_Runtime* pRuntime) {
1301 CPDF_FormField* pFormField = GetFirstFormField();
1302 if (!pFormField)
1304
1305 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1306 if (!pFormControl)
1308
1309 CFX_Color color = GetFormControlColor(pFormControl, pdfium::appearance::kBG);
1310 v8::Local<v8::Value> array =
1311 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
1312 if (array.IsEmpty())
1313 return CJS_Result::Success(pRuntime->NewArray());
1314 return CJS_Result::Success(array);
1315}
1316
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())
1322 if (!m_bCanSet)
1324 if (!fxv8::IsArray(vp))
1326 return CJS_Result::Success();
1327}
1328
1329CJS_Result CJS_Field::get_hidden(CJS_Runtime* pRuntime) {
1330 CPDF_FormField* pFormField = GetFirstFormField();
1331 if (!pFormField)
1333
1334 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1335 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
1336 if (!pWidget)
1338
1339 uint32_t dwFlags = pWidget->GetFlags();
1341 pRuntime->NewBoolean(pdfium::annotation_flags::kInvisible & dwFlags ||
1342 pdfium::annotation_flags::kHidden & dwFlags));
1343}
1344
1345CJS_Result CJS_Field::set_hidden(CJS_Runtime* pRuntime,
1346 v8::Local<v8::Value> vp) {
1347 if (!m_bCanSet)
1349
1350 if (m_bDelay) {
1351 AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp));
1352 } else {
1353 SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1354 pRuntime->ToBoolean(vp));
1355 }
1356 return CJS_Result::Success();
1357}
1358
1359CJS_Result CJS_Field::get_highlight(CJS_Runtime* pRuntime) {
1360 DCHECK(m_pFormFillEnv);
1361
1362 CPDF_FormField* pFormField = GetFirstFormField();
1363 if (!pFormField)
1365
1368
1369 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1370 if (!pFormControl)
1372
1373 int eHM = pFormControl->GetHighlightingMode();
1374 switch (eHM) {
1376 return CJS_Result::Success(pRuntime->NewString("none"));
1378 return CJS_Result::Success(pRuntime->NewString("push"));
1380 return CJS_Result::Success(pRuntime->NewString("invert"));
1382 return CJS_Result::Success(pRuntime->NewString("outline"));
1384 return CJS_Result::Success(pRuntime->NewString("toggle"));
1385 }
1386 return CJS_Result::Success();
1387}
1388
1389CJS_Result CJS_Field::set_highlight(CJS_Runtime* pRuntime,
1390 v8::Local<v8::Value> vp) {
1391 DCHECK(m_pFormFillEnv);
1392 if (!m_bCanSet)
1394 return CJS_Result::Success();
1395}
1396
1397CJS_Result CJS_Field::get_line_width(CJS_Runtime* pRuntime) {
1398 CPDF_FormField* pFormField = GetFirstFormField();
1399 if (!pFormField)
1401
1402 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1403 if (!pFormControl)
1405
1406 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1407 if (!pFormField->CountControls())
1409
1410 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormField->GetControl(0));
1411 if (!pWidget)
1413
1414 return CJS_Result::Success(pRuntime->NewNumber(pWidget->GetBorderWidth()));
1415}
1416
1417CJS_Result CJS_Field::set_line_width(CJS_Runtime* pRuntime,
1418 v8::Local<v8::Value> vp) {
1419 if (!m_bCanSet)
1421
1422 if (m_bDelay) {
1423 AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp));
1424 } else {
1425 SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1426 pRuntime->ToInt32(vp));
1427 }
1428 return CJS_Result::Success();
1429}
1430
1431CJS_Result CJS_Field::get_multiline(CJS_Runtime* pRuntime) {
1432 DCHECK(m_pFormFillEnv);
1433
1434 CPDF_FormField* pFormField = GetFirstFormField();
1435 if (!pFormField)
1437
1440
1441 return CJS_Result::Success(pRuntime->NewBoolean(
1442 !!(pFormField->GetFieldFlags() & pdfium::form_flags::kTextMultiline)));
1443}
1444
1445CJS_Result CJS_Field::set_multiline(CJS_Runtime* pRuntime,
1446 v8::Local<v8::Value> vp) {
1447 DCHECK(m_pFormFillEnv);
1448 if (!m_bCanSet)
1450 return CJS_Result::Success();
1451}
1452
1453CJS_Result CJS_Field::get_multiple_selection(CJS_Runtime* pRuntime) {
1454 DCHECK(m_pFormFillEnv);
1455 CPDF_FormField* pFormField = GetFirstFormField();
1456 if (!pFormField)
1458
1461
1462 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
1463 return CJS_Result::Success(pRuntime->NewBoolean(
1464 !!(dwFieldFlags & pdfium::form_flags::kChoiceMultiSelect)));
1465}
1466
1467CJS_Result CJS_Field::set_multiple_selection(CJS_Runtime* pRuntime,
1468 v8::Local<v8::Value> vp) {
1469 DCHECK(m_pFormFillEnv);
1470 if (!m_bCanSet)
1472 return CJS_Result::Success();
1473}
1474
1475CJS_Result CJS_Field::get_name(CJS_Runtime* pRuntime) {
1476 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
1477 if (FieldArray.empty())
1479
1480 return CJS_Result::Success(pRuntime->NewString(m_FieldName.AsStringView()));
1481}
1482
1483CJS_Result CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1485}
1486
1487CJS_Result CJS_Field::get_num_items(CJS_Runtime* pRuntime) {
1488 CPDF_FormField* pFormField = GetFirstFormField();
1489 if (!pFormField)
1491
1492 if (!IsComboBoxOrListBox(pFormField))
1494
1495 return CJS_Result::Success(pRuntime->NewNumber(pFormField->CountOptions()));
1496}
1497
1498CJS_Result CJS_Field::set_num_items(CJS_Runtime* pRuntime,
1499 v8::Local<v8::Value> vp) {
1501}
1502
1503CJS_Result CJS_Field::get_page(CJS_Runtime* pRuntime) {
1504 CPDF_FormField* pFormField = GetFirstFormField();
1505 if (!pFormField)
1507
1508 std::vector<ObservedPtr<CPDFSDK_Widget>> widgets;
1509 m_pFormFillEnv->GetInteractiveForm()->GetWidgets(pFormField, &widgets);
1510 if (widgets.empty())
1511 return CJS_Result::Success(pRuntime->NewNumber(-1));
1512
1513 v8::Local<v8::Array> PageArray = pRuntime->NewArray();
1514 int i = 0;
1515 for (const auto& pWidget : widgets) {
1516 if (!pWidget)
1517 return CJS_Result::Failure(JSMessage::kBadObjectError);
1518
1519 pRuntime->PutArrayElement(
1520 PageArray, i,
1521 pRuntime->NewNumber(pWidget->GetPageView()->GetPageIndex()));
1522 ++i;
1523 }
1524 return CJS_Result::Success(PageArray);
1525}
1526
1527CJS_Result CJS_Field::set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1529}
1530
1531CJS_Result CJS_Field::get_password(CJS_Runtime* pRuntime) {
1532 DCHECK(m_pFormFillEnv);
1533
1534 CPDF_FormField* pFormField = GetFirstFormField();
1535 if (!pFormField)
1537
1540
1541 return CJS_Result::Success(pRuntime->NewBoolean(
1542 !!(pFormField->GetFieldFlags() & pdfium::form_flags::kTextPassword)));
1543}
1544
1545CJS_Result CJS_Field::set_password(CJS_Runtime* pRuntime,
1546 v8::Local<v8::Value> vp) {
1547 DCHECK(m_pFormFillEnv);
1548 if (!m_bCanSet)
1550 return CJS_Result::Success();
1551}
1552
1553CJS_Result CJS_Field::get_print(CJS_Runtime* pRuntime) {
1554 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1555 CPDF_FormField* pFormField = GetFirstFormField();
1556 if (!pFormField)
1558
1559 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
1560 if (!pWidget)
1562
1563 return CJS_Result::Success(pRuntime->NewBoolean(
1564 !!(pWidget->GetFlags() & pdfium::annotation_flags::kPrint)));
1565}
1566
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())
1573
1574 if (!m_bCanSet)
1576
1577 for (CPDF_FormField* pFormField : FieldArray) {
1578 if (m_nFormControlIndex < 0) {
1579 bool bSet = false;
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;
1586 else
1587 dwFlags &= ~pdfium::annotation_flags::kPrint;
1588
1589 if (dwFlags != pWidget->GetFlags()) {
1590 pWidget->SetFlags(dwFlags);
1591 bSet = true;
1592 }
1593 }
1594 }
1595
1596 if (bSet)
1597 UpdateFormField(m_pFormFillEnv.Get(), pFormField, false);
1598
1599 continue;
1600 }
1601
1602 if (m_nFormControlIndex >= pFormField->CountControls())
1603 return CJS_Result::Failure(JSMessage::kValueError);
1604
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;
1611 else
1612 dwFlags &= ~pdfium::annotation_flags::kPrint;
1613
1614 if (dwFlags != pWidget->GetFlags()) {
1615 pWidget->SetFlags(dwFlags);
1616 UpdateFormControl(m_pFormFillEnv.Get(),
1617 pFormField->GetControl(m_nFormControlIndex), false);
1618 }
1619 }
1620 }
1621 }
1622 return CJS_Result::Success();
1623}
1624
1625CJS_Result CJS_Field::get_radios_in_unison(CJS_Runtime* pRuntime) {
1626 CPDF_FormField* pFormField = GetFirstFormField();
1627 if (!pFormField)
1629
1632
1633 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
1634 return CJS_Result::Success(pRuntime->NewBoolean(
1635 !!(dwFieldFlags & pdfium::form_flags::kButtonRadiosInUnison)));
1636}
1637
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())
1643 if (!m_bCanSet)
1645 return CJS_Result::Success();
1646}
1647
1648CJS_Result CJS_Field::get_readonly(CJS_Runtime* pRuntime) {
1649 CPDF_FormField* pFormField = GetFirstFormField();
1650 if (!pFormField)
1652
1653 return CJS_Result::Success(pRuntime->NewBoolean(
1654 !!(pFormField->GetFieldFlags() & pdfium::form_flags::kReadOnly)));
1655}
1656
1657CJS_Result CJS_Field::set_readonly(CJS_Runtime* pRuntime,
1658 v8::Local<v8::Value> vp) {
1659 CPDF_FormField* pFormField = GetFirstFormField();
1660 if (!pFormField)
1662
1663 if (!m_bCanSet)
1665
1666 const bool bReadOnly = pRuntime->ToBoolean(vp);
1667 const uint32_t dwFlags = pFormField->GetFieldFlags();
1668 const uint32_t dwNewFlags = bReadOnly
1669 ? (dwFlags | pdfium::form_flags::kReadOnly)
1670 : (dwFlags & ~pdfium::form_flags::kReadOnly);
1671 if (dwNewFlags != dwFlags)
1672 pFormField->SetFieldFlags(dwNewFlags);
1673
1674 return CJS_Result::Success();
1675}
1676
1677CJS_Result CJS_Field::get_rect(CJS_Runtime* pRuntime) {
1678 CPDF_FormField* pFormField = GetFirstFormField();
1679 if (!pFormField)
1681
1682 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1683 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
1684 if (!pWidget)
1686
1687 CFX_FloatRect crRect = pWidget->GetRect();
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)));
1697
1698 return CJS_Result::Success(rcArray);
1699}
1700
1701CJS_Result CJS_Field::set_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1702 if (!m_bCanSet)
1704 if (!fxv8::IsArray(vp))
1706
1707 v8::Local<v8::Array> rcArray = pRuntime->ToArray(vp);
1708 if (pRuntime->GetArrayLength(rcArray) < 4)
1710
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)));
1719
1720 CFX_FloatRect crRect(f0, f1, f2, f3);
1721 if (m_bDelay) {
1722 AddDelay_Rect(FP_RECT, crRect);
1723 } else {
1724 SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, crRect);
1725 }
1726 return CJS_Result::Success();
1727}
1728
1729CJS_Result CJS_Field::get_required(CJS_Runtime* pRuntime) {
1730 CPDF_FormField* pFormField = GetFirstFormField();
1731 if (!pFormField)
1733
1736
1737 return CJS_Result::Success(pRuntime->NewBoolean(
1738 !!(pFormField->GetFieldFlags() & pdfium::form_flags::kRequired)));
1739}
1740
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())
1746 if (!m_bCanSet)
1748 return CJS_Result::Success();
1749}
1750
1751CJS_Result CJS_Field::get_rich_text(CJS_Runtime* pRuntime) {
1752 DCHECK(m_pFormFillEnv);
1753
1754 CPDF_FormField* pFormField = GetFirstFormField();
1755 if (!pFormField)
1757
1760
1761 return CJS_Result::Success(pRuntime->NewBoolean(
1762 !!(pFormField->GetFieldFlags() & pdfium::form_flags::kTextRichText)));
1763}
1764
1765CJS_Result CJS_Field::set_rich_text(CJS_Runtime* pRuntime,
1766 v8::Local<v8::Value> vp) {
1767 DCHECK(m_pFormFillEnv);
1768 if (!m_bCanSet)
1770 return CJS_Result::Success();
1771}
1772
1773CJS_Result CJS_Field::get_rich_value(CJS_Runtime* pRuntime) {
1774 return CJS_Result::Success();
1775}
1776
1777CJS_Result CJS_Field::set_rich_value(CJS_Runtime* pRuntime,
1778 v8::Local<v8::Value> vp) {
1779 return CJS_Result::Success();
1780}
1781
1782CJS_Result CJS_Field::get_rotation(CJS_Runtime* pRuntime) {
1783 DCHECK(m_pFormFillEnv);
1784
1785 CPDF_FormField* pFormField = GetFirstFormField();
1786 if (!pFormField)
1788
1789 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1790 if (!pFormControl)
1792
1793 return CJS_Result::Success(pRuntime->NewNumber(pFormControl->GetRotation()));
1794}
1795
1796CJS_Result CJS_Field::set_rotation(CJS_Runtime* pRuntime,
1797 v8::Local<v8::Value> vp) {
1798 DCHECK(m_pFormFillEnv);
1799 if (!m_bCanSet)
1801 return CJS_Result::Success();
1802}
1803
1804CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) {
1805 return CJS_Result::Success();
1806}
1807
1808CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime,
1809 v8::Local<v8::Value> vp) {
1810 return CJS_Result::Success();
1811}
1812
1813CJS_Result CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) {
1814 CPDF_FormField* pFormField = GetFirstFormField();
1815 if (!pFormField)
1817
1818 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1819 if (!pFormControl)
1821
1822 CFX_Color color = GetFormControlColor(pFormControl, pdfium::appearance::kBC);
1823 v8::Local<v8::Value> array =
1824 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
1825 if (array.IsEmpty())
1826 return CJS_Result::Success(pRuntime->NewArray());
1827 return CJS_Result::Success(array);
1828}
1829
1830CJS_Result CJS_Field::set_stroke_color(CJS_Runtime* pRuntime,
1831 v8::Local<v8::Value> vp) {
1832 if (!m_bCanSet)
1834 if (!fxv8::IsArray(vp))
1836 return CJS_Result::Success();
1837}
1838
1839CJS_Result CJS_Field::get_style(CJS_Runtime* pRuntime) {
1840 DCHECK(m_pFormFillEnv);
1841
1842 CPDF_FormField* pFormField = GetFirstFormField();
1843 if (!pFormField)
1845
1846 if (!IsCheckBoxOrRadioButton(pFormField))
1848
1849 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1850 if (!pFormControl)
1852
1853 wchar_t selector = GetSelectorFromCaptionForFieldType(
1854 pFormControl->GetNormalCaption(), pFormControl->GetType());
1855
1856 ByteString csBCaption;
1857 switch (selector) {
1858 case kCircleSelector:
1859 csBCaption = "circle";
1860 break;
1861 case kCrossSelector:
1862 csBCaption = "cross";
1863 break;
1864 case kDiamondSelector:
1865 csBCaption = "diamond";
1866 break;
1867 case kSquareSelector:
1868 csBCaption = "square";
1869 break;
1870 case kStarSelector:
1871 csBCaption = "star";
1872 break;
1873 case kCheckSelector:
1874 default:
1875 csBCaption = "check";
1876 break;
1877 }
1878 return CJS_Result::Success(pRuntime->NewString(csBCaption.AsStringView()));
1879}
1880
1881CJS_Result CJS_Field::set_style(CJS_Runtime* pRuntime,
1882 v8::Local<v8::Value> vp) {
1883 DCHECK(m_pFormFillEnv);
1884 if (!m_bCanSet)
1886 return CJS_Result::Success();
1887}
1888
1889CJS_Result CJS_Field::get_submit_name(CJS_Runtime* pRuntime) {
1890 return CJS_Result::Success();
1891}
1892
1893CJS_Result CJS_Field::set_submit_name(CJS_Runtime* pRuntime,
1894 v8::Local<v8::Value> vp) {
1895 return CJS_Result::Success();
1896}
1897
1898CJS_Result CJS_Field::get_text_color(CJS_Runtime* pRuntime) {
1899 CPDF_FormField* pFormField = GetFirstFormField();
1900 if (!pFormField)
1902
1903 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1904 if (!pFormControl)
1906
1907 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
1908 absl::optional<CFX_Color::TypeAndARGB> maybe_type_argb_pair =
1909 FieldAppearance.GetColorARGB();
1910
1911 CFX_Color crRet;
1912 if (maybe_type_argb_pair.has_value() &&
1913 maybe_type_argb_pair.value().color_type !=
1914 CFX_Color::Type::kTransparent) {
1915 int32_t a;
1916 int32_t r;
1917 int32_t g;
1918 int32_t b;
1919 std::tie(a, r, g, b) = ArgbDecode(maybe_type_argb_pair.value().argb);
1920 crRet =
1921 CFX_Color(CFX_Color::Type::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
1922 }
1923
1924 v8::Local<v8::Value> array =
1925 CJS_Color::ConvertPWLColorToArray(pRuntime, crRet);
1926 if (array.IsEmpty())
1927 return CJS_Result::Success(pRuntime->NewArray());
1928 return CJS_Result::Success(array);
1929}
1930
1931CJS_Result CJS_Field::set_text_color(CJS_Runtime* pRuntime,
1932 v8::Local<v8::Value> vp) {
1933 if (!m_bCanSet)
1935 if (!fxv8::IsArray(vp))
1937 return CJS_Result::Success();
1938}
1939
1940CJS_Result CJS_Field::get_text_font(CJS_Runtime* pRuntime) {
1941 DCHECK(m_pFormFillEnv);
1942
1943 CPDF_FormField* pFormField = GetFirstFormField();
1944 if (!pFormField)
1946
1947 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1948 if (!pFormControl)
1950
1951 FormFieldType fieldType = pFormField->GetFieldType();
1952 if (fieldType != FormFieldType::kPushButton &&
1953 fieldType != FormFieldType::kComboBox &&
1954 fieldType != FormFieldType::kListBox &&
1955 fieldType != FormFieldType::kTextField) {
1957 }
1958
1959 absl::optional<WideString> wsFontName =
1960 pFormControl->GetDefaultControlFontName();
1961 if (!wsFontName.has_value())
1963
1964 return CJS_Result::Success(
1965 pRuntime->NewString(wsFontName.value().AsStringView()));
1966}
1967
1968CJS_Result CJS_Field::set_text_font(CJS_Runtime* pRuntime,
1969 v8::Local<v8::Value> vp) {
1970 DCHECK(m_pFormFillEnv);
1971
1972 if (!m_bCanSet)
1974 if (pRuntime->ToByteString(vp).IsEmpty())
1976 return CJS_Result::Success();
1977}
1978
1979CJS_Result CJS_Field::get_text_size(CJS_Runtime* pRuntime) {
1980 DCHECK(m_pFormFillEnv);
1981
1982 CPDF_FormField* pFormField = GetFirstFormField();
1983 if (!pFormField)
1985
1986 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1987 if (!pFormControl)
1989
1990 float fFontSize;
1991 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
1992 FieldAppearance.GetFont(&fFontSize);
1993 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int>(fFontSize)));
1994}
1995
1996CJS_Result CJS_Field::set_text_size(CJS_Runtime* pRuntime,
1997 v8::Local<v8::Value> vp) {
1998 DCHECK(m_pFormFillEnv);
1999 if (!m_bCanSet)
2001 return CJS_Result::Success();
2002}
2003
2004CJS_Result CJS_Field::get_type(CJS_Runtime* pRuntime) {
2005 CPDF_FormField* pFormField = GetFirstFormField();
2006 if (!pFormField)
2008
2009 switch (pFormField->GetFieldType()) {
2011 return CJS_Result::Success(pRuntime->NewString("unknown"));
2013 return CJS_Result::Success(pRuntime->NewString("button"));
2015 return CJS_Result::Success(pRuntime->NewString("checkbox"));
2017 return CJS_Result::Success(pRuntime->NewString("radiobutton"));
2019 return CJS_Result::Success(pRuntime->NewString("combobox"));
2021 return CJS_Result::Success(pRuntime->NewString("listbox"));
2023 return CJS_Result::Success(pRuntime->NewString("text"));
2025 return CJS_Result::Success(pRuntime->NewString("signature"));
2026#ifdef PDF_ENABLE_XFA
2027 default:
2028 return CJS_Result::Success(pRuntime->NewString("unknown"));
2029#endif
2030 }
2031}
2032
2033CJS_Result CJS_Field::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
2035}
2036
2037CJS_Result CJS_Field::get_user_name(CJS_Runtime* pRuntime) {
2038 DCHECK(m_pFormFillEnv);
2039
2040 CPDF_FormField* pFormField = GetFirstFormField();
2041 if (!pFormField)
2043
2045 pRuntime->NewString(pFormField->GetAlternateName().AsStringView()));
2046}
2047
2048CJS_Result CJS_Field::set_user_name(CJS_Runtime* pRuntime,
2049 v8::Local<v8::Value> vp) {
2050 DCHECK(m_pFormFillEnv);
2051 if (!m_bCanSet)
2053 return CJS_Result::Success();
2054}
2055
2056CJS_Result CJS_Field::get_value(CJS_Runtime* pRuntime) {
2057 CPDF_FormField* pFormField = GetFirstFormField();
2058 if (!pFormField)
2060
2061 v8::Local<v8::Value> ret;
2062 switch (pFormField->GetFieldType()) {
2065 case FormFieldType::kComboBox:
2066 case FormFieldType::kTextField:
2067 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
2068 break;
2070 if (pFormField->CountSelectedItems() > 1) {
2071 v8::Local<v8::Array> ValueArray = pRuntime->NewArray();
2072 v8::Local<v8::Value> ElementValue;
2073 int iIndex;
2074 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2075 iIndex = pFormField->GetSelectedIndex(i);
2076 ElementValue = pRuntime->NewString(
2077 pFormField->GetOptionValue(iIndex).AsStringView());
2078 if (pRuntime->ToWideString(ElementValue).IsEmpty()) {
2079 ElementValue = pRuntime->NewString(
2080 pFormField->GetOptionLabel(iIndex).AsStringView());
2081 }
2082 pRuntime->PutArrayElement(ValueArray, i, ElementValue);
2083 }
2084 ret = ValueArray;
2085 } else {
2086 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
2087 }
2088 break;
2089 }
2092 bool bFind = false;
2093 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2094 if (pFormField->GetControl(i)->IsChecked()) {
2095 ret = pRuntime->NewString(
2096 pFormField->GetControl(i)->GetExportValue().AsStringView());
2097 bFind = true;
2098 break;
2099 }
2100 }
2101 if (!bFind)
2102 ret = pRuntime->NewString("Off");
2103
2104 break;
2105 }
2106 default:
2107 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
2108 break;
2109 }
2110 return CJS_Result::Success(pRuntime->MaybeCoerceToNumber(ret));
2111}
2112
2113CJS_Result CJS_Field::set_value(CJS_Runtime* pRuntime,
2114 v8::Local<v8::Value> vp) {
2115 if (!m_bCanSet)
2117
2118 std::vector<WideString> strArray;
2119 if (fxv8::IsArray(vp)) {
2120 v8::Local<v8::Array> ValueArray = pRuntime->ToArray(vp);
2121 for (size_t i = 0; i < pRuntime->GetArrayLength(ValueArray); i++) {
2122 strArray.push_back(
2123 pRuntime->ToWideString(pRuntime->GetArrayElement(ValueArray, i)));
2124 }
2125 } else {
2126 strArray.push_back(pRuntime->ToWideString(vp));
2127 }
2128
2129 if (m_bDelay) {
2130 AddDelay_WideStringArray(FP_VALUE, strArray);
2131 } else {
2132 SetFieldValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
2133 strArray);
2134 }
2135 return CJS_Result::Success();
2136}
2137
2138CJS_Result CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) {
2139 CPDF_FormField* pFormField = GetFirstFormField();
2140 if (!pFormField)
2142
2145
2146 if (pFormField->GetFieldType() == FormFieldType::kCheckBox) {
2147 if (!pFormField->CountControls())
2149 return CJS_Result::Success(pRuntime->NewString(
2150 pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off"));
2151 }
2152
2154 !(pFormField->GetFieldFlags() &
2156 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2157 if (pFormField->GetControl(i)->IsChecked()) {
2158 return CJS_Result::Success(pRuntime->NewString(
2159 pFormField->GetControl(i)->GetExportValue().AsStringView()));
2160 }
2161 }
2162 return CJS_Result::Success(pRuntime->NewString("Off"));
2163 }
2164
2165 if (pFormField->GetFieldType() == FormFieldType::kListBox &&
2166 (pFormField->CountSelectedItems() > 1)) {
2167 return CJS_Result::Success(pRuntime->NewString(""));
2168 }
2170 pRuntime->NewString(pFormField->GetValue().AsStringView()));
2171}
2172
2173CJS_Result CJS_Field::set_value_as_string(CJS_Runtime* pRuntime,
2174 v8::Local<v8::Value> vp) {
2176}
2177
2178CJS_Result CJS_Field::browseForFileToSubmit(
2179 CJS_Runtime* pRuntime,
2180 pdfium::span<v8::Local<v8::Value>> params) {
2181 CPDF_FormField* pFormField = GetFirstFormField();
2182 if (!pFormField)
2184
2185 if ((pFormField->GetFieldFlags() & pdfium::form_flags::kTextFileSelect) &&
2187 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
2188 if (!wsFileName.IsEmpty()) {
2190 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true);
2191 }
2192 return CJS_Result::Success();
2193 }
2195}
2196
2197CJS_Result CJS_Field::buttonGetCaption(
2198 CJS_Runtime* pRuntime,
2199 pdfium::span<v8::Local<v8::Value>> params) {
2200 int nface = 0;
2201 if (params.size() >= 1)
2202 nface = pRuntime->ToInt32(params[0]);
2203
2204 CPDF_FormField* pFormField = GetFirstFormField();
2205 if (!pFormField)
2207
2210
2211 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2212 if (!pFormControl)
2214
2215 if (nface == 0) {
2217 pRuntime->NewString(pFormControl->GetNormalCaption().AsStringView()));
2218 }
2219 if (nface == 1) {
2221 pRuntime->NewString(pFormControl->GetDownCaption().AsStringView()));
2222 }
2223 if (nface == 2) {
2225 pRuntime->NewString(pFormControl->GetRolloverCaption().AsStringView()));
2226 }
2228}
2229
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)
2236 }
2237
2238 CPDF_FormField* pFormField = GetFirstFormField();
2239 if (!pFormField)
2241
2244
2245 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2246 if (!pFormControl)
2248
2249 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2250 CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
2251 if (pObj.IsEmpty())
2253
2254 auto* pJS_Icon = static_cast<CJS_Icon*>(
2255 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
2256 return pJS_Icon ? CJS_Result::Success(pJS_Icon->ToV8Object())
2258}
2259
2260CJS_Result CJS_Field::buttonImportIcon(
2261 CJS_Runtime* pRuntime,
2262 pdfium::span<v8::Local<v8::Value>> params) {
2263 return CJS_Result::Success();
2264}
2265
2266CJS_Result CJS_Field::buttonSetCaption(
2267 CJS_Runtime* pRuntime,
2268 pdfium::span<v8::Local<v8::Value>> params) {
2270}
2271
2272CJS_Result CJS_Field::buttonSetIcon(CJS_Runtime* pRuntime,
2273 pdfium::span<v8::Local<v8::Value>> params) {
2275}
2276
2277CJS_Result CJS_Field::checkThisBox(CJS_Runtime* pRuntime,
2278 pdfium::span<v8::Local<v8::Value>> params) {
2279 const size_t nSize = params.size();
2280 if (nSize == 0)
2282
2283 if (!m_bCanSet)
2285
2286 int nWidget = pRuntime->ToInt32(params[0]);
2287 bool bCheckit = true;
2288 if (nSize >= 2)
2289 bCheckit = pRuntime->ToBoolean(params[1]);
2290
2291 CPDF_FormField* pFormField = GetFirstFormField();
2292 if (!pFormField)
2294
2295 if (!IsCheckBoxOrRadioButton(pFormField))
2297
2298 if (nWidget < 0 || nWidget >= pFormField->CountControls())
2300
2301 // TODO(weili): Check whether anything special needed for radio button.
2302 // (When pFormField->GetFieldType() == FormFieldType::kRadioButton.)
2303 pFormField->CheckControl(nWidget, bCheckit, NotificationOption::kNotify);
2304 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true);
2305 return CJS_Result::Success();
2306}
2307
2308CJS_Result CJS_Field::clearItems(CJS_Runtime* pRuntime,
2309 pdfium::span<v8::Local<v8::Value>> params) {
2310 return CJS_Result::Success();
2311}
2312
2313CJS_Result CJS_Field::defaultIsChecked(
2314 CJS_Runtime* pRuntime,
2315 pdfium::span<v8::Local<v8::Value>> params) {
2316 if (!m_bCanSet)
2318
2319 if (params.empty())
2321
2322 CPDF_FormField* pFormField = GetFirstFormField();
2323 if (!pFormField)
2325
2326 int nWidget = pRuntime->ToInt32(params[0]);
2327 if (nWidget < 0 || nWidget >= pFormField->CountControls())
2329
2331 pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField)));
2332}
2333
2334CJS_Result CJS_Field::deleteItemAt(CJS_Runtime* pRuntime,
2335 pdfium::span<v8::Local<v8::Value>> params) {
2336 return CJS_Result::Success();
2337}
2338
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())
2344
2345 std::vector<std::unique_ptr<WideString>> swSort;
2346 for (CPDF_FormField* pFormField : FieldArray) {
2347 swSort.push_back(std::make_unique<WideString>(pFormField->GetFullName()));
2348 }
2349
2350 std::sort(swSort.begin(), swSort.end(),
2351 [](const std::unique_ptr<WideString>& p1,
2352 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
2353
2354 v8::Local<v8::Array> FormFieldArray = pRuntime->NewArray();
2355 int j = 0;
2356 for (const auto& pStr : swSort) {
2357 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2358 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
2359 if (pObj.IsEmpty())
2360 return CJS_Result::Failure(JSMessage::kBadObjectError);
2361
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++,
2366 pJSField
2367 ? v8::Local<v8::Value>(pJSField->ToV8Object())
2368 : v8::Local<v8::Value>());
2369 }
2370 return CJS_Result::Success(FormFieldArray);
2371}
2372
2373CJS_Result CJS_Field::getItemAt(CJS_Runtime* pRuntime,
2374 pdfium::span<v8::Local<v8::Value>> params) {
2375 const size_t nSize = params.size();
2376 int nIdx = -1;
2377 if (nSize >= 1)
2378 nIdx = pRuntime->ToInt32(params[0]);
2379
2380 bool bExport = true;
2381 if (nSize >= 2)
2382 bExport = pRuntime->ToBoolean(params[1]);
2383
2384 CPDF_FormField* pFormField = GetFirstFormField();
2385 if (!pFormField)
2387
2388 if (!IsComboBoxOrListBox(pFormField))
2390
2391 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2392 nIdx = pFormField->CountOptions() - 1;
2393 if (!bExport) {
2395 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
2396 }
2397
2398 WideString strval = pFormField->GetOptionValue(nIdx);
2399 if (strval.IsEmpty()) {
2401 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
2402 }
2403 return CJS_Result::Success(pRuntime->NewString(strval.AsStringView()));
2404}
2405
2406CJS_Result CJS_Field::getLock(CJS_Runtime* pRuntime,
2407 pdfium::span<v8::Local<v8::Value>> params) {
2409}
2410
2411CJS_Result CJS_Field::insertItemAt(CJS_Runtime* pRuntime,
2412 pdfium::span<v8::Local<v8::Value>> params) {
2413 return CJS_Result::Success();
2414}
2415
2416CJS_Result CJS_Field::isBoxChecked(CJS_Runtime* pRuntime,
2417 pdfium::span<v8::Local<v8::Value>> params) {
2418 int nIndex = -1;
2419 if (params.size() >= 1)
2420 nIndex = pRuntime->ToInt32(params[0]);
2421
2422 CPDF_FormField* pFormField = GetFirstFormField();
2423 if (!pFormField)
2425
2426 if (nIndex < 0 || nIndex >= pFormField->CountControls())
2428
2430 pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) &&
2431 pFormField->GetControl(nIndex)->IsChecked() != 0)));
2432}
2433
2434CJS_Result CJS_Field::isDefaultChecked(
2435 CJS_Runtime* pRuntime,
2436 pdfium::span<v8::Local<v8::Value>> params) {
2437 int nIndex = -1;
2438 if (params.size() >= 1)
2439 nIndex = pRuntime->ToInt32(params[0]);
2440
2441 CPDF_FormField* pFormField = GetFirstFormField();
2442 if (!pFormField)
2444
2445 if (nIndex < 0 || nIndex >= pFormField->CountControls())
2447
2448 return CJS_Result::Success(pRuntime->NewBoolean(
2449 (IsCheckBoxOrRadioButton(pFormField) &&
2450 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)));
2451}
2452
2453CJS_Result CJS_Field::setAction(CJS_Runtime* pRuntime,
2454 pdfium::span<v8::Local<v8::Value>> params) {
2455 return CJS_Result::Success();
2456}
2457
2458CJS_Result CJS_Field::setFocus(CJS_Runtime* pRuntime,
2459 pdfium::span<v8::Local<v8::Value>> params) {
2460 CPDF_FormField* pFormField = GetFirstFormField();
2461 if (!pFormField)
2463
2464 int32_t nCount = pFormField->CountControls();
2465 if (nCount < 1)
2467
2468 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
2469 CPDFSDK_Widget* pWidget = nullptr;
2470 if (nCount == 1) {
2471 pWidget = pForm->GetWidget(pFormField->GetControl(0));
2472 } else {
2473 IPDF_Page* pPage = m_pFormFillEnv->GetCurrentPage();
2474 if (!pPage)
2476 CPDFSDK_PageView* pCurPageView = m_pFormFillEnv->GetOrCreatePageView(pPage);
2477 for (int32_t i = 0; i < nCount; i++) {
2478 if (CPDFSDK_Widget* pTempWidget =
2479 pForm->GetWidget(pFormField->GetControl(i))) {
2480 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2481 pWidget = pTempWidget;
2482 break;
2483 }
2484 }
2485 }
2486 }
2487
2488 if (pWidget) {
2489 ObservedPtr<CPDFSDK_Annot> pObserved(pWidget);
2490 m_pFormFillEnv->SetFocusAnnot(pObserved);
2491 }
2492
2493 return CJS_Result::Success();
2494}
2495
2496CJS_Result CJS_Field::setItems(CJS_Runtime* pRuntime,
2497 pdfium::span<v8::Local<v8::Value>> params) {
2498 return CJS_Result::Success();
2499}
2500
2501CJS_Result CJS_Field::setLock(CJS_Runtime* pRuntime,
2502 pdfium::span<v8::Local<v8::Value>> params) {
2504}
2505
2506CJS_Result CJS_Field::signatureGetModifications(
2507 CJS_Runtime* pRuntime,
2508 pdfium::span<v8::Local<v8::Value>> params) {
2510}
2511
2512CJS_Result CJS_Field::signatureGetSeedValue(
2513 CJS_Runtime* pRuntime,
2514 pdfium::span<v8::Local<v8::Value>> params) {
2516}
2517
2518CJS_Result CJS_Field::signatureInfo(CJS_Runtime* pRuntime,
2519 pdfium::span<v8::Local<v8::Value>> params) {
2521}
2522
2523CJS_Result CJS_Field::signatureSetSeedValue(
2524 CJS_Runtime* pRuntime,
2525 pdfium::span<v8::Local<v8::Value>> params) {
2527}
2528
2529CJS_Result CJS_Field::signatureSign(CJS_Runtime* pRuntime,
2530 pdfium::span<v8::Local<v8::Value>> params) {
2532}
2533
2534CJS_Result CJS_Field::signatureValidate(
2535 CJS_Runtime* pRuntime,
2536 pdfium::span<v8::Local<v8::Value>> params) {
2538}
2539
2540void CJS_Field::SetDelay(bool bDelay) {
2541 m_bDelay = bDelay;
2542 if (m_bDelay)
2543 return;
2544
2545 if (m_pJSDoc)
2546 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
2547}
2548
2549void CJS_Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
2550 auto pNewData =
2551 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2552 pNewData->num = n;
2553 m_pJSDoc->AddDelayData(std::move(pNewData));
2554}
2555
2556void CJS_Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
2557 auto pNewData =
2558 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2559 pNewData->b = b;
2560 m_pJSDoc->AddDelayData(std::move(pNewData));
2561}
2562
2563void CJS_Field::AddDelay_String(FIELD_PROP prop, const ByteString& str) {
2564 auto pNewData =
2565 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2566 pNewData->bytestring = str;
2567 m_pJSDoc->AddDelayData(std::move(pNewData));
2568}
2569
2570void CJS_Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
2571 auto pNewData =
2572 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2573 pNewData->rect = rect;
2574 m_pJSDoc->AddDelayData(std::move(pNewData));
2575}
2576
2577void CJS_Field::AddDelay_WordArray(FIELD_PROP prop,
2578 const std::vector<uint32_t>& array) {
2579 auto pNewData =
2580 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2581 pNewData->wordarray = array;
2582 m_pJSDoc->AddDelayData(std::move(pNewData));
2583}
2584
2585void CJS_Field::AddDelay_WideStringArray(FIELD_PROP prop,
2586 const std::vector<WideString>& array) {
2587 auto pNewData =
2588 std::make_unique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
2589 pNewData->widestringarray = array;
2590 m_pJSDoc->AddDelayData(std::move(pNewData));
2591}
2592
2593void CJS_Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2594 CJS_DelayData* pData) {
2595 DCHECK(pFormFillEnv);
2596 switch (pData->eProp) {
2597 case FP_BORDERSTYLE:
2598 SetBorderStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2599 pData->bytestring);
2600 break;
2602 SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
2603 pData->nControlIndex, pData->wordarray);
2604 break;
2605 case FP_DISPLAY:
2606 SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2607 pData->num);
2608 break;
2609 case FP_HIDDEN:
2610 SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2611 pData->b);
2612 break;
2613 case FP_LINEWIDTH:
2614 SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2615 pData->num);
2616 break;
2617 case FP_RECT:
2618 SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2619 pData->rect);
2620 break;
2621 case FP_VALUE:
2622 SetFieldValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2623 pData->widestringarray);
2624 break;
2625 }
2626}
BorderStyle
@ FXJSOBJTYPE_DYNAMIC
FIELD_PROP
Definition cjs_field.h:21
@ FP_HIDDEN
Definition cjs_field.h:25
@ FP_DISPLAY
Definition cjs_field.h:24
@ FP_LINEWIDTH
Definition cjs_field.h:26
@ FP_CURRENTVALUEINDICES
Definition cjs_field.h:23
@ FP_VALUE
Definition cjs_field.h:28
@ FP_BORDERSTYLE
Definition cjs_field.h:22
@ FP_RECT
Definition cjs_field.h:27
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)
~CJS_Field() override
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()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
CPDF_Page * GetPDFPage()
BorderStyle GetBorderStyle() const
int GetBorderWidth() const
void SetFlags(uint32_t nFlags)
CFX_FloatRect GetRect() const override
uint32_t GetFlags() const
CPDFSDK_InteractiveForm * GetInteractiveForm()
void UpdateAllViews(CPDFSDK_Annot *pAnnot)
CPDFSDK_Widget * GetWidget(CPDF_FormControl *pControl) const
CPDF_InteractiveForm * GetInteractiveForm() const
CPDF_Page * GetPDFPage() const
FormFieldType GetFieldType() const
CPDF_FormField::Type GetType() const
WideString GetExportValue() const
int GetControlAlignment() const
WideString GetDownCaption() const
HighlightingMode GetHighlightingMode() const
float GetOriginalColorComponent(int index, const ByteString &csEntry)
WideString GetRolloverCaption() const
WideString GetNormalCaption() const
CPDF_IconFit GetIconFit() const
CPDF_DefaultAppearance GetDefaultAppearance() const
CFX_Color::TypeAndARGB GetColorARGB(const ByteString &csEntry)
bool IsDefaultChecked() const
int GetTextPosition() const
int GetSelectedIndex(int index) const
int CountOptions() const
WideString GetValue() const
int CountControls() const
uint32_t GetFieldFlags() const
WideString GetAlternateName() const
int GetMaxLen() const
WideString GetOptionLabel(int index) const
int CountSelectedItems() const
CPDF_FormControl * GetControl(int index) const
FormFieldType GetFieldType() const
WideString GetOptionValue(int index) const
WideString GetDefaultValue() const
bool CheckControl(int iControlIndex, bool bChecked, NotificationOption notify)
void SetFieldFlags(uint32_t dwFlags)
bool SetValue(const WideString &value, NotificationOption notify)
ScaleMethod GetScaleMethod() const
bool GetFittingBounds() const
bool IsProportionalScale() const
int FindFieldInCalculationOrder(const CPDF_FormField *pField)
bool operator==(const char *ptr) const
ByteString & operator=(const char *str)
CharType operator[](const size_t index) const
Definition widestring.h:146
bool IsEmpty() const
Definition widestring.h:118
const wchar_t * c_str() const
Definition widestring.h:81
void TrimRight(wchar_t target)
bool operator!=(const wchar_t *ptr) const
Definition widestring.h:138
NotificationOption
FormFieldType
int32_t FXSYS_wtoi(const wchar_t *str)
JSMessage
@ kObjectTypeError
@ kNotSupportedError
Definition fxv8.h:22
bool IsArray(v8::Local< v8::Value > value)
Definition fxv8.cpp:47
constexpr uint32_t kNoView
constexpr uint32_t kHidden
constexpr uint32_t kPrint
constexpr uint32_t kInvisible
const char kBC[]
const char kBG[]
constexpr uint32_t kReadOnly
Definition form_flags.h:13
constexpr uint32_t kChoiceEdit
Definition form_flags.h:37
constexpr uint32_t kTextFileSelect
Definition form_flags.h:28
constexpr uint32_t kButtonRadiosInUnison
Definition form_flags.h:22
constexpr uint32_t kTextPassword
Definition form_flags.h:27
constexpr uint32_t kTextDoNotSpellCheck
Definition form_flags.h:29
constexpr uint32_t kRequired
Definition form_flags.h:14
constexpr uint32_t kChoiceCommitOnSelChange
Definition form_flags.h:41
constexpr uint32_t kChoiceMultiSelect
Definition form_flags.h:39
constexpr uint32_t kTextDoNotScroll
Definition form_flags.h:30
constexpr uint32_t kTextRichText
Definition form_flags.h:32
constexpr uint32_t kTextComb
Definition form_flags.h:31
constexpr uint32_t kTextMultiline
Definition form_flags.h:26
CFX_Color::Type color_type
Definition cfx_color.h:20
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)
Definition cfx_color.h:27
FIELD_PROP eProp
CFX_FloatRect rect