John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 7 | #ifndef FPDFSDK_JAVASCRIPT_FIELD_H_ |
| 8 | #define FPDFSDK_JAVASCRIPT_FIELD_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 12 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 13 | #include "core/fxcrt/cfx_observable.h" |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 15 | #include "fpdfsdk/javascript/JS_Define.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 16 | #include "fpdfsdk/pdfwindow/PWL_Wnd.h" // For CPWL_Color. |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 17 | |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 18 | class CPDFSDK_Widget; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 19 | class Document; |
| 20 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | enum FIELD_PROP { |
| 22 | FP_ALIGNMENT, |
| 23 | FP_BORDERSTYLE, |
| 24 | FP_BUTTONALIGNX, |
| 25 | FP_BUTTONALIGNY, |
| 26 | FP_BUTTONFITBOUNDS, |
| 27 | FP_BUTTONPOSITION, |
| 28 | FP_BUTTONSCALEHOW, |
| 29 | FP_BUTTONSCALEWHEN, |
| 30 | FP_CALCORDERINDEX, |
| 31 | FP_CHARLIMIT, |
| 32 | FP_COMB, |
| 33 | FP_COMMITONSELCHANGE, |
| 34 | FP_CURRENTVALUEINDICES, |
| 35 | FP_DEFAULTVALUE, |
| 36 | FP_DONOTSCROLL, |
| 37 | FP_DISPLAY, |
| 38 | FP_FILLCOLOR, |
| 39 | FP_HIDDEN, |
| 40 | FP_HIGHLIGHT, |
| 41 | FP_LINEWIDTH, |
| 42 | FP_MULTILINE, |
| 43 | FP_MULTIPLESELECTION, |
| 44 | FP_PASSWORD, |
| 45 | FP_RECT, |
| 46 | FP_RICHTEXT, |
| 47 | FP_RICHVALUE, |
| 48 | FP_ROTATION, |
| 49 | FP_STROKECOLOR, |
| 50 | FP_STYLE, |
| 51 | FP_TEXTCOLOR, |
| 52 | FP_TEXTFONT, |
| 53 | FP_TEXTSIZE, |
| 54 | FP_USERNAME, |
| 55 | FP_VALUE |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | struct CJS_DelayData { |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 59 | CJS_DelayData(FIELD_PROP prop, int idx, const CFX_WideString& name); |
| 60 | ~CJS_DelayData(); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 61 | |
| 62 | FIELD_PROP eProp; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | int nControlIndex; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 64 | CFX_WideString sFieldName; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | int32_t num; |
| 66 | bool b; |
| 67 | CFX_ByteString string; |
| 68 | CFX_WideString widestring; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 69 | CFX_FloatRect rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | CPWL_Color color; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 71 | std::vector<uint32_t> wordarray; |
| 72 | std::vector<CFX_WideString> widestringarray; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | class Field : public CJS_EmbedObj { |
| 76 | public: |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 77 | explicit Field(CJS_Object* pJSObject); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 78 | ~Field() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 80 | bool alignment(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 81 | bool borderStyle(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 82 | bool buttonAlignX(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 83 | bool buttonAlignY(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 84 | bool buttonFitBounds(IJS_Context* cc, |
| 85 | CJS_PropValue& vp, |
| 86 | CFX_WideString& sError); |
| 87 | bool buttonPosition(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | CJS_PropValue& vp, |
| 89 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 90 | bool buttonScaleHow(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | CJS_PropValue& vp, |
| 92 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 93 | bool buttonScaleWhen(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | CJS_PropValue& vp, |
| 95 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 96 | bool calcOrderIndex(IJS_Context* cc, |
| 97 | CJS_PropValue& vp, |
| 98 | CFX_WideString& sError); |
| 99 | bool charLimit(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 100 | bool comb(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 101 | bool commitOnSelChange(IJS_Context* cc, |
| 102 | CJS_PropValue& vp, |
| 103 | CFX_WideString& sError); |
| 104 | bool currentValueIndices(IJS_Context* cc, |
| 105 | CJS_PropValue& vp, |
| 106 | CFX_WideString& sError); |
| 107 | bool defaultStyle(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 108 | bool defaultValue(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 109 | bool doNotScroll(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 110 | bool doNotSpellCheck(IJS_Context* cc, |
| 111 | CJS_PropValue& vp, |
| 112 | CFX_WideString& sError); |
| 113 | bool delay(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 114 | bool display(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 115 | bool doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 116 | bool editable(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 117 | bool exportValues(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 118 | bool fileSelect(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 119 | bool fillColor(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 120 | bool hidden(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 121 | bool highlight(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 122 | bool lineWidth(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 123 | bool multiline(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 124 | bool multipleSelection(IJS_Context* cc, |
| 125 | CJS_PropValue& vp, |
| 126 | CFX_WideString& sError); |
| 127 | bool name(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 128 | bool numItems(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 129 | bool page(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 130 | bool password(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 131 | bool print(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 132 | bool radiosInUnison(IJS_Context* cc, |
| 133 | CJS_PropValue& vp, |
| 134 | CFX_WideString& sError); |
| 135 | bool readonly(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 136 | bool rect(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 137 | bool required(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 138 | bool richText(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 139 | bool richValue(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 140 | bool rotation(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 141 | bool strokeColor(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 142 | bool style(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 143 | bool submitName(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 144 | bool textColor(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 145 | bool textFont(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 146 | bool textSize(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 147 | bool type(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 148 | bool userName(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 149 | bool value(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
| 150 | bool valueAsString(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | CJS_PropValue& vp, |
| 152 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 153 | bool source(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 154 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 155 | bool browseForFileToSubmit(IJS_Context* cc, |
| 156 | const std::vector<CJS_Value>& params, |
| 157 | CJS_Value& vRet, |
| 158 | CFX_WideString& sError); |
| 159 | bool buttonGetCaption(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 160 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | CJS_Value& vRet, |
| 162 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 163 | bool buttonGetIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 164 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | CJS_Value& vRet, |
| 166 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 167 | bool buttonImportIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 168 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | CJS_Value& vRet, |
| 170 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 171 | bool buttonSetCaption(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 172 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | CJS_Value& vRet, |
| 174 | CFX_WideString& sError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 175 | bool buttonSetIcon(IJS_Context* cc, |
| 176 | const std::vector<CJS_Value>& params, |
| 177 | CJS_Value& vRet, |
| 178 | CFX_WideString& sError); |
| 179 | bool checkThisBox(IJS_Context* cc, |
| 180 | const std::vector<CJS_Value>& params, |
| 181 | CJS_Value& vRet, |
| 182 | CFX_WideString& sError); |
| 183 | bool clearItems(IJS_Context* cc, |
| 184 | const std::vector<CJS_Value>& params, |
| 185 | CJS_Value& vRet, |
| 186 | CFX_WideString& sError); |
| 187 | bool defaultIsChecked(IJS_Context* cc, |
| 188 | const std::vector<CJS_Value>& params, |
| 189 | CJS_Value& vRet, |
| 190 | CFX_WideString& sError); |
| 191 | bool deleteItemAt(IJS_Context* cc, |
| 192 | const std::vector<CJS_Value>& params, |
| 193 | CJS_Value& vRet, |
| 194 | CFX_WideString& sError); |
| 195 | bool getArray(IJS_Context* cc, |
| 196 | const std::vector<CJS_Value>& params, |
| 197 | CJS_Value& vRet, |
| 198 | CFX_WideString& sError); |
| 199 | bool getItemAt(IJS_Context* cc, |
| 200 | const std::vector<CJS_Value>& params, |
| 201 | CJS_Value& vRet, |
| 202 | CFX_WideString& sError); |
| 203 | bool getLock(IJS_Context* cc, |
| 204 | const std::vector<CJS_Value>& params, |
| 205 | CJS_Value& vRet, |
| 206 | CFX_WideString& sError); |
| 207 | bool insertItemAt(IJS_Context* cc, |
| 208 | const std::vector<CJS_Value>& params, |
| 209 | CJS_Value& vRet, |
| 210 | CFX_WideString& sError); |
| 211 | bool isBoxChecked(IJS_Context* cc, |
| 212 | const std::vector<CJS_Value>& params, |
| 213 | CJS_Value& vRet, |
| 214 | CFX_WideString& sError); |
| 215 | bool isDefaultChecked(IJS_Context* cc, |
| 216 | const std::vector<CJS_Value>& params, |
| 217 | CJS_Value& vRet, |
| 218 | CFX_WideString& sError); |
| 219 | bool setAction(IJS_Context* cc, |
| 220 | const std::vector<CJS_Value>& params, |
| 221 | CJS_Value& vRet, |
| 222 | CFX_WideString& sError); |
| 223 | bool setFocus(IJS_Context* cc, |
| 224 | const std::vector<CJS_Value>& params, |
| 225 | CJS_Value& vRet, |
| 226 | CFX_WideString& sError); |
| 227 | bool setItems(IJS_Context* cc, |
| 228 | const std::vector<CJS_Value>& params, |
| 229 | CJS_Value& vRet, |
| 230 | CFX_WideString& sError); |
| 231 | bool setLock(IJS_Context* cc, |
| 232 | const std::vector<CJS_Value>& params, |
| 233 | CJS_Value& vRet, |
| 234 | CFX_WideString& sError); |
| 235 | bool signatureGetModifications(IJS_Context* cc, |
| 236 | const std::vector<CJS_Value>& params, |
| 237 | CJS_Value& vRet, |
| 238 | CFX_WideString& sError); |
| 239 | bool signatureGetSeedValue(IJS_Context* cc, |
| 240 | const std::vector<CJS_Value>& params, |
| 241 | CJS_Value& vRet, |
| 242 | CFX_WideString& sError); |
| 243 | bool signatureInfo(IJS_Context* cc, |
| 244 | const std::vector<CJS_Value>& params, |
| 245 | CJS_Value& vRet, |
| 246 | CFX_WideString& sError); |
| 247 | bool signatureSetSeedValue(IJS_Context* cc, |
| 248 | const std::vector<CJS_Value>& params, |
| 249 | CJS_Value& vRet, |
| 250 | CFX_WideString& sError); |
| 251 | bool signatureSign(IJS_Context* cc, |
| 252 | const std::vector<CJS_Value>& params, |
| 253 | CJS_Value& vRet, |
| 254 | CFX_WideString& sError); |
| 255 | bool signatureValidate(IJS_Context* cc, |
| 256 | const std::vector<CJS_Value>& params, |
| 257 | CJS_Value& vRet, |
| 258 | CFX_WideString& sError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 259 | |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 260 | static void SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | const CFX_WideString& swFieldName, |
| 262 | int nControlIndex, |
| 263 | const CFX_ByteString& string); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 264 | static void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | const CFX_WideString& swFieldName, |
| 266 | int nControlIndex, |
| 267 | const CFX_ByteString& string); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 268 | static void SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | const CFX_WideString& swFieldName, |
| 270 | int nControlIndex, |
| 271 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 272 | static void SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 273 | const CFX_WideString& swFieldName, |
| 274 | int nControlIndex, |
| 275 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 276 | static void SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | const CFX_WideString& swFieldName, |
| 278 | int nControlIndex, |
| 279 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 280 | static void SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | const CFX_WideString& swFieldName, |
| 282 | int nControlIndex, |
| 283 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 284 | static void SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | const CFX_WideString& swFieldName, |
| 286 | int nControlIndex, |
| 287 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 288 | static void SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | const CFX_WideString& swFieldName, |
| 290 | int nControlIndex, |
| 291 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 292 | static void SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | const CFX_WideString& swFieldName, |
| 294 | int nControlIndex, |
| 295 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 296 | static void SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | const CFX_WideString& swFieldName, |
| 298 | int nControlIndex, |
| 299 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 300 | static void SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | const CFX_WideString& swFieldName, |
| 302 | int nControlIndex, |
| 303 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 304 | static void SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | const CFX_WideString& swFieldName, |
| 306 | int nControlIndex, |
| 307 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 308 | static void SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 309 | const CFX_WideString& swFieldName, |
| 310 | int nControlIndex, |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 311 | const std::vector<uint32_t>& array); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 312 | static void SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | const CFX_WideString& swFieldName, |
| 314 | int nControlIndex); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 315 | static void SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 316 | const CFX_WideString& swFieldName, |
| 317 | int nControlIndex, |
| 318 | const CFX_WideString& string); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 319 | static void SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | const CFX_WideString& swFieldName, |
| 321 | int nControlIndex, |
| 322 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 323 | static void SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 324 | const CFX_WideString& swFieldName, |
| 325 | int nControlIndex, |
| 326 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 327 | static void SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | const CFX_WideString& swFieldName, |
| 329 | int nControlIndex, |
| 330 | const CPWL_Color& color); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 331 | static void SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | const CFX_WideString& swFieldName, |
| 333 | int nControlIndex, |
| 334 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 335 | static void SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | const CFX_WideString& swFieldName, |
| 337 | int nControlIndex, |
| 338 | const CFX_ByteString& string); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 339 | static void SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 340 | const CFX_WideString& swFieldName, |
| 341 | int nControlIndex, |
| 342 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 343 | static void SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | const CFX_WideString& swFieldName, |
| 345 | int nControlIndex, |
| 346 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 347 | static void SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | const CFX_WideString& swFieldName, |
| 349 | int nControlIndex, |
| 350 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 351 | static void SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 352 | const CFX_WideString& swFieldName, |
| 353 | int nControlIndex, |
| 354 | bool b); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 355 | static void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 356 | const CFX_WideString& swFieldName, |
| 357 | int nControlIndex, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 358 | const CFX_FloatRect& rect); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 359 | static void SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 360 | const CFX_WideString& swFieldName, |
| 361 | int nControlIndex, |
| 362 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 363 | static void SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 364 | const CFX_WideString& swFieldName, |
| 365 | int nControlIndex, |
| 366 | const CPWL_Color& color); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 367 | static void SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 368 | const CFX_WideString& swFieldName, |
| 369 | int nControlIndex, |
| 370 | const CFX_ByteString& string); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 371 | static void SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 372 | const CFX_WideString& swFieldName, |
| 373 | int nControlIndex, |
| 374 | const CPWL_Color& color); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 375 | static void SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 376 | const CFX_WideString& swFieldName, |
| 377 | int nControlIndex, |
| 378 | const CFX_ByteString& string); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 379 | static void SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | const CFX_WideString& swFieldName, |
| 381 | int nControlIndex, |
| 382 | int number); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 383 | static void SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 384 | const CFX_WideString& swFieldName, |
| 385 | int nControlIndex, |
| 386 | const CFX_WideString& string); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 387 | static void SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 388 | const CFX_WideString& swFieldName, |
| 389 | int nControlIndex, |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 390 | const std::vector<CFX_WideString>& strArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 391 | |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 392 | static void AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | int nPageIndex, |
| 394 | int nFieldType, |
| 395 | const CFX_WideString& sName, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 396 | const CFX_FloatRect& rcCoords); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 397 | |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 398 | static void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 399 | CPDF_FormField* pFormField, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 400 | bool bChangeMark, |
| 401 | bool bResetAP, |
| 402 | bool bRefresh); |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 403 | static void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 404 | CPDF_FormControl* pFormControl, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 405 | bool bChangeMark, |
| 406 | bool bResetAP, |
| 407 | bool bRefresh); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 408 | |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 409 | static CPDFSDK_Widget* GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
dsinclair | ef523dd | 2016-08-15 13:10:03 -0700 | [diff] [blame] | 410 | CPDF_FormControl* pFormControl, |
| 411 | bool createIfNeeded); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 412 | static std::vector<CPDF_FormField*> GetFormFields( |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 413 | CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 414 | const CFX_WideString& csFieldName); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 415 | |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 416 | static void DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 417 | CJS_DelayData* pData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 418 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 419 | bool AttachField(Document* pDocument, const CFX_WideString& csFieldName); |
| 420 | void SetDelay(bool bDelay); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 421 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 422 | protected: |
| 423 | void ParseFieldName(const std::wstring& strFieldNameParsed, |
| 424 | std::wstring& strFieldName, |
| 425 | int& iControlNo); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 426 | std::vector<CPDF_FormField*> GetFormFields( |
| 427 | const CFX_WideString& csFieldName) const; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | CPDF_FormControl* GetSmartFieldControl(CPDF_FormField* pFormField); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 429 | bool ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 430 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 431 | void AddDelay_Int(FIELD_PROP prop, int32_t n); |
| 432 | void AddDelay_Bool(FIELD_PROP prop, bool b); |
| 433 | void AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string); |
| 434 | void AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string); |
| 435 | void AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect); |
| 436 | void AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color); |
| 437 | void AddDelay_WordArray(FIELD_PROP prop, const std::vector<uint32_t>& array); |
| 438 | void AddDelay_WideStringArray(FIELD_PROP prop, |
| 439 | const std::vector<CFX_WideString>& array); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | |
| 441 | void DoDelay(); |
| 442 | |
| 443 | public: |
| 444 | Document* m_pJSDoc; |
dsinclair | 3a7741a | 2016-10-11 10:39:49 -0700 | [diff] [blame] | 445 | CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 446 | CFX_WideString m_FieldName; |
| 447 | int m_nFormControlIndex; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 448 | bool m_bCanSet; |
| 449 | bool m_bDelay; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 450 | }; |
| 451 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | class CJS_Field : public CJS_Object { |
| 453 | public: |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 454 | explicit CJS_Field(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} |
weili | bff506d | 2016-06-20 11:37:05 -0700 | [diff] [blame] | 455 | ~CJS_Field() override {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 456 | |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 457 | void InitInstance(IJS_Runtime* pIRuntime) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 458 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 459 | DECLARE_JS_CLASS(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 460 | JS_STATIC_PROP(alignment, Field); |
| 461 | JS_STATIC_PROP(borderStyle, Field); |
| 462 | JS_STATIC_PROP(buttonAlignX, Field); |
| 463 | JS_STATIC_PROP(buttonAlignY, Field); |
| 464 | JS_STATIC_PROP(buttonFitBounds, Field); |
| 465 | JS_STATIC_PROP(buttonPosition, Field); |
| 466 | JS_STATIC_PROP(buttonScaleHow, Field); |
| 467 | JS_STATIC_PROP(buttonScaleWhen, Field); |
| 468 | JS_STATIC_PROP(calcOrderIndex, Field); |
| 469 | JS_STATIC_PROP(charLimit, Field); |
| 470 | JS_STATIC_PROP(comb, Field); |
| 471 | JS_STATIC_PROP(commitOnSelChange, Field); |
| 472 | JS_STATIC_PROP(currentValueIndices, Field); |
| 473 | JS_STATIC_PROP(defaultStyle, Field); |
| 474 | JS_STATIC_PROP(defaultValue, Field); |
| 475 | JS_STATIC_PROP(doNotScroll, Field); |
| 476 | JS_STATIC_PROP(doNotSpellCheck, Field); |
| 477 | JS_STATIC_PROP(delay, Field); |
| 478 | JS_STATIC_PROP(display, Field); |
| 479 | JS_STATIC_PROP(doc, Field); |
| 480 | JS_STATIC_PROP(editable, Field); |
| 481 | JS_STATIC_PROP(exportValues, Field); |
| 482 | JS_STATIC_PROP(fileSelect, Field); |
| 483 | JS_STATIC_PROP(fillColor, Field); |
| 484 | JS_STATIC_PROP(hidden, Field); |
| 485 | JS_STATIC_PROP(highlight, Field); |
| 486 | JS_STATIC_PROP(lineWidth, Field); |
| 487 | JS_STATIC_PROP(multiline, Field); |
| 488 | JS_STATIC_PROP(multipleSelection, Field); |
| 489 | JS_STATIC_PROP(name, Field); |
| 490 | JS_STATIC_PROP(numItems, Field); |
| 491 | JS_STATIC_PROP(page, Field); |
| 492 | JS_STATIC_PROP(password, Field); |
| 493 | JS_STATIC_PROP(print, Field); |
| 494 | JS_STATIC_PROP(radiosInUnison, Field); |
| 495 | JS_STATIC_PROP(readonly, Field); |
| 496 | JS_STATIC_PROP(rect, Field); |
| 497 | JS_STATIC_PROP(required, Field); |
| 498 | JS_STATIC_PROP(richText, Field); |
| 499 | JS_STATIC_PROP(richValue, Field); |
| 500 | JS_STATIC_PROP(rotation, Field); |
| 501 | JS_STATIC_PROP(strokeColor, Field); |
| 502 | JS_STATIC_PROP(style, Field); |
| 503 | JS_STATIC_PROP(submitName, Field); |
| 504 | JS_STATIC_PROP(textColor, Field); |
| 505 | JS_STATIC_PROP(textFont, Field); |
| 506 | JS_STATIC_PROP(textSize, Field); |
| 507 | JS_STATIC_PROP(type, Field); |
| 508 | JS_STATIC_PROP(userName, Field); |
| 509 | JS_STATIC_PROP(value, Field); |
| 510 | JS_STATIC_PROP(valueAsString, Field); |
| 511 | JS_STATIC_PROP(source, Field); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 512 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | JS_STATIC_METHOD(browseForFileToSubmit, Field); |
| 514 | JS_STATIC_METHOD(buttonGetCaption, Field); |
| 515 | JS_STATIC_METHOD(buttonGetIcon, Field); |
| 516 | JS_STATIC_METHOD(buttonImportIcon, Field); |
| 517 | JS_STATIC_METHOD(buttonSetCaption, Field); |
| 518 | JS_STATIC_METHOD(buttonSetIcon, Field); |
| 519 | JS_STATIC_METHOD(checkThisBox, Field); |
| 520 | JS_STATIC_METHOD(clearItems, Field); |
| 521 | JS_STATIC_METHOD(defaultIsChecked, Field); |
| 522 | JS_STATIC_METHOD(deleteItemAt, Field); |
| 523 | JS_STATIC_METHOD(getArray, Field); |
| 524 | JS_STATIC_METHOD(getItemAt, Field); |
| 525 | JS_STATIC_METHOD(getLock, Field); |
| 526 | JS_STATIC_METHOD(insertItemAt, Field); |
| 527 | JS_STATIC_METHOD(isBoxChecked, Field); |
| 528 | JS_STATIC_METHOD(isDefaultChecked, Field); |
| 529 | JS_STATIC_METHOD(setAction, Field); |
| 530 | JS_STATIC_METHOD(setFocus, Field); |
| 531 | JS_STATIC_METHOD(setItems, Field); |
| 532 | JS_STATIC_METHOD(setLock, Field); |
| 533 | JS_STATIC_METHOD(signatureGetModifications, Field); |
| 534 | JS_STATIC_METHOD(signatureGetSeedValue, Field); |
| 535 | JS_STATIC_METHOD(signatureInfo, Field); |
| 536 | JS_STATIC_METHOD(signatureSetSeedValue, Field); |
| 537 | JS_STATIC_METHOD(signatureSign, Field); |
| 538 | JS_STATIC_METHOD(signatureValidate, Field); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 539 | }; |
| 540 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 541 | #endif // FPDFSDK_JAVASCRIPT_FIELD_H_ |