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