OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "fpdfsdk/cpdfsdk_interform.h" | 7 #include "fpdfsdk/cpdfsdk_interform.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "core/fpdfapi/page/cpdf_page.h" | 13 #include "core/fpdfapi/page/cpdf_page.h" |
14 #include "core/fpdfapi/parser/cfdf_document.h" | 14 #include "core/fpdfapi/parser/cfdf_document.h" |
15 #include "core/fpdfapi/parser/cpdf_array.h" | 15 #include "core/fpdfapi/parser/cpdf_array.h" |
16 #include "core/fpdfapi/parser/cpdf_document.h" | 16 #include "core/fpdfapi/parser/cpdf_document.h" |
17 #include "core/fpdfapi/parser/cpdf_stream.h" | 17 #include "core/fpdfapi/parser/cpdf_stream.h" |
18 #include "core/fpdfdoc/cpdf_actionfields.h" | 18 #include "core/fpdfdoc/cpdf_actionfields.h" |
19 #include "core/fpdfdoc/cpdf_interform.h" | 19 #include "core/fpdfdoc/cpdf_interform.h" |
20 #include "core/fxge/cfx_graphstatedata.h" | 20 #include "core/fxge/cfx_graphstatedata.h" |
21 #include "core/fxge/cfx_pathdata.h" | 21 #include "core/fxge/cfx_pathdata.h" |
22 #include "core/fxge/cfx_renderdevice.h" | 22 #include "core/fxge/cfx_renderdevice.h" |
23 #include "fpdfsdk/cba_annotiterator.h" | 23 #include "fpdfsdk/cba_annotiterator.h" |
24 #include "fpdfsdk/cpdfsdk_annot.h" | 24 #include "fpdfsdk/cpdfsdk_annot.h" |
25 #include "fpdfsdk/cpdfsdk_document.h" | |
26 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 25 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
27 #include "fpdfsdk/cpdfsdk_pageview.h" | 26 #include "fpdfsdk/cpdfsdk_pageview.h" |
28 #include "fpdfsdk/cpdfsdk_widget.h" | 27 #include "fpdfsdk/cpdfsdk_widget.h" |
29 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 28 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
30 #include "fpdfsdk/fsdk_actionhandler.h" | 29 #include "fpdfsdk/fsdk_actionhandler.h" |
31 #include "fpdfsdk/fsdk_define.h" | 30 #include "fpdfsdk/fsdk_define.h" |
32 #include "fpdfsdk/fxedit/fxet_edit.h" | 31 #include "fpdfsdk/fxedit/fxet_edit.h" |
33 #include "fpdfsdk/ipdfsdk_annothandler.h" | 32 #include "fpdfsdk/ipdfsdk_annothandler.h" |
34 #include "fpdfsdk/javascript/ijs_context.h" | 33 #include "fpdfsdk/javascript/ijs_context.h" |
35 #include "fpdfsdk/javascript/ijs_runtime.h" | 34 #include "fpdfsdk/javascript/ijs_runtime.h" |
36 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 35 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
37 #include "third_party/base/stl_util.h" | 36 #include "third_party/base/stl_util.h" |
38 | 37 |
39 #ifdef PDF_ENABLE_XFA | 38 #ifdef PDF_ENABLE_XFA |
40 #include "fpdfsdk/cpdfsdk_xfawidget.h" | 39 #include "fpdfsdk/cpdfsdk_xfawidget.h" |
41 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" | 40 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" |
42 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" | 41 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
43 #include "xfa/fxfa/cxfa_eventparam.h" | 42 #include "xfa/fxfa/cxfa_eventparam.h" |
44 #include "xfa/fxfa/xfa_ffdocview.h" | 43 #include "xfa/fxfa/xfa_ffdocview.h" |
45 #include "xfa/fxfa/xfa_ffwidget.h" | 44 #include "xfa/fxfa/xfa_ffwidget.h" |
46 #include "xfa/fxfa/xfa_ffwidgethandler.h" | 45 #include "xfa/fxfa/xfa_ffwidgethandler.h" |
47 #endif // PDF_ENABLE_XFA | 46 #endif // PDF_ENABLE_XFA |
48 | 47 |
49 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv) | 48 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv) |
50 : m_pFormFillEnv(pFormFillEnv), | 49 : m_pFormFillEnv(pFormFillEnv), |
51 m_pInterForm(new CPDF_InterForm( | 50 m_pInterForm(new CPDF_InterForm(m_pFormFillEnv->GetPDFDocument())), |
52 m_pFormFillEnv->GetSDKDocument()->GetPDFDocument())), | |
53 #ifdef PDF_ENABLE_XFA | 51 #ifdef PDF_ENABLE_XFA |
54 m_bXfaCalculate(TRUE), | 52 m_bXfaCalculate(TRUE), |
55 m_bXfaValidationsEnabled(TRUE), | 53 m_bXfaValidationsEnabled(TRUE), |
56 #endif // PDF_ENABLE_XFA | 54 #endif // PDF_ENABLE_XFA |
57 m_bCalculate(TRUE), | 55 m_bCalculate(TRUE), |
58 m_bBusy(FALSE), | 56 m_bBusy(FALSE), |
59 m_iHighlightAlpha(0) { | 57 m_iHighlightAlpha(0) { |
60 m_pInterForm->SetFormNotify(this); | 58 m_pInterForm->SetFormNotify(this); |
61 for (int i = 0; i < kNumFieldTypes; ++i) | 59 for (int i = 0; i < kNumFieldTypes; ++i) |
62 m_bNeedHightlight[i] = FALSE; | 60 m_bNeedHightlight[i] = FALSE; |
(...skipping 29 matching lines...) Expand all Loading... |
92 CPDFSDK_Widget* pWidget = nullptr; | 90 CPDFSDK_Widget* pWidget = nullptr; |
93 const auto it = m_Map.find(pControl); | 91 const auto it = m_Map.find(pControl); |
94 if (it != m_Map.end()) | 92 if (it != m_Map.end()) |
95 pWidget = it->second; | 93 pWidget = it->second; |
96 if (pWidget) | 94 if (pWidget) |
97 return pWidget; | 95 return pWidget; |
98 if (!createIfNeeded) | 96 if (!createIfNeeded) |
99 return nullptr; | 97 return nullptr; |
100 | 98 |
101 CPDF_Dictionary* pControlDict = pControl->GetWidget(); | 99 CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
102 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 100 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
103 CPDFSDK_PageView* pPage = nullptr; | 101 CPDFSDK_PageView* pPage = nullptr; |
104 | 102 |
105 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) { | 103 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) { |
106 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); | 104 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
107 if (nPageIndex >= 0) | 105 if (nPageIndex >= 0) |
108 pPage = m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageIndex); | 106 pPage = m_pFormFillEnv->GetPageView(nPageIndex); |
109 } | 107 } |
110 | 108 |
111 if (!pPage) { | 109 if (!pPage) { |
112 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); | 110 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
113 if (nPageIndex >= 0) | 111 if (nPageIndex >= 0) |
114 pPage = m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageIndex); | 112 pPage = m_pFormFillEnv->GetPageView(nPageIndex); |
115 } | 113 } |
116 | 114 |
117 if (!pPage) | 115 if (!pPage) |
118 return nullptr; | 116 return nullptr; |
119 | 117 |
120 return static_cast<CPDFSDK_Widget*>(pPage->GetAnnotByDict(pControlDict)); | 118 return static_cast<CPDFSDK_Widget*>(pPage->GetAnnotByDict(pControlDict)); |
121 } | 119 } |
122 | 120 |
123 void CPDFSDK_InterForm::GetWidgets( | 121 void CPDFSDK_InterForm::GetWidgets( |
124 const CFX_WideString& sFieldName, | 122 const CFX_WideString& sFieldName, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 327 } |
330 } | 328 } |
331 | 329 |
332 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { | 330 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { |
333 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 331 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
334 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); | 332 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
335 ASSERT(pFormCtrl); | 333 ASSERT(pFormCtrl); |
336 | 334 |
337 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { | 335 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { |
338 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 336 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
339 CPDFSDK_PageView* pPageView = | 337 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); |
340 m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); | |
341 FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox( | 338 FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox( |
342 pPageView, pWidget); | 339 pPageView, pWidget); |
343 | 340 |
344 m_pFormFillEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, | 341 m_pFormFillEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
345 rcBBox.bottom); | 342 rcBBox.bottom); |
346 } | 343 } |
347 } | 344 } |
348 } | 345 } |
349 | 346 |
350 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, | 347 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 nBufSize = fdfEncodedData.GetLength(); | 503 nBufSize = fdfEncodedData.GetLength(); |
507 pBuf = FX_Alloc(uint8_t, nBufSize); | 504 pBuf = FX_Alloc(uint8_t, nBufSize); |
508 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); | 505 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); |
509 return TRUE; | 506 return TRUE; |
510 } | 507 } |
511 | 508 |
512 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( | 509 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( |
513 const std::vector<CPDF_FormField*>& fields, | 510 const std::vector<CPDF_FormField*>& fields, |
514 bool bIncludeOrExclude, | 511 bool bIncludeOrExclude, |
515 CFX_ByteTextBuf& textBuf) { | 512 CFX_ByteTextBuf& textBuf) { |
516 std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( | 513 std::unique_ptr<CFDF_Document> pFDF( |
517 m_pFormFillEnv->GetSDKDocument()->GetPath().AsStringC(), fields, | 514 m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath().AsStringC(), |
518 bIncludeOrExclude, false)); | 515 fields, bIncludeOrExclude, false)); |
519 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; | 516 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; |
520 } | 517 } |
521 | 518 |
522 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( | 519 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
523 const CFX_WideString& sFileExt) { | 520 const CFX_WideString& sFileExt) { |
524 return L""; | 521 return L""; |
525 } | 522 } |
526 | 523 |
527 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, | 524 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
528 FX_BOOL bUrlEncoded) { | 525 FX_BOOL bUrlEncoded) { |
529 if (sDestination.IsEmpty()) | 526 if (sDestination.IsEmpty()) |
530 return FALSE; | 527 return FALSE; |
531 | 528 |
532 if (!m_pFormFillEnv || !m_pFormFillEnv->GetSDKDocument() || !m_pInterForm) | 529 if (!m_pFormFillEnv || !m_pInterForm) |
533 return FALSE; | 530 return FALSE; |
534 | 531 |
535 CFX_WideString wsPDFFilePath = m_pFormFillEnv->GetSDKDocument()->GetPath(); | 532 CFX_WideString wsPDFFilePath = m_pFormFillEnv->JS_docGetFilePath(); |
536 CFDF_Document* pFDFDoc = | 533 CFDF_Document* pFDFDoc = |
537 m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); | 534 m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); |
538 if (!pFDFDoc) | 535 if (!pFDFDoc) |
539 return FALSE; | 536 return FALSE; |
540 | 537 |
541 CFX_ByteTextBuf FdfBuffer; | 538 CFX_ByteTextBuf FdfBuffer; |
542 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); | 539 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); |
543 delete pFDFDoc; | 540 delete pFDFDoc; |
544 if (!bRet) | 541 if (!bRet) |
545 return FALSE; | 542 return FALSE; |
546 | 543 |
547 uint8_t* pBuffer = FdfBuffer.GetBuffer(); | 544 uint8_t* pBuffer = FdfBuffer.GetBuffer(); |
548 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); | 545 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); |
549 | 546 |
550 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) | 547 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) |
551 return FALSE; | 548 return FALSE; |
552 | 549 |
553 m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); | 550 m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); |
554 | 551 |
555 if (bUrlEncoded) | 552 if (bUrlEncoded) |
556 FX_Free(pBuffer); | 553 FX_Free(pBuffer); |
557 | 554 |
558 return TRUE; | 555 return TRUE; |
559 } | 556 } |
560 | 557 |
561 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { | 558 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { |
562 CFDF_Document* pFDF = m_pInterForm->ExportToFDF( | 559 CFDF_Document* pFDF = m_pInterForm->ExportToFDF( |
563 m_pFormFillEnv->GetSDKDocument()->GetPath().AsStringC(), false); | 560 m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); |
564 if (!pFDF) | 561 if (!pFDF) |
565 return FALSE; | 562 return FALSE; |
566 | 563 |
567 FX_BOOL bRet = pFDF->WriteBuf(textBuf); | 564 FX_BOOL bRet = pFDF->WriteBuf(textBuf); |
568 delete pFDF; | 565 delete pFDF; |
569 | 566 |
570 return bRet; | 567 return bRet; |
571 } | 568 } |
572 | 569 |
573 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { | 570 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 } | 707 } |
711 } | 708 } |
712 | 709 |
713 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { | 710 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
714 if (nFieldType < 0 || nFieldType > kNumFieldTypes) | 711 if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
715 return FXSYS_RGB(255, 255, 255); | 712 return FXSYS_RGB(255, 255, 255); |
716 if (nFieldType == 0) | 713 if (nFieldType == 0) |
717 return m_aHighlightColor[0]; | 714 return m_aHighlightColor[0]; |
718 return m_aHighlightColor[nFieldType - 1]; | 715 return m_aHighlightColor[nFieldType - 1]; |
719 } | 716 } |
OLD | NEW |