1 // Copyright 2014 The PDFium Authors 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 #ifndef FXJS_CJS_FIELD_H_ 8 #define FXJS_CJS_FIELD_H_ 9 10 #include <vector> 11 12 #include "fxjs/cjs_document.h" 13 #include "fxjs/cjs_object.h" 14 #include "fxjs/js_define.h" 15 16 class CFX_FloatRect; 17 class CPDF_FormControl; 18 struct CJS_DelayData; 19 20 enum FIELD_PROP { 21 FP_BORDERSTYLE, 22 FP_CURRENTVALUEINDICES, 23 FP_DISPLAY, 24 FP_HIDDEN, 25 FP_LINEWIDTH, 26 FP_RECT, 27 FP_VALUE 28 }; 29 30 class CJS_Field final : public CJS_Object { 31 public: 32 static uint32_t GetObjDefnID(); 33 static void DefineJSObjects(CFXJS_Engine* pEngine); 34 static void DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv, 35 CJS_DelayData* pData); 36 37 CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime); 38 ~CJS_Field() override; 39 40 bool AttachField(CJS_Document* pDocument, const WideString& csFieldName); 41 42 JS_STATIC_PROP(alignment, alignment, CJS_Field) 43 JS_STATIC_PROP(borderStyle, border_style, CJS_Field) 44 JS_STATIC_PROP(buttonAlignX, button_align_x, CJS_Field) 45 JS_STATIC_PROP(buttonAlignY, button_align_y, CJS_Field) 46 JS_STATIC_PROP(buttonFitBounds, button_fit_bounds, CJS_Field) 47 JS_STATIC_PROP(buttonPosition, button_position, CJS_Field) 48 JS_STATIC_PROP(buttonScaleHow, button_scale_how, CJS_Field) 49 JS_STATIC_PROP(ButtonScaleWhen, button_scale_when, CJS_Field) 50 JS_STATIC_PROP(calcOrderIndex, calc_order_index, CJS_Field) 51 JS_STATIC_PROP(charLimit, char_limit, CJS_Field) 52 JS_STATIC_PROP(comb, comb, CJS_Field) 53 JS_STATIC_PROP(commitOnSelChange, commit_on_sel_change, CJS_Field) 54 JS_STATIC_PROP(currentValueIndices, current_value_indices, CJS_Field) 55 JS_STATIC_PROP(defaultStyle, default_style, CJS_Field) 56 JS_STATIC_PROP(defaultValue, default_value, CJS_Field) 57 JS_STATIC_PROP(doNotScroll, do_not_scroll, CJS_Field) 58 JS_STATIC_PROP(doNotSpellCheck, do_not_spell_check, CJS_Field) 59 JS_STATIC_PROP(delay, delay, CJS_Field) 60 JS_STATIC_PROP(display, display, CJS_Field) 61 JS_STATIC_PROP(doc, doc, CJS_Field) 62 JS_STATIC_PROP(editable, editable, CJS_Field) 63 JS_STATIC_PROP(exportValues, export_values, CJS_Field) 64 JS_STATIC_PROP(fileSelect, file_select, CJS_Field) 65 JS_STATIC_PROP(fillColor, fill_color, CJS_Field) 66 JS_STATIC_PROP(hidden, hidden, CJS_Field) 67 JS_STATIC_PROP(highlight, highlight, CJS_Field) 68 JS_STATIC_PROP(lineWidth, line_width, CJS_Field) 69 JS_STATIC_PROP(multiline, multiline, CJS_Field) 70 JS_STATIC_PROP(multipleSelection, multiple_selection, CJS_Field) 71 JS_STATIC_PROP(name, name, CJS_Field) 72 JS_STATIC_PROP(numItems, num_items, CJS_Field) 73 JS_STATIC_PROP(page, page, CJS_Field) 74 JS_STATIC_PROP(password, password, CJS_Field) 75 JS_STATIC_PROP(print, print, CJS_Field) 76 JS_STATIC_PROP(radiosInUnison, radios_in_unison, CJS_Field) 77 JS_STATIC_PROP(readonly, readonly, CJS_Field) 78 JS_STATIC_PROP(rect, rect, CJS_Field) 79 JS_STATIC_PROP(required, required, CJS_Field) 80 JS_STATIC_PROP(richText, rich_text, CJS_Field) 81 JS_STATIC_PROP(richValue, rich_value, CJS_Field) 82 JS_STATIC_PROP(rotation, rotation, CJS_Field) 83 JS_STATIC_PROP(source, source, CJS_Field) 84 JS_STATIC_PROP(strokeColor, stroke_color, CJS_Field) 85 JS_STATIC_PROP(style, style, CJS_Field) 86 JS_STATIC_PROP(submitName, submit_name, CJS_Field) 87 JS_STATIC_PROP(textColor, text_color, CJS_Field) 88 JS_STATIC_PROP(textFont, text_font, CJS_Field) 89 JS_STATIC_PROP(textSize, text_size, CJS_Field) 90 JS_STATIC_PROP(type, type, CJS_Field) 91 JS_STATIC_PROP(userName, user_name, CJS_Field) 92 JS_STATIC_PROP(value, value, CJS_Field) 93 JS_STATIC_PROP(valueAsString, value_as_string, CJS_Field) 94 95 JS_STATIC_METHOD(browseForFileToSubmit, CJS_Field) 96 JS_STATIC_METHOD(buttonGetCaption, CJS_Field) 97 JS_STATIC_METHOD(buttonGetIcon, CJS_Field) 98 JS_STATIC_METHOD(buttonImportIcon, CJS_Field) 99 JS_STATIC_METHOD(buttonSetCaption, CJS_Field) 100 JS_STATIC_METHOD(buttonSetIcon, CJS_Field) 101 JS_STATIC_METHOD(checkThisBox, CJS_Field) 102 JS_STATIC_METHOD(clearItems, CJS_Field) 103 JS_STATIC_METHOD(defaultIsChecked, CJS_Field) 104 JS_STATIC_METHOD(deleteItemAt, CJS_Field) 105 JS_STATIC_METHOD(getArray, CJS_Field) 106 JS_STATIC_METHOD(getItemAt, CJS_Field) 107 JS_STATIC_METHOD(getLock, CJS_Field) 108 JS_STATIC_METHOD(insertItemAt, CJS_Field) 109 JS_STATIC_METHOD(isBoxChecked, CJS_Field) 110 JS_STATIC_METHOD(isDefaultChecked, CJS_Field) 111 JS_STATIC_METHOD(setAction, CJS_Field) 112 JS_STATIC_METHOD(setFocus, CJS_Field) 113 JS_STATIC_METHOD(setItems, CJS_Field) 114 JS_STATIC_METHOD(setLock, CJS_Field) 115 JS_STATIC_METHOD(signatureGetModifications, CJS_Field) 116 JS_STATIC_METHOD(signatureGetSeedValue, CJS_Field) 117 JS_STATIC_METHOD(signatureInfo, CJS_Field) 118 JS_STATIC_METHOD(signatureSetSeedValue, CJS_Field) 119 JS_STATIC_METHOD(signatureSign, CJS_Field) 120 JS_STATIC_METHOD(signatureValidate, CJS_Field) 121 122 CJS_Result get_text_color(CJS_Runtime* pRuntime); 123 CJS_Result set_text_color(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 124 125 private: 126 static uint32_t ObjDefnID; 127 static const char kName[]; 128 static const JSPropertySpec PropertySpecs[]; 129 static const JSMethodSpec MethodSpecs[]; 130 131 CJS_Result get_alignment(CJS_Runtime* pRuntime); 132 CJS_Result set_alignment(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 133 134 CJS_Result get_border_style(CJS_Runtime* pRuntime); 135 CJS_Result set_border_style(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 136 137 CJS_Result get_button_align_x(CJS_Runtime* pRuntime); 138 CJS_Result set_button_align_x(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 139 140 CJS_Result get_button_align_y(CJS_Runtime* pRuntime); 141 CJS_Result set_button_align_y(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 142 143 CJS_Result get_button_fit_bounds(CJS_Runtime* pRuntime); 144 CJS_Result set_button_fit_bounds(CJS_Runtime* pRuntime, 145 v8::Local<v8::Value> vp); 146 147 CJS_Result get_button_position(CJS_Runtime* pRuntime); 148 CJS_Result set_button_position(CJS_Runtime* pRuntime, 149 v8::Local<v8::Value> vp); 150 151 CJS_Result get_button_scale_how(CJS_Runtime* pRuntime); 152 CJS_Result set_button_scale_how(CJS_Runtime* pRuntime, 153 v8::Local<v8::Value> vp); 154 155 CJS_Result get_button_scale_when(CJS_Runtime* pRuntime); 156 CJS_Result set_button_scale_when(CJS_Runtime* pRuntime, 157 v8::Local<v8::Value> vp); 158 159 CJS_Result get_calc_order_index(CJS_Runtime* pRuntime); 160 CJS_Result set_calc_order_index(CJS_Runtime* pRuntime, 161 v8::Local<v8::Value> vp); 162 163 CJS_Result get_char_limit(CJS_Runtime* pRuntime); 164 CJS_Result set_char_limit(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 165 166 CJS_Result get_comb(CJS_Runtime* pRuntime); 167 CJS_Result set_comb(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 168 169 CJS_Result get_commit_on_sel_change(CJS_Runtime* pRuntime); 170 CJS_Result set_commit_on_sel_change(CJS_Runtime* pRuntime, 171 v8::Local<v8::Value> vp); 172 173 CJS_Result get_current_value_indices(CJS_Runtime* pRuntime); 174 CJS_Result set_current_value_indices(CJS_Runtime* pRuntime, 175 v8::Local<v8::Value> vp); 176 177 CJS_Result get_default_style(CJS_Runtime* pRuntime); 178 CJS_Result set_default_style(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 179 180 CJS_Result get_default_value(CJS_Runtime* pRuntime); 181 CJS_Result set_default_value(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 182 183 CJS_Result get_do_not_scroll(CJS_Runtime* pRuntime); 184 CJS_Result set_do_not_scroll(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 185 186 CJS_Result get_do_not_spell_check(CJS_Runtime* pRuntime); 187 CJS_Result set_do_not_spell_check(CJS_Runtime* pRuntime, 188 v8::Local<v8::Value> vp); 189 190 CJS_Result get_delay(CJS_Runtime* pRuntime); 191 CJS_Result set_delay(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 192 193 CJS_Result get_display(CJS_Runtime* pRuntime); 194 CJS_Result set_display(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 195 196 CJS_Result get_doc(CJS_Runtime* pRuntime); 197 CJS_Result set_doc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 198 199 CJS_Result get_editable(CJS_Runtime* pRuntime); 200 CJS_Result set_editable(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 201 202 CJS_Result get_export_values(CJS_Runtime* pRuntime); 203 CJS_Result set_export_values(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 204 205 CJS_Result get_file_select(CJS_Runtime* pRuntime); 206 CJS_Result set_file_select(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 207 208 CJS_Result get_fill_color(CJS_Runtime* pRuntime); 209 CJS_Result set_fill_color(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 210 211 CJS_Result get_hidden(CJS_Runtime* pRuntime); 212 CJS_Result set_hidden(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 213 214 CJS_Result get_highlight(CJS_Runtime* pRuntime); 215 CJS_Result set_highlight(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 216 217 CJS_Result get_line_width(CJS_Runtime* pRuntime); 218 CJS_Result set_line_width(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 219 220 CJS_Result get_multiline(CJS_Runtime* pRuntime); 221 CJS_Result set_multiline(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 222 223 CJS_Result get_multiple_selection(CJS_Runtime* pRuntime); 224 CJS_Result set_multiple_selection(CJS_Runtime* pRuntime, 225 v8::Local<v8::Value> vp); 226 227 CJS_Result get_name(CJS_Runtime* pRuntime); 228 CJS_Result set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 229 230 CJS_Result get_num_items(CJS_Runtime* pRuntime); 231 CJS_Result set_num_items(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 232 233 CJS_Result get_page(CJS_Runtime* pRuntime); 234 CJS_Result set_page(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 235 236 CJS_Result get_password(CJS_Runtime* pRuntime); 237 CJS_Result set_password(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 238 239 CJS_Result get_print(CJS_Runtime* pRuntime); 240 CJS_Result set_print(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 241 242 CJS_Result get_radios_in_unison(CJS_Runtime* pRuntime); 243 CJS_Result set_radios_in_unison(CJS_Runtime* pRuntime, 244 v8::Local<v8::Value> vp); 245 246 CJS_Result get_readonly(CJS_Runtime* pRuntime); 247 CJS_Result set_readonly(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 248 249 CJS_Result get_rect(CJS_Runtime* pRuntime); 250 CJS_Result set_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 251 252 CJS_Result get_required(CJS_Runtime* pRuntime); 253 CJS_Result set_required(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 254 255 CJS_Result get_rich_text(CJS_Runtime* pRuntime); 256 CJS_Result set_rich_text(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 257 258 CJS_Result get_rich_value(CJS_Runtime* pRuntime); 259 CJS_Result set_rich_value(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 260 261 CJS_Result get_rotation(CJS_Runtime* pRuntime); 262 CJS_Result set_rotation(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 263 264 CJS_Result get_stroke_color(CJS_Runtime* pRuntime); 265 CJS_Result set_stroke_color(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 266 267 CJS_Result get_style(CJS_Runtime* pRuntime); 268 CJS_Result set_style(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 269 270 CJS_Result get_submit_name(CJS_Runtime* pRuntime); 271 CJS_Result set_submit_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 272 273 CJS_Result get_text_font(CJS_Runtime* pRuntime); 274 CJS_Result set_text_font(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 275 276 CJS_Result get_text_size(CJS_Runtime* pRuntime); 277 CJS_Result set_text_size(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 278 279 CJS_Result get_type(CJS_Runtime* pRuntime); 280 CJS_Result set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 281 282 CJS_Result get_user_name(CJS_Runtime* pRuntime); 283 CJS_Result set_user_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 284 285 CJS_Result get_value(CJS_Runtime* pRuntime); 286 CJS_Result set_value(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 287 288 CJS_Result get_value_as_string(CJS_Runtime* pRuntime); 289 CJS_Result set_value_as_string(CJS_Runtime* pRuntime, 290 v8::Local<v8::Value> vp); 291 292 CJS_Result get_source(CJS_Runtime* pRuntime); 293 CJS_Result set_source(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp); 294 295 CJS_Result browseForFileToSubmit( 296 CJS_Runtime* pRuntime, 297 const std::vector<v8::Local<v8::Value>>& params); 298 CJS_Result buttonGetCaption(CJS_Runtime* pRuntime, 299 const std::vector<v8::Local<v8::Value>>& params); 300 CJS_Result buttonGetIcon(CJS_Runtime* pRuntime, 301 const std::vector<v8::Local<v8::Value>>& params); 302 CJS_Result buttonImportIcon(CJS_Runtime* pRuntime, 303 const std::vector<v8::Local<v8::Value>>& params); 304 CJS_Result buttonSetCaption(CJS_Runtime* pRuntime, 305 const std::vector<v8::Local<v8::Value>>& params); 306 CJS_Result buttonSetIcon(CJS_Runtime* pRuntime, 307 const std::vector<v8::Local<v8::Value>>& params); 308 CJS_Result checkThisBox(CJS_Runtime* pRuntime, 309 const std::vector<v8::Local<v8::Value>>& params); 310 CJS_Result clearItems(CJS_Runtime* pRuntime, 311 const std::vector<v8::Local<v8::Value>>& params); 312 CJS_Result defaultIsChecked(CJS_Runtime* pRuntime, 313 const std::vector<v8::Local<v8::Value>>& params); 314 CJS_Result deleteItemAt(CJS_Runtime* pRuntime, 315 const std::vector<v8::Local<v8::Value>>& params); 316 CJS_Result getArray(CJS_Runtime* pRuntime, 317 const std::vector<v8::Local<v8::Value>>& params); 318 CJS_Result getItemAt(CJS_Runtime* pRuntime, 319 const std::vector<v8::Local<v8::Value>>& params); 320 CJS_Result getLock(CJS_Runtime* pRuntime, 321 const std::vector<v8::Local<v8::Value>>& params); 322 CJS_Result insertItemAt(CJS_Runtime* pRuntime, 323 const std::vector<v8::Local<v8::Value>>& params); 324 CJS_Result isBoxChecked(CJS_Runtime* pRuntime, 325 const std::vector<v8::Local<v8::Value>>& params); 326 CJS_Result isDefaultChecked(CJS_Runtime* pRuntime, 327 const std::vector<v8::Local<v8::Value>>& params); 328 CJS_Result setAction(CJS_Runtime* pRuntime, 329 const std::vector<v8::Local<v8::Value>>& params); 330 CJS_Result setFocus(CJS_Runtime* pRuntime, 331 const std::vector<v8::Local<v8::Value>>& params); 332 CJS_Result setItems(CJS_Runtime* pRuntime, 333 const std::vector<v8::Local<v8::Value>>& params); 334 CJS_Result setLock(CJS_Runtime* pRuntime, 335 const std::vector<v8::Local<v8::Value>>& params); 336 CJS_Result signatureGetModifications( 337 CJS_Runtime* pRuntime, 338 const std::vector<v8::Local<v8::Value>>& params); 339 CJS_Result signatureGetSeedValue( 340 CJS_Runtime* pRuntime, 341 const std::vector<v8::Local<v8::Value>>& params); 342 CJS_Result signatureInfo(CJS_Runtime* pRuntime, 343 const std::vector<v8::Local<v8::Value>>& params); 344 CJS_Result signatureSetSeedValue( 345 CJS_Runtime* pRuntime, 346 const std::vector<v8::Local<v8::Value>>& params); 347 CJS_Result signatureSign(CJS_Runtime* pRuntime, 348 const std::vector<v8::Local<v8::Value>>& params); 349 CJS_Result signatureValidate(CJS_Runtime* pRuntime, 350 const std::vector<v8::Local<v8::Value>>& params); 351 352 std::vector<CPDF_FormField*> GetFormFields() const; 353 CPDF_FormField* GetFirstFormField() const; 354 CPDF_FormControl* GetSmartFieldControl(CPDF_FormField* pFormField); 355 356 void SetDelay(bool bDelay); 357 void AddDelay_Int(FIELD_PROP prop, int32_t n); 358 void AddDelay_Bool(FIELD_PROP prop, bool b); 359 void AddDelay_String(FIELD_PROP prop, const ByteString& str); 360 void AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect); 361 void AddDelay_WordArray(FIELD_PROP prop, const std::vector<uint32_t>& array); 362 void AddDelay_WideStringArray(FIELD_PROP prop, 363 const std::vector<WideString>& array); 364 void DoDelay(); 365 366 ObservedPtr<CJS_Document> m_pJSDoc; 367 ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv; 368 WideString m_FieldName; 369 int m_nFormControlIndex = -1; 370 bool m_bCanSet = false; 371 bool m_bDelay = false; 372 }; 373 374 #endif // FXJS_CJS_FIELD_H_ 375