Chromium Code Reviews| 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/fpdf_page/include/cpdf_page.h" | 12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 14 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" | 14 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
| 15 #include "core/fpdfdoc/include/cpdf_formcontrol.h" | 15 #include "core/fpdfdoc/include/cpdf_formcontrol.h" |
| 16 #include "core/fpdfdoc/include/cpdf_formfield.h" | 16 #include "core/fpdfdoc/include/cpdf_formfield.h" |
| 17 #include "core/fpdfdoc/include/cpdf_interform.h" | 17 #include "core/fpdfdoc/include/cpdf_interform.h" |
| 18 #include "core/fpdfdoc/include/cpdf_occontext.h" | 18 #include "core/fpdfdoc/include/cpdf_occontext.h" |
| 19 #include "core/fxge/include/cfx_fxgedevice.h" | 19 #include "core/fxge/include/cfx_fxgedevice.h" |
| 20 #include "fpdfsdk/include/cpdfdoc_environment.h" | |
| 21 #include "fpdfsdk/include/cpdfsdk_document.h" | 20 #include "fpdfsdk/include/cpdfsdk_document.h" |
| 21 #include "fpdfsdk/include/cpdfsdk_environment.h" | |
| 22 #include "fpdfsdk/include/cpdfsdk_interform.h" | 22 #include "fpdfsdk/include/cpdfsdk_interform.h" |
| 23 #include "fpdfsdk/include/cpdfsdk_pageview.h" | 23 #include "fpdfsdk/include/cpdfsdk_pageview.h" |
| 24 #include "fpdfsdk/include/fsdk_actionhandler.h" | 24 #include "fpdfsdk/include/fsdk_actionhandler.h" |
| 25 #include "fpdfsdk/include/fsdk_define.h" | 25 #include "fpdfsdk/include/fsdk_define.h" |
| 26 #include "public/fpdfview.h" | 26 #include "public/fpdfview.h" |
| 27 #include "third_party/base/stl_util.h" | 27 #include "third_party/base/stl_util.h" |
| 28 | 28 |
| 29 #ifdef PDF_ENABLE_XFA | 29 #ifdef PDF_ENABLE_XFA |
| 30 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" | 30 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" |
| 31 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | 31 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 if (!pPage) | 79 if (!pPage) |
| 80 return; | 80 return; |
| 81 | 81 |
| 82 #ifdef PDF_ENABLE_XFA | 82 #ifdef PDF_ENABLE_XFA |
| 83 CPDFXFA_Document* pDocument = pPage->GetDocument(); | 83 CPDFXFA_Document* pDocument = pPage->GetDocument(); |
| 84 if (!pDocument) | 84 if (!pDocument) |
| 85 return; | 85 return; |
| 86 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); | 86 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); |
| 87 if (!pPDFDoc) | 87 if (!pPDFDoc) |
| 88 return; | 88 return; |
| 89 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; | 89 CPDFSDK_Environment* pEnv = (CPDFSDK_Environment*)hHandle; |
|
Tom Sepez
2016/09/13 20:55:26
nit: static or reinterpret casts here, or helper f
dsinclair
2016/09/14 14:11:35
Done.
| |
| 90 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); | 90 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); |
| 91 if (!pFXDoc) | 91 if (!pFXDoc) |
| 92 return; | 92 return; |
| 93 #endif // PDF_ENABLE_XFA | 93 #endif // PDF_ENABLE_XFA |
| 94 | 94 |
| 95 CFX_Matrix matrix; | 95 CFX_Matrix matrix; |
| 96 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); | 96 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); |
| 97 | 97 |
| 98 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); | 98 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); |
| 99 | 99 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 #else // PDF_ENABLE_XFA | 231 #else // PDF_ENABLE_XFA |
| 232 const int kRequiredVersion = 1; | 232 const int kRequiredVersion = 1; |
| 233 #endif // PDF_ENABLE_XFA | 233 #endif // PDF_ENABLE_XFA |
| 234 if (!formInfo || formInfo->version != kRequiredVersion) | 234 if (!formInfo || formInfo->version != kRequiredVersion) |
| 235 return nullptr; | 235 return nullptr; |
| 236 | 236 |
| 237 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); | 237 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
| 238 if (!pDocument) | 238 if (!pDocument) |
| 239 return nullptr; | 239 return nullptr; |
| 240 | 240 |
| 241 CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); | 241 CPDFSDK_Environment* pEnv = new CPDFSDK_Environment(pDocument, formInfo); |
| 242 #ifdef PDF_ENABLE_XFA | 242 #ifdef PDF_ENABLE_XFA |
| 243 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); | 243 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); |
| 244 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); | 244 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| 245 pApp->AddFormFillEnv(pEnv); | 245 pApp->AddFormFillEnv(pEnv); |
| 246 #else // PDF_ENABLE_XFA | 246 #else // PDF_ENABLE_XFA |
| 247 pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); | 247 pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); |
| 248 #endif // PDF_ENABLE_XFA | 248 #endif // PDF_ENABLE_XFA |
| 249 return pEnv; | 249 return pEnv; |
| 250 } | 250 } |
| 251 | 251 |
| 252 DLLEXPORT void STDCALL | 252 DLLEXPORT void STDCALL |
| 253 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { | 253 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
| 254 if (!hHandle) | 254 if (!hHandle) |
| 255 return; | 255 return; |
| 256 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; | 256 CPDFSDK_Environment* pEnv = (CPDFSDK_Environment*)hHandle; |
| 257 #ifdef PDF_ENABLE_XFA | 257 #ifdef PDF_ENABLE_XFA |
| 258 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); | 258 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| 259 pApp->RemoveFormFillEnv(pEnv); | 259 pApp->RemoveFormFillEnv(pEnv); |
| 260 #else // PDF_ENABLE_XFA | 260 #else // PDF_ENABLE_XFA |
| 261 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { | 261 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
| 262 pEnv->SetSDKDocument(nullptr); | 262 pEnv->SetSDKDocument(nullptr); |
| 263 delete pSDKDoc; | 263 delete pSDKDoc; |
| 264 } | 264 } |
| 265 #endif // PDF_ENABLE_XFA | 265 #endif // PDF_ENABLE_XFA |
| 266 delete pEnv; | 266 delete pEnv; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 FPDF_FORMHANDLE hHandle) { | 634 FPDF_FORMHANDLE hHandle) { |
| 635 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) | 635 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
| 636 pPageView->SetValid(TRUE); | 636 pPageView->SetValid(TRUE); |
| 637 } | 637 } |
| 638 | 638 |
| 639 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, | 639 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 640 FPDF_FORMHANDLE hHandle) { | 640 FPDF_FORMHANDLE hHandle) { |
| 641 if (!hHandle) | 641 if (!hHandle) |
| 642 return; | 642 return; |
| 643 | 643 |
| 644 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); | 644 CPDFSDK_Document* pSDKDoc = ((CPDFSDK_Environment*)hHandle)->GetSDKDocument(); |
| 645 if (!pSDKDoc) | 645 if (!pSDKDoc) |
| 646 return; | 646 return; |
| 647 | 647 |
| 648 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 648 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 649 if (!pPage) | 649 if (!pPage) |
| 650 return; | 650 return; |
| 651 | 651 |
| 652 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, false); | 652 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, false); |
| 653 if (pPageView) { | 653 if (pPageView) { |
| 654 pPageView->SetValid(FALSE); | 654 pPageView->SetValid(FALSE); |
| 655 // RemovePageView() takes care of the delete for us. | 655 // RemovePageView() takes care of the delete for us. |
| 656 pSDKDoc->RemovePageView(pPage); | 656 pSDKDoc->RemovePageView(pPage); |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 | 659 |
| 660 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { | 660 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
| 661 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 661 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 662 if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated()) | 662 if (pSDKDoc && ((CPDFSDK_Environment*)hHandle)->IsJSInitiated()) |
| 663 pSDKDoc->ProcJavascriptFun(); | 663 pSDKDoc->ProcJavascriptFun(); |
| 664 } | 664 } |
| 665 | 665 |
| 666 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { | 666 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
| 667 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 667 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 668 if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated()) | 668 if (pSDKDoc && ((CPDFSDK_Environment*)hHandle)->IsJSInitiated()) |
| 669 pSDKDoc->ProcOpenAction(); | 669 pSDKDoc->ProcOpenAction(); |
| 670 } | 670 } |
| 671 | 671 |
| 672 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, | 672 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 673 int aaType) { | 673 int aaType) { |
| 674 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 674 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 675 if (!pSDKDoc) | 675 if (!pSDKDoc) |
| 676 return; | 676 return; |
| 677 | 677 |
| 678 CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); | 678 CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); |
| 679 CPDF_Dictionary* pDic = pDoc->GetRoot(); | 679 CPDF_Dictionary* pDic = pDoc->GetRoot(); |
| 680 if (!pDic) | 680 if (!pDic) |
| 681 return; | 681 return; |
| 682 | 682 |
| 683 CPDF_AAction aa(pDic->GetDictBy("AA")); | 683 CPDF_AAction aa(pDic->GetDictBy("AA")); |
| 684 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { | 684 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { |
| 685 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); | 685 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); |
| 686 CPDFSDK_ActionHandler* pActionHandler = | 686 CPDFSDK_ActionHandler* pActionHandler = |
| 687 ((CPDFDoc_Environment*)hHandle)->GetActionHander(); | 687 ((CPDFSDK_Environment*)hHandle)->GetActionHander(); |
| 688 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, | 688 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
| 689 pSDKDoc); | 689 pSDKDoc); |
| 690 } | 690 } |
| 691 } | 691 } |
| 692 | 692 |
| 693 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, | 693 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, |
| 694 FPDF_FORMHANDLE hHandle, | 694 FPDF_FORMHANDLE hHandle, |
| 695 int aaType) { | 695 int aaType) { |
| 696 if (!hHandle) | 696 if (!hHandle) |
| 697 return; | 697 return; |
| 698 | 698 |
| 699 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 699 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 700 if (!pSDKDoc) | 700 if (!pSDKDoc) |
| 701 return; | 701 return; |
| 702 | 702 |
| 703 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 703 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 704 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); | 704 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
| 705 if (!pPDFPage) | 705 if (!pPDFPage) |
| 706 return; | 706 return; |
| 707 | 707 |
| 708 if (!pSDKDoc->GetPageView(pPage, false)) | 708 if (!pSDKDoc->GetPageView(pPage, false)) |
| 709 return; | 709 return; |
| 710 | 710 |
| 711 CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); | 711 CPDFSDK_Environment* pEnv = pSDKDoc->GetEnv(); |
| 712 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 712 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 713 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; | 713 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; |
| 714 CPDF_AAction aa(pPageDict->GetDictBy("AA")); | 714 CPDF_AAction aa(pPageDict->GetDictBy("AA")); |
| 715 if (FPDFPAGE_AACTION_OPEN == aaType) { | 715 if (FPDFPAGE_AACTION_OPEN == aaType) { |
| 716 if (aa.ActionExist(CPDF_AAction::OpenPage)) { | 716 if (aa.ActionExist(CPDF_AAction::OpenPage)) { |
| 717 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 717 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
| 718 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 718 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
| 719 } | 719 } |
| 720 } else { | 720 } else { |
| 721 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 721 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
| 722 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 722 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
| 723 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 723 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 } | 726 } |
| OLD | NEW |