blob: e541b81cc30be50abd6524986785f2d0c150d63d [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
Dan Sinclairf55e72e2017-07-13 14:53:28 -0400129 if (flags & FPDF_GRAYSCALE)
130 options.m_ColorMode = CPDF_RenderOptions::kGray;
131
Tom Sepez1629f602017-04-21 14:11:26 -0700132 options.m_bDrawAnnots = flags & FPDF_ANNOT;
thestigbefa4502016-05-26 20:15:19 -0700133
jaepark738766e2016-09-02 18:51:44 -0700134#ifdef PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700135 options.m_pOCContext =
136 pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View);
137 if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true))
138 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
jaepark738766e2016-09-02 18:51:44 -0700139#else // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700140 options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>(
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700141 pPage->m_pDocument.Get(), CPDF_OCContext::View);
Tom Sepez1629f602017-04-21 14:11:26 -0700142 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
143 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
thestigbefa4502016-05-26 20:15:19 -0700144#endif // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700145 }
caryclark8f875502016-12-06 13:49:34 -0800146#ifdef _SKIA_SUPPORT_PATHS_
Cary Clark364d18b2017-07-25 10:39:10 -0400147 pDevice->Flush(true);
Tom Sepezf0799fe2017-03-28 09:31:32 -0700148 holder->UnPreMultiply();
caryclark687fbde2016-11-22 12:44:25 -0800149#endif
thestigbefa4502016-05-26 20:15:19 -0700150}
151
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700152} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -0700153
Lei Zhangbdf72c32015-08-14 19:24:08 -0700154DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
155 FPDF_PAGE page,
156 double page_x,
157 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700158 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700159 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700160 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 if (pPage) {
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700162 CPDF_InterForm interform(pPage->m_pDocument.Get());
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500163 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400164 pPage,
165 CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500166 nullptr);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700167 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800170 return pFormField ? pFormField->GetFieldType() : -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 }
172
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800173#ifdef PDF_ENABLE_XFA
174 CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
175 if (!pXFAPage)
176 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177
dsinclairdf4bc592016-03-31 20:34:43 -0700178 CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800179 if (!pPageView)
180 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181
dsinclairdf4bc592016-03-31 20:34:43 -0700182 CXFA_FFDocView* pDocView = pPageView->GetDocView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800183 if (!pDocView)
184 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185
dsinclairdf4bc592016-03-31 20:34:43 -0700186 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800187 if (!pWidgetHandler)
188 return -1;
189
tsepezcc4d6d82016-05-16 13:21:03 -0700190 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700191 pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form,
192 XFA_WidgetStatus_Viewable));
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800193 if (!pWidgetIterator)
194 return -1;
195
dsinclairdf4bc592016-03-31 20:34:43 -0700196 CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800197 while (pXFAAnnot) {
Dan Sinclair1b08df12017-02-09 09:17:20 -0500198 CFX_RectF rcBBox = pXFAAnnot->GetBBox(0);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800199 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
200 rcBBox.top + rcBBox.height);
Lei Zhang1fed5a22017-06-01 11:52:22 -0700201 rcWidget.Inflate(1.0f, 1.0f);
Dan Sinclair05df0752017-03-14 14:43:42 -0400202 if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x),
203 static_cast<float>(page_y)))) {
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800204 return FPDF_FORMFIELD_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 }
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800206 pXFAAnnot = pWidgetIterator->MoveToNext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800208#endif // PDF_ENABLE_XFA
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800209 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210}
211
Lei Zhangbdf72c32015-08-14 19:24:08 -0700212DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
213 FPDF_PAGE page,
214 double page_x,
215 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700216 if (!hHandle)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700217 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700218 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
219 if (!pPage)
220 return -1;
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700221 CPDF_InterForm interform(pPage->m_pDocument.Get());
Lei Zhangbdf72c32015-08-14 19:24:08 -0700222 int z_order = -1;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500223 (void)interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400224 pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500225 &z_order);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700226 return z_order;
227}
228
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229DLLEXPORT FPDF_FORMHANDLE STDCALL
230FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
231 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800232#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800233 const int kRequiredVersion = 2;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800234#else // PDF_ENABLE_XFA
235 const int kRequiredVersion = 1;
236#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800237 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Tom Sepez540c4362015-11-24 13:33:57 -0800240 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
241 if (!pDocument)
242 return nullptr;
243
Tom Sepez40e9ff32015-11-30 12:39:54 -0800244#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700245 // If the CPDFXFA_Context has a FormFillEnvironment already then we've done
dsinclair8779fa82016-10-12 12:05:44 -0700246 // this and can just return the old Env. Otherwise, we'll end up setting a new
247 // environment into the XFADocument and, that could get weird.
dsinclair655fcca2016-10-11 13:53:37 -0700248 if (pDocument->GetFormFillEnv())
249 return pDocument->GetFormFillEnv();
dsinclaira939bfe2016-09-22 13:18:45 -0700250#endif
251
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700252 auto pFormFillEnv =
253 pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>(pDocument, formInfo);
dsinclaira939bfe2016-09-22 13:18:45 -0700254
255#ifdef PDF_ENABLE_XFA
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700256 pDocument->SetFormFillEnv(pFormFillEnv.get());
Tom Sepez40e9ff32015-11-30 12:39:54 -0800257#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700258
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700259 return pFormFillEnv.release(); // Caller takes ownership.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260}
261
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262DLLEXPORT void STDCALL
263FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700264 CPDFSDK_FormFillEnvironment* pFormFillEnv =
265 HandleToCPDFSDKEnvironment(hHandle);
Lei Zhang1fed5a22017-06-01 11:52:22 -0700266 if (!pFormFillEnv)
267 return;
dsinclaira939bfe2016-09-22 13:18:45 -0700268
Tom Sepez40e9ff32015-11-30 12:39:54 -0800269#ifdef PDF_ENABLE_XFA
dsinclair21161052016-10-05 15:46:15 -0700270 // Reset the focused annotations and remove the SDK document from the
271 // XFA document.
dsinclair7cbe68e2016-10-12 11:56:23 -0700272 pFormFillEnv->ClearAllFocusedAnnots();
dsinclairf3fbe832016-10-11 13:08:04 -0700273 // If the document was closed first, it's possible the XFA document
274 // is now a nullptr.
dsinclair521b7502016-11-02 13:02:28 -0700275 if (pFormFillEnv->GetXFAContext())
276 pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800277#endif // PDF_ENABLE_XFA
dsinclairf3fbe832016-10-11 13:08:04 -0700278 delete pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279}
280
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
282 FPDF_PAGE page,
283 int modifier,
284 double page_x,
285 double page_y) {
286 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
287 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700288 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500289 return pPageView->OnMouseMove(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290}
291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(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->OnLButtonDown(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_OnLButtonUp(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;
Lei Zhang1fed5a22017-06-01 11:52:22 -0700311 return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312}
313
Tom Sepez51da0932015-11-25 16:05:49 -0800314#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
316 FPDF_PAGE page,
317 int modifier,
318 double page_x,
319 double page_y) {
320 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
321 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700322 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500323 return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700324}
325
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(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;
Lei Zhang1fed5a22017-06-01 11:52:22 -0700334 return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700335}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800336#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700337
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
339 FPDF_PAGE page,
340 int nKeyCode,
341 int modifier) {
342 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
343 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700344 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700346}
347
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
349 FPDF_PAGE page,
350 int nKeyCode,
351 int modifier) {
352 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
353 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700354 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356}
357
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
359 FPDF_PAGE page,
360 int nChar,
361 int modifier) {
362 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
363 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700364 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366}
367
Diana Gagedce2d722017-06-20 11:17:11 -0700368DLLEXPORT unsigned long STDCALL FORM_GetSelectedText(FPDF_FORMHANDLE hHandle,
369 FPDF_PAGE page,
370 void* buffer,
371 unsigned long buflen) {
372 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
373 if (!pPageView)
374 return 0;
375
376 CFX_WideString wide_str_form_text = pPageView->GetSelectedText();
377 CFX_ByteString encoded_form_text = wide_str_form_text.UTF16LE_Encode();
378 unsigned long form_text_len = encoded_form_text.GetLength();
379
380 if (buffer && buflen >= form_text_len)
381 memcpy(buffer, encoded_form_text.c_str(), form_text_len);
382
383 return form_text_len;
384}
385
Diana Gage1c7f1422017-07-24 11:19:52 -0700386DLLEXPORT void STDCALL FORM_DeleteSelectedText(FPDF_FORMHANDLE hHandle,
387 FPDF_PAGE page) {
388 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
389 if (!pPageView)
390 return;
391 pPageView->DeleteSelectedText();
392}
393
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700395 CPDFSDK_FormFillEnvironment* pFormFillEnv =
396 HandleToCPDFSDKEnvironment(hHandle);
397 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700398 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700399 return pFormFillEnv->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700400}
401
Cary Clark399be5b2016-03-14 16:51:29 -0400402DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
403 FPDF_BITMAP bitmap,
404 FPDF_PAGE page,
405 int start_x,
406 int start_y,
407 int size_x,
408 int size_y,
409 int rotate,
410 int flags) {
411 FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
412 rotate, flags);
413}
414
415#ifdef _SKIA_SUPPORT_
416DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle,
417 FPDF_RECORDER recorder,
418 FPDF_PAGE page,
419 int start_x,
420 int start_y,
421 int size_x,
422 int size_y,
423 int rotate,
424 int flags) {
425 FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y,
426 rotate, flags);
427}
428#endif
429
Tom Sepez40e9ff32015-11-30 12:39:54 -0800430#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
432 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700433 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700435
dsinclair521b7502016-11-02 13:02:28 -0700436 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400437 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
438 pContext->GetDocType() != XFA_DocType::Static) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 return;
Dan Sinclaircdba7472017-03-23 09:17:10 -0400440 }
Bo Xufdc00a72014-10-28 23:03:33 -0700441
dsinclair221caf62016-04-04 12:08:40 -0700442 static_cast<CXFA_FFWidget*>(hWidget)->Undo();
Bo Xufdc00a72014-10-28 23:03:33 -0700443}
dsinclair521b7502016-11-02 13:02:28 -0700444
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
446 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700447 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700449
dsinclair521b7502016-11-02 13:02:28 -0700450 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400451 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
452 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700454
dsinclair221caf62016-04-04 12:08:40 -0700455 static_cast<CXFA_FFWidget*>(hWidget)->Redo();
Bo Xufdc00a72014-10-28 23:03:33 -0700456}
457
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document,
459 FPDF_WIDGET hWidget) {
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
dsinclair221caf62016-04-04 12:08:40 -0700468 static_cast<CXFA_FFWidget*>(hWidget)->SelectAll();
Bo Xufdc00a72014-10-28 23:03:33 -0700469}
dsinclair521b7502016-11-02 13:02:28 -0700470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
472 FPDF_WIDGET hWidget,
473 FPDF_WIDESTRING wsText,
474 FPDF_DWORD* size) {
dsinclair221caf62016-04-04 12:08:40 -0700475 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700477
dsinclair521b7502016-11-02 13:02:28 -0700478 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400479 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
480 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700482
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700484 static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700485
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700487 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
thestigbefa4502016-05-26 20:15:19 -0700488 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 *size = len;
490 return;
491 }
Bo Xufdc00a72014-10-28 23:03:33 -0700492
weili47ca6922016-03-31 15:08:27 -0700493 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400495 memcpy((void*)wsText,
496 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
497 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
499 }
500 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700501}
Tom Sepezab277682016-02-17 10:07:21 -0800502
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
504 FPDF_WIDGET hWidget,
505 FPDF_WIDESTRING wsText,
506 FPDF_DWORD* size) {
thestigbefa4502016-05-26 20:15:19 -0700507 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 return;
thestigbefa4502016-05-26 20:15:19 -0700509
dsinclair521b7502016-11-02 13:02:28 -0700510 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400511 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
512 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700514
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700516 static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700517
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700519 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
dsinclair221caf62016-04-04 12:08:40 -0700520 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 *size = len;
522 return;
523 }
Bo Xufdc00a72014-10-28 23:03:33 -0700524
weili47ca6922016-03-31 15:08:27 -0700525 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400527 memcpy((void*)wsText,
528 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
529 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
531 }
532 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700533}
Tom Sepezab277682016-02-17 10:07:21 -0800534
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
536 FPDF_WIDGET hWidget,
537 FPDF_WIDESTRING wsText,
538 FPDF_DWORD size) {
dsinclair221caf62016-04-04 12:08:40 -0700539 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700541
dsinclair521b7502016-11-02 13:02:28 -0700542 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400543 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
544 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700546
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
dsinclair221caf62016-04-04 12:08:40 -0700548 static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700549}
Tom Sepezab277682016-02-17 10:07:21 -0800550
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551DLLEXPORT void STDCALL
552FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
553 FPDF_WIDGET hWidget,
554 float x,
555 float y,
556 FPDF_BYTESTRING bsText) {
dsinclair221caf62016-04-04 12:08:40 -0700557 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700559
dsinclair521b7502016-11-02 13:02:28 -0700560 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400561 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
562 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700564
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 CFX_PointF ptPopup;
566 ptPopup.x = x;
567 ptPopup.y = y;
568 CFX_ByteStringC bs(bsText);
dsinclair221caf62016-04-04 12:08:40 -0700569 static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700570}
Tom Sepezab277682016-02-17 10:07:21 -0800571
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572DLLEXPORT void STDCALL
573FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
574 FPDF_WIDGET hWidget,
575 float x,
576 float y,
577 FPDF_STRINGHANDLE* stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800578 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700580
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700581 auto* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400582 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
583 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700585
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 CFX_PointF ptPopup;
587 ptPopup.x = x;
588 ptPopup.y = y;
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700589 auto sSuggestWords = pdfium::MakeUnique<std::vector<CFX_ByteString>>();
590 static_cast<CXFA_FFWidget*>(hWidget)->GetSuggestWords(ptPopup,
591 sSuggestWords.get());
592
593 // Caller takes ownership.
594 *stringHandle = ToFPDFStringHandle(sSuggestWords.release());
Bo Xufdc00a72014-10-28 23:03:33 -0700595}
Tom Sepezab277682016-02-17 10:07:21 -0800596
597DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
598 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
599 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700600}
Tom Sepezab277682016-02-17 10:07:21 -0800601
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700602DLLEXPORT FPDF_BOOL STDCALL
Tom Sepezab277682016-02-17 10:07:21 -0800603FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 int index,
605 FPDF_BYTESTRING bsText,
606 FPDF_DWORD* size) {
Tom Sepezab277682016-02-17 10:07:21 -0800607 if (!sHandle || !size)
tsepez4cf55152016-11-02 14:37:54 -0700608 return false;
Tom Sepezab277682016-02-17 10:07:21 -0800609
610 int count = FPDF_StringHandleCounts(sHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 if (index < 0 || index >= count)
tsepez4cf55152016-11-02 14:37:54 -0700612 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700613
Tom Sepezab277682016-02-17 10:07:21 -0800614 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
weili47ca6922016-03-31 15:08:27 -0700615 uint32_t len = (*sSuggestWords)[index].GetLength();
Tom Sepezab277682016-02-17 10:07:21 -0800616 if (!bsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 *size = len;
tsepez4cf55152016-11-02 14:37:54 -0700618 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 }
620
weili47ca6922016-03-31 15:08:27 -0700621 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 if (real_size > 0)
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400623 memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 *size = real_size;
tsepez4cf55152016-11-02 14:37:54 -0700625 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700626}
Tom Sepezab277682016-02-17 10:07:21 -0800627
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628DLLEXPORT void STDCALL
629FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800630 delete FromFPDFStringHandle(stringHandle);
Bo Xufdc00a72014-10-28 23:03:33 -0700631}
632
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633DLLEXPORT FPDF_BOOL STDCALL
634FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
635 FPDF_BYTESTRING bsText,
636 FPDF_DWORD size) {
Tom Sepezab277682016-02-17 10:07:21 -0800637 if (!stringHandle || !bsText || size == 0)
tsepez4cf55152016-11-02 14:37:54 -0700638 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700639
Tom Sepezab277682016-02-17 10:07:21 -0800640 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
tsepez4cf55152016-11-02 14:37:54 -0700641 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700642}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800643#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
646 int fieldType,
647 unsigned long color) {
648 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
649 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650}
651
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
653 unsigned char alpha) {
654 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
655 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
657
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
659 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
660 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661}
662
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
664 FPDF_FORMHANDLE hHandle) {
665 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
tsepez4cf55152016-11-02 14:37:54 -0700666 pPageView->SetValid(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
670 FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700671 CPDFSDK_FormFillEnvironment* pFormFillEnv =
672 HandleToCPDFSDKEnvironment(hHandle);
673 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700675
Tom Sepez540c4362015-11-24 13:33:57 -0800676 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
677 if (!pPage)
678 return;
679
dsinclair7cbe68e2016-10-12 11:56:23 -0700680 CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 if (pPageView) {
tsepez4cf55152016-11-02 14:37:54 -0700682 pPageView->SetValid(false);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800683 // RemovePageView() takes care of the delete for us.
dsinclair7cbe68e2016-10-12 11:56:23 -0700684 pFormFillEnv->RemovePageView(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 }
686}
687
688DLLEXPORT void STDCALL FORM_DoDocumentJSAction(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->ProcJavascriptFun();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693}
694
695DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700696 CPDFSDK_FormFillEnvironment* pFormFillEnv =
697 HandleToCPDFSDKEnvironment(hHandle);
698 if (pFormFillEnv && pFormFillEnv->IsJSInitiated())
dsinclair7cbe68e2016-10-12 11:56:23 -0700699 pFormFillEnv->ProcOpenAction();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700}
701
702DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
703 int aaType) {
dsinclairf3fbe832016-10-11 13:08:04 -0700704 CPDFSDK_FormFillEnvironment* pFormFillEnv =
705 HandleToCPDFSDKEnvironment(hHandle);
706 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 return;
708
dsinclair7cbe68e2016-10-12 11:56:23 -0700709 CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument();
Lei Zhang1fed5a22017-06-01 11:52:22 -0700710 CPDF_Dictionary* pDict = pDoc->GetRoot();
711 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700713
Lei Zhang1fed5a22017-06-01 11:52:22 -0700714 CPDF_AAction aa(pDict->GetDictFor("AA"));
715 auto type = static_cast<CPDF_AAction::AActionType>(aaType);
716 if (aa.ActionExist(type)) {
717 CPDF_Action action = aa.GetAction(type);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 CPDFSDK_ActionHandler* pActionHandler =
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700719 HandleToCPDFSDKEnvironment(hHandle)->GetActionHandler();
Lei Zhang1fed5a22017-06-01 11:52:22 -0700720 pActionHandler->DoAction_Document(action, type, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 }
722}
723
724DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
725 FPDF_FORMHANDLE hHandle,
726 int aaType) {
dsinclairf3fbe832016-10-11 13:08:04 -0700727 CPDFSDK_FormFillEnvironment* pFormFillEnv =
728 HandleToCPDFSDKEnvironment(hHandle);
729 if (!pFormFillEnv)
tonikitoo401d4f22016-08-10 11:37:45 -0700730 return;
731
Tom Sepez540c4362015-11-24 13:33:57 -0800732 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
733 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700734 if (!pPDFPage)
735 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700736
dsinclair7cbe68e2016-10-12 11:56:23 -0700737 if (!pFormFillEnv->GetPageView(pPage, false))
tonikitoo401d4f22016-08-10 11:37:45 -0700738 return;
739
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700740 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler();
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700741 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get();
dsinclair38fd8442016-09-15 10:15:32 -0700742 CPDF_AAction aa(pPageDict->GetDictFor("AA"));
Lei Zhang1fed5a22017-06-01 11:52:22 -0700743 CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN
744 ? CPDF_AAction::OpenPage
745 : CPDF_AAction::ClosePage;
746 if (aa.ActionExist(type)) {
747 CPDF_Action action = aa.GetAction(type);
748 pActionHandler->DoAction_Page(action, type, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700750}