| 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 #include "public/fpdf_formfill.h" | 7 #include "public/fpdf_formfill.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "core/fpdfapi/page/cpdf_page.h" | 12 #include "core/fpdfapi/page/cpdf_page.h" |
| 13 #include "core/fpdfapi/parser/cpdf_document.h" | 13 #include "core/fpdfapi/parser/cpdf_document.h" |
| 14 #include "core/fpdfapi/render/cpdf_renderoptions.h" | 14 #include "core/fpdfapi/render/cpdf_renderoptions.h" |
| 15 #include "core/fpdfdoc/cpdf_formcontrol.h" | 15 #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 16 #include "core/fpdfdoc/cpdf_formfield.h" | 16 #include "core/fpdfdoc/cpdf_formfield.h" |
| 17 #include "core/fpdfdoc/cpdf_interform.h" | 17 #include "core/fpdfdoc/cpdf_interform.h" |
| 18 #include "core/fpdfdoc/cpdf_occontext.h" | 18 #include "core/fpdfdoc/cpdf_occontext.h" |
| 19 #include "core/fxge/cfx_fxgedevice.h" | 19 #include "core/fxge/cfx_fxgedevice.h" |
| 20 #include "fpdfsdk/cpdfsdk_document.h" | |
| 21 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 20 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 22 #include "fpdfsdk/cpdfsdk_interform.h" | 21 #include "fpdfsdk/cpdfsdk_interform.h" |
| 23 #include "fpdfsdk/cpdfsdk_pageview.h" | 22 #include "fpdfsdk/cpdfsdk_pageview.h" |
| 24 #include "fpdfsdk/fsdk_actionhandler.h" | 23 #include "fpdfsdk/fsdk_actionhandler.h" |
| 25 #include "fpdfsdk/fsdk_define.h" | 24 #include "fpdfsdk/fsdk_define.h" |
| 26 #include "public/fpdfview.h" | 25 #include "public/fpdfview.h" |
| 27 #include "third_party/base/ptr_util.h" | 26 #include "third_party/base/ptr_util.h" |
| 28 #include "third_party/base/stl_util.h" | 27 #include "third_party/base/stl_util.h" |
| 29 | 28 |
| 30 #ifdef PDF_ENABLE_XFA | 29 #ifdef PDF_ENABLE_XFA |
| 31 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" | 30 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" |
| 32 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" | 31 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" |
| 33 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" | 32 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
| 34 #include "xfa/fxfa/xfa_ffdocview.h" | 33 #include "xfa/fxfa/xfa_ffdocview.h" |
| 35 #include "xfa/fxfa/xfa_ffpageview.h" | 34 #include "xfa/fxfa/xfa_ffpageview.h" |
| 36 #include "xfa/fxfa/xfa_ffwidget.h" | 35 #include "xfa/fxfa/xfa_ffwidget.h" |
| 37 #endif // PDF_ENABLE_XFA | 36 #endif // PDF_ENABLE_XFA |
| 38 | 37 |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( | 40 CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( |
| 42 FPDF_FORMHANDLE handle) { | 41 FPDF_FORMHANDLE handle) { |
| 43 return static_cast<CPDFSDK_FormFillEnvironment*>(handle); | 42 return static_cast<CPDFSDK_FormFillEnvironment*>(handle); |
| 44 } | 43 } |
| 45 | 44 |
| 46 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { | 45 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
| 47 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 46 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 48 HandleToCPDFSDKEnvironment(hHandle); | 47 HandleToCPDFSDKEnvironment(hHandle); |
| 49 return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetInterForm() | 48 return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr; |
| 50 : nullptr; | |
| 51 } | 49 } |
| 52 | 50 |
| 53 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, | 51 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 54 FPDF_PAGE page) { | 52 FPDF_PAGE page) { |
| 55 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 53 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 56 if (!pPage) | 54 if (!pPage) |
| 57 return nullptr; | 55 return nullptr; |
| 58 | 56 |
| 59 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 57 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 60 HandleToCPDFSDKEnvironment(hHandle); | 58 HandleToCPDFSDKEnvironment(hHandle); |
| 61 return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true) | 59 return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr; |
| 62 : nullptr; | |
| 63 } | 60 } |
| 64 | 61 |
| 65 #ifdef PDF_ENABLE_XFA | 62 #ifdef PDF_ENABLE_XFA |
| 66 std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) { | 63 std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) { |
| 67 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle); | 64 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle); |
| 68 } | 65 } |
| 69 | 66 |
| 70 FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) { | 67 FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) { |
| 71 return reinterpret_cast<FPDF_STRINGHANDLE>(strings); | 68 return reinterpret_cast<FPDF_STRINGHANDLE>(strings); |
| 72 } | 69 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 if (flags & FPDF_GRAYSCALE) { | 122 if (flags & FPDF_GRAYSCALE) { |
| 126 options.m_ColorMode = RENDER_COLOR_GRAY; | 123 options.m_ColorMode = RENDER_COLOR_GRAY; |
| 127 options.m_ForeColor = 0; | 124 options.m_ForeColor = 0; |
| 128 options.m_BackColor = 0xffffff; | 125 options.m_BackColor = 0xffffff; |
| 129 } | 126 } |
| 130 options.m_AddFlags = flags >> 8; | 127 options.m_AddFlags = flags >> 8; |
| 131 options.m_bDrawAnnots = flags & FPDF_ANNOT; | 128 options.m_bDrawAnnots = flags & FPDF_ANNOT; |
| 132 | 129 |
| 133 #ifdef PDF_ENABLE_XFA | 130 #ifdef PDF_ENABLE_XFA |
| 134 options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View); | 131 options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View); |
| 135 if (CPDFSDK_PageView* pPageView = | 132 if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true)) |
| 136 pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true)) | |
| 137 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); | 133 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); |
| 138 #else // PDF_ENABLE_XFA | 134 #else // PDF_ENABLE_XFA |
| 139 options.m_pOCContext = | 135 options.m_pOCContext = |
| 140 new CPDF_OCContext(pPage->m_pDocument, CPDF_OCContext::View); | 136 new CPDF_OCContext(pPage->m_pDocument, CPDF_OCContext::View); |
| 141 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) | 137 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) |
| 142 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); | 138 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); |
| 143 #endif // PDF_ENABLE_XFA | 139 #endif // PDF_ENABLE_XFA |
| 144 | 140 |
| 145 pDevice->RestoreState(false); | 141 pDevice->RestoreState(false); |
| 146 delete options.m_pOCContext; | 142 delete options.m_pOCContext; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 return; | 270 return; |
| 275 | 271 |
| 276 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 272 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 277 HandleToCPDFSDKEnvironment(hHandle); | 273 HandleToCPDFSDKEnvironment(hHandle); |
| 278 | 274 |
| 279 #ifdef PDF_ENABLE_XFA | 275 #ifdef PDF_ENABLE_XFA |
| 280 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pFormFillEnv); | 276 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pFormFillEnv); |
| 281 | 277 |
| 282 // Reset the focused annotations and remove the SDK document from the | 278 // Reset the focused annotations and remove the SDK document from the |
| 283 // XFA document. | 279 // XFA document. |
| 284 pFormFillEnv->GetSDKDocument()->ClearAllFocusedAnnots(); | 280 pFormFillEnv->ClearAllFocusedAnnots(); |
| 285 // If the document was closed first, it's possible the XFA document | 281 // If the document was closed first, it's possible the XFA document |
| 286 // is now a nullptr. | 282 // is now a nullptr. |
| 287 if (pFormFillEnv->GetSDKDocument()->GetXFADocument()) | 283 if (pFormFillEnv->GetXFADocument()) |
| 288 pFormFillEnv->GetSDKDocument()->GetXFADocument()->SetFormFillEnv(nullptr); | 284 pFormFillEnv->GetXFADocument()->SetFormFillEnv(nullptr); |
| 289 #endif // PDF_ENABLE_XFA | 285 #endif // PDF_ENABLE_XFA |
| 290 | 286 |
| 291 delete pFormFillEnv; | 287 delete pFormFillEnv; |
| 292 } | 288 } |
| 293 | 289 |
| 294 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, | 290 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 295 FPDF_PAGE page, | 291 FPDF_PAGE page, |
| 296 int modifier, | 292 int modifier, |
| 297 double page_x, | 293 double page_x, |
| 298 double page_y) { | 294 double page_y) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 return FALSE; | 385 return FALSE; |
| 390 | 386 |
| 391 return pPageView->OnChar(nChar, modifier); | 387 return pPageView->OnChar(nChar, modifier); |
| 392 } | 388 } |
| 393 | 389 |
| 394 DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { | 390 DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
| 395 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 391 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 396 HandleToCPDFSDKEnvironment(hHandle); | 392 HandleToCPDFSDKEnvironment(hHandle); |
| 397 if (!pFormFillEnv) | 393 if (!pFormFillEnv) |
| 398 return FALSE; | 394 return FALSE; |
| 399 return pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); | 395 return pFormFillEnv->KillFocusAnnot(0); |
| 400 } | 396 } |
| 401 | 397 |
| 402 DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, | 398 DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 403 FPDF_BITMAP bitmap, | 399 FPDF_BITMAP bitmap, |
| 404 FPDF_PAGE page, | 400 FPDF_PAGE page, |
| 405 int start_x, | 401 int start_x, |
| 406 int start_y, | 402 int start_y, |
| 407 int size_x, | 403 int size_x, |
| 408 int size_y, | 404 int size_y, |
| 409 int rotate, | 405 int rotate, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 664 |
| 669 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 665 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 670 HandleToCPDFSDKEnvironment(hHandle); | 666 HandleToCPDFSDKEnvironment(hHandle); |
| 671 if (!pFormFillEnv) | 667 if (!pFormFillEnv) |
| 672 return; | 668 return; |
| 673 | 669 |
| 674 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 670 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 675 if (!pPage) | 671 if (!pPage) |
| 676 return; | 672 return; |
| 677 | 673 |
| 678 CPDFSDK_PageView* pPageView = | 674 CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); |
| 679 pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); | |
| 680 if (pPageView) { | 675 if (pPageView) { |
| 681 pPageView->SetValid(FALSE); | 676 pPageView->SetValid(FALSE); |
| 682 // RemovePageView() takes care of the delete for us. | 677 // RemovePageView() takes care of the delete for us. |
| 683 pFormFillEnv->GetSDKDocument()->RemovePageView(pPage); | 678 pFormFillEnv->RemovePageView(pPage); |
| 684 } | 679 } |
| 685 } | 680 } |
| 686 | 681 |
| 687 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { | 682 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
| 688 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 683 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 689 HandleToCPDFSDKEnvironment(hHandle); | 684 HandleToCPDFSDKEnvironment(hHandle); |
| 690 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) | 685 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
| 691 pFormFillEnv->GetSDKDocument()->ProcJavascriptFun(); | 686 pFormFillEnv->ProcJavascriptFun(); |
| 692 } | 687 } |
| 693 | 688 |
| 694 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { | 689 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
| 695 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 690 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 696 HandleToCPDFSDKEnvironment(hHandle); | 691 HandleToCPDFSDKEnvironment(hHandle); |
| 697 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) | 692 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
| 698 pFormFillEnv->GetSDKDocument()->ProcOpenAction(); | 693 pFormFillEnv->ProcOpenAction(); |
| 699 } | 694 } |
| 700 | 695 |
| 701 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, | 696 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 702 int aaType) { | 697 int aaType) { |
| 703 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 698 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 704 HandleToCPDFSDKEnvironment(hHandle); | 699 HandleToCPDFSDKEnvironment(hHandle); |
| 705 if (!pFormFillEnv) | 700 if (!pFormFillEnv) |
| 706 return; | 701 return; |
| 707 | 702 |
| 708 CPDF_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 703 CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); |
| 709 CPDF_Dictionary* pDic = pDoc->GetRoot(); | 704 CPDF_Dictionary* pDic = pDoc->GetRoot(); |
| 710 if (!pDic) | 705 if (!pDic) |
| 711 return; | 706 return; |
| 712 | 707 |
| 713 CPDF_AAction aa(pDic->GetDictFor("AA")); | 708 CPDF_AAction aa(pDic->GetDictFor("AA")); |
| 714 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { | 709 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { |
| 715 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); | 710 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); |
| 716 CPDFSDK_ActionHandler* pActionHandler = | 711 CPDFSDK_ActionHandler* pActionHandler = |
| 717 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); | 712 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); |
| 718 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, | 713 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 729 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 724 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 730 HandleToCPDFSDKEnvironment(hHandle); | 725 HandleToCPDFSDKEnvironment(hHandle); |
| 731 if (!pFormFillEnv) | 726 if (!pFormFillEnv) |
| 732 return; | 727 return; |
| 733 | 728 |
| 734 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 729 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 735 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); | 730 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
| 736 if (!pPDFPage) | 731 if (!pPDFPage) |
| 737 return; | 732 return; |
| 738 | 733 |
| 739 if (!pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false)) | 734 if (!pFormFillEnv->GetPageView(pPage, false)) |
| 740 return; | 735 return; |
| 741 | 736 |
| 742 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); | 737 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); |
| 743 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; | 738 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; |
| 744 CPDF_AAction aa(pPageDict->GetDictFor("AA")); | 739 CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
| 745 if (FPDFPAGE_AACTION_OPEN == aaType) { | 740 if (FPDFPAGE_AACTION_OPEN == aaType) { |
| 746 if (aa.ActionExist(CPDF_AAction::OpenPage)) { | 741 if (aa.ActionExist(CPDF_AAction::OpenPage)) { |
| 747 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 742 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
| 748 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, | 743 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, |
| 749 pFormFillEnv); | 744 pFormFillEnv); |
| 750 } | 745 } |
| 751 } else { | 746 } else { |
| 752 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 747 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
| 753 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 748 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
| 754 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, | 749 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, |
| 755 pFormFillEnv); | 750 pFormFillEnv); |
| 756 } | 751 } |
| 757 } | 752 } |
| 758 } | 753 } |
| OLD | NEW |