Home | History | Annotate | Download | only in javascript
      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.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #include "fpdfsdk/javascript/Field.h"
      8 
      9 #include <algorithm>
     10 #include <memory>
     11 #include <string>
     12 #include <vector>
     13 
     14 #include "core/fpdfapi/font/cpdf_font.h"
     15 #include "core/fpdfapi/page/cpdf_page.h"
     16 #include "core/fpdfapi/parser/cpdf_document.h"
     17 #include "core/fpdfdoc/cpdf_interform.h"
     18 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
     19 #include "fpdfsdk/cpdfsdk_interform.h"
     20 #include "fpdfsdk/cpdfsdk_pageview.h"
     21 #include "fpdfsdk/cpdfsdk_widget.h"
     22 #include "fpdfsdk/javascript/Document.h"
     23 #include "fpdfsdk/javascript/Icon.h"
     24 #include "fpdfsdk/javascript/JS_Define.h"
     25 #include "fpdfsdk/javascript/JS_EventHandler.h"
     26 #include "fpdfsdk/javascript/JS_Object.h"
     27 #include "fpdfsdk/javascript/JS_Value.h"
     28 #include "fpdfsdk/javascript/PublicMethods.h"
     29 #include "fpdfsdk/javascript/cjs_event_context.h"
     30 #include "fpdfsdk/javascript/cjs_runtime.h"
     31 #include "fpdfsdk/javascript/color.h"
     32 
     33 namespace {
     34 
     35 bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
     36   if (!pWidget)
     37     return false;
     38 
     39   uint32_t dwFlag = pWidget->GetFlags();
     40   switch (value) {
     41     case 0:
     42       dwFlag &= ~ANNOTFLAG_INVISIBLE;
     43       dwFlag &= ~ANNOTFLAG_HIDDEN;
     44       dwFlag &= ~ANNOTFLAG_NOVIEW;
     45       dwFlag |= ANNOTFLAG_PRINT;
     46       break;
     47     case 1:
     48       dwFlag &= ~ANNOTFLAG_INVISIBLE;
     49       dwFlag &= ~ANNOTFLAG_NOVIEW;
     50       dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
     51       break;
     52     case 2:
     53       dwFlag &= ~ANNOTFLAG_INVISIBLE;
     54       dwFlag &= ~ANNOTFLAG_PRINT;
     55       dwFlag &= ~ANNOTFLAG_HIDDEN;
     56       dwFlag &= ~ANNOTFLAG_NOVIEW;
     57       break;
     58     case 3:
     59       dwFlag |= ANNOTFLAG_NOVIEW;
     60       dwFlag |= ANNOTFLAG_PRINT;
     61       dwFlag &= ~ANNOTFLAG_HIDDEN;
     62       break;
     63   }
     64 
     65   if (dwFlag != pWidget->GetFlags()) {
     66     pWidget->SetFlags(dwFlag);
     67     return true;
     68   }
     69 
     70   return false;
     71 }
     72 
     73 }  // namespace
     74 
     75 JSConstSpec CJS_Field::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
     76 
     77 JSPropertySpec CJS_Field::PropertySpecs[] = {
     78     {"alignment", get_alignment_static, set_alignment_static},
     79     {"borderStyle", get_borderStyle_static, set_borderStyle_static},
     80     {"buttonAlignX", get_buttonAlignX_static, set_buttonAlignX_static},
     81     {"buttonAlignY", get_buttonAlignY_static, set_buttonAlignY_static},
     82     {"buttonFitBounds", get_buttonFitBounds_static, set_buttonFitBounds_static},
     83     {"buttonPosition", get_buttonPosition_static, set_buttonPosition_static},
     84     {"buttonScaleHow", get_buttonScaleHow_static, set_buttonScaleHow_static},
     85     {"buttonScaleWhen", get_buttonScaleWhen_static, set_buttonScaleWhen_static},
     86     {"calcOrderIndex", get_calcOrderIndex_static, set_calcOrderIndex_static},
     87     {"charLimit", get_charLimit_static, set_charLimit_static},
     88     {"comb", get_comb_static, set_comb_static},
     89     {"commitOnSelChange", get_commitOnSelChange_static,
     90      set_commitOnSelChange_static},
     91     {"currentValueIndices", get_currentValueIndices_static,
     92      set_currentValueIndices_static},
     93     {"defaultStyle", get_defaultStyle_static, set_defaultStyle_static},
     94     {"defaultValue", get_defaultValue_static, set_defaultValue_static},
     95     {"doNotScroll", get_doNotScroll_static, set_doNotScroll_static},
     96     {"doNotSpellCheck", get_doNotSpellCheck_static, set_doNotSpellCheck_static},
     97     {"delay", get_delay_static, set_delay_static},
     98     {"display", get_display_static, set_display_static},
     99     {"doc", get_doc_static, set_doc_static},
    100     {"editable", get_editable_static, set_editable_static},
    101     {"exportValues", get_exportValues_static, set_exportValues_static},
    102     {"hidden", get_hidden_static, set_hidden_static},
    103     {"fileSelect", get_fileSelect_static, set_fileSelect_static},
    104     {"fillColor", get_fillColor_static, set_fillColor_static},
    105     {"lineWidth", get_lineWidth_static, set_lineWidth_static},
    106     {"highlight", get_highlight_static, set_highlight_static},
    107     {"multiline", get_multiline_static, set_multiline_static},
    108     {"multipleSelection", get_multipleSelection_static,
    109      set_multipleSelection_static},
    110     {"name", get_name_static, set_name_static},
    111     {"numItems", get_numItems_static, set_numItems_static},
    112     {"page", get_page_static, set_page_static},
    113     {"password", get_password_static, set_password_static},
    114     {"print", get_print_static, set_print_static},
    115     {"radiosInUnison", get_radiosInUnison_static, set_radiosInUnison_static},
    116     {"readonly", get_readonly_static, set_readonly_static},
    117     {"rect", get_rect_static, set_rect_static},
    118     {"required", get_required_static, set_required_static},
    119     {"richText", get_richText_static, set_richText_static},
    120     {"richValue", get_richValue_static, set_richValue_static},
    121     {"rotation", get_rotation_static, set_rotation_static},
    122     {"strokeColor", get_strokeColor_static, set_strokeColor_static},
    123     {"style", get_style_static, set_style_static},
    124     {"submitName", get_submitName_static, set_submitName_static},
    125     {"textColor", get_textColor_static, set_textColor_static},
    126     {"textFont", get_textFont_static, set_textFont_static},
    127     {"textSize", get_textSize_static, set_textSize_static},
    128     {"type", get_type_static, set_type_static},
    129     {"userName", get_userName_static, set_userName_static},
    130     {"value", get_value_static, set_value_static},
    131     {"valueAsString", get_valueAsString_static, set_valueAsString_static},
    132     {"source", get_source_static, set_source_static},
    133     {0, 0, 0}};
    134 
    135 JSMethodSpec CJS_Field::MethodSpecs[] = {
    136     {"browseForFileToSubmit", browseForFileToSubmit_static},
    137     {"buttonGetCaption", buttonGetCaption_static},
    138     {"buttonGetIcon", buttonGetIcon_static},
    139     {"buttonImportIcon", buttonImportIcon_static},
    140     {"buttonSetCaption", buttonSetCaption_static},
    141     {"buttonSetIcon", buttonSetIcon_static},
    142     {"checkThisBox", checkThisBox_static},
    143     {"clearItems", clearItems_static},
    144     {"defaultIsChecked", defaultIsChecked_static},
    145     {"deleteItemAt", deleteItemAt_static},
    146     {"getArray", getArray_static},
    147     {"getItemAt", getItemAt_static},
    148     {"getLock", getLock_static},
    149     {"insertItemAt", insertItemAt_static},
    150     {"isBoxChecked", isBoxChecked_static},
    151     {"isDefaultChecked", isDefaultChecked_static},
    152     {"setAction", setAction_static},
    153     {"setFocus", setFocus_static},
    154     {"setItems", setItems_static},
    155     {"setLock", setLock_static},
    156     {"signatureGetModifications", signatureGetModifications_static},
    157     {"signatureGetSeedValue", signatureGetSeedValue_static},
    158     {"signatureInfo", signatureInfo_static},
    159     {"signatureSetSeedValue", signatureSetSeedValue_static},
    160     {"signatureSign", signatureSign_static},
    161     {"signatureValidate", signatureValidate_static},
    162     {0, 0}};
    163 
    164 IMPLEMENT_JS_CLASS(CJS_Field, Field)
    165 
    166 CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
    167                              int idx,
    168                              const CFX_WideString& name)
    169     : eProp(prop), nControlIndex(idx), sFieldName(name) {}
    170 
    171 CJS_DelayData::~CJS_DelayData() {}
    172 
    173 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
    174 }
    175 
    176 Field::Field(CJS_Object* pJSObject)
    177     : CJS_EmbedObj(pJSObject),
    178       m_pJSDoc(nullptr),
    179       m_pFormFillEnv(nullptr),
    180       m_nFormControlIndex(-1),
    181       m_bCanSet(false),
    182       m_bDelay(false) {}
    183 
    184 Field::~Field() {}
    185 
    186 // note: iControlNo = -1, means not a widget.
    187 void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
    188                            std::wstring& strFieldName,
    189                            int& iControlNo) {
    190   int iStart = strFieldNameParsed.find_last_of(L'.');
    191   if (iStart == -1) {
    192     strFieldName = strFieldNameParsed;
    193     iControlNo = -1;
    194     return;
    195   }
    196   std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
    197   iControlNo = FXSYS_wtoi(suffixal.c_str());
    198   if (iControlNo == 0) {
    199     int iSpaceStart;
    200     while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
    201       suffixal.erase(iSpaceStart, 1);
    202     }
    203 
    204     if (suffixal.compare(L"0") != 0) {
    205       strFieldName = strFieldNameParsed;
    206       iControlNo = -1;
    207       return;
    208     }
    209   }
    210   strFieldName = strFieldNameParsed.substr(0, iStart);
    211 }
    212 
    213 bool Field::AttachField(Document* pDocument,
    214                         const CFX_WideString& csFieldName) {
    215   m_pJSDoc = pDocument;
    216   m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
    217   m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
    218               m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
    219               m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
    220 
    221   CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
    222   CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
    223   CFX_WideString swFieldNameTemp = csFieldName;
    224   swFieldNameTemp.Replace(L"..", L".");
    225 
    226   if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
    227     std::wstring strFieldName;
    228     int iControlNo = -1;
    229     ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
    230     if (iControlNo == -1)
    231       return false;
    232 
    233     m_FieldName = strFieldName.c_str();
    234     m_nFormControlIndex = iControlNo;
    235     return true;
    236   }
    237 
    238   m_FieldName = swFieldNameTemp;
    239   m_nFormControlIndex = -1;
    240 
    241   return true;
    242 }
    243 
    244 std::vector<CPDF_FormField*> Field::GetFormFields(
    245     CPDFSDK_FormFillEnvironment* pFormFillEnv,
    246     const CFX_WideString& csFieldName) {
    247   std::vector<CPDF_FormField*> fields;
    248   CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
    249   CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
    250   for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
    251     if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
    252       fields.push_back(pFormField);
    253   }
    254   return fields;
    255 }
    256 
    257 std::vector<CPDF_FormField*> Field::GetFormFields(
    258     const CFX_WideString& csFieldName) const {
    259   return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName);
    260 }
    261 
    262 void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    263                             CPDF_FormField* pFormField,
    264                             bool bChangeMark,
    265                             bool bResetAP,
    266                             bool bRefresh) {
    267   CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
    268 
    269   if (bResetAP) {
    270     std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
    271     pInterForm->GetWidgets(pFormField, &widgets);
    272 
    273     int nFieldType = pFormField->GetFieldType();
    274     if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
    275       for (auto& pObserved : widgets) {
    276         if (pObserved) {
    277           bool bFormatted = false;
    278           CFX_WideString sValue = static_cast<CPDFSDK_Widget*>(pObserved.Get())
    279                                       ->OnFormat(bFormatted);
    280           if (pObserved) {  // Not redundant, may be clobbered by OnFormat.
    281             static_cast<CPDFSDK_Widget*>(pObserved.Get())
    282                 ->ResetAppearance(bFormatted ? &sValue : nullptr, false);
    283           }
    284         }
    285       }
    286     } else {
    287       for (auto& pObserved : widgets) {
    288         if (pObserved) {
    289           static_cast<CPDFSDK_Widget*>(pObserved.Get())
    290               ->ResetAppearance(nullptr, false);
    291         }
    292       }
    293     }
    294   }
    295 
    296   if (bRefresh) {
    297     // Refresh the widget list. The calls in |bResetAP| may have caused widgets
    298     // to be removed from the list. We need to call |GetWidgets| again to be
    299     // sure none of the widgets have been deleted.
    300     std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
    301     pInterForm->GetWidgets(pFormField, &widgets);
    302 
    303     // TODO(dsinclair): Determine if all widgets share the same
    304     // CPDFSDK_InterForm. If that's the case, we can move the code to
    305     // |GetFormFillEnv| out of the loop.
    306     for (auto& pObserved : widgets) {
    307       if (pObserved) {
    308         CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
    309         pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
    310                                                                   pWidget);
    311       }
    312     }
    313   }
    314 
    315   if (bChangeMark)
    316     pFormFillEnv->SetChangeMark();
    317 }
    318 
    319 void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    320                               CPDF_FormControl* pFormControl,
    321                               bool bChangeMark,
    322                               bool bResetAP,
    323                               bool bRefresh) {
    324   ASSERT(pFormControl);
    325 
    326   CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
    327   CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
    328 
    329   if (pWidget) {
    330     if (bResetAP) {
    331       int nFieldType = pWidget->GetFieldType();
    332       if (nFieldType == FIELDTYPE_COMBOBOX ||
    333           nFieldType == FIELDTYPE_TEXTFIELD) {
    334         bool bFormatted = false;
    335         CFX_WideString sValue = pWidget->OnFormat(bFormatted);
    336         pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, false);
    337       } else {
    338         pWidget->ResetAppearance(nullptr, false);
    339       }
    340     }
    341 
    342     if (bRefresh) {
    343       CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
    344       pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
    345     }
    346   }
    347 
    348   if (bChangeMark)
    349     pFormFillEnv->SetChangeMark();
    350 }
    351 
    352 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    353                                  CPDF_FormControl* pFormControl) {
    354   CPDFSDK_InterForm* pInterForm =
    355       static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
    356   return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
    357 }
    358 
    359 bool Field::ValueIsOccur(CPDF_FormField* pFormField,
    360                          CFX_WideString csOptLabel) {
    361   for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
    362     if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
    363       return true;
    364   }
    365 
    366   return false;
    367 }
    368 
    369 CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
    370   if (!pFormField->CountControls() ||
    371       m_nFormControlIndex >= pFormField->CountControls())
    372     return nullptr;
    373 
    374   if (m_nFormControlIndex < 0)
    375     return pFormField->GetControl(0);
    376 
    377   return pFormField->GetControl(m_nFormControlIndex);
    378 }
    379 
    380 bool Field::alignment(CJS_Runtime* pRuntime,
    381                       CJS_PropValue& vp,
    382                       CFX_WideString& sError) {
    383   ASSERT(m_pFormFillEnv);
    384 
    385   if (vp.IsSetting()) {
    386     if (!m_bCanSet)
    387       return false;
    388 
    389     CFX_ByteString alignStr;
    390     vp >> alignStr;
    391 
    392     if (m_bDelay) {
    393       AddDelay_String(FP_ALIGNMENT, alignStr);
    394     } else {
    395       Field::SetAlignment(m_pFormFillEnv.Get(), m_FieldName,
    396                           m_nFormControlIndex, alignStr);
    397     }
    398   } else {
    399     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    400     if (FieldArray.empty())
    401       return false;
    402 
    403     CPDF_FormField* pFormField = FieldArray[0];
    404     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
    405       return false;
    406 
    407     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
    408     if (!pFormControl)
    409       return false;
    410 
    411     switch (pFormControl->GetControlAlignment()) {
    412       case 1:
    413         vp << L"center";
    414         break;
    415       case 0:
    416         vp << L"left";
    417         break;
    418       case 2:
    419         vp << L"right";
    420         break;
    421       default:
    422         vp << L"";
    423     }
    424   }
    425 
    426   return true;
    427 }
    428 
    429 void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    430                          const CFX_WideString& swFieldName,
    431                          int nControlIndex,
    432                          const CFX_ByteString& string) {
    433   // Not supported.
    434 }
    435 
    436 bool Field::borderStyle(CJS_Runtime* pRuntime,
    437                         CJS_PropValue& vp,
    438                         CFX_WideString& sError) {
    439   ASSERT(m_pFormFillEnv);
    440 
    441   if (vp.IsSetting()) {
    442     if (!m_bCanSet)
    443       return false;
    444 
    445     CFX_ByteString strType = "";
    446     vp >> strType;
    447 
    448     if (m_bDelay) {
    449       AddDelay_String(FP_BORDERSTYLE, strType);
    450     } else {
    451       Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
    452                             m_nFormControlIndex, strType);
    453     }
    454   } else {
    455     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    456     if (FieldArray.empty())
    457       return false;
    458 
    459     CPDF_FormField* pFormField = FieldArray[0];
    460     if (!pFormField)
    461       return false;
    462 
    463     CPDFSDK_Widget* pWidget =
    464         GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
    465     if (!pWidget)
    466       return false;
    467 
    468     switch (pWidget->GetBorderStyle()) {
    469       case BorderStyle::SOLID:
    470         vp << L"solid";
    471         break;
    472       case BorderStyle::DASH:
    473         vp << L"dashed";
    474         break;
    475       case BorderStyle::BEVELED:
    476         vp << L"beveled";
    477         break;
    478       case BorderStyle::INSET:
    479         vp << L"inset";
    480         break;
    481       case BorderStyle::UNDERLINE:
    482         vp << L"underline";
    483         break;
    484       default:
    485         vp << L"";
    486         break;
    487     }
    488   }
    489 
    490   return true;
    491 }
    492 
    493 void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    494                            const CFX_WideString& swFieldName,
    495                            int nControlIndex,
    496                            const CFX_ByteString& string) {
    497   ASSERT(pFormFillEnv);
    498 
    499   BorderStyle nBorderStyle = BorderStyle::SOLID;
    500   if (string == "solid")
    501     nBorderStyle = BorderStyle::SOLID;
    502   else if (string == "beveled")
    503     nBorderStyle = BorderStyle::BEVELED;
    504   else if (string == "dashed")
    505     nBorderStyle = BorderStyle::DASH;
    506   else if (string == "inset")
    507     nBorderStyle = BorderStyle::INSET;
    508   else if (string == "underline")
    509     nBorderStyle = BorderStyle::UNDERLINE;
    510   else
    511     return;
    512 
    513   std::vector<CPDF_FormField*> FieldArray =
    514       GetFormFields(pFormFillEnv, swFieldName);
    515   for (CPDF_FormField* pFormField : FieldArray) {
    516     if (nControlIndex < 0) {
    517       bool bSet = false;
    518       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
    519         if (CPDFSDK_Widget* pWidget =
    520                 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
    521           if (pWidget->GetBorderStyle() != nBorderStyle) {
    522             pWidget->SetBorderStyle(nBorderStyle);
    523             bSet = true;
    524           }
    525         }
    526       }
    527       if (bSet)
    528         UpdateFormField(pFormFillEnv, pFormField, true, true, true);
    529     } else {
    530       if (nControlIndex >= pFormField->CountControls())
    531         return;
    532       if (CPDF_FormControl* pFormControl =
    533               pFormField->GetControl(nControlIndex)) {
    534         if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
    535           if (pWidget->GetBorderStyle() != nBorderStyle) {
    536             pWidget->SetBorderStyle(nBorderStyle);
    537             UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
    538           }
    539         }
    540       }
    541     }
    542   }
    543 }
    544 
    545 bool Field::buttonAlignX(CJS_Runtime* pRuntime,
    546                          CJS_PropValue& vp,
    547                          CFX_WideString& sError) {
    548   ASSERT(m_pFormFillEnv);
    549 
    550   if (vp.IsSetting()) {
    551     if (!m_bCanSet)
    552       return false;
    553 
    554     int nVP;
    555     vp >> nVP;
    556 
    557     if (m_bDelay) {
    558       AddDelay_Int(FP_BUTTONALIGNX, nVP);
    559     } else {
    560       Field::SetButtonAlignX(m_pFormFillEnv.Get(), m_FieldName,
    561                              m_nFormControlIndex, nVP);
    562     }
    563   } else {
    564     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    565     if (FieldArray.empty())
    566       return false;
    567 
    568     CPDF_FormField* pFormField = FieldArray[0];
    569     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
    570       return false;
    571 
    572     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
    573     if (!pFormControl)
    574       return false;
    575 
    576     CPDF_IconFit IconFit = pFormControl->GetIconFit();
    577 
    578     FX_FLOAT fLeft, fBottom;
    579     IconFit.GetIconPosition(fLeft, fBottom);
    580 
    581     vp << (int32_t)fLeft;
    582   }
    583 
    584   return true;
    585 }
    586 
    587 void Field::SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    588                             const CFX_WideString& swFieldName,
    589                             int nControlIndex,
    590                             int number) {
    591   // Not supported.
    592 }
    593 
    594 bool Field::buttonAlignY(CJS_Runtime* pRuntime,
    595                          CJS_PropValue& vp,
    596                          CFX_WideString& sError) {
    597   ASSERT(m_pFormFillEnv);
    598 
    599   if (vp.IsSetting()) {
    600     if (!m_bCanSet)
    601       return false;
    602 
    603     int nVP;
    604     vp >> nVP;
    605 
    606     if (m_bDelay) {
    607       AddDelay_Int(FP_BUTTONALIGNY, nVP);
    608     } else {
    609       Field::SetButtonAlignY(m_pFormFillEnv.Get(), m_FieldName,
    610                              m_nFormControlIndex, nVP);
    611     }
    612   } else {
    613     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    614     if (FieldArray.empty())
    615       return false;
    616 
    617     CPDF_FormField* pFormField = FieldArray[0];
    618     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
    619       return false;
    620 
    621     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
    622     if (!pFormControl)
    623       return false;
    624 
    625     CPDF_IconFit IconFit = pFormControl->GetIconFit();
    626 
    627     FX_FLOAT fLeft, fBottom;
    628     IconFit.GetIconPosition(fLeft, fBottom);
    629 
    630     vp << (int32_t)fBottom;
    631   }
    632 
    633   return true;
    634 }
    635 
    636 void Field::SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    637                             const CFX_WideString& swFieldName,
    638                             int nControlIndex,
    639                             int number) {
    640   // Not supported.
    641 }
    642 
    643 bool Field::buttonFitBounds(CJS_Runtime* pRuntime,
    644                             CJS_PropValue& vp,
    645                             CFX_WideString& sError) {
    646   ASSERT(m_pFormFillEnv);
    647 
    648   if (vp.IsSetting()) {
    649     if (!m_bCanSet)
    650       return false;
    651 
    652     bool bVP;
    653     vp >> bVP;
    654 
    655     if (m_bDelay) {
    656       AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
    657     } else {
    658       Field::SetButtonFitBounds(m_pFormFillEnv.Get(), m_FieldName,
    659                                 m_nFormControlIndex, bVP);
    660     }
    661   } else {
    662     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    663     if (FieldArray.empty())
    664       return false;
    665 
    666     CPDF_FormField* pFormField = FieldArray[0];
    667     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
    668       return false;
    669 
    670     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
    671     if (!pFormControl)
    672       return false;
    673 
    674     vp << pFormControl->GetIconFit().GetFittingBounds();
    675   }
    676 
    677   return true;
    678 }
    679 
    680 void Field::SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    681                                const CFX_WideString& swFieldName,
    682                                int nControlIndex,
    683                                bool b) {
    684   // Not supported.
    685 }
    686 
    687 bool Field::buttonPosition(CJS_Runtime* pRuntime,
    688                            CJS_PropValue& vp,
    689                            CFX_WideString& sError) {
    690   ASSERT(m_pFormFillEnv);
    691 
    692   if (vp.IsSetting()) {
    693     if (!m_bCanSet)
    694       return false;
    695 
    696     int nVP;
    697     vp >> nVP;
    698 
    699     if (m_bDelay) {
    700       AddDelay_Int(FP_BUTTONPOSITION, nVP);
    701     } else {
    702       Field::SetButtonPosition(m_pFormFillEnv.Get(), m_FieldName,
    703                                m_nFormControlIndex, nVP);
    704     }
    705   } else {
    706     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    707     if (FieldArray.empty())
    708       return false;
    709 
    710     CPDF_FormField* pFormField = FieldArray[0];
    711     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
    712       return false;
    713 
    714     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
    715     if (!pFormControl)
    716       return false;
    717 
    718     vp << pFormControl->GetTextPosition();
    719   }
    720   return true;
    721 }
    722 
    723 void Field::SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    724                               const CFX_WideString& swFieldName,
    725                               int nControlIndex,
    726                               int number) {
    727   // Not supported.
    728 }
    729 
    730 bool Field::buttonScaleHow(CJS_Runtime* pRuntime,
    731                            CJS_PropValue& vp,
    732                            CFX_WideString& sError) {
    733   ASSERT(m_pFormFillEnv);
    734 
    735   if (vp.IsSetting()) {
    736     if (!m_bCanSet)
    737       return false;
    738 
    739     int nVP;
    740     vp >> nVP;
    741 
    742     if (m_bDelay) {
    743       AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
    744     } else {
    745       Field::SetButtonScaleHow(m_pFormFillEnv.Get(), m_FieldName,
    746                                m_nFormControlIndex, nVP);
    747     }
    748   } else {
    749     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    750     if (FieldArray.empty())
    751       return false;
    752 
    753     CPDF_FormField* pFormField = FieldArray[0];
    754     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
    755       return false;
    756 
    757     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
    758     if (!pFormControl)
    759       return false;
    760 
    761     CPDF_IconFit IconFit = pFormControl->GetIconFit();
    762     if (IconFit.IsProportionalScale())
    763       vp << (int32_t)0;
    764     else
    765       vp << (int32_t)1;
    766   }
    767 
    768   return true;
    769 }
    770 
    771 void Field::SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    772                               const CFX_WideString& swFieldName,
    773                               int nControlIndex,
    774                               int number) {
    775   // Not supported.
    776 }
    777 
    778 bool Field::buttonScaleWhen(CJS_Runtime* pRuntime,
    779                             CJS_PropValue& vp,
    780                             CFX_WideString& sError) {
    781   ASSERT(m_pFormFillEnv);
    782 
    783   if (vp.IsSetting()) {
    784     if (!m_bCanSet)
    785       return false;
    786 
    787     int nVP;
    788     vp >> nVP;
    789 
    790     if (m_bDelay) {
    791       AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
    792     } else {
    793       Field::SetButtonScaleWhen(m_pFormFillEnv.Get(), m_FieldName,
    794                                 m_nFormControlIndex, nVP);
    795     }
    796   } else {
    797     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    798     if (FieldArray.empty())
    799       return false;
    800 
    801     CPDF_FormField* pFormField = FieldArray[0];
    802     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
    803       return false;
    804 
    805     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
    806     if (!pFormControl)
    807       return false;
    808 
    809     CPDF_IconFit IconFit = pFormControl->GetIconFit();
    810     int ScaleM = IconFit.GetScaleMethod();
    811     switch (ScaleM) {
    812       case CPDF_IconFit::Always:
    813         vp << (int32_t)CPDF_IconFit::Always;
    814         break;
    815       case CPDF_IconFit::Bigger:
    816         vp << (int32_t)CPDF_IconFit::Bigger;
    817         break;
    818       case CPDF_IconFit::Never:
    819         vp << (int32_t)CPDF_IconFit::Never;
    820         break;
    821       case CPDF_IconFit::Smaller:
    822         vp << (int32_t)CPDF_IconFit::Smaller;
    823         break;
    824     }
    825   }
    826 
    827   return true;
    828 }
    829 
    830 void Field::SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    831                                const CFX_WideString& swFieldName,
    832                                int nControlIndex,
    833                                int number) {
    834   // Not supported.
    835 }
    836 
    837 bool Field::calcOrderIndex(CJS_Runtime* pRuntime,
    838                            CJS_PropValue& vp,
    839                            CFX_WideString& sError) {
    840   ASSERT(m_pFormFillEnv);
    841 
    842   if (vp.IsSetting()) {
    843     if (!m_bCanSet)
    844       return false;
    845 
    846     int nVP;
    847     vp >> nVP;
    848 
    849     if (m_bDelay) {
    850       AddDelay_Int(FP_CALCORDERINDEX, nVP);
    851     } else {
    852       Field::SetCalcOrderIndex(m_pFormFillEnv.Get(), m_FieldName,
    853                                m_nFormControlIndex, nVP);
    854     }
    855   } else {
    856     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    857     if (FieldArray.empty())
    858       return false;
    859 
    860     CPDF_FormField* pFormField = FieldArray[0];
    861     if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
    862         pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
    863       return false;
    864     }
    865 
    866     CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
    867     CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
    868     vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
    869   }
    870 
    871   return true;
    872 }
    873 
    874 void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    875                               const CFX_WideString& swFieldName,
    876                               int nControlIndex,
    877                               int number) {
    878   // Not supported.
    879 }
    880 
    881 bool Field::charLimit(CJS_Runtime* pRuntime,
    882                       CJS_PropValue& vp,
    883                       CFX_WideString& sError) {
    884   ASSERT(m_pFormFillEnv);
    885 
    886   if (vp.IsSetting()) {
    887     if (!m_bCanSet)
    888       return false;
    889 
    890     int nVP;
    891     vp >> nVP;
    892 
    893     if (m_bDelay) {
    894       AddDelay_Int(FP_CHARLIMIT, nVP);
    895     } else {
    896       Field::SetCharLimit(m_pFormFillEnv.Get(), m_FieldName,
    897                           m_nFormControlIndex, nVP);
    898     }
    899   } else {
    900     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    901     if (FieldArray.empty())
    902       return false;
    903 
    904     CPDF_FormField* pFormField = FieldArray[0];
    905     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
    906       return false;
    907 
    908     vp << (int32_t)pFormField->GetMaxLen();
    909   }
    910   return true;
    911 }
    912 
    913 void Field::SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    914                          const CFX_WideString& swFieldName,
    915                          int nControlIndex,
    916                          int number) {
    917   // Not supported.
    918 }
    919 
    920 bool Field::comb(CJS_Runtime* pRuntime,
    921                  CJS_PropValue& vp,
    922                  CFX_WideString& sError) {
    923   ASSERT(m_pFormFillEnv);
    924 
    925   if (vp.IsSetting()) {
    926     if (!m_bCanSet)
    927       return false;
    928 
    929     bool bVP;
    930     vp >> bVP;
    931 
    932     if (m_bDelay) {
    933       AddDelay_Bool(FP_COMB, bVP);
    934     } else {
    935       Field::SetComb(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
    936                      bVP);
    937     }
    938   } else {
    939     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    940     if (FieldArray.empty())
    941       return false;
    942 
    943     CPDF_FormField* pFormField = FieldArray[0];
    944     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
    945       return false;
    946 
    947     if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
    948       vp << true;
    949     else
    950       vp << false;
    951   }
    952 
    953   return true;
    954 }
    955 
    956 void Field::SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv,
    957                     const CFX_WideString& swFieldName,
    958                     int nControlIndex,
    959                     bool b) {
    960   // Not supported.
    961 }
    962 
    963 bool Field::commitOnSelChange(CJS_Runtime* pRuntime,
    964                               CJS_PropValue& vp,
    965                               CFX_WideString& sError) {
    966   ASSERT(m_pFormFillEnv);
    967 
    968   if (vp.IsSetting()) {
    969     if (!m_bCanSet)
    970       return false;
    971 
    972     bool bVP;
    973     vp >> bVP;
    974 
    975     if (m_bDelay) {
    976       AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
    977     } else {
    978       Field::SetCommitOnSelChange(m_pFormFillEnv.Get(), m_FieldName,
    979                                   m_nFormControlIndex, bVP);
    980     }
    981   } else {
    982     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
    983     if (FieldArray.empty())
    984       return false;
    985 
    986     CPDF_FormField* pFormField = FieldArray[0];
    987     if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
    988         pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
    989       return false;
    990     }
    991 
    992     if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
    993       vp << true;
    994     else
    995       vp << false;
    996   }
    997 
    998   return true;
    999 }
   1000 
   1001 void Field::SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1002                                  const CFX_WideString& swFieldName,
   1003                                  int nControlIndex,
   1004                                  bool b) {
   1005   // Not supported.
   1006 }
   1007 
   1008 bool Field::currentValueIndices(CJS_Runtime* pRuntime,
   1009                                 CJS_PropValue& vp,
   1010                                 CFX_WideString& sError) {
   1011   if (vp.IsSetting()) {
   1012     if (!m_bCanSet)
   1013       return false;
   1014 
   1015     std::vector<uint32_t> array;
   1016     if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
   1017       int iSelecting = 0;
   1018       vp >> iSelecting;
   1019       array.push_back(iSelecting);
   1020     } else if (vp.GetJSValue()->IsArrayObject()) {
   1021       CJS_Array SelArray;
   1022       CJS_Value SelValue(pRuntime);
   1023       int iSelecting;
   1024       vp >> SelArray;
   1025       for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
   1026         SelArray.GetElement(pRuntime, i, SelValue);
   1027         iSelecting = SelValue.ToInt(pRuntime);
   1028         array.push_back(iSelecting);
   1029       }
   1030     }
   1031 
   1032     if (m_bDelay) {
   1033       AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
   1034     } else {
   1035       Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
   1036                                     m_nFormControlIndex, array);
   1037     }
   1038   } else {
   1039     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1040     if (FieldArray.empty())
   1041       return false;
   1042 
   1043     CPDF_FormField* pFormField = FieldArray[0];
   1044     if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
   1045         pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
   1046       return false;
   1047     }
   1048 
   1049     if (pFormField->CountSelectedItems() == 1) {
   1050       vp << pFormField->GetSelectedIndex(0);
   1051     } else if (pFormField->CountSelectedItems() > 1) {
   1052       CJS_Array SelArray;
   1053       for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
   1054         SelArray.SetElement(
   1055             pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
   1056       }
   1057       vp << SelArray;
   1058     } else {
   1059       vp << -1;
   1060     }
   1061   }
   1062 
   1063   return true;
   1064 }
   1065 
   1066 void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1067                                    const CFX_WideString& swFieldName,
   1068                                    int nControlIndex,
   1069                                    const std::vector<uint32_t>& array) {
   1070   ASSERT(pFormFillEnv);
   1071   std::vector<CPDF_FormField*> FieldArray =
   1072       GetFormFields(pFormFillEnv, swFieldName);
   1073 
   1074   for (CPDF_FormField* pFormField : FieldArray) {
   1075     int nFieldType = pFormField->GetFieldType();
   1076     if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
   1077       uint32_t dwFieldFlags = pFormField->GetFieldFlags();
   1078       pFormField->ClearSelection(true);
   1079       for (size_t i = 0; i < array.size(); ++i) {
   1080         if (i != 0 && !(dwFieldFlags & (1 << 21)))
   1081           break;
   1082         if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
   1083             !pFormField->IsItemSelected(array[i])) {
   1084           pFormField->SetItemSelection(array[i], true);
   1085         }
   1086       }
   1087       UpdateFormField(pFormFillEnv, pFormField, true, true, true);
   1088     }
   1089   }
   1090 }
   1091 
   1092 bool Field::defaultStyle(CJS_Runtime* pRuntime,
   1093                          CJS_PropValue& vp,
   1094                          CFX_WideString& sError) {
   1095   return false;
   1096 }
   1097 
   1098 void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1099                             const CFX_WideString& swFieldName,
   1100                             int nControlIndex) {
   1101   // Not supported.
   1102 }
   1103 
   1104 bool Field::defaultValue(CJS_Runtime* pRuntime,
   1105                          CJS_PropValue& vp,
   1106                          CFX_WideString& sError) {
   1107   ASSERT(m_pFormFillEnv);
   1108 
   1109   if (vp.IsSetting()) {
   1110     if (!m_bCanSet)
   1111       return false;
   1112 
   1113     CFX_WideString WideStr;
   1114     vp >> WideStr;
   1115 
   1116     if (m_bDelay) {
   1117       AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
   1118     } else {
   1119       Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName,
   1120                              m_nFormControlIndex, WideStr);
   1121     }
   1122   } else {
   1123     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1124     if (FieldArray.empty())
   1125       return false;
   1126 
   1127     CPDF_FormField* pFormField = FieldArray[0];
   1128     if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
   1129         pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
   1130       return false;
   1131     }
   1132 
   1133     vp << pFormField->GetDefaultValue();
   1134   }
   1135   return true;
   1136 }
   1137 
   1138 void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1139                             const CFX_WideString& swFieldName,
   1140                             int nControlIndex,
   1141                             const CFX_WideString& string) {
   1142   // Not supported.
   1143 }
   1144 
   1145 bool Field::doNotScroll(CJS_Runtime* pRuntime,
   1146                         CJS_PropValue& vp,
   1147                         CFX_WideString& sError) {
   1148   ASSERT(m_pFormFillEnv);
   1149 
   1150   if (vp.IsSetting()) {
   1151     if (!m_bCanSet)
   1152       return false;
   1153 
   1154     bool bVP;
   1155     vp >> bVP;
   1156 
   1157     if (m_bDelay) {
   1158       AddDelay_Bool(FP_DONOTSCROLL, bVP);
   1159     } else {
   1160       Field::SetDoNotScroll(m_pFormFillEnv.Get(), m_FieldName,
   1161                             m_nFormControlIndex, bVP);
   1162     }
   1163   } else {
   1164     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1165     if (FieldArray.empty())
   1166       return false;
   1167 
   1168     CPDF_FormField* pFormField = FieldArray[0];
   1169     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
   1170       return false;
   1171 
   1172     if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
   1173       vp << true;
   1174     else
   1175       vp << false;
   1176   }
   1177 
   1178   return true;
   1179 }
   1180 
   1181 void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1182                            const CFX_WideString& swFieldName,
   1183                            int nControlIndex,
   1184                            bool b) {
   1185   // Not supported.
   1186 }
   1187 
   1188 bool Field::doNotSpellCheck(CJS_Runtime* pRuntime,
   1189                             CJS_PropValue& vp,
   1190                             CFX_WideString& sError) {
   1191   ASSERT(m_pFormFillEnv);
   1192 
   1193   if (vp.IsSetting()) {
   1194     if (!m_bCanSet)
   1195       return false;
   1196 
   1197     bool bVP;
   1198     vp >> bVP;
   1199   } else {
   1200     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1201     if (FieldArray.empty())
   1202       return false;
   1203 
   1204     CPDF_FormField* pFormField = FieldArray[0];
   1205     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
   1206         pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
   1207       return false;
   1208     }
   1209 
   1210     if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
   1211       vp << true;
   1212     else
   1213       vp << false;
   1214   }
   1215 
   1216   return true;
   1217 }
   1218 
   1219 void Field::SetDelay(bool bDelay) {
   1220   m_bDelay = bDelay;
   1221 
   1222   if (!m_bDelay) {
   1223     if (m_pJSDoc)
   1224       m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
   1225   }
   1226 }
   1227 
   1228 bool Field::delay(CJS_Runtime* pRuntime,
   1229                   CJS_PropValue& vp,
   1230                   CFX_WideString& sError) {
   1231   if (!vp.IsSetting()) {
   1232     vp << m_bDelay;
   1233     return true;
   1234   }
   1235   if (!m_bCanSet)
   1236     return false;
   1237 
   1238   bool bVP;
   1239   vp >> bVP;
   1240   SetDelay(bVP);
   1241   return true;
   1242 }
   1243 
   1244 bool Field::display(CJS_Runtime* pRuntime,
   1245                     CJS_PropValue& vp,
   1246                     CFX_WideString& sError) {
   1247   if (vp.IsSetting()) {
   1248     if (!m_bCanSet)
   1249       return false;
   1250 
   1251     int nVP;
   1252     vp >> nVP;
   1253     if (m_bDelay) {
   1254       AddDelay_Int(FP_DISPLAY, nVP);
   1255     } else {
   1256       Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   1257                         nVP);
   1258     }
   1259     return true;
   1260   }
   1261   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1262   if (FieldArray.empty())
   1263     return false;
   1264 
   1265   CPDF_FormField* pFormField = FieldArray[0];
   1266   ASSERT(pFormField);
   1267   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   1268   CPDFSDK_Widget* pWidget =
   1269       pInterForm->GetWidget(GetSmartFieldControl(pFormField));
   1270   if (!pWidget)
   1271     return false;
   1272 
   1273   uint32_t dwFlag = pWidget->GetFlags();
   1274   if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
   1275     vp << (int32_t)1;
   1276   } else {
   1277     if (ANNOTFLAG_PRINT & dwFlag) {
   1278       if (ANNOTFLAG_NOVIEW & dwFlag) {
   1279         vp << (int32_t)3;
   1280       } else {
   1281         vp << (int32_t)0;
   1282       }
   1283     } else {
   1284       vp << (int32_t)2;
   1285     }
   1286   }
   1287   return true;
   1288 }
   1289 
   1290 void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1291                        const CFX_WideString& swFieldName,
   1292                        int nControlIndex,
   1293                        int number) {
   1294   CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
   1295   std::vector<CPDF_FormField*> FieldArray =
   1296       GetFormFields(pFormFillEnv, swFieldName);
   1297   for (CPDF_FormField* pFormField : FieldArray) {
   1298     if (nControlIndex < 0) {
   1299       bool bAnySet = false;
   1300       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
   1301         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
   1302         ASSERT(pFormControl);
   1303 
   1304         CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
   1305         if (SetWidgetDisplayStatus(pWidget, number))
   1306           bAnySet = true;
   1307       }
   1308 
   1309       if (bAnySet)
   1310         UpdateFormField(pFormFillEnv, pFormField, true, false, true);
   1311     } else {
   1312       if (nControlIndex >= pFormField->CountControls())
   1313         return;
   1314 
   1315       CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
   1316       if (!pFormControl)
   1317         return;
   1318 
   1319       CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
   1320       if (SetWidgetDisplayStatus(pWidget, number))
   1321         UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
   1322     }
   1323   }
   1324 }
   1325 
   1326 bool Field::doc(CJS_Runtime* pRuntime,
   1327                 CJS_PropValue& vp,
   1328                 CFX_WideString& sError) {
   1329   if (!vp.IsGetting())
   1330     return false;
   1331 
   1332   vp << m_pJSDoc->GetCJSDoc();
   1333   return true;
   1334 }
   1335 
   1336 bool Field::editable(CJS_Runtime* pRuntime,
   1337                      CJS_PropValue& vp,
   1338                      CFX_WideString& sError) {
   1339   if (vp.IsSetting()) {
   1340     if (!m_bCanSet)
   1341       return false;
   1342 
   1343     bool bVP;
   1344     vp >> bVP;
   1345     return true;
   1346   }
   1347   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1348   if (FieldArray.empty())
   1349     return false;
   1350 
   1351   CPDF_FormField* pFormField = FieldArray[0];
   1352   if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
   1353     return false;
   1354 
   1355   vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT);
   1356   return true;
   1357 }
   1358 
   1359 bool Field::exportValues(CJS_Runtime* pRuntime,
   1360                          CJS_PropValue& vp,
   1361                          CFX_WideString& sError) {
   1362   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1363   if (FieldArray.empty())
   1364     return false;
   1365 
   1366   CPDF_FormField* pFormField = FieldArray[0];
   1367   if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
   1368       pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
   1369     return false;
   1370   }
   1371   if (vp.IsSetting())
   1372     return m_bCanSet && vp.GetJSValue()->IsArrayObject();
   1373 
   1374   CJS_Array ExportValusArray;
   1375   if (m_nFormControlIndex < 0) {
   1376     for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
   1377       CPDF_FormControl* pFormControl = pFormField->GetControl(i);
   1378       ExportValusArray.SetElement(
   1379           pRuntime, i,
   1380           CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
   1381     }
   1382   } else {
   1383     if (m_nFormControlIndex >= pFormField->CountControls())
   1384       return false;
   1385 
   1386     CPDF_FormControl* pFormControl =
   1387         pFormField->GetControl(m_nFormControlIndex);
   1388     if (!pFormControl)
   1389       return false;
   1390 
   1391     ExportValusArray.SetElement(
   1392         pRuntime, 0,
   1393         CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
   1394   }
   1395   vp << ExportValusArray;
   1396   return true;
   1397 }
   1398 
   1399 bool Field::fileSelect(CJS_Runtime* pRuntime,
   1400                        CJS_PropValue& vp,
   1401                        CFX_WideString& sError) {
   1402   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1403   if (FieldArray.empty())
   1404     return false;
   1405 
   1406   CPDF_FormField* pFormField = FieldArray[0];
   1407   if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
   1408     return false;
   1409 
   1410   if (vp.IsSetting()) {
   1411     if (!m_bCanSet)
   1412       return false;
   1413 
   1414     bool bVP;
   1415     vp >> bVP;
   1416     return true;
   1417   }
   1418   vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT);
   1419   return true;
   1420 }
   1421 
   1422 bool Field::fillColor(CJS_Runtime* pRuntime,
   1423                       CJS_PropValue& vp,
   1424                       CFX_WideString& sError) {
   1425   CJS_Array crArray;
   1426   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1427   if (FieldArray.empty())
   1428     return false;
   1429 
   1430   if (vp.IsSetting()) {
   1431     if (!m_bCanSet)
   1432       return false;
   1433 
   1434     if (!vp.GetJSValue()->IsArrayObject())
   1435       return false;
   1436 
   1437     vp >> crArray;
   1438 
   1439     CPWL_Color color;
   1440     color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
   1441     if (m_bDelay) {
   1442       AddDelay_Color(FP_FILLCOLOR, color);
   1443     } else {
   1444       Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName,
   1445                           m_nFormControlIndex, color);
   1446     }
   1447     return true;
   1448   }
   1449   CPDF_FormField* pFormField = FieldArray[0];
   1450   ASSERT(pFormField);
   1451   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   1452   if (!pFormControl)
   1453     return false;
   1454 
   1455   int iColorType;
   1456   pFormControl->GetBackgroundColor(iColorType);
   1457 
   1458   CPWL_Color color;
   1459   if (iColorType == COLORTYPE_TRANSPARENT) {
   1460     color = CPWL_Color(COLORTYPE_TRANSPARENT);
   1461   } else if (iColorType == COLORTYPE_GRAY) {
   1462     color =
   1463         CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
   1464   } else if (iColorType == COLORTYPE_RGB) {
   1465     color =
   1466         CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
   1467                    pFormControl->GetOriginalBackgroundColor(1),
   1468                    pFormControl->GetOriginalBackgroundColor(2));
   1469   } else if (iColorType == COLORTYPE_CMYK) {
   1470     color =
   1471         CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
   1472                    pFormControl->GetOriginalBackgroundColor(1),
   1473                    pFormControl->GetOriginalBackgroundColor(2),
   1474                    pFormControl->GetOriginalBackgroundColor(3));
   1475   } else {
   1476     return false;
   1477   }
   1478   color::ConvertPWLColorToArray(pRuntime, color, &crArray);
   1479   vp << crArray;
   1480   return true;
   1481 }
   1482 
   1483 void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1484                          const CFX_WideString& swFieldName,
   1485                          int nControlIndex,
   1486                          const CPWL_Color& color) {
   1487   // Not supported.
   1488 }
   1489 
   1490 bool Field::hidden(CJS_Runtime* pRuntime,
   1491                    CJS_PropValue& vp,
   1492                    CFX_WideString& sError) {
   1493   if (vp.IsSetting()) {
   1494     if (!m_bCanSet)
   1495       return false;
   1496 
   1497     bool bVP;
   1498     vp >> bVP;
   1499     if (m_bDelay) {
   1500       AddDelay_Bool(FP_HIDDEN, bVP);
   1501     } else {
   1502       Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   1503                        bVP);
   1504     }
   1505     return true;
   1506   }
   1507   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1508   if (FieldArray.empty())
   1509     return false;
   1510 
   1511   CPDF_FormField* pFormField = FieldArray[0];
   1512   ASSERT(pFormField);
   1513   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   1514   CPDFSDK_Widget* pWidget =
   1515       pInterForm->GetWidget(GetSmartFieldControl(pFormField));
   1516   if (!pWidget)
   1517     return false;
   1518 
   1519   uint32_t dwFlags = pWidget->GetFlags();
   1520   if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
   1521     vp << true;
   1522   else
   1523     vp << false;
   1524 
   1525   return true;
   1526 }
   1527 
   1528 void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1529                       const CFX_WideString& swFieldName,
   1530                       int nControlIndex,
   1531                       bool b) {
   1532   int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
   1533   SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
   1534 }
   1535 
   1536 bool Field::highlight(CJS_Runtime* pRuntime,
   1537                       CJS_PropValue& vp,
   1538                       CFX_WideString& sError) {
   1539   ASSERT(m_pFormFillEnv);
   1540   if (vp.IsSetting()) {
   1541     if (!m_bCanSet)
   1542       return false;
   1543 
   1544     CFX_ByteString strMode;
   1545     vp >> strMode;
   1546 
   1547     if (m_bDelay) {
   1548       AddDelay_String(FP_HIGHLIGHT, strMode);
   1549     } else {
   1550       Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName,
   1551                           m_nFormControlIndex, strMode);
   1552     }
   1553     return true;
   1554   }
   1555   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1556   if (FieldArray.empty())
   1557     return false;
   1558 
   1559   CPDF_FormField* pFormField = FieldArray[0];
   1560   if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
   1561     return false;
   1562 
   1563   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   1564   if (!pFormControl)
   1565     return false;
   1566 
   1567   int eHM = pFormControl->GetHighlightingMode();
   1568   switch (eHM) {
   1569     case CPDF_FormControl::None:
   1570       vp << L"none";
   1571       break;
   1572     case CPDF_FormControl::Push:
   1573       vp << L"push";
   1574       break;
   1575     case CPDF_FormControl::Invert:
   1576       vp << L"invert";
   1577       break;
   1578     case CPDF_FormControl::Outline:
   1579       vp << L"outline";
   1580       break;
   1581     case CPDF_FormControl::Toggle:
   1582       vp << L"toggle";
   1583       break;
   1584   }
   1585   return true;
   1586 }
   1587 
   1588 void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1589                          const CFX_WideString& swFieldName,
   1590                          int nControlIndex,
   1591                          const CFX_ByteString& string) {
   1592   // Not supported.
   1593 }
   1594 
   1595 bool Field::lineWidth(CJS_Runtime* pRuntime,
   1596                       CJS_PropValue& vp,
   1597                       CFX_WideString& sError) {
   1598   if (vp.IsSetting()) {
   1599     if (!m_bCanSet)
   1600       return false;
   1601 
   1602     int iWidth;
   1603     vp >> iWidth;
   1604 
   1605     if (m_bDelay) {
   1606       AddDelay_Int(FP_LINEWIDTH, iWidth);
   1607     } else {
   1608       Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName,
   1609                           m_nFormControlIndex, iWidth);
   1610     }
   1611     return true;
   1612   }
   1613   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1614   if (FieldArray.empty())
   1615     return false;
   1616 
   1617   CPDF_FormField* pFormField = FieldArray[0];
   1618   ASSERT(pFormField);
   1619   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   1620   if (!pFormControl)
   1621     return false;
   1622 
   1623   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   1624   if (!pFormField->CountControls())
   1625     return false;
   1626 
   1627   CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
   1628   if (!pWidget)
   1629     return false;
   1630 
   1631   vp << (int32_t)pWidget->GetBorderWidth();
   1632   return true;
   1633 }
   1634 
   1635 void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1636                          const CFX_WideString& swFieldName,
   1637                          int nControlIndex,
   1638                          int number) {
   1639   CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
   1640   std::vector<CPDF_FormField*> FieldArray =
   1641       GetFormFields(pFormFillEnv, swFieldName);
   1642   for (CPDF_FormField* pFormField : FieldArray) {
   1643     if (nControlIndex < 0) {
   1644       bool bSet = false;
   1645       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
   1646         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
   1647         ASSERT(pFormControl);
   1648 
   1649         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
   1650           if (number != pWidget->GetBorderWidth()) {
   1651             pWidget->SetBorderWidth(number);
   1652             bSet = true;
   1653           }
   1654         }
   1655       }
   1656       if (bSet)
   1657         UpdateFormField(pFormFillEnv, pFormField, true, true, true);
   1658     } else {
   1659       if (nControlIndex >= pFormField->CountControls())
   1660         return;
   1661       if (CPDF_FormControl* pFormControl =
   1662               pFormField->GetControl(nControlIndex)) {
   1663         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
   1664           if (number != pWidget->GetBorderWidth()) {
   1665             pWidget->SetBorderWidth(number);
   1666             UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
   1667           }
   1668         }
   1669       }
   1670     }
   1671   }
   1672 }
   1673 
   1674 bool Field::multiline(CJS_Runtime* pRuntime,
   1675                       CJS_PropValue& vp,
   1676                       CFX_WideString& sError) {
   1677   ASSERT(m_pFormFillEnv);
   1678 
   1679   if (vp.IsSetting()) {
   1680     if (!m_bCanSet)
   1681       return false;
   1682 
   1683     bool bVP;
   1684     vp >> bVP;
   1685 
   1686     if (m_bDelay) {
   1687       AddDelay_Bool(FP_MULTILINE, bVP);
   1688     } else {
   1689       Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName,
   1690                           m_nFormControlIndex, bVP);
   1691     }
   1692     return true;
   1693   }
   1694   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1695   if (FieldArray.empty())
   1696     return false;
   1697 
   1698   CPDF_FormField* pFormField = FieldArray[0];
   1699   if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
   1700     return false;
   1701 
   1702   if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
   1703     vp << true;
   1704   else
   1705     vp << false;
   1706 
   1707   return true;
   1708 }
   1709 
   1710 void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1711                          const CFX_WideString& swFieldName,
   1712                          int nControlIndex,
   1713                          bool b) {
   1714   // Not supported.
   1715 }
   1716 
   1717 bool Field::multipleSelection(CJS_Runtime* pRuntime,
   1718                               CJS_PropValue& vp,
   1719                               CFX_WideString& sError) {
   1720   ASSERT(m_pFormFillEnv);
   1721   if (vp.IsSetting()) {
   1722     if (!m_bCanSet)
   1723       return false;
   1724 
   1725     bool bVP;
   1726     vp >> bVP;
   1727     if (m_bDelay) {
   1728       AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
   1729     } else {
   1730       Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName,
   1731                                   m_nFormControlIndex, bVP);
   1732     }
   1733     return true;
   1734   }
   1735   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1736   if (FieldArray.empty())
   1737     return false;
   1738 
   1739   CPDF_FormField* pFormField = FieldArray[0];
   1740   if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
   1741     return false;
   1742 
   1743   vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT);
   1744   return true;
   1745 }
   1746 
   1747 void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1748                                  const CFX_WideString& swFieldName,
   1749                                  int nControlIndex,
   1750                                  bool b) {
   1751   // Not supported.
   1752 }
   1753 
   1754 bool Field::name(CJS_Runtime* pRuntime,
   1755                  CJS_PropValue& vp,
   1756                  CFX_WideString& sError) {
   1757   if (!vp.IsGetting())
   1758     return false;
   1759 
   1760   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1761   if (FieldArray.empty())
   1762     return false;
   1763 
   1764   vp << m_FieldName;
   1765   return true;
   1766 }
   1767 
   1768 bool Field::numItems(CJS_Runtime* pRuntime,
   1769                      CJS_PropValue& vp,
   1770                      CFX_WideString& sError) {
   1771   if (!vp.IsGetting())
   1772     return false;
   1773 
   1774   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1775   if (FieldArray.empty())
   1776     return false;
   1777 
   1778   CPDF_FormField* pFormField = FieldArray[0];
   1779   if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
   1780       pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
   1781     return false;
   1782   }
   1783 
   1784   vp << (int32_t)pFormField->CountOptions();
   1785   return true;
   1786 }
   1787 
   1788 bool Field::page(CJS_Runtime* pRuntime,
   1789                  CJS_PropValue& vp,
   1790                  CFX_WideString& sError) {
   1791   if (!vp.IsGetting()) {
   1792     sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
   1793     return false;
   1794   }
   1795 
   1796   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1797   if (FieldArray.empty())
   1798     return false;
   1799 
   1800   CPDF_FormField* pFormField = FieldArray[0];
   1801   if (!pFormField)
   1802     return false;
   1803 
   1804   std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
   1805   m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
   1806   if (widgets.empty()) {
   1807     vp << (int32_t)-1;
   1808     return true;
   1809   }
   1810 
   1811   CJS_Array PageArray;
   1812   int i = 0;
   1813   for (const auto& pObserved : widgets) {
   1814     if (!pObserved) {
   1815       sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
   1816       return false;
   1817     }
   1818 
   1819     auto pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
   1820     CPDFSDK_PageView* pPageView = pWidget->GetPageView();
   1821     if (!pPageView)
   1822       return false;
   1823 
   1824     PageArray.SetElement(
   1825         pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
   1826     ++i;
   1827   }
   1828 
   1829   vp << PageArray;
   1830   return true;
   1831 }
   1832 
   1833 bool Field::password(CJS_Runtime* pRuntime,
   1834                      CJS_PropValue& vp,
   1835                      CFX_WideString& sError) {
   1836   ASSERT(m_pFormFillEnv);
   1837 
   1838   if (vp.IsSetting()) {
   1839     if (!m_bCanSet)
   1840       return false;
   1841 
   1842     bool bVP;
   1843     vp >> bVP;
   1844     if (m_bDelay) {
   1845       AddDelay_Bool(FP_PASSWORD, bVP);
   1846     } else {
   1847       Field::SetPassword(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   1848                          bVP);
   1849     }
   1850     return true;
   1851   }
   1852 
   1853   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1854   if (FieldArray.empty())
   1855     return false;
   1856 
   1857   CPDF_FormField* pFormField = FieldArray[0];
   1858   if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
   1859     return false;
   1860 
   1861   vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD);
   1862   return true;
   1863 }
   1864 
   1865 void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   1866                         const CFX_WideString& swFieldName,
   1867                         int nControlIndex,
   1868                         bool b) {
   1869   // Not supported.
   1870 }
   1871 
   1872 bool Field::print(CJS_Runtime* pRuntime,
   1873                   CJS_PropValue& vp,
   1874                   CFX_WideString& sError) {
   1875   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   1876   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1877   if (FieldArray.empty())
   1878     return false;
   1879 
   1880   if (vp.IsSetting()) {
   1881     if (!m_bCanSet)
   1882       return false;
   1883 
   1884     bool bVP;
   1885     vp >> bVP;
   1886 
   1887     for (CPDF_FormField* pFormField : FieldArray) {
   1888       if (m_nFormControlIndex < 0) {
   1889         bool bSet = false;
   1890         for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
   1891           if (CPDFSDK_Widget* pWidget =
   1892                   pInterForm->GetWidget(pFormField->GetControl(i))) {
   1893             uint32_t dwFlags = pWidget->GetFlags();
   1894             if (bVP)
   1895               dwFlags |= ANNOTFLAG_PRINT;
   1896             else
   1897               dwFlags &= ~ANNOTFLAG_PRINT;
   1898 
   1899             if (dwFlags != pWidget->GetFlags()) {
   1900               pWidget->SetFlags(dwFlags);
   1901               bSet = true;
   1902             }
   1903           }
   1904         }
   1905 
   1906         if (bSet)
   1907           UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
   1908       } else {
   1909         if (m_nFormControlIndex >= pFormField->CountControls())
   1910           return false;
   1911         if (CPDF_FormControl* pFormControl =
   1912                 pFormField->GetControl(m_nFormControlIndex)) {
   1913           if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
   1914             uint32_t dwFlags = pWidget->GetFlags();
   1915             if (bVP)
   1916               dwFlags |= ANNOTFLAG_PRINT;
   1917             else
   1918               dwFlags &= ~ANNOTFLAG_PRINT;
   1919 
   1920             if (dwFlags != pWidget->GetFlags()) {
   1921               pWidget->SetFlags(dwFlags);
   1922               UpdateFormControl(m_pFormFillEnv.Get(),
   1923                                 pFormField->GetControl(m_nFormControlIndex),
   1924                                 true, false, true);
   1925             }
   1926           }
   1927         }
   1928       }
   1929     }
   1930     return true;
   1931   }
   1932 
   1933   CPDF_FormField* pFormField = FieldArray[0];
   1934   CPDFSDK_Widget* pWidget =
   1935       pInterForm->GetWidget(GetSmartFieldControl(pFormField));
   1936   if (!pWidget)
   1937     return false;
   1938 
   1939   vp << !!(pWidget->GetFlags() & ANNOTFLAG_PRINT);
   1940   return true;
   1941 }
   1942 
   1943 bool Field::radiosInUnison(CJS_Runtime* pRuntime,
   1944                            CJS_PropValue& vp,
   1945                            CFX_WideString& sError) {
   1946   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1947   if (FieldArray.empty())
   1948     return false;
   1949 
   1950   if (vp.IsSetting()) {
   1951     if (!m_bCanSet)
   1952       return false;
   1953 
   1954     bool bVP;
   1955     vp >> bVP;
   1956     return true;
   1957   }
   1958   CPDF_FormField* pFormField = FieldArray[0];
   1959   if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
   1960     return false;
   1961 
   1962   vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON);
   1963   return true;
   1964 }
   1965 
   1966 bool Field::readonly(CJS_Runtime* pRuntime,
   1967                      CJS_PropValue& vp,
   1968                      CFX_WideString& sError) {
   1969   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   1970   if (FieldArray.empty())
   1971     return false;
   1972 
   1973   if (vp.IsSetting()) {
   1974     if (!m_bCanSet)
   1975       return false;
   1976 
   1977     bool bVP;
   1978     vp >> bVP;
   1979     return true;
   1980   }
   1981   vp << !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY);
   1982   return true;
   1983 }
   1984 
   1985 bool Field::rect(CJS_Runtime* pRuntime,
   1986                  CJS_PropValue& vp,
   1987                  CFX_WideString& sError) {
   1988   CJS_Value Upper_Leftx(pRuntime);
   1989   CJS_Value Upper_Lefty(pRuntime);
   1990   CJS_Value Lower_Rightx(pRuntime);
   1991   CJS_Value Lower_Righty(pRuntime);
   1992 
   1993   if (vp.IsSetting()) {
   1994     if (!m_bCanSet)
   1995       return false;
   1996     if (!vp.GetJSValue()->IsArrayObject())
   1997       return false;
   1998 
   1999     CJS_Array rcArray;
   2000     vp >> rcArray;
   2001     rcArray.GetElement(pRuntime, 0, Upper_Leftx);
   2002     rcArray.GetElement(pRuntime, 1, Upper_Lefty);
   2003     rcArray.GetElement(pRuntime, 2, Lower_Rightx);
   2004     rcArray.GetElement(pRuntime, 3, Lower_Righty);
   2005 
   2006     FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
   2007     pArray[0] = static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime));
   2008     pArray[1] = static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime));
   2009     pArray[2] = static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime));
   2010     pArray[3] = static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime));
   2011 
   2012     CFX_FloatRect crRect(pArray);
   2013     if (m_bDelay) {
   2014       AddDelay_Rect(FP_RECT, crRect);
   2015     } else {
   2016       Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   2017                      crRect);
   2018     }
   2019     return true;
   2020   }
   2021   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2022   if (FieldArray.empty())
   2023     return false;
   2024 
   2025   CPDF_FormField* pFormField = FieldArray[0];
   2026   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   2027   CPDFSDK_Widget* pWidget =
   2028       pInterForm->GetWidget(GetSmartFieldControl(pFormField));
   2029   if (!pWidget)
   2030     return false;
   2031 
   2032   CFX_FloatRect crRect = pWidget->GetRect();
   2033   Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
   2034   Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
   2035   Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
   2036   Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
   2037 
   2038   CJS_Array rcArray;
   2039   rcArray.SetElement(pRuntime, 0, Upper_Leftx);
   2040   rcArray.SetElement(pRuntime, 1, Upper_Lefty);
   2041   rcArray.SetElement(pRuntime, 2, Lower_Rightx);
   2042   rcArray.SetElement(pRuntime, 3, Lower_Righty);
   2043   vp << rcArray;
   2044   return true;
   2045 }
   2046 
   2047 void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2048                     const CFX_WideString& swFieldName,
   2049                     int nControlIndex,
   2050                     const CFX_FloatRect& rect) {
   2051   CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
   2052   std::vector<CPDF_FormField*> FieldArray =
   2053       GetFormFields(pFormFillEnv, swFieldName);
   2054   for (CPDF_FormField* pFormField : FieldArray) {
   2055     if (nControlIndex < 0) {
   2056       bool bSet = false;
   2057       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
   2058         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
   2059         ASSERT(pFormControl);
   2060 
   2061         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
   2062           CFX_FloatRect crRect = rect;
   2063 
   2064           CPDF_Page* pPDFPage = pWidget->GetPDFPage();
   2065           crRect.Intersect(pPDFPage->GetPageBBox());
   2066 
   2067           if (!crRect.IsEmpty()) {
   2068             CFX_FloatRect rcOld = pWidget->GetRect();
   2069             if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
   2070                 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
   2071               pWidget->SetRect(crRect);
   2072               bSet = true;
   2073             }
   2074           }
   2075         }
   2076       }
   2077 
   2078       if (bSet)
   2079         UpdateFormField(pFormFillEnv, pFormField, true, true, true);
   2080     } else {
   2081       if (nControlIndex >= pFormField->CountControls())
   2082         return;
   2083       if (CPDF_FormControl* pFormControl =
   2084               pFormField->GetControl(nControlIndex)) {
   2085         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
   2086           CFX_FloatRect crRect = rect;
   2087 
   2088           CPDF_Page* pPDFPage = pWidget->GetPDFPage();
   2089           crRect.Intersect(pPDFPage->GetPageBBox());
   2090 
   2091           if (!crRect.IsEmpty()) {
   2092             CFX_FloatRect rcOld = pWidget->GetRect();
   2093             if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
   2094                 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
   2095               pWidget->SetRect(crRect);
   2096               UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
   2097             }
   2098           }
   2099         }
   2100       }
   2101     }
   2102   }
   2103 }
   2104 
   2105 bool Field::required(CJS_Runtime* pRuntime,
   2106                      CJS_PropValue& vp,
   2107                      CFX_WideString& sError) {
   2108   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2109   if (FieldArray.empty())
   2110     return false;
   2111 
   2112   if (vp.IsSetting()) {
   2113     if (!m_bCanSet)
   2114       return false;
   2115 
   2116     bool bVP;
   2117     vp >> bVP;
   2118     return true;
   2119   }
   2120   CPDF_FormField* pFormField = FieldArray[0];
   2121   if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
   2122     return false;
   2123 
   2124   vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED);
   2125   return true;
   2126 }
   2127 
   2128 bool Field::richText(CJS_Runtime* pRuntime,
   2129                      CJS_PropValue& vp,
   2130                      CFX_WideString& sError) {
   2131   ASSERT(m_pFormFillEnv);
   2132 
   2133   if (vp.IsSetting()) {
   2134     if (!m_bCanSet)
   2135       return false;
   2136 
   2137     bool bVP;
   2138     vp >> bVP;
   2139     if (m_bDelay)
   2140       AddDelay_Bool(FP_RICHTEXT, bVP);
   2141 
   2142     return true;
   2143   }
   2144 
   2145   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2146   if (FieldArray.empty())
   2147     return false;
   2148 
   2149   CPDF_FormField* pFormField = FieldArray[0];
   2150   if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
   2151     return false;
   2152 
   2153   vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT);
   2154   return true;
   2155 }
   2156 
   2157 bool Field::richValue(CJS_Runtime* pRuntime,
   2158                       CJS_PropValue& vp,
   2159                       CFX_WideString& sError) {
   2160   return true;
   2161 }
   2162 
   2163 bool Field::rotation(CJS_Runtime* pRuntime,
   2164                      CJS_PropValue& vp,
   2165                      CFX_WideString& sError) {
   2166   ASSERT(m_pFormFillEnv);
   2167 
   2168   if (vp.IsSetting()) {
   2169     if (!m_bCanSet)
   2170       return false;
   2171 
   2172     int nVP;
   2173     vp >> nVP;
   2174     if (m_bDelay) {
   2175       AddDelay_Int(FP_ROTATION, nVP);
   2176     } else {
   2177       Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   2178                          nVP);
   2179     }
   2180     return true;
   2181   }
   2182   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2183   if (FieldArray.empty())
   2184     return false;
   2185 
   2186   CPDF_FormField* pFormField = FieldArray[0];
   2187   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2188   if (!pFormControl)
   2189     return false;
   2190 
   2191   vp << (int32_t)pFormControl->GetRotation();
   2192   return true;
   2193 }
   2194 
   2195 void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2196                         const CFX_WideString& swFieldName,
   2197                         int nControlIndex,
   2198                         int number) {
   2199   // Not supported.
   2200 }
   2201 
   2202 bool Field::strokeColor(CJS_Runtime* pRuntime,
   2203                         CJS_PropValue& vp,
   2204                         CFX_WideString& sError) {
   2205   CJS_Array crArray;
   2206 
   2207   if (vp.IsSetting()) {
   2208     if (!m_bCanSet)
   2209       return false;
   2210 
   2211     if (!vp.GetJSValue()->IsArrayObject())
   2212       return false;
   2213 
   2214     vp >> crArray;
   2215 
   2216     CPWL_Color color;
   2217     color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
   2218     if (m_bDelay) {
   2219       AddDelay_Color(FP_STROKECOLOR, color);
   2220     } else {
   2221       Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName,
   2222                             m_nFormControlIndex, color);
   2223     }
   2224     return true;
   2225   }
   2226   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2227   if (FieldArray.empty())
   2228     return false;
   2229 
   2230   CPDF_FormField* pFormField = FieldArray[0];
   2231   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2232   if (!pFormControl)
   2233     return false;
   2234 
   2235   int iColorType;
   2236   pFormControl->GetBorderColor(iColorType);
   2237 
   2238   CPWL_Color color;
   2239   if (iColorType == COLORTYPE_TRANSPARENT) {
   2240     color = CPWL_Color(COLORTYPE_TRANSPARENT);
   2241   } else if (iColorType == COLORTYPE_GRAY) {
   2242     color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
   2243   } else if (iColorType == COLORTYPE_RGB) {
   2244     color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
   2245                        pFormControl->GetOriginalBorderColor(1),
   2246                        pFormControl->GetOriginalBorderColor(2));
   2247   } else if (iColorType == COLORTYPE_CMYK) {
   2248     color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
   2249                        pFormControl->GetOriginalBorderColor(1),
   2250                        pFormControl->GetOriginalBorderColor(2),
   2251                        pFormControl->GetOriginalBorderColor(3));
   2252   } else {
   2253     return false;
   2254   }
   2255 
   2256   color::ConvertPWLColorToArray(pRuntime, color, &crArray);
   2257   vp << crArray;
   2258   return true;
   2259 }
   2260 
   2261 void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2262                            const CFX_WideString& swFieldName,
   2263                            int nControlIndex,
   2264                            const CPWL_Color& color) {
   2265   // Not supported.
   2266 }
   2267 
   2268 bool Field::style(CJS_Runtime* pRuntime,
   2269                   CJS_PropValue& vp,
   2270                   CFX_WideString& sError) {
   2271   ASSERT(m_pFormFillEnv);
   2272 
   2273   if (vp.IsSetting()) {
   2274     if (!m_bCanSet)
   2275       return false;
   2276 
   2277     CFX_ByteString csBCaption;
   2278     vp >> csBCaption;
   2279 
   2280     if (m_bDelay) {
   2281       AddDelay_String(FP_STYLE, csBCaption);
   2282     } else {
   2283       Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   2284                       csBCaption);
   2285     }
   2286     return true;
   2287   }
   2288   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2289   if (FieldArray.empty())
   2290     return false;
   2291 
   2292   CPDF_FormField* pFormField = FieldArray[0];
   2293   if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
   2294       pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
   2295     return false;
   2296   }
   2297 
   2298   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2299   if (!pFormControl)
   2300     return false;
   2301 
   2302   CFX_WideString csWCaption = pFormControl->GetNormalCaption();
   2303   CFX_ByteString csBCaption;
   2304 
   2305   switch (csWCaption[0]) {
   2306     case L'l':
   2307       csBCaption = "circle";
   2308       break;
   2309     case L'8':
   2310       csBCaption = "cross";
   2311       break;
   2312     case L'u':
   2313       csBCaption = "diamond";
   2314       break;
   2315     case L'n':
   2316       csBCaption = "square";
   2317       break;
   2318     case L'H':
   2319       csBCaption = "star";
   2320       break;
   2321     default:  // L'4'
   2322       csBCaption = "check";
   2323       break;
   2324   }
   2325   vp << csBCaption;
   2326   return true;
   2327 }
   2328 
   2329 void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2330                      const CFX_WideString& swFieldName,
   2331                      int nControlIndex,
   2332                      const CFX_ByteString& string) {
   2333   // Not supported.
   2334 }
   2335 
   2336 bool Field::submitName(CJS_Runtime* pRuntime,
   2337                        CJS_PropValue& vp,
   2338                        CFX_WideString& sError) {
   2339   return true;
   2340 }
   2341 
   2342 bool Field::textColor(CJS_Runtime* pRuntime,
   2343                       CJS_PropValue& vp,
   2344                       CFX_WideString& sError) {
   2345   CJS_Array crArray;
   2346 
   2347   if (vp.IsSetting()) {
   2348     if (!m_bCanSet)
   2349       return false;
   2350 
   2351     if (!vp.GetJSValue()->IsArrayObject())
   2352       return false;
   2353 
   2354     vp >> crArray;
   2355 
   2356     CPWL_Color color;
   2357     color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
   2358     if (m_bDelay) {
   2359       AddDelay_Color(FP_TEXTCOLOR, color);
   2360     } else {
   2361       Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName,
   2362                           m_nFormControlIndex, color);
   2363     }
   2364     return true;
   2365   }
   2366   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2367   if (FieldArray.empty())
   2368     return false;
   2369 
   2370   CPDF_FormField* pFormField = FieldArray[0];
   2371   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2372   if (!pFormControl)
   2373     return false;
   2374 
   2375   int iColorType;
   2376   FX_ARGB color;
   2377   CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
   2378   FieldAppearance.GetColor(color, iColorType);
   2379 
   2380   int32_t a;
   2381   int32_t r;
   2382   int32_t g;
   2383   int32_t b;
   2384   ArgbDecode(color, a, r, g, b);
   2385 
   2386   CPWL_Color crRet =
   2387       CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
   2388 
   2389   if (iColorType == COLORTYPE_TRANSPARENT)
   2390     crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
   2391 
   2392   color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
   2393   vp << crArray;
   2394   return true;
   2395 }
   2396 
   2397 void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2398                          const CFX_WideString& swFieldName,
   2399                          int nControlIndex,
   2400                          const CPWL_Color& color) {
   2401   // Not supported.
   2402 }
   2403 
   2404 bool Field::textFont(CJS_Runtime* pRuntime,
   2405                      CJS_PropValue& vp,
   2406                      CFX_WideString& sError) {
   2407   ASSERT(m_pFormFillEnv);
   2408 
   2409   if (vp.IsSetting()) {
   2410     if (!m_bCanSet)
   2411       return false;
   2412 
   2413     CFX_ByteString csFontName;
   2414     vp >> csFontName;
   2415     if (csFontName.IsEmpty())
   2416       return false;
   2417 
   2418     if (m_bDelay) {
   2419       AddDelay_String(FP_TEXTFONT, csFontName);
   2420     } else {
   2421       Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   2422                          csFontName);
   2423     }
   2424     return true;
   2425   }
   2426   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2427   if (FieldArray.empty())
   2428     return false;
   2429 
   2430   CPDF_FormField* pFormField = FieldArray[0];
   2431   ASSERT(pFormField);
   2432   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2433   if (!pFormControl)
   2434     return false;
   2435 
   2436   int nFieldType = pFormField->GetFieldType();
   2437   if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
   2438       nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
   2439     return false;
   2440   }
   2441   CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
   2442   if (!pFont)
   2443     return false;
   2444 
   2445   vp << pFont->GetBaseFont();
   2446   return true;
   2447 }
   2448 
   2449 void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2450                         const CFX_WideString& swFieldName,
   2451                         int nControlIndex,
   2452                         const CFX_ByteString& string) {
   2453   // Not supported.
   2454 }
   2455 
   2456 bool Field::textSize(CJS_Runtime* pRuntime,
   2457                      CJS_PropValue& vp,
   2458                      CFX_WideString& sError) {
   2459   ASSERT(m_pFormFillEnv);
   2460 
   2461   if (vp.IsSetting()) {
   2462     if (!m_bCanSet)
   2463       return false;
   2464 
   2465     int nVP;
   2466     vp >> nVP;
   2467     if (m_bDelay) {
   2468       AddDelay_Int(FP_TEXTSIZE, nVP);
   2469     } else {
   2470       Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   2471                          nVP);
   2472     }
   2473     return true;
   2474   }
   2475   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2476   if (FieldArray.empty())
   2477     return false;
   2478 
   2479   CPDF_FormField* pFormField = FieldArray[0];
   2480   ASSERT(pFormField);
   2481   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2482   if (!pFormControl)
   2483     return false;
   2484 
   2485   CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
   2486 
   2487   CFX_ByteString csFontNameTag;
   2488   FX_FLOAT fFontSize;
   2489   FieldAppearance.GetFont(csFontNameTag, fFontSize);
   2490   vp << (int)fFontSize;
   2491   return true;
   2492 }
   2493 
   2494 void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2495                         const CFX_WideString& swFieldName,
   2496                         int nControlIndex,
   2497                         int number) {
   2498   // Not supported.
   2499 }
   2500 
   2501 bool Field::type(CJS_Runtime* pRuntime,
   2502                  CJS_PropValue& vp,
   2503                  CFX_WideString& sError) {
   2504   if (!vp.IsGetting())
   2505     return false;
   2506 
   2507   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2508   if (FieldArray.empty())
   2509     return false;
   2510 
   2511   CPDF_FormField* pFormField = FieldArray[0];
   2512   switch (pFormField->GetFieldType()) {
   2513     case FIELDTYPE_UNKNOWN:
   2514       vp << L"unknown";
   2515       break;
   2516     case FIELDTYPE_PUSHBUTTON:
   2517       vp << L"button";
   2518       break;
   2519     case FIELDTYPE_CHECKBOX:
   2520       vp << L"checkbox";
   2521       break;
   2522     case FIELDTYPE_RADIOBUTTON:
   2523       vp << L"radiobutton";
   2524       break;
   2525     case FIELDTYPE_COMBOBOX:
   2526       vp << L"combobox";
   2527       break;
   2528     case FIELDTYPE_LISTBOX:
   2529       vp << L"listbox";
   2530       break;
   2531     case FIELDTYPE_TEXTFIELD:
   2532       vp << L"text";
   2533       break;
   2534     case FIELDTYPE_SIGNATURE:
   2535       vp << L"signature";
   2536       break;
   2537     default:
   2538       vp << L"unknown";
   2539       break;
   2540   }
   2541   return true;
   2542 }
   2543 
   2544 bool Field::userName(CJS_Runtime* pRuntime,
   2545                      CJS_PropValue& vp,
   2546                      CFX_WideString& sError) {
   2547   ASSERT(m_pFormFillEnv);
   2548 
   2549   if (vp.IsSetting()) {
   2550     if (!m_bCanSet)
   2551       return false;
   2552 
   2553     CFX_WideString swName;
   2554     vp >> swName;
   2555 
   2556     if (m_bDelay) {
   2557       AddDelay_WideString(FP_USERNAME, swName);
   2558     } else {
   2559       Field::SetUserName(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   2560                          swName);
   2561     }
   2562     return true;
   2563   }
   2564   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2565   if (FieldArray.empty())
   2566     return false;
   2567 
   2568   vp << FieldArray[0]->GetAlternateName();
   2569   return true;
   2570 }
   2571 
   2572 void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2573                         const CFX_WideString& swFieldName,
   2574                         int nControlIndex,
   2575                         const CFX_WideString& string) {
   2576   // Not supported.
   2577 }
   2578 
   2579 bool Field::value(CJS_Runtime* pRuntime,
   2580                   CJS_PropValue& vp,
   2581                   CFX_WideString& sError) {
   2582   if (vp.IsSetting()) {
   2583     if (!m_bCanSet)
   2584       return false;
   2585 
   2586     std::vector<CFX_WideString> strArray;
   2587     if (vp.GetJSValue()->IsArrayObject()) {
   2588       CJS_Array ValueArray;
   2589       vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
   2590       for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
   2591         CJS_Value ElementValue(pRuntime);
   2592         ValueArray.GetElement(pRuntime, i, ElementValue);
   2593         strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
   2594       }
   2595     } else {
   2596       CFX_WideString swValue;
   2597       vp >> swValue;
   2598       strArray.push_back(swValue);
   2599     }
   2600 
   2601     if (m_bDelay) {
   2602       AddDelay_WideStringArray(FP_VALUE, strArray);
   2603     } else {
   2604       Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
   2605                       strArray);
   2606     }
   2607     return true;
   2608   }
   2609 
   2610   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2611   if (FieldArray.empty())
   2612     return false;
   2613 
   2614   CPDF_FormField* pFormField = FieldArray[0];
   2615   switch (pFormField->GetFieldType()) {
   2616     case FIELDTYPE_PUSHBUTTON:
   2617       return false;
   2618     case FIELDTYPE_COMBOBOX:
   2619     case FIELDTYPE_TEXTFIELD: {
   2620       vp << pFormField->GetValue();
   2621     } break;
   2622     case FIELDTYPE_LISTBOX: {
   2623       if (pFormField->CountSelectedItems() > 1) {
   2624         CJS_Array ValueArray;
   2625         CJS_Value ElementValue(pRuntime);
   2626         int iIndex;
   2627         for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
   2628           iIndex = pFormField->GetSelectedIndex(i);
   2629           ElementValue =
   2630               CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
   2631           if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) ==
   2632               0) {
   2633             ElementValue =
   2634                 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
   2635           }
   2636           ValueArray.SetElement(pRuntime, i, ElementValue);
   2637         }
   2638         vp << ValueArray;
   2639       } else {
   2640         vp << pFormField->GetValue();
   2641       }
   2642     } break;
   2643     case FIELDTYPE_CHECKBOX:
   2644     case FIELDTYPE_RADIOBUTTON: {
   2645       bool bFind = false;
   2646       for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
   2647         if (pFormField->GetControl(i)->IsChecked()) {
   2648           vp << pFormField->GetControl(i)->GetExportValue();
   2649           bFind = true;
   2650           break;
   2651         }
   2652       }
   2653       if (!bFind)
   2654         vp << L"Off";
   2655     } break;
   2656     default:
   2657       vp << pFormField->GetValue();
   2658       break;
   2659   }
   2660   vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
   2661   return true;
   2662 }
   2663 
   2664 void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   2665                      const CFX_WideString& swFieldName,
   2666                      int nControlIndex,
   2667                      const std::vector<CFX_WideString>& strArray) {
   2668   ASSERT(pFormFillEnv);
   2669   if (strArray.empty())
   2670     return;
   2671 
   2672   std::vector<CPDF_FormField*> FieldArray =
   2673       GetFormFields(pFormFillEnv, swFieldName);
   2674 
   2675   for (CPDF_FormField* pFormField : FieldArray) {
   2676     if (pFormField->GetFullName().Compare(swFieldName) != 0)
   2677       continue;
   2678 
   2679     switch (pFormField->GetFieldType()) {
   2680       case FIELDTYPE_TEXTFIELD:
   2681       case FIELDTYPE_COMBOBOX:
   2682         if (pFormField->GetValue() != strArray[0]) {
   2683           pFormField->SetValue(strArray[0], true);
   2684           UpdateFormField(pFormFillEnv, pFormField, true, false, true);
   2685         }
   2686         break;
   2687       case FIELDTYPE_CHECKBOX:
   2688       case FIELDTYPE_RADIOBUTTON: {
   2689         if (pFormField->GetValue() != strArray[0]) {
   2690           pFormField->SetValue(strArray[0], true);
   2691           UpdateFormField(pFormFillEnv, pFormField, true, false, true);
   2692         }
   2693       } break;
   2694       case FIELDTYPE_LISTBOX: {
   2695         bool bModified = false;
   2696         for (const auto& str : strArray) {
   2697           if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
   2698             bModified = true;
   2699             break;
   2700           }
   2701         }
   2702         if (bModified) {
   2703           pFormField->ClearSelection(true);
   2704           for (const auto& str : strArray) {
   2705             int index = pFormField->FindOption(str);
   2706             if (!pFormField->IsItemSelected(index))
   2707               pFormField->SetItemSelection(index, true, true);
   2708           }
   2709           UpdateFormField(pFormFillEnv, pFormField, true, false, true);
   2710         }
   2711       } break;
   2712       default:
   2713         break;
   2714     }
   2715   }
   2716 }
   2717 
   2718 bool Field::valueAsString(CJS_Runtime* pRuntime,
   2719                           CJS_PropValue& vp,
   2720                           CFX_WideString& sError) {
   2721   if (!vp.IsGetting())
   2722     return false;
   2723 
   2724   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2725   if (FieldArray.empty())
   2726     return false;
   2727 
   2728   CPDF_FormField* pFormField = FieldArray[0];
   2729   if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
   2730     return false;
   2731 
   2732   if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
   2733     if (!pFormField->CountControls())
   2734       return false;
   2735 
   2736     if (pFormField->GetControl(0)->IsChecked())
   2737       vp << L"Yes";
   2738     else
   2739       vp << L"Off";
   2740   } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
   2741              !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
   2742     for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
   2743       if (pFormField->GetControl(i)->IsChecked()) {
   2744         vp << pFormField->GetControl(i)->GetExportValue().c_str();
   2745         break;
   2746       } else {
   2747         vp << L"Off";
   2748       }
   2749     }
   2750   } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
   2751              (pFormField->CountSelectedItems() > 1)) {
   2752     vp << L"";
   2753   } else {
   2754     vp << pFormField->GetValue().c_str();
   2755   }
   2756 
   2757   return true;
   2758 }
   2759 
   2760 bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
   2761                                   const std::vector<CJS_Value>& params,
   2762                                   CJS_Value& vRet,
   2763                                   CFX_WideString& sError) {
   2764   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2765   if (FieldArray.empty())
   2766     return false;
   2767 
   2768   CPDF_FormField* pFormField = FieldArray[0];
   2769   if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
   2770       (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
   2771     CFX_WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
   2772     if (!wsFileName.IsEmpty()) {
   2773       pFormField->SetValue(wsFileName);
   2774       UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
   2775     }
   2776     return true;
   2777   }
   2778   return false;
   2779 }
   2780 
   2781 bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
   2782                              const std::vector<CJS_Value>& params,
   2783                              CJS_Value& vRet,
   2784                              CFX_WideString& sError) {
   2785   int nface = 0;
   2786   int iSize = params.size();
   2787   if (iSize >= 1)
   2788     nface = params[0].ToInt(pRuntime);
   2789 
   2790   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2791   if (FieldArray.empty())
   2792     return false;
   2793 
   2794   CPDF_FormField* pFormField = FieldArray[0];
   2795   if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
   2796     return false;
   2797 
   2798   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2799   if (!pFormControl)
   2800     return false;
   2801 
   2802   if (nface == 0)
   2803     vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
   2804   else if (nface == 1)
   2805     vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
   2806   else if (nface == 2)
   2807     vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
   2808   else
   2809     return false;
   2810 
   2811   return true;
   2812 }
   2813 
   2814 bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
   2815                           const std::vector<CJS_Value>& params,
   2816                           CJS_Value& vRet,
   2817                           CFX_WideString& sError) {
   2818   if (params.size() >= 1) {
   2819     int nFace = params[0].ToInt(pRuntime);
   2820     if (nFace < 0 || nFace > 2)
   2821       return false;
   2822   }
   2823 
   2824   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2825   if (FieldArray.empty())
   2826     return false;
   2827 
   2828   CPDF_FormField* pFormField = FieldArray[0];
   2829   if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
   2830     return false;
   2831 
   2832   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
   2833   if (!pFormControl)
   2834     return false;
   2835 
   2836   v8::Local<v8::Object> pObj =
   2837       pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
   2838   if (pObj.IsEmpty())
   2839     return false;
   2840 
   2841   CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
   2842   vRet = CJS_Value(pRuntime, pJS_Icon);
   2843   return true;
   2844 }
   2845 
   2846 bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
   2847                              const std::vector<CJS_Value>& params,
   2848                              CJS_Value& vRet,
   2849                              CFX_WideString& sError) {
   2850   return true;
   2851 }
   2852 
   2853 bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
   2854                              const std::vector<CJS_Value>& params,
   2855                              CJS_Value& vRet,
   2856                              CFX_WideString& sError) {
   2857   return false;
   2858 }
   2859 
   2860 bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
   2861                           const std::vector<CJS_Value>& params,
   2862                           CJS_Value& vRet,
   2863                           CFX_WideString& sError) {
   2864   return false;
   2865 }
   2866 
   2867 bool Field::checkThisBox(CJS_Runtime* pRuntime,
   2868                          const std::vector<CJS_Value>& params,
   2869                          CJS_Value& vRet,
   2870                          CFX_WideString& sError) {
   2871   int iSize = params.size();
   2872   if (iSize < 1)
   2873     return false;
   2874 
   2875   if (!m_bCanSet)
   2876     return false;
   2877 
   2878   int nWidget = params[0].ToInt(pRuntime);
   2879   bool bCheckit = true;
   2880   if (iSize >= 2)
   2881     bCheckit = params[1].ToBool(pRuntime);
   2882 
   2883   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2884   if (FieldArray.empty())
   2885     return false;
   2886 
   2887   CPDF_FormField* pFormField = FieldArray[0];
   2888   if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
   2889       pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
   2890     return false;
   2891   if (nWidget < 0 || nWidget >= pFormField->CountControls())
   2892     return false;
   2893   // TODO(weili): Check whether anything special needed for radio button,
   2894   // otherwise merge these branches.
   2895   if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
   2896     pFormField->CheckControl(nWidget, bCheckit, true);
   2897   else
   2898     pFormField->CheckControl(nWidget, bCheckit, true);
   2899 
   2900   UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
   2901   return true;
   2902 }
   2903 
   2904 bool Field::clearItems(CJS_Runtime* pRuntime,
   2905                        const std::vector<CJS_Value>& params,
   2906                        CJS_Value& vRet,
   2907                        CFX_WideString& sError) {
   2908   return true;
   2909 }
   2910 
   2911 bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
   2912                              const std::vector<CJS_Value>& params,
   2913                              CJS_Value& vRet,
   2914                              CFX_WideString& sError) {
   2915   if (!m_bCanSet)
   2916     return false;
   2917 
   2918   int iSize = params.size();
   2919   if (iSize < 1)
   2920     return false;
   2921 
   2922   int nWidget = params[0].ToInt(pRuntime);
   2923   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2924   if (FieldArray.empty())
   2925     return false;
   2926 
   2927   CPDF_FormField* pFormField = FieldArray[0];
   2928   if (nWidget < 0 || nWidget >= pFormField->CountControls())
   2929     return false;
   2930 
   2931   vRet = CJS_Value(pRuntime,
   2932                    pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
   2933                        pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
   2934 
   2935   return true;
   2936 }
   2937 
   2938 bool Field::deleteItemAt(CJS_Runtime* pRuntime,
   2939                          const std::vector<CJS_Value>& params,
   2940                          CJS_Value& vRet,
   2941                          CFX_WideString& sError) {
   2942   return true;
   2943 }
   2944 
   2945 bool Field::getArray(CJS_Runtime* pRuntime,
   2946                      const std::vector<CJS_Value>& params,
   2947                      CJS_Value& vRet,
   2948                      CFX_WideString& sError) {
   2949   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2950   if (FieldArray.empty())
   2951     return false;
   2952 
   2953   std::vector<std::unique_ptr<CFX_WideString>> swSort;
   2954   for (CPDF_FormField* pFormField : FieldArray) {
   2955     swSort.push_back(std::unique_ptr<CFX_WideString>(
   2956         new CFX_WideString(pFormField->GetFullName())));
   2957   }
   2958 
   2959   std::sort(
   2960       swSort.begin(), swSort.end(),
   2961       [](const std::unique_ptr<CFX_WideString>& p1,
   2962          const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
   2963 
   2964   CJS_Array FormFieldArray;
   2965 
   2966   int j = 0;
   2967   for (const auto& pStr : swSort) {
   2968     v8::Local<v8::Object> pObj =
   2969         pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
   2970     if (pObj.IsEmpty())
   2971       return false;
   2972 
   2973     CJS_Field* pJSField =
   2974         static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
   2975     Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
   2976     pField->AttachField(m_pJSDoc, *pStr);
   2977     FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
   2978   }
   2979 
   2980   vRet = CJS_Value(pRuntime, FormFieldArray);
   2981   return true;
   2982 }
   2983 
   2984 bool Field::getItemAt(CJS_Runtime* pRuntime,
   2985                       const std::vector<CJS_Value>& params,
   2986                       CJS_Value& vRet,
   2987                       CFX_WideString& sError) {
   2988   int iSize = params.size();
   2989   int nIdx = -1;
   2990   if (iSize >= 1)
   2991     nIdx = params[0].ToInt(pRuntime);
   2992 
   2993   bool bExport = true;
   2994   if (iSize >= 2)
   2995     bExport = params[1].ToBool(pRuntime);
   2996 
   2997   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   2998   if (FieldArray.empty())
   2999     return false;
   3000 
   3001   CPDF_FormField* pFormField = FieldArray[0];
   3002   if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
   3003       (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
   3004     if (nIdx == -1 || nIdx > pFormField->CountOptions())
   3005       nIdx = pFormField->CountOptions() - 1;
   3006     if (bExport) {
   3007       CFX_WideString strval = pFormField->GetOptionValue(nIdx);
   3008       if (strval.IsEmpty())
   3009         vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
   3010       else
   3011         vRet = CJS_Value(pRuntime, strval.c_str());
   3012     } else {
   3013       vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
   3014     }
   3015   } else {
   3016     return false;
   3017   }
   3018 
   3019   return true;
   3020 }
   3021 
   3022 bool Field::getLock(CJS_Runtime* pRuntime,
   3023                     const std::vector<CJS_Value>& params,
   3024                     CJS_Value& vRet,
   3025                     CFX_WideString& sError) {
   3026   return false;
   3027 }
   3028 
   3029 bool Field::insertItemAt(CJS_Runtime* pRuntime,
   3030                          const std::vector<CJS_Value>& params,
   3031                          CJS_Value& vRet,
   3032                          CFX_WideString& sError) {
   3033   return true;
   3034 }
   3035 
   3036 bool Field::isBoxChecked(CJS_Runtime* pRuntime,
   3037                          const std::vector<CJS_Value>& params,
   3038                          CJS_Value& vRet,
   3039                          CFX_WideString& sError) {
   3040   int nIndex = -1;
   3041   if (params.size() >= 1)
   3042     nIndex = params[0].ToInt(pRuntime);
   3043 
   3044   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   3045   if (FieldArray.empty())
   3046     return false;
   3047 
   3048   CPDF_FormField* pFormField = FieldArray[0];
   3049   if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
   3050     return false;
   3051   }
   3052 
   3053   vRet = CJS_Value(pRuntime,
   3054                    ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
   3055                      pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
   3056                     pFormField->GetControl(nIndex)->IsChecked() != 0));
   3057   return true;
   3058 }
   3059 
   3060 bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
   3061                              const std::vector<CJS_Value>& params,
   3062                              CJS_Value& vRet,
   3063                              CFX_WideString& sError) {
   3064   int nIndex = -1;
   3065   if (params.size() >= 1)
   3066     nIndex = params[0].ToInt(pRuntime);
   3067 
   3068   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   3069   if (FieldArray.empty())
   3070     return false;
   3071 
   3072   CPDF_FormField* pFormField = FieldArray[0];
   3073   if (nIndex < 0 || nIndex >= pFormField->CountControls())
   3074     return false;
   3075 
   3076   vRet = CJS_Value(pRuntime,
   3077                    ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
   3078                      pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
   3079                     pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
   3080   return true;
   3081 }
   3082 
   3083 bool Field::setAction(CJS_Runtime* pRuntime,
   3084                       const std::vector<CJS_Value>& params,
   3085                       CJS_Value& vRet,
   3086                       CFX_WideString& sError) {
   3087   return true;
   3088 }
   3089 
   3090 bool Field::setFocus(CJS_Runtime* pRuntime,
   3091                      const std::vector<CJS_Value>& params,
   3092                      CJS_Value& vRet,
   3093                      CFX_WideString& sError) {
   3094   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
   3095   if (FieldArray.empty())
   3096     return false;
   3097 
   3098   CPDF_FormField* pFormField = FieldArray[0];
   3099   int32_t nCount = pFormField->CountControls();
   3100   if (nCount < 1)
   3101     return false;
   3102 
   3103   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   3104   CPDFSDK_Widget* pWidget = nullptr;
   3105   if (nCount == 1) {
   3106     pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
   3107   } else {
   3108     UnderlyingPageType* pPage =
   3109         UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
   3110             m_pFormFillEnv->GetUnderlyingDocument()));
   3111     if (!pPage)
   3112       return false;
   3113     if (CPDFSDK_PageView* pCurPageView =
   3114             m_pFormFillEnv->GetPageView(pPage, true)) {
   3115       for (int32_t i = 0; i < nCount; i++) {
   3116         if (CPDFSDK_Widget* pTempWidget =
   3117                 pInterForm->GetWidget(pFormField->GetControl(i))) {
   3118           if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
   3119             pWidget = pTempWidget;
   3120             break;
   3121           }
   3122         }
   3123       }
   3124     }
   3125   }
   3126 
   3127   if (pWidget) {
   3128     CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
   3129     m_pFormFillEnv->SetFocusAnnot(&pObserved);
   3130   }
   3131 
   3132   return true;
   3133 }
   3134 
   3135 bool Field::setItems(CJS_Runtime* pRuntime,
   3136                      const std::vector<CJS_Value>& params,
   3137                      CJS_Value& vRet,
   3138                      CFX_WideString& sError) {
   3139   return true;
   3140 }
   3141 
   3142 bool Field::setLock(CJS_Runtime* pRuntime,
   3143                     const std::vector<CJS_Value>& params,
   3144                     CJS_Value& vRet,
   3145                     CFX_WideString& sError) {
   3146   return false;
   3147 }
   3148 
   3149 bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
   3150                                       const std::vector<CJS_Value>& params,
   3151                                       CJS_Value& vRet,
   3152                                       CFX_WideString& sError) {
   3153   return false;
   3154 }
   3155 
   3156 bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
   3157                                   const std::vector<CJS_Value>& params,
   3158                                   CJS_Value& vRet,
   3159                                   CFX_WideString& sError) {
   3160   return false;
   3161 }
   3162 
   3163 bool Field::signatureInfo(CJS_Runtime* pRuntime,
   3164                           const std::vector<CJS_Value>& params,
   3165                           CJS_Value& vRet,
   3166                           CFX_WideString& sError) {
   3167   return false;
   3168 }
   3169 
   3170 bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
   3171                                   const std::vector<CJS_Value>& params,
   3172                                   CJS_Value& vRet,
   3173                                   CFX_WideString& sError) {
   3174   return false;
   3175 }
   3176 
   3177 bool Field::signatureSign(CJS_Runtime* pRuntime,
   3178                           const std::vector<CJS_Value>& params,
   3179                           CJS_Value& vRet,
   3180                           CFX_WideString& sError) {
   3181   return false;
   3182 }
   3183 
   3184 bool Field::signatureValidate(CJS_Runtime* pRuntime,
   3185                               const std::vector<CJS_Value>& params,
   3186                               CJS_Value& vRet,
   3187                               CFX_WideString& sError) {
   3188   return false;
   3189 }
   3190 
   3191 bool Field::source(CJS_Runtime* pRuntime,
   3192                    CJS_PropValue& vp,
   3193                    CFX_WideString& sError) {
   3194   if (vp.IsGetting()) {
   3195     vp << (CJS_Object*)nullptr;
   3196   }
   3197 
   3198   return true;
   3199 }
   3200 
   3201 void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
   3202   CJS_DelayData* pNewData =
   3203       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3204   pNewData->num = n;
   3205   m_pJSDoc->AddDelayData(pNewData);
   3206 }
   3207 
   3208 void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
   3209   CJS_DelayData* pNewData =
   3210       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3211   pNewData->b = b;
   3212   m_pJSDoc->AddDelayData(pNewData);
   3213 }
   3214 
   3215 void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
   3216   CJS_DelayData* pNewData =
   3217       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3218   pNewData->string = string;
   3219   m_pJSDoc->AddDelayData(pNewData);
   3220 }
   3221 
   3222 void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
   3223   CJS_DelayData* pNewData =
   3224       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3225   pNewData->widestring = string;
   3226   m_pJSDoc->AddDelayData(pNewData);
   3227 }
   3228 
   3229 void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
   3230   CJS_DelayData* pNewData =
   3231       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3232   pNewData->rect = rect;
   3233   m_pJSDoc->AddDelayData(pNewData);
   3234 }
   3235 
   3236 void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
   3237   CJS_DelayData* pNewData =
   3238       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3239   pNewData->color = color;
   3240   m_pJSDoc->AddDelayData(pNewData);
   3241 }
   3242 
   3243 void Field::AddDelay_WordArray(FIELD_PROP prop,
   3244                                const std::vector<uint32_t>& array) {
   3245   CJS_DelayData* pNewData =
   3246       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3247   pNewData->wordarray = array;
   3248   m_pJSDoc->AddDelayData(pNewData);
   3249 }
   3250 
   3251 void Field::AddDelay_WideStringArray(FIELD_PROP prop,
   3252                                      const std::vector<CFX_WideString>& array) {
   3253   CJS_DelayData* pNewData =
   3254       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
   3255   pNewData->widestringarray = array;
   3256   m_pJSDoc->AddDelayData(pNewData);
   3257 }
   3258 
   3259 void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   3260                     CJS_DelayData* pData) {
   3261   ASSERT(pFormFillEnv);
   3262   switch (pData->eProp) {
   3263     case FP_ALIGNMENT:
   3264       Field::SetAlignment(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3265                           pData->string);
   3266       break;
   3267     case FP_BORDERSTYLE:
   3268       Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
   3269                             pData->nControlIndex, pData->string);
   3270       break;
   3271     case FP_BUTTONALIGNX:
   3272       Field::SetButtonAlignX(pFormFillEnv, pData->sFieldName,
   3273                              pData->nControlIndex, pData->num);
   3274       break;
   3275     case FP_BUTTONALIGNY:
   3276       Field::SetButtonAlignY(pFormFillEnv, pData->sFieldName,
   3277                              pData->nControlIndex, pData->num);
   3278       break;
   3279     case FP_BUTTONFITBOUNDS:
   3280       Field::SetButtonFitBounds(pFormFillEnv, pData->sFieldName,
   3281                                 pData->nControlIndex, pData->b);
   3282       break;
   3283     case FP_BUTTONPOSITION:
   3284       Field::SetButtonPosition(pFormFillEnv, pData->sFieldName,
   3285                                pData->nControlIndex, pData->num);
   3286       break;
   3287     case FP_BUTTONSCALEHOW:
   3288       Field::SetButtonScaleHow(pFormFillEnv, pData->sFieldName,
   3289                                pData->nControlIndex, pData->num);
   3290       break;
   3291     case FP_BUTTONSCALEWHEN:
   3292       Field::SetButtonScaleWhen(pFormFillEnv, pData->sFieldName,
   3293                                 pData->nControlIndex, pData->num);
   3294       break;
   3295     case FP_CALCORDERINDEX:
   3296       Field::SetCalcOrderIndex(pFormFillEnv, pData->sFieldName,
   3297                                pData->nControlIndex, pData->num);
   3298       break;
   3299     case FP_CHARLIMIT:
   3300       Field::SetCharLimit(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3301                           pData->num);
   3302       break;
   3303     case FP_COMB:
   3304       Field::SetComb(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3305                      pData->b);
   3306       break;
   3307     case FP_COMMITONSELCHANGE:
   3308       Field::SetCommitOnSelChange(pFormFillEnv, pData->sFieldName,
   3309                                   pData->nControlIndex, pData->b);
   3310       break;
   3311     case FP_CURRENTVALUEINDICES:
   3312       Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
   3313                                     pData->nControlIndex, pData->wordarray);
   3314       break;
   3315     case FP_DEFAULTVALUE:
   3316       Field::SetDefaultValue(pFormFillEnv, pData->sFieldName,
   3317                              pData->nControlIndex, pData->widestring);
   3318       break;
   3319     case FP_DONOTSCROLL:
   3320       Field::SetDoNotScroll(pFormFillEnv, pData->sFieldName,
   3321                             pData->nControlIndex, pData->b);
   3322       break;
   3323     case FP_DISPLAY:
   3324       Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3325                         pData->num);
   3326       break;
   3327     case FP_FILLCOLOR:
   3328       Field::SetFillColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3329                           pData->color);
   3330       break;
   3331     case FP_HIDDEN:
   3332       Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3333                        pData->b);
   3334       break;
   3335     case FP_HIGHLIGHT:
   3336       Field::SetHighlight(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3337                           pData->string);
   3338       break;
   3339     case FP_LINEWIDTH:
   3340       Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3341                           pData->num);
   3342       break;
   3343     case FP_MULTILINE:
   3344       Field::SetMultiline(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3345                           pData->b);
   3346       break;
   3347     case FP_MULTIPLESELECTION:
   3348       Field::SetMultipleSelection(pFormFillEnv, pData->sFieldName,
   3349                                   pData->nControlIndex, pData->b);
   3350       break;
   3351     case FP_PASSWORD:
   3352       Field::SetPassword(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3353                          pData->b);
   3354       break;
   3355     case FP_RECT:
   3356       Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3357                      pData->rect);
   3358       break;
   3359     case FP_RICHTEXT:
   3360       // Not supported.
   3361       break;
   3362     case FP_RICHVALUE:
   3363       break;
   3364     case FP_ROTATION:
   3365       Field::SetRotation(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3366                          pData->num);
   3367       break;
   3368     case FP_STROKECOLOR:
   3369       Field::SetStrokeColor(pFormFillEnv, pData->sFieldName,
   3370                             pData->nControlIndex, pData->color);
   3371       break;
   3372     case FP_STYLE:
   3373       Field::SetStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3374                       pData->string);
   3375       break;
   3376     case FP_TEXTCOLOR:
   3377       Field::SetTextColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3378                           pData->color);
   3379       break;
   3380     case FP_TEXTFONT:
   3381       Field::SetTextFont(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3382                          pData->string);
   3383       break;
   3384     case FP_TEXTSIZE:
   3385       Field::SetTextSize(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3386                          pData->num);
   3387       break;
   3388     case FP_USERNAME:
   3389       Field::SetUserName(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3390                          pData->widestring);
   3391       break;
   3392     case FP_VALUE:
   3393       Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
   3394                       pData->widestringarray);
   3395       break;
   3396   }
   3397 }
   3398 
   3399 void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
   3400                      int nPageIndex,
   3401                      int nFieldType,
   3402                      const CFX_WideString& sName,
   3403                      const CFX_FloatRect& rcCoords) {
   3404   // Not supported.
   3405 }
   3406