John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_formfill.h" |
| 8 | |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 9 | #include <memory> |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 10 | #include <vector> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 11 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/render/cpdf_renderoptions.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 16 | #include "core/fpdfdoc/cpdf_formfield.h" |
| 17 | #include "core/fpdfdoc/cpdf_interform.h" |
| 18 | #include "core/fpdfdoc/cpdf_occontext.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 19 | #include "core/fxge/cfx_fxgedevice.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 22 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 23 | #include "fpdfsdk/fsdk_actionhandler.h" |
| 24 | #include "fpdfsdk/fsdk_define.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 25 | #include "public/fpdfview.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 26 | #include "third_party/base/ptr_util.h" |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 27 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 29 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 30 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 31 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 32 | #include "xfa/fxfa/xfa_ffdocview.h" |
| 33 | #include "xfa/fxfa/xfa_ffpageview.h" |
| 34 | #include "xfa/fxfa/xfa_ffwidget.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 35 | #endif // PDF_ENABLE_XFA |
| 36 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 37 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 39 | CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( |
| 40 | FPDF_FORMHANDLE handle) { |
| 41 | return static_cast<CPDFSDK_FormFillEnvironment*>(handle); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 45 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 46 | HandleToCPDFSDKEnvironment(hHandle); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 47 | return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 48 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 51 | FPDF_PAGE page) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 52 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 53 | if (!pPage) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | return nullptr; |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 55 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 56 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 57 | HandleToCPDFSDKEnvironment(hHandle); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 58 | return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 59 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 60 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 61 | #ifdef PDF_ENABLE_XFA |
| 62 | std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) { |
| 63 | return reinterpret_cast<std::vector<CFX_ByteString>*>(handle); |
| 64 | } |
| 65 | |
| 66 | FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) { |
| 67 | return reinterpret_cast<FPDF_STRINGHANDLE>(strings); |
| 68 | } |
| 69 | #endif // PDF_ENABLE_XFA |
| 70 | |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 71 | void FFLCommon(FPDF_FORMHANDLE hHandle, |
| 72 | FPDF_BITMAP bitmap, |
| 73 | FPDF_RECORDER recorder, |
| 74 | FPDF_PAGE page, |
| 75 | int start_x, |
| 76 | int start_y, |
| 77 | int size_x, |
| 78 | int size_y, |
| 79 | int rotate, |
| 80 | int flags) { |
| 81 | if (!hHandle) |
| 82 | return; |
| 83 | |
| 84 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 85 | if (!pPage) |
| 86 | return; |
| 87 | |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 88 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 89 | CPDFXFA_Context* pContext = pPage->GetContext(); |
| 90 | if (!pContext) |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 91 | return; |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 92 | CPDF_Document* pPDFDoc = pContext->GetPDFDoc(); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 93 | if (!pPDFDoc) |
| 94 | return; |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 95 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 96 | HandleToCPDFSDKEnvironment(hHandle); |
| 97 | if (!pFormFillEnv) |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 98 | return; |
| 99 | #endif // PDF_ENABLE_XFA |
| 100 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame^] | 101 | CFX_Matrix matrix = |
| 102 | pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 103 | FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); |
| 104 | |
| 105 | std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); |
| 106 | #ifdef _SKIA_SUPPORT_ |
| 107 | pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder)); |
| 108 | #endif |
| 109 | pDevice->Attach(CFXBitmapFromFPDFBitmap(bitmap), false, nullptr, false); |
| 110 | pDevice->SaveState(); |
| 111 | pDevice->SetClip_Rect(clip); |
| 112 | |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 113 | CPDF_RenderOptions options; |
| 114 | if (flags & FPDF_LCD_TEXT) |
| 115 | options.m_Flags |= RENDER_CLEARTYPE; |
| 116 | else |
| 117 | options.m_Flags &= ~RENDER_CLEARTYPE; |
| 118 | |
| 119 | // Grayscale output |
| 120 | if (flags & FPDF_GRAYSCALE) { |
| 121 | options.m_ColorMode = RENDER_COLOR_GRAY; |
| 122 | options.m_ForeColor = 0; |
| 123 | options.m_BackColor = 0xffffff; |
| 124 | } |
| 125 | options.m_AddFlags = flags >> 8; |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 126 | options.m_bDrawAnnots = flags & FPDF_ANNOT; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 127 | |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 128 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | f716f0b | 2017-01-30 10:04:07 -0800 | [diff] [blame] | 129 | options.m_pOCContext = |
| 130 | pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 131 | if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true)) |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 132 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 133 | #else // PDF_ENABLE_XFA |
Tom Sepez | f716f0b | 2017-01-30 10:04:07 -0800 | [diff] [blame] | 134 | options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>( |
| 135 | pPage->m_pDocument, CPDF_OCContext::View); |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 136 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) |
| 137 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 138 | #endif // PDF_ENABLE_XFA |
| 139 | |
caryclark | 8f87550 | 2016-12-06 13:49:34 -0800 | [diff] [blame] | 140 | pDevice->RestoreState(false); |
| 141 | #ifdef _SKIA_SUPPORT_PATHS_ |
| 142 | pDevice->Flush(); |
caryclark | 687fbde | 2016-11-22 12:44:25 -0800 | [diff] [blame] | 143 | CFXBitmapFromFPDFBitmap(bitmap)->UnPreMultiply(); |
| 144 | #endif |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 147 | } // namespace |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 148 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 149 | DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 150 | FPDF_PAGE page, |
| 151 | double page_x, |
| 152 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 153 | if (!hHandle) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 154 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 155 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 156 | if (pPage) { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 157 | CPDF_InterForm interform(pPage->m_pDocument); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 158 | CPDF_FormControl* pFormCtrl = |
| 159 | interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x), |
| 160 | static_cast<FX_FLOAT>(page_y), nullptr); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 161 | if (!pFormCtrl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 163 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 164 | return pFormField ? pFormField->GetFieldType() : -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 167 | #ifdef PDF_ENABLE_XFA |
| 168 | CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page); |
| 169 | if (!pXFAPage) |
| 170 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 172 | CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 173 | if (!pPageView) |
| 174 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 176 | CXFA_FFDocView* pDocView = pPageView->GetDocView(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 177 | if (!pDocView) |
| 178 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 180 | CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 181 | if (!pWidgetHandler) |
| 182 | return -1; |
| 183 | |
tsepez | cc4d6d8 | 2016-05-16 13:21:03 -0700 | [diff] [blame] | 184 | std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 185 | pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, |
| 186 | XFA_WidgetStatus_Viewable)); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 187 | if (!pWidgetIterator) |
| 188 | return -1; |
| 189 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 190 | CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 191 | while (pXFAAnnot) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame^] | 192 | CFX_RectF rcBBox = pXFAAnnot->GetBBox(0); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 193 | CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 194 | rcBBox.top + rcBBox.height); |
| 195 | rcWidget.left -= 1.0f; |
| 196 | rcWidget.right += 1.0f; |
| 197 | rcWidget.bottom -= 1.0f; |
| 198 | rcWidget.top += 1.0f; |
| 199 | |
| 200 | if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x), |
| 201 | static_cast<FX_FLOAT>(page_y))) { |
| 202 | return FPDF_FORMFIELD_XFA; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | } |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 204 | pXFAAnnot = pWidgetIterator->MoveToNext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 206 | #endif // PDF_ENABLE_XFA |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 207 | return -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 210 | DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 211 | FPDF_PAGE page, |
| 212 | double page_x, |
| 213 | double page_y) { |
| 214 | return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y); |
| 215 | } |
| 216 | |
| 217 | DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
| 218 | FPDF_PAGE page, |
| 219 | double page_x, |
| 220 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 221 | if (!hHandle) |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 222 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 223 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 224 | if (!pPage) |
| 225 | return -1; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 226 | CPDF_InterForm interform(pPage->m_pDocument); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 227 | int z_order = -1; |
| 228 | (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, |
| 229 | &z_order); |
| 230 | return z_order; |
| 231 | } |
| 232 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 233 | DLLEXPORT FPDF_FORMHANDLE STDCALL |
| 234 | FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| 235 | FPDF_FORMFILLINFO* formInfo) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 236 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 237 | const int kRequiredVersion = 2; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 238 | #else // PDF_ENABLE_XFA |
| 239 | const int kRequiredVersion = 1; |
| 240 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 241 | if (!formInfo || formInfo->version != kRequiredVersion) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 243 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 244 | UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
| 245 | if (!pDocument) |
| 246 | return nullptr; |
| 247 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 248 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 249 | // If the CPDFXFA_Context has a FormFillEnvironment already then we've done |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 250 | // this and can just return the old Env. Otherwise, we'll end up setting a new |
| 251 | // environment into the XFADocument and, that could get weird. |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 252 | if (pDocument->GetFormFillEnv()) |
| 253 | return pDocument->GetFormFillEnv(); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 254 | #endif |
| 255 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 256 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 257 | new CPDFSDK_FormFillEnvironment(pDocument, formInfo); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 258 | |
| 259 | #ifdef PDF_ENABLE_XFA |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 260 | pDocument->SetFormFillEnv(pFormFillEnv); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 261 | #endif // PDF_ENABLE_XFA |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 262 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 263 | return pFormFillEnv; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 266 | DLLEXPORT void STDCALL |
| 267 | FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
| 268 | if (!hHandle) |
| 269 | return; |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 270 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 271 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 272 | HandleToCPDFSDKEnvironment(hHandle); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 273 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 274 | #ifdef PDF_ENABLE_XFA |
dsinclair | 2116105 | 2016-10-05 15:46:15 -0700 | [diff] [blame] | 275 | // Reset the focused annotations and remove the SDK document from the |
| 276 | // XFA document. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 277 | pFormFillEnv->ClearAllFocusedAnnots(); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 278 | // If the document was closed first, it's possible the XFA document |
| 279 | // is now a nullptr. |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 280 | if (pFormFillEnv->GetXFAContext()) |
| 281 | pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 282 | #endif // PDF_ENABLE_XFA |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 283 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 284 | delete pFormFillEnv; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 288 | FPDF_PAGE page, |
| 289 | int modifier, |
| 290 | double page_x, |
| 291 | double page_y) { |
| 292 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 293 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 294 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 295 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 296 | CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | return pPageView->OnMouseMove(pt, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 300 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, |
| 301 | FPDF_PAGE page, |
| 302 | int modifier, |
| 303 | double page_x, |
| 304 | double page_y) { |
| 305 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 306 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 307 | return false; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 308 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 309 | CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | return pPageView->OnLButtonDown(pt, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, |
| 314 | FPDF_PAGE page, |
| 315 | int modifier, |
| 316 | double page_x, |
| 317 | double page_y) { |
| 318 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 319 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 320 | return false; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 321 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 322 | CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 323 | return pPageView->OnLButtonUp(pt, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 326 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| 328 | FPDF_PAGE page, |
| 329 | int modifier, |
| 330 | double page_x, |
| 331 | double page_y) { |
| 332 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 333 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 334 | return false; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 335 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 336 | CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | return pPageView->OnRButtonDown(pt, modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 340 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| 341 | FPDF_PAGE page, |
| 342 | int modifier, |
| 343 | double page_x, |
| 344 | double page_y) { |
| 345 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 346 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 347 | return false; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 348 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 349 | CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | return pPageView->OnRButtonUp(pt, modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 351 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 352 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 353 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
| 355 | FPDF_PAGE page, |
| 356 | int nKeyCode, |
| 357 | int modifier) { |
| 358 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 359 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 360 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 361 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 362 | return pPageView->OnKeyDown(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 365 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, |
| 366 | FPDF_PAGE page, |
| 367 | int nKeyCode, |
| 368 | int modifier) { |
| 369 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 370 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 371 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 372 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 373 | return pPageView->OnKeyUp(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 376 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, |
| 377 | FPDF_PAGE page, |
| 378 | int nChar, |
| 379 | int modifier) { |
| 380 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 381 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 382 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 383 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 384 | return pPageView->OnChar(nChar, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 388 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 389 | HandleToCPDFSDKEnvironment(hHandle); |
| 390 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 391 | return false; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 392 | return pFormFillEnv->KillFocusAnnot(0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 395 | DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 396 | FPDF_BITMAP bitmap, |
| 397 | FPDF_PAGE page, |
| 398 | int start_x, |
| 399 | int start_y, |
| 400 | int size_x, |
| 401 | int size_y, |
| 402 | int rotate, |
| 403 | int flags) { |
| 404 | FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y, |
| 405 | rotate, flags); |
| 406 | } |
| 407 | |
| 408 | #ifdef _SKIA_SUPPORT_ |
| 409 | DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle, |
| 410 | FPDF_RECORDER recorder, |
| 411 | FPDF_PAGE page, |
| 412 | int start_x, |
| 413 | int start_y, |
| 414 | int size_x, |
| 415 | int size_y, |
| 416 | int rotate, |
| 417 | int flags) { |
| 418 | FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y, |
| 419 | rotate, flags); |
| 420 | } |
| 421 | #endif |
| 422 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 423 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, |
| 425 | FPDF_WIDGET hWidget) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 426 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 427 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 428 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 429 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 430 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 431 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 433 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 434 | static_cast<CXFA_FFWidget*>(hWidget)->Undo(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 435 | } |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 436 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 437 | DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, |
| 438 | FPDF_WIDGET hWidget) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 439 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 441 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 442 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 443 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 444 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 445 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 446 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 447 | static_cast<CXFA_FFWidget*>(hWidget)->Redo(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 450 | DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, |
| 451 | FPDF_WIDGET hWidget) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 452 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 454 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 455 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 456 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 457 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 458 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 459 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 460 | static_cast<CXFA_FFWidget*>(hWidget)->SelectAll(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 461 | } |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 462 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, |
| 464 | FPDF_WIDGET hWidget, |
| 465 | FPDF_WIDESTRING wsText, |
| 466 | FPDF_DWORD* size) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 467 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 469 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 470 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 471 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 472 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 474 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | CFX_WideString wsCpText; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 476 | static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 477 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 478 | CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 479 | uint32_t len = bsCpText.GetLength() / sizeof(unsigned short); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 480 | if (!wsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | *size = len; |
| 482 | return; |
| 483 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 484 | |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 485 | uint32_t real_size = len < *size ? len : *size; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | if (real_size > 0) { |
| 487 | FXSYS_memcpy((void*)wsText, |
| 488 | bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 489 | real_size * sizeof(unsigned short)); |
| 490 | bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 491 | } |
| 492 | *size = real_size; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 493 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 494 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, |
| 496 | FPDF_WIDGET hWidget, |
| 497 | FPDF_WIDESTRING wsText, |
| 498 | FPDF_DWORD* size) { |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 499 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | return; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 501 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 502 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 503 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 504 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 505 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 506 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 507 | CFX_WideString wsCpText; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 508 | static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 509 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 510 | CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 511 | uint32_t len = bsCpText.GetLength() / sizeof(unsigned short); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 512 | if (!wsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | *size = len; |
| 514 | return; |
| 515 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 516 | |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 517 | uint32_t real_size = len < *size ? len : *size; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | if (real_size > 0) { |
| 519 | FXSYS_memcpy((void*)wsText, |
| 520 | bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 521 | real_size * sizeof(unsigned short)); |
| 522 | bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 523 | } |
| 524 | *size = real_size; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 525 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 526 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 527 | DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, |
| 528 | FPDF_WIDGET hWidget, |
| 529 | FPDF_WIDESTRING wsText, |
| 530 | FPDF_DWORD size) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 531 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 533 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 534 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 535 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 536 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 538 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 540 | static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 541 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 542 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 543 | DLLEXPORT void STDCALL |
| 544 | FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, |
| 545 | FPDF_WIDGET hWidget, |
| 546 | float x, |
| 547 | float y, |
| 548 | FPDF_BYTESTRING bsText) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 549 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 551 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 552 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 553 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 554 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 556 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | CFX_PointF ptPopup; |
| 558 | ptPopup.x = x; |
| 559 | ptPopup.y = y; |
| 560 | CFX_ByteStringC bs(bsText); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 561 | static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 562 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 563 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | DLLEXPORT void STDCALL |
| 565 | FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, |
| 566 | FPDF_WIDGET hWidget, |
| 567 | float x, |
| 568 | float y, |
| 569 | FPDF_STRINGHANDLE* stringHandle) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 570 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 571 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 572 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 573 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
| 574 | if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 575 | pContext->GetDocType() != XFA_DOCTYPE_Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 576 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 577 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 578 | std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 579 | CFX_PointF ptPopup; |
| 580 | ptPopup.x = x; |
| 581 | ptPopup.y = y; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 582 | static_cast<CXFA_FFWidget*>(hWidget) |
| 583 | ->GetSuggestWords(ptPopup, *sSuggestWords); |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 584 | *stringHandle = ToFPDFStringHandle(sSuggestWords); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 585 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 586 | |
| 587 | DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) { |
| 588 | std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle); |
| 589 | return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 590 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 591 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | DLLEXPORT FPDF_BOOL STDCALL |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 593 | FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | int index, |
| 595 | FPDF_BYTESTRING bsText, |
| 596 | FPDF_DWORD* size) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 597 | if (!sHandle || !size) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 598 | return false; |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 599 | |
| 600 | int count = FPDF_StringHandleCounts(sHandle); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | if (index < 0 || index >= count) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 602 | return false; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 603 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 604 | std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle); |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 605 | uint32_t len = (*sSuggestWords)[index].GetLength(); |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 606 | if (!bsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 607 | *size = len; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 608 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 609 | } |
| 610 | |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 611 | uint32_t real_size = len < *size ? len : *size; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | if (real_size > 0) |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 613 | FXSYS_memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | *size = real_size; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 615 | return true; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 616 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 617 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | DLLEXPORT void STDCALL |
| 619 | FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 620 | delete FromFPDFStringHandle(stringHandle); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 623 | DLLEXPORT FPDF_BOOL STDCALL |
| 624 | FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, |
| 625 | FPDF_BYTESTRING bsText, |
| 626 | FPDF_DWORD size) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 627 | if (!stringHandle || !bsText || size == 0) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 628 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 629 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 630 | FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 631 | return true; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 632 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 633 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 634 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 635 | DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
| 636 | int fieldType, |
| 637 | unsigned long color) { |
| 638 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 639 | pInterForm->SetHighlightColor(color, fieldType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 642 | DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, |
| 643 | unsigned char alpha) { |
| 644 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 645 | pInterForm->SetHighlightAlpha(alpha); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { |
| 649 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 650 | pInterForm->RemoveAllHighLight(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 653 | DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 654 | FPDF_FORMHANDLE hHandle) { |
| 655 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 656 | pPageView->SetValid(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 659 | DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 660 | FPDF_FORMHANDLE hHandle) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 661 | if (!hHandle) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 662 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 663 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 664 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 665 | HandleToCPDFSDKEnvironment(hHandle); |
| 666 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 667 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 668 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 669 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 670 | if (!pPage) |
| 671 | return; |
| 672 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 673 | CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 674 | if (pPageView) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 675 | pPageView->SetValid(false); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 676 | // RemovePageView() takes care of the delete for us. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 677 | pFormFillEnv->RemovePageView(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
| 681 | DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 682 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 683 | HandleToCPDFSDKEnvironment(hHandle); |
| 684 | if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 685 | pFormFillEnv->ProcJavascriptFun(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 689 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 690 | HandleToCPDFSDKEnvironment(hHandle); |
| 691 | if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 692 | pFormFillEnv->ProcOpenAction(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 696 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 697 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 698 | HandleToCPDFSDKEnvironment(hHandle); |
| 699 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 700 | return; |
| 701 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 702 | CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 703 | CPDF_Dictionary* pDic = pDoc->GetRoot(); |
| 704 | if (!pDic) |
| 705 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 706 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 707 | CPDF_AAction aa(pDic->GetDictFor("AA")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { |
| 709 | CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); |
| 710 | CPDFSDK_ActionHandler* pActionHandler = |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 711 | HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 712 | pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 713 | pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | |
| 717 | DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, |
| 718 | FPDF_FORMHANDLE hHandle, |
| 719 | int aaType) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 720 | if (!hHandle) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | return; |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 722 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 723 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 724 | HandleToCPDFSDKEnvironment(hHandle); |
| 725 | if (!pFormFillEnv) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 726 | return; |
| 727 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 728 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 729 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
Tom Sepez | de4791d | 2015-10-30 12:13:10 -0700 | [diff] [blame] | 730 | if (!pPDFPage) |
| 731 | return; |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 732 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 733 | if (!pFormFillEnv->GetPageView(pPage, false)) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 734 | return; |
| 735 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 736 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 737 | CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 738 | CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 739 | if (FPDFPAGE_AACTION_OPEN == aaType) { |
| 740 | if (aa.ActionExist(CPDF_AAction::OpenPage)) { |
| 741 | CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 742 | pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, |
| 743 | pFormFillEnv); |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 744 | } |
| 745 | } else { |
| 746 | if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
| 747 | CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 748 | pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, |
| 749 | pFormFillEnv); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 750 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 752 | } |