blob: 37ecce509dc85da2d1289d54930f50628bc419d5 [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"
dsinclair74a34fc2016-09-29 16:41:42 -070019#include "core/fxge/cfx_fxgedevice.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"
dsinclair5b493092016-09-29 20:20:24 -070032#include "xfa/fxfa/xfa_ffdocview.h"
33#include "xfa/fxfa/xfa_ffpageview.h"
34#include "xfa/fxfa/xfa_ffwidget.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080035#endif // PDF_ENABLE_XFA
36
Tom Sepezdcbc02f2015-07-17 09:16:17 -070037namespace {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038
dsinclair735606d2016-10-05 15:47:02 -070039CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment(
40 FPDF_FORMHANDLE handle) {
41 return static_cast<CPDFSDK_FormFillEnvironment*>(handle);
dsinclair79db6092016-09-14 07:27:21 -070042}
43
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -070045 CPDFSDK_FormFillEnvironment* pFormFillEnv =
46 HandleToCPDFSDKEnvironment(hHandle);
dsinclair7cbe68e2016-10-12 11:56:23 -070047 return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070048}
Bo Xufdc00a72014-10-28 23:03:33 -070049
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
51 FPDF_PAGE page) {
Tom Sepez540c4362015-11-24 13:33:57 -080052 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
53 if (!pPage)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 return nullptr;
Tom Sepez0b133982015-07-28 11:23:22 -070055
dsinclairf3fbe832016-10-11 13:08:04 -070056 CPDFSDK_FormFillEnvironment* pFormFillEnv =
57 HandleToCPDFSDKEnvironment(hHandle);
dsinclair7cbe68e2016-10-12 11:56:23 -070058 return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070059}
Bo Xufdc00a72014-10-28 23:03:33 -070060
Tom Sepezab277682016-02-17 10:07:21 -080061#ifdef PDF_ENABLE_XFA
62std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) {
63 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle);
64}
65
66FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) {
67 return reinterpret_cast<FPDF_STRINGHANDLE>(strings);
68}
69#endif // PDF_ENABLE_XFA
70
thestigbefa4502016-05-26 20:15:19 -070071void FFLCommon(FPDF_FORMHANDLE hHandle,
72 FPDF_BITMAP bitmap,
73 FPDF_RECORDER recorder,
74 FPDF_PAGE page,
75 int start_x,
76 int start_y,
77 int size_x,
78 int size_y,
79 int rotate,
80 int flags) {
81 if (!hHandle)
82 return;
83
84 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
85 if (!pPage)
86 return;
87
jaepark738766e2016-09-02 18:51:44 -070088#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070089 CPDFXFA_Context* pContext = pPage->GetContext();
90 if (!pContext)
thestigbefa4502016-05-26 20:15:19 -070091 return;
dsinclair521b7502016-11-02 13:02:28 -070092 CPDF_Document* pPDFDoc = pContext->GetPDFDoc();
thestigbefa4502016-05-26 20:15:19 -070093 if (!pPDFDoc)
94 return;
dsinclairf3fbe832016-10-11 13:08:04 -070095 CPDFSDK_FormFillEnvironment* pFormFillEnv =
96 HandleToCPDFSDKEnvironment(hHandle);
97 if (!pFormFillEnv)
thestigbefa4502016-05-26 20:15:19 -070098 return;
99#endif // PDF_ENABLE_XFA
100
Dan Sinclair1b08df12017-02-09 09:17:20 -0500101 CFX_Matrix matrix =
102 pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate);
thestigbefa4502016-05-26 20:15:19 -0700103 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y);
104
105 std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice);
106#ifdef _SKIA_SUPPORT_
107 pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
108#endif
109 pDevice->Attach(CFXBitmapFromFPDFBitmap(bitmap), false, nullptr, false);
110 pDevice->SaveState();
111 pDevice->SetClip_Rect(clip);
112
thestigbefa4502016-05-26 20:15:19 -0700113 CPDF_RenderOptions options;
114 if (flags & FPDF_LCD_TEXT)
115 options.m_Flags |= RENDER_CLEARTYPE;
116 else
117 options.m_Flags &= ~RENDER_CLEARTYPE;
118
119 // Grayscale output
120 if (flags & FPDF_GRAYSCALE) {
121 options.m_ColorMode = RENDER_COLOR_GRAY;
122 options.m_ForeColor = 0;
123 options.m_BackColor = 0xffffff;
124 }
125 options.m_AddFlags = flags >> 8;
jaepark75f84a52016-09-09 15:39:09 -0700126 options.m_bDrawAnnots = flags & FPDF_ANNOT;
thestigbefa4502016-05-26 20:15:19 -0700127
jaepark738766e2016-09-02 18:51:44 -0700128#ifdef PDF_ENABLE_XFA
Tom Sepezf716f0b2017-01-30 10:04:07 -0800129 options.m_pOCContext =
130 pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View);
dsinclair7cbe68e2016-10-12 11:56:23 -0700131 if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true))
thestigbefa4502016-05-26 20:15:19 -0700132 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
jaepark738766e2016-09-02 18:51:44 -0700133#else // PDF_ENABLE_XFA
Tom Sepezf716f0b2017-01-30 10:04:07 -0800134 options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>(
135 pPage->m_pDocument, CPDF_OCContext::View);
jaepark738766e2016-09-02 18:51:44 -0700136 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
137 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
thestigbefa4502016-05-26 20:15:19 -0700138#endif // PDF_ENABLE_XFA
139
caryclark8f875502016-12-06 13:49:34 -0800140 pDevice->RestoreState(false);
141#ifdef _SKIA_SUPPORT_PATHS_
142 pDevice->Flush();
caryclark687fbde2016-11-22 12:44:25 -0800143 CFXBitmapFromFPDFBitmap(bitmap)->UnPreMultiply();
144#endif
thestigbefa4502016-05-26 20:15:19 -0700145}
146
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700147} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -0700148
Lei Zhangbdf72c32015-08-14 19:24:08 -0700149DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
150 FPDF_PAGE page,
151 double page_x,
152 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700153 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700154 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700155 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 if (pPage) {
thestigdb1a24e2016-05-23 16:55:09 -0700157 CPDF_InterForm interform(pPage->m_pDocument);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800158 CPDF_FormControl* pFormCtrl =
159 interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x),
160 static_cast<FX_FLOAT>(page_y), nullptr);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700161 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800164 return pFormField ? pFormField->GetFieldType() : -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 }
166
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800167#ifdef PDF_ENABLE_XFA
168 CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
169 if (!pXFAPage)
170 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171
dsinclairdf4bc592016-03-31 20:34:43 -0700172 CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800173 if (!pPageView)
174 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175
dsinclairdf4bc592016-03-31 20:34:43 -0700176 CXFA_FFDocView* pDocView = pPageView->GetDocView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800177 if (!pDocView)
178 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179
dsinclairdf4bc592016-03-31 20:34:43 -0700180 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800181 if (!pWidgetHandler)
182 return -1;
183
tsepezcc4d6d82016-05-16 13:21:03 -0700184 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700185 pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form,
186 XFA_WidgetStatus_Viewable));
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800187 if (!pWidgetIterator)
188 return -1;
189
dsinclairdf4bc592016-03-31 20:34:43 -0700190 CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800191 while (pXFAAnnot) {
Dan Sinclair1b08df12017-02-09 09:17:20 -0500192 CFX_RectF rcBBox = pXFAAnnot->GetBBox(0);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800193 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
194 rcBBox.top + rcBBox.height);
195 rcWidget.left -= 1.0f;
196 rcWidget.right += 1.0f;
197 rcWidget.bottom -= 1.0f;
198 rcWidget.top += 1.0f;
199
200 if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x),
201 static_cast<FX_FLOAT>(page_y))) {
202 return FPDF_FORMFIELD_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 }
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800204 pXFAAnnot = pWidgetIterator->MoveToNext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800206#endif // PDF_ENABLE_XFA
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800207 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208}
209
Lei Zhangbdf72c32015-08-14 19:24:08 -0700210DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
211 FPDF_PAGE page,
212 double page_x,
213 double page_y) {
214 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y);
215}
216
217DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
218 FPDF_PAGE page,
219 double page_x,
220 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700221 if (!hHandle)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700222 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700223 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
224 if (!pPage)
225 return -1;
thestigdb1a24e2016-05-23 16:55:09 -0700226 CPDF_InterForm interform(pPage->m_pDocument);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700227 int z_order = -1;
228 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y,
229 &z_order);
230 return z_order;
231}
232
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233DLLEXPORT FPDF_FORMHANDLE STDCALL
234FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
235 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800236#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800237 const int kRequiredVersion = 2;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800238#else // PDF_ENABLE_XFA
239 const int kRequiredVersion = 1;
240#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800241 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
Tom Sepez540c4362015-11-24 13:33:57 -0800244 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
245 if (!pDocument)
246 return nullptr;
247
Tom Sepez40e9ff32015-11-30 12:39:54 -0800248#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700249 // If the CPDFXFA_Context has a FormFillEnvironment already then we've done
dsinclair8779fa82016-10-12 12:05:44 -0700250 // this and can just return the old Env. Otherwise, we'll end up setting a new
251 // environment into the XFADocument and, that could get weird.
dsinclair655fcca2016-10-11 13:53:37 -0700252 if (pDocument->GetFormFillEnv())
253 return pDocument->GetFormFillEnv();
dsinclaira939bfe2016-09-22 13:18:45 -0700254#endif
255
dsinclairf3fbe832016-10-11 13:08:04 -0700256 CPDFSDK_FormFillEnvironment* pFormFillEnv =
dsinclair735606d2016-10-05 15:47:02 -0700257 new CPDFSDK_FormFillEnvironment(pDocument, formInfo);
dsinclaira939bfe2016-09-22 13:18:45 -0700258
259#ifdef PDF_ENABLE_XFA
dsinclair655fcca2016-10-11 13:53:37 -0700260 pDocument->SetFormFillEnv(pFormFillEnv);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800261#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700262
dsinclairf3fbe832016-10-11 13:08:04 -0700263 return pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264}
265
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266DLLEXPORT void STDCALL
267FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
268 if (!hHandle)
269 return;
dsinclaira939bfe2016-09-22 13:18:45 -0700270
dsinclairf3fbe832016-10-11 13:08:04 -0700271 CPDFSDK_FormFillEnvironment* pFormFillEnv =
272 HandleToCPDFSDKEnvironment(hHandle);
dsinclaira939bfe2016-09-22 13:18:45 -0700273
Tom Sepez40e9ff32015-11-30 12:39:54 -0800274#ifdef PDF_ENABLE_XFA
dsinclair21161052016-10-05 15:46:15 -0700275 // Reset the focused annotations and remove the SDK document from the
276 // XFA document.
dsinclair7cbe68e2016-10-12 11:56:23 -0700277 pFormFillEnv->ClearAllFocusedAnnots();
dsinclairf3fbe832016-10-11 13:08:04 -0700278 // If the document was closed first, it's possible the XFA document
279 // is now a nullptr.
dsinclair521b7502016-11-02 13:02:28 -0700280 if (pFormFillEnv->GetXFAContext())
281 pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800282#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700283
dsinclairf3fbe832016-10-11 13:08:04 -0700284 delete pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700285}
286
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
288 FPDF_PAGE page,
289 int modifier,
290 double page_x,
291 double page_y) {
292 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
293 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700294 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700295
Tom Sepez281a9ea2016-02-26 14:24:28 -0800296 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 return pPageView->OnMouseMove(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700298}
299
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle,
301 FPDF_PAGE page,
302 int modifier,
303 double page_x,
304 double page_y) {
305 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
306 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700307 return false;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700308
Tom Sepez281a9ea2016-02-26 14:24:28 -0800309 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 return pPageView->OnLButtonDown(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311}
312
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
314 FPDF_PAGE page,
315 int modifier,
316 double page_x,
317 double page_y) {
318 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
319 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700320 return false;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700321
Tom Sepez281a9ea2016-02-26 14:24:28 -0800322 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 return pPageView->OnLButtonUp(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700324}
325
Tom Sepez51da0932015-11-25 16:05:49 -0800326#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
328 FPDF_PAGE page,
329 int modifier,
330 double page_x,
331 double page_y) {
332 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
333 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700334 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700335
Tom Sepez281a9ea2016-02-26 14:24:28 -0800336 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 return pPageView->OnRButtonDown(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700338}
339
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
341 FPDF_PAGE page,
342 int modifier,
343 double page_x,
344 double page_y) {
345 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
346 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700347 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700348
Tom Sepez281a9ea2016-02-26 14:24:28 -0800349 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 return pPageView->OnRButtonUp(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700351}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800352#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700353
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
355 FPDF_PAGE page,
356 int nKeyCode,
357 int modifier) {
358 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
359 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700360 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700361
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363}
364
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
366 FPDF_PAGE page,
367 int nKeyCode,
368 int modifier) {
369 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
370 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700371 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700372
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700374}
375
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
377 FPDF_PAGE page,
378 int nChar,
379 int modifier) {
380 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
381 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700382 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385}
386
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700388 CPDFSDK_FormFillEnvironment* pFormFillEnv =
389 HandleToCPDFSDKEnvironment(hHandle);
390 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700391 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700392 return pFormFillEnv->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393}
394
Cary Clark399be5b2016-03-14 16:51:29 -0400395DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
396 FPDF_BITMAP bitmap,
397 FPDF_PAGE page,
398 int start_x,
399 int start_y,
400 int size_x,
401 int size_y,
402 int rotate,
403 int flags) {
404 FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
405 rotate, flags);
406}
407
408#ifdef _SKIA_SUPPORT_
409DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle,
410 FPDF_RECORDER recorder,
411 FPDF_PAGE page,
412 int start_x,
413 int start_y,
414 int size_x,
415 int size_y,
416 int rotate,
417 int flags) {
418 FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y,
419 rotate, flags);
420}
421#endif
422
Tom Sepez40e9ff32015-11-30 12:39:54 -0800423#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
425 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700426 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700428
dsinclair521b7502016-11-02 13:02:28 -0700429 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
430 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
431 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700433
dsinclair221caf62016-04-04 12:08:40 -0700434 static_cast<CXFA_FFWidget*>(hWidget)->Undo();
Bo Xufdc00a72014-10-28 23:03:33 -0700435}
dsinclair521b7502016-11-02 13:02:28 -0700436
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
438 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700439 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700441
dsinclair521b7502016-11-02 13:02:28 -0700442 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
443 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
444 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700446
dsinclair221caf62016-04-04 12:08:40 -0700447 static_cast<CXFA_FFWidget*>(hWidget)->Redo();
Bo Xufdc00a72014-10-28 23:03:33 -0700448}
449
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document,
451 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700452 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700454
dsinclair521b7502016-11-02 13:02:28 -0700455 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
456 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
457 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700459
dsinclair221caf62016-04-04 12:08:40 -0700460 static_cast<CXFA_FFWidget*>(hWidget)->SelectAll();
Bo Xufdc00a72014-10-28 23:03:33 -0700461}
dsinclair521b7502016-11-02 13:02:28 -0700462
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
464 FPDF_WIDGET hWidget,
465 FPDF_WIDESTRING wsText,
466 FPDF_DWORD* size) {
dsinclair221caf62016-04-04 12:08:40 -0700467 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700469
dsinclair521b7502016-11-02 13:02:28 -0700470 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
471 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
472 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700474
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700476 static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700479 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
thestigbefa4502016-05-26 20:15:19 -0700480 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 *size = len;
482 return;
483 }
Bo Xufdc00a72014-10-28 23:03:33 -0700484
weili47ca6922016-03-31 15:08:27 -0700485 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 if (real_size > 0) {
487 FXSYS_memcpy((void*)wsText,
488 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
489 real_size * sizeof(unsigned short));
490 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
491 }
492 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700493}
Tom Sepezab277682016-02-17 10:07:21 -0800494
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
496 FPDF_WIDGET hWidget,
497 FPDF_WIDESTRING wsText,
498 FPDF_DWORD* size) {
thestigbefa4502016-05-26 20:15:19 -0700499 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 return;
thestigbefa4502016-05-26 20:15:19 -0700501
dsinclair521b7502016-11-02 13:02:28 -0700502 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
503 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
504 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700506
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700508 static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700509
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700511 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
dsinclair221caf62016-04-04 12:08:40 -0700512 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 *size = len;
514 return;
515 }
Bo Xufdc00a72014-10-28 23:03:33 -0700516
weili47ca6922016-03-31 15:08:27 -0700517 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 if (real_size > 0) {
519 FXSYS_memcpy((void*)wsText,
520 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
521 real_size * sizeof(unsigned short));
522 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
523 }
524 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700525}
Tom Sepezab277682016-02-17 10:07:21 -0800526
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
528 FPDF_WIDGET hWidget,
529 FPDF_WIDESTRING wsText,
530 FPDF_DWORD size) {
dsinclair221caf62016-04-04 12:08:40 -0700531 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700533
dsinclair521b7502016-11-02 13:02:28 -0700534 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
535 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
536 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700538
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
dsinclair221caf62016-04-04 12:08:40 -0700540 static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700541}
Tom Sepezab277682016-02-17 10:07:21 -0800542
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543DLLEXPORT void STDCALL
544FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
545 FPDF_WIDGET hWidget,
546 float x,
547 float y,
548 FPDF_BYTESTRING bsText) {
dsinclair221caf62016-04-04 12:08:40 -0700549 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700551
dsinclair521b7502016-11-02 13:02:28 -0700552 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
553 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
554 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700556
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 CFX_PointF ptPopup;
558 ptPopup.x = x;
559 ptPopup.y = y;
560 CFX_ByteStringC bs(bsText);
dsinclair221caf62016-04-04 12:08:40 -0700561 static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700562}
Tom Sepezab277682016-02-17 10:07:21 -0800563
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564DLLEXPORT void STDCALL
565FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
566 FPDF_WIDGET hWidget,
567 float x,
568 float y,
569 FPDF_STRINGHANDLE* stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800570 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700572
dsinclair521b7502016-11-02 13:02:28 -0700573 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
574 if (pContext->GetDocType() != XFA_DOCTYPE_Dynamic &&
575 pContext->GetDocType() != XFA_DOCTYPE_Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700577
Tom Sepezab277682016-02-17 10:07:21 -0800578 std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 CFX_PointF ptPopup;
580 ptPopup.x = x;
581 ptPopup.y = y;
dsinclair221caf62016-04-04 12:08:40 -0700582 static_cast<CXFA_FFWidget*>(hWidget)
583 ->GetSuggestWords(ptPopup, *sSuggestWords);
Tom Sepezab277682016-02-17 10:07:21 -0800584 *stringHandle = ToFPDFStringHandle(sSuggestWords);
Bo Xufdc00a72014-10-28 23:03:33 -0700585}
Tom Sepezab277682016-02-17 10:07:21 -0800586
587DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
588 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
589 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700590}
Tom Sepezab277682016-02-17 10:07:21 -0800591
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592DLLEXPORT FPDF_BOOL STDCALL
Tom Sepezab277682016-02-17 10:07:21 -0800593FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 int index,
595 FPDF_BYTESTRING bsText,
596 FPDF_DWORD* size) {
Tom Sepezab277682016-02-17 10:07:21 -0800597 if (!sHandle || !size)
tsepez4cf55152016-11-02 14:37:54 -0700598 return false;
Tom Sepezab277682016-02-17 10:07:21 -0800599
600 int count = FPDF_StringHandleCounts(sHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 if (index < 0 || index >= count)
tsepez4cf55152016-11-02 14:37:54 -0700602 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700603
Tom Sepezab277682016-02-17 10:07:21 -0800604 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
weili47ca6922016-03-31 15:08:27 -0700605 uint32_t len = (*sSuggestWords)[index].GetLength();
Tom Sepezab277682016-02-17 10:07:21 -0800606 if (!bsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 *size = len;
tsepez4cf55152016-11-02 14:37:54 -0700608 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 }
610
weili47ca6922016-03-31 15:08:27 -0700611 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 if (real_size > 0)
tsepezb4c9f3f2016-04-13 15:41:21 -0700613 FXSYS_memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 *size = real_size;
tsepez4cf55152016-11-02 14:37:54 -0700615 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700616}
Tom Sepezab277682016-02-17 10:07:21 -0800617
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618DLLEXPORT void STDCALL
619FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800620 delete FromFPDFStringHandle(stringHandle);
Bo Xufdc00a72014-10-28 23:03:33 -0700621}
622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623DLLEXPORT FPDF_BOOL STDCALL
624FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
625 FPDF_BYTESTRING bsText,
626 FPDF_DWORD size) {
Tom Sepezab277682016-02-17 10:07:21 -0800627 if (!stringHandle || !bsText || size == 0)
tsepez4cf55152016-11-02 14:37:54 -0700628 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700629
Tom Sepezab277682016-02-17 10:07:21 -0800630 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
tsepez4cf55152016-11-02 14:37:54 -0700631 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700632}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800633#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
636 int fieldType,
637 unsigned long color) {
638 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
639 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700640}
641
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
643 unsigned char alpha) {
644 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
645 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646}
647
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
649 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
650 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651}
652
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
654 FPDF_FORMHANDLE hHandle) {
655 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
tsepez4cf55152016-11-02 14:37:54 -0700656 pPageView->SetValid(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700657}
658
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
660 FPDF_FORMHANDLE hHandle) {
Tom Sepez540c4362015-11-24 13:33:57 -0800661 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700663
dsinclairf3fbe832016-10-11 13:08:04 -0700664 CPDFSDK_FormFillEnvironment* pFormFillEnv =
665 HandleToCPDFSDKEnvironment(hHandle);
666 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700668
Tom Sepez540c4362015-11-24 13:33:57 -0800669 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
670 if (!pPage)
671 return;
672
dsinclair7cbe68e2016-10-12 11:56:23 -0700673 CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674 if (pPageView) {
tsepez4cf55152016-11-02 14:37:54 -0700675 pPageView->SetValid(false);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800676 // RemovePageView() takes care of the delete for us.
dsinclair7cbe68e2016-10-12 11:56:23 -0700677 pFormFillEnv->RemovePageView(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 }
679}
680
681DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700682 CPDFSDK_FormFillEnvironment* pFormFillEnv =
683 HandleToCPDFSDKEnvironment(hHandle);
684 if (pFormFillEnv && pFormFillEnv->IsJSInitiated())
dsinclair7cbe68e2016-10-12 11:56:23 -0700685 pFormFillEnv->ProcJavascriptFun();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686}
687
688DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700689 CPDFSDK_FormFillEnvironment* pFormFillEnv =
690 HandleToCPDFSDKEnvironment(hHandle);
691 if (pFormFillEnv && pFormFillEnv->IsJSInitiated())
dsinclair7cbe68e2016-10-12 11:56:23 -0700692 pFormFillEnv->ProcOpenAction();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693}
694
695DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
696 int aaType) {
dsinclairf3fbe832016-10-11 13:08:04 -0700697 CPDFSDK_FormFillEnvironment* pFormFillEnv =
698 HandleToCPDFSDKEnvironment(hHandle);
699 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 return;
701
dsinclair7cbe68e2016-10-12 11:56:23 -0700702 CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 CPDF_Dictionary* pDic = pDoc->GetRoot();
704 if (!pDic)
705 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700706
dsinclair38fd8442016-09-15 10:15:32 -0700707 CPDF_AAction aa(pDic->GetDictFor("AA"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) {
709 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
710 CPDFSDK_ActionHandler* pActionHandler =
dsinclair79db6092016-09-14 07:27:21 -0700711 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType,
dsinclairf3fbe832016-10-11 13:08:04 -0700713 pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 }
715}
716
717DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
718 FPDF_FORMHANDLE hHandle,
719 int aaType) {
Tom Sepez540c4362015-11-24 13:33:57 -0800720 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700722
dsinclairf3fbe832016-10-11 13:08:04 -0700723 CPDFSDK_FormFillEnvironment* pFormFillEnv =
724 HandleToCPDFSDKEnvironment(hHandle);
725 if (!pFormFillEnv)
tonikitoo401d4f22016-08-10 11:37:45 -0700726 return;
727
Tom Sepez540c4362015-11-24 13:33:57 -0800728 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
729 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700730 if (!pPDFPage)
731 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700732
dsinclair7cbe68e2016-10-12 11:56:23 -0700733 if (!pFormFillEnv->GetPageView(pPage, false))
tonikitoo401d4f22016-08-10 11:37:45 -0700734 return;
735
dsinclairf3fbe832016-10-11 13:08:04 -0700736 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
tonikitoo401d4f22016-08-10 11:37:45 -0700737 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict;
dsinclair38fd8442016-09-15 10:15:32 -0700738 CPDF_AAction aa(pPageDict->GetDictFor("AA"));
tonikitoo401d4f22016-08-10 11:37:45 -0700739 if (FPDFPAGE_AACTION_OPEN == aaType) {
740 if (aa.ActionExist(CPDF_AAction::OpenPage)) {
741 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
dsinclairf3fbe832016-10-11 13:08:04 -0700742 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage,
743 pFormFillEnv);
tonikitoo401d4f22016-08-10 11:37:45 -0700744 }
745 } else {
746 if (aa.ActionExist(CPDF_AAction::ClosePage)) {
747 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
dsinclairf3fbe832016-10-11 13:08:04 -0700748 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage,
749 pFormFillEnv);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700750 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752}