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 | 4935770 | 2019-08-19 17:17:18 +0000 | [diff] [blame] | 10 | #include <utility> |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 11 | #include <vector> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 12 | |
Tom Sepez | 7fad4d6 | 2019-06-07 16:19:10 +0000 | [diff] [blame] | 13 | #include "core/fpdfapi/page/cpdf_occontext.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/page/cpdf_page.h" |
Lei Zhang | 8153561 | 2018-10-09 21:15:17 +0000 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 17 | #include "core/fpdfapi/render/cpdf_renderoptions.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 18 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 19 | #include "core/fpdfdoc/cpdf_formfield.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 20 | #include "core/fpdfdoc/cpdf_interactiveform.h" |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 21 | #include "core/fxge/cfx_defaultrenderdevice.h" |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 22 | #include "fpdfsdk/cpdfsdk_actionhandler.h" |
Tom Sepez | 4935770 | 2019-08-19 17:17:18 +0000 | [diff] [blame] | 23 | #include "fpdfsdk/cpdfsdk_baannothandler.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 24 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Dan Sinclair | 00d47a6 | 2018-03-28 18:39:04 +0000 | [diff] [blame] | 25 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 26 | #include "fpdfsdk/cpdfsdk_interactiveform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/cpdfsdk_pageview.h" |
Tom Sepez | 4935770 | 2019-08-19 17:17:18 +0000 | [diff] [blame] | 28 | #include "fpdfsdk/cpdfsdk_widgethandler.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 29 | #include "public/fpdfview.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 30 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 32 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 33 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 34 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Tom Sepez | 4935770 | 2019-08-19 17:17:18 +0000 | [diff] [blame] | 35 | #include "fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h" |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 36 | |
Ryan Harrison | c3cc2ab | 2018-06-21 21:09:54 +0000 | [diff] [blame] | 37 | static_assert(static_cast<int>(AlertButton::kDefault) == |
| 38 | JSPLATFORM_ALERT_BUTTON_DEFAULT, |
| 39 | "Default alert button types must match"); |
| 40 | static_assert(static_cast<int>(AlertButton::kOK) == JSPLATFORM_ALERT_BUTTON_OK, |
| 41 | "OK alert button types must match"); |
| 42 | static_assert(static_cast<int>(AlertButton::kOKCancel) == |
| 43 | JSPLATFORM_ALERT_BUTTON_OKCANCEL, |
| 44 | "OKCancel alert button types must match"); |
| 45 | static_assert(static_cast<int>(AlertButton::kYesNo) == |
| 46 | JSPLATFORM_ALERT_BUTTON_YESNO, |
| 47 | "YesNo alert button types must match"); |
| 48 | static_assert(static_cast<int>(AlertButton::kYesNoCancel) == |
| 49 | JSPLATFORM_ALERT_BUTTON_YESNOCANCEL, |
| 50 | "YesNoCancel alert button types must match"); |
| 51 | |
| 52 | static_assert(static_cast<int>(AlertIcon::kDefault) == |
| 53 | JSPLATFORM_ALERT_ICON_DEFAULT, |
| 54 | "Default alert icon types must match"); |
| 55 | static_assert(static_cast<int>(AlertIcon::kError) == |
| 56 | JSPLATFORM_ALERT_ICON_ERROR, |
| 57 | "Error alert icon types must match"); |
| 58 | static_assert(static_cast<int>(AlertIcon::kWarning) == |
| 59 | JSPLATFORM_ALERT_ICON_WARNING, |
| 60 | "Warning alert icon types must match"); |
| 61 | static_assert(static_cast<int>(AlertIcon::kQuestion) == |
| 62 | JSPLATFORM_ALERT_ICON_QUESTION, |
| 63 | "Question alert icon types must match"); |
| 64 | static_assert(static_cast<int>(AlertIcon::kStatus) == |
| 65 | JSPLATFORM_ALERT_ICON_STATUS, |
| 66 | "Status alert icon types must match"); |
| 67 | static_assert(static_cast<int>(AlertIcon::kAsterisk) == |
| 68 | JSPLATFORM_ALERT_ICON_ASTERISK, |
| 69 | "Asterisk alert icon types must match"); |
| 70 | |
| 71 | static_assert(static_cast<int>(AlertReturn::kOK) == JSPLATFORM_ALERT_RETURN_OK, |
| 72 | "OK alert return types must match"); |
| 73 | static_assert(static_cast<int>(AlertReturn::kCancel) == |
| 74 | JSPLATFORM_ALERT_RETURN_CANCEL, |
| 75 | "Cancel alert return types must match"); |
| 76 | static_assert(static_cast<int>(AlertReturn::kNo) == JSPLATFORM_ALERT_RETURN_NO, |
| 77 | "No alert return types must match"); |
| 78 | static_assert(static_cast<int>(AlertReturn::kYes) == |
| 79 | JSPLATFORM_ALERT_RETURN_YES, |
| 80 | "Yes alert return types must match"); |
| 81 | |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 82 | static_assert(static_cast<int>(FormType::kNone) == FORMTYPE_NONE, |
| 83 | "None form types must match"); |
| 84 | static_assert(static_cast<int>(FormType::kAcroForm) == FORMTYPE_ACRO_FORM, |
| 85 | "AcroForm form types must match"); |
| 86 | static_assert(static_cast<int>(FormType::kXFAFull) == FORMTYPE_XFA_FULL, |
| 87 | "XFA full form types must match"); |
| 88 | static_assert(static_cast<int>(FormType::kXFAForeground) == |
| 89 | FORMTYPE_XFA_FOREGROUND, |
| 90 | "XFA foreground form types must match"); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 91 | #endif // PDF_ENABLE_XFA |
| 92 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 93 | static_assert(static_cast<int>(FormFieldType::kUnknown) == |
| 94 | FPDF_FORMFIELD_UNKNOWN, |
| 95 | "Unknown form field types must match"); |
| 96 | static_assert(static_cast<int>(FormFieldType::kPushButton) == |
| 97 | FPDF_FORMFIELD_PUSHBUTTON, |
| 98 | "PushButton form field types must match"); |
| 99 | static_assert(static_cast<int>(FormFieldType::kCheckBox) == |
| 100 | FPDF_FORMFIELD_CHECKBOX, |
| 101 | "CheckBox form field types must match"); |
| 102 | static_assert(static_cast<int>(FormFieldType::kRadioButton) == |
| 103 | FPDF_FORMFIELD_RADIOBUTTON, |
| 104 | "RadioButton form field types must match"); |
| 105 | static_assert(static_cast<int>(FormFieldType::kComboBox) == |
| 106 | FPDF_FORMFIELD_COMBOBOX, |
| 107 | "ComboBox form field types must match"); |
| 108 | static_assert(static_cast<int>(FormFieldType::kListBox) == |
| 109 | FPDF_FORMFIELD_LISTBOX, |
| 110 | "ListBox form field types must match"); |
| 111 | static_assert(static_cast<int>(FormFieldType::kTextField) == |
| 112 | FPDF_FORMFIELD_TEXTFIELD, |
| 113 | "TextField form field types must match"); |
| 114 | static_assert(static_cast<int>(FormFieldType::kSignature) == |
| 115 | FPDF_FORMFIELD_SIGNATURE, |
| 116 | "Signature form field types must match"); |
| 117 | #ifdef PDF_ENABLE_XFA |
| 118 | static_assert(static_cast<int>(FormFieldType::kXFA) == FPDF_FORMFIELD_XFA, |
| 119 | "XFA form field types must match"); |
Ryan Harrison | 2056fac | 2018-01-16 16:06:45 +0000 | [diff] [blame] | 120 | static_assert(static_cast<int>(FormFieldType::kXFA_CheckBox) == |
| 121 | FPDF_FORMFIELD_XFA_CHECKBOX, |
| 122 | "XFA CheckBox form field types must match"); |
| 123 | static_assert(static_cast<int>(FormFieldType::kXFA_ComboBox) == |
| 124 | FPDF_FORMFIELD_XFA_COMBOBOX, |
| 125 | "XFA ComboBox form field types must match"); |
| 126 | static_assert(static_cast<int>(FormFieldType::kXFA_ImageField) == |
| 127 | FPDF_FORMFIELD_XFA_IMAGEFIELD, |
| 128 | "XFA ImageField form field types must match"); |
| 129 | static_assert(static_cast<int>(FormFieldType::kXFA_ListBox) == |
| 130 | FPDF_FORMFIELD_XFA_LISTBOX, |
| 131 | "XFA ListBox form field types must match"); |
| 132 | static_assert(static_cast<int>(FormFieldType::kXFA_PushButton) == |
| 133 | FPDF_FORMFIELD_XFA_PUSHBUTTON, |
| 134 | "XFA PushButton form field types must match"); |
| 135 | static_assert(static_cast<int>(FormFieldType::kXFA_Signature) == |
| 136 | FPDF_FORMFIELD_XFA_SIGNATURE, |
| 137 | "XFA Signature form field types must match"); |
| 138 | static_assert(static_cast<int>(FormFieldType::kXFA_TextField) == |
| 139 | FPDF_FORMFIELD_XFA_TEXTFIELD, |
| 140 | "XFA TextField form field types must match"); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 141 | #endif // PDF_ENABLE_XFA |
| 142 | static_assert(kFormFieldTypeCount == FPDF_FORMFIELD_COUNT, |
| 143 | "Number of form field types must match"); |
| 144 | |
Hans Wennborg | c320e9c | 2018-10-22 18:28:52 +0000 | [diff] [blame] | 145 | static_assert(static_cast<int>(CPDF_AAction::kCloseDocument) == |
Tom Sepez | 9ead811 | 2018-10-19 16:56:58 +0000 | [diff] [blame] | 146 | FPDFDOC_AACTION_WC, |
| 147 | "CloseDocument action must match"); |
Hans Wennborg | c320e9c | 2018-10-22 18:28:52 +0000 | [diff] [blame] | 148 | static_assert(static_cast<int>(CPDF_AAction::kSaveDocument) == |
Tom Sepez | 9ead811 | 2018-10-19 16:56:58 +0000 | [diff] [blame] | 149 | FPDFDOC_AACTION_WS, |
| 150 | "SaveDocument action must match"); |
Hans Wennborg | c320e9c | 2018-10-22 18:28:52 +0000 | [diff] [blame] | 151 | static_assert(static_cast<int>(CPDF_AAction::kDocumentSaved) == |
Tom Sepez | 9ead811 | 2018-10-19 16:56:58 +0000 | [diff] [blame] | 152 | FPDFDOC_AACTION_DS, |
| 153 | "DocumentSaved action must match"); |
Hans Wennborg | c320e9c | 2018-10-22 18:28:52 +0000 | [diff] [blame] | 154 | static_assert(static_cast<int>(CPDF_AAction::kPrintDocument) == |
Tom Sepez | 9ead811 | 2018-10-19 16:56:58 +0000 | [diff] [blame] | 155 | FPDFDOC_AACTION_WP, |
| 156 | "PrintDocument action must match"); |
Hans Wennborg | c320e9c | 2018-10-22 18:28:52 +0000 | [diff] [blame] | 157 | static_assert(static_cast<int>(CPDF_AAction::kDocumentPrinted) == |
Tom Sepez | 9ead811 | 2018-10-19 16:56:58 +0000 | [diff] [blame] | 158 | FPDFDOC_AACTION_DP, |
| 159 | "DocumentPrinted action must match"); |
| 160 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 161 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 163 | CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
Tom Sepez | dae73f5 | 2018-06-13 17:54:57 +0000 | [diff] [blame] | 164 | FPDF_PAGE fpdf_page) { |
| 165 | IPDF_Page* pPage = IPDFPageFromFPDFPage(fpdf_page); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 166 | if (!pPage) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | return nullptr; |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 168 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 169 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 170 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 171 | return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 172 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 173 | |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 174 | void FFLCommon(FPDF_FORMHANDLE hHandle, |
| 175 | FPDF_BITMAP bitmap, |
| 176 | FPDF_RECORDER recorder, |
Tom Sepez | dae73f5 | 2018-06-13 17:54:57 +0000 | [diff] [blame] | 177 | FPDF_PAGE fpdf_page, |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 178 | int start_x, |
| 179 | int start_y, |
| 180 | int size_x, |
| 181 | int size_y, |
| 182 | int rotate, |
| 183 | int flags) { |
| 184 | if (!hHandle) |
| 185 | return; |
| 186 | |
Tom Sepez | dae73f5 | 2018-06-13 17:54:57 +0000 | [diff] [blame] | 187 | IPDF_Page* pPage = IPDFPageFromFPDFPage(fpdf_page); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 188 | if (!pPage) |
| 189 | return; |
| 190 | |
Tom Sepez | ca027339 | 2018-05-25 23:37:50 +0000 | [diff] [blame] | 191 | CPDF_Document* pPDFDoc = pPage->GetDocument(); |
Tom Sepez | dae73f5 | 2018-06-13 17:54:57 +0000 | [diff] [blame] | 192 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, fpdf_page); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 193 | |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 194 | const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); |
| 195 | CFX_Matrix matrix = pPage->GetDisplayMatrix(rect, rotate); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 196 | |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 197 | auto pDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 198 | #ifdef _SKIA_SUPPORT_ |
| 199 | pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder)); |
| 200 | #endif |
Tom Sepez | dae73f5 | 2018-06-13 17:54:57 +0000 | [diff] [blame] | 201 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 202 | RetainPtr<CFX_DIBitmap> holder(CFXDIBitmapFromFPDFBitmap(bitmap)); |
Jing Wang | fd28192 | 2019-04-11 21:20:11 +0000 | [diff] [blame] | 203 | pDevice->Attach(holder, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 204 | { |
| 205 | CFX_RenderDevice::StateRestorer restorer(pDevice.get()); |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 206 | pDevice->SetClip_Rect(rect); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 207 | |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 208 | CPDF_RenderOptions options; |
Lei Zhang | b8b52b4 | 2018-11-08 19:11:22 +0000 | [diff] [blame] | 209 | options.GetOptions().bClearType = !!(flags & FPDF_LCD_TEXT); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 210 | |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 211 | // Grayscale output |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 212 | if (flags & FPDF_GRAYSCALE) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 213 | options.SetColorMode(CPDF_RenderOptions::kGray); |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 214 | |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 215 | options.SetDrawAnnots(flags & FPDF_ANNOT); |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 216 | options.SetOCContext( |
| 217 | pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View)); |
Tom Sepez | ca027339 | 2018-05-25 23:37:50 +0000 | [diff] [blame] | 218 | |
Tom Sepez | 45a5524 | 2018-05-25 23:57:13 +0000 | [diff] [blame] | 219 | if (pPageView) |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 220 | pPageView->PageView_OnDraw(pDevice.get(), matrix, &options, rect); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 221 | } |
Tom Sepez | dae73f5 | 2018-06-13 17:54:57 +0000 | [diff] [blame] | 222 | |
caryclark | 8f87550 | 2016-12-06 13:49:34 -0800 | [diff] [blame] | 223 | #ifdef _SKIA_SUPPORT_PATHS_ |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 224 | pDevice->Flush(true); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 225 | holder->UnPreMultiply(); |
caryclark | 687fbde | 2016-11-22 12:44:25 -0800 | [diff] [blame] | 226 | #endif |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 229 | } // namespace |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 230 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 231 | FPDF_EXPORT int FPDF_CALLCONV |
| 232 | FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 233 | FPDF_PAGE page, |
| 234 | double page_x, |
| 235 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 236 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 237 | if (pPage) { |
Lei Zhang | f7e6976 | 2019-02-13 19:09:15 +0000 | [diff] [blame] | 238 | CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); |
| 239 | if (!pForm) |
| 240 | return -1; |
| 241 | |
| 242 | CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); |
| 243 | CPDF_FormControl* pFormCtrl = pPDFForm->GetControlAtPoint( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 244 | pPage, |
| 245 | CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 246 | nullptr); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 247 | if (!pFormCtrl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 250 | return pFormField ? static_cast<int>(pFormField->GetFieldType()) : -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 253 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 254 | CPDFXFA_Page* pXFAPage = ToXFAPage(IPDFPageFromFPDFPage(page)); |
Tom Sepez | bcb7a69 | 2019-08-09 21:21:09 +0000 | [diff] [blame] | 255 | if (pXFAPage) { |
| 256 | return pXFAPage->HasFormFieldAtPoint( |
| 257 | CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 259 | #endif // PDF_ENABLE_XFA |
Tom Sepez | bcb7a69 | 2019-08-09 21:21:09 +0000 | [diff] [blame] | 260 | |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 261 | return -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 264 | FPDF_EXPORT int FPDF_CALLCONV |
| 265 | FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
| 266 | FPDF_PAGE page, |
| 267 | double page_x, |
| 268 | double page_y) { |
Lei Zhang | f7e6976 | 2019-02-13 19:09:15 +0000 | [diff] [blame] | 269 | CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); |
| 270 | if (!pForm) |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 271 | return -1; |
Lei Zhang | f7e6976 | 2019-02-13 19:09:15 +0000 | [diff] [blame] | 272 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 273 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 274 | if (!pPage) |
| 275 | return -1; |
Lei Zhang | f7e6976 | 2019-02-13 19:09:15 +0000 | [diff] [blame] | 276 | |
| 277 | CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 278 | int z_order = -1; |
Lei Zhang | f7e6976 | 2019-02-13 19:09:15 +0000 | [diff] [blame] | 279 | pPDFForm->GetControlAtPoint( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 280 | pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), |
Ryan Harrison | 6cec70a | 2018-06-05 14:06:10 +0000 | [diff] [blame] | 281 | &z_order); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 282 | return z_order; |
| 283 | } |
| 284 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 285 | FPDF_EXPORT FPDF_FORMHANDLE FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 286 | FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| 287 | FPDF_FORMFILLINFO* formInfo) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 288 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | f672baf | 2019-07-29 17:31:28 +0000 | [diff] [blame] | 289 | constexpr int kRequiredVersion = 2; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 290 | #else // PDF_ENABLE_XFA |
Lei Zhang | f672baf | 2019-07-29 17:31:28 +0000 | [diff] [blame] | 291 | constexpr int kRequiredVersion = 1; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 292 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 293 | if (!formInfo || formInfo->version != kRequiredVersion) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 294 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 295 | |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 296 | auto* pDocument = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 297 | if (!pDocument) |
| 298 | return nullptr; |
| 299 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 300 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 301 | // If the CPDFXFA_Context has a FormFillEnvironment already then we've done |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 302 | // this and can just return the old Env. Otherwise, we'll end up setting a new |
| 303 | // environment into the XFADocument and, that could get weird. |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 304 | auto* pContext = static_cast<CPDFXFA_Context*>(pDocument->GetExtension()); |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 305 | if (pContext && pContext->GetFormFillEnv()) { |
| 306 | return FPDFFormHandleFromCPDFSDKFormFillEnvironment( |
| 307 | pContext->GetFormFillEnv()); |
| 308 | } |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 309 | #endif |
| 310 | |
Tom Sepez | 4935770 | 2019-08-19 17:17:18 +0000 | [diff] [blame] | 311 | std::unique_ptr<IPDFSDK_AnnotHandler> pXFAHandler; |
| 312 | #ifdef PDF_ENABLE_XFA |
| 313 | pXFAHandler = pdfium::MakeUnique<CPDFXFA_WidgetHandler>(); |
| 314 | #endif // PDF_ENABLE_XFA |
| 315 | |
| 316 | auto pFormFillEnv = pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>( |
| 317 | pDocument, formInfo, |
| 318 | pdfium::MakeUnique<CPDFSDK_AnnotHandlerMgr>( |
| 319 | pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>(), |
| 320 | pdfium::MakeUnique<CPDFSDK_WidgetHandler>(), std::move(pXFAHandler))); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 321 | |
| 322 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 323 | if (pContext) |
| 324 | pContext->SetFormFillEnv(pFormFillEnv.get()); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 325 | #endif // PDF_ENABLE_XFA |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 326 | |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 327 | return FPDFFormHandleFromCPDFSDKFormFillEnvironment( |
| 328 | pFormFillEnv.release()); // Caller takes ownership. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 331 | FPDF_EXPORT void FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
Daniel Hosseinian | 9b87a7d | 2020-01-08 22:50:39 +0000 | [diff] [blame] | 333 | if (!hHandle) |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 334 | return; |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 335 | |
Daniel Hosseinian | 9b87a7d | 2020-01-08 22:50:39 +0000 | [diff] [blame] | 336 | // Take back ownership of the form fill environment. This is the inverse of |
| 337 | // FPDFDOC_InitFormFillEnvironment() above. |
| 338 | std::unique_ptr<CPDFSDK_FormFillEnvironment> pFormFillEnv( |
| 339 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle)); |
| 340 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 341 | #ifdef PDF_ENABLE_XFA |
dsinclair | 2116105 | 2016-10-05 15:46:15 -0700 | [diff] [blame] | 342 | // Reset the focused annotations and remove the SDK document from the |
| 343 | // XFA document. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 344 | pFormFillEnv->ClearAllFocusedAnnots(); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 345 | // If the document was closed first, it's possible the XFA document |
| 346 | // is now a nullptr. |
Tom Sepez | d48bd29 | 2019-08-14 19:48:55 +0000 | [diff] [blame] | 347 | auto* pContext = |
| 348 | static_cast<CPDFXFA_Context*>(pFormFillEnv->GetDocExtension()); |
| 349 | if (pContext) |
| 350 | pContext->SetFormFillEnv(nullptr); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 351 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 354 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnMouseMove(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->OnMouseMove(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Lei Zhang | 63b0126 | 2017-08-31 08:54:46 -0700 | [diff] [blame] | 365 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnFocus(FPDF_FORMHANDLE hHandle, |
| 366 | FPDF_PAGE page, |
| 367 | int modifier, |
| 368 | double page_x, |
| 369 | double page_y) { |
| 370 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 371 | if (!pPageView) |
| 372 | return false; |
| 373 | return pPageView->OnFocus(CFX_PointF(page_x, page_y), modifier); |
| 374 | } |
| 375 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 376 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, |
| 377 | FPDF_PAGE page, |
| 378 | int modifier, |
| 379 | double page_x, |
| 380 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 381 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 382 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 383 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 384 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 385 | fprintf(stderr, "mousedown,left,%d,%d\n", static_cast<int>(round(page_x)), |
| 386 | static_cast<int>(round(page_y))); |
| 387 | #endif // PDF_ENABLE_CLICK_LOGGING |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 388 | return pPageView->OnLButtonDown(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 391 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, |
| 392 | FPDF_PAGE page, |
| 393 | int modifier, |
| 394 | double page_x, |
| 395 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 396 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 397 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 398 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 399 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 400 | fprintf(stderr, "mouseup,left,%d,%d\n", static_cast<int>(round(page_x)), |
| 401 | static_cast<int>(round(page_y))); |
| 402 | #endif // PDF_ENABLE_CLICK_LOGGING |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 403 | return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 406 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 407 | FORM_OnLButtonDoubleClick(FPDF_FORMHANDLE hHandle, |
| 408 | FPDF_PAGE page, |
| 409 | int modifier, |
| 410 | double page_x, |
| 411 | double page_y) { |
| 412 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 413 | if (!pPageView) |
| 414 | return false; |
| 415 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 416 | fprintf(stderr, "mousedown,doubleleft,%d,%d\n", |
| 417 | static_cast<int>(round(page_x)), static_cast<int>(round(page_y))); |
| 418 | #endif // PDF_ENABLE_CLICK_LOGGING |
| 419 | return pPageView->OnLButtonDblClk(CFX_PointF(page_x, page_y), modifier); |
| 420 | } |
| 421 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 422 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| 423 | FPDF_PAGE page, |
| 424 | int modifier, |
| 425 | double page_x, |
| 426 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 427 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 428 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 429 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 430 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 431 | fprintf(stderr, "mousedown,right,%d,%d\n", static_cast<int>(round(page_x)), |
| 432 | static_cast<int>(round(page_y))); |
| 433 | #endif // PDF_ENABLE_CLICK_LOGGING |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 434 | return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 437 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| 438 | FPDF_PAGE page, |
| 439 | int modifier, |
| 440 | double page_x, |
| 441 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 442 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 443 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 444 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 445 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 446 | fprintf(stderr, "mouseup,right,%d,%d\n", static_cast<int>(round(page_x)), |
| 447 | static_cast<int>(round(page_y))); |
| 448 | #endif // PDF_ENABLE_CLICK_LOGGING |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 449 | return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 452 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
| 453 | FPDF_PAGE page, |
| 454 | int nKeyCode, |
| 455 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 457 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 458 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 459 | return pPageView->OnKeyDown(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 462 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, |
| 463 | FPDF_PAGE page, |
| 464 | int nKeyCode, |
| 465 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 467 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 468 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | return pPageView->OnKeyUp(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 472 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnChar(FPDF_FORMHANDLE hHandle, |
| 473 | FPDF_PAGE page, |
| 474 | int nChar, |
| 475 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 476 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 477 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 478 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | return pPageView->OnChar(nChar, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 482 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 483 | FORM_GetFocusedText(FPDF_FORMHANDLE hHandle, |
| 484 | FPDF_PAGE page, |
| 485 | void* buffer, |
| 486 | unsigned long buflen) { |
| 487 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 488 | if (!pPageView) |
| 489 | return 0; |
| 490 | |
| 491 | return Utf16EncodeMaybeCopyAndReturnLength(pPageView->GetFocusedFormText(), |
| 492 | buffer, buflen); |
| 493 | } |
| 494 | |
| 495 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 496 | FORM_GetSelectedText(FPDF_FORMHANDLE hHandle, |
| 497 | FPDF_PAGE page, |
| 498 | void* buffer, |
| 499 | unsigned long buflen) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 500 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 501 | if (!pPageView) |
| 502 | return 0; |
| 503 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 504 | return Utf16EncodeMaybeCopyAndReturnLength(pPageView->GetSelectedText(), |
| 505 | buffer, buflen); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 508 | FPDF_EXPORT void FPDF_CALLCONV FORM_ReplaceSelection(FPDF_FORMHANDLE hHandle, |
| 509 | FPDF_PAGE page, |
| 510 | FPDF_WIDESTRING wsText) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 511 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 512 | if (!pPageView) |
| 513 | return; |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 514 | |
Lei Zhang | b46a763 | 2019-01-09 02:56:16 +0000 | [diff] [blame] | 515 | pPageView->ReplaceSelection(WideStringFromFPDFWideString(wsText)); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 518 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanUndo(FPDF_FORMHANDLE hHandle, |
| 519 | FPDF_PAGE page) { |
| 520 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 521 | if (!pPageView) |
| 522 | return false; |
| 523 | return pPageView->CanUndo(); |
| 524 | } |
| 525 | |
| 526 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanRedo(FPDF_FORMHANDLE hHandle, |
| 527 | FPDF_PAGE page) { |
| 528 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 529 | if (!pPageView) |
| 530 | return false; |
| 531 | return pPageView->CanRedo(); |
| 532 | } |
| 533 | |
| 534 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Undo(FPDF_FORMHANDLE hHandle, |
| 535 | FPDF_PAGE page) { |
| 536 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 537 | if (!pPageView) |
| 538 | return false; |
| 539 | return pPageView->Undo(); |
| 540 | } |
| 541 | |
| 542 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Redo(FPDF_FORMHANDLE hHandle, |
| 543 | FPDF_PAGE page) { |
| 544 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 545 | if (!pPageView) |
| 546 | return false; |
| 547 | return pPageView->Redo(); |
| 548 | } |
| 549 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 550 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 551 | FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 552 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 553 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 554 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 555 | return false; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 556 | return pFormFillEnv->KillFocusAnnot(0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 559 | FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 560 | FPDF_BITMAP bitmap, |
| 561 | FPDF_PAGE page, |
| 562 | int start_x, |
| 563 | int start_y, |
| 564 | int size_x, |
| 565 | int size_y, |
| 566 | int rotate, |
| 567 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 568 | FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y, |
| 569 | rotate, flags); |
| 570 | } |
| 571 | |
| 572 | #ifdef _SKIA_SUPPORT_ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 573 | FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLRecord(FPDF_FORMHANDLE hHandle, |
| 574 | FPDF_RECORDER recorder, |
| 575 | FPDF_PAGE page, |
| 576 | int start_x, |
| 577 | int start_y, |
| 578 | int size_x, |
| 579 | int size_y, |
| 580 | int rotate, |
| 581 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 582 | FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y, |
| 583 | rotate, flags); |
| 584 | } |
| 585 | #endif |
| 586 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 587 | FPDF_EXPORT void FPDF_CALLCONV |
| 588 | FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
| 589 | int fieldType, |
| 590 | unsigned long color) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 591 | CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); |
| 592 | if (!pForm) |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 593 | return; |
| 594 | |
| 595 | Optional<FormFieldType> cast_input = IntToFormFieldType(fieldType); |
Ryan Harrison | 2056fac | 2018-01-16 16:06:45 +0000 | [diff] [blame] | 596 | if (!cast_input) |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 597 | return; |
| 598 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 599 | if (cast_input.value() == FormFieldType::kUnknown) |
| 600 | pForm->SetAllHighlightColors(color); |
| 601 | else |
| 602 | pForm->SetHighlightColor(color, cast_input.value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 605 | FPDF_EXPORT void FPDF_CALLCONV |
| 606 | FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 607 | if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) |
| 608 | pForm->SetHighlightAlpha(alpha); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 611 | FPDF_EXPORT void FPDF_CALLCONV |
| 612 | FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 613 | if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) |
| 614 | pForm->RemoveAllHighLights(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 617 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 618 | FPDF_FORMHANDLE hHandle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 619 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 620 | pPageView->SetValid(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 623 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 624 | FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 625 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 626 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 627 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 628 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 629 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 630 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 631 | if (!pPage) |
| 632 | return; |
| 633 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 634 | CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 635 | if (pPageView) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 636 | pPageView->SetValid(false); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 637 | // RemovePageView() takes care of the delete for us. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 638 | pFormFillEnv->RemovePageView(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 642 | FPDF_EXPORT void FPDF_CALLCONV |
| 643 | FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 644 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 645 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
Tom Sepez | f5ca90c | 2018-02-01 02:15:44 +0000 | [diff] [blame] | 646 | if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 647 | pFormFillEnv->ProcJavascriptFun(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 650 | FPDF_EXPORT void FPDF_CALLCONV |
| 651 | FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 652 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 653 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
Tom Sepez | f5ca90c | 2018-02-01 02:15:44 +0000 | [diff] [blame] | 654 | if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 655 | pFormFillEnv->ProcOpenAction(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 658 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 659 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 660 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 661 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 662 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 663 | return; |
| 664 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 665 | CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); |
Tom Sepez | 2292360 | 2019-07-15 21:33:35 +0000 | [diff] [blame] | 666 | CPDF_Dictionary* pDict = pDoc->GetRoot(); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 667 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 669 | |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 670 | CPDF_AAction aa(pDict->GetDictFor("AA")); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 671 | auto type = static_cast<CPDF_AAction::AActionType>(aaType); |
| 672 | if (aa.ActionExist(type)) { |
| 673 | CPDF_Action action = aa.GetAction(type); |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 674 | pFormFillEnv->GetActionHandler()->DoAction_Document(action, type, |
| 675 | pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 679 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoPageAAction(FPDF_PAGE page, |
| 680 | FPDF_FORMHANDLE hHandle, |
| 681 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 682 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 683 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 684 | if (!pFormFillEnv) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 685 | return; |
| 686 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 687 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 688 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 689 | if (!pPDFPage) |
| 690 | return; |
| 691 | |
| 692 | if (!pFormFillEnv->GetPageView(pPage, false)) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 693 | return; |
| 694 | |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 695 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); |
Henrique Nakashima | 888af47 | 2018-06-07 19:43:42 +0000 | [diff] [blame] | 696 | CPDF_Dictionary* pPageDict = pPDFPage->GetDict(); |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 697 | CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 698 | CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN |
Hans Wennborg | c320e9c | 2018-10-22 18:28:52 +0000 | [diff] [blame] | 699 | ? CPDF_AAction::kOpenPage |
| 700 | : CPDF_AAction::kClosePage; |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 701 | if (aa.ActionExist(type)) { |
| 702 | CPDF_Action action = aa.GetAction(type); |
| 703 | pActionHandler->DoAction_Page(action, type, pFormFillEnv); |
| 704 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 705 | } |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 706 | |
| 707 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 708 | FORM_SetIndexSelected(FPDF_FORMHANDLE hHandle, |
| 709 | FPDF_PAGE page, |
| 710 | int index, |
| 711 | FPDF_BOOL selected) { |
| 712 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 713 | if (!pPageView) |
| 714 | return false; |
| 715 | return pPageView->SetIndexSelected(index, selected); |
| 716 | } |
| 717 | |
| 718 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 719 | FORM_IsIndexSelected(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int index) { |
| 720 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 721 | if (!pPageView) |
| 722 | return false; |
| 723 | return pPageView->IsIndexSelected(index); |
| 724 | } |