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) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 333 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 334 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 335 | if (!pFormFillEnv) |
| 336 | return; |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 337 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 338 | #ifdef PDF_ENABLE_XFA |
dsinclair | 2116105 | 2016-10-05 15:46:15 -0700 | [diff] [blame] | 339 | // Reset the focused annotations and remove the SDK document from the |
| 340 | // XFA document. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 341 | pFormFillEnv->ClearAllFocusedAnnots(); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 342 | // If the document was closed first, it's possible the XFA document |
| 343 | // is now a nullptr. |
Tom Sepez | d48bd29 | 2019-08-14 19:48:55 +0000 | [diff] [blame] | 344 | auto* pContext = |
| 345 | static_cast<CPDFXFA_Context*>(pFormFillEnv->GetDocExtension()); |
| 346 | if (pContext) |
| 347 | pContext->SetFormFillEnv(nullptr); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 348 | #endif // PDF_ENABLE_XFA |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 349 | delete pFormFillEnv; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 352 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 353 | FPDF_PAGE page, |
| 354 | int modifier, |
| 355 | double page_x, |
| 356 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 357 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 358 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 359 | return false; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 360 | return pPageView->OnMouseMove(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Lei Zhang | 63b0126 | 2017-08-31 08:54:46 -0700 | [diff] [blame] | 363 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnFocus(FPDF_FORMHANDLE hHandle, |
| 364 | FPDF_PAGE page, |
| 365 | int modifier, |
| 366 | double page_x, |
| 367 | double page_y) { |
| 368 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 369 | if (!pPageView) |
| 370 | return false; |
| 371 | return pPageView->OnFocus(CFX_PointF(page_x, page_y), modifier); |
| 372 | } |
| 373 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 374 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, |
| 375 | FPDF_PAGE page, |
| 376 | int modifier, |
| 377 | double page_x, |
| 378 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 380 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 381 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 382 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 383 | fprintf(stderr, "mousedown,left,%d,%d\n", static_cast<int>(round(page_x)), |
| 384 | static_cast<int>(round(page_y))); |
| 385 | #endif // PDF_ENABLE_CLICK_LOGGING |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 386 | return pPageView->OnLButtonDown(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 389 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, |
| 390 | FPDF_PAGE page, |
| 391 | int modifier, |
| 392 | double page_x, |
| 393 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 394 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 395 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 396 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 397 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 398 | fprintf(stderr, "mouseup,left,%d,%d\n", static_cast<int>(round(page_x)), |
| 399 | static_cast<int>(round(page_y))); |
| 400 | #endif // PDF_ENABLE_CLICK_LOGGING |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 401 | return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 404 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 405 | FORM_OnLButtonDoubleClick(FPDF_FORMHANDLE hHandle, |
| 406 | FPDF_PAGE page, |
| 407 | int modifier, |
| 408 | double page_x, |
| 409 | double page_y) { |
| 410 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 411 | if (!pPageView) |
| 412 | return false; |
| 413 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 414 | fprintf(stderr, "mousedown,doubleleft,%d,%d\n", |
| 415 | static_cast<int>(round(page_x)), static_cast<int>(round(page_y))); |
| 416 | #endif // PDF_ENABLE_CLICK_LOGGING |
| 417 | return pPageView->OnLButtonDblClk(CFX_PointF(page_x, page_y), modifier); |
| 418 | } |
| 419 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 420 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| 421 | FPDF_PAGE page, |
| 422 | int modifier, |
| 423 | double page_x, |
| 424 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 425 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 426 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 427 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 428 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 429 | fprintf(stderr, "mousedown,right,%d,%d\n", static_cast<int>(round(page_x)), |
| 430 | static_cast<int>(round(page_y))); |
| 431 | #endif // PDF_ENABLE_CLICK_LOGGING |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 432 | return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 435 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| 436 | FPDF_PAGE page, |
| 437 | int modifier, |
| 438 | double page_x, |
| 439 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 441 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 442 | return false; |
Ryan Harrison | 9ce75b8 | 2018-06-06 19:45:14 +0000 | [diff] [blame] | 443 | #ifdef PDF_ENABLE_CLICK_LOGGING |
| 444 | fprintf(stderr, "mouseup,right,%d,%d\n", static_cast<int>(round(page_x)), |
| 445 | static_cast<int>(round(page_y))); |
| 446 | #endif // PDF_ENABLE_CLICK_LOGGING |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 447 | return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 450 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
| 451 | FPDF_PAGE page, |
| 452 | int nKeyCode, |
| 453 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 455 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 456 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | return pPageView->OnKeyDown(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 460 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, |
| 461 | FPDF_PAGE page, |
| 462 | int nKeyCode, |
| 463 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 464 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 465 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 466 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 467 | return pPageView->OnKeyUp(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 470 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnChar(FPDF_FORMHANDLE hHandle, |
| 471 | FPDF_PAGE page, |
| 472 | int nChar, |
| 473 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 475 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 476 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | return pPageView->OnChar(nChar, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 480 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 481 | FORM_GetFocusedText(FPDF_FORMHANDLE hHandle, |
| 482 | FPDF_PAGE page, |
| 483 | void* buffer, |
| 484 | unsigned long buflen) { |
| 485 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 486 | if (!pPageView) |
| 487 | return 0; |
| 488 | |
| 489 | return Utf16EncodeMaybeCopyAndReturnLength(pPageView->GetFocusedFormText(), |
| 490 | buffer, buflen); |
| 491 | } |
| 492 | |
| 493 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 494 | FORM_GetSelectedText(FPDF_FORMHANDLE hHandle, |
| 495 | FPDF_PAGE page, |
| 496 | void* buffer, |
| 497 | unsigned long buflen) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 498 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 499 | if (!pPageView) |
| 500 | return 0; |
| 501 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 502 | return Utf16EncodeMaybeCopyAndReturnLength(pPageView->GetSelectedText(), |
| 503 | buffer, buflen); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 506 | FPDF_EXPORT void FPDF_CALLCONV FORM_ReplaceSelection(FPDF_FORMHANDLE hHandle, |
| 507 | FPDF_PAGE page, |
| 508 | FPDF_WIDESTRING wsText) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 509 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 510 | if (!pPageView) |
| 511 | return; |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 512 | |
Lei Zhang | b46a763 | 2019-01-09 02:56:16 +0000 | [diff] [blame] | 513 | pPageView->ReplaceSelection(WideStringFromFPDFWideString(wsText)); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 516 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanUndo(FPDF_FORMHANDLE hHandle, |
| 517 | FPDF_PAGE page) { |
| 518 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 519 | if (!pPageView) |
| 520 | return false; |
| 521 | return pPageView->CanUndo(); |
| 522 | } |
| 523 | |
| 524 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanRedo(FPDF_FORMHANDLE hHandle, |
| 525 | FPDF_PAGE page) { |
| 526 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 527 | if (!pPageView) |
| 528 | return false; |
| 529 | return pPageView->CanRedo(); |
| 530 | } |
| 531 | |
| 532 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Undo(FPDF_FORMHANDLE hHandle, |
| 533 | FPDF_PAGE page) { |
| 534 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 535 | if (!pPageView) |
| 536 | return false; |
| 537 | return pPageView->Undo(); |
| 538 | } |
| 539 | |
| 540 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Redo(FPDF_FORMHANDLE hHandle, |
| 541 | FPDF_PAGE page) { |
| 542 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 543 | if (!pPageView) |
| 544 | return false; |
| 545 | return pPageView->Redo(); |
| 546 | } |
| 547 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 548 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 549 | FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 550 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 551 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 552 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 553 | return false; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 554 | return pFormFillEnv->KillFocusAnnot(0); |
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 FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 558 | FPDF_BITMAP bitmap, |
| 559 | FPDF_PAGE page, |
| 560 | int start_x, |
| 561 | int start_y, |
| 562 | int size_x, |
| 563 | int size_y, |
| 564 | int rotate, |
| 565 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 566 | FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y, |
| 567 | rotate, flags); |
| 568 | } |
| 569 | |
| 570 | #ifdef _SKIA_SUPPORT_ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 571 | FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLRecord(FPDF_FORMHANDLE hHandle, |
| 572 | FPDF_RECORDER recorder, |
| 573 | FPDF_PAGE page, |
| 574 | int start_x, |
| 575 | int start_y, |
| 576 | int size_x, |
| 577 | int size_y, |
| 578 | int rotate, |
| 579 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 580 | FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y, |
| 581 | rotate, flags); |
| 582 | } |
| 583 | #endif |
| 584 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 585 | FPDF_EXPORT void FPDF_CALLCONV |
| 586 | FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
| 587 | int fieldType, |
| 588 | unsigned long color) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 589 | CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); |
| 590 | if (!pForm) |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 591 | return; |
| 592 | |
| 593 | Optional<FormFieldType> cast_input = IntToFormFieldType(fieldType); |
Ryan Harrison | 2056fac | 2018-01-16 16:06:45 +0000 | [diff] [blame] | 594 | if (!cast_input) |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 595 | return; |
| 596 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 597 | if (cast_input.value() == FormFieldType::kUnknown) |
| 598 | pForm->SetAllHighlightColors(color); |
| 599 | else |
| 600 | pForm->SetHighlightColor(color, cast_input.value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 603 | FPDF_EXPORT void FPDF_CALLCONV |
| 604 | FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 605 | if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) |
| 606 | pForm->SetHighlightAlpha(alpha); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 609 | FPDF_EXPORT void FPDF_CALLCONV |
| 610 | FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 611 | if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) |
| 612 | pForm->RemoveAllHighLights(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 615 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 616 | FPDF_FORMHANDLE hHandle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 618 | pPageView->SetValid(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 621 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 622 | FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 623 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 624 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 625 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 627 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 628 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 629 | if (!pPage) |
| 630 | return; |
| 631 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 632 | CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | if (pPageView) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 634 | pPageView->SetValid(false); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 635 | // RemovePageView() takes care of the delete for us. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 636 | pFormFillEnv->RemovePageView(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 640 | FPDF_EXPORT void FPDF_CALLCONV |
| 641 | FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 642 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 643 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
Tom Sepez | f5ca90c | 2018-02-01 02:15:44 +0000 | [diff] [blame] | 644 | if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 645 | pFormFillEnv->ProcJavascriptFun(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 648 | FPDF_EXPORT void FPDF_CALLCONV |
| 649 | FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 650 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 651 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
Tom Sepez | f5ca90c | 2018-02-01 02:15:44 +0000 | [diff] [blame] | 652 | if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 653 | pFormFillEnv->ProcOpenAction(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 656 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 657 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 658 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 659 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 660 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 661 | return; |
| 662 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 663 | CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); |
Tom Sepez | 2292360 | 2019-07-15 21:33:35 +0000 | [diff] [blame] | 664 | CPDF_Dictionary* pDict = pDoc->GetRoot(); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 665 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 667 | |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 668 | CPDF_AAction aa(pDict->GetDictFor("AA")); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 669 | auto type = static_cast<CPDF_AAction::AActionType>(aaType); |
| 670 | if (aa.ActionExist(type)) { |
| 671 | CPDF_Action action = aa.GetAction(type); |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 672 | pFormFillEnv->GetActionHandler()->DoAction_Document(action, type, |
| 673 | pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 677 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoPageAAction(FPDF_PAGE page, |
| 678 | FPDF_FORMHANDLE hHandle, |
| 679 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 680 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 681 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 682 | if (!pFormFillEnv) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 683 | return; |
| 684 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 685 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 686 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 687 | if (!pPDFPage) |
| 688 | return; |
| 689 | |
| 690 | if (!pFormFillEnv->GetPageView(pPage, false)) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 691 | return; |
| 692 | |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 693 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); |
Henrique Nakashima | 888af47 | 2018-06-07 19:43:42 +0000 | [diff] [blame] | 694 | CPDF_Dictionary* pPageDict = pPDFPage->GetDict(); |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 695 | CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 696 | CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN |
Hans Wennborg | c320e9c | 2018-10-22 18:28:52 +0000 | [diff] [blame] | 697 | ? CPDF_AAction::kOpenPage |
| 698 | : CPDF_AAction::kClosePage; |
Henrique Nakashima | 7b094f8 | 2018-05-08 20:32:08 +0000 | [diff] [blame] | 699 | if (aa.ActionExist(type)) { |
| 700 | CPDF_Action action = aa.GetAction(type); |
| 701 | pActionHandler->DoAction_Page(action, type, pFormFillEnv); |
| 702 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 703 | } |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 704 | |
| 705 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 706 | FORM_SetIndexSelected(FPDF_FORMHANDLE hHandle, |
| 707 | FPDF_PAGE page, |
| 708 | int index, |
| 709 | FPDF_BOOL selected) { |
| 710 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 711 | if (!pPageView) |
| 712 | return false; |
| 713 | return pPageView->SetIndexSelected(index, selected); |
| 714 | } |
| 715 | |
| 716 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 717 | FORM_IsIndexSelected(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int index) { |
| 718 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 719 | if (!pPageView) |
| 720 | return false; |
| 721 | return pPageView->IsIndexSelected(index); |
| 722 | } |