blob: 45715e22a0ed30b53a0287bcea2c8f3af12fe315 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclaire0345a42017-10-30 20:20:42 +00007#include "fxjs/cjs_field.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Tom Sepezb9cc7a02016-02-01 13:42:30 -08009#include <algorithm>
10#include <memory>
Tom Sepez75acda62018-01-29 20:17:36 +000011#include <utility>
Tom Sepezb9cc7a02016-02-01 13:42:30 -080012
dsinclairbc5e6d22016-10-04 11:08:49 -070013#include "core/fpdfapi/font/cpdf_font.h"
Dan Sinclair51230322017-10-30 15:36:02 +000014#include "core/fpdfdoc/cpdf_formfield.h"
dsinclair1727aee2016-09-29 13:12:56 -070015#include "core/fpdfdoc/cpdf_interform.h"
dsinclair114e46a2016-09-29 17:18:21 -070016#include "fpdfsdk/cpdfsdk_interform.h"
17#include "fpdfsdk/cpdfsdk_pageview.h"
18#include "fpdfsdk/cpdfsdk_widget.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000019#include "fxjs/cjs_color.h"
20#include "fxjs/cjs_delaydata.h"
21#include "fxjs/cjs_document.h"
22#include "fxjs/cjs_icon.h"
23#include "fxjs/js_resources.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024
tonikitoo7c05a7a2016-08-17 11:08:46 -070025namespace {
26
Lei Zhang94919f72018-07-12 21:16:30 +000027bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) {
28 return pFormField->GetFieldType() == FormFieldType::kCheckBox ||
29 pFormField->GetFieldType() == FormFieldType::kRadioButton;
30}
31
32bool IsComboBoxOrListBox(const CPDF_FormField* pFormField) {
33 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
34 pFormField->GetFieldType() == FormFieldType::kListBox;
35}
36
37bool IsComboBoxOrTextField(const CPDF_FormField* pFormField) {
38 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
39 pFormField->GetFieldType() == FormFieldType::kTextField;
40}
41
42void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
43 CPDF_FormField* pFormField,
44 bool bChangeMark,
45 bool bResetAP,
46 bool bRefresh) {
47 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
48
49 if (bResetAP) {
50 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
51 pInterForm->GetWidgets(pFormField, &widgets);
52
53 if (IsComboBoxOrTextField(pFormField)) {
54 for (auto& pObserved : widgets) {
55 if (pObserved) {
56 bool bFormatted = false;
Tom Sepez4ef943b2018-07-26 19:06:06 +000057 WideString sValue =
58 ToCPDFSDKWidget(pObserved.Get())->OnFormat(bFormatted);
Lei Zhang94919f72018-07-12 21:16:30 +000059 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
Tom Sepez4ef943b2018-07-26 19:06:06 +000060 ToCPDFSDKWidget(pObserved.Get())->ResetAppearance(
61 bFormatted ? &sValue : nullptr, false);
Lei Zhang94919f72018-07-12 21:16:30 +000062 }
63 }
64 }
65 } else {
66 for (auto& pObserved : widgets) {
Tom Sepez4ef943b2018-07-26 19:06:06 +000067 if (pObserved)
68 ToCPDFSDKWidget(pObserved.Get())->ResetAppearance(nullptr, false);
Lei Zhang94919f72018-07-12 21:16:30 +000069 }
70 }
71 }
72
73 if (bRefresh) {
74 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
75 // to be removed from the list. We need to call |GetWidgets| again to be
76 // sure none of the widgets have been deleted.
77 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
78 pInterForm->GetWidgets(pFormField, &widgets);
79
80 // TODO(dsinclair): Determine if all widgets share the same
81 // CPDFSDK_InterForm. If that's the case, we can move the code to
82 // |GetFormFillEnv| out of the loop.
83 for (auto& pObserved : widgets) {
84 if (pObserved) {
Tom Sepez4ef943b2018-07-26 19:06:06 +000085 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pObserved.Get());
Lei Zhang94919f72018-07-12 21:16:30 +000086 pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
87 pWidget);
88 }
89 }
90 }
91
92 if (bChangeMark)
93 pFormFillEnv->SetChangeMark();
94}
95
96void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
97 CPDF_FormControl* pFormControl,
98 bool bChangeMark,
99 bool bResetAP,
100 bool bRefresh) {
101 ASSERT(pFormControl);
102
103 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
104 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
105
106 if (pWidget) {
107 CPDFSDK_Widget::ObservedPtr observed_widget(pWidget);
108 if (bResetAP) {
109 FormFieldType fieldType = pWidget->GetFieldType();
110 if (fieldType == FormFieldType::kComboBox ||
111 fieldType == FormFieldType::kTextField) {
112 bool bFormatted = false;
113 WideString sValue = pWidget->OnFormat(bFormatted);
114 if (!observed_widget)
115 return;
116 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, false);
117 } else {
118 pWidget->ResetAppearance(nullptr, false);
119 }
120 if (!observed_widget)
121 return;
122 }
123
124 if (bRefresh) {
125 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
126 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
127 }
128 }
129
130 if (bChangeMark)
131 pFormFillEnv->SetChangeMark();
132}
133
134std::vector<CPDF_FormField*> GetFormFieldsForName(
135 CPDFSDK_FormFillEnvironment* pFormFillEnv,
136 const WideString& csFieldName) {
137 std::vector<CPDF_FormField*> fields;
138 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
139 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
140 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
141 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
142 fields.push_back(pFormField);
143 }
144 return fields;
145}
146
147CPDFSDK_Widget* GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
148 CPDF_FormControl* pFormControl) {
149 CPDFSDK_InterForm* pInterForm =
150 static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
151 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
152}
153
tonikitoo7c05a7a2016-08-17 11:08:46 -0700154bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
155 if (!pWidget)
156 return false;
157
158 uint32_t dwFlag = pWidget->GetFlags();
159 switch (value) {
160 case 0:
161 dwFlag &= ~ANNOTFLAG_INVISIBLE;
162 dwFlag &= ~ANNOTFLAG_HIDDEN;
163 dwFlag &= ~ANNOTFLAG_NOVIEW;
164 dwFlag |= ANNOTFLAG_PRINT;
165 break;
166 case 1:
167 dwFlag &= ~ANNOTFLAG_INVISIBLE;
168 dwFlag &= ~ANNOTFLAG_NOVIEW;
169 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
170 break;
171 case 2:
172 dwFlag &= ~ANNOTFLAG_INVISIBLE;
173 dwFlag &= ~ANNOTFLAG_PRINT;
174 dwFlag &= ~ANNOTFLAG_HIDDEN;
175 dwFlag &= ~ANNOTFLAG_NOVIEW;
176 break;
177 case 3:
178 dwFlag |= ANNOTFLAG_NOVIEW;
179 dwFlag |= ANNOTFLAG_PRINT;
180 dwFlag &= ~ANNOTFLAG_HIDDEN;
181 break;
182 }
183
184 if (dwFlag != pWidget->GetFlags()) {
185 pWidget->SetFlags(dwFlag);
186 return true;
187 }
188
189 return false;
190}
191
Lei Zhang94919f72018-07-12 21:16:30 +0000192void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
193 const WideString& swFieldName,
194 int nControlIndex,
195 const ByteString& string) {
196 ASSERT(pFormFillEnv);
197
198 BorderStyle nBorderStyle = BorderStyle::SOLID;
199 if (string == "solid")
200 nBorderStyle = BorderStyle::SOLID;
201 else if (string == "beveled")
202 nBorderStyle = BorderStyle::BEVELED;
203 else if (string == "dashed")
204 nBorderStyle = BorderStyle::DASH;
205 else if (string == "inset")
206 nBorderStyle = BorderStyle::INSET;
207 else if (string == "underline")
208 nBorderStyle = BorderStyle::UNDERLINE;
209 else
210 return;
211
212 std::vector<CPDF_FormField*> FieldArray =
213 GetFormFieldsForName(pFormFillEnv, swFieldName);
214 for (CPDF_FormField* pFormField : FieldArray) {
215 if (nControlIndex < 0) {
216 bool bSet = false;
217 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
218 if (CPDFSDK_Widget* pWidget =
219 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
220 if (pWidget->GetBorderStyle() != nBorderStyle) {
221 pWidget->SetBorderStyle(nBorderStyle);
222 bSet = true;
223 }
224 }
225 }
226 if (bSet)
227 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
228 } else {
229 if (nControlIndex >= pFormField->CountControls())
230 return;
231 if (CPDF_FormControl* pFormControl =
232 pFormField->GetControl(nControlIndex)) {
233 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
234 if (pWidget->GetBorderStyle() != nBorderStyle) {
235 pWidget->SetBorderStyle(nBorderStyle);
236 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
237 }
238 }
239 }
240 }
241 }
Lei Zhangdfa2ac22018-07-12 19:06:50 +0000242}
243
Lei Zhang94919f72018-07-12 21:16:30 +0000244void SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
245 const WideString& swFieldName,
246 int nControlIndex,
247 const std::vector<uint32_t>& array) {
248 ASSERT(pFormFillEnv);
249 std::vector<CPDF_FormField*> FieldArray =
250 GetFormFieldsForName(pFormFillEnv, swFieldName);
251
252 for (CPDF_FormField* pFormField : FieldArray) {
253 if (!IsComboBoxOrListBox(pFormField))
254 continue;
255
256 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
257 pFormField->ClearSelection(true);
258 for (size_t i = 0; i < array.size(); ++i) {
259 if (i != 0 && !(dwFieldFlags & (1 << 21)))
260 break;
261 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
262 !pFormField->IsItemSelected(array[i])) {
263 pFormField->SetItemSelection(array[i], true);
264 }
265 }
266 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
267 }
Lei Zhang83f2d702018-07-12 19:07:40 +0000268}
269
Lei Zhang94919f72018-07-12 21:16:30 +0000270void SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
271 const WideString& swFieldName,
272 int nControlIndex,
273 int number) {
274 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
275 std::vector<CPDF_FormField*> FieldArray =
276 GetFormFieldsForName(pFormFillEnv, swFieldName);
277 for (CPDF_FormField* pFormField : FieldArray) {
278 if (nControlIndex < 0) {
279 bool bAnySet = false;
280 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
281 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
282 ASSERT(pFormControl);
283
284 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
285 if (SetWidgetDisplayStatus(pWidget, number))
286 bAnySet = true;
287 }
288
289 if (bAnySet)
290 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
291 } else {
292 if (nControlIndex >= pFormField->CountControls())
293 return;
294
295 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
296 if (!pFormControl)
297 return;
298
299 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
300 if (SetWidgetDisplayStatus(pWidget, number))
301 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
302 }
303 }
304}
305
306void SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
307 const WideString& swFieldName,
308 int nControlIndex,
309 bool b) {
310 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
311 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
312}
313
314void SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
315 const WideString& swFieldName,
316 int nControlIndex,
317 int number) {
318 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
319 std::vector<CPDF_FormField*> FieldArray =
320 GetFormFieldsForName(pFormFillEnv, swFieldName);
321 for (CPDF_FormField* pFormField : FieldArray) {
322 if (nControlIndex < 0) {
323 bool bSet = false;
324 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
325 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
326 ASSERT(pFormControl);
327
328 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
329 if (number != pWidget->GetBorderWidth()) {
330 pWidget->SetBorderWidth(number);
331 bSet = true;
332 }
333 }
334 }
335 if (bSet)
336 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
337 } else {
338 if (nControlIndex >= pFormField->CountControls())
339 return;
340 if (CPDF_FormControl* pFormControl =
341 pFormField->GetControl(nControlIndex)) {
342 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
343 if (number != pWidget->GetBorderWidth()) {
344 pWidget->SetBorderWidth(number);
345 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
346 }
347 }
348 }
349 }
350 }
351}
352
353void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
354 const WideString& swFieldName,
355 int nControlIndex,
356 const CFX_FloatRect& rect) {
357 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
358 std::vector<CPDF_FormField*> FieldArray =
359 GetFormFieldsForName(pFormFillEnv, swFieldName);
360 for (CPDF_FormField* pFormField : FieldArray) {
361 if (nControlIndex < 0) {
362 bool bSet = false;
363 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
364 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
365 ASSERT(pFormControl);
366
367 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
368 CFX_FloatRect crRect = rect;
369
370 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
371 crRect.Intersect(pPDFPage->GetBBox());
372
373 if (!crRect.IsEmpty()) {
374 CFX_FloatRect rcOld = pWidget->GetRect();
375 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
376 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
377 pWidget->SetRect(crRect);
378 bSet = true;
379 }
380 }
381 }
382 }
383
384 if (bSet)
385 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
386
387 continue;
388 }
389
390 if (nControlIndex >= pFormField->CountControls())
391 return;
392 if (CPDF_FormControl* pFormControl =
393 pFormField->GetControl(nControlIndex)) {
394 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
395 CFX_FloatRect crRect = rect;
396 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
397 crRect.Intersect(pPDFPage->GetBBox());
398 if (!crRect.IsEmpty()) {
399 CFX_FloatRect rcOld = pWidget->GetRect();
400 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
401 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
402 pWidget->SetRect(crRect);
403 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
404 }
405 }
406 }
407 }
408 }
409}
410
411void SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
412 const WideString& swFieldName,
413 int nControlIndex,
414 const std::vector<WideString>& strArray) {
415 ASSERT(pFormFillEnv);
416 if (strArray.empty())
417 return;
418
419 std::vector<CPDF_FormField*> FieldArray =
420 GetFormFieldsForName(pFormFillEnv, swFieldName);
421
422 for (CPDF_FormField* pFormField : FieldArray) {
423 if (pFormField->GetFullName().Compare(swFieldName) != 0)
424 continue;
425
426 switch (pFormField->GetFieldType()) {
427 case FormFieldType::kTextField:
428 case FormFieldType::kComboBox:
429 if (pFormField->GetValue() != strArray[0]) {
430 pFormField->SetValue(strArray[0], true);
431 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
432 }
433 break;
434 case FormFieldType::kCheckBox:
435 case FormFieldType::kRadioButton:
436 if (pFormField->GetValue() != strArray[0]) {
437 pFormField->SetValue(strArray[0], true);
438 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
439 }
440 break;
441 case FormFieldType::kListBox: {
442 bool bModified = false;
443 for (const auto& str : strArray) {
444 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
445 bModified = true;
446 break;
447 }
448 }
449 if (bModified) {
450 pFormField->ClearSelection(true);
451 for (const auto& str : strArray) {
452 int index = pFormField->FindOption(str);
453 if (!pFormField->IsItemSelected(index))
454 pFormField->SetItemSelection(index, true, true);
455 }
456 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
457 }
458 break;
459 }
460 default:
461 break;
462 }
463 }
Lei Zhang83f2d702018-07-12 19:07:40 +0000464}
465
tonikitoo7c05a7a2016-08-17 11:08:46 -0700466} // namespace
467
Dan Sinclairc94a7932017-10-26 16:48:57 -0400468const JSPropertySpec CJS_Field::PropertySpecs[] = {
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800469 {"alignment", get_alignment_static, set_alignment_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400470 {"borderStyle", get_border_style_static, set_border_style_static},
471 {"buttonAlignX", get_button_align_x_static, set_button_align_x_static},
472 {"buttonAlignY", get_button_align_y_static, set_button_align_y_static},
473 {"buttonFitBounds", get_button_fit_bounds_static,
474 set_button_fit_bounds_static},
475 {"buttonPosition", get_button_position_static, set_button_position_static},
476 {"buttonScaleHow", get_button_scale_how_static,
477 set_button_scale_how_static},
478 {"buttonScaleWhen", get_button_scale_when_static,
479 set_button_scale_when_static},
480 {"calcOrderIndex", get_calc_order_index_static,
481 set_calc_order_index_static},
482 {"charLimit", get_char_limit_static, set_char_limit_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800483 {"comb", get_comb_static, set_comb_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400484 {"commitOnSelChange", get_commit_on_sel_change_static,
485 set_commit_on_sel_change_static},
486 {"currentValueIndices", get_current_value_indices_static,
487 set_current_value_indices_static},
488 {"defaultStyle", get_default_style_static, set_default_style_static},
489 {"defaultValue", get_default_value_static, set_default_value_static},
490 {"doNotScroll", get_do_not_scroll_static, set_do_not_scroll_static},
491 {"doNotSpellCheck", get_do_not_spell_check_static,
492 set_do_not_spell_check_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800493 {"delay", get_delay_static, set_delay_static},
494 {"display", get_display_static, set_display_static},
495 {"doc", get_doc_static, set_doc_static},
496 {"editable", get_editable_static, set_editable_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400497 {"exportValues", get_export_values_static, set_export_values_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800498 {"hidden", get_hidden_static, set_hidden_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400499 {"fileSelect", get_file_select_static, set_file_select_static},
500 {"fillColor", get_fill_color_static, set_fill_color_static},
501 {"lineWidth", get_line_width_static, set_line_width_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800502 {"highlight", get_highlight_static, set_highlight_static},
503 {"multiline", get_multiline_static, set_multiline_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400504 {"multipleSelection", get_multiple_selection_static,
505 set_multiple_selection_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800506 {"name", get_name_static, set_name_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400507 {"numItems", get_num_items_static, set_num_items_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800508 {"page", get_page_static, set_page_static},
509 {"password", get_password_static, set_password_static},
510 {"print", get_print_static, set_print_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400511 {"radiosInUnison", get_radios_in_unison_static,
512 set_radios_in_unison_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800513 {"readonly", get_readonly_static, set_readonly_static},
514 {"rect", get_rect_static, set_rect_static},
515 {"required", get_required_static, set_required_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400516 {"richText", get_rich_text_static, set_rich_text_static},
517 {"richValue", get_rich_value_static, set_rich_value_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800518 {"rotation", get_rotation_static, set_rotation_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400519 {"strokeColor", get_stroke_color_static, set_stroke_color_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800520 {"style", get_style_static, set_style_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400521 {"submitName", get_submit_name_static, set_submit_name_static},
522 {"textColor", get_text_color_static, set_text_color_static},
523 {"textFont", get_text_font_static, set_text_font_static},
524 {"textSize", get_text_size_static, set_text_size_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800525 {"type", get_type_static, set_type_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400526 {"userName", get_user_name_static, set_user_name_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800527 {"value", get_value_static, set_value_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400528 {"valueAsString", get_value_as_string_static, set_value_as_string_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +0000529 {"source", get_source_static, set_source_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700530
Dan Sinclairc94a7932017-10-26 16:48:57 -0400531const JSMethodSpec CJS_Field::MethodSpecs[] = {
Tom Sepez9b99b632017-02-21 15:05:57 -0800532 {"browseForFileToSubmit", browseForFileToSubmit_static},
533 {"buttonGetCaption", buttonGetCaption_static},
534 {"buttonGetIcon", buttonGetIcon_static},
535 {"buttonImportIcon", buttonImportIcon_static},
536 {"buttonSetCaption", buttonSetCaption_static},
537 {"buttonSetIcon", buttonSetIcon_static},
538 {"checkThisBox", checkThisBox_static},
539 {"clearItems", clearItems_static},
540 {"defaultIsChecked", defaultIsChecked_static},
541 {"deleteItemAt", deleteItemAt_static},
542 {"getArray", getArray_static},
543 {"getItemAt", getItemAt_static},
544 {"getLock", getLock_static},
545 {"insertItemAt", insertItemAt_static},
546 {"isBoxChecked", isBoxChecked_static},
547 {"isDefaultChecked", isDefaultChecked_static},
548 {"setAction", setAction_static},
549 {"setFocus", setFocus_static},
550 {"setItems", setItems_static},
551 {"setLock", setLock_static},
552 {"signatureGetModifications", signatureGetModifications_static},
553 {"signatureGetSeedValue", signatureGetSeedValue_static},
554 {"signatureInfo", signatureInfo_static},
555 {"signatureSetSeedValue", signatureSetSeedValue_static},
556 {"signatureSign", signatureSign_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +0000557 {"signatureValidate", signatureValidate_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700558
Dan Sinclairef299532017-10-26 16:48:30 -0400559int CJS_Field::ObjDefnID = -1;
Dan Sinclairf7435522018-02-05 22:27:22 +0000560const char CJS_Field::kName[] = "Field";
Dan Sinclair89d26c82017-10-26 12:21:28 -0400561
Dan Sinclairef299532017-10-26 16:48:30 -0400562// static
563int CJS_Field::GetObjDefnID() {
564 return ObjDefnID;
565}
566
567// static
Dan Sinclairbef4d3e2017-10-26 16:49:38 -0400568void CJS_Field::DefineJSObjects(CFXJS_Engine* pEngine) {
Dan Sinclairf7435522018-02-05 22:27:22 +0000569 ObjDefnID = pEngine->DefineObj(CJS_Field::kName, FXJSOBJTYPE_DYNAMIC,
Dan Sinclair998fee32018-02-05 21:43:19 +0000570 JSConstructor<CJS_Field>, JSDestructor);
Tom Sepez8b4ddeb2018-06-11 15:55:17 +0000571 DefineProps(pEngine, ObjDefnID, PropertySpecs);
572 DefineMethods(pEngine, ObjDefnID, MethodSpecs);
Dan Sinclair89d26c82017-10-26 12:21:28 -0400573}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700574
Tom Sepez36aae4f2018-06-04 19:44:37 +0000575CJS_Field::CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
576 : CJS_Object(pObject, pRuntime) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577
Dan Sinclairf7435522018-02-05 22:27:22 +0000578CJS_Field::~CJS_Field() = default;
579
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580// note: iControlNo = -1, means not a widget.
Dan Sinclairf7435522018-02-05 22:27:22 +0000581void CJS_Field::ParseFieldName(const std::wstring& strFieldNameParsed,
582 std::wstring& strFieldName,
583 int& iControlNo) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 int iStart = strFieldNameParsed.find_last_of(L'.');
585 if (iStart == -1) {
586 strFieldName = strFieldNameParsed;
587 iControlNo = -1;
588 return;
589 }
590 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
591 iControlNo = FXSYS_wtoi(suffixal.c_str());
592 if (iControlNo == 0) {
weilidb444d22016-06-02 15:48:15 -0700593 int iSpaceStart;
594 while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
595 suffixal.erase(iSpaceStart, 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596 }
597
598 if (suffixal.compare(L"0") != 0) {
599 strFieldName = strFieldNameParsed;
600 iControlNo = -1;
601 return;
602 }
603 }
604 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700605}
606
Dan Sinclairf7435522018-02-05 22:27:22 +0000607bool CJS_Field::AttachField(CJS_Document* pDocument,
608 const WideString& csFieldName) {
Tom Sepez2cbae732018-06-26 15:11:28 +0000609 m_pJSDoc.Reset(pDocument);
dsinclair82e17672016-10-11 12:38:01 -0700610 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
dsinclair7cbe68e2016-10-12 11:56:23 -0700611 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
612 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
613 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614
dsinclair7cbe68e2016-10-12 11:56:23 -0700615 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Ryan Harrison275e2602017-09-18 14:23:18 -0400617 WideString swFieldNameTemp = csFieldName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 swFieldNameTemp.Replace(L"..", L".");
619
620 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
621 std::wstring strFieldName;
622 int iControlNo = -1;
623 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
624 if (iControlNo == -1)
tsepez4cf55152016-11-02 14:37:54 -0700625 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626
627 m_FieldName = strFieldName.c_str();
628 m_nFormControlIndex = iControlNo;
tsepez4cf55152016-11-02 14:37:54 -0700629 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 }
631
632 m_FieldName = swFieldNameTemp;
633 m_nFormControlIndex = -1;
634
tsepez4cf55152016-11-02 14:37:54 -0700635 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700636}
637
Lei Zhang18915232018-07-12 20:53:40 +0000638std::vector<CPDF_FormField*> CJS_Field::GetFormFields() const {
Lei Zhang94919f72018-07-12 21:16:30 +0000639 return GetFormFieldsForName(m_pFormFillEnv.Get(), m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640}
641
Lei Zhang4c7ad662018-07-12 20:29:40 +0000642CPDF_FormField* CJS_Field::GetFirstFormField() const {
Lei Zhang18915232018-07-12 20:53:40 +0000643 std::vector<CPDF_FormField*> fields = GetFormFields();
Lei Zhang4c7ad662018-07-12 20:29:40 +0000644 return fields.empty() ? nullptr : fields[0];
645}
646
Dan Sinclairf7435522018-02-05 22:27:22 +0000647bool CJS_Field::ValueIsOccur(CPDF_FormField* pFormField,
Lei Zhang18915232018-07-12 20:53:40 +0000648 WideString csOptLabel) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
650 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
tsepez4cf55152016-11-02 14:37:54 -0700651 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 }
653
tsepez4cf55152016-11-02 14:37:54 -0700654 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655}
656
Dan Sinclairf7435522018-02-05 22:27:22 +0000657CPDF_FormControl* CJS_Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658 if (!pFormField->CountControls() ||
659 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700660 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661 if (m_nFormControlIndex < 0)
662 return pFormField->GetControl(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 return pFormField->GetControl(m_nFormControlIndex);
664}
665
Dan Sinclairf7435522018-02-05 22:27:22 +0000666CJS_Return CJS_Field::get_alignment(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700667 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668
Lei Zhang4c7ad662018-07-12 20:29:40 +0000669 CPDF_FormField* pFormField = GetFirstFormField();
670 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000671 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000673 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +0000674 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675
dan sinclair646634b2017-10-19 14:30:28 -0400676 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
677 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +0000678 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679
dan sinclair646634b2017-10-19 14:30:28 -0400680 switch (pFormControl->GetControlAlignment()) {
dan sinclair646634b2017-10-19 14:30:28 -0400681 case 0:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400682 return CJS_Return(pRuntime->NewString(L"left"));
683 case 1:
684 return CJS_Return(pRuntime->NewString(L"center"));
dan sinclair646634b2017-10-19 14:30:28 -0400685 case 2:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400686 return CJS_Return(pRuntime->NewString(L"right"));
dan sinclair646634b2017-10-19 14:30:28 -0400687 }
Dan Sinclair8f524d62017-10-25 13:30:31 -0400688 return CJS_Return(pRuntime->NewString(L""));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689}
690
Dan Sinclairf7435522018-02-05 22:27:22 +0000691CJS_Return CJS_Field::set_alignment(CJS_Runtime* pRuntime,
692 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400693 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000694 if (!m_bCanSet)
695 return CJS_Return(JSMessage::kReadOnlyError);
696 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697}
698
Dan Sinclairf7435522018-02-05 22:27:22 +0000699CJS_Return CJS_Field::get_border_style(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700700 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701
Lei Zhang4c7ad662018-07-12 20:29:40 +0000702 CPDF_FormField* pFormField = GetFirstFormField();
703 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000704 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705
Tom Sepez16999822018-06-08 18:23:05 +0000706 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707
dan sinclaircbe23db2017-10-19 14:29:33 -0400708 CPDFSDK_Widget* pWidget =
709 GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
710 if (!pWidget)
Tom Sepez16999822018-06-08 18:23:05 +0000711 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712
dan sinclaircbe23db2017-10-19 14:29:33 -0400713 switch (pWidget->GetBorderStyle()) {
714 case BorderStyle::SOLID:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400715 return CJS_Return(pRuntime->NewString(L"solid"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400716 case BorderStyle::DASH:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400717 return CJS_Return(pRuntime->NewString(L"dashed"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400718 case BorderStyle::BEVELED:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400719 return CJS_Return(pRuntime->NewString(L"beveled"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400720 case BorderStyle::INSET:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400721 return CJS_Return(pRuntime->NewString(L"inset"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400722 case BorderStyle::UNDERLINE:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400723 return CJS_Return(pRuntime->NewString(L"underline"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 }
Dan Sinclair8f524d62017-10-25 13:30:31 -0400725 return CJS_Return(pRuntime->NewString(L""));
dan sinclaircbe23db2017-10-19 14:29:33 -0400726}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727
Dan Sinclairf7435522018-02-05 22:27:22 +0000728CJS_Return CJS_Field::set_border_style(CJS_Runtime* pRuntime,
729 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400730 ASSERT(m_pFormFillEnv);
dan sinclaircbe23db2017-10-19 14:29:33 -0400731 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +0000732 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400733
Tom Sepez34dab072018-08-08 17:49:02 +0000734 ByteString byte_str = pRuntime->ToWideString(vp).ToDefANSI();
dan sinclaircbe23db2017-10-19 14:29:33 -0400735 if (m_bDelay) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400736 AddDelay_String(FP_BORDERSTYLE, byte_str);
dan sinclaircbe23db2017-10-19 14:29:33 -0400737 } else {
Lei Zhang94919f72018-07-12 21:16:30 +0000738 SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
739 byte_str);
dan sinclaircbe23db2017-10-19 14:29:33 -0400740 }
Tom Sepez16999822018-06-08 18:23:05 +0000741 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742}
743
Dan Sinclairf7435522018-02-05 22:27:22 +0000744CJS_Return CJS_Field::get_button_align_x(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700745 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746
Lei Zhang4c7ad662018-07-12 20:29:40 +0000747 CPDF_FormField* pFormField = GetFirstFormField();
748 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000749 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700750
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000751 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +0000752 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753
dan sinclaircbe23db2017-10-19 14:29:33 -0400754 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
755 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +0000756 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400757
758 CPDF_IconFit IconFit = pFormControl->GetIconFit();
759
760 float fLeft;
761 float fBottom;
762 IconFit.GetIconPosition(fLeft, fBottom);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400763 return CJS_Return(pRuntime->NewNumber(static_cast<int32_t>(fLeft)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400764}
765
Dan Sinclairf7435522018-02-05 22:27:22 +0000766CJS_Return CJS_Field::set_button_align_x(CJS_Runtime* pRuntime,
767 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400768 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000769 if (!m_bCanSet)
770 return CJS_Return(JSMessage::kReadOnlyError);
771 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772}
773
Dan Sinclairf7435522018-02-05 22:27:22 +0000774CJS_Return CJS_Field::get_button_align_y(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700775 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776
Lei Zhang4c7ad662018-07-12 20:29:40 +0000777 CPDF_FormField* pFormField = GetFirstFormField();
778 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000779 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000781 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +0000782 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783
dan sinclaircbe23db2017-10-19 14:29:33 -0400784 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
785 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +0000786 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400787
788 CPDF_IconFit IconFit = pFormControl->GetIconFit();
789
790 float fLeft;
791 float fBottom;
792 IconFit.GetIconPosition(fLeft, fBottom);
793
Dan Sinclair8f524d62017-10-25 13:30:31 -0400794 return CJS_Return(pRuntime->NewNumber(static_cast<int32_t>(fBottom)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400795}
796
Dan Sinclairf7435522018-02-05 22:27:22 +0000797CJS_Return CJS_Field::set_button_align_y(CJS_Runtime* pRuntime,
798 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400799 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000800 if (!m_bCanSet)
801 return CJS_Return(JSMessage::kReadOnlyError);
802 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803}
804
Dan Sinclairf7435522018-02-05 22:27:22 +0000805CJS_Return CJS_Field::get_button_fit_bounds(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700806 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807
Lei Zhang4c7ad662018-07-12 20:29:40 +0000808 CPDF_FormField* pFormField = GetFirstFormField();
809 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000810 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700811
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000812 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +0000813 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814
dan sinclair646634b2017-10-19 14:30:28 -0400815 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
816 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +0000817 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818
Dan Sinclair8f524d62017-10-25 13:30:31 -0400819 return CJS_Return(
820 pRuntime->NewBoolean(pFormControl->GetIconFit().GetFittingBounds()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400821}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700822
Dan Sinclairf7435522018-02-05 22:27:22 +0000823CJS_Return CJS_Field::set_button_fit_bounds(CJS_Runtime* pRuntime,
824 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400825 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000826 if (!m_bCanSet)
827 return CJS_Return(JSMessage::kReadOnlyError);
828 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829}
830
Dan Sinclairf7435522018-02-05 22:27:22 +0000831CJS_Return CJS_Field::get_button_position(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700832 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833
Lei Zhang4c7ad662018-07-12 20:29:40 +0000834 CPDF_FormField* pFormField = GetFirstFormField();
835 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000836 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000838 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +0000839 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840
dan sinclair646634b2017-10-19 14:30:28 -0400841 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
842 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +0000843 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844
Dan Sinclair8f524d62017-10-25 13:30:31 -0400845 return CJS_Return(pRuntime->NewNumber(pFormControl->GetTextPosition()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400846}
847
Dan Sinclairf7435522018-02-05 22:27:22 +0000848CJS_Return CJS_Field::set_button_position(CJS_Runtime* pRuntime,
849 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400850 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000851 if (!m_bCanSet)
852 return CJS_Return(JSMessage::kBadObjectError);
853 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854}
855
Dan Sinclairf7435522018-02-05 22:27:22 +0000856CJS_Return CJS_Field::get_button_scale_how(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700857 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700858
Lei Zhang4c7ad662018-07-12 20:29:40 +0000859 CPDF_FormField* pFormField = GetFirstFormField();
860 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000861 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000863 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +0000864 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865
dan sinclair646634b2017-10-19 14:30:28 -0400866 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
867 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +0000868 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869
Dan Sinclair8f524d62017-10-25 13:30:31 -0400870 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -0400871 pFormControl->GetIconFit().IsProportionalScale() ? 0 : 1));
dan sinclaircbe23db2017-10-19 14:29:33 -0400872}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873
Dan Sinclairf7435522018-02-05 22:27:22 +0000874CJS_Return CJS_Field::set_button_scale_how(CJS_Runtime* pRuntime,
875 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400876 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000877 if (!m_bCanSet)
878 return CJS_Return(JSMessage::kReadOnlyError);
879 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880}
881
Dan Sinclairf7435522018-02-05 22:27:22 +0000882CJS_Return CJS_Field::get_button_scale_when(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700883 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884
Lei Zhang4c7ad662018-07-12 20:29:40 +0000885 CPDF_FormField* pFormField = GetFirstFormField();
886 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000887 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000889 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +0000890 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891
dan sinclair646634b2017-10-19 14:30:28 -0400892 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
893 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +0000894 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895
dan sinclair646634b2017-10-19 14:30:28 -0400896 CPDF_IconFit IconFit = pFormControl->GetIconFit();
897 int ScaleM = IconFit.GetScaleMethod();
898 switch (ScaleM) {
899 case CPDF_IconFit::Always:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400900 return CJS_Return(
901 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Always)));
dan sinclair646634b2017-10-19 14:30:28 -0400902 case CPDF_IconFit::Bigger:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400903 return CJS_Return(
904 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Bigger)));
dan sinclair646634b2017-10-19 14:30:28 -0400905 case CPDF_IconFit::Never:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400906 return CJS_Return(
907 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Never)));
dan sinclair646634b2017-10-19 14:30:28 -0400908 case CPDF_IconFit::Smaller:
Dan Sinclair8f524d62017-10-25 13:30:31 -0400909 return CJS_Return(
910 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Smaller)));
dan sinclair646634b2017-10-19 14:30:28 -0400911 }
Tom Sepez16999822018-06-08 18:23:05 +0000912 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -0400913}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914
Dan Sinclairf7435522018-02-05 22:27:22 +0000915CJS_Return CJS_Field::set_button_scale_when(CJS_Runtime* pRuntime,
916 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400917 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000918 if (!m_bCanSet)
919 return CJS_Return(JSMessage::kReadOnlyError);
920 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700921}
922
Dan Sinclairf7435522018-02-05 22:27:22 +0000923CJS_Return CJS_Field::get_calc_order_index(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700924 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925
Lei Zhang4c7ad662018-07-12 20:29:40 +0000926 CPDF_FormField* pFormField = GetFirstFormField();
927 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000928 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929
Lei Zhang83f2d702018-07-12 19:07:40 +0000930 if (!IsComboBoxOrTextField(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +0000931 return CJS_Return(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700932
dan sinclair646634b2017-10-19 14:30:28 -0400933 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
934 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400935 return CJS_Return(pRuntime->NewNumber(static_cast<int32_t>(
Dan Sinclaire4974922017-10-24 09:36:16 -0400936 pInterForm->FindFieldInCalculationOrder(pFormField))));
dan sinclaircbe23db2017-10-19 14:29:33 -0400937}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700938
Dan Sinclairf7435522018-02-05 22:27:22 +0000939CJS_Return CJS_Field::set_calc_order_index(CJS_Runtime* pRuntime,
940 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400941 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000942 if (!m_bCanSet)
943 return CJS_Return(JSMessage::kReadOnlyError);
944 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945}
946
Dan Sinclairf7435522018-02-05 22:27:22 +0000947CJS_Return CJS_Field::get_char_limit(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700948 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700949
Lei Zhang4c7ad662018-07-12 20:29:40 +0000950 CPDF_FormField* pFormField = GetFirstFormField();
951 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000952 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700953
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000954 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +0000955 return CJS_Return(JSMessage::kObjectTypeError);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400956 return CJS_Return(
957 pRuntime->NewNumber(static_cast<int32_t>(pFormField->GetMaxLen())));
dan sinclaircbe23db2017-10-19 14:29:33 -0400958}
959
Dan Sinclairf7435522018-02-05 22:27:22 +0000960CJS_Return CJS_Field::set_char_limit(CJS_Runtime* pRuntime,
961 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400962 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000963 if (!m_bCanSet)
964 return CJS_Return(JSMessage::kReadOnlyError);
965 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700967
Dan Sinclairf7435522018-02-05 22:27:22 +0000968CJS_Return CJS_Field::get_comb(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700969 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700970
Lei Zhang4c7ad662018-07-12 20:29:40 +0000971 CPDF_FormField* pFormField = GetFirstFormField();
972 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000973 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000975 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +0000976 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977
Dan Sinclair8f524d62017-10-25 13:30:31 -0400978 return CJS_Return(
Dan Sinclaire4974922017-10-24 09:36:16 -0400979 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMB)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400980}
981
Dan Sinclairf7435522018-02-05 22:27:22 +0000982CJS_Return CJS_Field::set_comb(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400983 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000984 if (!m_bCanSet)
985 return CJS_Return(JSMessage::kReadOnlyError);
986 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700987}
988
Dan Sinclairf7435522018-02-05 22:27:22 +0000989CJS_Return CJS_Field::get_commit_on_sel_change(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700990 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700991
Lei Zhang4c7ad662018-07-12 20:29:40 +0000992 CPDF_FormField* pFormField = GetFirstFormField();
993 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +0000994 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700995
Lei Zhang83f2d702018-07-12 19:07:40 +0000996 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +0000997 return CJS_Return(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700998
Dan Sinclair8f524d62017-10-25 13:30:31 -0400999 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001000 !!(pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001001}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001002
Dan Sinclairf7435522018-02-05 22:27:22 +00001003CJS_Return CJS_Field::set_commit_on_sel_change(CJS_Runtime* pRuntime,
1004 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001005 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001006 if (!m_bCanSet)
1007 return CJS_Return(JSMessage::kReadOnlyError);
1008 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001009}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001010
Dan Sinclairf7435522018-02-05 22:27:22 +00001011CJS_Return CJS_Field::get_current_value_indices(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001012 CPDF_FormField* pFormField = GetFirstFormField();
1013 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001014 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015
Lei Zhang83f2d702018-07-12 19:07:40 +00001016 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +00001017 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018
dan sinclaircbe23db2017-10-19 14:29:33 -04001019 int count = pFormField->CountSelectedItems();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001020 if (count <= 0)
1021 return CJS_Return(pRuntime->NewNumber(-1));
1022 if (count == 1)
1023 return CJS_Return(pRuntime->NewNumber(pFormField->GetSelectedIndex(0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001024
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001025 v8::Local<v8::Array> SelArray = pRuntime->NewArray();
1026 for (int i = 0; i < count; i++) {
1027 pRuntime->PutArrayElement(
1028 SelArray, i, pRuntime->NewNumber(pFormField->GetSelectedIndex(i)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001029 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001030 if (SelArray.IsEmpty())
Dan Sinclair8f524d62017-10-25 13:30:31 -04001031 return CJS_Return(pRuntime->NewArray());
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001032 return CJS_Return(SelArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001033}
1034
Dan Sinclairf7435522018-02-05 22:27:22 +00001035CJS_Return CJS_Field::set_current_value_indices(CJS_Runtime* pRuntime,
1036 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001037 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001038 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001039
1040 std::vector<uint32_t> array;
dan sinclair80435cb2017-10-24 21:40:24 -04001041 if (vp->IsNumber()) {
1042 array.push_back(pRuntime->ToInt32(vp));
1043 } else if (!vp.IsEmpty() && vp->IsArray()) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001044 v8::Local<v8::Array> SelArray = pRuntime->ToArray(vp);
1045 for (size_t i = 0; i < pRuntime->GetArrayLength(SelArray); i++) {
1046 array.push_back(
1047 pRuntime->ToInt32(pRuntime->GetArrayElement(SelArray, i)));
1048 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001049 }
1050
dan sinclaircbe23db2017-10-19 14:29:33 -04001051 if (m_bDelay) {
1052 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1053 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001054 SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
1055 m_nFormControlIndex, array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001056 }
Tom Sepez16999822018-06-08 18:23:05 +00001057 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001058}
1059
Dan Sinclairf7435522018-02-05 22:27:22 +00001060CJS_Return CJS_Field::get_default_style(CJS_Runtime* pRuntime) {
Tom Sepez16999822018-06-08 18:23:05 +00001061 return CJS_Return(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001062}
1063
Dan Sinclairf7435522018-02-05 22:27:22 +00001064CJS_Return CJS_Field::set_default_style(CJS_Runtime* pRuntime,
1065 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001066 return CJS_Return(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001067}
1068
Dan Sinclairf7435522018-02-05 22:27:22 +00001069CJS_Return CJS_Field::get_default_value(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001070 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001071
Lei Zhang4c7ad662018-07-12 20:29:40 +00001072 CPDF_FormField* pFormField = GetFirstFormField();
1073 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001074 return CJS_Return(JSMessage::kBadObjectError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001075
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001076 if (pFormField->GetFieldType() == FormFieldType::kPushButton ||
1077 pFormField->GetFieldType() == FormFieldType::kSignature) {
Tom Sepez16999822018-06-08 18:23:05 +00001078 return CJS_Return(JSMessage::kObjectTypeError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001079 }
1080
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001081 return CJS_Return(
1082 pRuntime->NewString(pFormField->GetDefaultValue().AsStringView()));
Dan Sinclair8f524d62017-10-25 13:30:31 -04001083}
1084
Dan Sinclairf7435522018-02-05 22:27:22 +00001085CJS_Return CJS_Field::set_default_value(CJS_Runtime* pRuntime,
1086 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001087 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001088 if (!m_bCanSet)
1089 return CJS_Return(JSMessage::kReadOnlyError);
1090 return CJS_Return();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001091}
1092
Dan Sinclairf7435522018-02-05 22:27:22 +00001093CJS_Return CJS_Field::get_do_not_scroll(CJS_Runtime* pRuntime) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001094 ASSERT(m_pFormFillEnv);
1095
Lei Zhang4c7ad662018-07-12 20:29:40 +00001096 CPDF_FormField* pFormField = GetFirstFormField();
1097 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001098 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001099
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001100 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +00001101 return CJS_Return(JSMessage::kObjectTypeError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001102
Dan Sinclair8f524d62017-10-25 13:30:31 -04001103 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001104 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001105}
1106
Dan Sinclairf7435522018-02-05 22:27:22 +00001107CJS_Return CJS_Field::set_do_not_scroll(CJS_Runtime* pRuntime,
1108 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001109 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001110 if (!m_bCanSet)
1111 return CJS_Return(JSMessage::kReadOnlyError);
1112 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001113}
1114
Dan Sinclairf7435522018-02-05 22:27:22 +00001115CJS_Return CJS_Field::get_do_not_spell_check(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001116 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001117
Lei Zhang4c7ad662018-07-12 20:29:40 +00001118 CPDF_FormField* pFormField = GetFirstFormField();
1119 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001120 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001121
Lei Zhang83f2d702018-07-12 19:07:40 +00001122 if (!IsComboBoxOrTextField(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +00001123 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001124
Dan Sinclair8f524d62017-10-25 13:30:31 -04001125 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001126 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001127}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001128
Dan Sinclairf7435522018-02-05 22:27:22 +00001129CJS_Return CJS_Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
1130 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001131 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001132 if (!m_bCanSet)
1133 return CJS_Return(JSMessage::kReadOnlyError);
1134 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001135}
1136
Dan Sinclairf7435522018-02-05 22:27:22 +00001137void CJS_Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001138 m_bDelay = bDelay;
1139
dan sinclaircbe23db2017-10-19 14:29:33 -04001140 if (m_bDelay)
1141 return;
dan sinclaircbe23db2017-10-19 14:29:33 -04001142 if (m_pJSDoc)
1143 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001144}
1145
Dan Sinclairf7435522018-02-05 22:27:22 +00001146CJS_Return CJS_Field::get_delay(CJS_Runtime* pRuntime) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001147 return CJS_Return(pRuntime->NewBoolean(m_bDelay));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001148}
1149
Dan Sinclairf7435522018-02-05 22:27:22 +00001150CJS_Return CJS_Field::set_delay(CJS_Runtime* pRuntime,
1151 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001152 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001153 return CJS_Return(JSMessage::kReadOnlyError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001154
dan sinclair80435cb2017-10-24 21:40:24 -04001155 SetDelay(pRuntime->ToBoolean(vp));
Tom Sepez16999822018-06-08 18:23:05 +00001156 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001157}
1158
Dan Sinclairf7435522018-02-05 22:27:22 +00001159CJS_Return CJS_Field::get_display(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001160 CPDF_FormField* pFormField = GetFirstFormField();
1161 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001162 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001163
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001164 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1165 CPDFSDK_Widget* pWidget =
1166 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1167 if (!pWidget)
Tom Sepez16999822018-06-08 18:23:05 +00001168 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001169
1170 uint32_t dwFlag = pWidget->GetFlags();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001171 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
1172 return CJS_Return(pRuntime->NewNumber(1));
1173
dan sinclaircbe23db2017-10-19 14:29:33 -04001174 if (ANNOTFLAG_PRINT & dwFlag) {
1175 if (ANNOTFLAG_NOVIEW & dwFlag)
Dan Sinclair8f524d62017-10-25 13:30:31 -04001176 return CJS_Return(pRuntime->NewNumber(3));
1177 return CJS_Return(pRuntime->NewNumber(0));
dan sinclaircbe23db2017-10-19 14:29:33 -04001178 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001179 return CJS_Return(pRuntime->NewNumber(2));
dan sinclaircbe23db2017-10-19 14:29:33 -04001180}
1181
Dan Sinclairf7435522018-02-05 22:27:22 +00001182CJS_Return CJS_Field::set_display(CJS_Runtime* pRuntime,
1183 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001184 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001185 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001186
1187 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001188 AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001189 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001190 SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1191 pRuntime->ToInt32(vp));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001192 }
Tom Sepez16999822018-06-08 18:23:05 +00001193 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001194}
1195
Dan Sinclairf7435522018-02-05 22:27:22 +00001196CJS_Return CJS_Field::get_doc(CJS_Runtime* pRuntime) {
1197 return CJS_Return(m_pJSDoc->ToV8Object());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001198}
1199
Dan Sinclairf7435522018-02-05 22:27:22 +00001200CJS_Return CJS_Field::set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001201 return CJS_Return(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001202}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203
Dan Sinclairf7435522018-02-05 22:27:22 +00001204CJS_Return CJS_Field::get_editable(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001205 CPDF_FormField* pFormField = GetFirstFormField();
1206 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001207 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001208
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001209 if (pFormField->GetFieldType() != FormFieldType::kComboBox)
Tom Sepez16999822018-06-08 18:23:05 +00001210 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001211
Dan Sinclair8f524d62017-10-25 13:30:31 -04001212 return CJS_Return(
Dan Sinclaire4974922017-10-24 09:36:16 -04001213 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001214}
1215
Dan Sinclairf7435522018-02-05 22:27:22 +00001216CJS_Return CJS_Field::set_editable(CJS_Runtime* pRuntime,
1217 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001218 if (!m_bCanSet)
1219 return CJS_Return(JSMessage::kReadOnlyError);
1220 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001221}
1222
Dan Sinclairf7435522018-02-05 22:27:22 +00001223CJS_Return CJS_Field::get_export_values(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001224 CPDF_FormField* pFormField = GetFirstFormField();
1225 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001226 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001227
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001228 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +00001229 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001230
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001231 v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001232 if (m_nFormControlIndex < 0) {
1233 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1234 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001235 pRuntime->PutArrayElement(
1236 ExportValuesArray, i,
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001237 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001238 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001239 } else {
1240 if (m_nFormControlIndex >= pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00001241 return CJS_Return(JSMessage::kValueError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001242
1243 CPDF_FormControl* pFormControl =
1244 pFormField->GetControl(m_nFormControlIndex);
1245 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001246 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001247
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001248 pRuntime->PutArrayElement(
1249 ExportValuesArray, 0,
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001250 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001251 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001252 return CJS_Return(ExportValuesArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001253}
1254
Dan Sinclairf7435522018-02-05 22:27:22 +00001255CJS_Return CJS_Field::set_export_values(CJS_Runtime* pRuntime,
1256 v8::Local<v8::Value> vp) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001257 CPDF_FormField* pFormField = GetFirstFormField();
1258 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001259 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001260
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001261 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +00001262 return CJS_Return(JSMessage::kObjectTypeError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001263
Tom Sepez16999822018-06-08 18:23:05 +00001264 if (!m_bCanSet)
1265 return CJS_Return(JSMessage::kReadOnlyError);
1266
1267 if (vp.IsEmpty() || !vp->IsArray())
1268 return CJS_Return(JSMessage::kBadObjectError);
1269
1270 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001271}
1272
Dan Sinclairf7435522018-02-05 22:27:22 +00001273CJS_Return CJS_Field::get_file_select(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001274 CPDF_FormField* pFormField = GetFirstFormField();
1275 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001276 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001277
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001278 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +00001279 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001280
Dan Sinclair8f524d62017-10-25 13:30:31 -04001281 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001282 !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001283}
1284
Dan Sinclairf7435522018-02-05 22:27:22 +00001285CJS_Return CJS_Field::set_file_select(CJS_Runtime* pRuntime,
1286 v8::Local<v8::Value> vp) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001287 CPDF_FormField* pFormField = GetFirstFormField();
1288 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001289 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001290
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001291 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +00001292 return CJS_Return(JSMessage::kObjectTypeError);
1293
1294 if (!m_bCanSet)
1295 return CJS_Return(JSMessage::kReadOnlyError);
1296
1297 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001298}
1299
Dan Sinclairf7435522018-02-05 22:27:22 +00001300CJS_Return CJS_Field::get_fill_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001301 CPDF_FormField* pFormField = GetFirstFormField();
1302 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001303 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001304
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001305 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1306 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001307 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001308
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001309 int iColorType;
1310 pFormControl->GetBackgroundColor(iColorType);
1311
Dan Sinclair7f55a542017-07-13 14:17:10 -04001312 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001313 if (iColorType == CFX_Color::kTransparent) {
1314 color = CFX_Color(CFX_Color::kTransparent);
1315 } else if (iColorType == CFX_Color::kGray) {
1316 color = CFX_Color(CFX_Color::kGray,
1317 pFormControl->GetOriginalBackgroundColor(0));
1318 } else if (iColorType == CFX_Color::kRGB) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001319 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001320 CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001321 pFormControl->GetOriginalBackgroundColor(1),
1322 pFormControl->GetOriginalBackgroundColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001323 } else if (iColorType == CFX_Color::kCMYK) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001324 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001325 CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001326 pFormControl->GetOriginalBackgroundColor(1),
1327 pFormControl->GetOriginalBackgroundColor(2),
1328 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001329 } else {
Tom Sepez16999822018-06-08 18:23:05 +00001330 return CJS_Return(JSMessage::kValueError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001331 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001332
Dan Sinclairf7435522018-02-05 22:27:22 +00001333 v8::Local<v8::Value> array =
1334 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001335 if (array.IsEmpty())
Dan Sinclair8f524d62017-10-25 13:30:31 -04001336 return CJS_Return(pRuntime->NewArray());
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001337 return CJS_Return(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001338}
1339
Dan Sinclairf7435522018-02-05 22:27:22 +00001340CJS_Return CJS_Field::set_fill_color(CJS_Runtime* pRuntime,
1341 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001342 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001343 if (FieldArray.empty())
Tom Sepez16999822018-06-08 18:23:05 +00001344 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001345 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001346 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001347 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez16999822018-06-08 18:23:05 +00001348 return CJS_Return(JSMessage::kBadObjectError);
1349 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001350}
1351
Dan Sinclairf7435522018-02-05 22:27:22 +00001352CJS_Return CJS_Field::get_hidden(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001353 CPDF_FormField* pFormField = GetFirstFormField();
1354 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001355 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001356
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001357 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1358 CPDFSDK_Widget* pWidget =
1359 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1360 if (!pWidget)
Tom Sepez16999822018-06-08 18:23:05 +00001361 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001362
1363 uint32_t dwFlags = pWidget->GetFlags();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001364 return CJS_Return(pRuntime->NewBoolean(ANNOTFLAG_INVISIBLE & dwFlags ||
1365 ANNOTFLAG_HIDDEN & dwFlags));
dan sinclaircbe23db2017-10-19 14:29:33 -04001366}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001367
Dan Sinclairf7435522018-02-05 22:27:22 +00001368CJS_Return CJS_Field::set_hidden(CJS_Runtime* pRuntime,
1369 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001370 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001371 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001372
1373 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001374 AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001375 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001376 SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1377 pRuntime->ToBoolean(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001378 }
Tom Sepez16999822018-06-08 18:23:05 +00001379 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001380}
1381
Dan Sinclairf7435522018-02-05 22:27:22 +00001382CJS_Return CJS_Field::get_highlight(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001383 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001384
Lei Zhang4c7ad662018-07-12 20:29:40 +00001385 CPDF_FormField* pFormField = GetFirstFormField();
1386 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001387 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001388
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001389 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +00001390 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001391
1392 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1393 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001394 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001395
1396 int eHM = pFormControl->GetHighlightingMode();
1397 switch (eHM) {
1398 case CPDF_FormControl::None:
Dan Sinclair8f524d62017-10-25 13:30:31 -04001399 return CJS_Return(pRuntime->NewString(L"none"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001400 case CPDF_FormControl::Push:
Dan Sinclair8f524d62017-10-25 13:30:31 -04001401 return CJS_Return(pRuntime->NewString(L"push"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001402 case CPDF_FormControl::Invert:
Dan Sinclair8f524d62017-10-25 13:30:31 -04001403 return CJS_Return(pRuntime->NewString(L"invert"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001404 case CPDF_FormControl::Outline:
Dan Sinclair8f524d62017-10-25 13:30:31 -04001405 return CJS_Return(pRuntime->NewString(L"outline"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001406 case CPDF_FormControl::Toggle:
Dan Sinclair8f524d62017-10-25 13:30:31 -04001407 return CJS_Return(pRuntime->NewString(L"toggle"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001408 }
Tom Sepez16999822018-06-08 18:23:05 +00001409 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001410}
1411
Dan Sinclairf7435522018-02-05 22:27:22 +00001412CJS_Return CJS_Field::set_highlight(CJS_Runtime* pRuntime,
1413 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001414 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001415 if (!m_bCanSet)
1416 return CJS_Return(JSMessage::kReadOnlyError);
1417 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418}
1419
Dan Sinclairf7435522018-02-05 22:27:22 +00001420CJS_Return CJS_Field::get_line_width(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001421 CPDF_FormField* pFormField = GetFirstFormField();
1422 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001423 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001424
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001425 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1426 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001427 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001428
1429 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1430 if (!pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00001431 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001432
1433 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1434 if (!pWidget)
Tom Sepez16999822018-06-08 18:23:05 +00001435 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001436
Dan Sinclair8f524d62017-10-25 13:30:31 -04001437 return CJS_Return(pRuntime->NewNumber(pWidget->GetBorderWidth()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001438}
1439
Dan Sinclairf7435522018-02-05 22:27:22 +00001440CJS_Return CJS_Field::set_line_width(CJS_Runtime* pRuntime,
1441 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001442 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001443 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001444
1445 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001446 AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001447 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001448 SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1449 pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001450 }
Tom Sepez16999822018-06-08 18:23:05 +00001451 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001452}
1453
Dan Sinclairf7435522018-02-05 22:27:22 +00001454CJS_Return CJS_Field::get_multiline(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001455 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001456
Lei Zhang4c7ad662018-07-12 20:29:40 +00001457 CPDF_FormField* pFormField = GetFirstFormField();
1458 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001459 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001460
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001461 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +00001462 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001463
Dan Sinclair8f524d62017-10-25 13:30:31 -04001464 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001465 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001466}
1467
Dan Sinclairf7435522018-02-05 22:27:22 +00001468CJS_Return CJS_Field::set_multiline(CJS_Runtime* pRuntime,
1469 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001470 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001471 if (!m_bCanSet)
1472 return CJS_Return(JSMessage::kReadOnlyError);
1473 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001474}
1475
Dan Sinclairf7435522018-02-05 22:27:22 +00001476CJS_Return CJS_Field::get_multiple_selection(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001477 ASSERT(m_pFormFillEnv);
Lei Zhang4c7ad662018-07-12 20:29:40 +00001478 CPDF_FormField* pFormField = GetFirstFormField();
1479 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001480 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001481
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001482 if (pFormField->GetFieldType() != FormFieldType::kListBox)
Tom Sepez16999822018-06-08 18:23:05 +00001483 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001484
Dan Sinclair8f524d62017-10-25 13:30:31 -04001485 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001486 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001487}
1488
Dan Sinclairf7435522018-02-05 22:27:22 +00001489CJS_Return CJS_Field::set_multiple_selection(CJS_Runtime* pRuntime,
1490 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001491 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001492 if (!m_bCanSet)
1493 return CJS_Return(JSMessage::kReadOnlyError);
1494 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001495}
1496
Dan Sinclairf7435522018-02-05 22:27:22 +00001497CJS_Return CJS_Field::get_name(CJS_Runtime* pRuntime) {
Lei Zhang18915232018-07-12 20:53:40 +00001498 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08001499 if (FieldArray.empty())
Tom Sepez16999822018-06-08 18:23:05 +00001500 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001501
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001502 return CJS_Return(pRuntime->NewString(m_FieldName.AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001503}
1504
Dan Sinclairf7435522018-02-05 22:27:22 +00001505CJS_Return CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001506 return CJS_Return(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001507}
Tom Sepez67fd5df2015-10-08 12:24:19 -07001508
Dan Sinclairf7435522018-02-05 22:27:22 +00001509CJS_Return CJS_Field::get_num_items(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001510 CPDF_FormField* pFormField = GetFirstFormField();
1511 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001512 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001513
Lei Zhang83f2d702018-07-12 19:07:40 +00001514 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +00001515 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001516
Dan Sinclair8f524d62017-10-25 13:30:31 -04001517 return CJS_Return(pRuntime->NewNumber(pFormField->CountOptions()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001518}
1519
Dan Sinclairf7435522018-02-05 22:27:22 +00001520CJS_Return CJS_Field::set_num_items(CJS_Runtime* pRuntime,
1521 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001522 return CJS_Return(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001523}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001524
Dan Sinclairf7435522018-02-05 22:27:22 +00001525CJS_Return CJS_Field::get_page(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001526 CPDF_FormField* pFormField = GetFirstFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001527 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001528 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529
tsepez8fa82792017-01-11 09:32:33 -08001530 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001531 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001532 if (widgets.empty())
1533 return CJS_Return(pRuntime->NewNumber(-1));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001534
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001535 v8::Local<v8::Array> PageArray = pRuntime->NewArray();
tsepez8fa82792017-01-11 09:32:33 -08001536 int i = 0;
1537 for (const auto& pObserved : widgets) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001538 if (!pObserved)
Tom Sepez16999822018-06-08 18:23:05 +00001539 return CJS_Return(JSMessage::kBadObjectError);
tsepez8fa82792017-01-11 09:32:33 -08001540
Tom Sepez4ef943b2018-07-26 19:06:06 +00001541 auto* pWidget = ToCPDFSDKWidget(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001542 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001543 if (!pPageView)
Tom Sepez16999822018-06-08 18:23:05 +00001544 return CJS_Return(JSMessage::kBadObjectError);
Lei Zhangd88a3642015-11-10 09:38:57 -08001545
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001546 pRuntime->PutArrayElement(
1547 PageArray, i,
dan sinclair80435cb2017-10-24 21:40:24 -04001548 pRuntime->NewNumber(static_cast<int32_t>(pPageView->GetPageIndex())));
tsepez8fa82792017-01-11 09:32:33 -08001549 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001550 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001551 return CJS_Return(PageArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552}
1553
Dan Sinclairf7435522018-02-05 22:27:22 +00001554CJS_Return CJS_Field::set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001555 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001556}
1557
Dan Sinclairf7435522018-02-05 22:27:22 +00001558CJS_Return CJS_Field::get_password(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001559 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001560
Lei Zhang4c7ad662018-07-12 20:29:40 +00001561 CPDF_FormField* pFormField = GetFirstFormField();
1562 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001563 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001564
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001565 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +00001566 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001567
Dan Sinclair8f524d62017-10-25 13:30:31 -04001568 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001569 !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001570}
1571
Dan Sinclairf7435522018-02-05 22:27:22 +00001572CJS_Return CJS_Field::set_password(CJS_Runtime* pRuntime,
1573 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001574 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001575 if (!m_bCanSet)
1576 return CJS_Return(JSMessage::kReadOnlyError);
1577 return CJS_Return();
dan sinclair646634b2017-10-19 14:30:28 -04001578}
dan sinclaircbe23db2017-10-19 14:29:33 -04001579
Dan Sinclairf7435522018-02-05 22:27:22 +00001580CJS_Return CJS_Field::get_print(CJS_Runtime* pRuntime) {
dan sinclair646634b2017-10-19 14:30:28 -04001581 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhang4c7ad662018-07-12 20:29:40 +00001582 CPDF_FormField* pFormField = GetFirstFormField();
1583 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001584 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001585
dan sinclair646634b2017-10-19 14:30:28 -04001586 CPDFSDK_Widget* pWidget =
1587 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1588 if (!pWidget)
Tom Sepez16999822018-06-08 18:23:05 +00001589 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001590
Dan Sinclair8f524d62017-10-25 13:30:31 -04001591 return CJS_Return(
1592 pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001593}
1594
Dan Sinclairf7435522018-02-05 22:27:22 +00001595CJS_Return CJS_Field::set_print(CJS_Runtime* pRuntime,
1596 v8::Local<v8::Value> vp) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001597 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhang18915232018-07-12 20:53:40 +00001598 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08001599 if (FieldArray.empty())
Tom Sepez16999822018-06-08 18:23:05 +00001600 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001601
Dan Sinclair8f524d62017-10-25 13:30:31 -04001602 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001603 return CJS_Return(JSMessage::kReadOnlyError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001604
Dan Sinclair8f524d62017-10-25 13:30:31 -04001605 for (CPDF_FormField* pFormField : FieldArray) {
1606 if (m_nFormControlIndex < 0) {
1607 bool bSet = false;
1608 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1609 if (CPDFSDK_Widget* pWidget =
1610 pInterForm->GetWidget(pFormField->GetControl(i))) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001611 uint32_t dwFlags = pWidget->GetFlags();
dan sinclair80435cb2017-10-24 21:40:24 -04001612 if (pRuntime->ToBoolean(vp))
dan sinclaircbe23db2017-10-19 14:29:33 -04001613 dwFlags |= ANNOTFLAG_PRINT;
1614 else
1615 dwFlags &= ~ANNOTFLAG_PRINT;
1616
1617 if (dwFlags != pWidget->GetFlags()) {
1618 pWidget->SetFlags(dwFlags);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001619 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001620 }
1621 }
1622 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001623
1624 if (bSet)
1625 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
1626
1627 continue;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001628 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001629
1630 if (m_nFormControlIndex >= pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00001631 return CJS_Return(JSMessage::kValueError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001632
1633 if (CPDF_FormControl* pFormControl =
1634 pFormField->GetControl(m_nFormControlIndex)) {
1635 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1636 uint32_t dwFlags = pWidget->GetFlags();
1637 if (pRuntime->ToBoolean(vp))
1638 dwFlags |= ANNOTFLAG_PRINT;
1639 else
1640 dwFlags &= ~ANNOTFLAG_PRINT;
1641
1642 if (dwFlags != pWidget->GetFlags()) {
1643 pWidget->SetFlags(dwFlags);
1644 UpdateFormControl(m_pFormFillEnv.Get(),
1645 pFormField->GetControl(m_nFormControlIndex), true,
1646 false, true);
1647 }
1648 }
1649 }
1650 }
Tom Sepez16999822018-06-08 18:23:05 +00001651 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001652}
1653
Dan Sinclairf7435522018-02-05 22:27:22 +00001654CJS_Return CJS_Field::get_radios_in_unison(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001655 CPDF_FormField* pFormField = GetFirstFormField();
1656 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001657 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001658
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001659 if (pFormField->GetFieldType() != FormFieldType::kRadioButton)
Tom Sepez16999822018-06-08 18:23:05 +00001660 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001661
Dan Sinclair8f524d62017-10-25 13:30:31 -04001662 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001663 !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001664}
1665
Dan Sinclairf7435522018-02-05 22:27:22 +00001666CJS_Return CJS_Field::set_radios_in_unison(CJS_Runtime* pRuntime,
1667 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001668 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001669 if (FieldArray.empty())
Tom Sepez16999822018-06-08 18:23:05 +00001670 return CJS_Return(JSMessage::kBadObjectError);
1671 if (!m_bCanSet)
1672 return CJS_Return(JSMessage::kReadOnlyError);
1673 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001674}
1675
Dan Sinclairf7435522018-02-05 22:27:22 +00001676CJS_Return CJS_Field::get_readonly(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001677 CPDF_FormField* pFormField = GetFirstFormField();
1678 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001679 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001680
Dan Sinclair8f524d62017-10-25 13:30:31 -04001681 return CJS_Return(pRuntime->NewBoolean(
Lei Zhang4c7ad662018-07-12 20:29:40 +00001682 !!(pFormField->GetFieldFlags() & FIELDFLAG_READONLY)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001683}
1684
Dan Sinclairf7435522018-02-05 22:27:22 +00001685CJS_Return CJS_Field::set_readonly(CJS_Runtime* pRuntime,
1686 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001687 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001688 if (FieldArray.empty())
Tom Sepez16999822018-06-08 18:23:05 +00001689 return CJS_Return(JSMessage::kBadObjectError);
1690 if (!m_bCanSet)
1691 return CJS_Return(JSMessage::kReadOnlyError);
1692 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001693}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001694
Dan Sinclairf7435522018-02-05 22:27:22 +00001695CJS_Return CJS_Field::get_rect(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001696 CPDF_FormField* pFormField = GetFirstFormField();
1697 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001698 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001699
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001700 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1701 CPDFSDK_Widget* pWidget =
1702 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1703 if (!pWidget)
Tom Sepez16999822018-06-08 18:23:05 +00001704 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001705
1706 CFX_FloatRect crRect = pWidget->GetRect();
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001707 v8::Local<v8::Array> rcArray = pRuntime->NewArray();
1708 pRuntime->PutArrayElement(
1709 rcArray, 0, pRuntime->NewNumber(static_cast<int32_t>(crRect.left)));
1710 pRuntime->PutArrayElement(
1711 rcArray, 1, pRuntime->NewNumber(static_cast<int32_t>(crRect.top)));
1712 pRuntime->PutArrayElement(
1713 rcArray, 2, pRuntime->NewNumber(static_cast<int32_t>(crRect.right)));
1714 pRuntime->PutArrayElement(
1715 rcArray, 3, pRuntime->NewNumber(static_cast<int32_t>(crRect.bottom)));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001716
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001717 return CJS_Return(rcArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001718}
1719
Dan Sinclairf7435522018-02-05 22:27:22 +00001720CJS_Return CJS_Field::set_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001721 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001722 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001723 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez16999822018-06-08 18:23:05 +00001724 return CJS_Return(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001725
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001726 v8::Local<v8::Array> rcArray = pRuntime->ToArray(vp);
1727 if (pRuntime->GetArrayLength(rcArray) < 4)
Tom Sepez16999822018-06-08 18:23:05 +00001728 return CJS_Return(JSMessage::kValueError);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001729
dan sinclaircbe23db2017-10-19 14:29:33 -04001730 float pArray[4];
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001731 pArray[0] = static_cast<float>(
1732 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 0)));
1733 pArray[1] = static_cast<float>(
1734 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 1)));
1735 pArray[2] = static_cast<float>(
1736 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 2)));
1737 pArray[3] = static_cast<float>(
1738 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 3)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001739
1740 CFX_FloatRect crRect(pArray);
1741 if (m_bDelay) {
1742 AddDelay_Rect(FP_RECT, crRect);
1743 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001744 SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, crRect);
dan sinclaircbe23db2017-10-19 14:29:33 -04001745 }
Tom Sepez16999822018-06-08 18:23:05 +00001746 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001747}
1748
Dan Sinclairf7435522018-02-05 22:27:22 +00001749CJS_Return CJS_Field::get_required(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001750 CPDF_FormField* pFormField = GetFirstFormField();
1751 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001752 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001753
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001754 if (pFormField->GetFieldType() == FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +00001755 return CJS_Return(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001756
Dan Sinclair8f524d62017-10-25 13:30:31 -04001757 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001758 !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001759}
1760
Dan Sinclairf7435522018-02-05 22:27:22 +00001761CJS_Return CJS_Field::set_required(CJS_Runtime* pRuntime,
1762 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001763 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001764 if (FieldArray.empty())
Tom Sepez16999822018-06-08 18:23:05 +00001765 return CJS_Return(JSMessage::kBadObjectError);
1766 if (!m_bCanSet)
1767 return CJS_Return(JSMessage::kReadOnlyError);
1768 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001769}
1770
Dan Sinclairf7435522018-02-05 22:27:22 +00001771CJS_Return CJS_Field::get_rich_text(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001772 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001773
Lei Zhang4c7ad662018-07-12 20:29:40 +00001774 CPDF_FormField* pFormField = GetFirstFormField();
1775 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001776 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001777
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001778 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez16999822018-06-08 18:23:05 +00001779 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001780
Dan Sinclair8f524d62017-10-25 13:30:31 -04001781 return CJS_Return(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001782 !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001783}
1784
Dan Sinclairf7435522018-02-05 22:27:22 +00001785CJS_Return CJS_Field::set_rich_text(CJS_Runtime* pRuntime,
1786 v8::Local<v8::Value> vp) {
dsinclair3a7741a2016-10-11 10:39:49 -07001787 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001788 if (!m_bCanSet)
1789 return CJS_Return(JSMessage::kReadOnlyError);
1790 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001791}
1792
Dan Sinclairf7435522018-02-05 22:27:22 +00001793CJS_Return CJS_Field::get_rich_value(CJS_Runtime* pRuntime) {
Tom Sepez16999822018-06-08 18:23:05 +00001794 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001795}
1796
Dan Sinclairf7435522018-02-05 22:27:22 +00001797CJS_Return CJS_Field::set_rich_value(CJS_Runtime* pRuntime,
1798 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001799 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001800}
1801
Dan Sinclairf7435522018-02-05 22:27:22 +00001802CJS_Return CJS_Field::get_rotation(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001803 ASSERT(m_pFormFillEnv);
1804
Lei Zhang4c7ad662018-07-12 20:29:40 +00001805 CPDF_FormField* pFormField = GetFirstFormField();
1806 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001807 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001808
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001809 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1810 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001811 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001812
Dan Sinclair8f524d62017-10-25 13:30:31 -04001813 return CJS_Return(pRuntime->NewNumber(pFormControl->GetRotation()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001814}
1815
Dan Sinclairf7435522018-02-05 22:27:22 +00001816CJS_Return CJS_Field::set_rotation(CJS_Runtime* pRuntime,
1817 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001818 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001819 if (!m_bCanSet)
1820 return CJS_Return(JSMessage::kReadOnlyError);
1821 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001822}
1823
Dan Sinclairf7435522018-02-05 22:27:22 +00001824CJS_Return CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001825 CPDF_FormField* pFormField = GetFirstFormField();
1826 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001827 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001828
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001829 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1830 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001831 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001832
1833 int iColorType;
1834 pFormControl->GetBorderColor(iColorType);
1835
Dan Sinclair7f55a542017-07-13 14:17:10 -04001836 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001837 if (iColorType == CFX_Color::kTransparent) {
1838 color = CFX_Color(CFX_Color::kTransparent);
1839 } else if (iColorType == CFX_Color::kGray) {
1840 color =
1841 CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0));
1842 } else if (iColorType == CFX_Color::kRGB) {
1843 color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001844 pFormControl->GetOriginalBorderColor(1),
1845 pFormControl->GetOriginalBorderColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001846 } else if (iColorType == CFX_Color::kCMYK) {
1847 color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001848 pFormControl->GetOriginalBorderColor(1),
1849 pFormControl->GetOriginalBorderColor(2),
1850 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001851 } else {
Tom Sepez16999822018-06-08 18:23:05 +00001852 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001853 }
1854
Dan Sinclairf7435522018-02-05 22:27:22 +00001855 v8::Local<v8::Value> array =
1856 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001857 if (array.IsEmpty())
Dan Sinclair8f524d62017-10-25 13:30:31 -04001858 return CJS_Return(pRuntime->NewArray());
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001859 return CJS_Return(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001860}
1861
Dan Sinclairf7435522018-02-05 22:27:22 +00001862CJS_Return CJS_Field::set_stroke_color(CJS_Runtime* pRuntime,
1863 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001864 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001865 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001866 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez16999822018-06-08 18:23:05 +00001867 return CJS_Return(JSMessage::kBadObjectError);
1868 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001869}
1870
Dan Sinclairf7435522018-02-05 22:27:22 +00001871CJS_Return CJS_Field::get_style(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001872 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001873
Lei Zhang4c7ad662018-07-12 20:29:40 +00001874 CPDF_FormField* pFormField = GetFirstFormField();
1875 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001876 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001877
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001878 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +00001879 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001880
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001881 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1882 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001883 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001884
Ryan Harrison275e2602017-09-18 14:23:18 -04001885 WideString csWCaption = pFormControl->GetNormalCaption();
1886 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001887
1888 switch (csWCaption[0]) {
1889 case L'l':
1890 csBCaption = "circle";
1891 break;
1892 case L'8':
1893 csBCaption = "cross";
1894 break;
1895 case L'u':
1896 csBCaption = "diamond";
1897 break;
1898 case L'n':
1899 csBCaption = "square";
1900 break;
1901 case L'H':
1902 csBCaption = "star";
1903 break;
1904 default: // L'4'
1905 csBCaption = "check";
1906 break;
1907 }
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001908 return CJS_Return(pRuntime->NewString(
1909 WideString::FromLocal(csBCaption.AsStringView()).AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001910}
1911
Dan Sinclairf7435522018-02-05 22:27:22 +00001912CJS_Return CJS_Field::set_style(CJS_Runtime* pRuntime,
1913 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001914 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001915 if (!m_bCanSet)
1916 return CJS_Return(JSMessage::kReadOnlyError);
1917 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001918}
1919
Dan Sinclairf7435522018-02-05 22:27:22 +00001920CJS_Return CJS_Field::get_submit_name(CJS_Runtime* pRuntime) {
Tom Sepez16999822018-06-08 18:23:05 +00001921 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001922}
1923
Dan Sinclairf7435522018-02-05 22:27:22 +00001924CJS_Return CJS_Field::set_submit_name(CJS_Runtime* pRuntime,
1925 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001926 return CJS_Return();
dan sinclaircbe23db2017-10-19 14:29:33 -04001927}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001928
Dan Sinclairf7435522018-02-05 22:27:22 +00001929CJS_Return CJS_Field::get_text_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001930 CPDF_FormField* pFormField = GetFirstFormField();
1931 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001932 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001933
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001934 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1935 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001936 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001937
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001938 Optional<CFX_Color::Type> iColorType;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001939 FX_ARGB color;
1940 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
Dan Sinclaira17a0e22018-03-28 21:10:35 +00001941 std::tie(iColorType, color) = FieldAppearance.GetColor();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001942
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001943 CFX_Color crRet;
1944 if (!iColorType || *iColorType == CFX_Color::kTransparent) {
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001945 crRet = CFX_Color(CFX_Color::kTransparent);
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001946 } else {
1947 int32_t a;
1948 int32_t r;
1949 int32_t g;
1950 int32_t b;
1951 std::tie(a, r, g, b) = ArgbDecode(color);
1952 crRet = CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
1953 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001954
Dan Sinclairf7435522018-02-05 22:27:22 +00001955 v8::Local<v8::Value> array =
1956 CJS_Color::ConvertPWLColorToArray(pRuntime, crRet);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001957 if (array.IsEmpty())
Dan Sinclair8f524d62017-10-25 13:30:31 -04001958 return CJS_Return(pRuntime->NewArray());
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001959 return CJS_Return(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001960}
1961
Dan Sinclairf7435522018-02-05 22:27:22 +00001962CJS_Return CJS_Field::set_text_color(CJS_Runtime* pRuntime,
1963 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001964 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00001965 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001966 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez16999822018-06-08 18:23:05 +00001967 return CJS_Return(JSMessage::kBadObjectError);
1968 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001969}
1970
Dan Sinclairf7435522018-02-05 22:27:22 +00001971CJS_Return CJS_Field::get_text_font(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001972 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001973
Lei Zhang4c7ad662018-07-12 20:29:40 +00001974 CPDF_FormField* pFormField = GetFirstFormField();
1975 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00001976 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001977
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001978 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1979 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00001980 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001981
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001982 FormFieldType fieldType = pFormField->GetFieldType();
1983 if (fieldType != FormFieldType::kPushButton &&
1984 fieldType != FormFieldType::kComboBox &&
1985 fieldType != FormFieldType::kListBox &&
1986 fieldType != FormFieldType::kTextField) {
Tom Sepez16999822018-06-08 18:23:05 +00001987 return CJS_Return(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001988 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001989
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001990 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
1991 if (!pFont)
Tom Sepez16999822018-06-08 18:23:05 +00001992 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001993
Dan Sinclair8f524d62017-10-25 13:30:31 -04001994 return CJS_Return(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001995 WideString::FromLocal(pFont->GetBaseFont().AsStringView())
1996 .AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001997}
1998
Dan Sinclairf7435522018-02-05 22:27:22 +00001999CJS_Return CJS_Field::set_text_font(CJS_Runtime* pRuntime,
2000 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002001 ASSERT(m_pFormFillEnv);
2002
dan sinclair646634b2017-10-19 14:30:28 -04002003 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00002004 return CJS_Return(JSMessage::kReadOnlyError);
Tom Sepez34dab072018-08-08 17:49:02 +00002005 if (pRuntime->ToWideString(vp).ToDefANSI().IsEmpty())
Tom Sepez16999822018-06-08 18:23:05 +00002006 return CJS_Return(JSMessage::kValueError);
2007 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002008}
2009
Dan Sinclairf7435522018-02-05 22:27:22 +00002010CJS_Return CJS_Field::get_text_size(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07002011 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002012
Lei Zhang4c7ad662018-07-12 20:29:40 +00002013 CPDF_FormField* pFormField = GetFirstFormField();
2014 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002015 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002016
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002017 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2018 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00002019 return CJS_Return(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002020
Dan Sinclair05df0752017-03-14 14:43:42 -04002021 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002022 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2023 FieldAppearance.GetFont(&fFontSize);
Dan Sinclair8f524d62017-10-25 13:30:31 -04002024 return CJS_Return(pRuntime->NewNumber(static_cast<int>(fFontSize)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002025}
2026
Dan Sinclairf7435522018-02-05 22:27:22 +00002027CJS_Return CJS_Field::set_text_size(CJS_Runtime* pRuntime,
2028 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002029 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00002030 if (!m_bCanSet)
2031 return CJS_Return(JSMessage::kReadOnlyError);
2032 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002033}
2034
Dan Sinclairf7435522018-02-05 22:27:22 +00002035CJS_Return CJS_Field::get_type(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002036 CPDF_FormField* pFormField = GetFirstFormField();
2037 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002038 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002039
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002040 switch (pFormField->GetFieldType()) {
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002041 case FormFieldType::kUnknown:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002042 return CJS_Return(pRuntime->NewString(L"unknown"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002043 case FormFieldType::kPushButton:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002044 return CJS_Return(pRuntime->NewString(L"button"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002045 case FormFieldType::kCheckBox:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002046 return CJS_Return(pRuntime->NewString(L"checkbox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002047 case FormFieldType::kRadioButton:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002048 return CJS_Return(pRuntime->NewString(L"radiobutton"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002049 case FormFieldType::kComboBox:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002050 return CJS_Return(pRuntime->NewString(L"combobox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002051 case FormFieldType::kListBox:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002052 return CJS_Return(pRuntime->NewString(L"listbox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002053 case FormFieldType::kTextField:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002054 return CJS_Return(pRuntime->NewString(L"text"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002055 case FormFieldType::kSignature:
Dan Sinclair8f524d62017-10-25 13:30:31 -04002056 return CJS_Return(pRuntime->NewString(L"signature"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002057 default:
2058 return CJS_Return(pRuntime->NewString(L"unknown"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002059 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002060}
2061
Dan Sinclairf7435522018-02-05 22:27:22 +00002062CJS_Return CJS_Field::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00002063 return CJS_Return(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002064}
2065
Dan Sinclairf7435522018-02-05 22:27:22 +00002066CJS_Return CJS_Field::get_user_name(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07002067 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002068
Lei Zhang4c7ad662018-07-12 20:29:40 +00002069 CPDF_FormField* pFormField = GetFirstFormField();
2070 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002071 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002072
Dan Sinclair8f524d62017-10-25 13:30:31 -04002073 return CJS_Return(
Lei Zhang4c7ad662018-07-12 20:29:40 +00002074 pRuntime->NewString(pFormField->GetAlternateName().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002075}
2076
Dan Sinclairf7435522018-02-05 22:27:22 +00002077CJS_Return CJS_Field::set_user_name(CJS_Runtime* pRuntime,
2078 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002079 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00002080 if (!m_bCanSet)
2081 return CJS_Return(JSMessage::kReadOnlyError);
2082 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002083}
2084
Dan Sinclairf7435522018-02-05 22:27:22 +00002085CJS_Return CJS_Field::get_value(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002086 CPDF_FormField* pFormField = GetFirstFormField();
2087 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002088 return CJS_Return(JSMessage::kBadObjectError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04002089
2090 v8::Local<v8::Value> ret;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002091 switch (pFormField->GetFieldType()) {
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002092 case FormFieldType::kPushButton:
Tom Sepez16999822018-06-08 18:23:05 +00002093 return CJS_Return(JSMessage::kObjectTypeError);
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002094 case FormFieldType::kComboBox:
2095 case FormFieldType::kTextField:
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002096 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
dan sinclaircbe23db2017-10-19 14:29:33 -04002097 break;
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002098 case FormFieldType::kListBox: {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002099 if (pFormField->CountSelectedItems() > 1) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002100 v8::Local<v8::Array> ValueArray = pRuntime->NewArray();
dan sinclair80435cb2017-10-24 21:40:24 -04002101 v8::Local<v8::Value> ElementValue;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002102 int iIndex;
2103 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2104 iIndex = pFormField->GetSelectedIndex(i);
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002105 ElementValue = pRuntime->NewString(
2106 pFormField->GetOptionValue(iIndex).AsStringView());
dan sinclair80435cb2017-10-24 21:40:24 -04002107 if (wcslen(pRuntime->ToWideString(ElementValue).c_str()) == 0) {
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002108 ElementValue = pRuntime->NewString(
2109 pFormField->GetOptionLabel(iIndex).AsStringView());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002110 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002111 pRuntime->PutArrayElement(ValueArray, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002112 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002113 ret = ValueArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002114 } else {
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002115 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002116 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002117 break;
2118 }
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002119 case FormFieldType::kCheckBox:
2120 case FormFieldType::kRadioButton: {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002121 bool bFind = false;
2122 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2123 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002124 ret = pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002125 pFormField->GetControl(i)->GetExportValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002126 bFind = true;
2127 break;
2128 }
2129 }
2130 if (!bFind)
Dan Sinclair8f524d62017-10-25 13:30:31 -04002131 ret = pRuntime->NewString(L"Off");
dan sinclaircbe23db2017-10-19 14:29:33 -04002132
2133 break;
2134 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002135 default:
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002136 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002137 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002138 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04002139 return CJS_Return(pRuntime->MaybeCoerceToNumber(ret));
dan sinclaircbe23db2017-10-19 14:29:33 -04002140}
2141
Dan Sinclairf7435522018-02-05 22:27:22 +00002142CJS_Return CJS_Field::set_value(CJS_Runtime* pRuntime,
2143 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002144 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00002145 return CJS_Return(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002146
2147 std::vector<WideString> strArray;
dan sinclair80435cb2017-10-24 21:40:24 -04002148 if (!vp.IsEmpty() && vp->IsArray()) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002149 v8::Local<v8::Array> ValueArray = pRuntime->ToArray(vp);
2150 for (size_t i = 0; i < pRuntime->GetArrayLength(ValueArray); i++) {
dan sinclair80435cb2017-10-24 21:40:24 -04002151 strArray.push_back(
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002152 pRuntime->ToWideString(pRuntime->GetArrayElement(ValueArray, i)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002153 }
2154 } else {
dan sinclair80435cb2017-10-24 21:40:24 -04002155 strArray.push_back(pRuntime->ToWideString(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04002156 }
2157
2158 if (m_bDelay) {
2159 AddDelay_WideStringArray(FP_VALUE, strArray);
2160 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00002161 SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, strArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04002162 }
Tom Sepez16999822018-06-08 18:23:05 +00002163 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002164}
2165
Dan Sinclairf7435522018-02-05 22:27:22 +00002166CJS_Return CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002167 CPDF_FormField* pFormField = GetFirstFormField();
2168 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002169 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002170
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002171 if (pFormField->GetFieldType() == FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +00002172 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002173
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002174 if (pFormField->GetFieldType() == FormFieldType::kCheckBox) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002175 if (!pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00002176 return CJS_Return(JSMessage::kBadObjectError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04002177 return CJS_Return(pRuntime->NewString(
Dan Sinclaire4974922017-10-24 09:36:16 -04002178 pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002179 }
2180
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002181 if (pFormField->GetFieldType() == FormFieldType::kRadioButton &&
dan sinclaircbe23db2017-10-19 14:29:33 -04002182 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2184 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002185 return CJS_Return(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002186 pFormField->GetControl(i)->GetExportValue().AsStringView()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002187 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002188 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04002189 return CJS_Return(pRuntime->NewString(L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002190 }
2191
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002192 if (pFormField->GetFieldType() == FormFieldType::kListBox &&
dan sinclaircbe23db2017-10-19 14:29:33 -04002193 (pFormField->CountSelectedItems() > 1)) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002194 return CJS_Return(pRuntime->NewString(L""));
Lei Zhangd88a3642015-11-10 09:38:57 -08002195 }
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002196 return CJS_Return(pRuntime->NewString(pFormField->GetValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002197}
2198
Dan Sinclairf7435522018-02-05 22:27:22 +00002199CJS_Return CJS_Field::set_value_as_string(CJS_Runtime* pRuntime,
2200 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00002201 return CJS_Return(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002202}
2203
Dan Sinclairf7435522018-02-05 22:27:22 +00002204CJS_Return CJS_Field::browseForFileToSubmit(
dan sinclair80435cb2017-10-24 21:40:24 -04002205 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002206 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002207 CPDF_FormField* pFormField = GetFirstFormField();
2208 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002209 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002210
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002211 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002212 (pFormField->GetFieldType() == FormFieldType::kTextField)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002213 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002214 if (!wsFileName.IsEmpty()) {
2215 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002216 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002217 }
Tom Sepez16999822018-06-08 18:23:05 +00002218 return CJS_Return();
Lei Zhangd88a3642015-11-10 09:38:57 -08002219 }
Tom Sepez16999822018-06-08 18:23:05 +00002220 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002221}
2222
Dan Sinclairf7435522018-02-05 22:27:22 +00002223CJS_Return CJS_Field::buttonGetCaption(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002224 CJS_Runtime* pRuntime,
2225 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002226 int nface = 0;
2227 int iSize = params.size();
2228 if (iSize >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002229 nface = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002230
Lei Zhang4c7ad662018-07-12 20:29:40 +00002231 CPDF_FormField* pFormField = GetFirstFormField();
2232 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002233 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002234
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002235 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +00002236 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002237
2238 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2239 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00002240 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002241
Dan Sinclair8f524d62017-10-25 13:30:31 -04002242 if (nface == 0) {
2243 return CJS_Return(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002244 pRuntime->NewString(pFormControl->GetNormalCaption().AsStringView()));
2245 }
2246 if (nface == 1) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002247 return CJS_Return(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002248 pRuntime->NewString(pFormControl->GetDownCaption().AsStringView()));
2249 }
2250 if (nface == 2) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002251 return CJS_Return(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002252 pRuntime->NewString(pFormControl->GetRolloverCaption().AsStringView()));
Dan Sinclair8f524d62017-10-25 13:30:31 -04002253 }
Tom Sepez16999822018-06-08 18:23:05 +00002254 return CJS_Return(JSMessage::kValueError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002255}
2256
Dan Sinclairf7435522018-02-05 22:27:22 +00002257CJS_Return CJS_Field::buttonGetIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002258 CJS_Runtime* pRuntime,
2259 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002260 if (params.size() >= 1) {
dan sinclair80435cb2017-10-24 21:40:24 -04002261 int nFace = pRuntime->ToInt32(params[0]);
Tom Sepez40e0a812017-02-23 13:07:36 -08002262 if (nFace < 0 || nFace > 2)
Tom Sepez16999822018-06-08 18:23:05 +00002263 return CJS_Return(JSMessage::kValueError);
Tom Sepez40e0a812017-02-23 13:07:36 -08002264 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002265
Lei Zhang4c7ad662018-07-12 20:29:40 +00002266 CPDF_FormField* pFormField = GetFirstFormField();
2267 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002268 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002269
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002270 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez16999822018-06-08 18:23:05 +00002271 return CJS_Return(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002272
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002273 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2274 if (!pFormControl)
Tom Sepez16999822018-06-08 18:23:05 +00002275 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002276
Tom Sepez55ccb522018-08-14 23:40:10 +00002277 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2278 CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -08002279 if (pObj.IsEmpty())
Tom Sepez16999822018-06-08 18:23:05 +00002280 return CJS_Return(JSMessage::kBadObjectError);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002281
Tom Sepezddaa40f2018-06-06 18:30:15 +00002282 auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
Tom Sepez16999822018-06-08 18:23:05 +00002283 return pJS_Icon ? CJS_Return(pJS_Icon->ToV8Object())
2284 : CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002285}
2286
Dan Sinclairf7435522018-02-05 22:27:22 +00002287CJS_Return CJS_Field::buttonImportIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002288 CJS_Runtime* pRuntime,
2289 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002290 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002291}
2292
Dan Sinclairf7435522018-02-05 22:27:22 +00002293CJS_Return CJS_Field::buttonSetCaption(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002294 CJS_Runtime* pRuntime,
2295 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002296 return CJS_Return(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -07002297}
2298
Dan Sinclairf7435522018-02-05 22:27:22 +00002299CJS_Return CJS_Field::buttonSetIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002300 CJS_Runtime* pRuntime,
2301 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002302 return CJS_Return(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -07002303}
2304
Dan Sinclairf7435522018-02-05 22:27:22 +00002305CJS_Return CJS_Field::checkThisBox(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002306 CJS_Runtime* pRuntime,
2307 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002308 int iSize = params.size();
2309 if (iSize < 1)
Tom Sepez16999822018-06-08 18:23:05 +00002310 return CJS_Return(JSMessage::kParamError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002311
tsepezf3dc8c62016-08-10 06:29:29 -07002312 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00002313 return CJS_Return(JSMessage::kReadOnlyError);
tsepezf3dc8c62016-08-10 06:29:29 -07002314
dan sinclair80435cb2017-10-24 21:40:24 -04002315 int nWidget = pRuntime->ToInt32(params[0]);
Wei Li97da9762016-03-11 17:00:48 -08002316 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002317 if (iSize >= 2)
dan sinclair80435cb2017-10-24 21:40:24 -04002318 bCheckit = pRuntime->ToBoolean(params[1]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002319
Lei Zhang4c7ad662018-07-12 20:29:40 +00002320 CPDF_FormField* pFormField = GetFirstFormField();
2321 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002322 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002323
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002324 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez16999822018-06-08 18:23:05 +00002325 return CJS_Return(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002326 if (nWidget < 0 || nWidget >= pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00002327 return CJS_Return(JSMessage::kValueError);
Lei Zhangbc486922018-01-29 15:30:46 +00002328
2329 // TODO(weili): Check whether anything special needed for radio button.
2330 // (When pFormField->GetFieldType() == FormFieldType::kRadioButton.)
2331 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002332
tsepez4cf55152016-11-02 14:37:54 -07002333 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Tom Sepez16999822018-06-08 18:23:05 +00002334 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002335}
2336
Dan Sinclairf7435522018-02-05 22:27:22 +00002337CJS_Return CJS_Field::clearItems(
2338 CJS_Runtime* pRuntime,
2339 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002340 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002341}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002342
Dan Sinclairf7435522018-02-05 22:27:22 +00002343CJS_Return CJS_Field::defaultIsChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002344 CJS_Runtime* pRuntime,
2345 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002346 if (!m_bCanSet)
Tom Sepez16999822018-06-08 18:23:05 +00002347 return CJS_Return(JSMessage::kReadOnlyError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002348
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002349 int iSize = params.size();
2350 if (iSize < 1)
Tom Sepez16999822018-06-08 18:23:05 +00002351 return CJS_Return(JSMessage::kParamError);
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002352
Lei Zhang4c7ad662018-07-12 20:29:40 +00002353 CPDF_FormField* pFormField = GetFirstFormField();
2354 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002355 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002356
Lei Zhang4c7ad662018-07-12 20:29:40 +00002357 int nWidget = pRuntime->ToInt32(params[0]);
tsepezf3dc8c62016-08-10 06:29:29 -07002358 if (nWidget < 0 || nWidget >= pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00002359 return CJS_Return(JSMessage::kValueError);
tsepezf3dc8c62016-08-10 06:29:29 -07002360
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002361 return CJS_Return(pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002362}
2363
Dan Sinclairf7435522018-02-05 22:27:22 +00002364CJS_Return CJS_Field::deleteItemAt(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002365 CJS_Runtime* pRuntime,
2366 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002367 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002368}
2369
Dan Sinclairf7435522018-02-05 22:27:22 +00002370CJS_Return CJS_Field::getArray(
2371 CJS_Runtime* pRuntime,
2372 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang18915232018-07-12 20:53:40 +00002373 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08002374 if (FieldArray.empty())
Tom Sepez16999822018-06-08 18:23:05 +00002375 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002376
Ryan Harrison275e2602017-09-18 14:23:18 -04002377 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002378 for (CPDF_FormField* pFormField : FieldArray) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002379 swSort.push_back(pdfium::MakeUnique<WideString>(pFormField->GetFullName()));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002380 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002381
Ryan Harrison275e2602017-09-18 14:23:18 -04002382 std::sort(swSort.begin(), swSort.end(),
2383 [](const std::unique_ptr<WideString>& p1,
2384 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002385
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002386 v8::Local<v8::Array> FormFieldArray = pRuntime->NewArray();
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002387 int j = 0;
2388 for (const auto& pStr : swSort) {
Tom Sepez55ccb522018-08-14 23:40:10 +00002389 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2390 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -08002391 if (pObj.IsEmpty())
Tom Sepez16999822018-06-08 18:23:05 +00002392 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002393
Tom Sepezddaa40f2018-06-06 18:30:15 +00002394 auto* pJSField =
2395 static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pObj));
Tom Sepez2cbae732018-06-26 15:11:28 +00002396 pJSField->AttachField(m_pJSDoc.Get(), *pStr);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002397 pRuntime->PutArrayElement(FormFieldArray, j++,
dan sinclair80435cb2017-10-24 21:40:24 -04002398 pJSField
2399 ? v8::Local<v8::Value>(pJSField->ToV8Object())
2400 : v8::Local<v8::Value>());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002401 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002402 return CJS_Return(FormFieldArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002403}
2404
Dan Sinclairf7435522018-02-05 22:27:22 +00002405CJS_Return CJS_Field::getItemAt(
2406 CJS_Runtime* pRuntime,
2407 const std::vector<v8::Local<v8::Value>>& params) {
tsepezf3dc8c62016-08-10 06:29:29 -07002408 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002409 int nIdx = -1;
2410 if (iSize >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002411 nIdx = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002412
tsepez4cf55152016-11-02 14:37:54 -07002413 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002414 if (iSize >= 2)
dan sinclair80435cb2017-10-24 21:40:24 -04002415 bExport = pRuntime->ToBoolean(params[1]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002416
Lei Zhang4c7ad662018-07-12 20:29:40 +00002417 CPDF_FormField* pFormField = GetFirstFormField();
2418 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002419 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002420
Lei Zhang83f2d702018-07-12 19:07:40 +00002421 if (!IsComboBoxOrListBox(pFormField))
2422 return CJS_Return(JSMessage::kObjectTypeError);
2423
2424 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2425 nIdx = pFormField->CountOptions() - 1;
2426 if (!bExport) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002427 return CJS_Return(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002428 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002429 }
Lei Zhang83f2d702018-07-12 19:07:40 +00002430
2431 WideString strval = pFormField->GetOptionValue(nIdx);
2432 if (strval.IsEmpty()) {
2433 return CJS_Return(
2434 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
2435 }
2436 return CJS_Return(pRuntime->NewString(strval.AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002437}
2438
Dan Sinclairf7435522018-02-05 22:27:22 +00002439CJS_Return CJS_Field::getLock(CJS_Runtime* pRuntime,
2440 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002441 return CJS_Return(JSMessage::kNotSupportedError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002442}
2443
Dan Sinclairf7435522018-02-05 22:27:22 +00002444CJS_Return CJS_Field::insertItemAt(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002445 CJS_Runtime* pRuntime,
2446 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002447 return CJS_Return();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002448}
2449
Dan Sinclairf7435522018-02-05 22:27:22 +00002450CJS_Return CJS_Field::isBoxChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002451 CJS_Runtime* pRuntime,
2452 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002453 int nIndex = -1;
2454 if (params.size() >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002455 nIndex = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002456
Lei Zhang4c7ad662018-07-12 20:29:40 +00002457 CPDF_FormField* pFormField = GetFirstFormField();
2458 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002459 return CJS_Return(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002460
dan sinclair646634b2017-10-19 14:30:28 -04002461 if (nIndex < 0 || nIndex >= pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00002462 return CJS_Return(JSMessage::kValueError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002463
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002464 return CJS_Return(
2465 pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) &&
2466 pFormField->GetControl(nIndex)->IsChecked() != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002467}
2468
Dan Sinclairf7435522018-02-05 22:27:22 +00002469CJS_Return CJS_Field::isDefaultChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002470 CJS_Runtime* pRuntime,
2471 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002472 int nIndex = -1;
2473 if (params.size() >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002474 nIndex = pRuntime->ToInt32(params[0]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002475
Lei Zhang4c7ad662018-07-12 20:29:40 +00002476 CPDF_FormField* pFormField = GetFirstFormField();
2477 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002478 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002479
tsepezf3dc8c62016-08-10 06:29:29 -07002480 if (nIndex < 0 || nIndex >= pFormField->CountControls())
Tom Sepez16999822018-06-08 18:23:05 +00002481 return CJS_Return(JSMessage::kValueError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002482
Dan Sinclair8f524d62017-10-25 13:30:31 -04002483 return CJS_Return(pRuntime->NewBoolean(
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002484 (IsCheckBoxOrRadioButton(pFormField) &&
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002485 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002486}
2487
Dan Sinclairf7435522018-02-05 22:27:22 +00002488CJS_Return CJS_Field::setAction(
2489 CJS_Runtime* pRuntime,
2490 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002491 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002492}
2493
Dan Sinclairf7435522018-02-05 22:27:22 +00002494CJS_Return CJS_Field::setFocus(
2495 CJS_Runtime* pRuntime,
2496 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002497 CPDF_FormField* pFormField = GetFirstFormField();
2498 if (!pFormField)
Tom Sepez16999822018-06-08 18:23:05 +00002499 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002500
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002501 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002502 if (nCount < 1)
Tom Sepez16999822018-06-08 18:23:05 +00002503 return CJS_Return(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002504
dsinclair7cbe68e2016-10-12 11:56:23 -07002505 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07002506 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002507 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07002508 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002509 } else {
Tom Sepez101535f2018-06-12 13:36:05 +00002510 IPDF_Page* pPage = IPDFPageFromFPDFPage(m_pFormFillEnv->GetCurrentPage());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002511 if (!pPage)
Tom Sepez16999822018-06-08 18:23:05 +00002512 return CJS_Return(JSMessage::kBadObjectError);
dsinclair461eeaf2016-07-27 07:40:05 -07002513 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07002514 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002515 for (int32_t i = 0; i < nCount; i++) {
2516 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07002517 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002518 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2519 pWidget = pTempWidget;
2520 break;
2521 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002522 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002523 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002524 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002525 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002526
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002527 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07002528 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07002529 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002530 }
2531
Tom Sepez16999822018-06-08 18:23:05 +00002532 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002533}
2534
Dan Sinclairf7435522018-02-05 22:27:22 +00002535CJS_Return CJS_Field::setItems(
2536 CJS_Runtime* pRuntime,
2537 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002538 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002539}
2540
Dan Sinclairf7435522018-02-05 22:27:22 +00002541CJS_Return CJS_Field::setLock(CJS_Runtime* pRuntime,
2542 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002543 return CJS_Return(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002544}
2545
Dan Sinclairf7435522018-02-05 22:27:22 +00002546CJS_Return CJS_Field::signatureGetModifications(
dan sinclair80435cb2017-10-24 21:40:24 -04002547 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002548 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002549 return CJS_Return(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002550}
2551
Dan Sinclairf7435522018-02-05 22:27:22 +00002552CJS_Return CJS_Field::signatureGetSeedValue(
dan sinclair80435cb2017-10-24 21:40:24 -04002553 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002554 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002555 return CJS_Return(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002556}
2557
Dan Sinclairf7435522018-02-05 22:27:22 +00002558CJS_Return CJS_Field::signatureInfo(
dan sinclair80435cb2017-10-24 21:40:24 -04002559 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002560 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002561 return CJS_Return(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002562}
2563
Dan Sinclairf7435522018-02-05 22:27:22 +00002564CJS_Return CJS_Field::signatureSetSeedValue(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002565 CJS_Runtime* pRuntime,
2566 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002567 return CJS_Return(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002568}
2569
Dan Sinclairf7435522018-02-05 22:27:22 +00002570CJS_Return CJS_Field::signatureSign(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002571 CJS_Runtime* pRuntime,
2572 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002573 return CJS_Return(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002574}
2575
Dan Sinclairf7435522018-02-05 22:27:22 +00002576CJS_Return CJS_Field::signatureValidate(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002577 CJS_Runtime* pRuntime,
2578 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez16999822018-06-08 18:23:05 +00002579 return CJS_Return(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002580}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002581
Dan Sinclairf7435522018-02-05 22:27:22 +00002582CJS_Return CJS_Field::get_source(CJS_Runtime* pRuntime) {
Tom Sepez16999822018-06-08 18:23:05 +00002583 return CJS_Return();
Dan Sinclair8f524d62017-10-25 13:30:31 -04002584}
2585
Dan Sinclairf7435522018-02-05 22:27:22 +00002586CJS_Return CJS_Field::set_source(CJS_Runtime* pRuntime,
2587 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00002588 return CJS_Return();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002589}
2590
Dan Sinclairf7435522018-02-05 22:27:22 +00002591void CJS_Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
Tom Sepez75acda62018-01-29 20:17:36 +00002592 auto pNewData =
2593 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002594 pNewData->num = n;
Tom Sepez75acda62018-01-29 20:17:36 +00002595 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002596}
2597
Dan Sinclairf7435522018-02-05 22:27:22 +00002598void CJS_Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
Tom Sepez75acda62018-01-29 20:17:36 +00002599 auto pNewData =
2600 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002601 pNewData->b = b;
Tom Sepez75acda62018-01-29 20:17:36 +00002602 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002603}
2604
Dan Sinclairf7435522018-02-05 22:27:22 +00002605void CJS_Field::AddDelay_String(FIELD_PROP prop, const ByteString& string) {
Tom Sepez75acda62018-01-29 20:17:36 +00002606 auto pNewData =
2607 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002608 pNewData->string = string;
Tom Sepez75acda62018-01-29 20:17:36 +00002609 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002610}
2611
Dan Sinclairf7435522018-02-05 22:27:22 +00002612void CJS_Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
Tom Sepez75acda62018-01-29 20:17:36 +00002613 auto pNewData =
2614 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002615 pNewData->rect = rect;
Tom Sepez75acda62018-01-29 20:17:36 +00002616 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002617}
2618
Dan Sinclairf7435522018-02-05 22:27:22 +00002619void CJS_Field::AddDelay_WordArray(FIELD_PROP prop,
2620 const std::vector<uint32_t>& array) {
Tom Sepez75acda62018-01-29 20:17:36 +00002621 auto pNewData =
2622 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
tsepez41a53ad2016-03-28 16:59:30 -07002623 pNewData->wordarray = array;
Tom Sepez75acda62018-01-29 20:17:36 +00002624 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002625}
2626
Dan Sinclairf7435522018-02-05 22:27:22 +00002627void CJS_Field::AddDelay_WideStringArray(FIELD_PROP prop,
2628 const std::vector<WideString>& array) {
Tom Sepez75acda62018-01-29 20:17:36 +00002629 auto pNewData =
2630 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
tsepez41a53ad2016-03-28 16:59:30 -07002631 pNewData->widestringarray = array;
Tom Sepez75acda62018-01-29 20:17:36 +00002632 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002633}
2634
Dan Sinclairf7435522018-02-05 22:27:22 +00002635void CJS_Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2636 CJS_DelayData* pData) {
dsinclair3a7741a2016-10-11 10:39:49 -07002637 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002638 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002639 case FP_BORDERSTYLE:
Lei Zhang94919f72018-07-12 21:16:30 +00002640 SetBorderStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2641 pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002642 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002643 case FP_CURRENTVALUEINDICES:
Lei Zhang94919f72018-07-12 21:16:30 +00002644 SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
2645 pData->nControlIndex, pData->wordarray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002646 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002647 case FP_DISPLAY:
Lei Zhang94919f72018-07-12 21:16:30 +00002648 SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2649 pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002650 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002651 case FP_HIDDEN:
Lei Zhang94919f72018-07-12 21:16:30 +00002652 SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2653 pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002654 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002655 case FP_LINEWIDTH:
Lei Zhang94919f72018-07-12 21:16:30 +00002656 SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2657 pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002658 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002659 case FP_RECT:
Lei Zhang94919f72018-07-12 21:16:30 +00002660 SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2661 pData->rect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002662 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002663 case FP_VALUE:
Lei Zhang94919f72018-07-12 21:16:30 +00002664 SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2665 pData->widestringarray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002666 break;
dan sinclair646634b2017-10-19 14:30:28 -04002667 default:
2668 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002669 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002670}