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> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( | 40 CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( |
| 41 FPDF_FORMHANDLE handle) { | 41 FPDF_FORMHANDLE handle) { |
| 42 return static_cast<CPDFSDK_FormFillEnvironment*>(handle); | 42 return static_cast<CPDFSDK_FormFillEnvironment*>(handle); |
| 43 } | 43 } |
| 44 | 44 |
| 45 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { | 45 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
| 46 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 46 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 47 HandleToCPDFSDKEnvironment(hHandle); | 47 HandleToCPDFSDKEnvironment(hHandle); |
| 48 return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetInterForm() | 48 return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr; |
| 49 : nullptr; | |
| 50 } | 49 } |
| 51 | 50 |
| 52 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, | 51 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 53 FPDF_PAGE page) { | 52 FPDF_PAGE page) { |
| 54 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 53 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 55 if (!pPage) | 54 if (!pPage) |
| 56 return nullptr; | 55 return nullptr; |
| 57 | 56 |
| 58 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 57 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 59 HandleToCPDFSDKEnvironment(hHandle); | 58 HandleToCPDFSDKEnvironment(hHandle); |
| 60 return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true) | 59 return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr; |
| 61 : nullptr; | |
| 62 } | 60 } |
| 63 | 61 |
| 64 #ifdef PDF_ENABLE_XFA | 62 #ifdef PDF_ENABLE_XFA |
| 65 std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) { | 63 std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) { |
| 66 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle); | 64 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle); |
| 67 } | 65 } |
| 68 | 66 |
| 69 FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) { | 67 FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) { |
| 70 return reinterpret_cast<FPDF_STRINGHANDLE>(strings); | 68 return reinterpret_cast<FPDF_STRINGHANDLE>(strings); |
| 71 } | 69 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 if (flags & FPDF_GRAYSCALE) { | 122 if (flags & FPDF_GRAYSCALE) { |
| 125 options.m_ColorMode = RENDER_COLOR_GRAY; | 123 options.m_ColorMode = RENDER_COLOR_GRAY; |
| 126 options.m_ForeColor = 0; | 124 options.m_ForeColor = 0; |
| 127 options.m_BackColor = 0xffffff; | 125 options.m_BackColor = 0xffffff; |
| 128 } | 126 } |
| 129 options.m_AddFlags = flags >> 8; | 127 options.m_AddFlags = flags >> 8; |
| 130 options.m_bDrawAnnots = flags & FPDF_ANNOT; | 128 options.m_bDrawAnnots = flags & FPDF_ANNOT; |
| 131 | 129 |
| 132 #ifdef PDF_ENABLE_XFA | 130 #ifdef PDF_ENABLE_XFA |
| 133 options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View); | 131 options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View); |
| 134 if (CPDFSDK_PageView* pPageView = | 132 if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true)) |
| 135 pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true)) | |
| 136 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); | 133 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); |
| 137 #else // PDF_ENABLE_XFA | 134 #else // PDF_ENABLE_XFA |
| 138 options.m_pOCContext = | 135 options.m_pOCContext = |
| 139 new CPDF_OCContext(pPage->m_pDocument, CPDF_OCContext::View); | 136 new CPDF_OCContext(pPage->m_pDocument, CPDF_OCContext::View); |
| 140 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) | 137 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) |
| 141 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); | 138 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); |
| 142 #endif // PDF_ENABLE_XFA | 139 #endif // PDF_ENABLE_XFA |
| 143 | 140 |
| 144 pDevice->RestoreState(false); | 141 pDevice->RestoreState(false); |
| 145 delete options.m_pOCContext; | 142 delete options.m_pOCContext; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 const int kRequiredVersion = 1; | 239 const int kRequiredVersion = 1; |
| 243 #endif // PDF_ENABLE_XFA | 240 #endif // PDF_ENABLE_XFA |
| 244 if (!formInfo || formInfo->version != kRequiredVersion) | 241 if (!formInfo || formInfo->version != kRequiredVersion) |
| 245 return nullptr; | 242 return nullptr; |
| 246 | 243 |
| 247 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); | 244 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
| 248 if (!pDocument) | 245 if (!pDocument) |
| 249 return nullptr; | 246 return nullptr; |
| 250 | 247 |
| 251 #ifdef PDF_ENABLE_XFA | 248 #ifdef PDF_ENABLE_XFA |
| 252 // If the CPDFXFA_Document has a SDKDocument already then we've done this | 249 // If the CPDFXFA_Document has a FormFillEnvironment already then we've done |
| 253 // and can just return the old Env. Otherwise, we'll end up setting a new | 250 // thi and can just return the old Env. Otherwise, we'll end up setting a new |
|
Tom Sepez
2016/10/11 16:47:21
nit: this
| |
| 254 // SDKDocument into the XFADocument and, that could get weird. | 251 // environment into the XFADocument and, that could get weird. |
| 255 if (pDocument->GetFormFillEnv()) | 252 if (pDocument->GetFormFillEnv()) |
| 256 return pDocument->GetFormFillEnv(); | 253 return pDocument->GetFormFillEnv(); |
| 257 #endif | 254 #endif |
| 258 | 255 |
| 259 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 256 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 260 new CPDFSDK_FormFillEnvironment(pDocument, formInfo); | 257 new CPDFSDK_FormFillEnvironment(pDocument, formInfo); |
| 261 | 258 |
| 262 #ifdef PDF_ENABLE_XFA | 259 #ifdef PDF_ENABLE_XFA |
| 263 pDocument->SetFormFillEnv(pFormFillEnv); | 260 pDocument->SetFormFillEnv(pFormFillEnv); |
| 264 CPDFXFA_App::GetInstance()->AddFormFillEnv(pFormFillEnv); | 261 CPDFXFA_App::GetInstance()->AddFormFillEnv(pFormFillEnv); |
| 265 #endif // PDF_ENABLE_XFA | 262 #endif // PDF_ENABLE_XFA |
| 266 | 263 |
| 267 return pFormFillEnv; | 264 return pFormFillEnv; |
| 268 } | 265 } |
| 269 | 266 |
| 270 DLLEXPORT void STDCALL | 267 DLLEXPORT void STDCALL |
| 271 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { | 268 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
| 272 if (!hHandle) | 269 if (!hHandle) |
| 273 return; | 270 return; |
| 274 | 271 |
| 275 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 272 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 276 HandleToCPDFSDKEnvironment(hHandle); | 273 HandleToCPDFSDKEnvironment(hHandle); |
| 277 | 274 |
| 278 #ifdef PDF_ENABLE_XFA | 275 #ifdef PDF_ENABLE_XFA |
| 279 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pFormFillEnv); | 276 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pFormFillEnv); |
| 280 | 277 |
| 281 // Reset the focused annotations and remove the SDK document from the | 278 // Reset the focused annotations and remove the SDK document from the |
| 282 // XFA document. | 279 // XFA document. |
| 283 pFormFillEnv->GetSDKDocument()->ClearAllFocusedAnnots(); | 280 pFormFillEnv->ClearAllFocusedAnnots(); |
| 284 // 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 |
| 285 // is now a nullptr. | 282 // is now a nullptr. |
| 286 if (pFormFillEnv->GetSDKDocument()->GetXFADocument()) | 283 if (pFormFillEnv->GetXFADocument()) |
| 287 pFormFillEnv->GetSDKDocument()->GetXFADocument()->SetFormFillEnv(nullptr); | 284 pFormFillEnv->GetXFADocument()->SetFormFillEnv(nullptr); |
| 288 #endif // PDF_ENABLE_XFA | 285 #endif // PDF_ENABLE_XFA |
| 289 | 286 |
| 290 delete pFormFillEnv; | 287 delete pFormFillEnv; |
| 291 } | 288 } |
| 292 | 289 |
| 293 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, | 290 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 294 FPDF_PAGE page, | 291 FPDF_PAGE page, |
| 295 int modifier, | 292 int modifier, |
| 296 double page_x, | 293 double page_x, |
| 297 double page_y) { | 294 double page_y) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 return FALSE; | 385 return FALSE; |
| 389 | 386 |
| 390 return pPageView->OnChar(nChar, modifier); | 387 return pPageView->OnChar(nChar, modifier); |
| 391 } | 388 } |
| 392 | 389 |
| 393 DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { | 390 DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
| 394 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 391 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 395 HandleToCPDFSDKEnvironment(hHandle); | 392 HandleToCPDFSDKEnvironment(hHandle); |
| 396 if (!pFormFillEnv) | 393 if (!pFormFillEnv) |
| 397 return FALSE; | 394 return FALSE; |
| 398 return pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); | 395 return pFormFillEnv->KillFocusAnnot(0); |
| 399 } | 396 } |
| 400 | 397 |
| 401 DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, | 398 DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 402 FPDF_BITMAP bitmap, | 399 FPDF_BITMAP bitmap, |
| 403 FPDF_PAGE page, | 400 FPDF_PAGE page, |
| 404 int start_x, | 401 int start_x, |
| 405 int start_y, | 402 int start_y, |
| 406 int size_x, | 403 int size_x, |
| 407 int size_y, | 404 int size_y, |
| 408 int rotate, | 405 int rotate, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 | 664 |
| 668 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 665 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 669 HandleToCPDFSDKEnvironment(hHandle); | 666 HandleToCPDFSDKEnvironment(hHandle); |
| 670 if (!pFormFillEnv) | 667 if (!pFormFillEnv) |
| 671 return; | 668 return; |
| 672 | 669 |
| 673 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 670 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 674 if (!pPage) | 671 if (!pPage) |
| 675 return; | 672 return; |
| 676 | 673 |
| 677 CPDFSDK_PageView* pPageView = | 674 CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); |
| 678 pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); | |
| 679 if (pPageView) { | 675 if (pPageView) { |
| 680 pPageView->SetValid(FALSE); | 676 pPageView->SetValid(FALSE); |
| 681 // RemovePageView() takes care of the delete for us. | 677 // RemovePageView() takes care of the delete for us. |
| 682 pFormFillEnv->GetSDKDocument()->RemovePageView(pPage); | 678 pFormFillEnv->RemovePageView(pPage); |
| 683 } | 679 } |
| 684 } | 680 } |
| 685 | 681 |
| 686 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { | 682 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
| 687 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 683 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 688 HandleToCPDFSDKEnvironment(hHandle); | 684 HandleToCPDFSDKEnvironment(hHandle); |
| 689 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) | 685 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
| 690 pFormFillEnv->GetSDKDocument()->ProcJavascriptFun(); | 686 pFormFillEnv->ProcJavascriptFun(); |
| 691 } | 687 } |
| 692 | 688 |
| 693 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { | 689 DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
| 694 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 690 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 695 HandleToCPDFSDKEnvironment(hHandle); | 691 HandleToCPDFSDKEnvironment(hHandle); |
| 696 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) | 692 if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
| 697 pFormFillEnv->GetSDKDocument()->ProcOpenAction(); | 693 pFormFillEnv->ProcOpenAction(); |
| 698 } | 694 } |
| 699 | 695 |
| 700 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, | 696 DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 701 int aaType) { | 697 int aaType) { |
| 702 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 698 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 703 HandleToCPDFSDKEnvironment(hHandle); | 699 HandleToCPDFSDKEnvironment(hHandle); |
| 704 if (!pFormFillEnv) | 700 if (!pFormFillEnv) |
| 705 return; | 701 return; |
| 706 | 702 |
| 707 CPDF_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 703 CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); |
| 708 CPDF_Dictionary* pDic = pDoc->GetRoot(); | 704 CPDF_Dictionary* pDic = pDoc->GetRoot(); |
| 709 if (!pDic) | 705 if (!pDic) |
| 710 return; | 706 return; |
| 711 | 707 |
| 712 CPDF_AAction aa(pDic->GetDictFor("AA")); | 708 CPDF_AAction aa(pDic->GetDictFor("AA")); |
| 713 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { | 709 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { |
| 714 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); | 710 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); |
| 715 CPDFSDK_ActionHandler* pActionHandler = | 711 CPDFSDK_ActionHandler* pActionHandler = |
| 716 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); | 712 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); |
| 717 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, | 713 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 728 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 724 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 729 HandleToCPDFSDKEnvironment(hHandle); | 725 HandleToCPDFSDKEnvironment(hHandle); |
| 730 if (!pFormFillEnv) | 726 if (!pFormFillEnv) |
| 731 return; | 727 return; |
| 732 | 728 |
| 733 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 729 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 734 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); | 730 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
| 735 if (!pPDFPage) | 731 if (!pPDFPage) |
| 736 return; | 732 return; |
| 737 | 733 |
| 738 if (!pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false)) | 734 if (!pFormFillEnv->GetPageView(pPage, false)) |
| 739 return; | 735 return; |
| 740 | 736 |
| 741 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); | 737 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); |
| 742 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; | 738 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; |
| 743 CPDF_AAction aa(pPageDict->GetDictFor("AA")); | 739 CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
| 744 if (FPDFPAGE_AACTION_OPEN == aaType) { | 740 if (FPDFPAGE_AACTION_OPEN == aaType) { |
| 745 if (aa.ActionExist(CPDF_AAction::OpenPage)) { | 741 if (aa.ActionExist(CPDF_AAction::OpenPage)) { |
| 746 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 742 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
| 747 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, | 743 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, |
| 748 pFormFillEnv); | 744 pFormFillEnv); |
| 749 } | 745 } |
| 750 } else { | 746 } else { |
| 751 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 747 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
| 752 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 748 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
| 753 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, | 749 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, |
| 754 pFormFillEnv); | 750 pFormFillEnv); |
| 755 } | 751 } |
| 756 } | 752 } |
| 757 } | 753 } |
| OLD | NEW |