| 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" | 20 #include "fpdfsdk/cpdfsdk_document.h" |
| 21 #include "fpdfsdk/cpdfsdk_environment.h" | 21 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 22 #include "fpdfsdk/cpdfsdk_interform.h" | 22 #include "fpdfsdk/cpdfsdk_interform.h" |
| 23 #include "fpdfsdk/cpdfsdk_pageview.h" | 23 #include "fpdfsdk/cpdfsdk_pageview.h" |
| 24 #include "fpdfsdk/fsdk_actionhandler.h" | 24 #include "fpdfsdk/fsdk_actionhandler.h" |
| 25 #include "fpdfsdk/fsdk_define.h" | 25 #include "fpdfsdk/fsdk_define.h" |
| 26 #include "public/fpdfview.h" | 26 #include "public/fpdfview.h" |
| 27 #include "third_party/base/ptr_util.h" | 27 #include "third_party/base/ptr_util.h" |
| 28 #include "third_party/base/stl_util.h" | 28 #include "third_party/base/stl_util.h" |
| 29 | 29 |
| 30 #ifdef PDF_ENABLE_XFA | 30 #ifdef PDF_ENABLE_XFA |
| 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_Environment* HandleToCPDFSDKEnvironment(FPDF_FORMHANDLE handle) { | 41 CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( |
| 42 return static_cast<CPDFSDK_Environment*>(handle); | 42 FPDF_FORMHANDLE handle) { |
| 43 return static_cast<CPDFSDK_FormFillEnvironment*>(handle); |
| 43 } | 44 } |
| 44 | 45 |
| 45 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { | 46 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
| 46 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 47 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
| 47 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; | 48 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; |
| 48 } | 49 } |
| 49 | 50 |
| 50 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, | 51 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 51 FPDF_PAGE page) { | 52 FPDF_PAGE page) { |
| 52 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 53 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (!pPage) | 85 if (!pPage) |
| 85 return; | 86 return; |
| 86 | 87 |
| 87 #ifdef PDF_ENABLE_XFA | 88 #ifdef PDF_ENABLE_XFA |
| 88 CPDFXFA_Document* pDocument = pPage->GetDocument(); | 89 CPDFXFA_Document* pDocument = pPage->GetDocument(); |
| 89 if (!pDocument) | 90 if (!pDocument) |
| 90 return; | 91 return; |
| 91 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); | 92 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); |
| 92 if (!pPDFDoc) | 93 if (!pPDFDoc) |
| 93 return; | 94 return; |
| 94 CPDFSDK_Environment* pEnv = HandleToCPDFSDKEnvironment(hHandle); | 95 CPDFSDK_FormFillEnvironment* pEnv = HandleToCPDFSDKEnvironment(hHandle); |
| 95 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); | 96 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); |
| 96 if (!pFXDoc) | 97 if (!pFXDoc) |
| 97 return; | 98 return; |
| 98 #endif // PDF_ENABLE_XFA | 99 #endif // PDF_ENABLE_XFA |
| 99 | 100 |
| 100 CFX_Matrix matrix; | 101 CFX_Matrix matrix; |
| 101 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); | 102 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); |
| 102 | 103 |
| 103 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); | 104 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); |
| 104 | 105 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 return nullptr; | 245 return nullptr; |
| 245 | 246 |
| 246 #ifdef PDF_ENABLE_XFA | 247 #ifdef PDF_ENABLE_XFA |
| 247 // If the CPDFXFA_Document has a SDKDocument already then we've done this | 248 // If the CPDFXFA_Document has a SDKDocument already then we've done this |
| 248 // and can just return the old Env. Otherwise, we'll end up setting a new | 249 // and can just return the old Env. Otherwise, we'll end up setting a new |
| 249 // SDKDocument into the XFADocument and, that could get weird. | 250 // SDKDocument into the XFADocument and, that could get weird. |
| 250 if (pDocument->GetSDKDoc()) | 251 if (pDocument->GetSDKDoc()) |
| 251 return pDocument->GetSDKDoc()->GetEnv(); | 252 return pDocument->GetSDKDoc()->GetEnv(); |
| 252 #endif | 253 #endif |
| 253 | 254 |
| 254 CPDFSDK_Environment* pEnv = new CPDFSDK_Environment(pDocument, formInfo); | 255 CPDFSDK_FormFillEnvironment* pEnv = |
| 256 new CPDFSDK_FormFillEnvironment(pDocument, formInfo); |
| 255 | 257 |
| 256 #ifdef PDF_ENABLE_XFA | 258 #ifdef PDF_ENABLE_XFA |
| 257 pDocument->SetSDKDoc(pEnv->GetSDKDocument()); | 259 pDocument->SetSDKDoc(pEnv->GetSDKDocument()); |
| 258 CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); | 260 CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); |
| 259 #endif // PDF_ENABLE_XFA | 261 #endif // PDF_ENABLE_XFA |
| 260 | 262 |
| 261 return pEnv; | 263 return pEnv; |
| 262 } | 264 } |
| 263 | 265 |
| 264 DLLEXPORT void STDCALL | 266 DLLEXPORT void STDCALL |
| 265 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { | 267 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
| 266 if (!hHandle) | 268 if (!hHandle) |
| 267 return; | 269 return; |
| 268 | 270 |
| 269 CPDFSDK_Environment* pEnv = HandleToCPDFSDKEnvironment(hHandle); | 271 CPDFSDK_FormFillEnvironment* pEnv = HandleToCPDFSDKEnvironment(hHandle); |
| 270 | 272 |
| 271 #ifdef PDF_ENABLE_XFA | 273 #ifdef PDF_ENABLE_XFA |
| 272 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv); | 274 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv); |
| 273 | 275 |
| 274 // Reset the focused annotations and remove the SDK document from the | 276 // Reset the focused annotations and remove the SDK document from the |
| 275 // XFA document. | 277 // XFA document. |
| 276 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { | 278 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
| 277 pSDKDoc->ClearAllFocusedAnnots(); | 279 pSDKDoc->ClearAllFocusedAnnots(); |
| 278 pSDKDoc->GetXFADocument()->SetSDKDoc(nullptr); | 280 pSDKDoc->GetXFADocument()->SetSDKDoc(nullptr); |
| 279 } | 281 } |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 return; | 720 return; |
| 719 | 721 |
| 720 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 722 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 721 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); | 723 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
| 722 if (!pPDFPage) | 724 if (!pPDFPage) |
| 723 return; | 725 return; |
| 724 | 726 |
| 725 if (!pSDKDoc->GetPageView(pPage, false)) | 727 if (!pSDKDoc->GetPageView(pPage, false)) |
| 726 return; | 728 return; |
| 727 | 729 |
| 728 CPDFSDK_Environment* pEnv = pSDKDoc->GetEnv(); | 730 CPDFSDK_FormFillEnvironment* pEnv = pSDKDoc->GetEnv(); |
| 729 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 731 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 730 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; | 732 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; |
| 731 CPDF_AAction aa(pPageDict->GetDictFor("AA")); | 733 CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
| 732 if (FPDFPAGE_AACTION_OPEN == aaType) { | 734 if (FPDFPAGE_AACTION_OPEN == aaType) { |
| 733 if (aa.ActionExist(CPDF_AAction::OpenPage)) { | 735 if (aa.ActionExist(CPDF_AAction::OpenPage)) { |
| 734 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 736 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
| 735 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 737 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
| 736 } | 738 } |
| 737 } else { | 739 } else { |
| 738 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 740 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
| 739 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 741 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
| 740 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 742 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
| 741 } | 743 } |
| 742 } | 744 } |
| 743 } | 745 } |
| OLD | NEW |