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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 #else // PDF_ENABLE_XFA | 235 #else // PDF_ENABLE_XFA |
236 const int kRequiredVersion = 1; | 236 const int kRequiredVersion = 1; |
237 #endif // PDF_ENABLE_XFA | 237 #endif // PDF_ENABLE_XFA |
238 if (!formInfo || formInfo->version != kRequiredVersion) | 238 if (!formInfo || formInfo->version != kRequiredVersion) |
239 return nullptr; | 239 return nullptr; |
240 | 240 |
241 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); | 241 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
242 if (!pDocument) | 242 if (!pDocument) |
243 return nullptr; | 243 return nullptr; |
244 | 244 |
| 245 #ifdef PDF_ENABLE_XFA |
| 246 // If the CPDFXFA_Document has a SDKDocument already then we've done this |
| 247 // and can just return the old Env. Otherwise, we'll end up setting a new |
| 248 // SDKDocument into the XFADocument and, that could get weird. |
| 249 if (pDocument->GetSDKDoc()) |
| 250 return pDocument->GetSDKDoc()->GetEnv(); |
| 251 #endif |
| 252 |
245 CPDFSDK_Environment* pEnv = new CPDFSDK_Environment(pDocument, formInfo); | 253 CPDFSDK_Environment* pEnv = new CPDFSDK_Environment(pDocument, formInfo); |
| 254 |
246 #ifdef PDF_ENABLE_XFA | 255 #ifdef PDF_ENABLE_XFA |
247 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); | 256 // Ownership of the SDKDocument is passed to the CPDFXFA_Document. |
248 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); | 257 pDocument->SetSDKDoc(WrapUnique(pEnv->GetSDKDocument())); |
249 pApp->AddFormFillEnv(pEnv); | 258 CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); |
250 #else // PDF_ENABLE_XFA | |
251 pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); | |
252 #endif // PDF_ENABLE_XFA | 259 #endif // PDF_ENABLE_XFA |
| 260 |
253 return pEnv; | 261 return pEnv; |
254 } | 262 } |
255 | 263 |
256 DLLEXPORT void STDCALL | 264 DLLEXPORT void STDCALL |
257 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { | 265 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
258 if (!hHandle) | 266 if (!hHandle) |
259 return; | 267 return; |
| 268 |
260 CPDFSDK_Environment* pEnv = HandleToCPDFSDKEnvironment(hHandle); | 269 CPDFSDK_Environment* pEnv = HandleToCPDFSDKEnvironment(hHandle); |
| 270 |
261 #ifdef PDF_ENABLE_XFA | 271 #ifdef PDF_ENABLE_XFA |
262 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); | 272 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv); |
263 pApp->RemoveFormFillEnv(pEnv); | |
264 #else // PDF_ENABLE_XFA | 273 #else // PDF_ENABLE_XFA |
265 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { | 274 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
266 pEnv->SetSDKDocument(nullptr); | 275 pEnv->SetSDKDocument(nullptr); |
267 delete pSDKDoc; | 276 delete pSDKDoc; |
268 } | 277 } |
269 #endif // PDF_ENABLE_XFA | 278 #endif // PDF_ENABLE_XFA |
| 279 |
270 delete pEnv; | 280 delete pEnv; |
271 } | 281 } |
272 | 282 |
273 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, | 283 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
274 FPDF_PAGE page, | 284 FPDF_PAGE page, |
275 int modifier, | 285 int modifier, |
276 double page_x, | 286 double page_x, |
277 double page_y) { | 287 double page_y) { |
278 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); | 288 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
279 if (!pPageView) | 289 if (!pPageView) |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 732 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
723 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 733 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
724 } | 734 } |
725 } else { | 735 } else { |
726 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 736 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
727 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 737 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
728 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 738 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
729 } | 739 } |
730 } | 740 } |
731 } | 741 } |
OLD | NEW |