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" |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 19 | #include "core/fxge/cfx_defaultrenderdevice.h" |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_actionhandler.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Dan Sinclair | 00d47a6 | 2018-03-28 18:39:04 +0000 | [diff] [blame] | 22 | #include "fpdfsdk/cpdfsdk_helpers.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 23 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 24 | #include "fpdfsdk/cpdfsdk_pageview.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" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 32 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 33 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 34 | #include "xfa/fxfa/cxfa_ffwidget.h" |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 35 | |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 36 | static_assert(static_cast<int>(FormType::kNone) == FORMTYPE_NONE, |
| 37 | "None form types must match"); |
| 38 | static_assert(static_cast<int>(FormType::kAcroForm) == FORMTYPE_ACRO_FORM, |
| 39 | "AcroForm form types must match"); |
| 40 | static_assert(static_cast<int>(FormType::kXFAFull) == FORMTYPE_XFA_FULL, |
| 41 | "XFA full form types must match"); |
| 42 | static_assert(static_cast<int>(FormType::kXFAForeground) == |
| 43 | FORMTYPE_XFA_FOREGROUND, |
| 44 | "XFA foreground form types must match"); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 45 | #endif // PDF_ENABLE_XFA |
| 46 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 47 | static_assert(static_cast<int>(FormFieldType::kUnknown) == |
| 48 | FPDF_FORMFIELD_UNKNOWN, |
| 49 | "Unknown form field types must match"); |
| 50 | static_assert(static_cast<int>(FormFieldType::kPushButton) == |
| 51 | FPDF_FORMFIELD_PUSHBUTTON, |
| 52 | "PushButton form field types must match"); |
| 53 | static_assert(static_cast<int>(FormFieldType::kCheckBox) == |
| 54 | FPDF_FORMFIELD_CHECKBOX, |
| 55 | "CheckBox form field types must match"); |
| 56 | static_assert(static_cast<int>(FormFieldType::kRadioButton) == |
| 57 | FPDF_FORMFIELD_RADIOBUTTON, |
| 58 | "RadioButton form field types must match"); |
| 59 | static_assert(static_cast<int>(FormFieldType::kComboBox) == |
| 60 | FPDF_FORMFIELD_COMBOBOX, |
| 61 | "ComboBox form field types must match"); |
| 62 | static_assert(static_cast<int>(FormFieldType::kListBox) == |
| 63 | FPDF_FORMFIELD_LISTBOX, |
| 64 | "ListBox form field types must match"); |
| 65 | static_assert(static_cast<int>(FormFieldType::kTextField) == |
| 66 | FPDF_FORMFIELD_TEXTFIELD, |
| 67 | "TextField form field types must match"); |
| 68 | static_assert(static_cast<int>(FormFieldType::kSignature) == |
| 69 | FPDF_FORMFIELD_SIGNATURE, |
| 70 | "Signature form field types must match"); |
| 71 | #ifdef PDF_ENABLE_XFA |
| 72 | static_assert(static_cast<int>(FormFieldType::kXFA) == FPDF_FORMFIELD_XFA, |
| 73 | "XFA form field types must match"); |
Ryan Harrison | 2056fac | 2018-01-16 16:06:45 +0000 | [diff] [blame] | 74 | static_assert(static_cast<int>(FormFieldType::kXFA_CheckBox) == |
| 75 | FPDF_FORMFIELD_XFA_CHECKBOX, |
| 76 | "XFA CheckBox form field types must match"); |
| 77 | static_assert(static_cast<int>(FormFieldType::kXFA_ComboBox) == |
| 78 | FPDF_FORMFIELD_XFA_COMBOBOX, |
| 79 | "XFA ComboBox form field types must match"); |
| 80 | static_assert(static_cast<int>(FormFieldType::kXFA_ImageField) == |
| 81 | FPDF_FORMFIELD_XFA_IMAGEFIELD, |
| 82 | "XFA ImageField form field types must match"); |
| 83 | static_assert(static_cast<int>(FormFieldType::kXFA_ListBox) == |
| 84 | FPDF_FORMFIELD_XFA_LISTBOX, |
| 85 | "XFA ListBox form field types must match"); |
| 86 | static_assert(static_cast<int>(FormFieldType::kXFA_PushButton) == |
| 87 | FPDF_FORMFIELD_XFA_PUSHBUTTON, |
| 88 | "XFA PushButton form field types must match"); |
| 89 | static_assert(static_cast<int>(FormFieldType::kXFA_Signature) == |
| 90 | FPDF_FORMFIELD_XFA_SIGNATURE, |
| 91 | "XFA Signature form field types must match"); |
| 92 | static_assert(static_cast<int>(FormFieldType::kXFA_TextField) == |
| 93 | FPDF_FORMFIELD_XFA_TEXTFIELD, |
| 94 | "XFA TextField form field types must match"); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 95 | #endif // PDF_ENABLE_XFA |
| 96 | static_assert(kFormFieldTypeCount == FPDF_FORMFIELD_COUNT, |
| 97 | "Number of form field types must match"); |
| 98 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 99 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 101 | CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( |
| 102 | FPDF_FORMHANDLE handle) { |
| 103 | return static_cast<CPDFSDK_FormFillEnvironment*>(handle); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 107 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 108 | HandleToCPDFSDKEnvironment(hHandle); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 109 | return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 110 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 111 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 113 | FPDF_PAGE page) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 114 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 115 | if (!pPage) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | return nullptr; |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 117 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 118 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 119 | HandleToCPDFSDKEnvironment(hHandle); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 120 | return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 121 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 122 | |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 123 | void FFLCommon(FPDF_FORMHANDLE hHandle, |
| 124 | FPDF_BITMAP bitmap, |
| 125 | FPDF_RECORDER recorder, |
| 126 | FPDF_PAGE page, |
| 127 | int start_x, |
| 128 | int start_y, |
| 129 | int size_x, |
| 130 | int size_y, |
| 131 | int rotate, |
| 132 | int flags) { |
| 133 | if (!hHandle) |
| 134 | return; |
| 135 | |
| 136 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 137 | if (!pPage) |
| 138 | return; |
| 139 | |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 140 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 141 | CPDFXFA_Context* pContext = pPage->GetContext(); |
| 142 | if (!pContext) |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 143 | return; |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 144 | CPDF_Document* pPDFDoc = pContext->GetPDFDoc(); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 145 | if (!pPDFDoc) |
| 146 | return; |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 147 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 148 | HandleToCPDFSDKEnvironment(hHandle); |
| 149 | if (!pFormFillEnv) |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 150 | return; |
| 151 | #endif // PDF_ENABLE_XFA |
| 152 | |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 153 | const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); |
| 154 | CFX_Matrix matrix = pPage->GetDisplayMatrix(rect, rotate); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 155 | |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 156 | auto pDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 157 | #ifdef _SKIA_SUPPORT_ |
| 158 | pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder)); |
| 159 | #endif |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 160 | RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap)); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 161 | pDevice->Attach(holder, false, nullptr, false); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 162 | { |
| 163 | CFX_RenderDevice::StateRestorer restorer(pDevice.get()); |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 164 | pDevice->SetClip_Rect(rect); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 165 | |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 166 | CPDF_RenderOptions options; |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 167 | uint32_t option_flags = options.GetFlags(); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 168 | if (flags & FPDF_LCD_TEXT) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 169 | option_flags |= RENDER_CLEARTYPE; |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 170 | else |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 171 | option_flags &= ~RENDER_CLEARTYPE; |
| 172 | options.SetFlags(option_flags); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 173 | |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 174 | // Grayscale output |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 175 | if (flags & FPDF_GRAYSCALE) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 176 | options.SetColorMode(CPDF_RenderOptions::kGray); |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 177 | |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 178 | options.SetDrawAnnots(flags & FPDF_ANNOT); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 179 | |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 180 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 181 | options.SetOCContext( |
| 182 | pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View)); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 183 | if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true)) |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 184 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, rect); |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 185 | #else // PDF_ENABLE_XFA |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 186 | options.SetOCContext(pdfium::MakeRetain<CPDF_OCContext>( |
| 187 | pPage->m_pDocument.Get(), CPDF_OCContext::View)); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 188 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) |
| 189 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 190 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 191 | } |
caryclark | 8f87550 | 2016-12-06 13:49:34 -0800 | [diff] [blame] | 192 | #ifdef _SKIA_SUPPORT_PATHS_ |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 193 | pDevice->Flush(true); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 194 | holder->UnPreMultiply(); |
caryclark | 687fbde | 2016-11-22 12:44:25 -0800 | [diff] [blame] | 195 | #endif |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 198 | } // namespace |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 199 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 200 | FPDF_EXPORT int FPDF_CALLCONV |
| 201 | FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 202 | FPDF_PAGE page, |
| 203 | double page_x, |
| 204 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 205 | if (!hHandle) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 206 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 207 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | if (pPage) { |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 209 | CPDF_InterForm interform(pPage->m_pDocument.Get()); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 210 | CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 211 | pPage, |
| 212 | CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 213 | nullptr); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 214 | if (!pFormCtrl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 217 | return pFormField ? static_cast<int>(pFormField->GetFieldType()) : -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 220 | #ifdef PDF_ENABLE_XFA |
| 221 | CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page); |
| 222 | if (!pXFAPage) |
| 223 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 224 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 225 | CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 226 | if (!pPageView) |
| 227 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 229 | CXFA_FFDocView* pDocView = pPageView->GetDocView(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 230 | if (!pDocView) |
| 231 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 233 | CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 234 | if (!pWidgetHandler) |
| 235 | return -1; |
| 236 | |
tsepez | cc4d6d8 | 2016-05-16 13:21:03 -0700 | [diff] [blame] | 237 | std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 238 | pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, |
| 239 | XFA_WidgetStatus_Viewable)); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 240 | if (!pWidgetIterator) |
| 241 | return -1; |
| 242 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 243 | CXFA_FFWidget* pXFAAnnot; |
| 244 | while ((pXFAAnnot = pWidgetIterator->MoveToNext()) != nullptr) { |
Henrique Nakashima | 1087ebc | 2018-02-16 19:31:39 +0000 | [diff] [blame] | 245 | if (pXFAAnnot->GetFormFieldType() == FormFieldType::kXFA) |
| 246 | continue; |
| 247 | |
| 248 | CFX_RectF rcBBox = pXFAAnnot->GetWidgetRect(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 249 | CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 250 | rcBBox.top + rcBBox.height); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 251 | rcWidget.Inflate(1.0f, 1.0f); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 252 | if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x), |
| 253 | static_cast<float>(page_y)))) { |
Ryan Harrison | 2056fac | 2018-01-16 16:06:45 +0000 | [diff] [blame] | 254 | return static_cast<int>(pXFAAnnot->GetFormFieldType()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 256 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 257 | #endif // PDF_ENABLE_XFA |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 258 | return -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 261 | FPDF_EXPORT int FPDF_CALLCONV |
| 262 | FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
| 263 | FPDF_PAGE page, |
| 264 | double page_x, |
| 265 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 266 | if (!hHandle) |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 267 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 268 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 269 | if (!pPage) |
| 270 | return -1; |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 271 | CPDF_InterForm interform(pPage->m_pDocument.Get()); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 272 | int z_order = -1; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 273 | (void)interform.GetControlAtPoint( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 274 | pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 275 | &z_order); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 276 | return z_order; |
| 277 | } |
| 278 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 279 | FPDF_EXPORT FPDF_FORMHANDLE FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| 281 | FPDF_FORMFILLINFO* formInfo) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 282 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 283 | const int kRequiredVersion = 2; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 284 | #else // PDF_ENABLE_XFA |
| 285 | const int kRequiredVersion = 1; |
| 286 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 287 | if (!formInfo || formInfo->version != kRequiredVersion) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 289 | |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame^] | 290 | auto* pDocument = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 291 | if (!pDocument) |
| 292 | return nullptr; |
| 293 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 294 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 295 | // If the CPDFXFA_Context has a FormFillEnvironment already then we've done |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 296 | // this and can just return the old Env. Otherwise, we'll end up setting a new |
| 297 | // environment into the XFADocument and, that could get weird. |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame^] | 298 | auto* pContext = static_cast<CPDFXFA_Context*>(pDocument->GetExtension()); |
| 299 | if (pContext->GetFormFillEnv()) |
| 300 | return pContext->GetFormFillEnv(); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 301 | #endif |
| 302 | |
Tom Sepez | da8063f | 2018-04-30 17:41:49 +0000 | [diff] [blame] | 303 | auto pFormFillEnv = pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>( |
| 304 | CPDFDocumentFromFPDFDocument(document), formInfo); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 305 | |
| 306 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame^] | 307 | pContext->SetFormFillEnv(pFormFillEnv.get()); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 308 | #endif // PDF_ENABLE_XFA |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 309 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 310 | return pFormFillEnv.release(); // Caller takes ownership. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 313 | FPDF_EXPORT void FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 314 | FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 315 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 316 | HandleToCPDFSDKEnvironment(hHandle); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 317 | if (!pFormFillEnv) |
| 318 | return; |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 319 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 320 | #ifdef PDF_ENABLE_XFA |
dsinclair | 2116105 | 2016-10-05 15:46:15 -0700 | [diff] [blame] | 321 | // Reset the focused annotations and remove the SDK document from the |
| 322 | // XFA document. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 323 | pFormFillEnv->ClearAllFocusedAnnots(); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 324 | // If the document was closed first, it's possible the XFA document |
| 325 | // is now a nullptr. |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 326 | if (pFormFillEnv->GetXFAContext()) |
| 327 | pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 328 | #endif // PDF_ENABLE_XFA |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 329 | delete pFormFillEnv; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 332 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 333 | FPDF_PAGE page, |
| 334 | int modifier, |
| 335 | double page_x, |
| 336 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 338 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 339 | return false; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 340 | return pPageView->OnMouseMove(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Lei Zhang | 63b0126 | 2017-08-31 08:54:46 -0700 | [diff] [blame] | 343 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnFocus(FPDF_FORMHANDLE hHandle, |
| 344 | FPDF_PAGE page, |
| 345 | int modifier, |
| 346 | double page_x, |
| 347 | double page_y) { |
| 348 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 349 | if (!pPageView) |
| 350 | return false; |
| 351 | return pPageView->OnFocus(CFX_PointF(page_x, page_y), modifier); |
| 352 | } |
| 353 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 354 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, |
| 355 | FPDF_PAGE page, |
| 356 | int modifier, |
| 357 | double page_x, |
| 358 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 360 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 361 | return false; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 362 | return pPageView->OnLButtonDown(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 365 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, |
| 366 | FPDF_PAGE page, |
| 367 | int modifier, |
| 368 | double page_x, |
| 369 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 371 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 372 | return false; |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 373 | return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 376 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 377 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| 378 | FPDF_PAGE page, |
| 379 | int modifier, |
| 380 | double page_x, |
| 381 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 383 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 384 | return false; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 385 | return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 388 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| 389 | FPDF_PAGE page, |
| 390 | int modifier, |
| 391 | double page_x, |
| 392 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 394 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 395 | return false; |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 396 | return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 397 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 398 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 399 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 400 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
| 401 | FPDF_PAGE page, |
| 402 | int nKeyCode, |
| 403 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 404 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 405 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 406 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | return pPageView->OnKeyDown(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 410 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, |
| 411 | FPDF_PAGE page, |
| 412 | int nKeyCode, |
| 413 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 415 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 416 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | return pPageView->OnKeyUp(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 420 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnChar(FPDF_FORMHANDLE hHandle, |
| 421 | FPDF_PAGE page, |
| 422 | int nChar, |
| 423 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 425 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 426 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 427 | return pPageView->OnChar(nChar, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 430 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 431 | FORM_GetFocusedText(FPDF_FORMHANDLE hHandle, |
| 432 | FPDF_PAGE page, |
| 433 | void* buffer, |
| 434 | unsigned long buflen) { |
| 435 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 436 | if (!pPageView) |
| 437 | return 0; |
| 438 | |
| 439 | return Utf16EncodeMaybeCopyAndReturnLength(pPageView->GetFocusedFormText(), |
| 440 | buffer, buflen); |
| 441 | } |
| 442 | |
| 443 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 444 | FORM_GetSelectedText(FPDF_FORMHANDLE hHandle, |
| 445 | FPDF_PAGE page, |
| 446 | void* buffer, |
| 447 | unsigned long buflen) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 448 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 449 | if (!pPageView) |
| 450 | return 0; |
| 451 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 452 | return Utf16EncodeMaybeCopyAndReturnLength(pPageView->GetSelectedText(), |
| 453 | buffer, buflen); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 456 | FPDF_EXPORT void FPDF_CALLCONV FORM_ReplaceSelection(FPDF_FORMHANDLE hHandle, |
| 457 | FPDF_PAGE page, |
| 458 | FPDF_WIDESTRING wsText) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 459 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 460 | if (!pPageView) |
| 461 | return; |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 462 | |
Ryan Harrison | 875e98c | 2017-09-27 10:53:11 -0400 | [diff] [blame] | 463 | size_t len = WideString::WStringLength(wsText); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 464 | WideString wide_str_text = WideString::FromUTF16LE(wsText, len); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 465 | |
| 466 | pPageView->ReplaceSelection(wide_str_text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 469 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanUndo(FPDF_FORMHANDLE hHandle, |
| 470 | FPDF_PAGE page) { |
| 471 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 472 | if (!pPageView) |
| 473 | return false; |
| 474 | return pPageView->CanUndo(); |
| 475 | } |
| 476 | |
| 477 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanRedo(FPDF_FORMHANDLE hHandle, |
| 478 | FPDF_PAGE page) { |
| 479 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 480 | if (!pPageView) |
| 481 | return false; |
| 482 | return pPageView->CanRedo(); |
| 483 | } |
| 484 | |
| 485 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Undo(FPDF_FORMHANDLE hHandle, |
| 486 | FPDF_PAGE page) { |
| 487 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 488 | if (!pPageView) |
| 489 | return false; |
| 490 | return pPageView->Undo(); |
| 491 | } |
| 492 | |
| 493 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Redo(FPDF_FORMHANDLE hHandle, |
| 494 | FPDF_PAGE page) { |
| 495 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 496 | if (!pPageView) |
| 497 | return false; |
| 498 | return pPageView->Redo(); |
| 499 | } |
| 500 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 501 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 502 | FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 503 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 504 | HandleToCPDFSDKEnvironment(hHandle); |
| 505 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 506 | return false; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 507 | return pFormFillEnv->KillFocusAnnot(0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 510 | FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 511 | FPDF_BITMAP bitmap, |
| 512 | FPDF_PAGE page, |
| 513 | int start_x, |
| 514 | int start_y, |
| 515 | int size_x, |
| 516 | int size_y, |
| 517 | int rotate, |
| 518 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 519 | FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y, |
| 520 | rotate, flags); |
| 521 | } |
| 522 | |
| 523 | #ifdef _SKIA_SUPPORT_ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 524 | FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLRecord(FPDF_FORMHANDLE hHandle, |
| 525 | FPDF_RECORDER recorder, |
| 526 | FPDF_PAGE page, |
| 527 | int start_x, |
| 528 | int start_y, |
| 529 | int size_x, |
| 530 | int size_y, |
| 531 | int rotate, |
| 532 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 533 | FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y, |
| 534 | rotate, flags); |
| 535 | } |
| 536 | #endif |
| 537 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 538 | FPDF_EXPORT void FPDF_CALLCONV |
| 539 | FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
| 540 | int fieldType, |
| 541 | unsigned long color) { |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 542 | CPDFSDK_InterForm* interForm = FormHandleToInterForm(hHandle); |
| 543 | if (!interForm) |
| 544 | return; |
| 545 | |
| 546 | Optional<FormFieldType> cast_input = IntToFormFieldType(fieldType); |
Ryan Harrison | 2056fac | 2018-01-16 16:06:45 +0000 | [diff] [blame] | 547 | if (!cast_input) |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 548 | return; |
| 549 | |
| 550 | if (cast_input.value() == FormFieldType::kUnknown) { |
| 551 | interForm->SetAllHighlightColors(color); |
| 552 | } else { |
| 553 | interForm->SetHighlightColor(color, cast_input.value()); |
| 554 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 557 | FPDF_EXPORT void FPDF_CALLCONV |
| 558 | FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 560 | pInterForm->SetHighlightAlpha(alpha); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 563 | FPDF_EXPORT void FPDF_CALLCONV |
| 564 | FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 566 | pInterForm->RemoveAllHighLights(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 569 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 570 | FPDF_FORMHANDLE hHandle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 571 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 572 | pPageView->SetValid(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 575 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 576 | FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 577 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 578 | HandleToCPDFSDKEnvironment(hHandle); |
| 579 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 580 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 581 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 582 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 583 | if (!pPage) |
| 584 | return; |
| 585 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 586 | CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 587 | if (pPageView) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 588 | pPageView->SetValid(false); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 589 | // RemovePageView() takes care of the delete for us. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 590 | pFormFillEnv->RemovePageView(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 594 | FPDF_EXPORT void FPDF_CALLCONV |
| 595 | FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 596 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 597 | HandleToCPDFSDKEnvironment(hHandle); |
Tom Sepez | f5ca90c | 2018-02-01 02:15:44 +0000 | [diff] [blame] | 598 | if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 599 | pFormFillEnv->ProcJavascriptFun(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 602 | FPDF_EXPORT void FPDF_CALLCONV |
| 603 | FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 604 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 605 | HandleToCPDFSDKEnvironment(hHandle); |
Tom Sepez | f5ca90c | 2018-02-01 02:15:44 +0000 | [diff] [blame] | 606 | if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 607 | pFormFillEnv->ProcOpenAction(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 610 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 611 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 612 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 613 | HandleToCPDFSDKEnvironment(hHandle); |
| 614 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 615 | return; |
| 616 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 617 | CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 618 | const CPDF_Dictionary* pDict = pDoc->GetRoot(); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 619 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 620 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 621 | |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 622 | CPDF_AAction aa(pDict->GetDictFor("AA")); |
| 623 | auto type = static_cast<CPDF_AAction::AActionType>(aaType); |
| 624 | if (aa.ActionExist(type)) { |
| 625 | CPDF_Action action = aa.GetAction(type); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | CPDFSDK_ActionHandler* pActionHandler = |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 627 | HandleToCPDFSDKEnvironment(hHandle)->GetActionHandler(); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 628 | pActionHandler->DoAction_Document(action, type, pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 632 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoPageAAction(FPDF_PAGE page, |
| 633 | FPDF_FORMHANDLE hHandle, |
| 634 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 635 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 636 | HandleToCPDFSDKEnvironment(hHandle); |
| 637 | if (!pFormFillEnv) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 638 | return; |
| 639 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 640 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 641 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
Tom Sepez | de4791d | 2015-10-30 12:13:10 -0700 | [diff] [blame] | 642 | if (!pPDFPage) |
| 643 | return; |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 644 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 645 | if (!pFormFillEnv->GetPageView(pPage, false)) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 646 | return; |
| 647 | |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 648 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 649 | CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 650 | CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 651 | CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN |
| 652 | ? CPDF_AAction::OpenPage |
| 653 | : CPDF_AAction::ClosePage; |
| 654 | if (aa.ActionExist(type)) { |
| 655 | CPDF_Action action = aa.GetAction(type); |
| 656 | pActionHandler->DoAction_Page(action, type, pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 657 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 658 | } |