blob: f2ae6210982f18dccf1ff3403a6418e4d53c2f88 [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 }
Tom Sepez1629f602017-04-21 14:11:26 -0700134 options.m_bDrawAnnots = flags & FPDF_ANNOT;
thestigbefa4502016-05-26 20:15:19 -0700135
jaepark738766e2016-09-02 18:51:44 -0700136#ifdef PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700137 options.m_pOCContext =
138 pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View);
139 if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true))
140 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
jaepark738766e2016-09-02 18:51:44 -0700141#else // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700142 options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>(
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700143 pPage->m_pDocument.Get(), CPDF_OCContext::View);
Tom Sepez1629f602017-04-21 14:11:26 -0700144 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
145 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
thestigbefa4502016-05-26 20:15:19 -0700146#endif // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700147 }
caryclark8f875502016-12-06 13:49:34 -0800148#ifdef _SKIA_SUPPORT_PATHS_
149 pDevice->Flush();
Tom Sepezf0799fe2017-03-28 09:31:32 -0700150 holder->UnPreMultiply();
caryclark687fbde2016-11-22 12:44:25 -0800151#endif
thestigbefa4502016-05-26 20:15:19 -0700152}
153
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700154} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -0700155
Lei Zhangbdf72c32015-08-14 19:24:08 -0700156DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
157 FPDF_PAGE page,
158 double page_x,
159 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700160 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700161 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700162 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 if (pPage) {
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700164 CPDF_InterForm interform(pPage->m_pDocument.Get());
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500165 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400166 pPage,
167 CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500168 nullptr);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700169 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800172 return pFormField ? pFormField->GetFieldType() : -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 }
174
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800175#ifdef PDF_ENABLE_XFA
176 CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
177 if (!pXFAPage)
178 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179
dsinclairdf4bc592016-03-31 20:34:43 -0700180 CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800181 if (!pPageView)
182 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183
dsinclairdf4bc592016-03-31 20:34:43 -0700184 CXFA_FFDocView* pDocView = pPageView->GetDocView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800185 if (!pDocView)
186 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187
dsinclairdf4bc592016-03-31 20:34:43 -0700188 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800189 if (!pWidgetHandler)
190 return -1;
191
tsepezcc4d6d82016-05-16 13:21:03 -0700192 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700193 pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form,
194 XFA_WidgetStatus_Viewable));
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800195 if (!pWidgetIterator)
196 return -1;
197
dsinclairdf4bc592016-03-31 20:34:43 -0700198 CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800199 while (pXFAAnnot) {
Dan Sinclair1b08df12017-02-09 09:17:20 -0500200 CFX_RectF rcBBox = pXFAAnnot->GetBBox(0);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800201 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
202 rcBBox.top + rcBBox.height);
Lei Zhang1fed5a22017-06-01 11:52:22 -0700203 rcWidget.Inflate(1.0f, 1.0f);
Dan Sinclair05df0752017-03-14 14:43:42 -0400204 if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x),
205 static_cast<float>(page_y)))) {
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800206 return FPDF_FORMFIELD_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 }
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800208 pXFAAnnot = pWidgetIterator->MoveToNext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800210#endif // PDF_ENABLE_XFA
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800211 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212}
213
Lei Zhangbdf72c32015-08-14 19:24:08 -0700214DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
215 FPDF_PAGE page,
216 double page_x,
217 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700218 if (!hHandle)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700219 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700220 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
221 if (!pPage)
222 return -1;
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700223 CPDF_InterForm interform(pPage->m_pDocument.Get());
Lei Zhangbdf72c32015-08-14 19:24:08 -0700224 int z_order = -1;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500225 (void)interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400226 pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500227 &z_order);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700228 return z_order;
229}
230
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231DLLEXPORT FPDF_FORMHANDLE STDCALL
232FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
233 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800234#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800235 const int kRequiredVersion = 2;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800236#else // PDF_ENABLE_XFA
237 const int kRequiredVersion = 1;
238#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800239 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241
Tom Sepez540c4362015-11-24 13:33:57 -0800242 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
243 if (!pDocument)
244 return nullptr;
245
Tom Sepez40e9ff32015-11-30 12:39:54 -0800246#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700247 // If the CPDFXFA_Context has a FormFillEnvironment already then we've done
dsinclair8779fa82016-10-12 12:05:44 -0700248 // this and can just return the old Env. Otherwise, we'll end up setting a new
249 // environment into the XFADocument and, that could get weird.
dsinclair655fcca2016-10-11 13:53:37 -0700250 if (pDocument->GetFormFillEnv())
251 return pDocument->GetFormFillEnv();
dsinclaira939bfe2016-09-22 13:18:45 -0700252#endif
253
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700254 auto pFormFillEnv =
255 pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>(pDocument, formInfo);
dsinclaira939bfe2016-09-22 13:18:45 -0700256
257#ifdef PDF_ENABLE_XFA
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700258 pDocument->SetFormFillEnv(pFormFillEnv.get());
Tom Sepez40e9ff32015-11-30 12:39:54 -0800259#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700260
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700261 return pFormFillEnv.release(); // Caller takes ownership.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262}
263
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264DLLEXPORT void STDCALL
265FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700266 CPDFSDK_FormFillEnvironment* pFormFillEnv =
267 HandleToCPDFSDKEnvironment(hHandle);
Lei Zhang1fed5a22017-06-01 11:52:22 -0700268 if (!pFormFillEnv)
269 return;
dsinclaira939bfe2016-09-22 13:18:45 -0700270
Tom Sepez40e9ff32015-11-30 12:39:54 -0800271#ifdef PDF_ENABLE_XFA
dsinclair21161052016-10-05 15:46:15 -0700272 // Reset the focused annotations and remove the SDK document from the
273 // XFA document.
dsinclair7cbe68e2016-10-12 11:56:23 -0700274 pFormFillEnv->ClearAllFocusedAnnots();
dsinclairf3fbe832016-10-11 13:08:04 -0700275 // If the document was closed first, it's possible the XFA document
276 // is now a nullptr.
dsinclair521b7502016-11-02 13:02:28 -0700277 if (pFormFillEnv->GetXFAContext())
278 pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800279#endif // PDF_ENABLE_XFA
dsinclairf3fbe832016-10-11 13:08:04 -0700280 delete pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700281}
282
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
284 FPDF_PAGE page,
285 int modifier,
286 double page_x,
287 double page_y) {
288 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
289 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700290 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500291 return pPageView->OnMouseMove(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292}
293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle,
295 FPDF_PAGE page,
296 int modifier,
297 double page_x,
298 double page_y) {
299 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
300 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700301 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500302 return pPageView->OnLButtonDown(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700303}
304
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
306 FPDF_PAGE page,
307 int modifier,
308 double page_x,
309 double page_y) {
310 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
311 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700312 return false;
Lei Zhang1fed5a22017-06-01 11:52:22 -0700313 return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700314}
315
Tom Sepez51da0932015-11-25 16:05:49 -0800316#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
318 FPDF_PAGE page,
319 int modifier,
320 double page_x,
321 double page_y) {
322 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
323 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700324 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500325 return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700326}
327
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
329 FPDF_PAGE page,
330 int modifier,
331 double page_x,
332 double page_y) {
333 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
334 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700335 return false;
Lei Zhang1fed5a22017-06-01 11:52:22 -0700336 return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700337}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800338#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700339
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
341 FPDF_PAGE page,
342 int nKeyCode,
343 int modifier) {
344 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
345 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700346 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700348}
349
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
351 FPDF_PAGE page,
352 int nKeyCode,
353 int modifier) {
354 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
355 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700356 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358}
359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
361 FPDF_PAGE page,
362 int nChar,
363 int modifier) {
364 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
365 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700366 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700368}
369
Diana Gagedce2d722017-06-20 11:17:11 -0700370DLLEXPORT unsigned long STDCALL FORM_GetSelectedText(FPDF_FORMHANDLE hHandle,
371 FPDF_PAGE page,
372 void* buffer,
373 unsigned long buflen) {
374 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
375 if (!pPageView)
376 return 0;
377
378 CFX_WideString wide_str_form_text = pPageView->GetSelectedText();
379 CFX_ByteString encoded_form_text = wide_str_form_text.UTF16LE_Encode();
380 unsigned long form_text_len = encoded_form_text.GetLength();
381
382 if (buffer && buflen >= form_text_len)
383 memcpy(buffer, encoded_form_text.c_str(), form_text_len);
384
385 return form_text_len;
386}
387
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700389 CPDFSDK_FormFillEnvironment* pFormFillEnv =
390 HandleToCPDFSDKEnvironment(hHandle);
391 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700392 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700393 return pFormFillEnv->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700394}
395
Cary Clark399be5b2016-03-14 16:51:29 -0400396DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
397 FPDF_BITMAP bitmap,
398 FPDF_PAGE page,
399 int start_x,
400 int start_y,
401 int size_x,
402 int size_y,
403 int rotate,
404 int flags) {
405 FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
406 rotate, flags);
407}
408
409#ifdef _SKIA_SUPPORT_
410DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle,
411 FPDF_RECORDER recorder,
412 FPDF_PAGE page,
413 int start_x,
414 int start_y,
415 int size_x,
416 int size_y,
417 int rotate,
418 int flags) {
419 FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y,
420 rotate, flags);
421}
422#endif
423
Tom Sepez40e9ff32015-11-30 12:39:54 -0800424#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
426 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700427 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700429
dsinclair521b7502016-11-02 13:02:28 -0700430 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400431 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
432 pContext->GetDocType() != XFA_DocType::Static) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 return;
Dan Sinclaircdba7472017-03-23 09:17:10 -0400434 }
Bo Xufdc00a72014-10-28 23:03:33 -0700435
dsinclair221caf62016-04-04 12:08:40 -0700436 static_cast<CXFA_FFWidget*>(hWidget)->Undo();
Bo Xufdc00a72014-10-28 23:03:33 -0700437}
dsinclair521b7502016-11-02 13:02:28 -0700438
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
440 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700441 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700443
dsinclair521b7502016-11-02 13:02:28 -0700444 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400445 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
446 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700448
dsinclair221caf62016-04-04 12:08:40 -0700449 static_cast<CXFA_FFWidget*>(hWidget)->Redo();
Bo Xufdc00a72014-10-28 23:03:33 -0700450}
451
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document,
453 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700454 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700456
dsinclair521b7502016-11-02 13:02:28 -0700457 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400458 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
459 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700461
dsinclair221caf62016-04-04 12:08:40 -0700462 static_cast<CXFA_FFWidget*>(hWidget)->SelectAll();
Bo Xufdc00a72014-10-28 23:03:33 -0700463}
dsinclair521b7502016-11-02 13:02:28 -0700464
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
466 FPDF_WIDGET hWidget,
467 FPDF_WIDESTRING wsText,
468 FPDF_DWORD* size) {
dsinclair221caf62016-04-04 12:08:40 -0700469 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700471
dsinclair521b7502016-11-02 13:02:28 -0700472 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400473 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
474 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700476
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700478 static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700481 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
thestigbefa4502016-05-26 20:15:19 -0700482 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 *size = len;
484 return;
485 }
Bo Xufdc00a72014-10-28 23:03:33 -0700486
weili47ca6922016-03-31 15:08:27 -0700487 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400489 memcpy((void*)wsText,
490 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
491 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
493 }
494 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700495}
Tom Sepezab277682016-02-17 10:07:21 -0800496
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
498 FPDF_WIDGET hWidget,
499 FPDF_WIDESTRING wsText,
500 FPDF_DWORD* size) {
thestigbefa4502016-05-26 20:15:19 -0700501 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 return;
thestigbefa4502016-05-26 20:15:19 -0700503
dsinclair521b7502016-11-02 13:02:28 -0700504 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400505 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
506 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700508
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700510 static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700511
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700513 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
dsinclair221caf62016-04-04 12:08:40 -0700514 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 *size = len;
516 return;
517 }
Bo Xufdc00a72014-10-28 23:03:33 -0700518
weili47ca6922016-03-31 15:08:27 -0700519 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400521 memcpy((void*)wsText,
522 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
523 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
525 }
526 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700527}
Tom Sepezab277682016-02-17 10:07:21 -0800528
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
530 FPDF_WIDGET hWidget,
531 FPDF_WIDESTRING wsText,
532 FPDF_DWORD size) {
dsinclair221caf62016-04-04 12:08:40 -0700533 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700535
dsinclair521b7502016-11-02 13:02:28 -0700536 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400537 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
538 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700540
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
dsinclair221caf62016-04-04 12:08:40 -0700542 static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700543}
Tom Sepezab277682016-02-17 10:07:21 -0800544
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545DLLEXPORT void STDCALL
546FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
547 FPDF_WIDGET hWidget,
548 float x,
549 float y,
550 FPDF_BYTESTRING bsText) {
dsinclair221caf62016-04-04 12:08:40 -0700551 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700553
dsinclair521b7502016-11-02 13:02:28 -0700554 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400555 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
556 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 CFX_PointF ptPopup;
560 ptPopup.x = x;
561 ptPopup.y = y;
562 CFX_ByteStringC bs(bsText);
dsinclair221caf62016-04-04 12:08:40 -0700563 static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700564}
Tom Sepezab277682016-02-17 10:07:21 -0800565
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566DLLEXPORT void STDCALL
567FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
568 FPDF_WIDGET hWidget,
569 float x,
570 float y,
571 FPDF_STRINGHANDLE* stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800572 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700574
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700575 auto* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400576 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
577 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700579
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 CFX_PointF ptPopup;
581 ptPopup.x = x;
582 ptPopup.y = y;
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700583 auto sSuggestWords = pdfium::MakeUnique<std::vector<CFX_ByteString>>();
584 static_cast<CXFA_FFWidget*>(hWidget)->GetSuggestWords(ptPopup,
585 sSuggestWords.get());
586
587 // Caller takes ownership.
588 *stringHandle = ToFPDFStringHandle(sSuggestWords.release());
Bo Xufdc00a72014-10-28 23:03:33 -0700589}
Tom Sepezab277682016-02-17 10:07:21 -0800590
591DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
592 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
593 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700594}
Tom Sepezab277682016-02-17 10:07:21 -0800595
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596DLLEXPORT FPDF_BOOL STDCALL
Tom Sepezab277682016-02-17 10:07:21 -0800597FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 int index,
599 FPDF_BYTESTRING bsText,
600 FPDF_DWORD* size) {
Tom Sepezab277682016-02-17 10:07:21 -0800601 if (!sHandle || !size)
tsepez4cf55152016-11-02 14:37:54 -0700602 return false;
Tom Sepezab277682016-02-17 10:07:21 -0800603
604 int count = FPDF_StringHandleCounts(sHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 if (index < 0 || index >= count)
tsepez4cf55152016-11-02 14:37:54 -0700606 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700607
Tom Sepezab277682016-02-17 10:07:21 -0800608 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
weili47ca6922016-03-31 15:08:27 -0700609 uint32_t len = (*sSuggestWords)[index].GetLength();
Tom Sepezab277682016-02-17 10:07:21 -0800610 if (!bsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 *size = len;
tsepez4cf55152016-11-02 14:37:54 -0700612 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 }
614
weili47ca6922016-03-31 15:08:27 -0700615 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 if (real_size > 0)
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400617 memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 *size = real_size;
tsepez4cf55152016-11-02 14:37:54 -0700619 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700620}
Tom Sepezab277682016-02-17 10:07:21 -0800621
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622DLLEXPORT void STDCALL
623FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800624 delete FromFPDFStringHandle(stringHandle);
Bo Xufdc00a72014-10-28 23:03:33 -0700625}
626
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627DLLEXPORT FPDF_BOOL STDCALL
628FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
629 FPDF_BYTESTRING bsText,
630 FPDF_DWORD size) {
Tom Sepezab277682016-02-17 10:07:21 -0800631 if (!stringHandle || !bsText || size == 0)
tsepez4cf55152016-11-02 14:37:54 -0700632 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700633
Tom Sepezab277682016-02-17 10:07:21 -0800634 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
tsepez4cf55152016-11-02 14:37:54 -0700635 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700636}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800637#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700638
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
640 int fieldType,
641 unsigned long color) {
642 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
643 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644}
645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
647 unsigned char alpha) {
648 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
649 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650}
651
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
653 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
654 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700655}
656
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
658 FPDF_FORMHANDLE hHandle) {
659 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
tsepez4cf55152016-11-02 14:37:54 -0700660 pPageView->SetValid(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661}
662
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
664 FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700665 CPDFSDK_FormFillEnvironment* pFormFillEnv =
666 HandleToCPDFSDKEnvironment(hHandle);
667 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700669
Tom Sepez540c4362015-11-24 13:33:57 -0800670 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
671 if (!pPage)
672 return;
673
dsinclair7cbe68e2016-10-12 11:56:23 -0700674 CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 if (pPageView) {
tsepez4cf55152016-11-02 14:37:54 -0700676 pPageView->SetValid(false);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800677 // RemovePageView() takes care of the delete for us.
dsinclair7cbe68e2016-10-12 11:56:23 -0700678 pFormFillEnv->RemovePageView(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 }
680}
681
682DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700683 CPDFSDK_FormFillEnvironment* pFormFillEnv =
684 HandleToCPDFSDKEnvironment(hHandle);
685 if (pFormFillEnv && pFormFillEnv->IsJSInitiated())
dsinclair7cbe68e2016-10-12 11:56:23 -0700686 pFormFillEnv->ProcJavascriptFun();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687}
688
689DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700690 CPDFSDK_FormFillEnvironment* pFormFillEnv =
691 HandleToCPDFSDKEnvironment(hHandle);
692 if (pFormFillEnv && pFormFillEnv->IsJSInitiated())
dsinclair7cbe68e2016-10-12 11:56:23 -0700693 pFormFillEnv->ProcOpenAction();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694}
695
696DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
697 int aaType) {
dsinclairf3fbe832016-10-11 13:08:04 -0700698 CPDFSDK_FormFillEnvironment* pFormFillEnv =
699 HandleToCPDFSDKEnvironment(hHandle);
700 if (!pFormFillEnv)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 return;
702
dsinclair7cbe68e2016-10-12 11:56:23 -0700703 CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument();
Lei Zhang1fed5a22017-06-01 11:52:22 -0700704 CPDF_Dictionary* pDict = pDoc->GetRoot();
705 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700707
Lei Zhang1fed5a22017-06-01 11:52:22 -0700708 CPDF_AAction aa(pDict->GetDictFor("AA"));
709 auto type = static_cast<CPDF_AAction::AActionType>(aaType);
710 if (aa.ActionExist(type)) {
711 CPDF_Action action = aa.GetAction(type);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 CPDFSDK_ActionHandler* pActionHandler =
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700713 HandleToCPDFSDKEnvironment(hHandle)->GetActionHandler();
Lei Zhang1fed5a22017-06-01 11:52:22 -0700714 pActionHandler->DoAction_Document(action, type, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 }
716}
717
718DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
719 FPDF_FORMHANDLE hHandle,
720 int aaType) {
dsinclairf3fbe832016-10-11 13:08:04 -0700721 CPDFSDK_FormFillEnvironment* pFormFillEnv =
722 HandleToCPDFSDKEnvironment(hHandle);
723 if (!pFormFillEnv)
tonikitoo401d4f22016-08-10 11:37:45 -0700724 return;
725
Tom Sepez540c4362015-11-24 13:33:57 -0800726 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
727 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700728 if (!pPDFPage)
729 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700730
dsinclair7cbe68e2016-10-12 11:56:23 -0700731 if (!pFormFillEnv->GetPageView(pPage, false))
tonikitoo401d4f22016-08-10 11:37:45 -0700732 return;
733
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700734 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler();
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700735 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get();
dsinclair38fd8442016-09-15 10:15:32 -0700736 CPDF_AAction aa(pPageDict->GetDictFor("AA"));
Lei Zhang1fed5a22017-06-01 11:52:22 -0700737 CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN
738 ? CPDF_AAction::OpenPage
739 : CPDF_AAction::ClosePage;
740 if (aa.ActionExist(type)) {
741 CPDF_Action action = aa.GetAction(type);
742 pActionHandler->DoAction_Page(action, type, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}