blob: 00b8300095c001c8d12e3079f8541660b75e0122 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_formfill.h"
8
Lei Zhangaa8bf7e2015-12-24 19:13:32 -08009#include <memory>
Tom Sepezab277682016-02-17 10:07:21 -080010#include <vector>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080011
dsinclair41872fa2016-10-04 11:29:35 -070012#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070013#include "core/fpdfapi/parser/cpdf_document.h"
dsinclair69d9c682016-10-04 12:18:35 -070014#include "core/fpdfapi/render/cpdf_renderoptions.h"
dsinclair1727aee2016-09-29 13:12:56 -070015#include "core/fpdfdoc/cpdf_formcontrol.h"
16#include "core/fpdfdoc/cpdf_formfield.h"
17#include "core/fpdfdoc/cpdf_interform.h"
18#include "core/fpdfdoc/cpdf_occontext.h"
Dan Sinclaira5085d42017-05-11 16:26:50 -040019#include "core/fxge/cfx_defaultrenderdevice.h"
dsinclair735606d2016-10-05 15:47:02 -070020#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070021#include "fpdfsdk/cpdfsdk_interform.h"
22#include "fpdfsdk/cpdfsdk_pageview.h"
23#include "fpdfsdk/fsdk_actionhandler.h"
24#include "fpdfsdk/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080025#include "public/fpdfview.h"
tsepez36eb4bd2016-10-03 15:24:27 -070026#include "third_party/base/ptr_util.h"
Tom Sepezab277682016-02-17 10:07:21 -080027#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Tom Sepez40e9ff32015-11-30 12:39:54 -080029#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070030#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair4d29e782016-10-04 14:02:47 -070031#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040032#include "xfa/fxfa/cxfa_ffdocview.h"
33#include "xfa/fxfa/cxfa_ffpageview.h"
34#include "xfa/fxfa/cxfa_ffwidget.h"
Dan Sinclaircdba7472017-03-23 09:17:10 -040035
36static_assert(static_cast<int>(XFA_DocType::PDF) == DOCTYPE_PDF,
37 "PDF doctype must match");
38static_assert(static_cast<int>(XFA_DocType::Dynamic) == DOCTYPE_DYNAMIC_XFA,
39 "Dynamic XFA doctype must match");
40static_assert(static_cast<int>(XFA_DocType::Static) == DOCTYPE_STATIC_XFA,
41 "Static XFA doctype must match");
Tom Sepez40e9ff32015-11-30 12:39:54 -080042#endif // PDF_ENABLE_XFA
43
Tom Sepezdcbc02f2015-07-17 09:16:17 -070044namespace {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045
dsinclair735606d2016-10-05 15:47:02 -070046CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment(
47 FPDF_FORMHANDLE handle) {
48 return static_cast<CPDFSDK_FormFillEnvironment*>(handle);
dsinclair79db6092016-09-14 07:27:21 -070049}
50
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -070052 CPDFSDK_FormFillEnvironment* pFormFillEnv =
53 HandleToCPDFSDKEnvironment(hHandle);
dsinclair7cbe68e2016-10-12 11:56:23 -070054 return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070055}
Bo Xufdc00a72014-10-28 23:03:33 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
58 FPDF_PAGE page) {
Tom Sepez540c4362015-11-24 13:33:57 -080059 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
60 if (!pPage)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 return nullptr;
Tom Sepez0b133982015-07-28 11:23:22 -070062
dsinclairf3fbe832016-10-11 13:08:04 -070063 CPDFSDK_FormFillEnvironment* pFormFillEnv =
64 HandleToCPDFSDKEnvironment(hHandle);
dsinclair7cbe68e2016-10-12 11:56:23 -070065 return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070066}
Bo Xufdc00a72014-10-28 23:03:33 -070067
Tom Sepezab277682016-02-17 10:07:21 -080068#ifdef PDF_ENABLE_XFA
69std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) {
Nicolas Pena46abb662017-05-17 17:23:22 -040070 return static_cast<std::vector<CFX_ByteString>*>(handle);
Tom Sepezab277682016-02-17 10:07:21 -080071}
72
73FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) {
Nicolas Pena46abb662017-05-17 17:23:22 -040074 return static_cast<FPDF_STRINGHANDLE>(strings);
Tom Sepezab277682016-02-17 10:07:21 -080075}
76#endif // PDF_ENABLE_XFA
77
thestigbefa4502016-05-26 20:15:19 -070078void FFLCommon(FPDF_FORMHANDLE hHandle,
79 FPDF_BITMAP bitmap,
80 FPDF_RECORDER recorder,
81 FPDF_PAGE page,
82 int start_x,
83 int start_y,
84 int size_x,
85 int size_y,
86 int rotate,
87 int flags) {
88 if (!hHandle)
89 return;
90
91 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
92 if (!pPage)
93 return;
94
jaepark738766e2016-09-02 18:51:44 -070095#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070096 CPDFXFA_Context* pContext = pPage->GetContext();
97 if (!pContext)
thestigbefa4502016-05-26 20:15:19 -070098 return;
dsinclair521b7502016-11-02 13:02:28 -070099 CPDF_Document* pPDFDoc = pContext->GetPDFDoc();
thestigbefa4502016-05-26 20:15:19 -0700100 if (!pPDFDoc)
101 return;
dsinclairf3fbe832016-10-11 13:08:04 -0700102 CPDFSDK_FormFillEnvironment* pFormFillEnv =
103 HandleToCPDFSDKEnvironment(hHandle);
104 if (!pFormFillEnv)
thestigbefa4502016-05-26 20:15:19 -0700105 return;
106#endif // PDF_ENABLE_XFA
107
Dan Sinclair1b08df12017-02-09 09:17:20 -0500108 CFX_Matrix matrix =
109 pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate);
thestigbefa4502016-05-26 20:15:19 -0700110 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y);
111
Dan Sinclaira5085d42017-05-11 16:26:50 -0400112 auto pDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>();
thestigbefa4502016-05-26 20:15:19 -0700113#ifdef _SKIA_SUPPORT_
114 pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
115#endif
Tom Sepezf0799fe2017-03-28 09:31:32 -0700116 CFX_RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
117 pDevice->Attach(holder, false, nullptr, false);
Tom Sepez1629f602017-04-21 14:11:26 -0700118 {
119 CFX_RenderDevice::StateRestorer restorer(pDevice.get());
120 pDevice->SetClip_Rect(clip);
thestigbefa4502016-05-26 20:15:19 -0700121
Tom Sepez1629f602017-04-21 14:11:26 -0700122 CPDF_RenderOptions options;
123 if (flags & FPDF_LCD_TEXT)
124 options.m_Flags |= RENDER_CLEARTYPE;
125 else
126 options.m_Flags &= ~RENDER_CLEARTYPE;
thestigbefa4502016-05-26 20:15:19 -0700127
Tom Sepez1629f602017-04-21 14:11:26 -0700128 // Grayscale output
129 if (flags & FPDF_GRAYSCALE) {
130 options.m_ColorMode = RENDER_COLOR_GRAY;
131 options.m_ForeColor = 0;
132 options.m_BackColor = 0xffffff;
133 }
134 options.m_AddFlags = flags >> 8;
135 options.m_bDrawAnnots = flags & FPDF_ANNOT;
thestigbefa4502016-05-26 20:15:19 -0700136
jaepark738766e2016-09-02 18:51:44 -0700137#ifdef PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700138 options.m_pOCContext =
139 pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View);
140 if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true))
141 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
jaepark738766e2016-09-02 18:51:44 -0700142#else // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700143 options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>(
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700144 pPage->m_pDocument.Get(), CPDF_OCContext::View);
Tom Sepez1629f602017-04-21 14:11:26 -0700145 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
146 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
thestigbefa4502016-05-26 20:15:19 -0700147#endif // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700148 }
caryclark8f875502016-12-06 13:49:34 -0800149#ifdef _SKIA_SUPPORT_PATHS_
150 pDevice->Flush();
Tom Sepezf0799fe2017-03-28 09:31:32 -0700151 holder->UnPreMultiply();
caryclark687fbde2016-11-22 12:44:25 -0800152#endif
thestigbefa4502016-05-26 20:15:19 -0700153}
154
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700155} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -0700156
Lei Zhangbdf72c32015-08-14 19:24:08 -0700157DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
158 FPDF_PAGE page,
159 double page_x,
160 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700161 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700162 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700163 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 if (pPage) {
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700165 CPDF_InterForm interform(pPage->m_pDocument.Get());
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500166 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400167 pPage,
168 CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500169 nullptr);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700170 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800173 return pFormField ? pFormField->GetFieldType() : -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 }
175
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800176#ifdef PDF_ENABLE_XFA
177 CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
178 if (!pXFAPage)
179 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180
dsinclairdf4bc592016-03-31 20:34:43 -0700181 CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800182 if (!pPageView)
183 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184
dsinclairdf4bc592016-03-31 20:34:43 -0700185 CXFA_FFDocView* pDocView = pPageView->GetDocView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800186 if (!pDocView)
187 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188
dsinclairdf4bc592016-03-31 20:34:43 -0700189 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800190 if (!pWidgetHandler)
191 return -1;
192
tsepezcc4d6d82016-05-16 13:21:03 -0700193 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700194 pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form,
195 XFA_WidgetStatus_Viewable));
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800196 if (!pWidgetIterator)
197 return -1;
198
dsinclairdf4bc592016-03-31 20:34:43 -0700199 CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800200 while (pXFAAnnot) {
Dan Sinclair1b08df12017-02-09 09:17:20 -0500201 CFX_RectF rcBBox = pXFAAnnot->GetBBox(0);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800202 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
203 rcBBox.top + rcBBox.height);
Lei Zhang1fed5a22017-06-01 11:52:22 -0700204 rcWidget.Inflate(1.0f, 1.0f);
Dan Sinclair05df0752017-03-14 14:43:42 -0400205 if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x),
206 static_cast<float>(page_y)))) {
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800207 return FPDF_FORMFIELD_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 }
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800209 pXFAAnnot = pWidgetIterator->MoveToNext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800211#endif // PDF_ENABLE_XFA
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800212 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700213}
214
Lei Zhangbdf72c32015-08-14 19:24:08 -0700215DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
216 FPDF_PAGE page,
217 double page_x,
218 double page_y) {
219 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y);
220}
221
222DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
223 FPDF_PAGE page,
224 double page_x,
225 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700226 if (!hHandle)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700227 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700228 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
229 if (!pPage)
230 return -1;
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700231 CPDF_InterForm interform(pPage->m_pDocument.Get());
Lei Zhangbdf72c32015-08-14 19:24:08 -0700232 int z_order = -1;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500233 (void)interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400234 pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500235 &z_order);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700236 return z_order;
237}
238
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239DLLEXPORT FPDF_FORMHANDLE STDCALL
240FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
241 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800242#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800243 const int kRequiredVersion = 2;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800244#else // PDF_ENABLE_XFA
245 const int kRequiredVersion = 1;
246#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800247 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249
Tom Sepez540c4362015-11-24 13:33:57 -0800250 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
251 if (!pDocument)
252 return nullptr;
253
Tom Sepez40e9ff32015-11-30 12:39:54 -0800254#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700255 // If the CPDFXFA_Context has a FormFillEnvironment already then we've done
dsinclair8779fa82016-10-12 12:05:44 -0700256 // this and can just return the old Env. Otherwise, we'll end up setting a new
257 // environment into the XFADocument and, that could get weird.
dsinclair655fcca2016-10-11 13:53:37 -0700258 if (pDocument->GetFormFillEnv())
259 return pDocument->GetFormFillEnv();
dsinclaira939bfe2016-09-22 13:18:45 -0700260#endif
261
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700262 auto pFormFillEnv =
263 pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>(pDocument, formInfo);
dsinclaira939bfe2016-09-22 13:18:45 -0700264
265#ifdef PDF_ENABLE_XFA
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700266 pDocument->SetFormFillEnv(pFormFillEnv.get());
Tom Sepez40e9ff32015-11-30 12:39:54 -0800267#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700268
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700269 return pFormFillEnv.release(); // Caller takes ownership.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700270}
271
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272DLLEXPORT void STDCALL
273FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700274 CPDFSDK_FormFillEnvironment* pFormFillEnv =
275 HandleToCPDFSDKEnvironment(hHandle);
Lei Zhang1fed5a22017-06-01 11:52:22 -0700276 if (!pFormFillEnv)
277 return;
dsinclaira939bfe2016-09-22 13:18:45 -0700278
Tom Sepez40e9ff32015-11-30 12:39:54 -0800279#ifdef PDF_ENABLE_XFA
dsinclair21161052016-10-05 15:46:15 -0700280 // Reset the focused annotations and remove the SDK document from the
281 // XFA document.
dsinclair7cbe68e2016-10-12 11:56:23 -0700282 pFormFillEnv->ClearAllFocusedAnnots();
dsinclairf3fbe832016-10-11 13:08:04 -0700283 // If the document was closed first, it's possible the XFA document
284 // is now a nullptr.
dsinclair521b7502016-11-02 13:02:28 -0700285 if (pFormFillEnv->GetXFAContext())
286 pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800287#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700288
dsinclairf3fbe832016-10-11 13:08:04 -0700289 delete pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290}
291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
293 FPDF_PAGE page,
294 int modifier,
295 double page_x,
296 double page_y) {
297 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
298 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700299 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500300 return pPageView->OnMouseMove(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700301}
302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle,
304 FPDF_PAGE page,
305 int modifier,
306 double page_x,
307 double page_y) {
308 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
309 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700310 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500311 return pPageView->OnLButtonDown(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312}
313
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
315 FPDF_PAGE page,
316 int modifier,
317 double page_x,
318 double page_y) {
319 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
320 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700321 return false;
Lei Zhang1fed5a22017-06-01 11:52:22 -0700322 return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700323}
324
Tom Sepez51da0932015-11-25 16:05:49 -0800325#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
327 FPDF_PAGE page,
328 int modifier,
329 double page_x,
330 double page_y) {
331 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
332 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700333 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500334 return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700335}
336
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
338 FPDF_PAGE page,
339 int modifier,
340 double page_x,
341 double page_y) {
342 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
343 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700344 return false;
Lei Zhang1fed5a22017-06-01 11:52:22 -0700345 return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700346}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800347#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700348
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
350 FPDF_PAGE page,
351 int nKeyCode,
352 int modifier) {
353 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
354 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700355 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357}
358
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
360 FPDF_PAGE page,
361 int nKeyCode,
362 int modifier) {
363 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
364 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700365 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367}
368
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
370 FPDF_PAGE page,
371 int nChar,
372 int modifier) {
373 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
374 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700375 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377}
378
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700380 CPDFSDK_FormFillEnvironment* pFormFillEnv =
381 HandleToCPDFSDKEnvironment(hHandle);
382 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700383 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700384 return pFormFillEnv->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385}
386
Cary Clark399be5b2016-03-14 16:51:29 -0400387DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
388 FPDF_BITMAP bitmap,
389 FPDF_PAGE page,
390 int start_x,
391 int start_y,
392 int size_x,
393 int size_y,
394 int rotate,
395 int flags) {
396 FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
397 rotate, flags);
398}
399
400#ifdef _SKIA_SUPPORT_
401DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle,
402 FPDF_RECORDER recorder,
403 FPDF_PAGE page,
404 int start_x,
405 int start_y,
406 int size_x,
407 int size_y,
408 int rotate,
409 int flags) {
410 FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y,
411 rotate, flags);
412}
413#endif
414
Tom Sepez40e9ff32015-11-30 12:39:54 -0800415#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
417 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700418 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700420
dsinclair521b7502016-11-02 13:02:28 -0700421 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400422 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
423 pContext->GetDocType() != XFA_DocType::Static) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 return;
Dan Sinclaircdba7472017-03-23 09:17:10 -0400425 }
Bo Xufdc00a72014-10-28 23:03:33 -0700426
dsinclair221caf62016-04-04 12:08:40 -0700427 static_cast<CXFA_FFWidget*>(hWidget)->Undo();
Bo Xufdc00a72014-10-28 23:03:33 -0700428}
dsinclair521b7502016-11-02 13:02:28 -0700429
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
431 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700432 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700434
dsinclair521b7502016-11-02 13:02:28 -0700435 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400436 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
437 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700439
dsinclair221caf62016-04-04 12:08:40 -0700440 static_cast<CXFA_FFWidget*>(hWidget)->Redo();
Bo Xufdc00a72014-10-28 23:03:33 -0700441}
442
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document,
444 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700445 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700447
dsinclair521b7502016-11-02 13:02:28 -0700448 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400449 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
450 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700452
dsinclair221caf62016-04-04 12:08:40 -0700453 static_cast<CXFA_FFWidget*>(hWidget)->SelectAll();
Bo Xufdc00a72014-10-28 23:03:33 -0700454}
dsinclair521b7502016-11-02 13:02:28 -0700455
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
457 FPDF_WIDGET hWidget,
458 FPDF_WIDESTRING wsText,
459 FPDF_DWORD* size) {
dsinclair221caf62016-04-04 12:08:40 -0700460 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700462
dsinclair521b7502016-11-02 13:02:28 -0700463 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400464 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
465 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700467
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700469 static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700472 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
thestigbefa4502016-05-26 20:15:19 -0700473 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 *size = len;
475 return;
476 }
Bo Xufdc00a72014-10-28 23:03:33 -0700477
weili47ca6922016-03-31 15:08:27 -0700478 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400480 memcpy((void*)wsText,
481 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
482 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
484 }
485 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700486}
Tom Sepezab277682016-02-17 10:07:21 -0800487
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
489 FPDF_WIDGET hWidget,
490 FPDF_WIDESTRING wsText,
491 FPDF_DWORD* size) {
thestigbefa4502016-05-26 20:15:19 -0700492 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 return;
thestigbefa4502016-05-26 20:15:19 -0700494
dsinclair521b7502016-11-02 13:02:28 -0700495 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400496 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
497 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700501 static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700502
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700504 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
dsinclair221caf62016-04-04 12:08:40 -0700505 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 *size = len;
507 return;
508 }
Bo Xufdc00a72014-10-28 23:03:33 -0700509
weili47ca6922016-03-31 15:08:27 -0700510 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400512 memcpy((void*)wsText,
513 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
514 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
516 }
517 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700518}
Tom Sepezab277682016-02-17 10:07:21 -0800519
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
521 FPDF_WIDGET hWidget,
522 FPDF_WIDESTRING wsText,
523 FPDF_DWORD size) {
dsinclair221caf62016-04-04 12:08:40 -0700524 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700526
dsinclair521b7502016-11-02 13:02:28 -0700527 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400528 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
529 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700531
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
dsinclair221caf62016-04-04 12:08:40 -0700533 static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700534}
Tom Sepezab277682016-02-17 10:07:21 -0800535
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536DLLEXPORT void STDCALL
537FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
538 FPDF_WIDGET hWidget,
539 float x,
540 float y,
541 FPDF_BYTESTRING bsText) {
dsinclair221caf62016-04-04 12:08:40 -0700542 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700544
dsinclair521b7502016-11-02 13:02:28 -0700545 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400546 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
547 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700549
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 CFX_PointF ptPopup;
551 ptPopup.x = x;
552 ptPopup.y = y;
553 CFX_ByteStringC bs(bsText);
dsinclair221caf62016-04-04 12:08:40 -0700554 static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700555}
Tom Sepezab277682016-02-17 10:07:21 -0800556
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557DLLEXPORT void STDCALL
558FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
559 FPDF_WIDGET hWidget,
560 float x,
561 float y,
562 FPDF_STRINGHANDLE* stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800563 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700565
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700566 auto* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400567 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
568 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700570
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571 CFX_PointF ptPopup;
572 ptPopup.x = x;
573 ptPopup.y = y;
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700574 auto sSuggestWords = pdfium::MakeUnique<std::vector<CFX_ByteString>>();
575 static_cast<CXFA_FFWidget*>(hWidget)->GetSuggestWords(ptPopup,
576 sSuggestWords.get());
577
578 // Caller takes ownership.
579 *stringHandle = ToFPDFStringHandle(sSuggestWords.release());
Bo Xufdc00a72014-10-28 23:03:33 -0700580}
Tom Sepezab277682016-02-17 10:07:21 -0800581
582DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
583 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
584 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700585}
Tom Sepezab277682016-02-17 10:07:21 -0800586
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587DLLEXPORT FPDF_BOOL STDCALL
Tom Sepezab277682016-02-17 10:07:21 -0800588FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 int index,
590 FPDF_BYTESTRING bsText,
591 FPDF_DWORD* size) {
Tom Sepezab277682016-02-17 10:07:21 -0800592 if (!sHandle || !size)
tsepez4cf55152016-11-02 14:37:54 -0700593 return false;
Tom Sepezab277682016-02-17 10:07:21 -0800594
595 int count = FPDF_StringHandleCounts(sHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596 if (index < 0 || index >= count)
tsepez4cf55152016-11-02 14:37:54 -0700597 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700598
Tom Sepezab277682016-02-17 10:07:21 -0800599 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
weili47ca6922016-03-31 15:08:27 -0700600 uint32_t len = (*sSuggestWords)[index].GetLength();
Tom Sepezab277682016-02-17 10:07:21 -0800601 if (!bsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700602 *size = len;
tsepez4cf55152016-11-02 14:37:54 -0700603 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 }
605
weili47ca6922016-03-31 15:08:27 -0700606 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 if (real_size > 0)
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400608 memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 *size = real_size;
tsepez4cf55152016-11-02 14:37:54 -0700610 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700611}
Tom Sepezab277682016-02-17 10:07:21 -0800612
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613DLLEXPORT void STDCALL
614FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800615 delete FromFPDFStringHandle(stringHandle);
Bo Xufdc00a72014-10-28 23:03:33 -0700616}
617
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618DLLEXPORT FPDF_BOOL STDCALL
619FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
620 FPDF_BYTESTRING bsText,
621 FPDF_DWORD size) {
Tom Sepezab277682016-02-17 10:07:21 -0800622 if (!stringHandle || !bsText || size == 0)
tsepez4cf55152016-11-02 14:37:54 -0700623 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700624
Tom Sepezab277682016-02-17 10:07:21 -0800625 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
tsepez4cf55152016-11-02 14:37:54 -0700626 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700627}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800628#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
631 int fieldType,
632 unsigned long color) {
633 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
634 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
638 unsigned char alpha) {
639 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
640 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700641}
642
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
644 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
645 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646}
647
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
649 FPDF_FORMHANDLE hHandle) {
650 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
tsepez4cf55152016-11-02 14:37:54 -0700651 pPageView->SetValid(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700652}
653
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
655 FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700656 CPDFSDK_FormFillEnvironment* pFormFillEnv =
657 HandleToCPDFSDKEnvironment(hHandle);
658 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700660
Tom Sepez540c4362015-11-24 13:33:57 -0800661 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
662 if (!pPage)
663 return;
664
dsinclair7cbe68e2016-10-12 11:56:23 -0700665 CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 if (pPageView) {
tsepez4cf55152016-11-02 14:37:54 -0700667 pPageView->SetValid(false);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800668 // RemovePageView() takes care of the delete for us.
dsinclair7cbe68e2016-10-12 11:56:23 -0700669 pFormFillEnv->RemovePageView(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 }
671}
672
673DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700674 CPDFSDK_FormFillEnvironment* pFormFillEnv =
675 HandleToCPDFSDKEnvironment(hHandle);
676 if (pFormFillEnv && pFormFillEnv->IsJSInitiated())
dsinclair7cbe68e2016-10-12 11:56:23 -0700677 pFormFillEnv->ProcJavascriptFun();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678}
679
680DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700681 CPDFSDK_FormFillEnvironment* pFormFillEnv =
682 HandleToCPDFSDKEnvironment(hHandle);
683 if (pFormFillEnv && pFormFillEnv->IsJSInitiated())
dsinclair7cbe68e2016-10-12 11:56:23 -0700684 pFormFillEnv->ProcOpenAction();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685}
686
687DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
688 int aaType) {
dsinclairf3fbe832016-10-11 13:08:04 -0700689 CPDFSDK_FormFillEnvironment* pFormFillEnv =
690 HandleToCPDFSDKEnvironment(hHandle);
691 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 return;
693
dsinclair7cbe68e2016-10-12 11:56:23 -0700694 CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument();
Lei Zhang1fed5a22017-06-01 11:52:22 -0700695 CPDF_Dictionary* pDict = pDoc->GetRoot();
696 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700698
Lei Zhang1fed5a22017-06-01 11:52:22 -0700699 CPDF_AAction aa(pDict->GetDictFor("AA"));
700 auto type = static_cast<CPDF_AAction::AActionType>(aaType);
701 if (aa.ActionExist(type)) {
702 CPDF_Action action = aa.GetAction(type);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 CPDFSDK_ActionHandler* pActionHandler =
dsinclair79db6092016-09-14 07:27:21 -0700704 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander();
Lei Zhang1fed5a22017-06-01 11:52:22 -0700705 pActionHandler->DoAction_Document(action, type, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 }
707}
708
709DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
710 FPDF_FORMHANDLE hHandle,
711 int aaType) {
dsinclairf3fbe832016-10-11 13:08:04 -0700712 CPDFSDK_FormFillEnvironment* pFormFillEnv =
713 HandleToCPDFSDKEnvironment(hHandle);
714 if (!pFormFillEnv)
tonikitoo401d4f22016-08-10 11:37:45 -0700715 return;
716
Tom Sepez540c4362015-11-24 13:33:57 -0800717 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
718 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700719 if (!pPDFPage)
720 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700721
dsinclair7cbe68e2016-10-12 11:56:23 -0700722 if (!pFormFillEnv->GetPageView(pPage, false))
tonikitoo401d4f22016-08-10 11:37:45 -0700723 return;
724
dsinclairf3fbe832016-10-11 13:08:04 -0700725 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700726 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get();
dsinclair38fd8442016-09-15 10:15:32 -0700727 CPDF_AAction aa(pPageDict->GetDictFor("AA"));
Lei Zhang1fed5a22017-06-01 11:52:22 -0700728 CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN
729 ? CPDF_AAction::OpenPage
730 : CPDF_AAction::ClosePage;
731 if (aa.ActionExist(type)) {
732 CPDF_Action action = aa.GetAction(type);
733 pActionHandler->DoAction_Page(action, type, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700735}