John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // 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 Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 7 | #include "fxjs/cjs_field.h" |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 8 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 11 | #include <utility> |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 12 | |
dsinclair | bc5e6d2 | 2016-10-04 11:08:49 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/font/cpdf_font.h" |
Lei Zhang | bc75f62 | 2018-10-15 18:12:40 +0000 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
Dan Sinclair | 5123032 | 2017-10-30 15:36:02 +0000 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_formfield.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 16 | #include "core/fpdfdoc/cpdf_interactiveform.h" |
| 17 | #include "fpdfsdk/cpdfsdk_interactiveform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 19 | #include "fpdfsdk/cpdfsdk_widget.h" |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 20 | #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 Zhang | 99f5bbb | 2018-10-09 21:31:28 +0000 | [diff] [blame] | 25 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | |
tonikitoo | 7c05a7a | 2016-08-17 11:08:46 -0700 | [diff] [blame] | 27 | namespace { |
| 28 | |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 29 | bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) { |
| 30 | return pFormField->GetFieldType() == FormFieldType::kCheckBox || |
| 31 | pFormField->GetFieldType() == FormFieldType::kRadioButton; |
| 32 | } |
| 33 | |
| 34 | bool IsComboBoxOrListBox(const CPDF_FormField* pFormField) { |
| 35 | return pFormField->GetFieldType() == FormFieldType::kComboBox || |
| 36 | pFormField->GetFieldType() == FormFieldType::kListBox; |
| 37 | } |
| 38 | |
| 39 | bool IsComboBoxOrTextField(const CPDF_FormField* pFormField) { |
| 40 | return pFormField->GetFieldType() == FormFieldType::kComboBox || |
| 41 | pFormField->GetFieldType() == FormFieldType::kTextField; |
| 42 | } |
| 43 | |
| 44 | void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 45 | CPDF_FormField* pFormField, |
| 46 | bool bChangeMark, |
| 47 | bool bResetAP, |
| 48 | bool bRefresh) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 49 | CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 50 | |
| 51 | if (bResetAP) { |
| 52 | std::vector<CPDFSDK_Annot::ObservedPtr> widgets; |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 53 | pForm->GetWidgets(pFormField, &widgets); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 54 | |
| 55 | if (IsComboBoxOrTextField(pFormField)) { |
| 56 | for (auto& pObserved : widgets) { |
| 57 | if (pObserved) { |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 58 | Optional<WideString> sValue = |
| 59 | ToCPDFSDKWidget(pObserved.Get())->OnFormat(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 60 | if (pObserved) { // Not redundant, may be clobbered by OnFormat. |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 61 | ToCPDFSDKWidget(pObserved.Get())->ResetAppearance(sValue, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | } |
| 65 | } else { |
| 66 | for (auto& pObserved : widgets) { |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 67 | if (pObserved) |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 68 | ToCPDFSDKWidget(pObserved.Get())->ResetAppearance({}, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 69 | } |
| 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 Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 78 | pForm->GetWidgets(pFormField, &widgets); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 79 | |
| 80 | // TODO(dsinclair): Determine if all widgets share the same |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 81 | // CPDFSDK_InteractiveForm. If that's the case, we can move the code to |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 82 | // |GetFormFillEnv| out of the loop. |
| 83 | for (auto& pObserved : widgets) { |
| 84 | if (pObserved) { |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 85 | CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pObserved.Get()); |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 86 | pWidget->GetInteractiveForm()->GetFormFillEnv()->UpdateAllViews( |
| 87 | nullptr, pWidget); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (bChangeMark) |
| 93 | pFormFillEnv->SetChangeMark(); |
| 94 | } |
| 95 | |
| 96 | void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 97 | CPDF_FormControl* pFormControl, |
| 98 | bool bChangeMark, |
| 99 | bool bResetAP, |
| 100 | bool bRefresh) { |
| 101 | ASSERT(pFormControl); |
| 102 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 103 | CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 104 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); |
| 105 | |
| 106 | if (pWidget) { |
| 107 | CPDFSDK_Widget::ObservedPtr observed_widget(pWidget); |
| 108 | if (bResetAP) { |
| 109 | FormFieldType fieldType = pWidget->GetFieldType(); |
| 110 | if (fieldType == FormFieldType::kComboBox || |
| 111 | fieldType == FormFieldType::kTextField) { |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 112 | Optional<WideString> sValue = pWidget->OnFormat(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 113 | if (!observed_widget) |
| 114 | return; |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 115 | pWidget->ResetAppearance(sValue, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 116 | } else { |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 117 | pWidget->ResetAppearance({}, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 118 | } |
| 119 | if (!observed_widget) |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | if (bRefresh) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 124 | CPDFSDK_InteractiveForm* pWidgetForm = pWidget->GetInteractiveForm(); |
| 125 | pWidgetForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | if (bChangeMark) |
| 130 | pFormFillEnv->SetChangeMark(); |
| 131 | } |
| 132 | |
| 133 | std::vector<CPDF_FormField*> GetFormFieldsForName( |
| 134 | CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 135 | const WideString& csFieldName) { |
| 136 | std::vector<CPDF_FormField*> fields; |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 137 | 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 Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 141 | fields.push_back(pFormField); |
| 142 | } |
| 143 | return fields; |
| 144 | } |
| 145 | |
tonikitoo | 7c05a7a | 2016-08-17 11:08:46 -0700 | [diff] [blame] | 146 | bool 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 Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 184 | void 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 Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 206 | auto* pForm = pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 207 | 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 Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 211 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormField->GetControl(i)); |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 212 | if (pWidget) { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 213 | 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 Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 226 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 227 | if (pWidget) { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 228 | if (pWidget->GetBorderStyle() != nBorderStyle) { |
| 229 | pWidget->SetBorderStyle(nBorderStyle); |
| 230 | UpdateFormControl(pFormFillEnv, pFormControl, true, true, true); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | } |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 238 | void 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 Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 251 | pFormField->ClearSelection(NotificationOption::kNotify); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 252 | 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 Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 257 | pFormField->SetItemSelection(array[i], true, |
| 258 | NotificationOption::kDoNotNotify); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | UpdateFormField(pFormFillEnv, pFormField, true, true, true); |
| 262 | } |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 265 | void SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 266 | const WideString& swFieldName, |
| 267 | int nControlIndex, |
| 268 | int number) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 269 | CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 270 | std::vector<CPDF_FormField*> FieldArray = |
| 271 | GetFormFieldsForName(pFormFillEnv, swFieldName); |
| 272 | for (CPDF_FormField* pFormField : FieldArray) { |
| 273 | if (nControlIndex < 0) { |
| 274 | bool bAnySet = false; |
| 275 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 276 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 277 | ASSERT(pFormControl); |
| 278 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 279 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 280 | if (SetWidgetDisplayStatus(pWidget, number)) |
| 281 | bAnySet = true; |
| 282 | } |
| 283 | |
| 284 | if (bAnySet) |
| 285 | UpdateFormField(pFormFillEnv, pFormField, true, false, true); |
| 286 | } else { |
| 287 | if (nControlIndex >= pFormField->CountControls()) |
| 288 | return; |
| 289 | |
| 290 | CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex); |
| 291 | if (!pFormControl) |
| 292 | return; |
| 293 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 294 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 295 | if (SetWidgetDisplayStatus(pWidget, number)) |
| 296 | UpdateFormControl(pFormFillEnv, pFormControl, true, false, true); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | void 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 | |
| 309 | void SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 310 | const WideString& swFieldName, |
| 311 | int nControlIndex, |
| 312 | int number) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 313 | CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 314 | std::vector<CPDF_FormField*> FieldArray = |
| 315 | GetFormFieldsForName(pFormFillEnv, swFieldName); |
| 316 | for (CPDF_FormField* pFormField : FieldArray) { |
| 317 | if (nControlIndex < 0) { |
| 318 | bool bSet = false; |
| 319 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 320 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 321 | ASSERT(pFormControl); |
| 322 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 323 | if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 324 | if (number != pWidget->GetBorderWidth()) { |
| 325 | pWidget->SetBorderWidth(number); |
| 326 | bSet = true; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | if (bSet) |
| 331 | UpdateFormField(pFormFillEnv, pFormField, true, true, true); |
| 332 | } else { |
| 333 | if (nControlIndex >= pFormField->CountControls()) |
| 334 | return; |
| 335 | if (CPDF_FormControl* pFormControl = |
| 336 | pFormField->GetControl(nControlIndex)) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 337 | if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 338 | if (number != pWidget->GetBorderWidth()) { |
| 339 | pWidget->SetBorderWidth(number); |
| 340 | UpdateFormControl(pFormFillEnv, pFormControl, true, true, true); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 349 | const WideString& swFieldName, |
| 350 | int nControlIndex, |
| 351 | const CFX_FloatRect& rect) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 352 | CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 353 | std::vector<CPDF_FormField*> FieldArray = |
| 354 | GetFormFieldsForName(pFormFillEnv, swFieldName); |
| 355 | for (CPDF_FormField* pFormField : FieldArray) { |
| 356 | if (nControlIndex < 0) { |
| 357 | bool bSet = false; |
| 358 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 359 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 360 | ASSERT(pFormControl); |
| 361 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 362 | if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 363 | CFX_FloatRect crRect = rect; |
| 364 | |
| 365 | CPDF_Page* pPDFPage = pWidget->GetPDFPage(); |
| 366 | crRect.Intersect(pPDFPage->GetBBox()); |
| 367 | |
| 368 | if (!crRect.IsEmpty()) { |
| 369 | CFX_FloatRect rcOld = pWidget->GetRect(); |
| 370 | if (crRect.left != rcOld.left || crRect.right != rcOld.right || |
| 371 | crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { |
| 372 | pWidget->SetRect(crRect); |
| 373 | bSet = true; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | if (bSet) |
| 380 | UpdateFormField(pFormFillEnv, pFormField, true, true, true); |
| 381 | |
| 382 | continue; |
| 383 | } |
| 384 | |
| 385 | if (nControlIndex >= pFormField->CountControls()) |
| 386 | return; |
| 387 | if (CPDF_FormControl* pFormControl = |
| 388 | pFormField->GetControl(nControlIndex)) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 389 | if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 390 | CFX_FloatRect crRect = rect; |
| 391 | CPDF_Page* pPDFPage = pWidget->GetPDFPage(); |
| 392 | crRect.Intersect(pPDFPage->GetBBox()); |
| 393 | if (!crRect.IsEmpty()) { |
| 394 | CFX_FloatRect rcOld = pWidget->GetRect(); |
| 395 | if (crRect.left != rcOld.left || crRect.right != rcOld.right || |
| 396 | crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { |
| 397 | pWidget->SetRect(crRect); |
| 398 | UpdateFormControl(pFormFillEnv, pFormControl, true, true, true); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | void 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 Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 425 | pFormField->SetValue(strArray[0], NotificationOption::kNotify); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 426 | UpdateFormField(pFormFillEnv, pFormField, true, false, true); |
| 427 | } |
| 428 | break; |
| 429 | case FormFieldType::kCheckBox: |
| 430 | case FormFieldType::kRadioButton: |
| 431 | if (pFormField->GetValue() != strArray[0]) { |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 432 | pFormField->SetValue(strArray[0], NotificationOption::kNotify); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 433 | 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 Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 445 | pFormField->ClearSelection(NotificationOption::kNotify); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 446 | for (const auto& str : strArray) { |
| 447 | int index = pFormField->FindOption(str); |
| 448 | if (!pFormField->IsItemSelected(index)) |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 449 | pFormField->SetItemSelection(index, true, |
| 450 | NotificationOption::kNotify); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 451 | } |
| 452 | UpdateFormField(pFormFillEnv, pFormField, true, false, true); |
| 453 | } |
| 454 | break; |
| 455 | } |
| 456 | default: |
| 457 | break; |
| 458 | } |
| 459 | } |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 460 | } |
| 461 | |
tonikitoo | 7c05a7a | 2016-08-17 11:08:46 -0700 | [diff] [blame] | 462 | } // namespace |
| 463 | |
Dan Sinclair | c94a793 | 2017-10-26 16:48:57 -0400 | [diff] [blame] | 464 | const JSPropertySpec CJS_Field::PropertySpecs[] = { |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 465 | {"alignment", get_alignment_static, set_alignment_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 466 | {"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 Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 479 | {"comb", get_comb_static, set_comb_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 480 | {"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 Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 489 | {"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 sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 493 | {"exportValues", get_export_values_static, set_export_values_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 494 | {"hidden", get_hidden_static, set_hidden_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 495 | {"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 Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 498 | {"highlight", get_highlight_static, set_highlight_static}, |
| 499 | {"multiline", get_multiline_static, set_multiline_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 500 | {"multipleSelection", get_multiple_selection_static, |
| 501 | set_multiple_selection_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 502 | {"name", get_name_static, set_name_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 503 | {"numItems", get_num_items_static, set_num_items_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 504 | {"page", get_page_static, set_page_static}, |
| 505 | {"password", get_password_static, set_password_static}, |
| 506 | {"print", get_print_static, set_print_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 507 | {"radiosInUnison", get_radios_in_unison_static, |
| 508 | set_radios_in_unison_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 509 | {"readonly", get_readonly_static, set_readonly_static}, |
| 510 | {"rect", get_rect_static, set_rect_static}, |
| 511 | {"required", get_required_static, set_required_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 512 | {"richText", get_rich_text_static, set_rich_text_static}, |
| 513 | {"richValue", get_rich_value_static, set_rich_value_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 514 | {"rotation", get_rotation_static, set_rotation_static}, |
Tom Sepez | b14a2f2 | 2018-10-12 23:21:58 +0000 | [diff] [blame] | 515 | {"source", get_source_static, set_source_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 516 | {"strokeColor", get_stroke_color_static, set_stroke_color_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 517 | {"style", get_style_static, set_style_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 518 | {"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 Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 522 | {"type", get_type_static, set_type_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 523 | {"userName", get_user_name_static, set_user_name_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 524 | {"value", get_value_static, set_value_static}, |
Tom Sepez | b14a2f2 | 2018-10-12 23:21:58 +0000 | [diff] [blame] | 525 | {"valueAsString", get_value_as_string_static, set_value_as_string_static}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 526 | |
Dan Sinclair | c94a793 | 2017-10-26 16:48:57 -0400 | [diff] [blame] | 527 | const JSMethodSpec CJS_Field::MethodSpecs[] = { |
Tom Sepez | 9b99b63 | 2017-02-21 15:05:57 -0800 | [diff] [blame] | 528 | {"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 Sinclair | 909fa2d | 2017-12-12 01:53:28 +0000 | [diff] [blame] | 553 | {"signatureValidate", signatureValidate_static}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 554 | |
Dan Sinclair | ef29953 | 2017-10-26 16:48:30 -0400 | [diff] [blame] | 555 | int CJS_Field::ObjDefnID = -1; |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 556 | const char CJS_Field::kName[] = "Field"; |
Dan Sinclair | 89d26c8 | 2017-10-26 12:21:28 -0400 | [diff] [blame] | 557 | |
Dan Sinclair | ef29953 | 2017-10-26 16:48:30 -0400 | [diff] [blame] | 558 | // static |
| 559 | int CJS_Field::GetObjDefnID() { |
| 560 | return ObjDefnID; |
| 561 | } |
| 562 | |
| 563 | // static |
Dan Sinclair | bef4d3e | 2017-10-26 16:49:38 -0400 | [diff] [blame] | 564 | void CJS_Field::DefineJSObjects(CFXJS_Engine* pEngine) { |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 565 | ObjDefnID = pEngine->DefineObj(CJS_Field::kName, FXJSOBJTYPE_DYNAMIC, |
Dan Sinclair | 998fee3 | 2018-02-05 21:43:19 +0000 | [diff] [blame] | 566 | JSConstructor<CJS_Field>, JSDestructor); |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 567 | DefineProps(pEngine, ObjDefnID, PropertySpecs); |
| 568 | DefineMethods(pEngine, ObjDefnID, MethodSpecs); |
Dan Sinclair | 89d26c8 | 2017-10-26 12:21:28 -0400 | [diff] [blame] | 569 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 570 | |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 571 | CJS_Field::CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) |
| 572 | : CJS_Object(pObject, pRuntime) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 573 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 574 | CJS_Field::~CJS_Field() = default; |
| 575 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 576 | // note: iControlNo = -1, means not a widget. |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 577 | void CJS_Field::ParseFieldName(const std::wstring& strFieldNameParsed, |
| 578 | std::wstring& strFieldName, |
| 579 | int& iControlNo) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 580 | 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) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 589 | int iSpaceStart; |
| 590 | while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) { |
| 591 | suffixal.erase(iSpaceStart, 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | } |
| 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 603 | bool CJS_Field::AttachField(CJS_Document* pDocument, |
| 604 | const WideString& csFieldName) { |
Tom Sepez | 2cbae73 | 2018-06-26 15:11:28 +0000 | [diff] [blame] | 605 | m_pJSDoc.Reset(pDocument); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 606 | m_pFormFillEnv.Reset(pDocument->GetFormFillEnv()); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 607 | m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) || |
| 608 | m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 609 | m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 610 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 611 | CPDFSDK_InteractiveForm* pRDForm = m_pFormFillEnv->GetInteractiveForm(); |
| 612 | CPDF_InteractiveForm* pForm = pRDForm->GetInteractiveForm(); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 613 | WideString swFieldNameTemp = csFieldName; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | swFieldNameTemp.Replace(L"..", L"."); |
| 615 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 616 | if (pForm->CountFields(swFieldNameTemp) <= 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | std::wstring strFieldName; |
| 618 | int iControlNo = -1; |
| 619 | ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo); |
| 620 | if (iControlNo == -1) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 621 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | |
| 623 | m_FieldName = strFieldName.c_str(); |
| 624 | m_nFormControlIndex = iControlNo; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 625 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | m_FieldName = swFieldNameTemp; |
| 629 | m_nFormControlIndex = -1; |
| 630 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 631 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 634 | std::vector<CPDF_FormField*> CJS_Field::GetFormFields() const { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 635 | return GetFormFieldsForName(m_pFormFillEnv.Get(), m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 638 | CPDF_FormField* CJS_Field::GetFirstFormField() const { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 639 | std::vector<CPDF_FormField*> fields = GetFormFields(); |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 640 | return fields.empty() ? nullptr : fields[0]; |
| 641 | } |
| 642 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 643 | bool CJS_Field::ValueIsOccur(CPDF_FormField* pFormField, |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 644 | WideString csOptLabel) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) { |
| 646 | if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 647 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | } |
| 649 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 650 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 653 | CPDF_FormControl* CJS_Field::GetSmartFieldControl(CPDF_FormField* pFormField) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | if (!pFormField->CountControls() || |
| 655 | m_nFormControlIndex >= pFormField->CountControls()) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 656 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 657 | if (m_nFormControlIndex < 0) |
| 658 | return pFormField->GetControl(0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 659 | return pFormField->GetControl(m_nFormControlIndex); |
| 660 | } |
| 661 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 662 | CJS_Result CJS_Field::get_alignment(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 663 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 664 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 665 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 666 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 667 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 669 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 670 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 671 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 672 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 673 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 674 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 676 | switch (pFormControl->GetControlAlignment()) { |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 677 | case 0: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 678 | return CJS_Result::Success(pRuntime->NewString(L"left")); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 679 | case 1: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 680 | return CJS_Result::Success(pRuntime->NewString(L"center")); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 681 | case 2: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 682 | return CJS_Result::Success(pRuntime->NewString(L"right")); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 683 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 684 | return CJS_Result::Success(pRuntime->NewString(L"")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 687 | CJS_Result CJS_Field::set_alignment(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 688 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 689 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 690 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 691 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 692 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 693 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 696 | CJS_Result CJS_Field::get_border_style(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 697 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 699 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 700 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 701 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 702 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 703 | CPDFSDK_Widget* pWidget = m_pFormFillEnv->GetInteractiveForm()->GetWidget( |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 704 | GetSmartFieldControl(pFormField)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 705 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 706 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 707 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 708 | switch (pWidget->GetBorderStyle()) { |
| 709 | case BorderStyle::SOLID: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 710 | return CJS_Result::Success(pRuntime->NewString(L"solid")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 711 | case BorderStyle::DASH: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 712 | return CJS_Result::Success(pRuntime->NewString(L"dashed")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 713 | case BorderStyle::BEVELED: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 714 | return CJS_Result::Success(pRuntime->NewString(L"beveled")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 715 | case BorderStyle::INSET: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 716 | return CJS_Result::Success(pRuntime->NewString(L"inset")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 717 | case BorderStyle::UNDERLINE: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 718 | return CJS_Result::Success(pRuntime->NewString(L"underline")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 720 | return CJS_Result::Success(pRuntime->NewString(L"")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 721 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 722 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 723 | CJS_Result CJS_Field::set_border_style(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 724 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 725 | ASSERT(m_pFormFillEnv); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 726 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 727 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 728 | |
Tom Sepez | 34dab07 | 2018-08-08 17:49:02 +0000 | [diff] [blame] | 729 | ByteString byte_str = pRuntime->ToWideString(vp).ToDefANSI(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 730 | if (m_bDelay) { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame] | 731 | AddDelay_String(FP_BORDERSTYLE, byte_str); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 732 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 733 | SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 734 | byte_str); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 735 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 736 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 739 | CJS_Result CJS_Field::get_button_align_x(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 740 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 741 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 742 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 743 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 744 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 745 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 746 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 747 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 748 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 749 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 750 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 751 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 752 | |
| 753 | CPDF_IconFit IconFit = pFormControl->GetIconFit(); |
Lei Zhang | 65b8db9 | 2018-10-10 17:50:31 +0000 | [diff] [blame] | 754 | CFX_PointF pos = IconFit.GetIconBottomLeftPosition(); |
| 755 | return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>(pos.x))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 756 | } |
| 757 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 758 | CJS_Result CJS_Field::set_button_align_x(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 759 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 760 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 761 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 762 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 763 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 766 | CJS_Result CJS_Field::get_button_align_y(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 767 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 768 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 769 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 770 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 771 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 772 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 773 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 774 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 775 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 776 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 777 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 778 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 779 | |
| 780 | CPDF_IconFit IconFit = pFormControl->GetIconFit(); |
Lei Zhang | 65b8db9 | 2018-10-10 17:50:31 +0000 | [diff] [blame] | 781 | CFX_PointF pos = IconFit.GetIconBottomLeftPosition(); |
| 782 | return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>(pos.y))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 783 | } |
| 784 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 785 | CJS_Result CJS_Field::set_button_align_y(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 786 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 787 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 788 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 789 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 790 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 793 | CJS_Result CJS_Field::get_button_fit_bounds(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 794 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 795 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 796 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 797 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 798 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 799 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 800 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 801 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 803 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 804 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 805 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 806 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 807 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 808 | pRuntime->NewBoolean(pFormControl->GetIconFit().GetFittingBounds())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 809 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 810 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 811 | CJS_Result CJS_Field::set_button_fit_bounds(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 812 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 813 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 814 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 815 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 816 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 819 | CJS_Result CJS_Field::get_button_position(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 820 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 821 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 822 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 823 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 824 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 825 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 826 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 827 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 828 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 829 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 830 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 831 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 832 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 833 | return CJS_Result::Success( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 834 | pRuntime->NewNumber(pFormControl->GetTextPosition())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 835 | } |
| 836 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 837 | CJS_Result CJS_Field::set_button_position(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 838 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 839 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 840 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 841 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 842 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 845 | CJS_Result CJS_Field::get_button_scale_how(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 846 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 847 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 848 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 849 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 850 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 851 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 852 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 853 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 854 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 855 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 856 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 857 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 858 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 859 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 860 | pFormControl->GetIconFit().IsProportionalScale() ? 0 : 1)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 861 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 862 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 863 | CJS_Result CJS_Field::set_button_scale_how(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 864 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 865 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 866 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 867 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 868 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 871 | CJS_Result CJS_Field::get_button_scale_when(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 872 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 873 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 874 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 875 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 876 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 877 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 878 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 879 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 880 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 881 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 882 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 883 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 884 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 885 | CPDF_IconFit IconFit = pFormControl->GetIconFit(); |
| 886 | int ScaleM = IconFit.GetScaleMethod(); |
| 887 | switch (ScaleM) { |
| 888 | case CPDF_IconFit::Always: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 889 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 890 | pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Always))); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 891 | case CPDF_IconFit::Bigger: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 892 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 893 | pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Bigger))); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 894 | case CPDF_IconFit::Never: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 895 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 896 | pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Never))); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 897 | case CPDF_IconFit::Smaller: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 898 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 899 | pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Smaller))); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 900 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 901 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 902 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 903 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 904 | CJS_Result CJS_Field::set_button_scale_when(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 905 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 906 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 907 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 908 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 909 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 912 | CJS_Result CJS_Field::get_calc_order_index(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 913 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 914 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 915 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 916 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 917 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 918 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 919 | if (!IsComboBoxOrTextField(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 920 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 921 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 922 | 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 sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 926 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 927 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 928 | CJS_Result CJS_Field::set_calc_order_index(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 929 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 930 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 931 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 932 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 933 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 936 | CJS_Result CJS_Field::get_char_limit(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 937 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 938 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 939 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 940 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 941 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 942 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 943 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 944 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
| 945 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 946 | pRuntime->NewNumber(static_cast<int32_t>(pFormField->GetMaxLen()))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 947 | } |
| 948 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 949 | CJS_Result CJS_Field::set_char_limit(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 950 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 951 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 952 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 953 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 954 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 956 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 957 | CJS_Result CJS_Field::get_comb(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 958 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 959 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 960 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 961 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 962 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 963 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 964 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 965 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 966 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 967 | return CJS_Result::Success( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 968 | pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMB))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 969 | } |
| 970 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 971 | CJS_Result CJS_Field::set_comb(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 972 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 973 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 974 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 975 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 978 | CJS_Result CJS_Field::get_commit_on_sel_change(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 979 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 980 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 981 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 982 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 983 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 984 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 985 | if (!IsComboBoxOrListBox(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 986 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 987 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 988 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 989 | !!(pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 990 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 991 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 992 | CJS_Result CJS_Field::set_commit_on_sel_change(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 993 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 994 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 995 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 996 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 997 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 998 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 999 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1000 | CJS_Result CJS_Field::get_current_value_indices(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1001 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1002 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1003 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1004 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 1005 | if (!IsComboBoxOrListBox(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1006 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1007 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1008 | int count = pFormField->CountSelectedItems(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1009 | if (count <= 0) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1010 | return CJS_Result::Success(pRuntime->NewNumber(-1)); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1011 | if (count == 1) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1012 | return CJS_Result::Success( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 1013 | pRuntime->NewNumber(pFormField->GetSelectedIndex(0))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1014 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1015 | 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 sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1019 | } |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1020 | if (SelArray.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1021 | return CJS_Result::Success(pRuntime->NewArray()); |
| 1022 | return CJS_Result::Success(SelArray); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1025 | CJS_Result CJS_Field::set_current_value_indices(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1026 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1027 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1028 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1029 | |
| 1030 | std::vector<uint32_t> array; |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1031 | if (vp->IsNumber()) { |
| 1032 | array.push_back(pRuntime->ToInt32(vp)); |
| 1033 | } else if (!vp.IsEmpty() && vp->IsArray()) { |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1034 | 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 Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1041 | if (m_bDelay) { |
| 1042 | AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); |
| 1043 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1044 | SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName, |
| 1045 | m_nFormControlIndex, array); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1046 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1047 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1050 | CJS_Result CJS_Field::get_default_style(CJS_Runtime* pRuntime) { |
| 1051 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1054 | CJS_Result CJS_Field::set_default_style(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1055 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1056 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1059 | CJS_Result CJS_Field::get_default_value(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1060 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1061 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1062 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1063 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1064 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1065 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1066 | if (pFormField->GetFieldType() == FormFieldType::kPushButton || |
| 1067 | pFormField->GetFieldType() == FormFieldType::kSignature) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1068 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1071 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1072 | pRuntime->NewString(pFormField->GetDefaultValue().AsStringView())); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1075 | CJS_Result CJS_Field::set_default_value(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1076 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1077 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1078 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1079 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1080 | return CJS_Result::Success(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1081 | } |
| 1082 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1083 | CJS_Result CJS_Field::get_do_not_scroll(CJS_Runtime* pRuntime) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1084 | ASSERT(m_pFormFillEnv); |
| 1085 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1086 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1087 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1088 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1089 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1090 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1091 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1092 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1093 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1094 | !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1097 | CJS_Result CJS_Field::set_do_not_scroll(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1098 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1099 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1100 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1101 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1102 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1105 | CJS_Result CJS_Field::get_do_not_spell_check(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1106 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1108 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1109 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1110 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1111 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 1112 | if (!IsComboBoxOrTextField(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1113 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1114 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1115 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1116 | !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1117 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1118 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1119 | CJS_Result CJS_Field::set_do_not_spell_check(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1120 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1121 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1122 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1123 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1124 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1127 | void CJS_Field::SetDelay(bool bDelay) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1128 | m_bDelay = bDelay; |
| 1129 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1130 | if (m_bDelay) |
| 1131 | return; |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1132 | if (m_pJSDoc) |
| 1133 | m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1136 | CJS_Result CJS_Field::get_delay(CJS_Runtime* pRuntime) { |
| 1137 | return CJS_Result::Success(pRuntime->NewBoolean(m_bDelay)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1140 | CJS_Result CJS_Field::set_delay(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1141 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1142 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1143 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1144 | |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1145 | SetDelay(pRuntime->ToBoolean(vp)); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1146 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1149 | CJS_Result CJS_Field::get_display(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1150 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1151 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1152 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1153 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1154 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
| 1155 | CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1156 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1157 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1158 | |
| 1159 | uint32_t dwFlag = pWidget->GetFlags(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1160 | if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1161 | return CJS_Result::Success(pRuntime->NewNumber(1)); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1162 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1163 | if (ANNOTFLAG_PRINT & dwFlag) { |
| 1164 | if (ANNOTFLAG_NOVIEW & dwFlag) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1165 | return CJS_Result::Success(pRuntime->NewNumber(3)); |
| 1166 | return CJS_Result::Success(pRuntime->NewNumber(0)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1167 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1168 | return CJS_Result::Success(pRuntime->NewNumber(2)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1171 | CJS_Result CJS_Field::set_display(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1172 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1173 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1174 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1175 | |
| 1176 | if (m_bDelay) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1177 | AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1178 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1179 | SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1180 | pRuntime->ToInt32(vp)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1181 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1182 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1185 | CJS_Result CJS_Field::get_doc(CJS_Runtime* pRuntime) { |
| 1186 | return CJS_Result::Success(m_pJSDoc->ToV8Object()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1189 | CJS_Result CJS_Field::set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 1190 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1191 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1192 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1193 | CJS_Result CJS_Field::get_editable(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1194 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1195 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1196 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1197 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1198 | if (pFormField->GetFieldType() != FormFieldType::kComboBox) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1199 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1200 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1201 | return CJS_Result::Success( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1202 | pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1205 | CJS_Result CJS_Field::set_editable(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1206 | v8::Local<v8::Value> vp) { |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1207 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1208 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1209 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1212 | CJS_Result CJS_Field::get_export_values(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1213 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1214 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1215 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1216 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 1217 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1218 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1219 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1220 | v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray(); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1221 | if (m_nFormControlIndex < 0) { |
| 1222 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 1223 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1224 | pRuntime->PutArrayElement( |
| 1225 | ExportValuesArray, i, |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1226 | pRuntime->NewString(pFormControl->GetExportValue().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1227 | } |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1228 | } else { |
| 1229 | if (m_nFormControlIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1230 | return CJS_Result::Failure(JSMessage::kValueError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1231 | |
| 1232 | CPDF_FormControl* pFormControl = |
| 1233 | pFormField->GetControl(m_nFormControlIndex); |
| 1234 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1235 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1236 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1237 | pRuntime->PutArrayElement( |
| 1238 | ExportValuesArray, 0, |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1239 | pRuntime->NewString(pFormControl->GetExportValue().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1240 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1241 | return CJS_Result::Success(ExportValuesArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1244 | CJS_Result CJS_Field::set_export_values(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1245 | v8::Local<v8::Value> vp) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1246 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1247 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1248 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1249 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 1250 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1251 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1252 | |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1253 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1254 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1255 | |
| 1256 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1257 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1258 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1259 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1262 | CJS_Result CJS_Field::get_file_select(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1263 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1264 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1265 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1266 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1267 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1268 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1269 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1270 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1271 | !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1274 | CJS_Result CJS_Field::set_file_select(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1275 | v8::Local<v8::Value> vp) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1276 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1277 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1278 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1279 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1280 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1281 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1282 | |
| 1283 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1284 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1285 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1286 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1289 | CJS_Result CJS_Field::get_fill_color(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1290 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1291 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1292 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1293 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1294 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1295 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1296 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1297 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1298 | int iColorType; |
| 1299 | pFormControl->GetBackgroundColor(iColorType); |
| 1300 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1301 | CFX_Color color; |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1302 | 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 Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1308 | color = |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1309 | CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0), |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1310 | pFormControl->GetOriginalBackgroundColor(1), |
| 1311 | pFormControl->GetOriginalBackgroundColor(2)); |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1312 | } else if (iColorType == CFX_Color::kCMYK) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1313 | color = |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1314 | CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0), |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1315 | pFormControl->GetOriginalBackgroundColor(1), |
| 1316 | pFormControl->GetOriginalBackgroundColor(2), |
| 1317 | pFormControl->GetOriginalBackgroundColor(3)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1318 | } else { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1319 | return CJS_Result::Failure(JSMessage::kValueError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1320 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1321 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1322 | v8::Local<v8::Value> array = |
| 1323 | CJS_Color::ConvertPWLColorToArray(pRuntime, color); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1324 | if (array.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1325 | return CJS_Result::Success(pRuntime->NewArray()); |
| 1326 | return CJS_Result::Success(array); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1327 | } |
| 1328 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1329 | CJS_Result CJS_Field::set_fill_color(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1330 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1331 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1332 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1333 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1334 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1335 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1336 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1337 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 1338 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1341 | CJS_Result CJS_Field::get_hidden(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1342 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1343 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1344 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1345 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1346 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
| 1347 | CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1348 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1349 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1350 | |
| 1351 | uint32_t dwFlags = pWidget->GetFlags(); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1352 | return CJS_Result::Success(pRuntime->NewBoolean( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 1353 | ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1354 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1355 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1356 | CJS_Result CJS_Field::set_hidden(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1357 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1358 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1359 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1360 | |
| 1361 | if (m_bDelay) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1362 | AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1363 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1364 | SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1365 | pRuntime->ToBoolean(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1366 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1367 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1370 | CJS_Result CJS_Field::get_highlight(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1371 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1372 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1373 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1374 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1375 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1376 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1377 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1378 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1379 | |
| 1380 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1381 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1382 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1383 | |
| 1384 | int eHM = pFormControl->GetHighlightingMode(); |
| 1385 | switch (eHM) { |
| 1386 | case CPDF_FormControl::None: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1387 | return CJS_Result::Success(pRuntime->NewString(L"none")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1388 | case CPDF_FormControl::Push: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1389 | return CJS_Result::Success(pRuntime->NewString(L"push")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1390 | case CPDF_FormControl::Invert: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1391 | return CJS_Result::Success(pRuntime->NewString(L"invert")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1392 | case CPDF_FormControl::Outline: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1393 | return CJS_Result::Success(pRuntime->NewString(L"outline")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1394 | case CPDF_FormControl::Toggle: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1395 | return CJS_Result::Success(pRuntime->NewString(L"toggle")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1396 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1397 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1400 | CJS_Result CJS_Field::set_highlight(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1401 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1402 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1403 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1404 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1405 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1408 | CJS_Result CJS_Field::get_line_width(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1409 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1410 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1411 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1412 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1413 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1414 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1415 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1416 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1417 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1418 | if (!pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1419 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1420 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1421 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormField->GetControl(0)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1422 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1423 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1424 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1425 | return CJS_Result::Success(pRuntime->NewNumber(pWidget->GetBorderWidth())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1428 | CJS_Result CJS_Field::set_line_width(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1429 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1430 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1431 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1432 | |
| 1433 | if (m_bDelay) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1434 | AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1435 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1436 | SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1437 | pRuntime->ToInt32(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1438 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1439 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1442 | CJS_Result CJS_Field::get_multiline(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1443 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1444 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1445 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1446 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1447 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1448 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1449 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1450 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1451 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1452 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1453 | !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1456 | CJS_Result CJS_Field::set_multiline(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1457 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1458 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1459 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1460 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1461 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1464 | CJS_Result CJS_Field::get_multiple_selection(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1465 | ASSERT(m_pFormFillEnv); |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1466 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1467 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1468 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1469 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1470 | if (pFormField->GetFieldType() != FormFieldType::kListBox) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1471 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1472 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1473 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1474 | !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1475 | } |
| 1476 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1477 | CJS_Result CJS_Field::set_multiple_selection(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1478 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1479 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1480 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1481 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1482 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1485 | CJS_Result CJS_Field::get_name(CJS_Runtime* pRuntime) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1486 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1487 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1488 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1489 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1490 | return CJS_Result::Success(pRuntime->NewString(m_FieldName.AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1493 | CJS_Result CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 1494 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1495 | } |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1496 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1497 | CJS_Result CJS_Field::get_num_items(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1498 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1499 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1500 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1501 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 1502 | if (!IsComboBoxOrListBox(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1503 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1504 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1505 | return CJS_Result::Success(pRuntime->NewNumber(pFormField->CountOptions())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1508 | CJS_Result CJS_Field::set_num_items(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1509 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1510 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1511 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1512 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1513 | CJS_Result CJS_Field::get_page(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1514 | CPDF_FormField* pFormField = GetFirstFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1515 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1516 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1517 | |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1518 | std::vector<CPDFSDK_Annot::ObservedPtr> widgets; |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1519 | m_pFormFillEnv->GetInteractiveForm()->GetWidgets(pFormField, &widgets); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1520 | if (widgets.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1521 | return CJS_Result::Success(pRuntime->NewNumber(-1)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1522 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1523 | v8::Local<v8::Array> PageArray = pRuntime->NewArray(); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1524 | int i = 0; |
| 1525 | for (const auto& pObserved : widgets) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1526 | if (!pObserved) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1527 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1528 | |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 1529 | auto* pWidget = ToCPDFSDKWidget(pObserved.Get()); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1530 | CPDFSDK_PageView* pPageView = pWidget->GetPageView(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1531 | if (!pPageView) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1532 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1533 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1534 | pRuntime->PutArrayElement( |
| 1535 | PageArray, i, |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1536 | pRuntime->NewNumber(static_cast<int32_t>(pPageView->GetPageIndex()))); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1537 | ++i; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1538 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1539 | return CJS_Result::Success(PageArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1542 | CJS_Result CJS_Field::set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 1543 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1544 | } |
| 1545 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1546 | CJS_Result CJS_Field::get_password(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1547 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1548 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1549 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1550 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1551 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1552 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1553 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1554 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1555 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1556 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1557 | !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1560 | CJS_Result CJS_Field::set_password(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1561 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1562 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1563 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1564 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1565 | return CJS_Result::Success(); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 1566 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1567 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1568 | CJS_Result CJS_Field::get_print(CJS_Runtime* pRuntime) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1569 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1570 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1571 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1572 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1573 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1574 | CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField)); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 1575 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1576 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1577 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1578 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1579 | pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1582 | CJS_Result CJS_Field::set_print(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1583 | v8::Local<v8::Value> vp) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1584 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1585 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1586 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1587 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1588 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1589 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1590 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1591 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1592 | 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 Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1597 | pForm->GetWidget(pFormField->GetControl(i))) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1598 | uint32_t dwFlags = pWidget->GetFlags(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1599 | if (pRuntime->ToBoolean(vp)) |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1600 | dwFlags |= ANNOTFLAG_PRINT; |
| 1601 | else |
| 1602 | dwFlags &= ~ANNOTFLAG_PRINT; |
| 1603 | |
| 1604 | if (dwFlags != pWidget->GetFlags()) { |
| 1605 | pWidget->SetFlags(dwFlags); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1606 | bSet = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1610 | |
| 1611 | if (bSet) |
| 1612 | UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true); |
| 1613 | |
| 1614 | continue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1615 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1616 | |
| 1617 | if (m_nFormControlIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1618 | return CJS_Result::Failure(JSMessage::kValueError); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1619 | |
| 1620 | if (CPDF_FormControl* pFormControl = |
| 1621 | pFormField->GetControl(m_nFormControlIndex)) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1622 | if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1623 | 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 Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1638 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1641 | CJS_Result CJS_Field::get_radios_in_unison(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1642 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1643 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1644 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1645 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1646 | if (pFormField->GetFieldType() != FormFieldType::kRadioButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1647 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1648 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1649 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1650 | !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1653 | CJS_Result CJS_Field::set_radios_in_unison(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1654 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1655 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1656 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1657 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1658 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1659 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1660 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1661 | } |
| 1662 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1663 | CJS_Result CJS_Field::get_readonly(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1664 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1665 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1666 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1667 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1668 | return CJS_Result::Success(pRuntime->NewBoolean( |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1669 | !!(pFormField->GetFieldFlags() & FIELDFLAG_READONLY))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1672 | CJS_Result CJS_Field::set_readonly(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1673 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1674 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1675 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1676 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1677 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1678 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1679 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1680 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1681 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1682 | CJS_Result CJS_Field::get_rect(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1683 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1684 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1685 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1686 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 1687 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
| 1688 | CPDFSDK_Widget* pWidget = pForm->GetWidget(GetSmartFieldControl(pFormField)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1689 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1690 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1691 | |
| 1692 | CFX_FloatRect crRect = pWidget->GetRect(); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1693 | 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 Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame] | 1702 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1703 | return CJS_Result::Success(rcArray); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1706 | CJS_Result CJS_Field::set_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1707 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1708 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1709 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1710 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1711 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1712 | v8::Local<v8::Array> rcArray = pRuntime->ToArray(vp); |
| 1713 | if (pRuntime->GetArrayLength(rcArray) < 4) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1714 | return CJS_Result::Failure(JSMessage::kValueError); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1715 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1716 | float pArray[4]; |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1717 | 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 sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1725 | |
| 1726 | CFX_FloatRect crRect(pArray); |
| 1727 | if (m_bDelay) { |
| 1728 | AddDelay_Rect(FP_RECT, crRect); |
| 1729 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1730 | SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, crRect); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1731 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1732 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1735 | CJS_Result CJS_Field::get_required(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1736 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1737 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1738 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1739 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1740 | if (pFormField->GetFieldType() == FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1741 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1742 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1743 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1744 | !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1747 | CJS_Result CJS_Field::set_required(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1748 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1749 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1750 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1751 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1752 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1753 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1754 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1755 | } |
| 1756 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1757 | CJS_Result CJS_Field::get_rich_text(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1758 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1759 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1760 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1761 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1762 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1763 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1764 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1765 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1766 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1767 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1768 | !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1771 | CJS_Result CJS_Field::set_rich_text(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1772 | v8::Local<v8::Value> vp) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1773 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1774 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1775 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1776 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1777 | } |
| 1778 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1779 | CJS_Result CJS_Field::get_rich_value(CJS_Runtime* pRuntime) { |
| 1780 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1781 | } |
| 1782 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1783 | CJS_Result CJS_Field::set_rich_value(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1784 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1785 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1786 | } |
| 1787 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1788 | CJS_Result CJS_Field::get_rotation(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1789 | ASSERT(m_pFormFillEnv); |
| 1790 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1791 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1792 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1793 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1794 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1795 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1796 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1797 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1798 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1799 | return CJS_Result::Success(pRuntime->NewNumber(pFormControl->GetRotation())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1800 | } |
| 1801 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1802 | CJS_Result CJS_Field::set_rotation(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1803 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1804 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1805 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1806 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1807 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Tom Sepez | b14a2f2 | 2018-10-12 23:21:58 +0000 | [diff] [blame] | 1810 | CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) { |
| 1811 | return CJS_Result::Success(); |
| 1812 | } |
| 1813 | |
| 1814 | CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime, |
| 1815 | v8::Local<v8::Value> vp) { |
| 1816 | return CJS_Result::Success(); |
| 1817 | } |
| 1818 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1819 | CJS_Result CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1820 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1821 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1822 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1823 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1824 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1825 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1826 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1827 | |
| 1828 | int iColorType; |
| 1829 | pFormControl->GetBorderColor(iColorType); |
| 1830 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1831 | CFX_Color color; |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1832 | 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 Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1839 | pFormControl->GetOriginalBorderColor(1), |
| 1840 | pFormControl->GetOriginalBorderColor(2)); |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1841 | } else if (iColorType == CFX_Color::kCMYK) { |
| 1842 | color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0), |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1843 | pFormControl->GetOriginalBorderColor(1), |
| 1844 | pFormControl->GetOriginalBorderColor(2), |
| 1845 | pFormControl->GetOriginalBorderColor(3)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1846 | } else { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1847 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1848 | } |
| 1849 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1850 | v8::Local<v8::Value> array = |
| 1851 | CJS_Color::ConvertPWLColorToArray(pRuntime, color); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1852 | if (array.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1853 | return CJS_Result::Success(pRuntime->NewArray()); |
| 1854 | return CJS_Result::Success(array); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1855 | } |
| 1856 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1857 | CJS_Result CJS_Field::set_stroke_color(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1858 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1859 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1860 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1861 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1862 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 1863 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1866 | CJS_Result CJS_Field::get_style(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1867 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1868 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1869 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1870 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1871 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1872 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 1873 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1874 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1875 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1876 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1877 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1878 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1879 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1880 | WideString csWCaption = pFormControl->GetNormalCaption(); |
| 1881 | ByteString csBCaption; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1882 | |
| 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 Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1903 | return CJS_Result::Success(pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1904 | WideString::FromLocal(csBCaption.AsStringView()).AsStringView())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1905 | } |
| 1906 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1907 | CJS_Result CJS_Field::set_style(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1908 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1909 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1910 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1911 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1912 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1915 | CJS_Result CJS_Field::get_submit_name(CJS_Runtime* pRuntime) { |
| 1916 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1919 | CJS_Result CJS_Field::set_submit_name(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1920 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1921 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1922 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1923 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1924 | CJS_Result CJS_Field::get_text_color(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1925 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1926 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1927 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1928 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1929 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1930 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1931 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1932 | |
Dan Sinclair | 28bb2f2 | 2018-04-03 19:52:27 +0000 | [diff] [blame] | 1933 | Optional<CFX_Color::Type> iColorType; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1934 | FX_ARGB color; |
| 1935 | CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance(); |
Dan Sinclair | a17a0e2 | 2018-03-28 21:10:35 +0000 | [diff] [blame] | 1936 | std::tie(iColorType, color) = FieldAppearance.GetColor(); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1937 | |
Dan Sinclair | 28bb2f2 | 2018-04-03 19:52:27 +0000 | [diff] [blame] | 1938 | CFX_Color crRet; |
| 1939 | if (!iColorType || *iColorType == CFX_Color::kTransparent) { |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1940 | crRet = CFX_Color(CFX_Color::kTransparent); |
Dan Sinclair | 28bb2f2 | 2018-04-03 19:52:27 +0000 | [diff] [blame] | 1941 | } 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 Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1949 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1950 | v8::Local<v8::Value> array = |
| 1951 | CJS_Color::ConvertPWLColorToArray(pRuntime, crRet); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1952 | if (array.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1953 | return CJS_Result::Success(pRuntime->NewArray()); |
| 1954 | return CJS_Result::Success(array); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1955 | } |
| 1956 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1957 | CJS_Result CJS_Field::set_text_color(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1958 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1959 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1960 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1961 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1962 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 1963 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1966 | CJS_Result CJS_Field::get_text_font(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1967 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1968 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1969 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1970 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1971 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1972 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1973 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1974 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1975 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1976 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1977 | FormFieldType fieldType = pFormField->GetFieldType(); |
| 1978 | if (fieldType != FormFieldType::kPushButton && |
| 1979 | fieldType != FormFieldType::kComboBox && |
| 1980 | fieldType != FormFieldType::kListBox && |
| 1981 | fieldType != FormFieldType::kTextField) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1982 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1983 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1984 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1985 | CPDF_Font* pFont = pFormControl->GetDefaultControlFont(); |
| 1986 | if (!pFont) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1987 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1988 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1989 | return CJS_Result::Success(pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1990 | WideString::FromLocal(pFont->GetBaseFont().AsStringView()) |
| 1991 | .AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1994 | CJS_Result CJS_Field::set_text_font(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1995 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1996 | ASSERT(m_pFormFillEnv); |
| 1997 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 1998 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1999 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Tom Sepez | 34dab07 | 2018-08-08 17:49:02 +0000 | [diff] [blame] | 2000 | if (pRuntime->ToWideString(vp).ToDefANSI().IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2001 | return CJS_Result::Failure(JSMessage::kValueError); |
| 2002 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2005 | CJS_Result CJS_Field::get_text_size(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 2006 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2007 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2008 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2009 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2010 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2011 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2012 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2013 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2014 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2015 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2016 | float fFontSize; |
Tom Sepez | c4a2b75 | 2017-04-07 13:56:13 -0700 | [diff] [blame] | 2017 | CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance(); |
| 2018 | FieldAppearance.GetFont(&fFontSize); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2019 | return CJS_Result::Success(pRuntime->NewNumber(static_cast<int>(fFontSize))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2020 | } |
| 2021 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2022 | CJS_Result CJS_Field::set_text_size(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2023 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2024 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 2025 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2026 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 2027 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2030 | CJS_Result CJS_Field::get_type(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2031 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2032 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2033 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2034 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2035 | switch (pFormField->GetFieldType()) { |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2036 | case FormFieldType::kUnknown: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2037 | return CJS_Result::Success(pRuntime->NewString(L"unknown")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2038 | case FormFieldType::kPushButton: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2039 | return CJS_Result::Success(pRuntime->NewString(L"button")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2040 | case FormFieldType::kCheckBox: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2041 | return CJS_Result::Success(pRuntime->NewString(L"checkbox")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2042 | case FormFieldType::kRadioButton: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2043 | return CJS_Result::Success(pRuntime->NewString(L"radiobutton")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2044 | case FormFieldType::kComboBox: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2045 | return CJS_Result::Success(pRuntime->NewString(L"combobox")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2046 | case FormFieldType::kListBox: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2047 | return CJS_Result::Success(pRuntime->NewString(L"listbox")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2048 | case FormFieldType::kTextField: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2049 | return CJS_Result::Success(pRuntime->NewString(L"text")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2050 | case FormFieldType::kSignature: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2051 | return CJS_Result::Success(pRuntime->NewString(L"signature")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2052 | default: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2053 | return CJS_Result::Success(pRuntime->NewString(L"unknown")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2054 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2057 | CJS_Result CJS_Field::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 2058 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2059 | } |
| 2060 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2061 | CJS_Result CJS_Field::get_user_name(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 2062 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2063 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2064 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2065 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2066 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2067 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2068 | return CJS_Result::Success( |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2069 | pRuntime->NewString(pFormField->GetAlternateName().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2072 | CJS_Result CJS_Field::set_user_name(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2073 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2074 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 2075 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2076 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 2077 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2080 | CJS_Result CJS_Field::get_value(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2081 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2082 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2083 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2084 | |
| 2085 | v8::Local<v8::Value> ret; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2086 | switch (pFormField->GetFieldType()) { |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2087 | case FormFieldType::kPushButton: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2088 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2089 | case FormFieldType::kComboBox: |
| 2090 | case FormFieldType::kTextField: |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2091 | ret = pRuntime->NewString(pFormField->GetValue().AsStringView()); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2092 | break; |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2093 | case FormFieldType::kListBox: { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2094 | if (pFormField->CountSelectedItems() > 1) { |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2095 | v8::Local<v8::Array> ValueArray = pRuntime->NewArray(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2096 | v8::Local<v8::Value> ElementValue; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2097 | int iIndex; |
| 2098 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 2099 | iIndex = pFormField->GetSelectedIndex(i); |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2100 | ElementValue = pRuntime->NewString( |
| 2101 | pFormField->GetOptionValue(iIndex).AsStringView()); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2102 | if (wcslen(pRuntime->ToWideString(ElementValue).c_str()) == 0) { |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2103 | ElementValue = pRuntime->NewString( |
| 2104 | pFormField->GetOptionLabel(iIndex).AsStringView()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2105 | } |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2106 | pRuntime->PutArrayElement(ValueArray, i, ElementValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2107 | } |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2108 | ret = ValueArray; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2109 | } else { |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2110 | ret = pRuntime->NewString(pFormField->GetValue().AsStringView()); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2111 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2112 | break; |
| 2113 | } |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2114 | case FormFieldType::kCheckBox: |
| 2115 | case FormFieldType::kRadioButton: { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2116 | bool bFind = false; |
| 2117 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2118 | if (pFormField->GetControl(i)->IsChecked()) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2119 | ret = pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2120 | pFormField->GetControl(i)->GetExportValue().AsStringView()); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2121 | bFind = true; |
| 2122 | break; |
| 2123 | } |
| 2124 | } |
| 2125 | if (!bFind) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2126 | ret = pRuntime->NewString(L"Off"); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2127 | |
| 2128 | break; |
| 2129 | } |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2130 | default: |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2131 | ret = pRuntime->NewString(pFormField->GetValue().AsStringView()); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2132 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2133 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2134 | return CJS_Result::Success(pRuntime->MaybeCoerceToNumber(ret)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2135 | } |
| 2136 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2137 | CJS_Result CJS_Field::set_value(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2138 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2139 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2140 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2141 | |
| 2142 | std::vector<WideString> strArray; |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2143 | if (!vp.IsEmpty() && vp->IsArray()) { |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2144 | v8::Local<v8::Array> ValueArray = pRuntime->ToArray(vp); |
| 2145 | for (size_t i = 0; i < pRuntime->GetArrayLength(ValueArray); i++) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2146 | strArray.push_back( |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2147 | pRuntime->ToWideString(pRuntime->GetArrayElement(ValueArray, i))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2148 | } |
| 2149 | } else { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2150 | strArray.push_back(pRuntime->ToWideString(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | if (m_bDelay) { |
| 2154 | AddDelay_WideStringArray(FP_VALUE, strArray); |
| 2155 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2156 | SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, strArray); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2157 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2158 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2161 | CJS_Result CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2162 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2163 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2164 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2165 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2166 | if (pFormField->GetFieldType() == FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2167 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2168 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2169 | if (pFormField->GetFieldType() == FormFieldType::kCheckBox) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2170 | if (!pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2171 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 2172 | return CJS_Result::Success(pRuntime->NewString( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 2173 | pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2174 | } |
| 2175 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2176 | if (pFormField->GetFieldType() == FormFieldType::kRadioButton && |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2177 | !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2178 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2179 | if (pFormField->GetControl(i)->IsChecked()) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2180 | return CJS_Result::Success(pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2181 | pFormField->GetControl(i)->GetExportValue().AsStringView())); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2182 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2183 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2184 | return CJS_Result::Success(pRuntime->NewString(L"Off")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2185 | } |
| 2186 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2187 | if (pFormField->GetFieldType() == FormFieldType::kListBox && |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2188 | (pFormField->CountSelectedItems() > 1)) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2189 | return CJS_Result::Success(pRuntime->NewString(L"")); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2190 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2191 | return CJS_Result::Success( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 2192 | pRuntime->NewString(pFormField->GetValue().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2195 | CJS_Result CJS_Field::set_value_as_string(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2196 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2197 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2200 | CJS_Result CJS_Field::browseForFileToSubmit( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2201 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2202 | const std::vector<v8::Local<v8::Value>>& params) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2203 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2204 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2205 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2206 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2207 | if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) && |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2208 | (pFormField->GetFieldType() == FormFieldType::kTextField)) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 2209 | WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2210 | if (!wsFileName.IsEmpty()) { |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 2211 | pFormField->SetValue(wsFileName, NotificationOption::kDoNotNotify); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2212 | UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2213 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2214 | return CJS_Result::Success(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2215 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2216 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2219 | CJS_Result CJS_Field::buttonGetCaption( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2220 | CJS_Runtime* pRuntime, |
| 2221 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2222 | int nface = 0; |
| 2223 | int iSize = params.size(); |
| 2224 | if (iSize >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2225 | nface = pRuntime->ToInt32(params[0]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2226 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2227 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2228 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2229 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2230 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2231 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2232 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2233 | |
| 2234 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2235 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2236 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2237 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2238 | if (nface == 0) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2239 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2240 | pRuntime->NewString(pFormControl->GetNormalCaption().AsStringView())); |
| 2241 | } |
| 2242 | if (nface == 1) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2243 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2244 | pRuntime->NewString(pFormControl->GetDownCaption().AsStringView())); |
| 2245 | } |
| 2246 | if (nface == 2) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2247 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2248 | pRuntime->NewString(pFormControl->GetRolloverCaption().AsStringView())); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2249 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2250 | return CJS_Result::Failure(JSMessage::kValueError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2253 | CJS_Result CJS_Field::buttonGetIcon( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2254 | CJS_Runtime* pRuntime, |
| 2255 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 40e0a81 | 2017-02-23 13:07:36 -0800 | [diff] [blame] | 2256 | if (params.size() >= 1) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2257 | int nFace = pRuntime->ToInt32(params[0]); |
Tom Sepez | 40e0a81 | 2017-02-23 13:07:36 -0800 | [diff] [blame] | 2258 | if (nFace < 0 || nFace > 2) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2259 | return CJS_Result::Failure(JSMessage::kValueError); |
Tom Sepez | 40e0a81 | 2017-02-23 13:07:36 -0800 | [diff] [blame] | 2260 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2261 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2262 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2263 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2264 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2265 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2266 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2267 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2268 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2269 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2270 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2271 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2272 | |
Tom Sepez | 55ccb52 | 2018-08-14 23:40:10 +0000 | [diff] [blame] | 2273 | v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( |
| 2274 | CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 2275 | if (pObj.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2276 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2277 | |
Tom Sepez | ddaa40f | 2018-06-06 18:30:15 +0000 | [diff] [blame] | 2278 | auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj)); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2279 | return pJS_Icon ? CJS_Result::Success(pJS_Icon->ToV8Object()) |
| 2280 | : CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2283 | CJS_Result CJS_Field::buttonImportIcon( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2284 | CJS_Runtime* pRuntime, |
| 2285 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2286 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2289 | CJS_Result CJS_Field::buttonSetCaption( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2290 | CJS_Runtime* pRuntime, |
| 2291 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2292 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2295 | CJS_Result CJS_Field::buttonSetIcon( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2296 | CJS_Runtime* pRuntime, |
| 2297 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2298 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2301 | CJS_Result CJS_Field::checkThisBox( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2302 | CJS_Runtime* pRuntime, |
| 2303 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2304 | int iSize = params.size(); |
| 2305 | if (iSize < 1) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2306 | return CJS_Result::Failure(JSMessage::kParamError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2307 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2308 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2309 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2310 | |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2311 | int nWidget = pRuntime->ToInt32(params[0]); |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2312 | bool bCheckit = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2313 | if (iSize >= 2) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2314 | bCheckit = pRuntime->ToBoolean(params[1]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2315 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2316 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2317 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2318 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2319 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 2320 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2321 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 2322 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2323 | if (nWidget < 0 || nWidget >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2324 | return CJS_Result::Failure(JSMessage::kValueError); |
Lei Zhang | bc48692 | 2018-01-29 15:30:46 +0000 | [diff] [blame] | 2325 | |
| 2326 | // TODO(weili): Check whether anything special needed for radio button. |
| 2327 | // (When pFormField->GetFieldType() == FormFieldType::kRadioButton.) |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 2328 | pFormField->CheckControl(nWidget, bCheckit, NotificationOption::kNotify); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2329 | UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2330 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2333 | CJS_Result CJS_Field::clearItems( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2334 | CJS_Runtime* pRuntime, |
| 2335 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2336 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2337 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2338 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2339 | CJS_Result CJS_Field::defaultIsChecked( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2340 | CJS_Runtime* pRuntime, |
| 2341 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2342 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2343 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2344 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2345 | int iSize = params.size(); |
| 2346 | if (iSize < 1) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2347 | return CJS_Result::Failure(JSMessage::kParamError); |
Tom Sepez | f4ef3f9 | 2015-04-23 11:31:31 -0700 | [diff] [blame] | 2348 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2349 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2350 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2351 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2352 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2353 | int nWidget = pRuntime->ToInt32(params[0]); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2354 | if (nWidget < 0 || nWidget >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2355 | return CJS_Result::Failure(JSMessage::kValueError); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2356 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2357 | return CJS_Result::Success( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 2358 | pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2361 | CJS_Result CJS_Field::deleteItemAt( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2362 | CJS_Runtime* pRuntime, |
| 2363 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2364 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2367 | CJS_Result CJS_Field::getArray( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2368 | CJS_Runtime* pRuntime, |
| 2369 | const std::vector<v8::Local<v8::Value>>& params) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 2370 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2371 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2372 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2373 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 2374 | std::vector<std::unique_ptr<WideString>> swSort; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2375 | for (CPDF_FormField* pFormField : FieldArray) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2376 | swSort.push_back(pdfium::MakeUnique<WideString>(pFormField->GetFullName())); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2377 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2378 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 2379 | std::sort(swSort.begin(), swSort.end(), |
| 2380 | [](const std::unique_ptr<WideString>& p1, |
| 2381 | const std::unique_ptr<WideString>& p2) { return *p1 < *p2; }); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2382 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2383 | v8::Local<v8::Array> FormFieldArray = pRuntime->NewArray(); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2384 | int j = 0; |
| 2385 | for (const auto& pStr : swSort) { |
Tom Sepez | 55ccb52 | 2018-08-14 23:40:10 +0000 | [diff] [blame] | 2386 | v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( |
| 2387 | CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 2388 | if (pObj.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2389 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2390 | |
Tom Sepez | ddaa40f | 2018-06-06 18:30:15 +0000 | [diff] [blame] | 2391 | auto* pJSField = |
| 2392 | static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pObj)); |
Tom Sepez | 2cbae73 | 2018-06-26 15:11:28 +0000 | [diff] [blame] | 2393 | pJSField->AttachField(m_pJSDoc.Get(), *pStr); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2394 | pRuntime->PutArrayElement(FormFieldArray, j++, |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2395 | pJSField |
| 2396 | ? v8::Local<v8::Value>(pJSField->ToV8Object()) |
| 2397 | : v8::Local<v8::Value>()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2398 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2399 | return CJS_Result::Success(FormFieldArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2402 | CJS_Result CJS_Field::getItemAt( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2403 | CJS_Runtime* pRuntime, |
| 2404 | const std::vector<v8::Local<v8::Value>>& params) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2405 | int iSize = params.size(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2406 | int nIdx = -1; |
| 2407 | if (iSize >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2408 | nIdx = pRuntime->ToInt32(params[0]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2409 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2410 | bool bExport = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2411 | if (iSize >= 2) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2412 | bExport = pRuntime->ToBoolean(params[1]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2413 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2414 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2415 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2416 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2417 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2418 | if (!IsComboBoxOrListBox(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2419 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2420 | |
| 2421 | if (nIdx == -1 || nIdx > pFormField->CountOptions()) |
| 2422 | nIdx = pFormField->CountOptions() - 1; |
| 2423 | if (!bExport) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2424 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2425 | pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView())); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2426 | } |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2427 | |
| 2428 | WideString strval = pFormField->GetOptionValue(nIdx); |
| 2429 | if (strval.IsEmpty()) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2430 | return CJS_Result::Success( |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2431 | pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView())); |
| 2432 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2433 | return CJS_Result::Success(pRuntime->NewString(strval.AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2436 | CJS_Result CJS_Field::getLock(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2437 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2438 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2439 | } |
| 2440 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2441 | CJS_Result CJS_Field::insertItemAt( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2442 | CJS_Runtime* pRuntime, |
| 2443 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2444 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2447 | CJS_Result CJS_Field::isBoxChecked( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2448 | CJS_Runtime* pRuntime, |
| 2449 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2450 | int nIndex = -1; |
| 2451 | if (params.size() >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2452 | nIndex = pRuntime->ToInt32(params[0]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2453 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2454 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2455 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2456 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2457 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 2458 | if (nIndex < 0 || nIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2459 | return CJS_Result::Failure(JSMessage::kValueError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2460 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2461 | return CJS_Result::Success( |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 2462 | pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) && |
| 2463 | pFormField->GetControl(nIndex)->IsChecked() != 0))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2466 | CJS_Result CJS_Field::isDefaultChecked( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2467 | CJS_Runtime* pRuntime, |
| 2468 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2469 | int nIndex = -1; |
| 2470 | if (params.size() >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2471 | nIndex = pRuntime->ToInt32(params[0]); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2472 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2473 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2474 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2475 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2476 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2477 | if (nIndex < 0 || nIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2478 | return CJS_Result::Failure(JSMessage::kValueError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2479 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2480 | return CJS_Result::Success(pRuntime->NewBoolean( |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 2481 | (IsCheckBoxOrRadioButton(pFormField) && |
Dan Sinclair | 1d8d9ac | 2017-10-24 11:23:25 -0400 | [diff] [blame] | 2482 | pFormField->GetControl(nIndex)->IsDefaultChecked() != 0))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2485 | CJS_Result CJS_Field::setAction( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2486 | CJS_Runtime* pRuntime, |
| 2487 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2488 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2491 | CJS_Result CJS_Field::setFocus( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2492 | CJS_Runtime* pRuntime, |
| 2493 | const std::vector<v8::Local<v8::Value>>& params) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2494 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2495 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2496 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2497 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2498 | int32_t nCount = pFormField->CountControls(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2499 | if (nCount < 1) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2500 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2501 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 2502 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 2503 | CPDFSDK_Widget* pWidget = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2504 | if (nCount == 1) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 2505 | pWidget = pForm->GetWidget(pFormField->GetControl(0)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2506 | } else { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 2507 | IPDF_Page* pPage = IPDFPageFromFPDFPage(m_pFormFillEnv->GetCurrentPage()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2508 | if (!pPage) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2509 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 2510 | if (CPDFSDK_PageView* pCurPageView = |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 2511 | m_pFormFillEnv->GetPageView(pPage, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2512 | for (int32_t i = 0; i < nCount; i++) { |
| 2513 | if (CPDFSDK_Widget* pTempWidget = |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 2514 | pForm->GetWidget(pFormField->GetControl(i))) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2515 | if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) { |
| 2516 | pWidget = pTempWidget; |
| 2517 | break; |
| 2518 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2519 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2520 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2521 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2522 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2523 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2524 | if (pWidget) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 2525 | CPDFSDK_Annot::ObservedPtr pObserved(pWidget); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 2526 | m_pFormFillEnv->SetFocusAnnot(&pObserved); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2529 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2530 | } |
| 2531 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2532 | CJS_Result CJS_Field::setItems( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2533 | CJS_Runtime* pRuntime, |
| 2534 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2535 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2538 | CJS_Result CJS_Field::setLock(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2539 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2540 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2541 | } |
| 2542 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2543 | CJS_Result CJS_Field::signatureGetModifications( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2544 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2545 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2546 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2549 | CJS_Result CJS_Field::signatureGetSeedValue( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2550 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2551 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2552 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2555 | CJS_Result CJS_Field::signatureInfo( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2556 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2557 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2558 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2561 | CJS_Result CJS_Field::signatureSetSeedValue( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2562 | CJS_Runtime* pRuntime, |
| 2563 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2564 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2567 | CJS_Result CJS_Field::signatureSign( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2568 | CJS_Runtime* pRuntime, |
| 2569 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2570 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2573 | CJS_Result CJS_Field::signatureValidate( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2574 | CJS_Runtime* pRuntime, |
| 2575 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2576 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2577 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2578 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2579 | void CJS_Field::AddDelay_Int(FIELD_PROP prop, int32_t n) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2580 | auto pNewData = |
| 2581 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2582 | pNewData->num = n; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2583 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2586 | void CJS_Field::AddDelay_Bool(FIELD_PROP prop, bool b) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2587 | auto pNewData = |
| 2588 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2589 | pNewData->b = b; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2590 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
Lei Zhang | 109aa6d | 2018-09-20 01:21:05 +0000 | [diff] [blame] | 2593 | void CJS_Field::AddDelay_String(FIELD_PROP prop, const ByteString& str) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2594 | auto pNewData = |
| 2595 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Lei Zhang | 109aa6d | 2018-09-20 01:21:05 +0000 | [diff] [blame] | 2596 | pNewData->bytestring = str; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2597 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2600 | void CJS_Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2601 | auto pNewData = |
| 2602 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2603 | pNewData->rect = rect; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2604 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2607 | void CJS_Field::AddDelay_WordArray(FIELD_PROP prop, |
| 2608 | const std::vector<uint32_t>& array) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2609 | auto pNewData = |
| 2610 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2611 | pNewData->wordarray = array; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2612 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2615 | void CJS_Field::AddDelay_WideStringArray(FIELD_PROP prop, |
| 2616 | const std::vector<WideString>& array) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2617 | auto pNewData = |
| 2618 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2619 | pNewData->widestringarray = array; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2620 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2623 | void CJS_Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 2624 | CJS_DelayData* pData) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 2625 | ASSERT(pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2626 | switch (pData->eProp) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2627 | case FP_BORDERSTYLE: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2628 | SetBorderStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
Lei Zhang | 109aa6d | 2018-09-20 01:21:05 +0000 | [diff] [blame] | 2629 | pData->bytestring); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2630 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2631 | case FP_CURRENTVALUEINDICES: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2632 | SetCurrentValueIndices(pFormFillEnv, pData->sFieldName, |
| 2633 | pData->nControlIndex, pData->wordarray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2634 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2635 | case FP_DISPLAY: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2636 | SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2637 | pData->num); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2638 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2639 | case FP_HIDDEN: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2640 | SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2641 | pData->b); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2642 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2643 | case FP_LINEWIDTH: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2644 | SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2645 | pData->num); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2646 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2647 | case FP_RECT: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2648 | SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2649 | pData->rect); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2650 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2651 | case FP_VALUE: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2652 | SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2653 | pData->widestringarray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2654 | break; |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 2655 | default: |
| 2656 | NOTREACHED(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2657 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2658 | } |