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" |
Dan Sinclair | 5123032 | 2017-10-30 15:36:02 +0000 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_formfield.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 16 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 17 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 18 | #include "fpdfsdk/cpdfsdk_widget.h" |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 19 | #include "fxjs/cjs_color.h" |
| 20 | #include "fxjs/cjs_delaydata.h" |
| 21 | #include "fxjs/cjs_document.h" |
| 22 | #include "fxjs/cjs_icon.h" |
| 23 | #include "fxjs/js_resources.h" |
Lei Zhang | 99f5bbb | 2018-10-09 21:31:28 +0000 | [diff] [blame] | 24 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
tonikitoo | 7c05a7a | 2016-08-17 11:08:46 -0700 | [diff] [blame] | 26 | namespace { |
| 27 | |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 28 | bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) { |
| 29 | return pFormField->GetFieldType() == FormFieldType::kCheckBox || |
| 30 | pFormField->GetFieldType() == FormFieldType::kRadioButton; |
| 31 | } |
| 32 | |
| 33 | bool IsComboBoxOrListBox(const CPDF_FormField* pFormField) { |
| 34 | return pFormField->GetFieldType() == FormFieldType::kComboBox || |
| 35 | pFormField->GetFieldType() == FormFieldType::kListBox; |
| 36 | } |
| 37 | |
| 38 | bool IsComboBoxOrTextField(const CPDF_FormField* pFormField) { |
| 39 | return pFormField->GetFieldType() == FormFieldType::kComboBox || |
| 40 | pFormField->GetFieldType() == FormFieldType::kTextField; |
| 41 | } |
| 42 | |
| 43 | void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 44 | CPDF_FormField* pFormField, |
| 45 | bool bChangeMark, |
| 46 | bool bResetAP, |
| 47 | bool bRefresh) { |
| 48 | CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 49 | |
| 50 | if (bResetAP) { |
| 51 | std::vector<CPDFSDK_Annot::ObservedPtr> widgets; |
| 52 | pInterForm->GetWidgets(pFormField, &widgets); |
| 53 | |
| 54 | if (IsComboBoxOrTextField(pFormField)) { |
| 55 | for (auto& pObserved : widgets) { |
| 56 | if (pObserved) { |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 57 | Optional<WideString> sValue = |
| 58 | ToCPDFSDKWidget(pObserved.Get())->OnFormat(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 59 | if (pObserved) { // Not redundant, may be clobbered by OnFormat. |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 60 | ToCPDFSDKWidget(pObserved.Get())->ResetAppearance(sValue, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | } else { |
| 65 | for (auto& pObserved : widgets) { |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 66 | if (pObserved) |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 67 | ToCPDFSDKWidget(pObserved.Get())->ResetAppearance({}, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (bRefresh) { |
| 73 | // Refresh the widget list. The calls in |bResetAP| may have caused widgets |
| 74 | // to be removed from the list. We need to call |GetWidgets| again to be |
| 75 | // sure none of the widgets have been deleted. |
| 76 | std::vector<CPDFSDK_Annot::ObservedPtr> widgets; |
| 77 | pInterForm->GetWidgets(pFormField, &widgets); |
| 78 | |
| 79 | // TODO(dsinclair): Determine if all widgets share the same |
| 80 | // CPDFSDK_InterForm. If that's the case, we can move the code to |
| 81 | // |GetFormFillEnv| out of the loop. |
| 82 | for (auto& pObserved : widgets) { |
| 83 | if (pObserved) { |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 84 | CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pObserved.Get()); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 85 | pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr, |
| 86 | pWidget); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if (bChangeMark) |
| 92 | pFormFillEnv->SetChangeMark(); |
| 93 | } |
| 94 | |
| 95 | void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 96 | CPDF_FormControl* pFormControl, |
| 97 | bool bChangeMark, |
| 98 | bool bResetAP, |
| 99 | bool bRefresh) { |
| 100 | ASSERT(pFormControl); |
| 101 | |
| 102 | CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm(); |
| 103 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); |
| 104 | |
| 105 | if (pWidget) { |
| 106 | CPDFSDK_Widget::ObservedPtr observed_widget(pWidget); |
| 107 | if (bResetAP) { |
| 108 | FormFieldType fieldType = pWidget->GetFieldType(); |
| 109 | if (fieldType == FormFieldType::kComboBox || |
| 110 | fieldType == FormFieldType::kTextField) { |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 111 | Optional<WideString> sValue = pWidget->OnFormat(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 112 | if (!observed_widget) |
| 113 | return; |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 114 | pWidget->ResetAppearance(sValue, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 115 | } else { |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 116 | pWidget->ResetAppearance({}, false); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 117 | } |
| 118 | if (!observed_widget) |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | if (bRefresh) { |
| 123 | CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 124 | pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (bChangeMark) |
| 129 | pFormFillEnv->SetChangeMark(); |
| 130 | } |
| 131 | |
| 132 | std::vector<CPDF_FormField*> GetFormFieldsForName( |
| 133 | CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 134 | const WideString& csFieldName) { |
| 135 | std::vector<CPDF_FormField*> fields; |
| 136 | CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm(); |
| 137 | CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
| 138 | for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) { |
| 139 | if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName)) |
| 140 | fields.push_back(pFormField); |
| 141 | } |
| 142 | return fields; |
| 143 | } |
| 144 | |
tonikitoo | 7c05a7a | 2016-08-17 11:08:46 -0700 | [diff] [blame] | 145 | bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) { |
| 146 | if (!pWidget) |
| 147 | return false; |
| 148 | |
| 149 | uint32_t dwFlag = pWidget->GetFlags(); |
| 150 | switch (value) { |
| 151 | case 0: |
| 152 | dwFlag &= ~ANNOTFLAG_INVISIBLE; |
| 153 | dwFlag &= ~ANNOTFLAG_HIDDEN; |
| 154 | dwFlag &= ~ANNOTFLAG_NOVIEW; |
| 155 | dwFlag |= ANNOTFLAG_PRINT; |
| 156 | break; |
| 157 | case 1: |
| 158 | dwFlag &= ~ANNOTFLAG_INVISIBLE; |
| 159 | dwFlag &= ~ANNOTFLAG_NOVIEW; |
| 160 | dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); |
| 161 | break; |
| 162 | case 2: |
| 163 | dwFlag &= ~ANNOTFLAG_INVISIBLE; |
| 164 | dwFlag &= ~ANNOTFLAG_PRINT; |
| 165 | dwFlag &= ~ANNOTFLAG_HIDDEN; |
| 166 | dwFlag &= ~ANNOTFLAG_NOVIEW; |
| 167 | break; |
| 168 | case 3: |
| 169 | dwFlag |= ANNOTFLAG_NOVIEW; |
| 170 | dwFlag |= ANNOTFLAG_PRINT; |
| 171 | dwFlag &= ~ANNOTFLAG_HIDDEN; |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | if (dwFlag != pWidget->GetFlags()) { |
| 176 | pWidget->SetFlags(dwFlag); |
| 177 | return true; |
| 178 | } |
| 179 | |
| 180 | return false; |
| 181 | } |
| 182 | |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 183 | void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 184 | const WideString& swFieldName, |
| 185 | int nControlIndex, |
| 186 | const ByteString& string) { |
| 187 | ASSERT(pFormFillEnv); |
| 188 | |
| 189 | BorderStyle nBorderStyle = BorderStyle::SOLID; |
| 190 | if (string == "solid") |
| 191 | nBorderStyle = BorderStyle::SOLID; |
| 192 | else if (string == "beveled") |
| 193 | nBorderStyle = BorderStyle::BEVELED; |
| 194 | else if (string == "dashed") |
| 195 | nBorderStyle = BorderStyle::DASH; |
| 196 | else if (string == "inset") |
| 197 | nBorderStyle = BorderStyle::INSET; |
| 198 | else if (string == "underline") |
| 199 | nBorderStyle = BorderStyle::UNDERLINE; |
| 200 | else |
| 201 | return; |
| 202 | |
| 203 | std::vector<CPDF_FormField*> FieldArray = |
| 204 | GetFormFieldsForName(pFormFillEnv, swFieldName); |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame^] | 205 | auto* pInterForm = pFormFillEnv->GetInterForm(); |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 206 | for (CPDF_FormField* pFormField : FieldArray) { |
| 207 | if (nControlIndex < 0) { |
| 208 | bool bSet = false; |
| 209 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame^] | 210 | CPDFSDK_Widget* pWidget = |
| 211 | pInterForm->GetWidget(pFormField->GetControl(i)); |
| 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 | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame^] | 226 | CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl); |
| 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) { |
| 269 | CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 270 | std::vector<CPDF_FormField*> FieldArray = |
| 271 | GetFormFieldsForName(pFormFillEnv, swFieldName); |
| 272 | for (CPDF_FormField* pFormField : FieldArray) { |
| 273 | if (nControlIndex < 0) { |
| 274 | bool bAnySet = false; |
| 275 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 276 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 277 | ASSERT(pFormControl); |
| 278 | |
| 279 | CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl); |
| 280 | if (SetWidgetDisplayStatus(pWidget, number)) |
| 281 | bAnySet = true; |
| 282 | } |
| 283 | |
| 284 | if (bAnySet) |
| 285 | UpdateFormField(pFormFillEnv, pFormField, true, false, true); |
| 286 | } else { |
| 287 | if (nControlIndex >= pFormField->CountControls()) |
| 288 | return; |
| 289 | |
| 290 | CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex); |
| 291 | if (!pFormControl) |
| 292 | return; |
| 293 | |
| 294 | CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl); |
| 295 | if (SetWidgetDisplayStatus(pWidget, number)) |
| 296 | UpdateFormControl(pFormFillEnv, pFormControl, true, false, true); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 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) { |
| 313 | CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 314 | std::vector<CPDF_FormField*> FieldArray = |
| 315 | GetFormFieldsForName(pFormFillEnv, swFieldName); |
| 316 | for (CPDF_FormField* pFormField : FieldArray) { |
| 317 | if (nControlIndex < 0) { |
| 318 | bool bSet = false; |
| 319 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 320 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 321 | ASSERT(pFormControl); |
| 322 | |
| 323 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
| 324 | if (number != pWidget->GetBorderWidth()) { |
| 325 | pWidget->SetBorderWidth(number); |
| 326 | bSet = true; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | if (bSet) |
| 331 | UpdateFormField(pFormFillEnv, pFormField, true, true, true); |
| 332 | } else { |
| 333 | if (nControlIndex >= pFormField->CountControls()) |
| 334 | return; |
| 335 | if (CPDF_FormControl* pFormControl = |
| 336 | pFormField->GetControl(nControlIndex)) { |
| 337 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
| 338 | if (number != pWidget->GetBorderWidth()) { |
| 339 | pWidget->SetBorderWidth(number); |
| 340 | UpdateFormControl(pFormFillEnv, pFormControl, true, true, true); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 349 | const WideString& swFieldName, |
| 350 | int nControlIndex, |
| 351 | const CFX_FloatRect& rect) { |
| 352 | CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 353 | std::vector<CPDF_FormField*> FieldArray = |
| 354 | GetFormFieldsForName(pFormFillEnv, swFieldName); |
| 355 | for (CPDF_FormField* pFormField : FieldArray) { |
| 356 | if (nControlIndex < 0) { |
| 357 | bool bSet = false; |
| 358 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 359 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 360 | ASSERT(pFormControl); |
| 361 | |
| 362 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
| 363 | CFX_FloatRect crRect = rect; |
| 364 | |
| 365 | CPDF_Page* pPDFPage = pWidget->GetPDFPage(); |
| 366 | crRect.Intersect(pPDFPage->GetBBox()); |
| 367 | |
| 368 | if (!crRect.IsEmpty()) { |
| 369 | CFX_FloatRect rcOld = pWidget->GetRect(); |
| 370 | if (crRect.left != rcOld.left || crRect.right != rcOld.right || |
| 371 | crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { |
| 372 | pWidget->SetRect(crRect); |
| 373 | bSet = true; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | if (bSet) |
| 380 | UpdateFormField(pFormFillEnv, pFormField, true, true, true); |
| 381 | |
| 382 | continue; |
| 383 | } |
| 384 | |
| 385 | if (nControlIndex >= pFormField->CountControls()) |
| 386 | return; |
| 387 | if (CPDF_FormControl* pFormControl = |
| 388 | pFormField->GetControl(nControlIndex)) { |
| 389 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
| 390 | CFX_FloatRect crRect = rect; |
| 391 | CPDF_Page* pPDFPage = pWidget->GetPDFPage(); |
| 392 | crRect.Intersect(pPDFPage->GetBBox()); |
| 393 | if (!crRect.IsEmpty()) { |
| 394 | CFX_FloatRect rcOld = pWidget->GetRect(); |
| 395 | if (crRect.left != rcOld.left || crRect.right != rcOld.right || |
| 396 | crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { |
| 397 | pWidget->SetRect(crRect); |
| 398 | UpdateFormControl(pFormFillEnv, pFormControl, true, true, true); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 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}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 515 | {"strokeColor", get_stroke_color_static, set_stroke_color_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 516 | {"style", get_style_static, set_style_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 517 | {"submitName", get_submit_name_static, set_submit_name_static}, |
| 518 | {"textColor", get_text_color_static, set_text_color_static}, |
| 519 | {"textFont", get_text_font_static, set_text_font_static}, |
| 520 | {"textSize", get_text_size_static, set_text_size_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 521 | {"type", get_type_static, set_type_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 522 | {"userName", get_user_name_static, set_user_name_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 523 | {"value", get_value_static, set_value_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 524 | {"valueAsString", get_value_as_string_static, set_value_as_string_static}, |
Dan Sinclair | 909fa2d | 2017-12-12 01:53:28 +0000 | [diff] [blame] | 525 | {"source", get_source_static, set_source_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 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 611 | CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); |
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 | |
| 616 | if (pInterForm->CountFields(swFieldNameTemp) <= 0) { |
| 617 | std::wstring strFieldName; |
| 618 | int iControlNo = -1; |
| 619 | ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo); |
| 620 | if (iControlNo == -1) |
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 | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame^] | 703 | CPDFSDK_Widget* pWidget = m_pFormFillEnv->GetInterForm()->GetWidget( |
| 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 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 922 | CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm(); |
| 923 | CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 924 | return CJS_Result::Success(pRuntime->NewNumber(static_cast<int32_t>( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 925 | pInterForm->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 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1154 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1155 | CPDFSDK_Widget* pWidget = |
| 1156 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 1157 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1158 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1159 | |
| 1160 | uint32_t dwFlag = pWidget->GetFlags(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1161 | if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1162 | return CJS_Result::Success(pRuntime->NewNumber(1)); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1163 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1164 | if (ANNOTFLAG_PRINT & dwFlag) { |
| 1165 | if (ANNOTFLAG_NOVIEW & dwFlag) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1166 | return CJS_Result::Success(pRuntime->NewNumber(3)); |
| 1167 | return CJS_Result::Success(pRuntime->NewNumber(0)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1168 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1169 | return CJS_Result::Success(pRuntime->NewNumber(2)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1170 | } |
| 1171 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1172 | CJS_Result CJS_Field::set_display(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1173 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1174 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1175 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1176 | |
| 1177 | if (m_bDelay) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1178 | AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1179 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1180 | SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1181 | pRuntime->ToInt32(vp)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1182 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1183 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1186 | CJS_Result CJS_Field::get_doc(CJS_Runtime* pRuntime) { |
| 1187 | return CJS_Result::Success(m_pJSDoc->ToV8Object()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1190 | CJS_Result CJS_Field::set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 1191 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1192 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1193 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1194 | CJS_Result CJS_Field::get_editable(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1195 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1196 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1197 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1198 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1199 | if (pFormField->GetFieldType() != FormFieldType::kComboBox) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1200 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1201 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1202 | return CJS_Result::Success( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1203 | pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1206 | CJS_Result CJS_Field::set_editable(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1207 | v8::Local<v8::Value> vp) { |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1208 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1209 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1210 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1211 | } |
| 1212 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1213 | CJS_Result CJS_Field::get_export_values(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1214 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1215 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1216 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1217 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 1218 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1219 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1220 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1221 | v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray(); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1222 | if (m_nFormControlIndex < 0) { |
| 1223 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 1224 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1225 | pRuntime->PutArrayElement( |
| 1226 | ExportValuesArray, i, |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1227 | pRuntime->NewString(pFormControl->GetExportValue().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1228 | } |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1229 | } else { |
| 1230 | if (m_nFormControlIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1231 | return CJS_Result::Failure(JSMessage::kValueError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1232 | |
| 1233 | CPDF_FormControl* pFormControl = |
| 1234 | pFormField->GetControl(m_nFormControlIndex); |
| 1235 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1236 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1237 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1238 | pRuntime->PutArrayElement( |
| 1239 | ExportValuesArray, 0, |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1240 | pRuntime->NewString(pFormControl->GetExportValue().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1241 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1242 | return CJS_Result::Success(ExportValuesArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1245 | CJS_Result CJS_Field::set_export_values(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1246 | v8::Local<v8::Value> vp) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1247 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1248 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1249 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1250 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 1251 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1252 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1253 | |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1254 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1255 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1256 | |
| 1257 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1258 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1259 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1260 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1261 | } |
| 1262 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1263 | CJS_Result CJS_Field::get_file_select(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1264 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1265 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1266 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1267 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1268 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1269 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1270 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1271 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1272 | !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1275 | CJS_Result CJS_Field::set_file_select(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1276 | v8::Local<v8::Value> vp) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1277 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1278 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1279 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1280 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1281 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1282 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1283 | |
| 1284 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1285 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1286 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1287 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1290 | CJS_Result CJS_Field::get_fill_color(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1291 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1292 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1293 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1294 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1295 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1296 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1297 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1298 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1299 | int iColorType; |
| 1300 | pFormControl->GetBackgroundColor(iColorType); |
| 1301 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1302 | CFX_Color color; |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1303 | if (iColorType == CFX_Color::kTransparent) { |
| 1304 | color = CFX_Color(CFX_Color::kTransparent); |
| 1305 | } else if (iColorType == CFX_Color::kGray) { |
| 1306 | color = CFX_Color(CFX_Color::kGray, |
| 1307 | pFormControl->GetOriginalBackgroundColor(0)); |
| 1308 | } else if (iColorType == CFX_Color::kRGB) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1309 | color = |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1310 | CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0), |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1311 | pFormControl->GetOriginalBackgroundColor(1), |
| 1312 | pFormControl->GetOriginalBackgroundColor(2)); |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1313 | } else if (iColorType == CFX_Color::kCMYK) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1314 | color = |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1315 | CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0), |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1316 | pFormControl->GetOriginalBackgroundColor(1), |
| 1317 | pFormControl->GetOriginalBackgroundColor(2), |
| 1318 | pFormControl->GetOriginalBackgroundColor(3)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1319 | } else { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1320 | return CJS_Result::Failure(JSMessage::kValueError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1321 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1322 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1323 | v8::Local<v8::Value> array = |
| 1324 | CJS_Color::ConvertPWLColorToArray(pRuntime, color); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1325 | if (array.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1326 | return CJS_Result::Success(pRuntime->NewArray()); |
| 1327 | return CJS_Result::Success(array); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1328 | } |
| 1329 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1330 | CJS_Result CJS_Field::set_fill_color(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1331 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1332 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1333 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1334 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1335 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1336 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1337 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1338 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 1339 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1342 | CJS_Result CJS_Field::get_hidden(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1343 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1344 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1345 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1346 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1347 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1348 | CPDFSDK_Widget* pWidget = |
| 1349 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 1350 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1351 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1352 | |
| 1353 | uint32_t dwFlags = pWidget->GetFlags(); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1354 | return CJS_Result::Success(pRuntime->NewBoolean( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 1355 | ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1356 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1357 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1358 | CJS_Result CJS_Field::set_hidden(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1359 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1360 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1361 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1362 | |
| 1363 | if (m_bDelay) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1364 | AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1365 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1366 | SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1367 | pRuntime->ToBoolean(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1368 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1369 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1372 | CJS_Result CJS_Field::get_highlight(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1373 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1374 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1375 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1376 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1377 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1378 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1379 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1380 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1381 | |
| 1382 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1383 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1384 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1385 | |
| 1386 | int eHM = pFormControl->GetHighlightingMode(); |
| 1387 | switch (eHM) { |
| 1388 | case CPDF_FormControl::None: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1389 | return CJS_Result::Success(pRuntime->NewString(L"none")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1390 | case CPDF_FormControl::Push: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1391 | return CJS_Result::Success(pRuntime->NewString(L"push")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1392 | case CPDF_FormControl::Invert: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1393 | return CJS_Result::Success(pRuntime->NewString(L"invert")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1394 | case CPDF_FormControl::Outline: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1395 | return CJS_Result::Success(pRuntime->NewString(L"outline")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1396 | case CPDF_FormControl::Toggle: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1397 | return CJS_Result::Success(pRuntime->NewString(L"toggle")); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1398 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1399 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1402 | CJS_Result CJS_Field::set_highlight(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1403 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1404 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1405 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1406 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1407 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1410 | CJS_Result CJS_Field::get_line_width(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1411 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1412 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1413 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1414 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1415 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1416 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1417 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1418 | |
| 1419 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1420 | if (!pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1421 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1422 | |
| 1423 | CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); |
| 1424 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1425 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1426 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1427 | return CJS_Result::Success(pRuntime->NewNumber(pWidget->GetBorderWidth())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1428 | } |
| 1429 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1430 | CJS_Result CJS_Field::set_line_width(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1431 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1432 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1433 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1434 | |
| 1435 | if (m_bDelay) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1436 | AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1437 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1438 | SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1439 | pRuntime->ToInt32(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1440 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1441 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1444 | CJS_Result CJS_Field::get_multiline(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1445 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1446 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1447 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1448 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1449 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1450 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1451 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1452 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1453 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1454 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1455 | !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1458 | CJS_Result CJS_Field::set_multiline(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1459 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1460 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1461 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1462 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1463 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1466 | CJS_Result CJS_Field::get_multiple_selection(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1467 | ASSERT(m_pFormFillEnv); |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1468 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1469 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1470 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1471 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1472 | if (pFormField->GetFieldType() != FormFieldType::kListBox) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1473 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1474 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1475 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1476 | !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1477 | } |
| 1478 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1479 | CJS_Result CJS_Field::set_multiple_selection(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1480 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1481 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1482 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1483 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1484 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1487 | CJS_Result CJS_Field::get_name(CJS_Runtime* pRuntime) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1488 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1489 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1490 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1491 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1492 | return CJS_Result::Success(pRuntime->NewString(m_FieldName.AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1495 | CJS_Result CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 1496 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1497 | } |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1498 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1499 | CJS_Result CJS_Field::get_num_items(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1500 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1501 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1502 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1503 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 1504 | if (!IsComboBoxOrListBox(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1505 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1506 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1507 | return CJS_Result::Success(pRuntime->NewNumber(pFormField->CountOptions())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1510 | CJS_Result CJS_Field::set_num_items(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1511 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1512 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1513 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1514 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1515 | CJS_Result CJS_Field::get_page(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1516 | CPDF_FormField* pFormField = GetFirstFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1517 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1518 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1519 | |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1520 | std::vector<CPDFSDK_Annot::ObservedPtr> widgets; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1521 | m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1522 | if (widgets.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1523 | return CJS_Result::Success(pRuntime->NewNumber(-1)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1524 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1525 | v8::Local<v8::Array> PageArray = pRuntime->NewArray(); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1526 | int i = 0; |
| 1527 | for (const auto& pObserved : widgets) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1528 | if (!pObserved) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1529 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1530 | |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 1531 | auto* pWidget = ToCPDFSDKWidget(pObserved.Get()); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1532 | CPDFSDK_PageView* pPageView = pWidget->GetPageView(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1533 | if (!pPageView) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1534 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1535 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1536 | pRuntime->PutArrayElement( |
| 1537 | PageArray, i, |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1538 | pRuntime->NewNumber(static_cast<int32_t>(pPageView->GetPageIndex()))); |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 1539 | ++i; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1540 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1541 | return CJS_Result::Success(PageArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1544 | CJS_Result CJS_Field::set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 1545 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1546 | } |
| 1547 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1548 | CJS_Result CJS_Field::get_password(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1549 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1550 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1551 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1552 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1553 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1554 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1555 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1556 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1557 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1558 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1559 | !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1562 | CJS_Result CJS_Field::set_password(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1563 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1564 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1565 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1566 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1567 | return CJS_Result::Success(); |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 1568 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1569 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1570 | CJS_Result CJS_Field::get_print(CJS_Runtime* pRuntime) { |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 1571 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1572 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1573 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1574 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1575 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 1576 | CPDFSDK_Widget* pWidget = |
| 1577 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 1578 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1579 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1580 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1581 | return CJS_Result::Success( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1582 | pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1585 | CJS_Result CJS_Field::set_print(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1586 | v8::Local<v8::Value> vp) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 1587 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1588 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1589 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1590 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
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 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1593 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1594 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1595 | for (CPDF_FormField* pFormField : FieldArray) { |
| 1596 | if (m_nFormControlIndex < 0) { |
| 1597 | bool bSet = false; |
| 1598 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 1599 | if (CPDFSDK_Widget* pWidget = |
| 1600 | pInterForm->GetWidget(pFormField->GetControl(i))) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1601 | uint32_t dwFlags = pWidget->GetFlags(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1602 | if (pRuntime->ToBoolean(vp)) |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1603 | dwFlags |= ANNOTFLAG_PRINT; |
| 1604 | else |
| 1605 | dwFlags &= ~ANNOTFLAG_PRINT; |
| 1606 | |
| 1607 | if (dwFlags != pWidget->GetFlags()) { |
| 1608 | pWidget->SetFlags(dwFlags); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1609 | bSet = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1610 | } |
| 1611 | } |
| 1612 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1613 | |
| 1614 | if (bSet) |
| 1615 | UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true); |
| 1616 | |
| 1617 | continue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1618 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1619 | |
| 1620 | if (m_nFormControlIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1621 | return CJS_Result::Failure(JSMessage::kValueError); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1622 | |
| 1623 | if (CPDF_FormControl* pFormControl = |
| 1624 | pFormField->GetControl(m_nFormControlIndex)) { |
| 1625 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
| 1626 | uint32_t dwFlags = pWidget->GetFlags(); |
| 1627 | if (pRuntime->ToBoolean(vp)) |
| 1628 | dwFlags |= ANNOTFLAG_PRINT; |
| 1629 | else |
| 1630 | dwFlags &= ~ANNOTFLAG_PRINT; |
| 1631 | |
| 1632 | if (dwFlags != pWidget->GetFlags()) { |
| 1633 | pWidget->SetFlags(dwFlags); |
| 1634 | UpdateFormControl(m_pFormFillEnv.Get(), |
| 1635 | pFormField->GetControl(m_nFormControlIndex), true, |
| 1636 | false, true); |
| 1637 | } |
| 1638 | } |
| 1639 | } |
| 1640 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1641 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1644 | CJS_Result CJS_Field::get_radios_in_unison(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1645 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1646 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1647 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1648 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1649 | if (pFormField->GetFieldType() != FormFieldType::kRadioButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1650 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1651 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1652 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1653 | !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1656 | CJS_Result CJS_Field::set_radios_in_unison(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1657 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1658 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1659 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1660 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1661 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1662 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1663 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1666 | CJS_Result CJS_Field::get_readonly(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1667 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1668 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1669 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1670 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1671 | return CJS_Result::Success(pRuntime->NewBoolean( |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1672 | !!(pFormField->GetFieldFlags() & FIELDFLAG_READONLY))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1675 | CJS_Result CJS_Field::set_readonly(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1676 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1677 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1678 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1679 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1680 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1681 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1682 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1683 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1684 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1685 | CJS_Result CJS_Field::get_rect(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1686 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1687 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1688 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1689 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1690 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1691 | CPDFSDK_Widget* pWidget = |
| 1692 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 1693 | if (!pWidget) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1694 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1695 | |
| 1696 | CFX_FloatRect crRect = pWidget->GetRect(); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1697 | v8::Local<v8::Array> rcArray = pRuntime->NewArray(); |
| 1698 | pRuntime->PutArrayElement( |
| 1699 | rcArray, 0, pRuntime->NewNumber(static_cast<int32_t>(crRect.left))); |
| 1700 | pRuntime->PutArrayElement( |
| 1701 | rcArray, 1, pRuntime->NewNumber(static_cast<int32_t>(crRect.top))); |
| 1702 | pRuntime->PutArrayElement( |
| 1703 | rcArray, 2, pRuntime->NewNumber(static_cast<int32_t>(crRect.right))); |
| 1704 | pRuntime->PutArrayElement( |
| 1705 | rcArray, 3, pRuntime->NewNumber(static_cast<int32_t>(crRect.bottom))); |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame] | 1706 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1707 | return CJS_Result::Success(rcArray); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1710 | 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] | 1711 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1712 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1713 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1714 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1715 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1716 | v8::Local<v8::Array> rcArray = pRuntime->ToArray(vp); |
| 1717 | if (pRuntime->GetArrayLength(rcArray) < 4) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1718 | return CJS_Result::Failure(JSMessage::kValueError); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1719 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1720 | float pArray[4]; |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1721 | pArray[0] = static_cast<float>( |
| 1722 | pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 0))); |
| 1723 | pArray[1] = static_cast<float>( |
| 1724 | pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 1))); |
| 1725 | pArray[2] = static_cast<float>( |
| 1726 | pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 2))); |
| 1727 | pArray[3] = static_cast<float>( |
| 1728 | pRuntime->ToInt32(pRuntime->GetArrayElement(rcArray, 3))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1729 | |
| 1730 | CFX_FloatRect crRect(pArray); |
| 1731 | if (m_bDelay) { |
| 1732 | AddDelay_Rect(FP_RECT, crRect); |
| 1733 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 1734 | SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, crRect); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1735 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1736 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1739 | CJS_Result CJS_Field::get_required(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1740 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1741 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1742 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1743 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1744 | if (pFormField->GetFieldType() == FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1745 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1746 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1747 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1748 | !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1751 | CJS_Result CJS_Field::set_required(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1752 | v8::Local<v8::Value> vp) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 1753 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1754 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1755 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1756 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1757 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1758 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1759 | } |
| 1760 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1761 | CJS_Result CJS_Field::get_rich_text(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1762 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1763 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1764 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1765 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1766 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1767 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1768 | if (pFormField->GetFieldType() != FormFieldType::kTextField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1769 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1770 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1771 | return CJS_Result::Success(pRuntime->NewBoolean( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 1772 | !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1775 | CJS_Result CJS_Field::set_rich_text(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1776 | v8::Local<v8::Value> vp) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1777 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1778 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1779 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 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::get_rich_value(CJS_Runtime* pRuntime) { |
| 1784 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1785 | } |
| 1786 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1787 | CJS_Result CJS_Field::set_rich_value(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1788 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1789 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1790 | } |
| 1791 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1792 | CJS_Result CJS_Field::get_rotation(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1793 | ASSERT(m_pFormFillEnv); |
| 1794 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1795 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1796 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1797 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1798 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1799 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1800 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1801 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1802 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1803 | return CJS_Result::Success(pRuntime->NewNumber(pFormControl->GetRotation())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1804 | } |
| 1805 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1806 | CJS_Result CJS_Field::set_rotation(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1807 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1808 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1809 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1810 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1811 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1814 | CJS_Result CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1815 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1816 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1817 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1818 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1819 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1820 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1821 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1822 | |
| 1823 | int iColorType; |
| 1824 | pFormControl->GetBorderColor(iColorType); |
| 1825 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1826 | CFX_Color color; |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1827 | if (iColorType == CFX_Color::kTransparent) { |
| 1828 | color = CFX_Color(CFX_Color::kTransparent); |
| 1829 | } else if (iColorType == CFX_Color::kGray) { |
| 1830 | color = |
| 1831 | CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0)); |
| 1832 | } else if (iColorType == CFX_Color::kRGB) { |
| 1833 | color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0), |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1834 | pFormControl->GetOriginalBorderColor(1), |
| 1835 | pFormControl->GetOriginalBorderColor(2)); |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1836 | } else if (iColorType == CFX_Color::kCMYK) { |
| 1837 | color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0), |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 1838 | pFormControl->GetOriginalBorderColor(1), |
| 1839 | pFormControl->GetOriginalBorderColor(2), |
| 1840 | pFormControl->GetOriginalBorderColor(3)); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1841 | } else { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1842 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1845 | v8::Local<v8::Value> array = |
| 1846 | CJS_Color::ConvertPWLColorToArray(pRuntime, color); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1847 | if (array.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1848 | return CJS_Result::Success(pRuntime->NewArray()); |
| 1849 | return CJS_Result::Success(array); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1850 | } |
| 1851 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1852 | CJS_Result CJS_Field::set_stroke_color(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1853 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1854 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1855 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1856 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1857 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 1858 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1861 | CJS_Result CJS_Field::get_style(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1862 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1863 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1864 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1865 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1866 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1867 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 1868 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1869 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1870 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1871 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1872 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1873 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1874 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1875 | WideString csWCaption = pFormControl->GetNormalCaption(); |
| 1876 | ByteString csBCaption; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1877 | |
| 1878 | switch (csWCaption[0]) { |
| 1879 | case L'l': |
| 1880 | csBCaption = "circle"; |
| 1881 | break; |
| 1882 | case L'8': |
| 1883 | csBCaption = "cross"; |
| 1884 | break; |
| 1885 | case L'u': |
| 1886 | csBCaption = "diamond"; |
| 1887 | break; |
| 1888 | case L'n': |
| 1889 | csBCaption = "square"; |
| 1890 | break; |
| 1891 | case L'H': |
| 1892 | csBCaption = "star"; |
| 1893 | break; |
| 1894 | default: // L'4' |
| 1895 | csBCaption = "check"; |
| 1896 | break; |
| 1897 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1898 | return CJS_Result::Success(pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1899 | WideString::FromLocal(csBCaption.AsStringView()).AsStringView())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1900 | } |
| 1901 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1902 | CJS_Result CJS_Field::set_style(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1903 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1904 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 1905 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1906 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 1907 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1910 | CJS_Result CJS_Field::get_submit_name(CJS_Runtime* pRuntime) { |
| 1911 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1914 | CJS_Result CJS_Field::set_submit_name(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1915 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1916 | return CJS_Result::Success(); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1917 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1918 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1919 | CJS_Result CJS_Field::get_text_color(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1920 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1921 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1922 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1923 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1924 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1925 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1926 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1927 | |
Dan Sinclair | 28bb2f2 | 2018-04-03 19:52:27 +0000 | [diff] [blame] | 1928 | Optional<CFX_Color::Type> iColorType; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1929 | FX_ARGB color; |
| 1930 | CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance(); |
Dan Sinclair | a17a0e2 | 2018-03-28 21:10:35 +0000 | [diff] [blame] | 1931 | std::tie(iColorType, color) = FieldAppearance.GetColor(); |
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 | CFX_Color crRet; |
| 1934 | if (!iColorType || *iColorType == CFX_Color::kTransparent) { |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 1935 | crRet = CFX_Color(CFX_Color::kTransparent); |
Dan Sinclair | 28bb2f2 | 2018-04-03 19:52:27 +0000 | [diff] [blame] | 1936 | } else { |
| 1937 | int32_t a; |
| 1938 | int32_t r; |
| 1939 | int32_t g; |
| 1940 | int32_t b; |
| 1941 | std::tie(a, r, g, b) = ArgbDecode(color); |
| 1942 | crRet = CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f); |
| 1943 | } |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1944 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1945 | v8::Local<v8::Value> array = |
| 1946 | CJS_Color::ConvertPWLColorToArray(pRuntime, crRet); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 1947 | if (array.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1948 | return CJS_Result::Success(pRuntime->NewArray()); |
| 1949 | return CJS_Result::Success(array); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1950 | } |
| 1951 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1952 | CJS_Result CJS_Field::set_text_color(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1953 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1954 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1955 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 1956 | if (vp.IsEmpty() || !vp->IsArray()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1957 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 1958 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1961 | CJS_Result CJS_Field::get_text_font(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 1962 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1963 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 1964 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 1965 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1966 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1967 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1968 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1969 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1970 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1971 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 1972 | FormFieldType fieldType = pFormField->GetFieldType(); |
| 1973 | if (fieldType != FormFieldType::kPushButton && |
| 1974 | fieldType != FormFieldType::kComboBox && |
| 1975 | fieldType != FormFieldType::kListBox && |
| 1976 | fieldType != FormFieldType::kTextField) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1977 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1978 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 1979 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1980 | CPDF_Font* pFont = pFormControl->GetDefaultControlFont(); |
| 1981 | if (!pFont) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1982 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 1983 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1984 | return CJS_Result::Success(pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 1985 | WideString::FromLocal(pFont->GetBaseFont().AsStringView()) |
| 1986 | .AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1989 | CJS_Result CJS_Field::set_text_font(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 1990 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 1991 | ASSERT(m_pFormFillEnv); |
| 1992 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 1993 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1994 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
Tom Sepez | 34dab07 | 2018-08-08 17:49:02 +0000 | [diff] [blame] | 1995 | if (pRuntime->ToWideString(vp).ToDefANSI().IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 1996 | return CJS_Result::Failure(JSMessage::kValueError); |
| 1997 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2000 | CJS_Result CJS_Field::get_text_size(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 2001 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2002 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2003 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2004 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2005 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2006 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2007 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2008 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2009 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2010 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2011 | float fFontSize; |
Tom Sepez | c4a2b75 | 2017-04-07 13:56:13 -0700 | [diff] [blame] | 2012 | CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance(); |
| 2013 | FieldAppearance.GetFont(&fFontSize); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2014 | return CJS_Result::Success(pRuntime->NewNumber(static_cast<int>(fFontSize))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2015 | } |
| 2016 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2017 | CJS_Result CJS_Field::set_text_size(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2018 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2019 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 2020 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2021 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 2022 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2025 | CJS_Result CJS_Field::get_type(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2026 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2027 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2028 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2029 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2030 | switch (pFormField->GetFieldType()) { |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2031 | case FormFieldType::kUnknown: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2032 | return CJS_Result::Success(pRuntime->NewString(L"unknown")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2033 | case FormFieldType::kPushButton: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2034 | return CJS_Result::Success(pRuntime->NewString(L"button")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2035 | case FormFieldType::kCheckBox: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2036 | return CJS_Result::Success(pRuntime->NewString(L"checkbox")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2037 | case FormFieldType::kRadioButton: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2038 | return CJS_Result::Success(pRuntime->NewString(L"radiobutton")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2039 | case FormFieldType::kComboBox: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2040 | return CJS_Result::Success(pRuntime->NewString(L"combobox")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2041 | case FormFieldType::kListBox: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2042 | return CJS_Result::Success(pRuntime->NewString(L"listbox")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2043 | case FormFieldType::kTextField: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2044 | return CJS_Result::Success(pRuntime->NewString(L"text")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2045 | case FormFieldType::kSignature: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2046 | return CJS_Result::Success(pRuntime->NewString(L"signature")); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2047 | default: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2048 | return CJS_Result::Success(pRuntime->NewString(L"unknown")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2049 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2052 | CJS_Result CJS_Field::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 2053 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2054 | } |
| 2055 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2056 | CJS_Result CJS_Field::get_user_name(CJS_Runtime* pRuntime) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 2057 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2058 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2059 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2060 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2061 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2062 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2063 | return CJS_Result::Success( |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2064 | pRuntime->NewString(pFormField->GetAlternateName().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2067 | CJS_Result CJS_Field::set_user_name(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2068 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2069 | ASSERT(m_pFormFillEnv); |
Tom Sepez | 1699982 | 2018-06-08 18:23:05 +0000 | [diff] [blame] | 2070 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2071 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
| 2072 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2075 | CJS_Result CJS_Field::get_value(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2076 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2077 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2078 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2079 | |
| 2080 | v8::Local<v8::Value> ret; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2081 | switch (pFormField->GetFieldType()) { |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2082 | case FormFieldType::kPushButton: |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2083 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2084 | case FormFieldType::kComboBox: |
| 2085 | case FormFieldType::kTextField: |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2086 | ret = pRuntime->NewString(pFormField->GetValue().AsStringView()); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2087 | break; |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2088 | case FormFieldType::kListBox: { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2089 | if (pFormField->CountSelectedItems() > 1) { |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2090 | v8::Local<v8::Array> ValueArray = pRuntime->NewArray(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2091 | v8::Local<v8::Value> ElementValue; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2092 | int iIndex; |
| 2093 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 2094 | iIndex = pFormField->GetSelectedIndex(i); |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2095 | ElementValue = pRuntime->NewString( |
| 2096 | pFormField->GetOptionValue(iIndex).AsStringView()); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2097 | if (wcslen(pRuntime->ToWideString(ElementValue).c_str()) == 0) { |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2098 | ElementValue = pRuntime->NewString( |
| 2099 | pFormField->GetOptionLabel(iIndex).AsStringView()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2100 | } |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2101 | pRuntime->PutArrayElement(ValueArray, i, ElementValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2102 | } |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2103 | ret = ValueArray; |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2104 | } else { |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2105 | ret = pRuntime->NewString(pFormField->GetValue().AsStringView()); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2106 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2107 | break; |
| 2108 | } |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2109 | case FormFieldType::kCheckBox: |
| 2110 | case FormFieldType::kRadioButton: { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2111 | bool bFind = false; |
| 2112 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2113 | if (pFormField->GetControl(i)->IsChecked()) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2114 | ret = pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2115 | pFormField->GetControl(i)->GetExportValue().AsStringView()); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2116 | bFind = true; |
| 2117 | break; |
| 2118 | } |
| 2119 | } |
| 2120 | if (!bFind) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2121 | ret = pRuntime->NewString(L"Off"); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2122 | |
| 2123 | break; |
| 2124 | } |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2125 | default: |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2126 | ret = pRuntime->NewString(pFormField->GetValue().AsStringView()); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 2127 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2128 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2129 | return CJS_Result::Success(pRuntime->MaybeCoerceToNumber(ret)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2130 | } |
| 2131 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2132 | CJS_Result CJS_Field::set_value(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2133 | v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2134 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2135 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2136 | |
| 2137 | std::vector<WideString> strArray; |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2138 | if (!vp.IsEmpty() && vp->IsArray()) { |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2139 | v8::Local<v8::Array> ValueArray = pRuntime->ToArray(vp); |
| 2140 | for (size_t i = 0; i < pRuntime->GetArrayLength(ValueArray); i++) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2141 | strArray.push_back( |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2142 | pRuntime->ToWideString(pRuntime->GetArrayElement(ValueArray, i))); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2143 | } |
| 2144 | } else { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2145 | strArray.push_back(pRuntime->ToWideString(vp)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | if (m_bDelay) { |
| 2149 | AddDelay_WideStringArray(FP_VALUE, strArray); |
| 2150 | } else { |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2151 | SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, strArray); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2152 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2153 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2156 | CJS_Result CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2157 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2158 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2159 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2160 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2161 | if (pFormField->GetFieldType() == FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2162 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2163 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2164 | if (pFormField->GetFieldType() == FormFieldType::kCheckBox) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2165 | if (!pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2166 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
| 2167 | return CJS_Result::Success(pRuntime->NewString( |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 2168 | pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2169 | } |
| 2170 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2171 | if (pFormField->GetFieldType() == FormFieldType::kRadioButton && |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2172 | !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2173 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2174 | if (pFormField->GetControl(i)->IsChecked()) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2175 | return CJS_Result::Success(pRuntime->NewString( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2176 | pFormField->GetControl(i)->GetExportValue().AsStringView())); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2177 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2178 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2179 | return CJS_Result::Success(pRuntime->NewString(L"Off")); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2180 | } |
| 2181 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2182 | if (pFormField->GetFieldType() == FormFieldType::kListBox && |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2183 | (pFormField->CountSelectedItems() > 1)) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2184 | return CJS_Result::Success(pRuntime->NewString(L"")); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2185 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2186 | return CJS_Result::Success( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 2187 | pRuntime->NewString(pFormField->GetValue().AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2190 | CJS_Result CJS_Field::set_value_as_string(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2191 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2192 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2193 | } |
| 2194 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2195 | CJS_Result CJS_Field::browseForFileToSubmit( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2196 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2197 | const std::vector<v8::Local<v8::Value>>& params) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2198 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2199 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2200 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2201 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2202 | if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) && |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2203 | (pFormField->GetFieldType() == FormFieldType::kTextField)) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 2204 | WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2205 | if (!wsFileName.IsEmpty()) { |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 2206 | pFormField->SetValue(wsFileName, NotificationOption::kDoNotNotify); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2207 | UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2208 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2209 | return CJS_Result::Success(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2210 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2211 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2214 | CJS_Result CJS_Field::buttonGetCaption( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2215 | CJS_Runtime* pRuntime, |
| 2216 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2217 | int nface = 0; |
| 2218 | int iSize = params.size(); |
| 2219 | if (iSize >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2220 | nface = pRuntime->ToInt32(params[0]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2221 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2222 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2223 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2224 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2225 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2226 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2227 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2228 | |
| 2229 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2230 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2231 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2232 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2233 | if (nface == 0) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2234 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2235 | pRuntime->NewString(pFormControl->GetNormalCaption().AsStringView())); |
| 2236 | } |
| 2237 | if (nface == 1) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2238 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2239 | pRuntime->NewString(pFormControl->GetDownCaption().AsStringView())); |
| 2240 | } |
| 2241 | if (nface == 2) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2242 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2243 | pRuntime->NewString(pFormControl->GetRolloverCaption().AsStringView())); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2244 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2245 | return CJS_Result::Failure(JSMessage::kValueError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2248 | CJS_Result CJS_Field::buttonGetIcon( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2249 | CJS_Runtime* pRuntime, |
| 2250 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 40e0a81 | 2017-02-23 13:07:36 -0800 | [diff] [blame] | 2251 | if (params.size() >= 1) { |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2252 | int nFace = pRuntime->ToInt32(params[0]); |
Tom Sepez | 40e0a81 | 2017-02-23 13:07:36 -0800 | [diff] [blame] | 2253 | if (nFace < 0 || nFace > 2) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2254 | return CJS_Result::Failure(JSMessage::kValueError); |
Tom Sepez | 40e0a81 | 2017-02-23 13:07:36 -0800 | [diff] [blame] | 2255 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2256 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2257 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2258 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2259 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2260 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 2261 | if (pFormField->GetFieldType() != FormFieldType::kPushButton) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2262 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2263 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2264 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2265 | if (!pFormControl) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2266 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2267 | |
Tom Sepez | 55ccb52 | 2018-08-14 23:40:10 +0000 | [diff] [blame] | 2268 | v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( |
| 2269 | CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 2270 | if (pObj.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2271 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2272 | |
Tom Sepez | ddaa40f | 2018-06-06 18:30:15 +0000 | [diff] [blame] | 2273 | auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj)); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2274 | return pJS_Icon ? CJS_Result::Success(pJS_Icon->ToV8Object()) |
| 2275 | : CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2278 | CJS_Result CJS_Field::buttonImportIcon( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2279 | CJS_Runtime* pRuntime, |
| 2280 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2281 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2284 | CJS_Result CJS_Field::buttonSetCaption( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2285 | CJS_Runtime* pRuntime, |
| 2286 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2287 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2290 | CJS_Result CJS_Field::buttonSetIcon( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2291 | CJS_Runtime* pRuntime, |
| 2292 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2293 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2296 | CJS_Result CJS_Field::checkThisBox( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2297 | CJS_Runtime* pRuntime, |
| 2298 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2299 | int iSize = params.size(); |
| 2300 | if (iSize < 1) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2301 | return CJS_Result::Failure(JSMessage::kParamError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2302 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2303 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2304 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2305 | |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2306 | int nWidget = pRuntime->ToInt32(params[0]); |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2307 | bool bCheckit = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2308 | if (iSize >= 2) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2309 | bCheckit = pRuntime->ToBoolean(params[1]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2310 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2311 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2312 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2313 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2314 | |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 2315 | if (!IsCheckBoxOrRadioButton(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2316 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 2317 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2318 | if (nWidget < 0 || nWidget >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2319 | return CJS_Result::Failure(JSMessage::kValueError); |
Lei Zhang | bc48692 | 2018-01-29 15:30:46 +0000 | [diff] [blame] | 2320 | |
| 2321 | // TODO(weili): Check whether anything special needed for radio button. |
| 2322 | // (When pFormField->GetFieldType() == FormFieldType::kRadioButton.) |
Tom Sepez | b2e6b4c | 2018-08-16 20:53:58 +0000 | [diff] [blame] | 2323 | pFormField->CheckControl(nWidget, bCheckit, NotificationOption::kNotify); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2324 | UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true); |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2325 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2326 | } |
| 2327 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2328 | CJS_Result CJS_Field::clearItems( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2329 | CJS_Runtime* pRuntime, |
| 2330 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2331 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2332 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2333 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2334 | CJS_Result CJS_Field::defaultIsChecked( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2335 | CJS_Runtime* pRuntime, |
| 2336 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2337 | if (!m_bCanSet) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2338 | return CJS_Result::Failure(JSMessage::kReadOnlyError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2339 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2340 | int iSize = params.size(); |
| 2341 | if (iSize < 1) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2342 | return CJS_Result::Failure(JSMessage::kParamError); |
Tom Sepez | f4ef3f9 | 2015-04-23 11:31:31 -0700 | [diff] [blame] | 2343 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2344 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2345 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2346 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2347 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2348 | int nWidget = pRuntime->ToInt32(params[0]); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2349 | if (nWidget < 0 || nWidget >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2350 | return CJS_Result::Failure(JSMessage::kValueError); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2351 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2352 | return CJS_Result::Success( |
Tom Sepez | 20736f7 | 2018-08-17 16:44:50 +0000 | [diff] [blame] | 2353 | pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2356 | CJS_Result CJS_Field::deleteItemAt( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2357 | CJS_Runtime* pRuntime, |
| 2358 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2359 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2362 | CJS_Result CJS_Field::getArray( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2363 | CJS_Runtime* pRuntime, |
| 2364 | const std::vector<v8::Local<v8::Value>>& params) { |
Lei Zhang | 1891523 | 2018-07-12 20:53:40 +0000 | [diff] [blame] | 2365 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2366 | if (FieldArray.empty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2367 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2368 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 2369 | std::vector<std::unique_ptr<WideString>> swSort; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2370 | for (CPDF_FormField* pFormField : FieldArray) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2371 | swSort.push_back(pdfium::MakeUnique<WideString>(pFormField->GetFullName())); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2372 | } |
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::sort(swSort.begin(), swSort.end(), |
| 2375 | [](const std::unique_ptr<WideString>& p1, |
| 2376 | const std::unique_ptr<WideString>& p2) { return *p1 < *p2; }); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2377 | |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2378 | v8::Local<v8::Array> FormFieldArray = pRuntime->NewArray(); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2379 | int j = 0; |
| 2380 | for (const auto& pStr : swSort) { |
Tom Sepez | 55ccb52 | 2018-08-14 23:40:10 +0000 | [diff] [blame] | 2381 | v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( |
| 2382 | CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 2383 | if (pObj.IsEmpty()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2384 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2385 | |
Tom Sepez | ddaa40f | 2018-06-06 18:30:15 +0000 | [diff] [blame] | 2386 | auto* pJSField = |
| 2387 | static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pObj)); |
Tom Sepez | 2cbae73 | 2018-06-26 15:11:28 +0000 | [diff] [blame] | 2388 | pJSField->AttachField(m_pJSDoc.Get(), *pStr); |
Dan Sinclair | 3a1ba8e | 2017-10-26 09:28:59 -0400 | [diff] [blame] | 2389 | pRuntime->PutArrayElement(FormFieldArray, j++, |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2390 | pJSField |
| 2391 | ? v8::Local<v8::Value>(pJSField->ToV8Object()) |
| 2392 | : v8::Local<v8::Value>()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2393 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2394 | return CJS_Result::Success(FormFieldArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2397 | CJS_Result CJS_Field::getItemAt( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2398 | CJS_Runtime* pRuntime, |
| 2399 | const std::vector<v8::Local<v8::Value>>& params) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2400 | int iSize = params.size(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2401 | int nIdx = -1; |
| 2402 | if (iSize >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2403 | nIdx = pRuntime->ToInt32(params[0]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2404 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 2405 | bool bExport = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2406 | if (iSize >= 2) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2407 | bExport = pRuntime->ToBoolean(params[1]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2408 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2409 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2410 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2411 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2412 | |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2413 | if (!IsComboBoxOrListBox(pFormField)) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2414 | return CJS_Result::Failure(JSMessage::kObjectTypeError); |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2415 | |
| 2416 | if (nIdx == -1 || nIdx > pFormField->CountOptions()) |
| 2417 | nIdx = pFormField->CountOptions() - 1; |
| 2418 | if (!bExport) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2419 | return CJS_Result::Success( |
Tom Sepez | b6b01cb | 2018-06-20 16:10:13 +0000 | [diff] [blame] | 2420 | pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView())); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2421 | } |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2422 | |
| 2423 | WideString strval = pFormField->GetOptionValue(nIdx); |
| 2424 | if (strval.IsEmpty()) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2425 | return CJS_Result::Success( |
Lei Zhang | 83f2d70 | 2018-07-12 19:07:40 +0000 | [diff] [blame] | 2426 | pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView())); |
| 2427 | } |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2428 | return CJS_Result::Success(pRuntime->NewString(strval.AsStringView())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2431 | CJS_Result CJS_Field::getLock(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2432 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2433 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
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::insertItemAt( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2437 | CJS_Runtime* pRuntime, |
| 2438 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2439 | return CJS_Result::Success(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2442 | CJS_Result CJS_Field::isBoxChecked( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2443 | CJS_Runtime* pRuntime, |
| 2444 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2445 | int nIndex = -1; |
| 2446 | if (params.size() >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2447 | nIndex = pRuntime->ToInt32(params[0]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2448 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2449 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2450 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2451 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2452 | |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 2453 | if (nIndex < 0 || nIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2454 | return CJS_Result::Failure(JSMessage::kValueError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2455 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2456 | return CJS_Result::Success( |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 2457 | pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) && |
| 2458 | pFormField->GetControl(nIndex)->IsChecked() != 0))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2459 | } |
| 2460 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2461 | CJS_Result CJS_Field::isDefaultChecked( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2462 | CJS_Runtime* pRuntime, |
| 2463 | const std::vector<v8::Local<v8::Value>>& params) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2464 | int nIndex = -1; |
| 2465 | if (params.size() >= 1) |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2466 | nIndex = pRuntime->ToInt32(params[0]); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2467 | |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2468 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2469 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2470 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2471 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 2472 | if (nIndex < 0 || nIndex >= pFormField->CountControls()) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2473 | return CJS_Result::Failure(JSMessage::kValueError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2474 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2475 | return CJS_Result::Success(pRuntime->NewBoolean( |
Lei Zhang | dfa2ac2 | 2018-07-12 19:06:50 +0000 | [diff] [blame] | 2476 | (IsCheckBoxOrRadioButton(pFormField) && |
Dan Sinclair | 1d8d9ac | 2017-10-24 11:23:25 -0400 | [diff] [blame] | 2477 | pFormField->GetControl(nIndex)->IsDefaultChecked() != 0))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2480 | CJS_Result CJS_Field::setAction( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2481 | CJS_Runtime* pRuntime, |
| 2482 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2483 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2486 | CJS_Result CJS_Field::setFocus( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2487 | CJS_Runtime* pRuntime, |
| 2488 | const std::vector<v8::Local<v8::Value>>& params) { |
Lei Zhang | 4c7ad66 | 2018-07-12 20:29:40 +0000 | [diff] [blame] | 2489 | CPDF_FormField* pFormField = GetFirstFormField(); |
| 2490 | if (!pFormField) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2491 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2492 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2493 | int32_t nCount = pFormField->CountControls(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2494 | if (nCount < 1) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2495 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2496 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 2497 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 2498 | CPDFSDK_Widget* pWidget = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2499 | if (nCount == 1) { |
dsinclair | c5267c5 | 2016-11-04 15:35:12 -0700 | [diff] [blame] | 2500 | pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2501 | } else { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 2502 | IPDF_Page* pPage = IPDFPageFromFPDFPage(m_pFormFillEnv->GetCurrentPage()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2503 | if (!pPage) |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2504 | return CJS_Result::Failure(JSMessage::kBadObjectError); |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 2505 | if (CPDFSDK_PageView* pCurPageView = |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 2506 | m_pFormFillEnv->GetPageView(pPage, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2507 | for (int32_t i = 0; i < nCount; i++) { |
| 2508 | if (CPDFSDK_Widget* pTempWidget = |
dsinclair | c5267c5 | 2016-11-04 15:35:12 -0700 | [diff] [blame] | 2509 | pInterForm->GetWidget(pFormField->GetControl(i))) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2510 | if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) { |
| 2511 | pWidget = pTempWidget; |
| 2512 | break; |
| 2513 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2514 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2515 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2516 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2517 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2518 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2519 | if (pWidget) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 2520 | CPDFSDK_Annot::ObservedPtr pObserved(pWidget); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 2521 | m_pFormFillEnv->SetFocusAnnot(&pObserved); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2524 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2527 | CJS_Result CJS_Field::setItems( |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2528 | CJS_Runtime* pRuntime, |
| 2529 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2530 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2533 | CJS_Result CJS_Field::setLock(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 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::Failure(JSMessage::kNotSupportedError); |
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::signatureGetModifications( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2539 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2540 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2541 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2544 | CJS_Result CJS_Field::signatureGetSeedValue( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2545 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2546 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2547 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2550 | CJS_Result CJS_Field::signatureInfo( |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 2551 | CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2552 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2553 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2556 | CJS_Result CJS_Field::signatureSetSeedValue( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2557 | CJS_Runtime* pRuntime, |
| 2558 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2559 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2562 | CJS_Result CJS_Field::signatureSign( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2563 | CJS_Runtime* pRuntime, |
| 2564 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2565 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2568 | CJS_Result CJS_Field::signatureValidate( |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2569 | CJS_Runtime* pRuntime, |
| 2570 | const std::vector<v8::Local<v8::Value>>& params) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2571 | return CJS_Result::Failure(JSMessage::kNotSupportedError); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 2572 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2573 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2574 | CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) { |
| 2575 | return CJS_Result::Success(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 2576 | } |
| 2577 | |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2578 | CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime, |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2579 | v8::Local<v8::Value> vp) { |
Tom Sepez | 3a6d058 | 2018-08-17 19:28:52 +0000 | [diff] [blame] | 2580 | return CJS_Result::Success(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2583 | void CJS_Field::AddDelay_Int(FIELD_PROP prop, int32_t n) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2584 | auto pNewData = |
| 2585 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2586 | pNewData->num = n; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2587 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2590 | void CJS_Field::AddDelay_Bool(FIELD_PROP prop, bool b) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2591 | auto pNewData = |
| 2592 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2593 | pNewData->b = b; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2594 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Lei Zhang | 109aa6d | 2018-09-20 01:21:05 +0000 | [diff] [blame] | 2597 | void CJS_Field::AddDelay_String(FIELD_PROP prop, const ByteString& str) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2598 | auto pNewData = |
| 2599 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Lei Zhang | 109aa6d | 2018-09-20 01:21:05 +0000 | [diff] [blame] | 2600 | pNewData->bytestring = str; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2601 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2604 | void CJS_Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2605 | auto pNewData = |
| 2606 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2607 | pNewData->rect = rect; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2608 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2611 | void CJS_Field::AddDelay_WordArray(FIELD_PROP prop, |
| 2612 | const std::vector<uint32_t>& array) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2613 | auto pNewData = |
| 2614 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2615 | pNewData->wordarray = array; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2616 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2619 | void CJS_Field::AddDelay_WideStringArray(FIELD_PROP prop, |
| 2620 | const std::vector<WideString>& array) { |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2621 | auto pNewData = |
| 2622 | pdfium::MakeUnique<CJS_DelayData>(prop, m_nFormControlIndex, m_FieldName); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2623 | pNewData->widestringarray = array; |
Tom Sepez | 75acda6 | 2018-01-29 20:17:36 +0000 | [diff] [blame] | 2624 | m_pJSDoc->AddDelayData(std::move(pNewData)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 2627 | void CJS_Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 2628 | CJS_DelayData* pData) { |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 2629 | ASSERT(pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2630 | switch (pData->eProp) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2631 | case FP_BORDERSTYLE: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2632 | SetBorderStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
Lei Zhang | 109aa6d | 2018-09-20 01:21:05 +0000 | [diff] [blame] | 2633 | pData->bytestring); |
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_CURRENTVALUEINDICES: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2636 | SetCurrentValueIndices(pFormFillEnv, pData->sFieldName, |
| 2637 | pData->nControlIndex, pData->wordarray); |
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_DISPLAY: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2640 | SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2641 | pData->num); |
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_HIDDEN: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2644 | SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2645 | pData->b); |
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_LINEWIDTH: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2648 | SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2649 | pData->num); |
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_RECT: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2652 | SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2653 | pData->rect); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2654 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2655 | case FP_VALUE: |
Lei Zhang | 94919f7 | 2018-07-12 21:16:30 +0000 | [diff] [blame] | 2656 | SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex, |
| 2657 | pData->widestringarray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2658 | break; |
dan sinclair | 646634b | 2017-10-19 14:30:28 -0400 | [diff] [blame] | 2659 | default: |
| 2660 | NOTREACHED(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2661 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2662 | } |