| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef FPDFSDK_JAVASCRIPT_FIELD_H_ | 7 #ifndef FPDFSDK_JAVASCRIPT_FIELD_H_ |
| 8 #define FPDFSDK_JAVASCRIPT_FIELD_H_ | 8 #define FPDFSDK_JAVASCRIPT_FIELD_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "core/fxcrt/cfx_observable.h" | 13 #include "core/fxcrt/cfx_observable.h" |
| 14 #include "fpdfsdk/cpdfsdk_document.h" | 14 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 15 #include "fpdfsdk/javascript/JS_Define.h" | 15 #include "fpdfsdk/javascript/JS_Define.h" |
| 16 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" // For CPWL_Color. | 16 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" // For CPWL_Color. |
| 17 | 17 |
| 18 class CPDFSDK_Widget; | 18 class CPDFSDK_Widget; |
| 19 class Document; | 19 class Document; |
| 20 | 20 |
| 21 enum FIELD_PROP { | 21 enum FIELD_PROP { |
| 22 FP_ALIGNMENT, | 22 FP_ALIGNMENT, |
| 23 FP_BORDERSTYLE, | 23 FP_BORDERSTYLE, |
| 24 FP_BUTTONALIGNX, | 24 FP_BUTTONALIGNX, |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 CFX_WideString& sError); | 270 CFX_WideString& sError); |
| 271 FX_BOOL signatureSign(IJS_Context* cc, | 271 FX_BOOL signatureSign(IJS_Context* cc, |
| 272 const std::vector<CJS_Value>& params, | 272 const std::vector<CJS_Value>& params, |
| 273 CJS_Value& vRet, | 273 CJS_Value& vRet, |
| 274 CFX_WideString& sError); | 274 CFX_WideString& sError); |
| 275 FX_BOOL signatureValidate(IJS_Context* cc, | 275 FX_BOOL signatureValidate(IJS_Context* cc, |
| 276 const std::vector<CJS_Value>& params, | 276 const std::vector<CJS_Value>& params, |
| 277 CJS_Value& vRet, | 277 CJS_Value& vRet, |
| 278 CFX_WideString& sError); | 278 CFX_WideString& sError); |
| 279 | 279 |
| 280 static void SetAlignment(CPDFSDK_Document* pDocument, | 280 static void SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 281 const CFX_WideString& swFieldName, | 281 const CFX_WideString& swFieldName, |
| 282 int nControlIndex, | 282 int nControlIndex, |
| 283 const CFX_ByteString& string); | 283 const CFX_ByteString& string); |
| 284 static void SetBorderStyle(CPDFSDK_Document* pDocument, | 284 static void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 285 const CFX_WideString& swFieldName, | 285 const CFX_WideString& swFieldName, |
| 286 int nControlIndex, | 286 int nControlIndex, |
| 287 const CFX_ByteString& string); | 287 const CFX_ByteString& string); |
| 288 static void SetButtonAlignX(CPDFSDK_Document* pDocument, | 288 static void SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 289 const CFX_WideString& swFieldName, | 289 const CFX_WideString& swFieldName, |
| 290 int nControlIndex, | 290 int nControlIndex, |
| 291 int number); | 291 int number); |
| 292 static void SetButtonAlignY(CPDFSDK_Document* pDocument, | 292 static void SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 293 const CFX_WideString& swFieldName, | 293 const CFX_WideString& swFieldName, |
| 294 int nControlIndex, | 294 int nControlIndex, |
| 295 int number); | 295 int number); |
| 296 static void SetButtonFitBounds(CPDFSDK_Document* pDocument, | 296 static void SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 297 const CFX_WideString& swFieldName, | 297 const CFX_WideString& swFieldName, |
| 298 int nControlIndex, | 298 int nControlIndex, |
| 299 bool b); | 299 bool b); |
| 300 static void SetButtonPosition(CPDFSDK_Document* pDocument, | 300 static void SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 301 const CFX_WideString& swFieldName, | 301 const CFX_WideString& swFieldName, |
| 302 int nControlIndex, | 302 int nControlIndex, |
| 303 int number); | 303 int number); |
| 304 static void SetButtonScaleHow(CPDFSDK_Document* pDocument, | 304 static void SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 305 const CFX_WideString& swFieldName, | 305 const CFX_WideString& swFieldName, |
| 306 int nControlIndex, | 306 int nControlIndex, |
| 307 int number); | 307 int number); |
| 308 static void SetButtonScaleWhen(CPDFSDK_Document* pDocument, | 308 static void SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 309 const CFX_WideString& swFieldName, | 309 const CFX_WideString& swFieldName, |
| 310 int nControlIndex, | 310 int nControlIndex, |
| 311 int number); | 311 int number); |
| 312 static void SetCalcOrderIndex(CPDFSDK_Document* pDocument, | 312 static void SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 313 const CFX_WideString& swFieldName, | 313 const CFX_WideString& swFieldName, |
| 314 int nControlIndex, | 314 int nControlIndex, |
| 315 int number); | 315 int number); |
| 316 static void SetCharLimit(CPDFSDK_Document* pDocument, | 316 static void SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 317 const CFX_WideString& swFieldName, | 317 const CFX_WideString& swFieldName, |
| 318 int nControlIndex, | 318 int nControlIndex, |
| 319 int number); | 319 int number); |
| 320 static void SetComb(CPDFSDK_Document* pDocument, | 320 static void SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 321 const CFX_WideString& swFieldName, | 321 const CFX_WideString& swFieldName, |
| 322 int nControlIndex, | 322 int nControlIndex, |
| 323 bool b); | 323 bool b); |
| 324 static void SetCommitOnSelChange(CPDFSDK_Document* pDocument, | 324 static void SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 325 const CFX_WideString& swFieldName, | 325 const CFX_WideString& swFieldName, |
| 326 int nControlIndex, | 326 int nControlIndex, |
| 327 bool b); | 327 bool b); |
| 328 static void SetCurrentValueIndices(CPDFSDK_Document* pDocument, | 328 static void SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 329 const CFX_WideString& swFieldName, | 329 const CFX_WideString& swFieldName, |
| 330 int nControlIndex, | 330 int nControlIndex, |
| 331 const std::vector<uint32_t>& array); | 331 const std::vector<uint32_t>& array); |
| 332 static void SetDefaultStyle(CPDFSDK_Document* pDocument, | 332 static void SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 333 const CFX_WideString& swFieldName, | 333 const CFX_WideString& swFieldName, |
| 334 int nControlIndex); | 334 int nControlIndex); |
| 335 static void SetDefaultValue(CPDFSDK_Document* pDocument, | 335 static void SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 336 const CFX_WideString& swFieldName, | 336 const CFX_WideString& swFieldName, |
| 337 int nControlIndex, | 337 int nControlIndex, |
| 338 const CFX_WideString& string); | 338 const CFX_WideString& string); |
| 339 static void SetDoNotScroll(CPDFSDK_Document* pDocument, | 339 static void SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 340 const CFX_WideString& swFieldName, | 340 const CFX_WideString& swFieldName, |
| 341 int nControlIndex, | 341 int nControlIndex, |
| 342 bool b); | 342 bool b); |
| 343 static void SetDisplay(CPDFSDK_Document* pDocument, | 343 static void SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 344 const CFX_WideString& swFieldName, | 344 const CFX_WideString& swFieldName, |
| 345 int nControlIndex, | 345 int nControlIndex, |
| 346 int number); | 346 int number); |
| 347 static void SetFillColor(CPDFSDK_Document* pDocument, | 347 static void SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 348 const CFX_WideString& swFieldName, | 348 const CFX_WideString& swFieldName, |
| 349 int nControlIndex, | 349 int nControlIndex, |
| 350 const CPWL_Color& color); | 350 const CPWL_Color& color); |
| 351 static void SetHidden(CPDFSDK_Document* pDocument, | 351 static void SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 352 const CFX_WideString& swFieldName, | 352 const CFX_WideString& swFieldName, |
| 353 int nControlIndex, | 353 int nControlIndex, |
| 354 bool b); | 354 bool b); |
| 355 static void SetHighlight(CPDFSDK_Document* pDocument, | 355 static void SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 356 const CFX_WideString& swFieldName, | 356 const CFX_WideString& swFieldName, |
| 357 int nControlIndex, | 357 int nControlIndex, |
| 358 const CFX_ByteString& string); | 358 const CFX_ByteString& string); |
| 359 static void SetLineWidth(CPDFSDK_Document* pDocument, | 359 static void SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 360 const CFX_WideString& swFieldName, | 360 const CFX_WideString& swFieldName, |
| 361 int nControlIndex, | 361 int nControlIndex, |
| 362 int number); | 362 int number); |
| 363 static void SetMultiline(CPDFSDK_Document* pDocument, | 363 static void SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 364 const CFX_WideString& swFieldName, | 364 const CFX_WideString& swFieldName, |
| 365 int nControlIndex, | 365 int nControlIndex, |
| 366 bool b); | 366 bool b); |
| 367 static void SetMultipleSelection(CPDFSDK_Document* pDocument, | 367 static void SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 368 const CFX_WideString& swFieldName, | 368 const CFX_WideString& swFieldName, |
| 369 int nControlIndex, | 369 int nControlIndex, |
| 370 bool b); | 370 bool b); |
| 371 static void SetPassword(CPDFSDK_Document* pDocument, | 371 static void SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 372 const CFX_WideString& swFieldName, | 372 const CFX_WideString& swFieldName, |
| 373 int nControlIndex, | 373 int nControlIndex, |
| 374 bool b); | 374 bool b); |
| 375 static void SetRect(CPDFSDK_Document* pDocument, | 375 static void SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 376 const CFX_WideString& swFieldName, | 376 const CFX_WideString& swFieldName, |
| 377 int nControlIndex, | 377 int nControlIndex, |
| 378 const CFX_FloatRect& rect); | 378 const CFX_FloatRect& rect); |
| 379 static void SetRotation(CPDFSDK_Document* pDocument, | 379 static void SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 380 const CFX_WideString& swFieldName, | 380 const CFX_WideString& swFieldName, |
| 381 int nControlIndex, | 381 int nControlIndex, |
| 382 int number); | 382 int number); |
| 383 static void SetStrokeColor(CPDFSDK_Document* pDocument, | 383 static void SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 384 const CFX_WideString& swFieldName, | 384 const CFX_WideString& swFieldName, |
| 385 int nControlIndex, | 385 int nControlIndex, |
| 386 const CPWL_Color& color); | 386 const CPWL_Color& color); |
| 387 static void SetStyle(CPDFSDK_Document* pDocument, | 387 static void SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 388 const CFX_WideString& swFieldName, | 388 const CFX_WideString& swFieldName, |
| 389 int nControlIndex, | 389 int nControlIndex, |
| 390 const CFX_ByteString& string); | 390 const CFX_ByteString& string); |
| 391 static void SetTextColor(CPDFSDK_Document* pDocument, | 391 static void SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 392 const CFX_WideString& swFieldName, | 392 const CFX_WideString& swFieldName, |
| 393 int nControlIndex, | 393 int nControlIndex, |
| 394 const CPWL_Color& color); | 394 const CPWL_Color& color); |
| 395 static void SetTextFont(CPDFSDK_Document* pDocument, | 395 static void SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 396 const CFX_WideString& swFieldName, | 396 const CFX_WideString& swFieldName, |
| 397 int nControlIndex, | 397 int nControlIndex, |
| 398 const CFX_ByteString& string); | 398 const CFX_ByteString& string); |
| 399 static void SetTextSize(CPDFSDK_Document* pDocument, | 399 static void SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 400 const CFX_WideString& swFieldName, | 400 const CFX_WideString& swFieldName, |
| 401 int nControlIndex, | 401 int nControlIndex, |
| 402 int number); | 402 int number); |
| 403 static void SetUserName(CPDFSDK_Document* pDocument, | 403 static void SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 404 const CFX_WideString& swFieldName, | 404 const CFX_WideString& swFieldName, |
| 405 int nControlIndex, | 405 int nControlIndex, |
| 406 const CFX_WideString& string); | 406 const CFX_WideString& string); |
| 407 static void SetValue(CPDFSDK_Document* pDocument, | 407 static void SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 408 const CFX_WideString& swFieldName, | 408 const CFX_WideString& swFieldName, |
| 409 int nControlIndex, | 409 int nControlIndex, |
| 410 const std::vector<CFX_WideString>& strArray); | 410 const std::vector<CFX_WideString>& strArray); |
| 411 | 411 |
| 412 static void AddField(CPDFSDK_Document* pDocument, | 412 static void AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 413 int nPageIndex, | 413 int nPageIndex, |
| 414 int nFieldType, | 414 int nFieldType, |
| 415 const CFX_WideString& sName, | 415 const CFX_WideString& sName, |
| 416 const CFX_FloatRect& rcCoords); | 416 const CFX_FloatRect& rcCoords); |
| 417 | 417 |
| 418 static void UpdateFormField(CPDFSDK_Document* pDocument, | 418 static void UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 419 CPDF_FormField* pFormField, | 419 CPDF_FormField* pFormField, |
| 420 FX_BOOL bChangeMark, | 420 FX_BOOL bChangeMark, |
| 421 FX_BOOL bResetAP, | 421 FX_BOOL bResetAP, |
| 422 FX_BOOL bRefresh); | 422 FX_BOOL bRefresh); |
| 423 static void UpdateFormControl(CPDFSDK_Document* pDocument, | 423 static void UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 424 CPDF_FormControl* pFormControl, | 424 CPDF_FormControl* pFormControl, |
| 425 FX_BOOL bChangeMark, | 425 FX_BOOL bChangeMark, |
| 426 FX_BOOL bResetAP, | 426 FX_BOOL bResetAP, |
| 427 FX_BOOL bRefresh); | 427 FX_BOOL bRefresh); |
| 428 | 428 |
| 429 static CPDFSDK_Widget* GetWidget(CPDFSDK_Document* pDocument, | 429 static CPDFSDK_Widget* GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 430 CPDF_FormControl* pFormControl, | 430 CPDF_FormControl* pFormControl, |
| 431 bool createIfNeeded); | 431 bool createIfNeeded); |
| 432 static std::vector<CPDF_FormField*> GetFormFields( | 432 static std::vector<CPDF_FormField*> GetFormFields( |
| 433 CPDFSDK_Document* pDocument, | 433 CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 434 const CFX_WideString& csFieldName); | 434 const CFX_WideString& csFieldName); |
| 435 | 435 |
| 436 static void DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData); | 436 static void DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 437 CJS_DelayData* pData); |
| 437 | 438 |
| 438 FX_BOOL AttachField(Document* pDocument, const CFX_WideString& csFieldName); | 439 FX_BOOL AttachField(Document* pDocument, const CFX_WideString& csFieldName); |
| 439 void SetDelay(FX_BOOL bDelay); | 440 void SetDelay(FX_BOOL bDelay); |
| 440 | 441 |
| 441 protected: | 442 protected: |
| 442 void ParseFieldName(const std::wstring& strFieldNameParsed, | 443 void ParseFieldName(const std::wstring& strFieldNameParsed, |
| 443 std::wstring& strFieldName, | 444 std::wstring& strFieldName, |
| 444 int& iControlNo); | 445 int& iControlNo); |
| 445 std::vector<CPDF_FormField*> GetFormFields( | 446 std::vector<CPDF_FormField*> GetFormFields( |
| 446 const CFX_WideString& csFieldName) const; | 447 const CFX_WideString& csFieldName) const; |
| 447 CPDF_FormControl* GetSmartFieldControl(CPDF_FormField* pFormField); | 448 CPDF_FormControl* GetSmartFieldControl(CPDF_FormField* pFormField); |
| 448 FX_BOOL ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel); | 449 FX_BOOL ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel); |
| 449 | 450 |
| 450 void AddDelay_Int(FIELD_PROP prop, int32_t n); | 451 void AddDelay_Int(FIELD_PROP prop, int32_t n); |
| 451 void AddDelay_Bool(FIELD_PROP prop, bool b); | 452 void AddDelay_Bool(FIELD_PROP prop, bool b); |
| 452 void AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string); | 453 void AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string); |
| 453 void AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string); | 454 void AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string); |
| 454 void AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect); | 455 void AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect); |
| 455 void AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color); | 456 void AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color); |
| 456 void AddDelay_WordArray(FIELD_PROP prop, const std::vector<uint32_t>& array); | 457 void AddDelay_WordArray(FIELD_PROP prop, const std::vector<uint32_t>& array); |
| 457 void AddDelay_WideStringArray(FIELD_PROP prop, | 458 void AddDelay_WideStringArray(FIELD_PROP prop, |
| 458 const std::vector<CFX_WideString>& array); | 459 const std::vector<CFX_WideString>& array); |
| 459 | 460 |
| 460 void DoDelay(); | 461 void DoDelay(); |
| 461 | 462 |
| 462 public: | 463 public: |
| 463 Document* m_pJSDoc; | 464 Document* m_pJSDoc; |
| 464 CPDFSDK_Document::ObservedPtr m_pDocument; | 465 CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; |
| 465 CFX_WideString m_FieldName; | 466 CFX_WideString m_FieldName; |
| 466 int m_nFormControlIndex; | 467 int m_nFormControlIndex; |
| 467 FX_BOOL m_bCanSet; | 468 FX_BOOL m_bCanSet; |
| 468 FX_BOOL m_bDelay; | 469 FX_BOOL m_bDelay; |
| 469 }; | 470 }; |
| 470 | 471 |
| 471 class CJS_Field : public CJS_Object { | 472 class CJS_Field : public CJS_Object { |
| 472 public: | 473 public: |
| 473 explicit CJS_Field(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} | 474 explicit CJS_Field(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} |
| 474 ~CJS_Field() override {} | 475 ~CJS_Field() override {} |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 JS_STATIC_METHOD(setLock, Field); | 552 JS_STATIC_METHOD(setLock, Field); |
| 552 JS_STATIC_METHOD(signatureGetModifications, Field); | 553 JS_STATIC_METHOD(signatureGetModifications, Field); |
| 553 JS_STATIC_METHOD(signatureGetSeedValue, Field); | 554 JS_STATIC_METHOD(signatureGetSeedValue, Field); |
| 554 JS_STATIC_METHOD(signatureInfo, Field); | 555 JS_STATIC_METHOD(signatureInfo, Field); |
| 555 JS_STATIC_METHOD(signatureSetSeedValue, Field); | 556 JS_STATIC_METHOD(signatureSetSeedValue, Field); |
| 556 JS_STATIC_METHOD(signatureSign, Field); | 557 JS_STATIC_METHOD(signatureSign, Field); |
| 557 JS_STATIC_METHOD(signatureValidate, Field); | 558 JS_STATIC_METHOD(signatureValidate, Field); |
| 558 }; | 559 }; |
| 559 | 560 |
| 560 #endif // FPDFSDK_JAVASCRIPT_FIELD_H_ | 561 #endif // FPDFSDK_JAVASCRIPT_FIELD_H_ |
| OLD | NEW |