blob: cffefeb8c7983bb2863de19710fe0371cf287c44 [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"
Lei Zhang99f5bbb2018-10-09 21:31:28 +000024#include "third_party/base/ptr_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
tonikitoo7c05a7a2016-08-17 11:08:46 -070026namespace {
27
Lei Zhang94919f72018-07-12 21:16:30 +000028bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) {
29 return pFormField->GetFieldType() == FormFieldType::kCheckBox ||
30 pFormField->GetFieldType() == FormFieldType::kRadioButton;
31}
32
33bool IsComboBoxOrListBox(const CPDF_FormField* pFormField) {
34 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
35 pFormField->GetFieldType() == FormFieldType::kListBox;
36}
37
38bool IsComboBoxOrTextField(const CPDF_FormField* pFormField) {
39 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
40 pFormField->GetFieldType() == FormFieldType::kTextField;
41}
42
43void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
44 CPDF_FormField* pFormField,
45 bool bChangeMark,
46 bool bResetAP,
47 bool bRefresh) {
48 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
49
50 if (bResetAP) {
51 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
52 pInterForm->GetWidgets(pFormField, &widgets);
53
54 if (IsComboBoxOrTextField(pFormField)) {
55 for (auto& pObserved : widgets) {
56 if (pObserved) {
Lei Zhang4f261ff2018-10-10 18:44:45 +000057 Optional<WideString> sValue =
58 ToCPDFSDKWidget(pObserved.Get())->OnFormat();
Lei Zhang94919f72018-07-12 21:16:30 +000059 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
Lei Zhang4f261ff2018-10-10 18:44:45 +000060 ToCPDFSDKWidget(pObserved.Get())->ResetAppearance(sValue, false);
Lei Zhang94919f72018-07-12 21:16:30 +000061 }
62 }
63 }
64 } else {
65 for (auto& pObserved : widgets) {
Tom Sepez4ef943b2018-07-26 19:06:06 +000066 if (pObserved)
Lei Zhang4f261ff2018-10-10 18:44:45 +000067 ToCPDFSDKWidget(pObserved.Get())->ResetAppearance({}, false);
Lei Zhang94919f72018-07-12 21:16:30 +000068 }
69 }
70 }
71
72 if (bRefresh) {
73 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
74 // to be removed from the list. We need to call |GetWidgets| again to be
75 // sure none of the widgets have been deleted.
76 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
77 pInterForm->GetWidgets(pFormField, &widgets);
78
79 // TODO(dsinclair): Determine if all widgets share the same
80 // CPDFSDK_InterForm. If that's the case, we can move the code to
81 // |GetFormFillEnv| out of the loop.
82 for (auto& pObserved : widgets) {
83 if (pObserved) {
Tom Sepez4ef943b2018-07-26 19:06:06 +000084 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pObserved.Get());
Lei Zhang94919f72018-07-12 21:16:30 +000085 pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
86 pWidget);
87 }
88 }
89 }
90
91 if (bChangeMark)
92 pFormFillEnv->SetChangeMark();
93}
94
95void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
96 CPDF_FormControl* pFormControl,
97 bool bChangeMark,
98 bool bResetAP,
99 bool bRefresh) {
100 ASSERT(pFormControl);
101
102 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
103 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
104
105 if (pWidget) {
106 CPDFSDK_Widget::ObservedPtr observed_widget(pWidget);
107 if (bResetAP) {
108 FormFieldType fieldType = pWidget->GetFieldType();
109 if (fieldType == FormFieldType::kComboBox ||
110 fieldType == FormFieldType::kTextField) {
Lei Zhang4f261ff2018-10-10 18:44:45 +0000111 Optional<WideString> sValue = pWidget->OnFormat();
Lei Zhang94919f72018-07-12 21:16:30 +0000112 if (!observed_widget)
113 return;
Lei Zhang4f261ff2018-10-10 18:44:45 +0000114 pWidget->ResetAppearance(sValue, false);
Lei Zhang94919f72018-07-12 21:16:30 +0000115 } else {
Lei Zhang4f261ff2018-10-10 18:44:45 +0000116 pWidget->ResetAppearance({}, false);
Lei Zhang94919f72018-07-12 21:16:30 +0000117 }
118 if (!observed_widget)
119 return;
120 }
121
122 if (bRefresh) {
123 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
124 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
125 }
126 }
127
128 if (bChangeMark)
129 pFormFillEnv->SetChangeMark();
130}
131
132std::vector<CPDF_FormField*> GetFormFieldsForName(
133 CPDFSDK_FormFillEnvironment* pFormFillEnv,
134 const WideString& csFieldName) {
135 std::vector<CPDF_FormField*> fields;
136 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
137 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
138 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
139 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
140 fields.push_back(pFormField);
141 }
142 return fields;
143}
144
tonikitoo7c05a7a2016-08-17 11:08:46 -0700145bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
146 if (!pWidget)
147 return false;
148
149 uint32_t dwFlag = pWidget->GetFlags();
150 switch (value) {
151 case 0:
152 dwFlag &= ~ANNOTFLAG_INVISIBLE;
153 dwFlag &= ~ANNOTFLAG_HIDDEN;
154 dwFlag &= ~ANNOTFLAG_NOVIEW;
155 dwFlag |= ANNOTFLAG_PRINT;
156 break;
157 case 1:
158 dwFlag &= ~ANNOTFLAG_INVISIBLE;
159 dwFlag &= ~ANNOTFLAG_NOVIEW;
160 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
161 break;
162 case 2:
163 dwFlag &= ~ANNOTFLAG_INVISIBLE;
164 dwFlag &= ~ANNOTFLAG_PRINT;
165 dwFlag &= ~ANNOTFLAG_HIDDEN;
166 dwFlag &= ~ANNOTFLAG_NOVIEW;
167 break;
168 case 3:
169 dwFlag |= ANNOTFLAG_NOVIEW;
170 dwFlag |= ANNOTFLAG_PRINT;
171 dwFlag &= ~ANNOTFLAG_HIDDEN;
172 break;
173 }
174
175 if (dwFlag != pWidget->GetFlags()) {
176 pWidget->SetFlags(dwFlag);
177 return true;
178 }
179
180 return false;
181}
182
Lei Zhang94919f72018-07-12 21:16:30 +0000183void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
184 const WideString& swFieldName,
185 int nControlIndex,
186 const ByteString& string) {
187 ASSERT(pFormFillEnv);
188
189 BorderStyle nBorderStyle = BorderStyle::SOLID;
190 if (string == "solid")
191 nBorderStyle = BorderStyle::SOLID;
192 else if (string == "beveled")
193 nBorderStyle = BorderStyle::BEVELED;
194 else if (string == "dashed")
195 nBorderStyle = BorderStyle::DASH;
196 else if (string == "inset")
197 nBorderStyle = BorderStyle::INSET;
198 else if (string == "underline")
199 nBorderStyle = BorderStyle::UNDERLINE;
200 else
201 return;
202
203 std::vector<CPDF_FormField*> FieldArray =
204 GetFormFieldsForName(pFormFillEnv, swFieldName);
Lei Zhang7db136a2018-10-10 21:34:17 +0000205 auto* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhang94919f72018-07-12 21:16:30 +0000206 for (CPDF_FormField* pFormField : FieldArray) {
207 if (nControlIndex < 0) {
208 bool bSet = false;
209 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Lei Zhang7db136a2018-10-10 21:34:17 +0000210 CPDFSDK_Widget* pWidget =
211 pInterForm->GetWidget(pFormField->GetControl(i));
212 if (pWidget) {
Lei Zhang94919f72018-07-12 21:16:30 +0000213 if (pWidget->GetBorderStyle() != nBorderStyle) {
214 pWidget->SetBorderStyle(nBorderStyle);
215 bSet = true;
216 }
217 }
218 }
219 if (bSet)
220 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
221 } else {
222 if (nControlIndex >= pFormField->CountControls())
223 return;
224 if (CPDF_FormControl* pFormControl =
225 pFormField->GetControl(nControlIndex)) {
Lei Zhang7db136a2018-10-10 21:34:17 +0000226 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
227 if (pWidget) {
Lei Zhang94919f72018-07-12 21:16:30 +0000228 if (pWidget->GetBorderStyle() != nBorderStyle) {
229 pWidget->SetBorderStyle(nBorderStyle);
230 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
231 }
232 }
233 }
234 }
235 }
Lei Zhangdfa2ac22018-07-12 19:06:50 +0000236}
237
Lei Zhang94919f72018-07-12 21:16:30 +0000238void SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
239 const WideString& swFieldName,
240 int nControlIndex,
241 const std::vector<uint32_t>& array) {
242 ASSERT(pFormFillEnv);
243 std::vector<CPDF_FormField*> FieldArray =
244 GetFormFieldsForName(pFormFillEnv, swFieldName);
245
246 for (CPDF_FormField* pFormField : FieldArray) {
247 if (!IsComboBoxOrListBox(pFormField))
248 continue;
249
250 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
Tom Sepezb2e6b4c2018-08-16 20:53:58 +0000251 pFormField->ClearSelection(NotificationOption::kNotify);
Lei Zhang94919f72018-07-12 21:16:30 +0000252 for (size_t i = 0; i < array.size(); ++i) {
253 if (i != 0 && !(dwFieldFlags & (1 << 21)))
254 break;
255 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
256 !pFormField->IsItemSelected(array[i])) {
Tom Sepezb2e6b4c2018-08-16 20:53:58 +0000257 pFormField->SetItemSelection(array[i], true,
258 NotificationOption::kDoNotNotify);
Lei Zhang94919f72018-07-12 21:16:30 +0000259 }
260 }
261 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
262 }
Lei Zhang83f2d702018-07-12 19:07:40 +0000263}
264
Lei Zhang94919f72018-07-12 21:16:30 +0000265void SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
266 const WideString& swFieldName,
267 int nControlIndex,
268 int number) {
269 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
270 std::vector<CPDF_FormField*> FieldArray =
271 GetFormFieldsForName(pFormFillEnv, swFieldName);
272 for (CPDF_FormField* pFormField : FieldArray) {
273 if (nControlIndex < 0) {
274 bool bAnySet = false;
275 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
276 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
277 ASSERT(pFormControl);
278
279 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
280 if (SetWidgetDisplayStatus(pWidget, number))
281 bAnySet = true;
282 }
283
284 if (bAnySet)
285 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
286 } else {
287 if (nControlIndex >= pFormField->CountControls())
288 return;
289
290 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
291 if (!pFormControl)
292 return;
293
294 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
295 if (SetWidgetDisplayStatus(pWidget, number))
296 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
297 }
298 }
299}
300
301void SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
302 const WideString& swFieldName,
303 int nControlIndex,
304 bool b) {
305 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
306 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
307}
308
309void SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
310 const WideString& swFieldName,
311 int nControlIndex,
312 int number) {
313 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
314 std::vector<CPDF_FormField*> FieldArray =
315 GetFormFieldsForName(pFormFillEnv, swFieldName);
316 for (CPDF_FormField* pFormField : FieldArray) {
317 if (nControlIndex < 0) {
318 bool bSet = false;
319 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
320 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
321 ASSERT(pFormControl);
322
323 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
324 if (number != pWidget->GetBorderWidth()) {
325 pWidget->SetBorderWidth(number);
326 bSet = true;
327 }
328 }
329 }
330 if (bSet)
331 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
332 } else {
333 if (nControlIndex >= pFormField->CountControls())
334 return;
335 if (CPDF_FormControl* pFormControl =
336 pFormField->GetControl(nControlIndex)) {
337 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
338 if (number != pWidget->GetBorderWidth()) {
339 pWidget->SetBorderWidth(number);
340 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
341 }
342 }
343 }
344 }
345 }
346}
347
348void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
349 const WideString& swFieldName,
350 int nControlIndex,
351 const CFX_FloatRect& rect) {
352 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
353 std::vector<CPDF_FormField*> FieldArray =
354 GetFormFieldsForName(pFormFillEnv, swFieldName);
355 for (CPDF_FormField* pFormField : FieldArray) {
356 if (nControlIndex < 0) {
357 bool bSet = false;
358 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
359 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
360 ASSERT(pFormControl);
361
362 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
363 CFX_FloatRect crRect = rect;
364
365 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
366 crRect.Intersect(pPDFPage->GetBBox());
367
368 if (!crRect.IsEmpty()) {
369 CFX_FloatRect rcOld = pWidget->GetRect();
370 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
371 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
372 pWidget->SetRect(crRect);
373 bSet = true;
374 }
375 }
376 }
377 }
378
379 if (bSet)
380 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
381
382 continue;
383 }
384
385 if (nControlIndex >= pFormField->CountControls())
386 return;
387 if (CPDF_FormControl* pFormControl =
388 pFormField->GetControl(nControlIndex)) {
389 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
390 CFX_FloatRect crRect = rect;
391 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
392 crRect.Intersect(pPDFPage->GetBBox());
393 if (!crRect.IsEmpty()) {
394 CFX_FloatRect rcOld = pWidget->GetRect();
395 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
396 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
397 pWidget->SetRect(crRect);
398 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
399 }
400 }
401 }
402 }
403 }
404}
405
406void SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
407 const WideString& swFieldName,
408 int nControlIndex,
409 const std::vector<WideString>& strArray) {
410 ASSERT(pFormFillEnv);
411 if (strArray.empty())
412 return;
413
414 std::vector<CPDF_FormField*> FieldArray =
415 GetFormFieldsForName(pFormFillEnv, swFieldName);
416
417 for (CPDF_FormField* pFormField : FieldArray) {
418 if (pFormField->GetFullName().Compare(swFieldName) != 0)
419 continue;
420
421 switch (pFormField->GetFieldType()) {
422 case FormFieldType::kTextField:
423 case FormFieldType::kComboBox:
424 if (pFormField->GetValue() != strArray[0]) {
Tom Sepezb2e6b4c2018-08-16 20:53:58 +0000425 pFormField->SetValue(strArray[0], NotificationOption::kNotify);
Lei Zhang94919f72018-07-12 21:16:30 +0000426 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
427 }
428 break;
429 case FormFieldType::kCheckBox:
430 case FormFieldType::kRadioButton:
431 if (pFormField->GetValue() != strArray[0]) {
Tom Sepezb2e6b4c2018-08-16 20:53:58 +0000432 pFormField->SetValue(strArray[0], NotificationOption::kNotify);
Lei Zhang94919f72018-07-12 21:16:30 +0000433 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
434 }
435 break;
436 case FormFieldType::kListBox: {
437 bool bModified = false;
438 for (const auto& str : strArray) {
439 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
440 bModified = true;
441 break;
442 }
443 }
444 if (bModified) {
Tom Sepezb2e6b4c2018-08-16 20:53:58 +0000445 pFormField->ClearSelection(NotificationOption::kNotify);
Lei Zhang94919f72018-07-12 21:16:30 +0000446 for (const auto& str : strArray) {
447 int index = pFormField->FindOption(str);
448 if (!pFormField->IsItemSelected(index))
Tom Sepezb2e6b4c2018-08-16 20:53:58 +0000449 pFormField->SetItemSelection(index, true,
450 NotificationOption::kNotify);
Lei Zhang94919f72018-07-12 21:16:30 +0000451 }
452 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
453 }
454 break;
455 }
456 default:
457 break;
458 }
459 }
Lei Zhang83f2d702018-07-12 19:07:40 +0000460}
461
tonikitoo7c05a7a2016-08-17 11:08:46 -0700462} // namespace
463
Dan Sinclairc94a7932017-10-26 16:48:57 -0400464const JSPropertySpec CJS_Field::PropertySpecs[] = {
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800465 {"alignment", get_alignment_static, set_alignment_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400466 {"borderStyle", get_border_style_static, set_border_style_static},
467 {"buttonAlignX", get_button_align_x_static, set_button_align_x_static},
468 {"buttonAlignY", get_button_align_y_static, set_button_align_y_static},
469 {"buttonFitBounds", get_button_fit_bounds_static,
470 set_button_fit_bounds_static},
471 {"buttonPosition", get_button_position_static, set_button_position_static},
472 {"buttonScaleHow", get_button_scale_how_static,
473 set_button_scale_how_static},
474 {"buttonScaleWhen", get_button_scale_when_static,
475 set_button_scale_when_static},
476 {"calcOrderIndex", get_calc_order_index_static,
477 set_calc_order_index_static},
478 {"charLimit", get_char_limit_static, set_char_limit_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800479 {"comb", get_comb_static, set_comb_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400480 {"commitOnSelChange", get_commit_on_sel_change_static,
481 set_commit_on_sel_change_static},
482 {"currentValueIndices", get_current_value_indices_static,
483 set_current_value_indices_static},
484 {"defaultStyle", get_default_style_static, set_default_style_static},
485 {"defaultValue", get_default_value_static, set_default_value_static},
486 {"doNotScroll", get_do_not_scroll_static, set_do_not_scroll_static},
487 {"doNotSpellCheck", get_do_not_spell_check_static,
488 set_do_not_spell_check_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800489 {"delay", get_delay_static, set_delay_static},
490 {"display", get_display_static, set_display_static},
491 {"doc", get_doc_static, set_doc_static},
492 {"editable", get_editable_static, set_editable_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400493 {"exportValues", get_export_values_static, set_export_values_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800494 {"hidden", get_hidden_static, set_hidden_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400495 {"fileSelect", get_file_select_static, set_file_select_static},
496 {"fillColor", get_fill_color_static, set_fill_color_static},
497 {"lineWidth", get_line_width_static, set_line_width_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800498 {"highlight", get_highlight_static, set_highlight_static},
499 {"multiline", get_multiline_static, set_multiline_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400500 {"multipleSelection", get_multiple_selection_static,
501 set_multiple_selection_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800502 {"name", get_name_static, set_name_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400503 {"numItems", get_num_items_static, set_num_items_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800504 {"page", get_page_static, set_page_static},
505 {"password", get_password_static, set_password_static},
506 {"print", get_print_static, set_print_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400507 {"radiosInUnison", get_radios_in_unison_static,
508 set_radios_in_unison_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800509 {"readonly", get_readonly_static, set_readonly_static},
510 {"rect", get_rect_static, set_rect_static},
511 {"required", get_required_static, set_required_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400512 {"richText", get_rich_text_static, set_rich_text_static},
513 {"richValue", get_rich_value_static, set_rich_value_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800514 {"rotation", get_rotation_static, set_rotation_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400515 {"strokeColor", get_stroke_color_static, set_stroke_color_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800516 {"style", get_style_static, set_style_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400517 {"submitName", get_submit_name_static, set_submit_name_static},
518 {"textColor", get_text_color_static, set_text_color_static},
519 {"textFont", get_text_font_static, set_text_font_static},
520 {"textSize", get_text_size_static, set_text_size_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800521 {"type", get_type_static, set_type_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400522 {"userName", get_user_name_static, set_user_name_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800523 {"value", get_value_static, set_value_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400524 {"valueAsString", get_value_as_string_static, set_value_as_string_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +0000525 {"source", get_source_static, set_source_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700526
Dan Sinclairc94a7932017-10-26 16:48:57 -0400527const JSMethodSpec CJS_Field::MethodSpecs[] = {
Tom Sepez9b99b632017-02-21 15:05:57 -0800528 {"browseForFileToSubmit", browseForFileToSubmit_static},
529 {"buttonGetCaption", buttonGetCaption_static},
530 {"buttonGetIcon", buttonGetIcon_static},
531 {"buttonImportIcon", buttonImportIcon_static},
532 {"buttonSetCaption", buttonSetCaption_static},
533 {"buttonSetIcon", buttonSetIcon_static},
534 {"checkThisBox", checkThisBox_static},
535 {"clearItems", clearItems_static},
536 {"defaultIsChecked", defaultIsChecked_static},
537 {"deleteItemAt", deleteItemAt_static},
538 {"getArray", getArray_static},
539 {"getItemAt", getItemAt_static},
540 {"getLock", getLock_static},
541 {"insertItemAt", insertItemAt_static},
542 {"isBoxChecked", isBoxChecked_static},
543 {"isDefaultChecked", isDefaultChecked_static},
544 {"setAction", setAction_static},
545 {"setFocus", setFocus_static},
546 {"setItems", setItems_static},
547 {"setLock", setLock_static},
548 {"signatureGetModifications", signatureGetModifications_static},
549 {"signatureGetSeedValue", signatureGetSeedValue_static},
550 {"signatureInfo", signatureInfo_static},
551 {"signatureSetSeedValue", signatureSetSeedValue_static},
552 {"signatureSign", signatureSign_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +0000553 {"signatureValidate", signatureValidate_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554
Dan Sinclairef299532017-10-26 16:48:30 -0400555int CJS_Field::ObjDefnID = -1;
Dan Sinclairf7435522018-02-05 22:27:22 +0000556const char CJS_Field::kName[] = "Field";
Dan Sinclair89d26c82017-10-26 12:21:28 -0400557
Dan Sinclairef299532017-10-26 16:48:30 -0400558// static
559int CJS_Field::GetObjDefnID() {
560 return ObjDefnID;
561}
562
563// static
Dan Sinclairbef4d3e2017-10-26 16:49:38 -0400564void CJS_Field::DefineJSObjects(CFXJS_Engine* pEngine) {
Dan Sinclairf7435522018-02-05 22:27:22 +0000565 ObjDefnID = pEngine->DefineObj(CJS_Field::kName, FXJSOBJTYPE_DYNAMIC,
Dan Sinclair998fee32018-02-05 21:43:19 +0000566 JSConstructor<CJS_Field>, JSDestructor);
Tom Sepez8b4ddeb2018-06-11 15:55:17 +0000567 DefineProps(pEngine, ObjDefnID, PropertySpecs);
568 DefineMethods(pEngine, ObjDefnID, MethodSpecs);
Dan Sinclair89d26c82017-10-26 12:21:28 -0400569}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700570
Tom Sepez36aae4f2018-06-04 19:44:37 +0000571CJS_Field::CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
572 : CJS_Object(pObject, pRuntime) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573
Dan Sinclairf7435522018-02-05 22:27:22 +0000574CJS_Field::~CJS_Field() = default;
575
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576// note: iControlNo = -1, means not a widget.
Dan Sinclairf7435522018-02-05 22:27:22 +0000577void CJS_Field::ParseFieldName(const std::wstring& strFieldNameParsed,
578 std::wstring& strFieldName,
579 int& iControlNo) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 int iStart = strFieldNameParsed.find_last_of(L'.');
581 if (iStart == -1) {
582 strFieldName = strFieldNameParsed;
583 iControlNo = -1;
584 return;
585 }
586 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
587 iControlNo = FXSYS_wtoi(suffixal.c_str());
588 if (iControlNo == 0) {
weilidb444d22016-06-02 15:48:15 -0700589 int iSpaceStart;
590 while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
591 suffixal.erase(iSpaceStart, 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 }
593
594 if (suffixal.compare(L"0") != 0) {
595 strFieldName = strFieldNameParsed;
596 iControlNo = -1;
597 return;
598 }
599 }
600 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700601}
602
Dan Sinclairf7435522018-02-05 22:27:22 +0000603bool CJS_Field::AttachField(CJS_Document* pDocument,
604 const WideString& csFieldName) {
Tom Sepez2cbae732018-06-26 15:11:28 +0000605 m_pJSDoc.Reset(pDocument);
dsinclair82e17672016-10-11 12:38:01 -0700606 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
dsinclair7cbe68e2016-10-12 11:56:23 -0700607 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
608 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
609 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610
dsinclair7cbe68e2016-10-12 11:56:23 -0700611 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Ryan Harrison275e2602017-09-18 14:23:18 -0400613 WideString swFieldNameTemp = csFieldName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 swFieldNameTemp.Replace(L"..", L".");
615
616 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
617 std::wstring strFieldName;
618 int iControlNo = -1;
619 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
620 if (iControlNo == -1)
tsepez4cf55152016-11-02 14:37:54 -0700621 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622
623 m_FieldName = strFieldName.c_str();
624 m_nFormControlIndex = iControlNo;
tsepez4cf55152016-11-02 14:37:54 -0700625 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 }
627
628 m_FieldName = swFieldNameTemp;
629 m_nFormControlIndex = -1;
630
tsepez4cf55152016-11-02 14:37:54 -0700631 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632}
633
Lei Zhang18915232018-07-12 20:53:40 +0000634std::vector<CPDF_FormField*> CJS_Field::GetFormFields() const {
Lei Zhang94919f72018-07-12 21:16:30 +0000635 return GetFormFieldsForName(m_pFormFillEnv.Get(), m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636}
637
Lei Zhang4c7ad662018-07-12 20:29:40 +0000638CPDF_FormField* CJS_Field::GetFirstFormField() const {
Lei Zhang18915232018-07-12 20:53:40 +0000639 std::vector<CPDF_FormField*> fields = GetFormFields();
Lei Zhang4c7ad662018-07-12 20:29:40 +0000640 return fields.empty() ? nullptr : fields[0];
641}
642
Dan Sinclairf7435522018-02-05 22:27:22 +0000643bool CJS_Field::ValueIsOccur(CPDF_FormField* pFormField,
Lei Zhang18915232018-07-12 20:53:40 +0000644 WideString csOptLabel) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
646 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
tsepez4cf55152016-11-02 14:37:54 -0700647 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 }
649
tsepez4cf55152016-11-02 14:37:54 -0700650 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651}
652
Dan Sinclairf7435522018-02-05 22:27:22 +0000653CPDF_FormControl* CJS_Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 if (!pFormField->CountControls() ||
655 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700656 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657 if (m_nFormControlIndex < 0)
658 return pFormField->GetControl(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 return pFormField->GetControl(m_nFormControlIndex);
660}
661
Tom Sepez3a6d0582018-08-17 19:28:52 +0000662CJS_Result CJS_Field::get_alignment(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700663 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664
Lei Zhang4c7ad662018-07-12 20:29:40 +0000665 CPDF_FormField* pFormField = GetFirstFormField();
666 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000667 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000669 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000670 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671
dan sinclair646634b2017-10-19 14:30:28 -0400672 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
673 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000674 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675
dan sinclair646634b2017-10-19 14:30:28 -0400676 switch (pFormControl->GetControlAlignment()) {
dan sinclair646634b2017-10-19 14:30:28 -0400677 case 0:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000678 return CJS_Result::Success(pRuntime->NewString(L"left"));
Dan Sinclair8f524d62017-10-25 13:30:31 -0400679 case 1:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000680 return CJS_Result::Success(pRuntime->NewString(L"center"));
dan sinclair646634b2017-10-19 14:30:28 -0400681 case 2:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000682 return CJS_Result::Success(pRuntime->NewString(L"right"));
dan sinclair646634b2017-10-19 14:30:28 -0400683 }
Tom Sepez3a6d0582018-08-17 19:28:52 +0000684 return CJS_Result::Success(pRuntime->NewString(L""));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685}
686
Tom Sepez3a6d0582018-08-17 19:28:52 +0000687CJS_Result CJS_Field::set_alignment(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000688 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400689 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000690 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000691 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Tom Sepez20736f72018-08-17 16:44:50 +0000692
Tom Sepez3a6d0582018-08-17 19:28:52 +0000693 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694}
695
Tom Sepez3a6d0582018-08-17 19:28:52 +0000696CJS_Result CJS_Field::get_border_style(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700697 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698
Lei Zhang4c7ad662018-07-12 20:29:40 +0000699 CPDF_FormField* pFormField = GetFirstFormField();
700 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000701 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702
Lei Zhang7db136a2018-10-10 21:34:17 +0000703 CPDFSDK_Widget* pWidget = m_pFormFillEnv->GetInterForm()->GetWidget(
704 GetSmartFieldControl(pFormField));
dan sinclaircbe23db2017-10-19 14:29:33 -0400705 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000706 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707
dan sinclaircbe23db2017-10-19 14:29:33 -0400708 switch (pWidget->GetBorderStyle()) {
709 case BorderStyle::SOLID:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000710 return CJS_Result::Success(pRuntime->NewString(L"solid"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400711 case BorderStyle::DASH:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000712 return CJS_Result::Success(pRuntime->NewString(L"dashed"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400713 case BorderStyle::BEVELED:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000714 return CJS_Result::Success(pRuntime->NewString(L"beveled"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400715 case BorderStyle::INSET:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000716 return CJS_Result::Success(pRuntime->NewString(L"inset"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400717 case BorderStyle::UNDERLINE:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000718 return CJS_Result::Success(pRuntime->NewString(L"underline"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 }
Tom Sepez3a6d0582018-08-17 19:28:52 +0000720 return CJS_Result::Success(pRuntime->NewString(L""));
dan sinclaircbe23db2017-10-19 14:29:33 -0400721}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722
Tom Sepez3a6d0582018-08-17 19:28:52 +0000723CJS_Result CJS_Field::set_border_style(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000724 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400725 ASSERT(m_pFormFillEnv);
dan sinclaircbe23db2017-10-19 14:29:33 -0400726 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000727 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400728
Tom Sepez34dab072018-08-08 17:49:02 +0000729 ByteString byte_str = pRuntime->ToWideString(vp).ToDefANSI();
dan sinclaircbe23db2017-10-19 14:29:33 -0400730 if (m_bDelay) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400731 AddDelay_String(FP_BORDERSTYLE, byte_str);
dan sinclaircbe23db2017-10-19 14:29:33 -0400732 } else {
Lei Zhang94919f72018-07-12 21:16:30 +0000733 SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
734 byte_str);
dan sinclaircbe23db2017-10-19 14:29:33 -0400735 }
Tom Sepez3a6d0582018-08-17 19:28:52 +0000736 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737}
738
Tom Sepez3a6d0582018-08-17 19:28:52 +0000739CJS_Result CJS_Field::get_button_align_x(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700740 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741
Lei Zhang4c7ad662018-07-12 20:29:40 +0000742 CPDF_FormField* pFormField = GetFirstFormField();
743 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000744 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000746 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000747 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748
dan sinclaircbe23db2017-10-19 14:29:33 -0400749 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
750 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000751 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400752
753 CPDF_IconFit IconFit = pFormControl->GetIconFit();
Lei Zhang65b8db92018-10-10 17:50:31 +0000754 CFX_PointF pos = IconFit.GetIconBottomLeftPosition();
755 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>(pos.x)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400756}
757
Tom Sepez3a6d0582018-08-17 19:28:52 +0000758CJS_Result CJS_Field::set_button_align_x(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000759 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400760 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000761 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000762 return CJS_Result::Failure(JSMessage::kReadOnlyError);
763 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764}
765
Tom Sepez3a6d0582018-08-17 19:28:52 +0000766CJS_Result CJS_Field::get_button_align_y(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700767 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768
Lei Zhang4c7ad662018-07-12 20:29:40 +0000769 CPDF_FormField* pFormField = GetFirstFormField();
770 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000771 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000773 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000774 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775
dan sinclaircbe23db2017-10-19 14:29:33 -0400776 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
777 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000778 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400779
780 CPDF_IconFit IconFit = pFormControl->GetIconFit();
Lei Zhang65b8db92018-10-10 17:50:31 +0000781 CFX_PointF pos = IconFit.GetIconBottomLeftPosition();
782 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>(pos.y)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400783}
784
Tom Sepez3a6d0582018-08-17 19:28:52 +0000785CJS_Result CJS_Field::set_button_align_y(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000786 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400787 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000788 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000789 return CJS_Result::Failure(JSMessage::kReadOnlyError);
790 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791}
792
Tom Sepez3a6d0582018-08-17 19:28:52 +0000793CJS_Result CJS_Field::get_button_fit_bounds(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700794 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795
Lei Zhang4c7ad662018-07-12 20:29:40 +0000796 CPDF_FormField* pFormField = GetFirstFormField();
797 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000798 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000800 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000801 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802
dan sinclair646634b2017-10-19 14:30:28 -0400803 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
804 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000805 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806
Tom Sepez3a6d0582018-08-17 19:28:52 +0000807 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -0400808 pRuntime->NewBoolean(pFormControl->GetIconFit().GetFittingBounds()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400809}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810
Tom Sepez3a6d0582018-08-17 19:28:52 +0000811CJS_Result CJS_Field::set_button_fit_bounds(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000812 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400813 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000814 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000815 return CJS_Result::Failure(JSMessage::kReadOnlyError);
816 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700817}
818
Tom Sepez3a6d0582018-08-17 19:28:52 +0000819CJS_Result CJS_Field::get_button_position(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700820 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821
Lei Zhang4c7ad662018-07-12 20:29:40 +0000822 CPDF_FormField* pFormField = GetFirstFormField();
823 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000824 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000826 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000827 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700828
dan sinclair646634b2017-10-19 14:30:28 -0400829 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
830 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000831 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700832
Tom Sepez3a6d0582018-08-17 19:28:52 +0000833 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +0000834 pRuntime->NewNumber(pFormControl->GetTextPosition()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400835}
836
Tom Sepez3a6d0582018-08-17 19:28:52 +0000837CJS_Result CJS_Field::set_button_position(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000838 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400839 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000840 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000841 return CJS_Result::Failure(JSMessage::kBadObjectError);
842 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700843}
844
Tom Sepez3a6d0582018-08-17 19:28:52 +0000845CJS_Result CJS_Field::get_button_scale_how(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700846 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847
Lei Zhang4c7ad662018-07-12 20:29:40 +0000848 CPDF_FormField* pFormField = GetFirstFormField();
849 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000850 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700851
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000852 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000853 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854
dan sinclair646634b2017-10-19 14:30:28 -0400855 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
856 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000857 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700858
Tom Sepez3a6d0582018-08-17 19:28:52 +0000859 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -0400860 pFormControl->GetIconFit().IsProportionalScale() ? 0 : 1));
dan sinclaircbe23db2017-10-19 14:29:33 -0400861}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862
Tom Sepez3a6d0582018-08-17 19:28:52 +0000863CJS_Result CJS_Field::set_button_scale_how(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000864 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400865 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000866 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000867 return CJS_Result::Failure(JSMessage::kReadOnlyError);
868 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869}
870
Tom Sepez3a6d0582018-08-17 19:28:52 +0000871CJS_Result CJS_Field::get_button_scale_when(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700872 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873
Lei Zhang4c7ad662018-07-12 20:29:40 +0000874 CPDF_FormField* pFormField = GetFirstFormField();
875 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000876 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700877
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000878 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000879 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880
dan sinclair646634b2017-10-19 14:30:28 -0400881 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
882 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000883 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884
dan sinclair646634b2017-10-19 14:30:28 -0400885 CPDF_IconFit IconFit = pFormControl->GetIconFit();
886 int ScaleM = IconFit.GetScaleMethod();
887 switch (ScaleM) {
888 case CPDF_IconFit::Always:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000889 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -0400890 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Always)));
dan sinclair646634b2017-10-19 14:30:28 -0400891 case CPDF_IconFit::Bigger:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000892 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -0400893 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Bigger)));
dan sinclair646634b2017-10-19 14:30:28 -0400894 case CPDF_IconFit::Never:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000895 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -0400896 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Never)));
dan sinclair646634b2017-10-19 14:30:28 -0400897 case CPDF_IconFit::Smaller:
Tom Sepez3a6d0582018-08-17 19:28:52 +0000898 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -0400899 pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Smaller)));
dan sinclair646634b2017-10-19 14:30:28 -0400900 }
Tom Sepez3a6d0582018-08-17 19:28:52 +0000901 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400902}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903
Tom Sepez3a6d0582018-08-17 19:28:52 +0000904CJS_Result CJS_Field::set_button_scale_when(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000905 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400906 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000907 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000908 return CJS_Result::Failure(JSMessage::kReadOnlyError);
909 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910}
911
Tom Sepez3a6d0582018-08-17 19:28:52 +0000912CJS_Result CJS_Field::get_calc_order_index(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700913 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914
Lei Zhang4c7ad662018-07-12 20:29:40 +0000915 CPDF_FormField* pFormField = GetFirstFormField();
916 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000917 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700918
Lei Zhang83f2d702018-07-12 19:07:40 +0000919 if (!IsComboBoxOrTextField(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +0000920 return CJS_Result::Failure(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700921
dan sinclair646634b2017-10-19 14:30:28 -0400922 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
923 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000924 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>(
Dan Sinclaire4974922017-10-24 09:36:16 -0400925 pInterForm->FindFieldInCalculationOrder(pFormField))));
dan sinclaircbe23db2017-10-19 14:29:33 -0400926}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700927
Tom Sepez3a6d0582018-08-17 19:28:52 +0000928CJS_Result CJS_Field::set_calc_order_index(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000929 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400930 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000931 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000932 return CJS_Result::Failure(JSMessage::kReadOnlyError);
933 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934}
935
Tom Sepez3a6d0582018-08-17 19:28:52 +0000936CJS_Result CJS_Field::get_char_limit(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700937 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700938
Lei Zhang4c7ad662018-07-12 20:29:40 +0000939 CPDF_FormField* pFormField = GetFirstFormField();
940 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000941 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700942
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000943 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000944 return CJS_Result::Failure(JSMessage::kObjectTypeError);
945 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -0400946 pRuntime->NewNumber(static_cast<int32_t>(pFormField->GetMaxLen())));
dan sinclaircbe23db2017-10-19 14:29:33 -0400947}
948
Tom Sepez3a6d0582018-08-17 19:28:52 +0000949CJS_Result CJS_Field::set_char_limit(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000950 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400951 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000952 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000953 return CJS_Result::Failure(JSMessage::kReadOnlyError);
954 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700956
Tom Sepez3a6d0582018-08-17 19:28:52 +0000957CJS_Result CJS_Field::get_comb(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700958 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700959
Lei Zhang4c7ad662018-07-12 20:29:40 +0000960 CPDF_FormField* pFormField = GetFirstFormField();
961 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000962 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700963
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000964 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000965 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966
Tom Sepez3a6d0582018-08-17 19:28:52 +0000967 return CJS_Result::Success(
Dan Sinclaire4974922017-10-24 09:36:16 -0400968 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMB)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400969}
970
Tom Sepez3a6d0582018-08-17 19:28:52 +0000971CJS_Result CJS_Field::set_comb(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400972 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000973 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000974 return CJS_Result::Failure(JSMessage::kReadOnlyError);
975 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976}
977
Tom Sepez3a6d0582018-08-17 19:28:52 +0000978CJS_Result CJS_Field::get_commit_on_sel_change(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -0700979 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980
Lei Zhang4c7ad662018-07-12 20:29:40 +0000981 CPDF_FormField* pFormField = GetFirstFormField();
982 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000983 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984
Lei Zhang83f2d702018-07-12 19:07:40 +0000985 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +0000986 return CJS_Result::Failure(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700987
Tom Sepez3a6d0582018-08-17 19:28:52 +0000988 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -0400989 !!(pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400990}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700991
Tom Sepez3a6d0582018-08-17 19:28:52 +0000992CJS_Result CJS_Field::set_commit_on_sel_change(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000993 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400994 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +0000995 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000996 return CJS_Result::Failure(JSMessage::kReadOnlyError);
997 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700998}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700999
Tom Sepez3a6d0582018-08-17 19:28:52 +00001000CJS_Result CJS_Field::get_current_value_indices(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001001 CPDF_FormField* pFormField = GetFirstFormField();
1002 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001003 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001004
Lei Zhang83f2d702018-07-12 19:07:40 +00001005 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001006 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007
dan sinclaircbe23db2017-10-19 14:29:33 -04001008 int count = pFormField->CountSelectedItems();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001009 if (count <= 0)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001010 return CJS_Result::Success(pRuntime->NewNumber(-1));
Dan Sinclair8f524d62017-10-25 13:30:31 -04001011 if (count == 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001012 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +00001013 pRuntime->NewNumber(pFormField->GetSelectedIndex(0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001014
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001015 v8::Local<v8::Array> SelArray = pRuntime->NewArray();
1016 for (int i = 0; i < count; i++) {
1017 pRuntime->PutArrayElement(
1018 SelArray, i, pRuntime->NewNumber(pFormField->GetSelectedIndex(i)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001019 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001020 if (SelArray.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001021 return CJS_Result::Success(pRuntime->NewArray());
1022 return CJS_Result::Success(SelArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001023}
1024
Tom Sepez3a6d0582018-08-17 19:28:52 +00001025CJS_Result CJS_Field::set_current_value_indices(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001026 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001027 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001028 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001029
1030 std::vector<uint32_t> array;
dan sinclair80435cb2017-10-24 21:40:24 -04001031 if (vp->IsNumber()) {
1032 array.push_back(pRuntime->ToInt32(vp));
1033 } else if (!vp.IsEmpty() && vp->IsArray()) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001034 v8::Local<v8::Array> SelArray = pRuntime->ToArray(vp);
1035 for (size_t i = 0; i < pRuntime->GetArrayLength(SelArray); i++) {
1036 array.push_back(
1037 pRuntime->ToInt32(pRuntime->GetArrayElement(SelArray, i)));
1038 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001039 }
1040
dan sinclaircbe23db2017-10-19 14:29:33 -04001041 if (m_bDelay) {
1042 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1043 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001044 SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
1045 m_nFormControlIndex, array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001046 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001047 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001048}
1049
Tom Sepez3a6d0582018-08-17 19:28:52 +00001050CJS_Result CJS_Field::get_default_style(CJS_Runtime* pRuntime) {
1051 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001052}
1053
Tom Sepez3a6d0582018-08-17 19:28:52 +00001054CJS_Result CJS_Field::set_default_style(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001055 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001056 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001057}
1058
Tom Sepez3a6d0582018-08-17 19:28:52 +00001059CJS_Result CJS_Field::get_default_value(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001060 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001061
Lei Zhang4c7ad662018-07-12 20:29:40 +00001062 CPDF_FormField* pFormField = GetFirstFormField();
1063 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001064 return CJS_Result::Failure(JSMessage::kBadObjectError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001065
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001066 if (pFormField->GetFieldType() == FormFieldType::kPushButton ||
1067 pFormField->GetFieldType() == FormFieldType::kSignature) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001068 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001069 }
1070
Tom Sepez3a6d0582018-08-17 19:28:52 +00001071 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001072 pRuntime->NewString(pFormField->GetDefaultValue().AsStringView()));
Dan Sinclair8f524d62017-10-25 13:30:31 -04001073}
1074
Tom Sepez3a6d0582018-08-17 19:28:52 +00001075CJS_Result CJS_Field::set_default_value(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001076 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001077 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001078 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001079 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1080 return CJS_Result::Success();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001081}
1082
Tom Sepez3a6d0582018-08-17 19:28:52 +00001083CJS_Result CJS_Field::get_do_not_scroll(CJS_Runtime* pRuntime) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001084 ASSERT(m_pFormFillEnv);
1085
Lei Zhang4c7ad662018-07-12 20:29:40 +00001086 CPDF_FormField* pFormField = GetFirstFormField();
1087 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001088 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001089
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001090 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001091 return CJS_Result::Failure(JSMessage::kObjectTypeError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001092
Tom Sepez3a6d0582018-08-17 19:28:52 +00001093 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001094 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001095}
1096
Tom Sepez3a6d0582018-08-17 19:28:52 +00001097CJS_Result CJS_Field::set_do_not_scroll(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001098 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001099 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001100 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001101 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1102 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001103}
1104
Tom Sepez3a6d0582018-08-17 19:28:52 +00001105CJS_Result CJS_Field::get_do_not_spell_check(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001106 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001107
Lei Zhang4c7ad662018-07-12 20:29:40 +00001108 CPDF_FormField* pFormField = GetFirstFormField();
1109 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001110 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001111
Lei Zhang83f2d702018-07-12 19:07:40 +00001112 if (!IsComboBoxOrTextField(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001113 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001114
Tom Sepez3a6d0582018-08-17 19:28:52 +00001115 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001116 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001117}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001118
Tom Sepez3a6d0582018-08-17 19:28:52 +00001119CJS_Result CJS_Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001120 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001121 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001122 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001123 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1124 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001125}
1126
Dan Sinclairf7435522018-02-05 22:27:22 +00001127void CJS_Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001128 m_bDelay = bDelay;
1129
dan sinclaircbe23db2017-10-19 14:29:33 -04001130 if (m_bDelay)
1131 return;
dan sinclaircbe23db2017-10-19 14:29:33 -04001132 if (m_pJSDoc)
1133 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001134}
1135
Tom Sepez3a6d0582018-08-17 19:28:52 +00001136CJS_Result CJS_Field::get_delay(CJS_Runtime* pRuntime) {
1137 return CJS_Result::Success(pRuntime->NewBoolean(m_bDelay));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001138}
1139
Tom Sepez3a6d0582018-08-17 19:28:52 +00001140CJS_Result CJS_Field::set_delay(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001141 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001142 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001143 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001144
dan sinclair80435cb2017-10-24 21:40:24 -04001145 SetDelay(pRuntime->ToBoolean(vp));
Tom Sepez3a6d0582018-08-17 19:28:52 +00001146 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001147}
1148
Tom Sepez3a6d0582018-08-17 19:28:52 +00001149CJS_Result CJS_Field::get_display(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001150 CPDF_FormField* pFormField = GetFirstFormField();
1151 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001152 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001153
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001154 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1155 CPDFSDK_Widget* pWidget =
1156 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1157 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001158 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001159
1160 uint32_t dwFlag = pWidget->GetFlags();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001161 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001162 return CJS_Result::Success(pRuntime->NewNumber(1));
Dan Sinclair8f524d62017-10-25 13:30:31 -04001163
dan sinclaircbe23db2017-10-19 14:29:33 -04001164 if (ANNOTFLAG_PRINT & dwFlag) {
1165 if (ANNOTFLAG_NOVIEW & dwFlag)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001166 return CJS_Result::Success(pRuntime->NewNumber(3));
1167 return CJS_Result::Success(pRuntime->NewNumber(0));
dan sinclaircbe23db2017-10-19 14:29:33 -04001168 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001169 return CJS_Result::Success(pRuntime->NewNumber(2));
dan sinclaircbe23db2017-10-19 14:29:33 -04001170}
1171
Tom Sepez3a6d0582018-08-17 19:28:52 +00001172CJS_Result CJS_Field::set_display(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001173 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001174 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001175 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001176
1177 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001178 AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001179 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001180 SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1181 pRuntime->ToInt32(vp));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001182 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001183 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001184}
1185
Tom Sepez3a6d0582018-08-17 19:28:52 +00001186CJS_Result CJS_Field::get_doc(CJS_Runtime* pRuntime) {
1187 return CJS_Result::Success(m_pJSDoc->ToV8Object());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001188}
1189
Tom Sepez3a6d0582018-08-17 19:28:52 +00001190CJS_Result CJS_Field::set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1191 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001192}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001193
Tom Sepez3a6d0582018-08-17 19:28:52 +00001194CJS_Result CJS_Field::get_editable(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001195 CPDF_FormField* pFormField = GetFirstFormField();
1196 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001197 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001198
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001199 if (pFormField->GetFieldType() != FormFieldType::kComboBox)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001200 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001201
Tom Sepez3a6d0582018-08-17 19:28:52 +00001202 return CJS_Result::Success(
Dan Sinclaire4974922017-10-24 09:36:16 -04001203 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001204}
1205
Tom Sepez3a6d0582018-08-17 19:28:52 +00001206CJS_Result CJS_Field::set_editable(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001207 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001208 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001209 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1210 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001211}
1212
Tom Sepez3a6d0582018-08-17 19:28:52 +00001213CJS_Result CJS_Field::get_export_values(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001214 CPDF_FormField* pFormField = GetFirstFormField();
1215 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001216 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001217
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001218 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001219 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001220
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001221 v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001222 if (m_nFormControlIndex < 0) {
1223 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1224 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001225 pRuntime->PutArrayElement(
1226 ExportValuesArray, i,
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001227 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001228 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001229 } else {
1230 if (m_nFormControlIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001231 return CJS_Result::Failure(JSMessage::kValueError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001232
1233 CPDF_FormControl* pFormControl =
1234 pFormField->GetControl(m_nFormControlIndex);
1235 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001236 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001237
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001238 pRuntime->PutArrayElement(
1239 ExportValuesArray, 0,
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001240 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001241 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001242 return CJS_Result::Success(ExportValuesArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001243}
1244
Tom Sepez3a6d0582018-08-17 19:28:52 +00001245CJS_Result CJS_Field::set_export_values(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001246 v8::Local<v8::Value> vp) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001247 CPDF_FormField* pFormField = GetFirstFormField();
1248 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001249 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001250
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001251 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001252 return CJS_Result::Failure(JSMessage::kObjectTypeError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001253
Tom Sepez16999822018-06-08 18:23:05 +00001254 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001255 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Tom Sepez16999822018-06-08 18:23:05 +00001256
1257 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001258 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001259
Tom Sepez3a6d0582018-08-17 19:28:52 +00001260 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001261}
1262
Tom Sepez3a6d0582018-08-17 19:28:52 +00001263CJS_Result CJS_Field::get_file_select(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001264 CPDF_FormField* pFormField = GetFirstFormField();
1265 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001266 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001267
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001268 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001269 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001270
Tom Sepez3a6d0582018-08-17 19:28:52 +00001271 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001272 !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001273}
1274
Tom Sepez3a6d0582018-08-17 19:28:52 +00001275CJS_Result CJS_Field::set_file_select(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001276 v8::Local<v8::Value> vp) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001277 CPDF_FormField* pFormField = GetFirstFormField();
1278 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001279 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001280
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001281 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001282 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepez16999822018-06-08 18:23:05 +00001283
1284 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001285 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Tom Sepez16999822018-06-08 18:23:05 +00001286
Tom Sepez3a6d0582018-08-17 19:28:52 +00001287 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001288}
1289
Tom Sepez3a6d0582018-08-17 19:28:52 +00001290CJS_Result CJS_Field::get_fill_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001291 CPDF_FormField* pFormField = GetFirstFormField();
1292 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001293 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001294
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001295 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1296 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001297 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001298
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001299 int iColorType;
1300 pFormControl->GetBackgroundColor(iColorType);
1301
Dan Sinclair7f55a542017-07-13 14:17:10 -04001302 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001303 if (iColorType == CFX_Color::kTransparent) {
1304 color = CFX_Color(CFX_Color::kTransparent);
1305 } else if (iColorType == CFX_Color::kGray) {
1306 color = CFX_Color(CFX_Color::kGray,
1307 pFormControl->GetOriginalBackgroundColor(0));
1308 } else if (iColorType == CFX_Color::kRGB) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001309 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001310 CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001311 pFormControl->GetOriginalBackgroundColor(1),
1312 pFormControl->GetOriginalBackgroundColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001313 } else if (iColorType == CFX_Color::kCMYK) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001314 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001315 CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001316 pFormControl->GetOriginalBackgroundColor(1),
1317 pFormControl->GetOriginalBackgroundColor(2),
1318 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001319 } else {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001320 return CJS_Result::Failure(JSMessage::kValueError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001321 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001322
Dan Sinclairf7435522018-02-05 22:27:22 +00001323 v8::Local<v8::Value> array =
1324 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001325 if (array.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001326 return CJS_Result::Success(pRuntime->NewArray());
1327 return CJS_Result::Success(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001328}
1329
Tom Sepez3a6d0582018-08-17 19:28:52 +00001330CJS_Result CJS_Field::set_fill_color(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001331 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001332 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001333 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001334 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001335 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001336 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001337 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001338 return CJS_Result::Failure(JSMessage::kBadObjectError);
1339 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001340}
1341
Tom Sepez3a6d0582018-08-17 19:28:52 +00001342CJS_Result CJS_Field::get_hidden(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001343 CPDF_FormField* pFormField = GetFirstFormField();
1344 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001345 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001346
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001347 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1348 CPDFSDK_Widget* pWidget =
1349 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1350 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001351 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001352
1353 uint32_t dwFlags = pWidget->GetFlags();
Tom Sepez3a6d0582018-08-17 19:28:52 +00001354 return CJS_Result::Success(pRuntime->NewBoolean(
Tom Sepez20736f72018-08-17 16:44:50 +00001355 ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags));
dan sinclaircbe23db2017-10-19 14:29:33 -04001356}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001357
Tom Sepez3a6d0582018-08-17 19:28:52 +00001358CJS_Result CJS_Field::set_hidden(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001359 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001360 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001361 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001362
1363 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001364 AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001365 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001366 SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1367 pRuntime->ToBoolean(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001368 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001369 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370}
1371
Tom Sepez3a6d0582018-08-17 19:28:52 +00001372CJS_Result CJS_Field::get_highlight(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001373 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001374
Lei Zhang4c7ad662018-07-12 20:29:40 +00001375 CPDF_FormField* pFormField = GetFirstFormField();
1376 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001377 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001378
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001379 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001380 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001381
1382 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1383 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001384 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001385
1386 int eHM = pFormControl->GetHighlightingMode();
1387 switch (eHM) {
1388 case CPDF_FormControl::None:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001389 return CJS_Result::Success(pRuntime->NewString(L"none"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001390 case CPDF_FormControl::Push:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001391 return CJS_Result::Success(pRuntime->NewString(L"push"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001392 case CPDF_FormControl::Invert:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001393 return CJS_Result::Success(pRuntime->NewString(L"invert"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001394 case CPDF_FormControl::Outline:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001395 return CJS_Result::Success(pRuntime->NewString(L"outline"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001396 case CPDF_FormControl::Toggle:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001397 return CJS_Result::Success(pRuntime->NewString(L"toggle"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001398 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001399 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001400}
1401
Tom Sepez3a6d0582018-08-17 19:28:52 +00001402CJS_Result CJS_Field::set_highlight(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001403 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001404 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001405 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001406 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1407 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001408}
1409
Tom Sepez3a6d0582018-08-17 19:28:52 +00001410CJS_Result CJS_Field::get_line_width(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001411 CPDF_FormField* pFormField = GetFirstFormField();
1412 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001413 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001414
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001415 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1416 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001417 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001418
1419 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1420 if (!pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001421 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001422
1423 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1424 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001425 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001426
Tom Sepez3a6d0582018-08-17 19:28:52 +00001427 return CJS_Result::Success(pRuntime->NewNumber(pWidget->GetBorderWidth()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001428}
1429
Tom Sepez3a6d0582018-08-17 19:28:52 +00001430CJS_Result CJS_Field::set_line_width(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001431 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001432 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001433 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001434
1435 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001436 AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001437 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001438 SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1439 pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001440 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001441 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001442}
1443
Tom Sepez3a6d0582018-08-17 19:28:52 +00001444CJS_Result CJS_Field::get_multiline(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001445 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446
Lei Zhang4c7ad662018-07-12 20:29:40 +00001447 CPDF_FormField* pFormField = GetFirstFormField();
1448 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001449 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001450
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001451 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001452 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001453
Tom Sepez3a6d0582018-08-17 19:28:52 +00001454 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001455 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001456}
1457
Tom Sepez3a6d0582018-08-17 19:28:52 +00001458CJS_Result CJS_Field::set_multiline(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001459 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001460 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001461 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001462 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1463 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001464}
1465
Tom Sepez3a6d0582018-08-17 19:28:52 +00001466CJS_Result CJS_Field::get_multiple_selection(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001467 ASSERT(m_pFormFillEnv);
Lei Zhang4c7ad662018-07-12 20:29:40 +00001468 CPDF_FormField* pFormField = GetFirstFormField();
1469 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001470 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001471
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001472 if (pFormField->GetFieldType() != FormFieldType::kListBox)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001473 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001474
Tom Sepez3a6d0582018-08-17 19:28:52 +00001475 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001476 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001477}
1478
Tom Sepez3a6d0582018-08-17 19:28:52 +00001479CJS_Result CJS_Field::set_multiple_selection(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001480 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001481 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001482 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001483 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1484 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001485}
1486
Tom Sepez3a6d0582018-08-17 19:28:52 +00001487CJS_Result CJS_Field::get_name(CJS_Runtime* pRuntime) {
Lei Zhang18915232018-07-12 20:53:40 +00001488 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08001489 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001490 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491
Tom Sepez3a6d0582018-08-17 19:28:52 +00001492 return CJS_Result::Success(pRuntime->NewString(m_FieldName.AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001493}
1494
Tom Sepez3a6d0582018-08-17 19:28:52 +00001495CJS_Result CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1496 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001497}
Tom Sepez67fd5df2015-10-08 12:24:19 -07001498
Tom Sepez3a6d0582018-08-17 19:28:52 +00001499CJS_Result CJS_Field::get_num_items(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001500 CPDF_FormField* pFormField = GetFirstFormField();
1501 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001502 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001503
Lei Zhang83f2d702018-07-12 19:07:40 +00001504 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001505 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001506
Tom Sepez3a6d0582018-08-17 19:28:52 +00001507 return CJS_Result::Success(pRuntime->NewNumber(pFormField->CountOptions()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001508}
1509
Tom Sepez3a6d0582018-08-17 19:28:52 +00001510CJS_Result CJS_Field::set_num_items(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001511 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001512 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001513}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001514
Tom Sepez3a6d0582018-08-17 19:28:52 +00001515CJS_Result CJS_Field::get_page(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001516 CPDF_FormField* pFormField = GetFirstFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001517 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001518 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001519
tsepez8fa82792017-01-11 09:32:33 -08001520 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001521 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001522 if (widgets.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001523 return CJS_Result::Success(pRuntime->NewNumber(-1));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001524
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001525 v8::Local<v8::Array> PageArray = pRuntime->NewArray();
tsepez8fa82792017-01-11 09:32:33 -08001526 int i = 0;
1527 for (const auto& pObserved : widgets) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001528 if (!pObserved)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001529 return CJS_Result::Failure(JSMessage::kBadObjectError);
tsepez8fa82792017-01-11 09:32:33 -08001530
Tom Sepez4ef943b2018-07-26 19:06:06 +00001531 auto* pWidget = ToCPDFSDKWidget(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001532 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001533 if (!pPageView)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001534 return CJS_Result::Failure(JSMessage::kBadObjectError);
Lei Zhangd88a3642015-11-10 09:38:57 -08001535
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001536 pRuntime->PutArrayElement(
1537 PageArray, i,
dan sinclair80435cb2017-10-24 21:40:24 -04001538 pRuntime->NewNumber(static_cast<int32_t>(pPageView->GetPageIndex())));
tsepez8fa82792017-01-11 09:32:33 -08001539 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001540 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001541 return CJS_Result::Success(PageArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001542}
1543
Tom Sepez3a6d0582018-08-17 19:28:52 +00001544CJS_Result CJS_Field::set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1545 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001546}
1547
Tom Sepez3a6d0582018-08-17 19:28:52 +00001548CJS_Result CJS_Field::get_password(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001549 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001550
Lei Zhang4c7ad662018-07-12 20:29:40 +00001551 CPDF_FormField* pFormField = GetFirstFormField();
1552 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001553 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001554
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001555 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001556 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001557
Tom Sepez3a6d0582018-08-17 19:28:52 +00001558 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001559 !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001560}
1561
Tom Sepez3a6d0582018-08-17 19:28:52 +00001562CJS_Result CJS_Field::set_password(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001563 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001564 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001565 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001566 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1567 return CJS_Result::Success();
dan sinclair646634b2017-10-19 14:30:28 -04001568}
dan sinclaircbe23db2017-10-19 14:29:33 -04001569
Tom Sepez3a6d0582018-08-17 19:28:52 +00001570CJS_Result CJS_Field::get_print(CJS_Runtime* pRuntime) {
dan sinclair646634b2017-10-19 14:30:28 -04001571 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhang4c7ad662018-07-12 20:29:40 +00001572 CPDF_FormField* pFormField = GetFirstFormField();
1573 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001574 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001575
dan sinclair646634b2017-10-19 14:30:28 -04001576 CPDFSDK_Widget* pWidget =
1577 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1578 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001579 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001580
Tom Sepez3a6d0582018-08-17 19:28:52 +00001581 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -04001582 pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001583}
1584
Tom Sepez3a6d0582018-08-17 19:28:52 +00001585CJS_Result CJS_Field::set_print(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001586 v8::Local<v8::Value> vp) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001587 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhang18915232018-07-12 20:53:40 +00001588 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08001589 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001590 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001591
Dan Sinclair8f524d62017-10-25 13:30:31 -04001592 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001593 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001594
Dan Sinclair8f524d62017-10-25 13:30:31 -04001595 for (CPDF_FormField* pFormField : FieldArray) {
1596 if (m_nFormControlIndex < 0) {
1597 bool bSet = false;
1598 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1599 if (CPDFSDK_Widget* pWidget =
1600 pInterForm->GetWidget(pFormField->GetControl(i))) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001601 uint32_t dwFlags = pWidget->GetFlags();
dan sinclair80435cb2017-10-24 21:40:24 -04001602 if (pRuntime->ToBoolean(vp))
dan sinclaircbe23db2017-10-19 14:29:33 -04001603 dwFlags |= ANNOTFLAG_PRINT;
1604 else
1605 dwFlags &= ~ANNOTFLAG_PRINT;
1606
1607 if (dwFlags != pWidget->GetFlags()) {
1608 pWidget->SetFlags(dwFlags);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001609 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001610 }
1611 }
1612 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001613
1614 if (bSet)
1615 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
1616
1617 continue;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001618 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001619
1620 if (m_nFormControlIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001621 return CJS_Result::Failure(JSMessage::kValueError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001622
1623 if (CPDF_FormControl* pFormControl =
1624 pFormField->GetControl(m_nFormControlIndex)) {
1625 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1626 uint32_t dwFlags = pWidget->GetFlags();
1627 if (pRuntime->ToBoolean(vp))
1628 dwFlags |= ANNOTFLAG_PRINT;
1629 else
1630 dwFlags &= ~ANNOTFLAG_PRINT;
1631
1632 if (dwFlags != pWidget->GetFlags()) {
1633 pWidget->SetFlags(dwFlags);
1634 UpdateFormControl(m_pFormFillEnv.Get(),
1635 pFormField->GetControl(m_nFormControlIndex), true,
1636 false, true);
1637 }
1638 }
1639 }
1640 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001641 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001642}
1643
Tom Sepez3a6d0582018-08-17 19:28:52 +00001644CJS_Result CJS_Field::get_radios_in_unison(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001645 CPDF_FormField* pFormField = GetFirstFormField();
1646 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001647 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001648
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001649 if (pFormField->GetFieldType() != FormFieldType::kRadioButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001650 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001651
Tom Sepez3a6d0582018-08-17 19:28:52 +00001652 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001653 !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001654}
1655
Tom Sepez3a6d0582018-08-17 19:28:52 +00001656CJS_Result CJS_Field::set_radios_in_unison(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001657 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001658 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001659 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001660 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001661 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001662 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1663 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001664}
1665
Tom Sepez3a6d0582018-08-17 19:28:52 +00001666CJS_Result CJS_Field::get_readonly(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001667 CPDF_FormField* pFormField = GetFirstFormField();
1668 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001669 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001670
Tom Sepez3a6d0582018-08-17 19:28:52 +00001671 return CJS_Result::Success(pRuntime->NewBoolean(
Lei Zhang4c7ad662018-07-12 20:29:40 +00001672 !!(pFormField->GetFieldFlags() & FIELDFLAG_READONLY)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001673}
1674
Tom Sepez3a6d0582018-08-17 19:28:52 +00001675CJS_Result CJS_Field::set_readonly(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001676 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001677 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001678 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001679 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001680 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001681 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1682 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001683}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001684
Tom Sepez3a6d0582018-08-17 19:28:52 +00001685CJS_Result CJS_Field::get_rect(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001686 CPDF_FormField* pFormField = GetFirstFormField();
1687 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001688 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001689
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001690 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1691 CPDFSDK_Widget* pWidget =
1692 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1693 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001694 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001695
1696 CFX_FloatRect crRect = pWidget->GetRect();
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001697 v8::Local<v8::Array> rcArray = pRuntime->NewArray();
1698 pRuntime->PutArrayElement(
1699 rcArray, 0, pRuntime->NewNumber(static_cast<int32_t>(crRect.left)));
1700 pRuntime->PutArrayElement(
1701 rcArray, 1, pRuntime->NewNumber(static_cast<int32_t>(crRect.top)));
1702 pRuntime->PutArrayElement(
1703 rcArray, 2, pRuntime->NewNumber(static_cast<int32_t>(crRect.right)));
1704 pRuntime->PutArrayElement(
1705 rcArray, 3, pRuntime->NewNumber(static_cast<int32_t>(crRect.bottom)));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001706
Tom Sepez3a6d0582018-08-17 19:28:52 +00001707 return CJS_Result::Success(rcArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001708}
1709
Tom Sepez3a6d0582018-08-17 19:28:52 +00001710CJS_Result CJS_Field::set_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001711 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001712 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001713 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001714 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001715
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001716 v8::Local<v8::Array> rcArray = pRuntime->ToArray(vp);
1717 if (pRuntime->GetArrayLength(rcArray) < 4)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001718 return CJS_Result::Failure(JSMessage::kValueError);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001719
dan sinclaircbe23db2017-10-19 14:29:33 -04001720 float pArray[4];
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001721 pArray[0] = static_cast<float>(
1722 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 0)));
1723 pArray[1] = static_cast<float>(
1724 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 1)));
1725 pArray[2] = static_cast<float>(
1726 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 2)));
1727 pArray[3] = static_cast<float>(
1728 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 3)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001729
1730 CFX_FloatRect crRect(pArray);
1731 if (m_bDelay) {
1732 AddDelay_Rect(FP_RECT, crRect);
1733 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001734 SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, crRect);
dan sinclaircbe23db2017-10-19 14:29:33 -04001735 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001736 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001737}
1738
Tom Sepez3a6d0582018-08-17 19:28:52 +00001739CJS_Result CJS_Field::get_required(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001740 CPDF_FormField* pFormField = GetFirstFormField();
1741 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001742 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001743
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001744 if (pFormField->GetFieldType() == FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001745 return CJS_Result::Failure(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001746
Tom Sepez3a6d0582018-08-17 19:28:52 +00001747 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001748 !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001749}
1750
Tom Sepez3a6d0582018-08-17 19:28:52 +00001751CJS_Result CJS_Field::set_required(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001752 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001753 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001754 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001755 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001756 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001757 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1758 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001759}
1760
Tom Sepez3a6d0582018-08-17 19:28:52 +00001761CJS_Result CJS_Field::get_rich_text(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001762 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001763
Lei Zhang4c7ad662018-07-12 20:29:40 +00001764 CPDF_FormField* pFormField = GetFirstFormField();
1765 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001766 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001767
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001768 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001769 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001770
Tom Sepez3a6d0582018-08-17 19:28:52 +00001771 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001772 !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001773}
1774
Tom Sepez3a6d0582018-08-17 19:28:52 +00001775CJS_Result CJS_Field::set_rich_text(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001776 v8::Local<v8::Value> vp) {
dsinclair3a7741a2016-10-11 10:39:49 -07001777 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001778 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001779 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1780 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001781}
1782
Tom Sepez3a6d0582018-08-17 19:28:52 +00001783CJS_Result CJS_Field::get_rich_value(CJS_Runtime* pRuntime) {
1784 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001785}
1786
Tom Sepez3a6d0582018-08-17 19:28:52 +00001787CJS_Result CJS_Field::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001788 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001789 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001790}
1791
Tom Sepez3a6d0582018-08-17 19:28:52 +00001792CJS_Result CJS_Field::get_rotation(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001793 ASSERT(m_pFormFillEnv);
1794
Lei Zhang4c7ad662018-07-12 20:29:40 +00001795 CPDF_FormField* pFormField = GetFirstFormField();
1796 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001797 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001798
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001799 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1800 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001801 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001802
Tom Sepez3a6d0582018-08-17 19:28:52 +00001803 return CJS_Result::Success(pRuntime->NewNumber(pFormControl->GetRotation()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001804}
1805
Tom Sepez3a6d0582018-08-17 19:28:52 +00001806CJS_Result CJS_Field::set_rotation(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001807 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001808 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001809 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001810 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1811 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001812}
1813
Tom Sepez3a6d0582018-08-17 19:28:52 +00001814CJS_Result CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001815 CPDF_FormField* pFormField = GetFirstFormField();
1816 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001817 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001818
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001819 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1820 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001821 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001822
1823 int iColorType;
1824 pFormControl->GetBorderColor(iColorType);
1825
Dan Sinclair7f55a542017-07-13 14:17:10 -04001826 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001827 if (iColorType == CFX_Color::kTransparent) {
1828 color = CFX_Color(CFX_Color::kTransparent);
1829 } else if (iColorType == CFX_Color::kGray) {
1830 color =
1831 CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0));
1832 } else if (iColorType == CFX_Color::kRGB) {
1833 color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001834 pFormControl->GetOriginalBorderColor(1),
1835 pFormControl->GetOriginalBorderColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001836 } else if (iColorType == CFX_Color::kCMYK) {
1837 color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001838 pFormControl->GetOriginalBorderColor(1),
1839 pFormControl->GetOriginalBorderColor(2),
1840 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001841 } else {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001842 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001843 }
1844
Dan Sinclairf7435522018-02-05 22:27:22 +00001845 v8::Local<v8::Value> array =
1846 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001847 if (array.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001848 return CJS_Result::Success(pRuntime->NewArray());
1849 return CJS_Result::Success(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001850}
1851
Tom Sepez3a6d0582018-08-17 19:28:52 +00001852CJS_Result CJS_Field::set_stroke_color(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001853 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001854 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001855 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001856 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001857 return CJS_Result::Failure(JSMessage::kBadObjectError);
1858 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001859}
1860
Tom Sepez3a6d0582018-08-17 19:28:52 +00001861CJS_Result CJS_Field::get_style(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001862 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001863
Lei Zhang4c7ad662018-07-12 20:29:40 +00001864 CPDF_FormField* pFormField = GetFirstFormField();
1865 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001866 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001867
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001868 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001869 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001870
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001871 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1872 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001873 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001874
Ryan Harrison275e2602017-09-18 14:23:18 -04001875 WideString csWCaption = pFormControl->GetNormalCaption();
1876 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001877
1878 switch (csWCaption[0]) {
1879 case L'l':
1880 csBCaption = "circle";
1881 break;
1882 case L'8':
1883 csBCaption = "cross";
1884 break;
1885 case L'u':
1886 csBCaption = "diamond";
1887 break;
1888 case L'n':
1889 csBCaption = "square";
1890 break;
1891 case L'H':
1892 csBCaption = "star";
1893 break;
1894 default: // L'4'
1895 csBCaption = "check";
1896 break;
1897 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001898 return CJS_Result::Success(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001899 WideString::FromLocal(csBCaption.AsStringView()).AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001900}
1901
Tom Sepez3a6d0582018-08-17 19:28:52 +00001902CJS_Result CJS_Field::set_style(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001903 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001904 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001905 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001906 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1907 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001908}
1909
Tom Sepez3a6d0582018-08-17 19:28:52 +00001910CJS_Result CJS_Field::get_submit_name(CJS_Runtime* pRuntime) {
1911 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001912}
1913
Tom Sepez3a6d0582018-08-17 19:28:52 +00001914CJS_Result CJS_Field::set_submit_name(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001915 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001916 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001917}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001918
Tom Sepez3a6d0582018-08-17 19:28:52 +00001919CJS_Result CJS_Field::get_text_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001920 CPDF_FormField* pFormField = GetFirstFormField();
1921 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001922 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001923
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001924 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1925 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001926 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001927
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001928 Optional<CFX_Color::Type> iColorType;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001929 FX_ARGB color;
1930 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
Dan Sinclaira17a0e22018-03-28 21:10:35 +00001931 std::tie(iColorType, color) = FieldAppearance.GetColor();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001932
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001933 CFX_Color crRet;
1934 if (!iColorType || *iColorType == CFX_Color::kTransparent) {
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001935 crRet = CFX_Color(CFX_Color::kTransparent);
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001936 } else {
1937 int32_t a;
1938 int32_t r;
1939 int32_t g;
1940 int32_t b;
1941 std::tie(a, r, g, b) = ArgbDecode(color);
1942 crRet = CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
1943 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001944
Dan Sinclairf7435522018-02-05 22:27:22 +00001945 v8::Local<v8::Value> array =
1946 CJS_Color::ConvertPWLColorToArray(pRuntime, crRet);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001947 if (array.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001948 return CJS_Result::Success(pRuntime->NewArray());
1949 return CJS_Result::Success(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001950}
1951
Tom Sepez3a6d0582018-08-17 19:28:52 +00001952CJS_Result CJS_Field::set_text_color(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001953 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001954 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001955 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001956 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001957 return CJS_Result::Failure(JSMessage::kBadObjectError);
1958 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001959}
1960
Tom Sepez3a6d0582018-08-17 19:28:52 +00001961CJS_Result CJS_Field::get_text_font(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001962 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001963
Lei Zhang4c7ad662018-07-12 20:29:40 +00001964 CPDF_FormField* pFormField = GetFirstFormField();
1965 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001966 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001967
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001968 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1969 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001970 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001971
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001972 FormFieldType fieldType = pFormField->GetFieldType();
1973 if (fieldType != FormFieldType::kPushButton &&
1974 fieldType != FormFieldType::kComboBox &&
1975 fieldType != FormFieldType::kListBox &&
1976 fieldType != FormFieldType::kTextField) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001977 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001978 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001979
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001980 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
1981 if (!pFont)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001982 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001983
Tom Sepez3a6d0582018-08-17 19:28:52 +00001984 return CJS_Result::Success(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001985 WideString::FromLocal(pFont->GetBaseFont().AsStringView())
1986 .AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001987}
1988
Tom Sepez3a6d0582018-08-17 19:28:52 +00001989CJS_Result CJS_Field::set_text_font(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001990 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001991 ASSERT(m_pFormFillEnv);
1992
dan sinclair646634b2017-10-19 14:30:28 -04001993 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001994 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Tom Sepez34dab072018-08-08 17:49:02 +00001995 if (pRuntime->ToWideString(vp).ToDefANSI().IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001996 return CJS_Result::Failure(JSMessage::kValueError);
1997 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001998}
1999
Tom Sepez3a6d0582018-08-17 19:28:52 +00002000CJS_Result CJS_Field::get_text_size(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07002001 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002002
Lei Zhang4c7ad662018-07-12 20:29:40 +00002003 CPDF_FormField* pFormField = GetFirstFormField();
2004 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002005 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002006
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002007 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2008 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002009 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002010
Dan Sinclair05df0752017-03-14 14:43:42 -04002011 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002012 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2013 FieldAppearance.GetFont(&fFontSize);
Tom Sepez3a6d0582018-08-17 19:28:52 +00002014 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int>(fFontSize)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002015}
2016
Tom Sepez3a6d0582018-08-17 19:28:52 +00002017CJS_Result CJS_Field::set_text_size(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002018 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002019 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00002020 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002021 return CJS_Result::Failure(JSMessage::kReadOnlyError);
2022 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002023}
2024
Tom Sepez3a6d0582018-08-17 19:28:52 +00002025CJS_Result CJS_Field::get_type(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002026 CPDF_FormField* pFormField = GetFirstFormField();
2027 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002028 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002029
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002030 switch (pFormField->GetFieldType()) {
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002031 case FormFieldType::kUnknown:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002032 return CJS_Result::Success(pRuntime->NewString(L"unknown"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002033 case FormFieldType::kPushButton:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002034 return CJS_Result::Success(pRuntime->NewString(L"button"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002035 case FormFieldType::kCheckBox:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002036 return CJS_Result::Success(pRuntime->NewString(L"checkbox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002037 case FormFieldType::kRadioButton:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002038 return CJS_Result::Success(pRuntime->NewString(L"radiobutton"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002039 case FormFieldType::kComboBox:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002040 return CJS_Result::Success(pRuntime->NewString(L"combobox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002041 case FormFieldType::kListBox:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002042 return CJS_Result::Success(pRuntime->NewString(L"listbox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002043 case FormFieldType::kTextField:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002044 return CJS_Result::Success(pRuntime->NewString(L"text"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002045 case FormFieldType::kSignature:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002046 return CJS_Result::Success(pRuntime->NewString(L"signature"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002047 default:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002048 return CJS_Result::Success(pRuntime->NewString(L"unknown"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002049 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002050}
2051
Tom Sepez3a6d0582018-08-17 19:28:52 +00002052CJS_Result CJS_Field::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
2053 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002054}
2055
Tom Sepez3a6d0582018-08-17 19:28:52 +00002056CJS_Result CJS_Field::get_user_name(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07002057 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002058
Lei Zhang4c7ad662018-07-12 20:29:40 +00002059 CPDF_FormField* pFormField = GetFirstFormField();
2060 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002061 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002062
Tom Sepez3a6d0582018-08-17 19:28:52 +00002063 return CJS_Result::Success(
Lei Zhang4c7ad662018-07-12 20:29:40 +00002064 pRuntime->NewString(pFormField->GetAlternateName().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002065}
2066
Tom Sepez3a6d0582018-08-17 19:28:52 +00002067CJS_Result CJS_Field::set_user_name(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002068 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002069 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00002070 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002071 return CJS_Result::Failure(JSMessage::kReadOnlyError);
2072 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002073}
2074
Tom Sepez3a6d0582018-08-17 19:28:52 +00002075CJS_Result CJS_Field::get_value(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002076 CPDF_FormField* pFormField = GetFirstFormField();
2077 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002078 return CJS_Result::Failure(JSMessage::kBadObjectError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04002079
2080 v8::Local<v8::Value> ret;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002081 switch (pFormField->GetFieldType()) {
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002082 case FormFieldType::kPushButton:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002083 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002084 case FormFieldType::kComboBox:
2085 case FormFieldType::kTextField:
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002086 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
dan sinclaircbe23db2017-10-19 14:29:33 -04002087 break;
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002088 case FormFieldType::kListBox: {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002089 if (pFormField->CountSelectedItems() > 1) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002090 v8::Local<v8::Array> ValueArray = pRuntime->NewArray();
dan sinclair80435cb2017-10-24 21:40:24 -04002091 v8::Local<v8::Value> ElementValue;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002092 int iIndex;
2093 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2094 iIndex = pFormField->GetSelectedIndex(i);
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002095 ElementValue = pRuntime->NewString(
2096 pFormField->GetOptionValue(iIndex).AsStringView());
dan sinclair80435cb2017-10-24 21:40:24 -04002097 if (wcslen(pRuntime->ToWideString(ElementValue).c_str()) == 0) {
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002098 ElementValue = pRuntime->NewString(
2099 pFormField->GetOptionLabel(iIndex).AsStringView());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002100 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002101 pRuntime->PutArrayElement(ValueArray, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002102 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002103 ret = ValueArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002104 } else {
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002105 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002106 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002107 break;
2108 }
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002109 case FormFieldType::kCheckBox:
2110 case FormFieldType::kRadioButton: {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002111 bool bFind = false;
2112 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2113 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002114 ret = pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002115 pFormField->GetControl(i)->GetExportValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002116 bFind = true;
2117 break;
2118 }
2119 }
2120 if (!bFind)
Dan Sinclair8f524d62017-10-25 13:30:31 -04002121 ret = pRuntime->NewString(L"Off");
dan sinclaircbe23db2017-10-19 14:29:33 -04002122
2123 break;
2124 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002125 default:
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002126 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002127 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002128 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002129 return CJS_Result::Success(pRuntime->MaybeCoerceToNumber(ret));
dan sinclaircbe23db2017-10-19 14:29:33 -04002130}
2131
Tom Sepez3a6d0582018-08-17 19:28:52 +00002132CJS_Result CJS_Field::set_value(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002133 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002134 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002135 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002136
2137 std::vector<WideString> strArray;
dan sinclair80435cb2017-10-24 21:40:24 -04002138 if (!vp.IsEmpty() && vp->IsArray()) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002139 v8::Local<v8::Array> ValueArray = pRuntime->ToArray(vp);
2140 for (size_t i = 0; i < pRuntime->GetArrayLength(ValueArray); i++) {
dan sinclair80435cb2017-10-24 21:40:24 -04002141 strArray.push_back(
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002142 pRuntime->ToWideString(pRuntime->GetArrayElement(ValueArray, i)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002143 }
2144 } else {
dan sinclair80435cb2017-10-24 21:40:24 -04002145 strArray.push_back(pRuntime->ToWideString(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04002146 }
2147
2148 if (m_bDelay) {
2149 AddDelay_WideStringArray(FP_VALUE, strArray);
2150 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00002151 SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, strArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04002152 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002153 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002154}
2155
Tom Sepez3a6d0582018-08-17 19:28:52 +00002156CJS_Result CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002157 CPDF_FormField* pFormField = GetFirstFormField();
2158 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002159 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002160
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002161 if (pFormField->GetFieldType() == FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002162 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002163
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002164 if (pFormField->GetFieldType() == FormFieldType::kCheckBox) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002165 if (!pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002166 return CJS_Result::Failure(JSMessage::kBadObjectError);
2167 return CJS_Result::Success(pRuntime->NewString(
Dan Sinclaire4974922017-10-24 09:36:16 -04002168 pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002169 }
2170
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002171 if (pFormField->GetFieldType() == FormFieldType::kRadioButton &&
dan sinclaircbe23db2017-10-19 14:29:33 -04002172 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002173 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2174 if (pFormField->GetControl(i)->IsChecked()) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002175 return CJS_Result::Success(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002176 pFormField->GetControl(i)->GetExportValue().AsStringView()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002177 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002178 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002179 return CJS_Result::Success(pRuntime->NewString(L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002180 }
2181
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002182 if (pFormField->GetFieldType() == FormFieldType::kListBox &&
dan sinclaircbe23db2017-10-19 14:29:33 -04002183 (pFormField->CountSelectedItems() > 1)) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002184 return CJS_Result::Success(pRuntime->NewString(L""));
Lei Zhangd88a3642015-11-10 09:38:57 -08002185 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002186 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +00002187 pRuntime->NewString(pFormField->GetValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002188}
2189
Tom Sepez3a6d0582018-08-17 19:28:52 +00002190CJS_Result CJS_Field::set_value_as_string(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002191 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002192 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002193}
2194
Tom Sepez3a6d0582018-08-17 19:28:52 +00002195CJS_Result CJS_Field::browseForFileToSubmit(
dan sinclair80435cb2017-10-24 21:40:24 -04002196 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002197 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002198 CPDF_FormField* pFormField = GetFirstFormField();
2199 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002200 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002201
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002202 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002203 (pFormField->GetFieldType() == FormFieldType::kTextField)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002204 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002205 if (!wsFileName.IsEmpty()) {
Tom Sepezb2e6b4c2018-08-16 20:53:58 +00002206 pFormField->SetValue(wsFileName, NotificationOption::kDoNotNotify);
tsepez4cf55152016-11-02 14:37:54 -07002207 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002208 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002209 return CJS_Result::Success();
Lei Zhangd88a3642015-11-10 09:38:57 -08002210 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002211 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002212}
2213
Tom Sepez3a6d0582018-08-17 19:28:52 +00002214CJS_Result CJS_Field::buttonGetCaption(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002215 CJS_Runtime* pRuntime,
2216 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002217 int nface = 0;
2218 int iSize = params.size();
2219 if (iSize >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002220 nface = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002221
Lei Zhang4c7ad662018-07-12 20:29:40 +00002222 CPDF_FormField* pFormField = GetFirstFormField();
2223 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002224 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002225
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002226 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002227 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002228
2229 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2230 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002231 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002232
Dan Sinclair8f524d62017-10-25 13:30:31 -04002233 if (nface == 0) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002234 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002235 pRuntime->NewString(pFormControl->GetNormalCaption().AsStringView()));
2236 }
2237 if (nface == 1) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002238 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002239 pRuntime->NewString(pFormControl->GetDownCaption().AsStringView()));
2240 }
2241 if (nface == 2) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002242 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002243 pRuntime->NewString(pFormControl->GetRolloverCaption().AsStringView()));
Dan Sinclair8f524d62017-10-25 13:30:31 -04002244 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002245 return CJS_Result::Failure(JSMessage::kValueError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002246}
2247
Tom Sepez3a6d0582018-08-17 19:28:52 +00002248CJS_Result CJS_Field::buttonGetIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002249 CJS_Runtime* pRuntime,
2250 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002251 if (params.size() >= 1) {
dan sinclair80435cb2017-10-24 21:40:24 -04002252 int nFace = pRuntime->ToInt32(params[0]);
Tom Sepez40e0a812017-02-23 13:07:36 -08002253 if (nFace < 0 || nFace > 2)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002254 return CJS_Result::Failure(JSMessage::kValueError);
Tom Sepez40e0a812017-02-23 13:07:36 -08002255 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002256
Lei Zhang4c7ad662018-07-12 20:29:40 +00002257 CPDF_FormField* pFormField = GetFirstFormField();
2258 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002259 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002260
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002261 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002262 return CJS_Result::Failure(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002263
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002264 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2265 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002266 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002267
Tom Sepez55ccb522018-08-14 23:40:10 +00002268 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2269 CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -08002270 if (pObj.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002271 return CJS_Result::Failure(JSMessage::kBadObjectError);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002272
Tom Sepezddaa40f2018-06-06 18:30:15 +00002273 auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
Tom Sepez3a6d0582018-08-17 19:28:52 +00002274 return pJS_Icon ? CJS_Result::Success(pJS_Icon->ToV8Object())
2275 : CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002276}
2277
Tom Sepez3a6d0582018-08-17 19:28:52 +00002278CJS_Result CJS_Field::buttonImportIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002279 CJS_Runtime* pRuntime,
2280 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002281 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002282}
2283
Tom Sepez3a6d0582018-08-17 19:28:52 +00002284CJS_Result CJS_Field::buttonSetCaption(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002285 CJS_Runtime* pRuntime,
2286 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002287 return CJS_Result::Failure(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -07002288}
2289
Tom Sepez3a6d0582018-08-17 19:28:52 +00002290CJS_Result CJS_Field::buttonSetIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002291 CJS_Runtime* pRuntime,
2292 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002293 return CJS_Result::Failure(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -07002294}
2295
Tom Sepez3a6d0582018-08-17 19:28:52 +00002296CJS_Result CJS_Field::checkThisBox(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002297 CJS_Runtime* pRuntime,
2298 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002299 int iSize = params.size();
2300 if (iSize < 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002301 return CJS_Result::Failure(JSMessage::kParamError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002302
tsepezf3dc8c62016-08-10 06:29:29 -07002303 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002304 return CJS_Result::Failure(JSMessage::kReadOnlyError);
tsepezf3dc8c62016-08-10 06:29:29 -07002305
dan sinclair80435cb2017-10-24 21:40:24 -04002306 int nWidget = pRuntime->ToInt32(params[0]);
Wei Li97da9762016-03-11 17:00:48 -08002307 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002308 if (iSize >= 2)
dan sinclair80435cb2017-10-24 21:40:24 -04002309 bCheckit = pRuntime->ToBoolean(params[1]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002310
Lei Zhang4c7ad662018-07-12 20:29:40 +00002311 CPDF_FormField* pFormField = GetFirstFormField();
2312 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002313 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002314
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002315 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00002316 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezb2e6b4c2018-08-16 20:53:58 +00002317
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002318 if (nWidget < 0 || nWidget >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002319 return CJS_Result::Failure(JSMessage::kValueError);
Lei Zhangbc486922018-01-29 15:30:46 +00002320
2321 // TODO(weili): Check whether anything special needed for radio button.
2322 // (When pFormField->GetFieldType() == FormFieldType::kRadioButton.)
Tom Sepezb2e6b4c2018-08-16 20:53:58 +00002323 pFormField->CheckControl(nWidget, bCheckit, NotificationOption::kNotify);
tsepez4cf55152016-11-02 14:37:54 -07002324 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Tom Sepez3a6d0582018-08-17 19:28:52 +00002325 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002326}
2327
Tom Sepez3a6d0582018-08-17 19:28:52 +00002328CJS_Result CJS_Field::clearItems(
Dan Sinclairf7435522018-02-05 22:27:22 +00002329 CJS_Runtime* pRuntime,
2330 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002331 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002332}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002333
Tom Sepez3a6d0582018-08-17 19:28:52 +00002334CJS_Result CJS_Field::defaultIsChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002335 CJS_Runtime* pRuntime,
2336 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002337 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002338 return CJS_Result::Failure(JSMessage::kReadOnlyError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002339
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002340 int iSize = params.size();
2341 if (iSize < 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002342 return CJS_Result::Failure(JSMessage::kParamError);
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002343
Lei Zhang4c7ad662018-07-12 20:29:40 +00002344 CPDF_FormField* pFormField = GetFirstFormField();
2345 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002346 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002347
Lei Zhang4c7ad662018-07-12 20:29:40 +00002348 int nWidget = pRuntime->ToInt32(params[0]);
tsepezf3dc8c62016-08-10 06:29:29 -07002349 if (nWidget < 0 || nWidget >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002350 return CJS_Result::Failure(JSMessage::kValueError);
tsepezf3dc8c62016-08-10 06:29:29 -07002351
Tom Sepez3a6d0582018-08-17 19:28:52 +00002352 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +00002353 pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002354}
2355
Tom Sepez3a6d0582018-08-17 19:28:52 +00002356CJS_Result CJS_Field::deleteItemAt(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002357 CJS_Runtime* pRuntime,
2358 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002359 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002360}
2361
Tom Sepez3a6d0582018-08-17 19:28:52 +00002362CJS_Result CJS_Field::getArray(
Dan Sinclairf7435522018-02-05 22:27:22 +00002363 CJS_Runtime* pRuntime,
2364 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang18915232018-07-12 20:53:40 +00002365 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08002366 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002367 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002368
Ryan Harrison275e2602017-09-18 14:23:18 -04002369 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002370 for (CPDF_FormField* pFormField : FieldArray) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002371 swSort.push_back(pdfium::MakeUnique<WideString>(pFormField->GetFullName()));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002372 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002373
Ryan Harrison275e2602017-09-18 14:23:18 -04002374 std::sort(swSort.begin(), swSort.end(),
2375 [](const std::unique_ptr<WideString>& p1,
2376 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002377
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002378 v8::Local<v8::Array> FormFieldArray = pRuntime->NewArray();
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002379 int j = 0;
2380 for (const auto& pStr : swSort) {
Tom Sepez55ccb522018-08-14 23:40:10 +00002381 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2382 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -08002383 if (pObj.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002384 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002385
Tom Sepezddaa40f2018-06-06 18:30:15 +00002386 auto* pJSField =
2387 static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pObj));
Tom Sepez2cbae732018-06-26 15:11:28 +00002388 pJSField->AttachField(m_pJSDoc.Get(), *pStr);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002389 pRuntime->PutArrayElement(FormFieldArray, j++,
dan sinclair80435cb2017-10-24 21:40:24 -04002390 pJSField
2391 ? v8::Local<v8::Value>(pJSField->ToV8Object())
2392 : v8::Local<v8::Value>());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002393 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002394 return CJS_Result::Success(FormFieldArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002395}
2396
Tom Sepez3a6d0582018-08-17 19:28:52 +00002397CJS_Result CJS_Field::getItemAt(
Dan Sinclairf7435522018-02-05 22:27:22 +00002398 CJS_Runtime* pRuntime,
2399 const std::vector<v8::Local<v8::Value>>& params) {
tsepezf3dc8c62016-08-10 06:29:29 -07002400 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002401 int nIdx = -1;
2402 if (iSize >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002403 nIdx = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002404
tsepez4cf55152016-11-02 14:37:54 -07002405 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002406 if (iSize >= 2)
dan sinclair80435cb2017-10-24 21:40:24 -04002407 bExport = pRuntime->ToBoolean(params[1]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408
Lei Zhang4c7ad662018-07-12 20:29:40 +00002409 CPDF_FormField* pFormField = GetFirstFormField();
2410 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002411 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002412
Lei Zhang83f2d702018-07-12 19:07:40 +00002413 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00002414 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Lei Zhang83f2d702018-07-12 19:07:40 +00002415
2416 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2417 nIdx = pFormField->CountOptions() - 1;
2418 if (!bExport) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002419 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002420 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002421 }
Lei Zhang83f2d702018-07-12 19:07:40 +00002422
2423 WideString strval = pFormField->GetOptionValue(nIdx);
2424 if (strval.IsEmpty()) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002425 return CJS_Result::Success(
Lei Zhang83f2d702018-07-12 19:07:40 +00002426 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
2427 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002428 return CJS_Result::Success(pRuntime->NewString(strval.AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002429}
2430
Tom Sepez3a6d0582018-08-17 19:28:52 +00002431CJS_Result CJS_Field::getLock(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002432 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002433 return CJS_Result::Failure(JSMessage::kNotSupportedError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002434}
2435
Tom Sepez3a6d0582018-08-17 19:28:52 +00002436CJS_Result CJS_Field::insertItemAt(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002437 CJS_Runtime* pRuntime,
2438 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002439 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002440}
2441
Tom Sepez3a6d0582018-08-17 19:28:52 +00002442CJS_Result CJS_Field::isBoxChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002443 CJS_Runtime* pRuntime,
2444 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002445 int nIndex = -1;
2446 if (params.size() >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002447 nIndex = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002448
Lei Zhang4c7ad662018-07-12 20:29:40 +00002449 CPDF_FormField* pFormField = GetFirstFormField();
2450 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002451 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002452
dan sinclair646634b2017-10-19 14:30:28 -04002453 if (nIndex < 0 || nIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002454 return CJS_Result::Failure(JSMessage::kValueError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002455
Tom Sepez3a6d0582018-08-17 19:28:52 +00002456 return CJS_Result::Success(
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002457 pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) &&
2458 pFormField->GetControl(nIndex)->IsChecked() != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002459}
2460
Tom Sepez3a6d0582018-08-17 19:28:52 +00002461CJS_Result CJS_Field::isDefaultChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002462 CJS_Runtime* pRuntime,
2463 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002464 int nIndex = -1;
2465 if (params.size() >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002466 nIndex = pRuntime->ToInt32(params[0]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002467
Lei Zhang4c7ad662018-07-12 20:29:40 +00002468 CPDF_FormField* pFormField = GetFirstFormField();
2469 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002470 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002471
tsepezf3dc8c62016-08-10 06:29:29 -07002472 if (nIndex < 0 || nIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002473 return CJS_Result::Failure(JSMessage::kValueError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002474
Tom Sepez3a6d0582018-08-17 19:28:52 +00002475 return CJS_Result::Success(pRuntime->NewBoolean(
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002476 (IsCheckBoxOrRadioButton(pFormField) &&
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002477 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002478}
2479
Tom Sepez3a6d0582018-08-17 19:28:52 +00002480CJS_Result CJS_Field::setAction(
Dan Sinclairf7435522018-02-05 22:27:22 +00002481 CJS_Runtime* pRuntime,
2482 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002483 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002484}
2485
Tom Sepez3a6d0582018-08-17 19:28:52 +00002486CJS_Result CJS_Field::setFocus(
Dan Sinclairf7435522018-02-05 22:27:22 +00002487 CJS_Runtime* pRuntime,
2488 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002489 CPDF_FormField* pFormField = GetFirstFormField();
2490 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002491 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002492
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002493 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002494 if (nCount < 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002495 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002496
dsinclair7cbe68e2016-10-12 11:56:23 -07002497 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07002498 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002499 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07002500 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002501 } else {
Tom Sepez101535f2018-06-12 13:36:05 +00002502 IPDF_Page* pPage = IPDFPageFromFPDFPage(m_pFormFillEnv->GetCurrentPage());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002503 if (!pPage)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002504 return CJS_Result::Failure(JSMessage::kBadObjectError);
dsinclair461eeaf2016-07-27 07:40:05 -07002505 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07002506 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002507 for (int32_t i = 0; i < nCount; i++) {
2508 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07002509 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002510 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2511 pWidget = pTempWidget;
2512 break;
2513 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002514 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002515 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002516 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002517 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002518
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002519 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07002520 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07002521 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002522 }
2523
Tom Sepez3a6d0582018-08-17 19:28:52 +00002524 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002525}
2526
Tom Sepez3a6d0582018-08-17 19:28:52 +00002527CJS_Result CJS_Field::setItems(
Dan Sinclairf7435522018-02-05 22:27:22 +00002528 CJS_Runtime* pRuntime,
2529 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002530 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002531}
2532
Tom Sepez3a6d0582018-08-17 19:28:52 +00002533CJS_Result CJS_Field::setLock(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002534 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002535 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002536}
2537
Tom Sepez3a6d0582018-08-17 19:28:52 +00002538CJS_Result CJS_Field::signatureGetModifications(
dan sinclair80435cb2017-10-24 21:40:24 -04002539 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002540 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002541 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002542}
2543
Tom Sepez3a6d0582018-08-17 19:28:52 +00002544CJS_Result CJS_Field::signatureGetSeedValue(
dan sinclair80435cb2017-10-24 21:40:24 -04002545 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002546 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002547 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002548}
2549
Tom Sepez3a6d0582018-08-17 19:28:52 +00002550CJS_Result CJS_Field::signatureInfo(
dan sinclair80435cb2017-10-24 21:40:24 -04002551 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002552 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002553 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002554}
2555
Tom Sepez3a6d0582018-08-17 19:28:52 +00002556CJS_Result CJS_Field::signatureSetSeedValue(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002557 CJS_Runtime* pRuntime,
2558 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002559 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002560}
2561
Tom Sepez3a6d0582018-08-17 19:28:52 +00002562CJS_Result CJS_Field::signatureSign(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002563 CJS_Runtime* pRuntime,
2564 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002565 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002566}
2567
Tom Sepez3a6d0582018-08-17 19:28:52 +00002568CJS_Result CJS_Field::signatureValidate(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002569 CJS_Runtime* pRuntime,
2570 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002571 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002572}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002573
Tom Sepez3a6d0582018-08-17 19:28:52 +00002574CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) {
2575 return CJS_Result::Success();
Dan Sinclair8f524d62017-10-25 13:30:31 -04002576}
2577
Tom Sepez3a6d0582018-08-17 19:28:52 +00002578CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002579 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002580 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002581}
2582
Dan Sinclairf7435522018-02-05 22:27:22 +00002583void CJS_Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
Tom Sepez75acda62018-01-29 20:17:36 +00002584 auto pNewData =
2585 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002586 pNewData->num = n;
Tom Sepez75acda62018-01-29 20:17:36 +00002587 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002588}
2589
Dan Sinclairf7435522018-02-05 22:27:22 +00002590void CJS_Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
Tom Sepez75acda62018-01-29 20:17:36 +00002591 auto pNewData =
2592 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002593 pNewData->b = b;
Tom Sepez75acda62018-01-29 20:17:36 +00002594 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002595}
2596
Lei Zhang109aa6d2018-09-20 01:21:05 +00002597void CJS_Field::AddDelay_String(FIELD_PROP prop, const ByteString& str) {
Tom Sepez75acda62018-01-29 20:17:36 +00002598 auto pNewData =
2599 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Lei Zhang109aa6d2018-09-20 01:21:05 +00002600 pNewData->bytestring = str;
Tom Sepez75acda62018-01-29 20:17:36 +00002601 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002602}
2603
Dan Sinclairf7435522018-02-05 22:27:22 +00002604void CJS_Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
Tom Sepez75acda62018-01-29 20:17:36 +00002605 auto pNewData =
2606 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002607 pNewData->rect = rect;
Tom Sepez75acda62018-01-29 20:17:36 +00002608 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002609}
2610
Dan Sinclairf7435522018-02-05 22:27:22 +00002611void CJS_Field::AddDelay_WordArray(FIELD_PROP prop,
2612 const std::vector<uint32_t>& array) {
Tom Sepez75acda62018-01-29 20:17:36 +00002613 auto pNewData =
2614 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
tsepez41a53ad2016-03-28 16:59:30 -07002615 pNewData->wordarray = array;
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_WideStringArray(FIELD_PROP prop,
2620 const std::vector<WideString>& 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->widestringarray = 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::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2628 CJS_DelayData* pData) {
dsinclair3a7741a2016-10-11 10:39:49 -07002629 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002630 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002631 case FP_BORDERSTYLE:
Lei Zhang94919f72018-07-12 21:16:30 +00002632 SetBorderStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Lei Zhang109aa6d2018-09-20 01:21:05 +00002633 pData->bytestring);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002634 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002635 case FP_CURRENTVALUEINDICES:
Lei Zhang94919f72018-07-12 21:16:30 +00002636 SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
2637 pData->nControlIndex, pData->wordarray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002638 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002639 case FP_DISPLAY:
Lei Zhang94919f72018-07-12 21:16:30 +00002640 SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2641 pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002642 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002643 case FP_HIDDEN:
Lei Zhang94919f72018-07-12 21:16:30 +00002644 SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2645 pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002646 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002647 case FP_LINEWIDTH:
Lei Zhang94919f72018-07-12 21:16:30 +00002648 SetLineWidth(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_RECT:
Lei Zhang94919f72018-07-12 21:16:30 +00002652 SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2653 pData->rect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002654 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002655 case FP_VALUE:
Lei Zhang94919f72018-07-12 21:16:30 +00002656 SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2657 pData->widestringarray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002658 break;
dan sinclair646634b2017-10-19 14:30:28 -04002659 default:
2660 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002661 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002662}