| 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> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" | 31 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" |
| 32 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" | 32 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" |
| 33 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" | 33 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
| 34 #include "xfa/fxfa/xfa_ffdocview.h" | 34 #include "xfa/fxfa/xfa_ffdocview.h" |
| 35 #include "xfa/fxfa/xfa_ffpageview.h" | 35 #include "xfa/fxfa/xfa_ffpageview.h" |
| 36 #include "xfa/fxfa/xfa_ffwidget.h" | 36 #include "xfa/fxfa/xfa_ffwidget.h" |
| 37 #endif // PDF_ENABLE_XFA | 37 #endif // PDF_ENABLE_XFA |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( | 41 CPDFSDK_FormFillEnvironment* HandleToCPDFSDKFormFillEnvironment( |
| 42 FPDF_FORMHANDLE handle) { | 42 FPDF_FORMHANDLE handle) { |
| 43 return static_cast<CPDFSDK_FormFillEnvironment*>(handle); | 43 return static_cast<CPDFSDK_FormFillEnvironment*>(handle); |
| 44 } | 44 } |
| 45 | 45 |
| 46 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { | |
| 47 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | |
| 48 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; | |
| 49 } | |
| 50 | |
| 51 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, | 46 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 52 FPDF_PAGE page) { | 47 FPDF_PAGE page) { |
| 53 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 48 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 54 if (!pPage) | 49 if (!pPage) |
| 55 return nullptr; | 50 return nullptr; |
| 56 | 51 |
| 57 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 52 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 58 return pSDKDoc ? pSDKDoc->GetPageView(pPage, true) : nullptr; | 53 return pSDKDoc ? pSDKDoc->GetPageView(pPage, true) : nullptr; |
| 59 } | 54 } |
| 60 | 55 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 if (!pPage) | 80 if (!pPage) |
| 86 return; | 81 return; |
| 87 | 82 |
| 88 #ifdef PDF_ENABLE_XFA | 83 #ifdef PDF_ENABLE_XFA |
| 89 CPDFXFA_Document* pDocument = pPage->GetDocument(); | 84 CPDFXFA_Document* pDocument = pPage->GetDocument(); |
| 90 if (!pDocument) | 85 if (!pDocument) |
| 91 return; | 86 return; |
| 92 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); | 87 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); |
| 93 if (!pPDFDoc) | 88 if (!pPDFDoc) |
| 94 return; | 89 return; |
| 95 CPDFSDK_FormFillEnvironment* pEnv = HandleToCPDFSDKEnvironment(hHandle); | 90 CPDFSDK_FormFillEnvironment* pEnv = |
| 91 HandleToCPDFSDKFormFillEnvironment(hHandle); |
| 96 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); | 92 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); |
| 97 if (!pFXDoc) | 93 if (!pFXDoc) |
| 98 return; | 94 return; |
| 99 #endif // PDF_ENABLE_XFA | 95 #endif // PDF_ENABLE_XFA |
| 100 | 96 |
| 101 CFX_Matrix matrix; | 97 CFX_Matrix matrix; |
| 102 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); | 98 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); |
| 103 | 99 |
| 104 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); | 100 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); |
| 105 | 101 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 return nullptr; | 237 return nullptr; |
| 242 | 238 |
| 243 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); | 239 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
| 244 if (!pDocument) | 240 if (!pDocument) |
| 245 return nullptr; | 241 return nullptr; |
| 246 | 242 |
| 247 #ifdef PDF_ENABLE_XFA | 243 #ifdef PDF_ENABLE_XFA |
| 248 // If the CPDFXFA_Document has a SDKDocument already then we've done this | 244 // If the CPDFXFA_Document has a SDKDocument already then we've done this |
| 249 // and can just return the old Env. Otherwise, we'll end up setting a new | 245 // and can just return the old Env. Otherwise, we'll end up setting a new |
| 250 // SDKDocument into the XFADocument and, that could get weird. | 246 // SDKDocument into the XFADocument and, that could get weird. |
| 251 if (pDocument->GetSDKDoc()) | 247 if (pDocument->GetFormFillEnv()) |
| 252 return pDocument->GetSDKDoc()->GetEnv(); | 248 return pDocument->GetFormFillEnv(); |
| 253 #endif | 249 #endif |
| 254 | 250 |
| 255 CPDFSDK_FormFillEnvironment* pEnv = | 251 CPDFSDK_FormFillEnvironment* pEnv = |
| 256 new CPDFSDK_FormFillEnvironment(pDocument, formInfo); | 252 new CPDFSDK_FormFillEnvironment(pDocument, formInfo); |
| 257 | 253 |
| 258 #ifdef PDF_ENABLE_XFA | 254 #ifdef PDF_ENABLE_XFA |
| 259 pDocument->SetSDKDoc(pEnv->GetSDKDocument()); | 255 pDocument->SetSDKDoc(pEnv->GetSDKDocument()); |
| 260 CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); | 256 CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); |
| 261 #endif // PDF_ENABLE_XFA | 257 #endif // PDF_ENABLE_XFA |
| 262 | 258 |
| 263 return pEnv; | 259 return pEnv; |
| 264 } | 260 } |
| 265 | 261 |
| 266 DLLEXPORT void STDCALL | 262 DLLEXPORT void STDCALL |
| 267 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { | 263 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
| 268 if (!hHandle) | 264 if (!hHandle) |
| 269 return; | 265 return; |
| 270 | 266 |
| 271 CPDFSDK_FormFillEnvironment* pEnv = HandleToCPDFSDKEnvironment(hHandle); | 267 CPDFSDK_FormFillEnvironment* pEnv = |
| 268 HandleToCPDFSDKFormFillEnvironment(hHandle); |
| 272 | 269 |
| 273 #ifdef PDF_ENABLE_XFA | 270 #ifdef PDF_ENABLE_XFA |
| 274 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv); | 271 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv); |
| 275 | 272 |
| 276 // Reset the focused annotations and remove the SDK document from the | 273 // Reset the focused annotations and remove the SDK document from the |
| 277 // XFA document. | 274 // XFA document. |
| 278 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { | 275 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
| 279 pSDKDoc->ClearAllFocusedAnnots(); | 276 pSDKDoc->ClearAllFocusedAnnots(); |
| 280 pSDKDoc->GetXFADocument()->SetSDKDoc(nullptr); | 277 pEnv->GetXFADocument()->SetSDKDoc(nullptr); |
| 281 } | 278 } |
| 282 #endif // PDF_ENABLE_XFA | 279 #endif // PDF_ENABLE_XFA |
| 283 | 280 |
| 284 delete pEnv; | 281 delete pEnv; |
| 285 } | 282 } |
| 286 | 283 |
| 287 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, | 284 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 288 FPDF_PAGE page, | 285 FPDF_PAGE page, |
| 289 int modifier, | 286 int modifier, |
| 290 double page_x, | 287 double page_x, |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 return FALSE; | 623 return FALSE; |
| 627 | 624 |
| 628 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size)); | 625 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size)); |
| 629 return TRUE; | 626 return TRUE; |
| 630 } | 627 } |
| 631 #endif // PDF_ENABLE_XFA | 628 #endif // PDF_ENABLE_XFA |
| 632 | 629 |
| 633 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, | 630 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
| 634 int fieldType, | 631 int fieldType, |
| 635 unsigned long color) { | 632 unsigned long color) { |
| 636 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) | 633 if (CPDFSDK_InterForm* pInterForm = |
| 634 HandleToCPDFSDKFormFillEnvironment(hHandle)->GetInterForm()) |
| 637 pInterForm->SetHighlightColor(color, fieldType); | 635 pInterForm->SetHighlightColor(color, fieldType); |
| 638 } | 636 } |
| 639 | 637 |
| 640 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, | 638 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, |
| 641 unsigned char alpha) { | 639 unsigned char alpha) { |
| 642 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) | 640 if (CPDFSDK_InterForm* pInterForm = |
| 641 HandleToCPDFSDKFormFillEnvironment(hHandle)->GetInterForm()) |
| 643 pInterForm->SetHighlightAlpha(alpha); | 642 pInterForm->SetHighlightAlpha(alpha); |
| 644 } | 643 } |
| 645 | 644 |
| 646 DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { | 645 DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { |
| 647 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) | 646 if (CPDFSDK_InterForm* pInterForm = |
| 647 HandleToCPDFSDKFormFillEnvironment(hHandle)->GetInterForm()) |
| 648 pInterForm->RemoveAllHighLight(); | 648 pInterForm->RemoveAllHighLight(); |
| 649 } | 649 } |
| 650 | 650 |
| 651 DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, | 651 DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 652 FPDF_FORMHANDLE hHandle) { | 652 FPDF_FORMHANDLE hHandle) { |
| 653 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) | 653 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
| 654 pPageView->SetValid(TRUE); | 654 pPageView->SetValid(TRUE); |
| 655 } | 655 } |
| 656 | 656 |
| 657 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, | 657 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 658 FPDF_FORMHANDLE hHandle) { | 658 FPDF_FORMHANDLE hHandle) { |
| 659 if (!hHandle) | 659 if (!hHandle) |
| 660 return; | 660 return; |
| 661 | 661 |
| 662 CPDFSDK_Document* pSDKDoc = | 662 CPDFSDK_Document* pSDKDoc = |
| 663 HandleToCPDFSDKEnvironment(hHandle)->GetSDKDocument(); | 663 HandleToCPDFSDKFormFillEnvironment(hHandle)->GetSDKDocument(); |
| 664 if (!pSDKDoc) | 664 if (!pSDKDoc) |
| 665 return; | 665 return; |
| 666 | 666 |
| 667 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 667 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 668 if (!pPage) | 668 if (!pPage) |
| 669 return; | 669 return; |
| 670 | 670 |
| 671 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, false); | 671 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, false); |
| 672 if (pPageView) { | 672 if (pPageView) { |
| 673 pPageView->SetValid(FALSE); | 673 pPageView->SetValid(FALSE); |
| 674 // RemovePageView() takes care of the delete for us. | 674 // RemovePageView() takes care of the delete for us. |
| 675 pSDKDoc->RemovePageView(pPage); | 675 pSDKDoc->RemovePageView(pPage); |
| 676 } | 676 } |
| 677 } | 677 } |
| 678 | 678 |
| 679 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { | 679 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
| 680 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 680 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 681 if (pSDKDoc && HandleToCPDFSDKEnvironment(hHandle)->IsJSInitiated()) | 681 if (pSDKDoc && HandleToCPDFSDKFormFillEnvironment(hHandle)->IsJSInitiated()) |
| 682 pSDKDoc->ProcJavascriptFun(); | 682 pSDKDoc->ProcJavascriptFun(); |
| 683 } | 683 } |
| 684 | 684 |
| 685 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { | 685 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
| 686 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 686 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 687 if (pSDKDoc && HandleToCPDFSDKEnvironment(hHandle)->IsJSInitiated()) | 687 if (pSDKDoc && HandleToCPDFSDKFormFillEnvironment(hHandle)->IsJSInitiated()) |
| 688 pSDKDoc->ProcOpenAction(); | 688 pSDKDoc->ProcOpenAction(); |
| 689 } | 689 } |
| 690 | 690 |
| 691 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, | 691 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 692 int aaType) { | 692 int aaType) { |
| 693 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 693 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 694 if (!pSDKDoc) | 694 if (!pSDKDoc) |
| 695 return; | 695 return; |
| 696 | 696 |
| 697 CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); | 697 CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); |
| 698 CPDF_Dictionary* pDic = pDoc->GetRoot(); | 698 CPDF_Dictionary* pDic = pDoc->GetRoot(); |
| 699 if (!pDic) | 699 if (!pDic) |
| 700 return; | 700 return; |
| 701 | 701 |
| 702 CPDF_AAction aa(pDic->GetDictFor("AA")); | 702 CPDF_AAction aa(pDic->GetDictFor("AA")); |
| 703 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { | 703 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { |
| 704 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); | 704 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); |
| 705 CPDFSDK_ActionHandler* pActionHandler = | 705 CPDFSDK_ActionHandler* pActionHandler = |
| 706 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); | 706 HandleToCPDFSDKFormFillEnvironment(hHandle)->GetActionHander(); |
| 707 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, | 707 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
| 708 pSDKDoc); | 708 pSDKDoc); |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 | 711 |
| 712 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, | 712 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, |
| 713 FPDF_FORMHANDLE hHandle, | 713 FPDF_FORMHANDLE hHandle, |
| 714 int aaType) { | 714 int aaType) { |
| 715 if (!hHandle) | 715 if (!hHandle) |
| 716 return; | 716 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 736 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 736 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
| 737 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 737 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
| 738 } | 738 } |
| 739 } else { | 739 } else { |
| 740 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 740 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
| 741 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 741 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
| 742 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 742 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
| 743 } | 743 } |
| 744 } | 744 } |
| 745 } | 745 } |
| OLD | NEW |