blob: a7366264a54aef1f96bdd674bbd2af3b3393e920 [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"
Lei Zhangbc75f622018-10-15 18:12:40 +000014#include "core/fpdfdoc/cpdf_formcontrol.h"
Dan Sinclair51230322017-10-30 15:36:02 +000015#include "core/fpdfdoc/cpdf_formfield.h"
Lei Zhangc3450652018-10-11 16:54:42 +000016#include "core/fpdfdoc/cpdf_interactiveform.h"
17#include "fpdfsdk/cpdfsdk_interactiveform.h"
dsinclair114e46a2016-09-29 17:18:21 -070018#include "fpdfsdk/cpdfsdk_pageview.h"
19#include "fpdfsdk/cpdfsdk_widget.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000020#include "fxjs/cjs_color.h"
21#include "fxjs/cjs_delaydata.h"
22#include "fxjs/cjs_document.h"
23#include "fxjs/cjs_icon.h"
24#include "fxjs/js_resources.h"
Lei Zhang99f5bbb2018-10-09 21:31:28 +000025#include "third_party/base/ptr_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026
tonikitoo7c05a7a2016-08-17 11:08:46 -070027namespace {
28
Lei Zhang94919f72018-07-12 21:16:30 +000029bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) {
30 return pFormField->GetFieldType() == FormFieldType::kCheckBox ||
31 pFormField->GetFieldType() == FormFieldType::kRadioButton;
32}
33
34bool IsComboBoxOrListBox(const CPDF_FormField* pFormField) {
35 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
36 pFormField->GetFieldType() == FormFieldType::kListBox;
37}
38
39bool IsComboBoxOrTextField(const CPDF_FormField* pFormField) {
40 return pFormField->GetFieldType() == FormFieldType::kComboBox ||
41 pFormField->GetFieldType() == FormFieldType::kTextField;
42}
43
44void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
45 CPDF_FormField* pFormField,
46 bool bChangeMark,
47 bool bResetAP,
48 bool bRefresh) {
Lei Zhang073ecf42018-10-11 16:56:00 +000049 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
Lei Zhang94919f72018-07-12 21:16:30 +000050
51 if (bResetAP) {
52 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
Lei Zhang073ecf42018-10-11 16:56:00 +000053 pForm->GetWidgets(pFormField, &widgets);
Lei Zhang94919f72018-07-12 21:16:30 +000054
55 if (IsComboBoxOrTextField(pFormField)) {
56 for (auto& pObserved : widgets) {
57 if (pObserved) {
Lei Zhang4f261ff2018-10-10 18:44:45 +000058 Optional<WideString> sValue =
59 ToCPDFSDKWidget(pObserved.Get())->OnFormat();
Lei Zhang94919f72018-07-12 21:16:30 +000060 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
Lei Zhang4f261ff2018-10-10 18:44:45 +000061 ToCPDFSDKWidget(pObserved.Get())->ResetAppearance(sValue, false);
Lei Zhang94919f72018-07-12 21:16:30 +000062 }
63 }
64 }
65 } else {
66 for (auto& pObserved : widgets) {
Tom Sepez4ef943b2018-07-26 19:06:06 +000067 if (pObserved)
Lei Zhang4f261ff2018-10-10 18:44:45 +000068 ToCPDFSDKWidget(pObserved.Get())->ResetAppearance({}, false);
Lei Zhang94919f72018-07-12 21:16:30 +000069 }
70 }
71 }
72
73 if (bRefresh) {
74 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
75 // to be removed from the list. We need to call |GetWidgets| again to be
76 // sure none of the widgets have been deleted.
77 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
Lei Zhang073ecf42018-10-11 16:56:00 +000078 pForm->GetWidgets(pFormField, &widgets);
Lei Zhang94919f72018-07-12 21:16:30 +000079
80 // TODO(dsinclair): Determine if all widgets share the same
Lei Zhang073ecf42018-10-11 16:56:00 +000081 // CPDFSDK_InteractiveForm. If that's the case, we can move the code to
Lei Zhang94919f72018-07-12 21:16:30 +000082 // |GetFormFillEnv| out of the loop.
83 for (auto& pObserved : widgets) {
84 if (pObserved) {
Tom Sepez4ef943b2018-07-26 19:06:06 +000085 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pObserved.Get());
Lei Zhang073ecf42018-10-11 16:56:00 +000086 pWidget->GetInteractiveForm()->GetFormFillEnv()->UpdateAllViews(
87 nullptr, pWidget);
Lei Zhang94919f72018-07-12 21:16:30 +000088 }
89 }
90 }
91
92 if (bChangeMark)
93 pFormFillEnv->SetChangeMark();
94}
95
96void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
97 CPDF_FormControl* pFormControl,
98 bool bChangeMark,
99 bool bResetAP,
100 bool bRefresh) {
101 ASSERT(pFormControl);
102
Lei Zhang073ecf42018-10-11 16:56:00 +0000103 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
Lei Zhang94919f72018-07-12 21:16:30 +0000104 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
105
106 if (pWidget) {
107 CPDFSDK_Widget::ObservedPtr observed_widget(pWidget);
108 if (bResetAP) {
109 FormFieldType fieldType = pWidget->GetFieldType();
110 if (fieldType == FormFieldType::kComboBox ||
111 fieldType == FormFieldType::kTextField) {
Lei Zhang4f261ff2018-10-10 18:44:45 +0000112 Optional<WideString> sValue = pWidget->OnFormat();
Lei Zhang94919f72018-07-12 21:16:30 +0000113 if (!observed_widget)
114 return;
Lei Zhang4f261ff2018-10-10 18:44:45 +0000115 pWidget->ResetAppearance(sValue, false);
Lei Zhang94919f72018-07-12 21:16:30 +0000116 } else {
Lei Zhang4f261ff2018-10-10 18:44:45 +0000117 pWidget->ResetAppearance({}, false);
Lei Zhang94919f72018-07-12 21:16:30 +0000118 }
119 if (!observed_widget)
120 return;
121 }
122
123 if (bRefresh) {
Lei Zhang073ecf42018-10-11 16:56:00 +0000124 CPDFSDK_InteractiveForm* pWidgetForm = pWidget->GetInteractiveForm();
125 pWidgetForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
Lei Zhang94919f72018-07-12 21:16:30 +0000126 }
127 }
128
129 if (bChangeMark)
130 pFormFillEnv->SetChangeMark();
131}
132
133std::vector<CPDF_FormField*> GetFormFieldsForName(
134 CPDFSDK_FormFillEnvironment* pFormFillEnv,
135 const WideString& csFieldName) {
136 std::vector<CPDF_FormField*> fields;
Lei Zhang073ecf42018-10-11 16:56:00 +0000137 CPDFSDK_InteractiveForm* pReaderForm = pFormFillEnv->GetInteractiveForm();
138 CPDF_InteractiveForm* pForm = pReaderForm->GetInteractiveForm();
139 for (int i = 0, sz = pForm->CountFields(csFieldName); i < sz; ++i) {
140 if (CPDF_FormField* pFormField = pForm->GetField(i, csFieldName))
Lei Zhang94919f72018-07-12 21:16:30 +0000141 fields.push_back(pFormField);
142 }
143 return fields;
144}
145
tonikitoo7c05a7a2016-08-17 11:08:46 -0700146bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
147 if (!pWidget)
148 return false;
149
150 uint32_t dwFlag = pWidget->GetFlags();
151 switch (value) {
152 case 0:
153 dwFlag &= ~ANNOTFLAG_INVISIBLE;
154 dwFlag &= ~ANNOTFLAG_HIDDEN;
155 dwFlag &= ~ANNOTFLAG_NOVIEW;
156 dwFlag |= ANNOTFLAG_PRINT;
157 break;
158 case 1:
159 dwFlag &= ~ANNOTFLAG_INVISIBLE;
160 dwFlag &= ~ANNOTFLAG_NOVIEW;
161 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
162 break;
163 case 2:
164 dwFlag &= ~ANNOTFLAG_INVISIBLE;
165 dwFlag &= ~ANNOTFLAG_PRINT;
166 dwFlag &= ~ANNOTFLAG_HIDDEN;
167 dwFlag &= ~ANNOTFLAG_NOVIEW;
168 break;
169 case 3:
170 dwFlag |= ANNOTFLAG_NOVIEW;
171 dwFlag |= ANNOTFLAG_PRINT;
172 dwFlag &= ~ANNOTFLAG_HIDDEN;
173 break;
174 }
175
176 if (dwFlag != pWidget->GetFlags()) {
177 pWidget->SetFlags(dwFlag);
178 return true;
179 }
180
181 return false;
182}
183
Lei Zhang94919f72018-07-12 21:16:30 +0000184void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
185 const WideString& swFieldName,
186 int nControlIndex,
187 const ByteString& string) {
188 ASSERT(pFormFillEnv);
189
190 BorderStyle nBorderStyle = BorderStyle::SOLID;
191 if (string == "solid")
192 nBorderStyle = BorderStyle::SOLID;
193 else if (string == "beveled")
194 nBorderStyle = BorderStyle::BEVELED;
195 else if (string == "dashed")
196 nBorderStyle = BorderStyle::DASH;
197 else if (string == "inset")
198 nBorderStyle = BorderStyle::INSET;
199 else if (string == "underline")
200 nBorderStyle = BorderStyle::UNDERLINE;
201 else
202 return;
203
204 std::vector<CPDF_FormField*> FieldArray =
205 GetFormFieldsForName(pFormFillEnv, swFieldName);
Lei Zhang073ecf42018-10-11 16:56:00 +0000206 auto* pForm = pFormFillEnv->GetInteractiveForm();
Lei Zhang94919f72018-07-12 21:16:30 +0000207 for (CPDF_FormField* pFormField : FieldArray) {
208 if (nControlIndex < 0) {
209 bool bSet = false;
210 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Lei Zhang073ecf42018-10-11 16:56:00 +0000211 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormField->GetControl(i));
Lei Zhang7db136a2018-10-10 21:34:17 +0000212 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 Zhang073ecf42018-10-11 16:56:00 +0000226 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Lei Zhang7db136a2018-10-10 21:34:17 +0000227 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) {
Lei Zhang073ecf42018-10-11 16:56:00 +0000269 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
Lei Zhang94919f72018-07-12 21:16:30 +0000270 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
Lei Zhang073ecf42018-10-11 16:56:00 +0000279 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Lei Zhang94919f72018-07-12 21:16:30 +0000280 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
Lei Zhang073ecf42018-10-11 16:56:00 +0000294 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Lei Zhang94919f72018-07-12 21:16:30 +0000295 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) {
Lei Zhang073ecf42018-10-11 16:56:00 +0000313 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
Lei Zhang94919f72018-07-12 21:16:30 +0000314 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
Lei Zhang073ecf42018-10-11 16:56:00 +0000323 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
Lei Zhang94919f72018-07-12 21:16:30 +0000324 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)) {
Lei Zhang073ecf42018-10-11 16:56:00 +0000337 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
Lei Zhang94919f72018-07-12 21:16:30 +0000338 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) {
Lei Zhang073ecf42018-10-11 16:56:00 +0000352 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
Lei Zhang94919f72018-07-12 21:16:30 +0000353 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
Lei Zhang073ecf42018-10-11 16:56:00 +0000362 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
Lei Zhang94919f72018-07-12 21:16:30 +0000363 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)) {
Lei Zhang073ecf42018-10-11 16:56:00 +0000389 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
Lei Zhang94919f72018-07-12 21:16:30 +0000390 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},
Tom Sepezb14a2f22018-10-12 23:21:58 +0000515 {"source", get_source_static, set_source_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400516 {"strokeColor", get_stroke_color_static, set_stroke_color_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800517 {"style", get_style_static, set_style_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400518 {"submitName", get_submit_name_static, set_submit_name_static},
519 {"textColor", get_text_color_static, set_text_color_static},
520 {"textFont", get_text_font_static, set_text_font_static},
521 {"textSize", get_text_size_static, set_text_size_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800522 {"type", get_type_static, set_type_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400523 {"userName", get_user_name_static, set_user_name_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800524 {"value", get_value_static, set_value_static},
Tom Sepezb14a2f22018-10-12 23:21:58 +0000525 {"valueAsString", get_value_as_string_static, set_value_as_string_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
Lei Zhang073ecf42018-10-11 16:56:00 +0000611 CPDFSDK_InteractiveForm* pRDForm = m_pFormFillEnv->GetInteractiveForm();
612 CPDF_InteractiveForm* pForm = pRDForm->GetInteractiveForm();
Ryan Harrison275e2602017-09-18 14:23:18 -0400613 WideString swFieldNameTemp = csFieldName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 swFieldNameTemp.Replace(L"..", L".");
615
Lei Zhang073ecf42018-10-11 16:56:00 +0000616 if (pForm->CountFields(swFieldNameTemp) <= 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 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 Zhang073ecf42018-10-11 16:56:00 +0000703 CPDFSDK_Widget* pWidget = m_pFormFillEnv->GetInteractiveForm()->GetWidget(
Lei Zhang7db136a2018-10-10 21:34:17 +0000704 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
Lei Zhang073ecf42018-10-11 16:56:00 +0000922 CPDFSDK_InteractiveForm* pRDForm = m_pFormFillEnv->GetInteractiveForm();
923 CPDF_InteractiveForm* pForm = pRDForm->GetInteractiveForm();
924 return CJS_Result::Success(pRuntime->NewNumber(
925 static_cast<int32_t>(pForm->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
Lei Zhang073ecf42018-10-11 16:56:00 +00001154 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1155 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001156 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001157 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001158
1159 uint32_t dwFlag = pWidget->GetFlags();
Dan Sinclair8f524d62017-10-25 13:30:31 -04001160 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001161 return CJS_Result::Success(pRuntime->NewNumber(1));
Dan Sinclair8f524d62017-10-25 13:30:31 -04001162
dan sinclaircbe23db2017-10-19 14:29:33 -04001163 if (ANNOTFLAG_PRINT & dwFlag) {
1164 if (ANNOTFLAG_NOVIEW & dwFlag)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001165 return CJS_Result::Success(pRuntime->NewNumber(3));
1166 return CJS_Result::Success(pRuntime->NewNumber(0));
dan sinclaircbe23db2017-10-19 14:29:33 -04001167 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001168 return CJS_Result::Success(pRuntime->NewNumber(2));
dan sinclaircbe23db2017-10-19 14:29:33 -04001169}
1170
Tom Sepez3a6d0582018-08-17 19:28:52 +00001171CJS_Result CJS_Field::set_display(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001172 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001173 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001174 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001175
1176 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001177 AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001178 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001179 SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1180 pRuntime->ToInt32(vp));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001181 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001182 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001183}
1184
Tom Sepez3a6d0582018-08-17 19:28:52 +00001185CJS_Result CJS_Field::get_doc(CJS_Runtime* pRuntime) {
1186 return CJS_Result::Success(m_pJSDoc->ToV8Object());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001187}
1188
Tom Sepez3a6d0582018-08-17 19:28:52 +00001189CJS_Result CJS_Field::set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1190 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001191}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001192
Tom Sepez3a6d0582018-08-17 19:28:52 +00001193CJS_Result CJS_Field::get_editable(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001194 CPDF_FormField* pFormField = GetFirstFormField();
1195 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001196 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001197
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001198 if (pFormField->GetFieldType() != FormFieldType::kComboBox)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001199 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001200
Tom Sepez3a6d0582018-08-17 19:28:52 +00001201 return CJS_Result::Success(
Dan Sinclaire4974922017-10-24 09:36:16 -04001202 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203}
1204
Tom Sepez3a6d0582018-08-17 19:28:52 +00001205CJS_Result CJS_Field::set_editable(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001206 v8::Local<v8::Value> vp) {
Tom Sepez16999822018-06-08 18:23:05 +00001207 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001208 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1209 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001210}
1211
Tom Sepez3a6d0582018-08-17 19:28:52 +00001212CJS_Result CJS_Field::get_export_values(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001213 CPDF_FormField* pFormField = GetFirstFormField();
1214 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001215 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001216
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001217 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001218 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001219
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001220 v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001221 if (m_nFormControlIndex < 0) {
1222 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1223 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001224 pRuntime->PutArrayElement(
1225 ExportValuesArray, i,
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001226 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001227 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001228 } else {
1229 if (m_nFormControlIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001230 return CJS_Result::Failure(JSMessage::kValueError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001231
1232 CPDF_FormControl* pFormControl =
1233 pFormField->GetControl(m_nFormControlIndex);
1234 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001235 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001236
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001237 pRuntime->PutArrayElement(
1238 ExportValuesArray, 0,
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001239 pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001240 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001241 return CJS_Result::Success(ExportValuesArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001242}
1243
Tom Sepez3a6d0582018-08-17 19:28:52 +00001244CJS_Result CJS_Field::set_export_values(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001245 v8::Local<v8::Value> vp) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001246 CPDF_FormField* pFormField = GetFirstFormField();
1247 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001248 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001249
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001250 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001251 return CJS_Result::Failure(JSMessage::kObjectTypeError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001252
Tom Sepez16999822018-06-08 18:23:05 +00001253 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001254 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Tom Sepez16999822018-06-08 18:23:05 +00001255
1256 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001257 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001258
Tom Sepez3a6d0582018-08-17 19:28:52 +00001259 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001260}
1261
Tom Sepez3a6d0582018-08-17 19:28:52 +00001262CJS_Result CJS_Field::get_file_select(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001263 CPDF_FormField* pFormField = GetFirstFormField();
1264 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001265 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001266
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001267 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001268 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001269
Tom Sepez3a6d0582018-08-17 19:28:52 +00001270 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001271 !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001272}
1273
Tom Sepez3a6d0582018-08-17 19:28:52 +00001274CJS_Result CJS_Field::set_file_select(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001275 v8::Local<v8::Value> vp) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001276 CPDF_FormField* pFormField = GetFirstFormField();
1277 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001278 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001279
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001280 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001281 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepez16999822018-06-08 18:23:05 +00001282
1283 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001284 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Tom Sepez16999822018-06-08 18:23:05 +00001285
Tom Sepez3a6d0582018-08-17 19:28:52 +00001286 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001287}
1288
Tom Sepez3a6d0582018-08-17 19:28:52 +00001289CJS_Result CJS_Field::get_fill_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001290 CPDF_FormField* pFormField = GetFirstFormField();
1291 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001292 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001293
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001294 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1295 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001296 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001297
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001298 int iColorType;
1299 pFormControl->GetBackgroundColor(iColorType);
1300
Dan Sinclair7f55a542017-07-13 14:17:10 -04001301 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001302 if (iColorType == CFX_Color::kTransparent) {
1303 color = CFX_Color(CFX_Color::kTransparent);
1304 } else if (iColorType == CFX_Color::kGray) {
1305 color = CFX_Color(CFX_Color::kGray,
1306 pFormControl->GetOriginalBackgroundColor(0));
1307 } else if (iColorType == CFX_Color::kRGB) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001308 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001309 CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001310 pFormControl->GetOriginalBackgroundColor(1),
1311 pFormControl->GetOriginalBackgroundColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001312 } else if (iColorType == CFX_Color::kCMYK) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001313 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001314 CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001315 pFormControl->GetOriginalBackgroundColor(1),
1316 pFormControl->GetOriginalBackgroundColor(2),
1317 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001318 } else {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001319 return CJS_Result::Failure(JSMessage::kValueError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001320 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001321
Dan Sinclairf7435522018-02-05 22:27:22 +00001322 v8::Local<v8::Value> array =
1323 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001324 if (array.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001325 return CJS_Result::Success(pRuntime->NewArray());
1326 return CJS_Result::Success(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001327}
1328
Tom Sepez3a6d0582018-08-17 19:28:52 +00001329CJS_Result CJS_Field::set_fill_color(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001330 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001331 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001332 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001333 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001334 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001335 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001336 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001337 return CJS_Result::Failure(JSMessage::kBadObjectError);
1338 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001339}
1340
Tom Sepez3a6d0582018-08-17 19:28:52 +00001341CJS_Result CJS_Field::get_hidden(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001342 CPDF_FormField* pFormField = GetFirstFormField();
1343 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001344 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001345
Lei Zhang073ecf42018-10-11 16:56:00 +00001346 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1347 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001348 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001349 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001350
1351 uint32_t dwFlags = pWidget->GetFlags();
Tom Sepez3a6d0582018-08-17 19:28:52 +00001352 return CJS_Result::Success(pRuntime->NewBoolean(
Tom Sepez20736f72018-08-17 16:44:50 +00001353 ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags));
dan sinclaircbe23db2017-10-19 14:29:33 -04001354}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001355
Tom Sepez3a6d0582018-08-17 19:28:52 +00001356CJS_Result CJS_Field::set_hidden(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001357 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001358 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001359 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001360
1361 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001362 AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001363 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001364 SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1365 pRuntime->ToBoolean(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001366 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001367 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001368}
1369
Tom Sepez3a6d0582018-08-17 19:28:52 +00001370CJS_Result CJS_Field::get_highlight(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001371 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001372
Lei Zhang4c7ad662018-07-12 20:29:40 +00001373 CPDF_FormField* pFormField = GetFirstFormField();
1374 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001375 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001376
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001377 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001378 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001379
1380 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1381 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001382 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001383
1384 int eHM = pFormControl->GetHighlightingMode();
1385 switch (eHM) {
1386 case CPDF_FormControl::None:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001387 return CJS_Result::Success(pRuntime->NewString(L"none"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001388 case CPDF_FormControl::Push:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001389 return CJS_Result::Success(pRuntime->NewString(L"push"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001390 case CPDF_FormControl::Invert:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001391 return CJS_Result::Success(pRuntime->NewString(L"invert"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001392 case CPDF_FormControl::Outline:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001393 return CJS_Result::Success(pRuntime->NewString(L"outline"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001394 case CPDF_FormControl::Toggle:
Tom Sepez3a6d0582018-08-17 19:28:52 +00001395 return CJS_Result::Success(pRuntime->NewString(L"toggle"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001396 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001397 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001398}
1399
Tom Sepez3a6d0582018-08-17 19:28:52 +00001400CJS_Result CJS_Field::set_highlight(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001401 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001402 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001403 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001404 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1405 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001406}
1407
Tom Sepez3a6d0582018-08-17 19:28:52 +00001408CJS_Result CJS_Field::get_line_width(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001409 CPDF_FormField* pFormField = GetFirstFormField();
1410 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001411 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001412
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001413 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1414 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001415 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001416
Lei Zhang073ecf42018-10-11 16:56:00 +00001417 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001418 if (!pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001419 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001420
Lei Zhang073ecf42018-10-11 16:56:00 +00001421 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormField->GetControl(0));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001422 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001423 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001424
Tom Sepez3a6d0582018-08-17 19:28:52 +00001425 return CJS_Result::Success(pRuntime->NewNumber(pWidget->GetBorderWidth()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001426}
1427
Tom Sepez3a6d0582018-08-17 19:28:52 +00001428CJS_Result CJS_Field::set_line_width(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001429 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001430 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001431 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001432
1433 if (m_bDelay) {
dan sinclair80435cb2017-10-24 21:40:24 -04001434 AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001435 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001436 SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1437 pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04001438 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001439 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001440}
1441
Tom Sepez3a6d0582018-08-17 19:28:52 +00001442CJS_Result CJS_Field::get_multiline(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001443 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001444
Lei Zhang4c7ad662018-07-12 20:29:40 +00001445 CPDF_FormField* pFormField = GetFirstFormField();
1446 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001447 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001448
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001449 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001450 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001451
Tom Sepez3a6d0582018-08-17 19:28:52 +00001452 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001453 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001454}
1455
Tom Sepez3a6d0582018-08-17 19:28:52 +00001456CJS_Result CJS_Field::set_multiline(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001457 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001458 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001459 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001460 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1461 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001462}
1463
Tom Sepez3a6d0582018-08-17 19:28:52 +00001464CJS_Result CJS_Field::get_multiple_selection(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001465 ASSERT(m_pFormFillEnv);
Lei Zhang4c7ad662018-07-12 20:29:40 +00001466 CPDF_FormField* pFormField = GetFirstFormField();
1467 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001468 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001469
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001470 if (pFormField->GetFieldType() != FormFieldType::kListBox)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001471 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001472
Tom Sepez3a6d0582018-08-17 19:28:52 +00001473 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001474 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001475}
1476
Tom Sepez3a6d0582018-08-17 19:28:52 +00001477CJS_Result CJS_Field::set_multiple_selection(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001478 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001479 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001480 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001481 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1482 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001483}
1484
Tom Sepez3a6d0582018-08-17 19:28:52 +00001485CJS_Result CJS_Field::get_name(CJS_Runtime* pRuntime) {
Lei Zhang18915232018-07-12 20:53:40 +00001486 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08001487 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001488 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001489
Tom Sepez3a6d0582018-08-17 19:28:52 +00001490 return CJS_Result::Success(pRuntime->NewString(m_FieldName.AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491}
1492
Tom Sepez3a6d0582018-08-17 19:28:52 +00001493CJS_Result CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1494 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001495}
Tom Sepez67fd5df2015-10-08 12:24:19 -07001496
Tom Sepez3a6d0582018-08-17 19:28:52 +00001497CJS_Result CJS_Field::get_num_items(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001498 CPDF_FormField* pFormField = GetFirstFormField();
1499 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001500 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001501
Lei Zhang83f2d702018-07-12 19:07:40 +00001502 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001503 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001504
Tom Sepez3a6d0582018-08-17 19:28:52 +00001505 return CJS_Result::Success(pRuntime->NewNumber(pFormField->CountOptions()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001506}
1507
Tom Sepez3a6d0582018-08-17 19:28:52 +00001508CJS_Result CJS_Field::set_num_items(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001509 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001510 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001511}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001512
Tom Sepez3a6d0582018-08-17 19:28:52 +00001513CJS_Result CJS_Field::get_page(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001514 CPDF_FormField* pFormField = GetFirstFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001515 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001516 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001517
tsepez8fa82792017-01-11 09:32:33 -08001518 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
Lei Zhang073ecf42018-10-11 16:56:00 +00001519 m_pFormFillEnv->GetInteractiveForm()->GetWidgets(pFormField, &widgets);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001520 if (widgets.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001521 return CJS_Result::Success(pRuntime->NewNumber(-1));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001522
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001523 v8::Local<v8::Array> PageArray = pRuntime->NewArray();
tsepez8fa82792017-01-11 09:32:33 -08001524 int i = 0;
1525 for (const auto& pObserved : widgets) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001526 if (!pObserved)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001527 return CJS_Result::Failure(JSMessage::kBadObjectError);
tsepez8fa82792017-01-11 09:32:33 -08001528
Tom Sepez4ef943b2018-07-26 19:06:06 +00001529 auto* pWidget = ToCPDFSDKWidget(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001530 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001531 if (!pPageView)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001532 return CJS_Result::Failure(JSMessage::kBadObjectError);
Lei Zhangd88a3642015-11-10 09:38:57 -08001533
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001534 pRuntime->PutArrayElement(
1535 PageArray, i,
dan sinclair80435cb2017-10-24 21:40:24 -04001536 pRuntime->NewNumber(static_cast<int32_t>(pPageView->GetPageIndex())));
tsepez8fa82792017-01-11 09:32:33 -08001537 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001538 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001539 return CJS_Result::Success(PageArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001540}
1541
Tom Sepez3a6d0582018-08-17 19:28:52 +00001542CJS_Result CJS_Field::set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
1543 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001544}
1545
Tom Sepez3a6d0582018-08-17 19:28:52 +00001546CJS_Result CJS_Field::get_password(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001547 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001548
Lei Zhang4c7ad662018-07-12 20:29:40 +00001549 CPDF_FormField* pFormField = GetFirstFormField();
1550 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001551 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001552
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001553 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001554 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001555
Tom Sepez3a6d0582018-08-17 19:28:52 +00001556 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001557 !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001558}
1559
Tom Sepez3a6d0582018-08-17 19:28:52 +00001560CJS_Result CJS_Field::set_password(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001561 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001562 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001563 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001564 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1565 return CJS_Result::Success();
dan sinclair646634b2017-10-19 14:30:28 -04001566}
dan sinclaircbe23db2017-10-19 14:29:33 -04001567
Tom Sepez3a6d0582018-08-17 19:28:52 +00001568CJS_Result CJS_Field::get_print(CJS_Runtime* pRuntime) {
Lei Zhang073ecf42018-10-11 16:56:00 +00001569 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
Lei Zhang4c7ad662018-07-12 20:29:40 +00001570 CPDF_FormField* pFormField = GetFirstFormField();
1571 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001572 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001573
Lei Zhang073ecf42018-10-11 16:56:00 +00001574 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
dan sinclair646634b2017-10-19 14:30:28 -04001575 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001576 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001577
Tom Sepez3a6d0582018-08-17 19:28:52 +00001578 return CJS_Result::Success(
Dan Sinclair8f524d62017-10-25 13:30:31 -04001579 pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001580}
1581
Tom Sepez3a6d0582018-08-17 19:28:52 +00001582CJS_Result CJS_Field::set_print(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001583 v8::Local<v8::Value> vp) {
Lei Zhang073ecf42018-10-11 16:56:00 +00001584 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
Lei Zhang18915232018-07-12 20:53:40 +00001585 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08001586 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001587 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001588
Dan Sinclair8f524d62017-10-25 13:30:31 -04001589 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001590 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001591
Dan Sinclair8f524d62017-10-25 13:30:31 -04001592 for (CPDF_FormField* pFormField : FieldArray) {
1593 if (m_nFormControlIndex < 0) {
1594 bool bSet = false;
1595 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1596 if (CPDFSDK_Widget* pWidget =
Lei Zhang073ecf42018-10-11 16:56:00 +00001597 pForm->GetWidget(pFormField->GetControl(i))) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001598 uint32_t dwFlags = pWidget->GetFlags();
dan sinclair80435cb2017-10-24 21:40:24 -04001599 if (pRuntime->ToBoolean(vp))
dan sinclaircbe23db2017-10-19 14:29:33 -04001600 dwFlags |= ANNOTFLAG_PRINT;
1601 else
1602 dwFlags &= ~ANNOTFLAG_PRINT;
1603
1604 if (dwFlags != pWidget->GetFlags()) {
1605 pWidget->SetFlags(dwFlags);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001606 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001607 }
1608 }
1609 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001610
1611 if (bSet)
1612 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
1613
1614 continue;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001615 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001616
1617 if (m_nFormControlIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001618 return CJS_Result::Failure(JSMessage::kValueError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04001619
1620 if (CPDF_FormControl* pFormControl =
1621 pFormField->GetControl(m_nFormControlIndex)) {
Lei Zhang073ecf42018-10-11 16:56:00 +00001622 if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04001623 uint32_t dwFlags = pWidget->GetFlags();
1624 if (pRuntime->ToBoolean(vp))
1625 dwFlags |= ANNOTFLAG_PRINT;
1626 else
1627 dwFlags &= ~ANNOTFLAG_PRINT;
1628
1629 if (dwFlags != pWidget->GetFlags()) {
1630 pWidget->SetFlags(dwFlags);
1631 UpdateFormControl(m_pFormFillEnv.Get(),
1632 pFormField->GetControl(m_nFormControlIndex), true,
1633 false, true);
1634 }
1635 }
1636 }
1637 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001638 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001639}
1640
Tom Sepez3a6d0582018-08-17 19:28:52 +00001641CJS_Result CJS_Field::get_radios_in_unison(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001642 CPDF_FormField* pFormField = GetFirstFormField();
1643 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001644 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001645
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001646 if (pFormField->GetFieldType() != FormFieldType::kRadioButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001647 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001648
Tom Sepez3a6d0582018-08-17 19:28:52 +00001649 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001650 !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001651}
1652
Tom Sepez3a6d0582018-08-17 19:28:52 +00001653CJS_Result CJS_Field::set_radios_in_unison(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001654 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001655 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001656 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001657 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001658 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001659 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1660 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001661}
1662
Tom Sepez3a6d0582018-08-17 19:28:52 +00001663CJS_Result CJS_Field::get_readonly(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001664 CPDF_FormField* pFormField = GetFirstFormField();
1665 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001666 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667
Tom Sepez3a6d0582018-08-17 19:28:52 +00001668 return CJS_Result::Success(pRuntime->NewBoolean(
Lei Zhang4c7ad662018-07-12 20:29:40 +00001669 !!(pFormField->GetFieldFlags() & FIELDFLAG_READONLY)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001670}
1671
Tom Sepez3a6d0582018-08-17 19:28:52 +00001672CJS_Result CJS_Field::set_readonly(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001673 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001674 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001675 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001676 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001677 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001678 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1679 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001680}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001681
Tom Sepez3a6d0582018-08-17 19:28:52 +00001682CJS_Result CJS_Field::get_rect(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001683 CPDF_FormField* pFormField = GetFirstFormField();
1684 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001685 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001686
Lei Zhang073ecf42018-10-11 16:56:00 +00001687 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
1688 CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001689 if (!pWidget)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001690 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001691
1692 CFX_FloatRect crRect = pWidget->GetRect();
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001693 v8::Local<v8::Array> rcArray = pRuntime->NewArray();
1694 pRuntime->PutArrayElement(
1695 rcArray, 0, pRuntime->NewNumber(static_cast<int32_t>(crRect.left)));
1696 pRuntime->PutArrayElement(
1697 rcArray, 1, pRuntime->NewNumber(static_cast<int32_t>(crRect.top)));
1698 pRuntime->PutArrayElement(
1699 rcArray, 2, pRuntime->NewNumber(static_cast<int32_t>(crRect.right)));
1700 pRuntime->PutArrayElement(
1701 rcArray, 3, pRuntime->NewNumber(static_cast<int32_t>(crRect.bottom)));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001702
Tom Sepez3a6d0582018-08-17 19:28:52 +00001703 return CJS_Result::Success(rcArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001704}
1705
Tom Sepez3a6d0582018-08-17 19:28:52 +00001706CJS_Result CJS_Field::set_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001707 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001708 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001709 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001710 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -04001711
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001712 v8::Local<v8::Array> rcArray = pRuntime->ToArray(vp);
1713 if (pRuntime->GetArrayLength(rcArray) < 4)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001714 return CJS_Result::Failure(JSMessage::kValueError);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001715
dan sinclaircbe23db2017-10-19 14:29:33 -04001716 float pArray[4];
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001717 pArray[0] = static_cast<float>(
1718 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 0)));
1719 pArray[1] = static_cast<float>(
1720 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 1)));
1721 pArray[2] = static_cast<float>(
1722 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 2)));
1723 pArray[3] = static_cast<float>(
1724 pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 3)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001725
1726 CFX_FloatRect crRect(pArray);
1727 if (m_bDelay) {
1728 AddDelay_Rect(FP_RECT, crRect);
1729 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00001730 SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, crRect);
dan sinclaircbe23db2017-10-19 14:29:33 -04001731 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001732 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001733}
1734
Tom Sepez3a6d0582018-08-17 19:28:52 +00001735CJS_Result CJS_Field::get_required(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001736 CPDF_FormField* pFormField = GetFirstFormField();
1737 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001738 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001739
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001740 if (pFormField->GetFieldType() == FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001741 return CJS_Result::Failure(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001742
Tom Sepez3a6d0582018-08-17 19:28:52 +00001743 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001744 !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001745}
1746
Tom Sepez3a6d0582018-08-17 19:28:52 +00001747CJS_Result CJS_Field::set_required(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001748 v8::Local<v8::Value> vp) {
Lei Zhang18915232018-07-12 20:53:40 +00001749 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
dan sinclaircbe23db2017-10-19 14:29:33 -04001750 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001751 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepez16999822018-06-08 18:23:05 +00001752 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001753 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1754 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001755}
1756
Tom Sepez3a6d0582018-08-17 19:28:52 +00001757CJS_Result CJS_Field::get_rich_text(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001758 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001759
Lei Zhang4c7ad662018-07-12 20:29:40 +00001760 CPDF_FormField* pFormField = GetFirstFormField();
1761 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001762 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001763
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001764 if (pFormField->GetFieldType() != FormFieldType::kTextField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001765 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001766
Tom Sepez3a6d0582018-08-17 19:28:52 +00001767 return CJS_Result::Success(pRuntime->NewBoolean(
Dan Sinclaire4974922017-10-24 09:36:16 -04001768 !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001769}
1770
Tom Sepez3a6d0582018-08-17 19:28:52 +00001771CJS_Result CJS_Field::set_rich_text(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001772 v8::Local<v8::Value> vp) {
dsinclair3a7741a2016-10-11 10:39:49 -07001773 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001774 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001775 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1776 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001777}
1778
Tom Sepez3a6d0582018-08-17 19:28:52 +00001779CJS_Result CJS_Field::get_rich_value(CJS_Runtime* pRuntime) {
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::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001784 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001785 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001786}
1787
Tom Sepez3a6d0582018-08-17 19:28:52 +00001788CJS_Result CJS_Field::get_rotation(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001789 ASSERT(m_pFormFillEnv);
1790
Lei Zhang4c7ad662018-07-12 20:29:40 +00001791 CPDF_FormField* pFormField = GetFirstFormField();
1792 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001793 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001794
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001795 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1796 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001797 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001798
Tom Sepez3a6d0582018-08-17 19:28:52 +00001799 return CJS_Result::Success(pRuntime->NewNumber(pFormControl->GetRotation()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001800}
1801
Tom Sepez3a6d0582018-08-17 19:28:52 +00001802CJS_Result CJS_Field::set_rotation(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001803 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001804 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001805 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001806 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1807 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001808}
1809
Tom Sepezb14a2f22018-10-12 23:21:58 +00001810CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) {
1811 return CJS_Result::Success();
1812}
1813
1814CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime,
1815 v8::Local<v8::Value> vp) {
1816 return CJS_Result::Success();
1817}
1818
Tom Sepez3a6d0582018-08-17 19:28:52 +00001819CJS_Result CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001820 CPDF_FormField* pFormField = GetFirstFormField();
1821 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001822 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001823
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001824 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1825 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001826 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001827
1828 int iColorType;
1829 pFormControl->GetBorderColor(iColorType);
1830
Dan Sinclair7f55a542017-07-13 14:17:10 -04001831 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001832 if (iColorType == CFX_Color::kTransparent) {
1833 color = CFX_Color(CFX_Color::kTransparent);
1834 } else if (iColorType == CFX_Color::kGray) {
1835 color =
1836 CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0));
1837 } else if (iColorType == CFX_Color::kRGB) {
1838 color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001839 pFormControl->GetOriginalBorderColor(1),
1840 pFormControl->GetOriginalBorderColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001841 } else if (iColorType == CFX_Color::kCMYK) {
1842 color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001843 pFormControl->GetOriginalBorderColor(1),
1844 pFormControl->GetOriginalBorderColor(2),
1845 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001846 } else {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001847 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001848 }
1849
Dan Sinclairf7435522018-02-05 22:27:22 +00001850 v8::Local<v8::Value> array =
1851 CJS_Color::ConvertPWLColorToArray(pRuntime, color);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001852 if (array.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001853 return CJS_Result::Success(pRuntime->NewArray());
1854 return CJS_Result::Success(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001855}
1856
Tom Sepez3a6d0582018-08-17 19:28:52 +00001857CJS_Result CJS_Field::set_stroke_color(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001858 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001859 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001860 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001861 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001862 return CJS_Result::Failure(JSMessage::kBadObjectError);
1863 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001864}
1865
Tom Sepez3a6d0582018-08-17 19:28:52 +00001866CJS_Result CJS_Field::get_style(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001867 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001868
Lei Zhang4c7ad662018-07-12 20:29:40 +00001869 CPDF_FormField* pFormField = GetFirstFormField();
1870 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001871 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001872
Lei Zhangdfa2ac22018-07-12 19:06:50 +00001873 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00001874 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001875
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001876 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1877 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001878 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001879
Ryan Harrison275e2602017-09-18 14:23:18 -04001880 WideString csWCaption = pFormControl->GetNormalCaption();
1881 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001882
1883 switch (csWCaption[0]) {
1884 case L'l':
1885 csBCaption = "circle";
1886 break;
1887 case L'8':
1888 csBCaption = "cross";
1889 break;
1890 case L'u':
1891 csBCaption = "diamond";
1892 break;
1893 case L'n':
1894 csBCaption = "square";
1895 break;
1896 case L'H':
1897 csBCaption = "star";
1898 break;
1899 default: // L'4'
1900 csBCaption = "check";
1901 break;
1902 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00001903 return CJS_Result::Success(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001904 WideString::FromLocal(csBCaption.AsStringView()).AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001905}
1906
Tom Sepez3a6d0582018-08-17 19:28:52 +00001907CJS_Result CJS_Field::set_style(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001908 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001909 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00001910 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001911 return CJS_Result::Failure(JSMessage::kReadOnlyError);
1912 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001913}
1914
Tom Sepez3a6d0582018-08-17 19:28:52 +00001915CJS_Result CJS_Field::get_submit_name(CJS_Runtime* pRuntime) {
1916 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001917}
1918
Tom Sepez3a6d0582018-08-17 19:28:52 +00001919CJS_Result CJS_Field::set_submit_name(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001920 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001921 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -04001922}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001923
Tom Sepez3a6d0582018-08-17 19:28:52 +00001924CJS_Result CJS_Field::get_text_color(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00001925 CPDF_FormField* pFormField = GetFirstFormField();
1926 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001927 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001928
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001929 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1930 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001931 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001932
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001933 Optional<CFX_Color::Type> iColorType;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001934 FX_ARGB color;
1935 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
Dan Sinclaira17a0e22018-03-28 21:10:35 +00001936 std::tie(iColorType, color) = FieldAppearance.GetColor();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001937
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001938 CFX_Color crRet;
1939 if (!iColorType || *iColorType == CFX_Color::kTransparent) {
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001940 crRet = CFX_Color(CFX_Color::kTransparent);
Dan Sinclair28bb2f22018-04-03 19:52:27 +00001941 } else {
1942 int32_t a;
1943 int32_t r;
1944 int32_t g;
1945 int32_t b;
1946 std::tie(a, r, g, b) = ArgbDecode(color);
1947 crRet = CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
1948 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001949
Dan Sinclairf7435522018-02-05 22:27:22 +00001950 v8::Local<v8::Value> array =
1951 CJS_Color::ConvertPWLColorToArray(pRuntime, crRet);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04001952 if (array.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001953 return CJS_Result::Success(pRuntime->NewArray());
1954 return CJS_Result::Success(array);
dan sinclaircbe23db2017-10-19 14:29:33 -04001955}
1956
Tom Sepez3a6d0582018-08-17 19:28:52 +00001957CJS_Result CJS_Field::set_text_color(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001958 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001959 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001960 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclair80435cb2017-10-24 21:40:24 -04001961 if (vp.IsEmpty() || !vp->IsArray())
Tom Sepez3a6d0582018-08-17 19:28:52 +00001962 return CJS_Result::Failure(JSMessage::kBadObjectError);
1963 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001964}
1965
Tom Sepez3a6d0582018-08-17 19:28:52 +00001966CJS_Result CJS_Field::get_text_font(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07001967 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001968
Lei Zhang4c7ad662018-07-12 20:29:40 +00001969 CPDF_FormField* pFormField = GetFirstFormField();
1970 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001971 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001972
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001973 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1974 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001975 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001976
Ryan Harrison9baf31f2018-01-12 18:36:30 +00001977 FormFieldType fieldType = pFormField->GetFieldType();
1978 if (fieldType != FormFieldType::kPushButton &&
1979 fieldType != FormFieldType::kComboBox &&
1980 fieldType != FormFieldType::kListBox &&
1981 fieldType != FormFieldType::kTextField) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00001982 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001983 }
Dan Sinclair8f524d62017-10-25 13:30:31 -04001984
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001985 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
1986 if (!pFont)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001987 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001988
Tom Sepez3a6d0582018-08-17 19:28:52 +00001989 return CJS_Result::Success(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00001990 WideString::FromLocal(pFont->GetBaseFont().AsStringView())
1991 .AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001992}
1993
Tom Sepez3a6d0582018-08-17 19:28:52 +00001994CJS_Result CJS_Field::set_text_font(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00001995 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001996 ASSERT(m_pFormFillEnv);
1997
dan sinclair646634b2017-10-19 14:30:28 -04001998 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00001999 return CJS_Result::Failure(JSMessage::kReadOnlyError);
Tom Sepez34dab072018-08-08 17:49:02 +00002000 if (pRuntime->ToWideString(vp).ToDefANSI().IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002001 return CJS_Result::Failure(JSMessage::kValueError);
2002 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002003}
2004
Tom Sepez3a6d0582018-08-17 19:28:52 +00002005CJS_Result CJS_Field::get_text_size(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07002006 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002007
Lei Zhang4c7ad662018-07-12 20:29:40 +00002008 CPDF_FormField* pFormField = GetFirstFormField();
2009 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002010 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002011
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002012 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2013 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002014 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002015
Dan Sinclair05df0752017-03-14 14:43:42 -04002016 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002017 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2018 FieldAppearance.GetFont(&fFontSize);
Tom Sepez3a6d0582018-08-17 19:28:52 +00002019 return CJS_Result::Success(pRuntime->NewNumber(static_cast<int>(fFontSize)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002020}
2021
Tom Sepez3a6d0582018-08-17 19:28:52 +00002022CJS_Result CJS_Field::set_text_size(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002023 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002024 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00002025 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002026 return CJS_Result::Failure(JSMessage::kReadOnlyError);
2027 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002028}
2029
Tom Sepez3a6d0582018-08-17 19:28:52 +00002030CJS_Result CJS_Field::get_type(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002031 CPDF_FormField* pFormField = GetFirstFormField();
2032 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002033 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002034
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002035 switch (pFormField->GetFieldType()) {
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002036 case FormFieldType::kUnknown:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002037 return CJS_Result::Success(pRuntime->NewString(L"unknown"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002038 case FormFieldType::kPushButton:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002039 return CJS_Result::Success(pRuntime->NewString(L"button"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002040 case FormFieldType::kCheckBox:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002041 return CJS_Result::Success(pRuntime->NewString(L"checkbox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002042 case FormFieldType::kRadioButton:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002043 return CJS_Result::Success(pRuntime->NewString(L"radiobutton"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002044 case FormFieldType::kComboBox:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002045 return CJS_Result::Success(pRuntime->NewString(L"combobox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002046 case FormFieldType::kListBox:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002047 return CJS_Result::Success(pRuntime->NewString(L"listbox"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002048 case FormFieldType::kTextField:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002049 return CJS_Result::Success(pRuntime->NewString(L"text"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002050 case FormFieldType::kSignature:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002051 return CJS_Result::Success(pRuntime->NewString(L"signature"));
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002052 default:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002053 return CJS_Result::Success(pRuntime->NewString(L"unknown"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002054 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002055}
2056
Tom Sepez3a6d0582018-08-17 19:28:52 +00002057CJS_Result CJS_Field::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
2058 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002059}
2060
Tom Sepez3a6d0582018-08-17 19:28:52 +00002061CJS_Result CJS_Field::get_user_name(CJS_Runtime* pRuntime) {
dsinclair3a7741a2016-10-11 10:39:49 -07002062 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002063
Lei Zhang4c7ad662018-07-12 20:29:40 +00002064 CPDF_FormField* pFormField = GetFirstFormField();
2065 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002066 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002067
Tom Sepez3a6d0582018-08-17 19:28:52 +00002068 return CJS_Result::Success(
Lei Zhang4c7ad662018-07-12 20:29:40 +00002069 pRuntime->NewString(pFormField->GetAlternateName().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002070}
2071
Tom Sepez3a6d0582018-08-17 19:28:52 +00002072CJS_Result CJS_Field::set_user_name(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002073 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002074 ASSERT(m_pFormFillEnv);
Tom Sepez16999822018-06-08 18:23:05 +00002075 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002076 return CJS_Result::Failure(JSMessage::kReadOnlyError);
2077 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002078}
2079
Tom Sepez3a6d0582018-08-17 19:28:52 +00002080CJS_Result CJS_Field::get_value(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002081 CPDF_FormField* pFormField = GetFirstFormField();
2082 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002083 return CJS_Result::Failure(JSMessage::kBadObjectError);
Dan Sinclair8f524d62017-10-25 13:30:31 -04002084
2085 v8::Local<v8::Value> ret;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002086 switch (pFormField->GetFieldType()) {
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002087 case FormFieldType::kPushButton:
Tom Sepez3a6d0582018-08-17 19:28:52 +00002088 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002089 case FormFieldType::kComboBox:
2090 case FormFieldType::kTextField:
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002091 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
dan sinclaircbe23db2017-10-19 14:29:33 -04002092 break;
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002093 case FormFieldType::kListBox: {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002094 if (pFormField->CountSelectedItems() > 1) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002095 v8::Local<v8::Array> ValueArray = pRuntime->NewArray();
dan sinclair80435cb2017-10-24 21:40:24 -04002096 v8::Local<v8::Value> ElementValue;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002097 int iIndex;
2098 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2099 iIndex = pFormField->GetSelectedIndex(i);
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002100 ElementValue = pRuntime->NewString(
2101 pFormField->GetOptionValue(iIndex).AsStringView());
dan sinclair80435cb2017-10-24 21:40:24 -04002102 if (wcslen(pRuntime->ToWideString(ElementValue).c_str()) == 0) {
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002103 ElementValue = pRuntime->NewString(
2104 pFormField->GetOptionLabel(iIndex).AsStringView());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002105 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002106 pRuntime->PutArrayElement(ValueArray, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002107 }
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002108 ret = ValueArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002109 } else {
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002110 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002111 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002112 break;
2113 }
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002114 case FormFieldType::kCheckBox:
2115 case FormFieldType::kRadioButton: {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002116 bool bFind = false;
2117 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2118 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclair8f524d62017-10-25 13:30:31 -04002119 ret = pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002120 pFormField->GetControl(i)->GetExportValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002121 bFind = true;
2122 break;
2123 }
2124 }
2125 if (!bFind)
Dan Sinclair8f524d62017-10-25 13:30:31 -04002126 ret = pRuntime->NewString(L"Off");
dan sinclaircbe23db2017-10-19 14:29:33 -04002127
2128 break;
2129 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002130 default:
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002131 ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002132 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002133 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002134 return CJS_Result::Success(pRuntime->MaybeCoerceToNumber(ret));
dan sinclaircbe23db2017-10-19 14:29:33 -04002135}
2136
Tom Sepez3a6d0582018-08-17 19:28:52 +00002137CJS_Result CJS_Field::set_value(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002138 v8::Local<v8::Value> vp) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002139 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002140 return CJS_Result::Failure(JSMessage::kReadOnlyError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002141
2142 std::vector<WideString> strArray;
dan sinclair80435cb2017-10-24 21:40:24 -04002143 if (!vp.IsEmpty() && vp->IsArray()) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002144 v8::Local<v8::Array> ValueArray = pRuntime->ToArray(vp);
2145 for (size_t i = 0; i < pRuntime->GetArrayLength(ValueArray); i++) {
dan sinclair80435cb2017-10-24 21:40:24 -04002146 strArray.push_back(
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002147 pRuntime->ToWideString(pRuntime->GetArrayElement(ValueArray, i)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002148 }
2149 } else {
dan sinclair80435cb2017-10-24 21:40:24 -04002150 strArray.push_back(pRuntime->ToWideString(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -04002151 }
2152
2153 if (m_bDelay) {
2154 AddDelay_WideStringArray(FP_VALUE, strArray);
2155 } else {
Lei Zhang94919f72018-07-12 21:16:30 +00002156 SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, strArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04002157 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002158 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002159}
2160
Tom Sepez3a6d0582018-08-17 19:28:52 +00002161CJS_Result CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002162 CPDF_FormField* pFormField = GetFirstFormField();
2163 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002164 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002165
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002166 if (pFormField->GetFieldType() == FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002167 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002168
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002169 if (pFormField->GetFieldType() == FormFieldType::kCheckBox) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002170 if (!pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002171 return CJS_Result::Failure(JSMessage::kBadObjectError);
2172 return CJS_Result::Success(pRuntime->NewString(
Dan Sinclaire4974922017-10-24 09:36:16 -04002173 pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002174 }
2175
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002176 if (pFormField->GetFieldType() == FormFieldType::kRadioButton &&
dan sinclaircbe23db2017-10-19 14:29:33 -04002177 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002178 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2179 if (pFormField->GetControl(i)->IsChecked()) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002180 return CJS_Result::Success(pRuntime->NewString(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002181 pFormField->GetControl(i)->GetExportValue().AsStringView()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002182 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002184 return CJS_Result::Success(pRuntime->NewString(L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002185 }
2186
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002187 if (pFormField->GetFieldType() == FormFieldType::kListBox &&
dan sinclaircbe23db2017-10-19 14:29:33 -04002188 (pFormField->CountSelectedItems() > 1)) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002189 return CJS_Result::Success(pRuntime->NewString(L""));
Lei Zhangd88a3642015-11-10 09:38:57 -08002190 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002191 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +00002192 pRuntime->NewString(pFormField->GetValue().AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002193}
2194
Tom Sepez3a6d0582018-08-17 19:28:52 +00002195CJS_Result CJS_Field::set_value_as_string(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002196 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002197 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002198}
2199
Tom Sepez3a6d0582018-08-17 19:28:52 +00002200CJS_Result CJS_Field::browseForFileToSubmit(
dan sinclair80435cb2017-10-24 21:40:24 -04002201 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002202 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002203 CPDF_FormField* pFormField = GetFirstFormField();
2204 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002205 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002206
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002207 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002208 (pFormField->GetFieldType() == FormFieldType::kTextField)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002209 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002210 if (!wsFileName.IsEmpty()) {
Tom Sepezb2e6b4c2018-08-16 20:53:58 +00002211 pFormField->SetValue(wsFileName, NotificationOption::kDoNotNotify);
tsepez4cf55152016-11-02 14:37:54 -07002212 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002213 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002214 return CJS_Result::Success();
Lei Zhangd88a3642015-11-10 09:38:57 -08002215 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002216 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002217}
2218
Tom Sepez3a6d0582018-08-17 19:28:52 +00002219CJS_Result CJS_Field::buttonGetCaption(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002220 CJS_Runtime* pRuntime,
2221 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002222 int nface = 0;
2223 int iSize = params.size();
2224 if (iSize >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002225 nface = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002226
Lei Zhang4c7ad662018-07-12 20:29:40 +00002227 CPDF_FormField* pFormField = GetFirstFormField();
2228 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002229 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002230
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002231 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002232 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002233
2234 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2235 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002236 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002237
Dan Sinclair8f524d62017-10-25 13:30:31 -04002238 if (nface == 0) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002239 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002240 pRuntime->NewString(pFormControl->GetNormalCaption().AsStringView()));
2241 }
2242 if (nface == 1) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002243 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002244 pRuntime->NewString(pFormControl->GetDownCaption().AsStringView()));
2245 }
2246 if (nface == 2) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002247 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002248 pRuntime->NewString(pFormControl->GetRolloverCaption().AsStringView()));
Dan Sinclair8f524d62017-10-25 13:30:31 -04002249 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002250 return CJS_Result::Failure(JSMessage::kValueError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002251}
2252
Tom Sepez3a6d0582018-08-17 19:28:52 +00002253CJS_Result CJS_Field::buttonGetIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002254 CJS_Runtime* pRuntime,
2255 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002256 if (params.size() >= 1) {
dan sinclair80435cb2017-10-24 21:40:24 -04002257 int nFace = pRuntime->ToInt32(params[0]);
Tom Sepez40e0a812017-02-23 13:07:36 -08002258 if (nFace < 0 || nFace > 2)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002259 return CJS_Result::Failure(JSMessage::kValueError);
Tom Sepez40e0a812017-02-23 13:07:36 -08002260 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002261
Lei Zhang4c7ad662018-07-12 20:29:40 +00002262 CPDF_FormField* pFormField = GetFirstFormField();
2263 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002264 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002265
Ryan Harrison9baf31f2018-01-12 18:36:30 +00002266 if (pFormField->GetFieldType() != FormFieldType::kPushButton)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002267 return CJS_Result::Failure(JSMessage::kObjectTypeError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002268
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002269 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2270 if (!pFormControl)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002271 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002272
Tom Sepez55ccb522018-08-14 23:40:10 +00002273 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2274 CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -08002275 if (pObj.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002276 return CJS_Result::Failure(JSMessage::kBadObjectError);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002277
Tom Sepezddaa40f2018-06-06 18:30:15 +00002278 auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
Tom Sepez3a6d0582018-08-17 19:28:52 +00002279 return pJS_Icon ? CJS_Result::Success(pJS_Icon->ToV8Object())
2280 : CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002281}
2282
Tom Sepez3a6d0582018-08-17 19:28:52 +00002283CJS_Result CJS_Field::buttonImportIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002284 CJS_Runtime* pRuntime,
2285 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002286 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002287}
2288
Tom Sepez3a6d0582018-08-17 19:28:52 +00002289CJS_Result CJS_Field::buttonSetCaption(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002290 CJS_Runtime* pRuntime,
2291 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002292 return CJS_Result::Failure(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -07002293}
2294
Tom Sepez3a6d0582018-08-17 19:28:52 +00002295CJS_Result CJS_Field::buttonSetIcon(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002296 CJS_Runtime* pRuntime,
2297 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002298 return CJS_Result::Failure(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -07002299}
2300
Tom Sepez3a6d0582018-08-17 19:28:52 +00002301CJS_Result CJS_Field::checkThisBox(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002302 CJS_Runtime* pRuntime,
2303 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002304 int iSize = params.size();
2305 if (iSize < 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002306 return CJS_Result::Failure(JSMessage::kParamError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002307
tsepezf3dc8c62016-08-10 06:29:29 -07002308 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002309 return CJS_Result::Failure(JSMessage::kReadOnlyError);
tsepezf3dc8c62016-08-10 06:29:29 -07002310
dan sinclair80435cb2017-10-24 21:40:24 -04002311 int nWidget = pRuntime->ToInt32(params[0]);
Wei Li97da9762016-03-11 17:00:48 -08002312 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002313 if (iSize >= 2)
dan sinclair80435cb2017-10-24 21:40:24 -04002314 bCheckit = pRuntime->ToBoolean(params[1]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002315
Lei Zhang4c7ad662018-07-12 20:29:40 +00002316 CPDF_FormField* pFormField = GetFirstFormField();
2317 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002318 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002319
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002320 if (!IsCheckBoxOrRadioButton(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00002321 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Tom Sepezb2e6b4c2018-08-16 20:53:58 +00002322
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002323 if (nWidget < 0 || nWidget >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002324 return CJS_Result::Failure(JSMessage::kValueError);
Lei Zhangbc486922018-01-29 15:30:46 +00002325
2326 // TODO(weili): Check whether anything special needed for radio button.
2327 // (When pFormField->GetFieldType() == FormFieldType::kRadioButton.)
Tom Sepezb2e6b4c2018-08-16 20:53:58 +00002328 pFormField->CheckControl(nWidget, bCheckit, NotificationOption::kNotify);
tsepez4cf55152016-11-02 14:37:54 -07002329 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Tom Sepez3a6d0582018-08-17 19:28:52 +00002330 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002331}
2332
Tom Sepez3a6d0582018-08-17 19:28:52 +00002333CJS_Result CJS_Field::clearItems(
Dan Sinclairf7435522018-02-05 22:27:22 +00002334 CJS_Runtime* pRuntime,
2335 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002336 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002337}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002338
Tom Sepez3a6d0582018-08-17 19:28:52 +00002339CJS_Result CJS_Field::defaultIsChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002340 CJS_Runtime* pRuntime,
2341 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002342 if (!m_bCanSet)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002343 return CJS_Result::Failure(JSMessage::kReadOnlyError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002344
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002345 int iSize = params.size();
2346 if (iSize < 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002347 return CJS_Result::Failure(JSMessage::kParamError);
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002348
Lei Zhang4c7ad662018-07-12 20:29:40 +00002349 CPDF_FormField* pFormField = GetFirstFormField();
2350 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002351 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002352
Lei Zhang4c7ad662018-07-12 20:29:40 +00002353 int nWidget = pRuntime->ToInt32(params[0]);
tsepezf3dc8c62016-08-10 06:29:29 -07002354 if (nWidget < 0 || nWidget >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002355 return CJS_Result::Failure(JSMessage::kValueError);
tsepezf3dc8c62016-08-10 06:29:29 -07002356
Tom Sepez3a6d0582018-08-17 19:28:52 +00002357 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +00002358 pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002359}
2360
Tom Sepez3a6d0582018-08-17 19:28:52 +00002361CJS_Result CJS_Field::deleteItemAt(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002362 CJS_Runtime* pRuntime,
2363 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002364 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002365}
2366
Tom Sepez3a6d0582018-08-17 19:28:52 +00002367CJS_Result CJS_Field::getArray(
Dan Sinclairf7435522018-02-05 22:27:22 +00002368 CJS_Runtime* pRuntime,
2369 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang18915232018-07-12 20:53:40 +00002370 std::vector<CPDF_FormField*> FieldArray = GetFormFields();
Lei Zhangd88a3642015-11-10 09:38:57 -08002371 if (FieldArray.empty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002372 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002373
Ryan Harrison275e2602017-09-18 14:23:18 -04002374 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002375 for (CPDF_FormField* pFormField : FieldArray) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002376 swSort.push_back(pdfium::MakeUnique<WideString>(pFormField->GetFullName()));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002377 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002378
Ryan Harrison275e2602017-09-18 14:23:18 -04002379 std::sort(swSort.begin(), swSort.end(),
2380 [](const std::unique_ptr<WideString>& p1,
2381 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002382
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002383 v8::Local<v8::Array> FormFieldArray = pRuntime->NewArray();
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002384 int j = 0;
2385 for (const auto& pStr : swSort) {
Tom Sepez55ccb522018-08-14 23:40:10 +00002386 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
2387 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -08002388 if (pObj.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002389 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002390
Tom Sepezddaa40f2018-06-06 18:30:15 +00002391 auto* pJSField =
2392 static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pObj));
Tom Sepez2cbae732018-06-26 15:11:28 +00002393 pJSField->AttachField(m_pJSDoc.Get(), *pStr);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -04002394 pRuntime->PutArrayElement(FormFieldArray, j++,
dan sinclair80435cb2017-10-24 21:40:24 -04002395 pJSField
2396 ? v8::Local<v8::Value>(pJSField->ToV8Object())
2397 : v8::Local<v8::Value>());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002398 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002399 return CJS_Result::Success(FormFieldArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002400}
2401
Tom Sepez3a6d0582018-08-17 19:28:52 +00002402CJS_Result CJS_Field::getItemAt(
Dan Sinclairf7435522018-02-05 22:27:22 +00002403 CJS_Runtime* pRuntime,
2404 const std::vector<v8::Local<v8::Value>>& params) {
tsepezf3dc8c62016-08-10 06:29:29 -07002405 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002406 int nIdx = -1;
2407 if (iSize >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002408 nIdx = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002409
tsepez4cf55152016-11-02 14:37:54 -07002410 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002411 if (iSize >= 2)
dan sinclair80435cb2017-10-24 21:40:24 -04002412 bExport = pRuntime->ToBoolean(params[1]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002413
Lei Zhang4c7ad662018-07-12 20:29:40 +00002414 CPDF_FormField* pFormField = GetFirstFormField();
2415 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002416 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002417
Lei Zhang83f2d702018-07-12 19:07:40 +00002418 if (!IsComboBoxOrListBox(pFormField))
Tom Sepez3a6d0582018-08-17 19:28:52 +00002419 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Lei Zhang83f2d702018-07-12 19:07:40 +00002420
2421 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2422 nIdx = pFormField->CountOptions() - 1;
2423 if (!bExport) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002424 return CJS_Result::Success(
Tom Sepezb6b01cb2018-06-20 16:10:13 +00002425 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002426 }
Lei Zhang83f2d702018-07-12 19:07:40 +00002427
2428 WideString strval = pFormField->GetOptionValue(nIdx);
2429 if (strval.IsEmpty()) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002430 return CJS_Result::Success(
Lei Zhang83f2d702018-07-12 19:07:40 +00002431 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
2432 }
Tom Sepez3a6d0582018-08-17 19:28:52 +00002433 return CJS_Result::Success(pRuntime->NewString(strval.AsStringView()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002434}
2435
Tom Sepez3a6d0582018-08-17 19:28:52 +00002436CJS_Result CJS_Field::getLock(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002437 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002438 return CJS_Result::Failure(JSMessage::kNotSupportedError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002439}
2440
Tom Sepez3a6d0582018-08-17 19:28:52 +00002441CJS_Result CJS_Field::insertItemAt(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002442 CJS_Runtime* pRuntime,
2443 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002444 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002445}
2446
Tom Sepez3a6d0582018-08-17 19:28:52 +00002447CJS_Result CJS_Field::isBoxChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002448 CJS_Runtime* pRuntime,
2449 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002450 int nIndex = -1;
2451 if (params.size() >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002452 nIndex = pRuntime->ToInt32(params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002453
Lei Zhang4c7ad662018-07-12 20:29:40 +00002454 CPDF_FormField* pFormField = GetFirstFormField();
2455 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002456 return CJS_Result::Failure(JSMessage::kBadObjectError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002457
dan sinclair646634b2017-10-19 14:30:28 -04002458 if (nIndex < 0 || nIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002459 return CJS_Result::Failure(JSMessage::kValueError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002460
Tom Sepez3a6d0582018-08-17 19:28:52 +00002461 return CJS_Result::Success(
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002462 pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) &&
2463 pFormField->GetControl(nIndex)->IsChecked() != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002464}
2465
Tom Sepez3a6d0582018-08-17 19:28:52 +00002466CJS_Result CJS_Field::isDefaultChecked(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002467 CJS_Runtime* pRuntime,
2468 const std::vector<v8::Local<v8::Value>>& params) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002469 int nIndex = -1;
2470 if (params.size() >= 1)
dan sinclair80435cb2017-10-24 21:40:24 -04002471 nIndex = pRuntime->ToInt32(params[0]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002472
Lei Zhang4c7ad662018-07-12 20:29:40 +00002473 CPDF_FormField* pFormField = GetFirstFormField();
2474 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002475 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002476
tsepezf3dc8c62016-08-10 06:29:29 -07002477 if (nIndex < 0 || nIndex >= pFormField->CountControls())
Tom Sepez3a6d0582018-08-17 19:28:52 +00002478 return CJS_Result::Failure(JSMessage::kValueError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002479
Tom Sepez3a6d0582018-08-17 19:28:52 +00002480 return CJS_Result::Success(pRuntime->NewBoolean(
Lei Zhangdfa2ac22018-07-12 19:06:50 +00002481 (IsCheckBoxOrRadioButton(pFormField) &&
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002482 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002483}
2484
Tom Sepez3a6d0582018-08-17 19:28:52 +00002485CJS_Result CJS_Field::setAction(
Dan Sinclairf7435522018-02-05 22:27:22 +00002486 CJS_Runtime* pRuntime,
2487 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002488 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002489}
2490
Tom Sepez3a6d0582018-08-17 19:28:52 +00002491CJS_Result CJS_Field::setFocus(
Dan Sinclairf7435522018-02-05 22:27:22 +00002492 CJS_Runtime* pRuntime,
2493 const std::vector<v8::Local<v8::Value>>& params) {
Lei Zhang4c7ad662018-07-12 20:29:40 +00002494 CPDF_FormField* pFormField = GetFirstFormField();
2495 if (!pFormField)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002496 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002497
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002498 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002499 if (nCount < 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002500 return CJS_Result::Failure(JSMessage::kBadObjectError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002501
Lei Zhang073ecf42018-10-11 16:56:00 +00002502 CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm();
thestig1cd352e2016-06-07 17:53:06 -07002503 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002504 if (nCount == 1) {
Lei Zhang073ecf42018-10-11 16:56:00 +00002505 pWidget = pForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002506 } else {
Tom Sepez101535f2018-06-12 13:36:05 +00002507 IPDF_Page* pPage = IPDFPageFromFPDFPage(m_pFormFillEnv->GetCurrentPage());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002508 if (!pPage)
Tom Sepez3a6d0582018-08-17 19:28:52 +00002509 return CJS_Result::Failure(JSMessage::kBadObjectError);
dsinclair461eeaf2016-07-27 07:40:05 -07002510 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07002511 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002512 for (int32_t i = 0; i < nCount; i++) {
2513 if (CPDFSDK_Widget* pTempWidget =
Lei Zhang073ecf42018-10-11 16:56:00 +00002514 pForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002515 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2516 pWidget = pTempWidget;
2517 break;
2518 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002519 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002520 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002521 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002522 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002523
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002524 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07002525 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07002526 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002527 }
2528
Tom Sepez3a6d0582018-08-17 19:28:52 +00002529 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002530}
2531
Tom Sepez3a6d0582018-08-17 19:28:52 +00002532CJS_Result CJS_Field::setItems(
Dan Sinclairf7435522018-02-05 22:27:22 +00002533 CJS_Runtime* pRuntime,
2534 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002535 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002536}
2537
Tom Sepez3a6d0582018-08-17 19:28:52 +00002538CJS_Result CJS_Field::setLock(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +00002539 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002540 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002541}
2542
Tom Sepez3a6d0582018-08-17 19:28:52 +00002543CJS_Result CJS_Field::signatureGetModifications(
dan sinclair80435cb2017-10-24 21:40:24 -04002544 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002545 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002546 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002547}
2548
Tom Sepez3a6d0582018-08-17 19:28:52 +00002549CJS_Result CJS_Field::signatureGetSeedValue(
dan sinclair80435cb2017-10-24 21:40:24 -04002550 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002551 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002552 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002553}
2554
Tom Sepez3a6d0582018-08-17 19:28:52 +00002555CJS_Result CJS_Field::signatureInfo(
dan sinclair80435cb2017-10-24 21:40:24 -04002556 CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -04002557 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002558 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002559}
2560
Tom Sepez3a6d0582018-08-17 19:28:52 +00002561CJS_Result CJS_Field::signatureSetSeedValue(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002562 CJS_Runtime* pRuntime,
2563 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002564 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002565}
2566
Tom Sepez3a6d0582018-08-17 19:28:52 +00002567CJS_Result CJS_Field::signatureSign(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002568 CJS_Runtime* pRuntime,
2569 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002570 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002571}
2572
Tom Sepez3a6d0582018-08-17 19:28:52 +00002573CJS_Result CJS_Field::signatureValidate(
Dan Sinclair8f524d62017-10-25 13:30:31 -04002574 CJS_Runtime* pRuntime,
2575 const std::vector<v8::Local<v8::Value>>& params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +00002576 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -04002577}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002578
Dan Sinclairf7435522018-02-05 22:27:22 +00002579void CJS_Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
Tom Sepez75acda62018-01-29 20:17:36 +00002580 auto pNewData =
2581 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002582 pNewData->num = n;
Tom Sepez75acda62018-01-29 20:17:36 +00002583 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002584}
2585
Dan Sinclairf7435522018-02-05 22:27:22 +00002586void CJS_Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
Tom Sepez75acda62018-01-29 20:17:36 +00002587 auto pNewData =
2588 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002589 pNewData->b = b;
Tom Sepez75acda62018-01-29 20:17:36 +00002590 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002591}
2592
Lei Zhang109aa6d2018-09-20 01:21:05 +00002593void CJS_Field::AddDelay_String(FIELD_PROP prop, const ByteString& str) {
Tom Sepez75acda62018-01-29 20:17:36 +00002594 auto pNewData =
2595 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Lei Zhang109aa6d2018-09-20 01:21:05 +00002596 pNewData->bytestring = str;
Tom Sepez75acda62018-01-29 20:17:36 +00002597 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002598}
2599
Dan Sinclairf7435522018-02-05 22:27:22 +00002600void CJS_Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
Tom Sepez75acda62018-01-29 20:17:36 +00002601 auto pNewData =
2602 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002603 pNewData->rect = rect;
Tom Sepez75acda62018-01-29 20:17:36 +00002604 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002605}
2606
Dan Sinclairf7435522018-02-05 22:27:22 +00002607void CJS_Field::AddDelay_WordArray(FIELD_PROP prop,
2608 const std::vector<uint32_t>& array) {
Tom Sepez75acda62018-01-29 20:17:36 +00002609 auto pNewData =
2610 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
tsepez41a53ad2016-03-28 16:59:30 -07002611 pNewData->wordarray = array;
Tom Sepez75acda62018-01-29 20:17:36 +00002612 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002613}
2614
Dan Sinclairf7435522018-02-05 22:27:22 +00002615void CJS_Field::AddDelay_WideStringArray(FIELD_PROP prop,
2616 const std::vector<WideString>& array) {
Tom Sepez75acda62018-01-29 20:17:36 +00002617 auto pNewData =
2618 pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName);
tsepez41a53ad2016-03-28 16:59:30 -07002619 pNewData->widestringarray = array;
Tom Sepez75acda62018-01-29 20:17:36 +00002620 m_pJSDoc->AddDelayData(std::move(pNewData));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002621}
2622
Dan Sinclairf7435522018-02-05 22:27:22 +00002623void CJS_Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2624 CJS_DelayData* pData) {
dsinclair3a7741a2016-10-11 10:39:49 -07002625 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002626 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002627 case FP_BORDERSTYLE:
Lei Zhang94919f72018-07-12 21:16:30 +00002628 SetBorderStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Lei Zhang109aa6d2018-09-20 01:21:05 +00002629 pData->bytestring);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002630 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002631 case FP_CURRENTVALUEINDICES:
Lei Zhang94919f72018-07-12 21:16:30 +00002632 SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
2633 pData->nControlIndex, pData->wordarray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002634 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002635 case FP_DISPLAY:
Lei Zhang94919f72018-07-12 21:16:30 +00002636 SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2637 pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002638 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002639 case FP_HIDDEN:
Lei Zhang94919f72018-07-12 21:16:30 +00002640 SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2641 pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002642 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002643 case FP_LINEWIDTH:
Lei Zhang94919f72018-07-12 21:16:30 +00002644 SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2645 pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002646 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002647 case FP_RECT:
Lei Zhang94919f72018-07-12 21:16:30 +00002648 SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2649 pData->rect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002650 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002651 case FP_VALUE:
Lei Zhang94919f72018-07-12 21:16:30 +00002652 SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
2653 pData->widestringarray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002654 break;
dan sinclair646634b2017-10-19 14:30:28 -04002655 default:
2656 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002657 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002658}