blob: fb12967bde047496b211a28d1199b430b8e9ec01 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_formfill.h"
8
Lei Zhangaa8bf7e2015-12-24 19:13:32 -08009#include <memory>
Tom Sepezab277682016-02-17 10:07:21 -080010#include <vector>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080011
dsinclair41872fa2016-10-04 11:29:35 -070012#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070013#include "core/fpdfapi/parser/cpdf_document.h"
dsinclair69d9c682016-10-04 12:18:35 -070014#include "core/fpdfapi/render/cpdf_renderoptions.h"
dsinclair1727aee2016-09-29 13:12:56 -070015#include "core/fpdfdoc/cpdf_formcontrol.h"
16#include "core/fpdfdoc/cpdf_formfield.h"
17#include "core/fpdfdoc/cpdf_interform.h"
18#include "core/fpdfdoc/cpdf_occontext.h"
Dan Sinclaira5085d42017-05-11 16:26:50 -040019#include "core/fxge/cfx_defaultrenderdevice.h"
dsinclair735606d2016-10-05 15:47:02 -070020#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070021#include "fpdfsdk/cpdfsdk_interform.h"
22#include "fpdfsdk/cpdfsdk_pageview.h"
23#include "fpdfsdk/fsdk_actionhandler.h"
24#include "fpdfsdk/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080025#include "public/fpdfview.h"
tsepez36eb4bd2016-10-03 15:24:27 -070026#include "third_party/base/ptr_util.h"
Tom Sepezab277682016-02-17 10:07:21 -080027#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Tom Sepez40e9ff32015-11-30 12:39:54 -080029#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070030#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair4d29e782016-10-04 14:02:47 -070031#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040032#include "xfa/fxfa/cxfa_ffdocview.h"
33#include "xfa/fxfa/cxfa_ffpageview.h"
34#include "xfa/fxfa/cxfa_ffwidget.h"
Dan Sinclaircdba7472017-03-23 09:17:10 -040035
36static_assert(static_cast<int>(XFA_DocType::PDF) == DOCTYPE_PDF,
37 "PDF doctype must match");
38static_assert(static_cast<int>(XFA_DocType::Dynamic) == DOCTYPE_DYNAMIC_XFA,
39 "Dynamic XFA doctype must match");
40static_assert(static_cast<int>(XFA_DocType::Static) == DOCTYPE_STATIC_XFA,
41 "Static XFA doctype must match");
Tom Sepez40e9ff32015-11-30 12:39:54 -080042#endif // PDF_ENABLE_XFA
43
Tom Sepezdcbc02f2015-07-17 09:16:17 -070044namespace {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045
dsinclair735606d2016-10-05 15:47:02 -070046CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment(
47 FPDF_FORMHANDLE handle) {
48 return static_cast<CPDFSDK_FormFillEnvironment*>(handle);
dsinclair79db6092016-09-14 07:27:21 -070049}
50
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -070052 CPDFSDK_FormFillEnvironment* pFormFillEnv =
53 HandleToCPDFSDKEnvironment(hHandle);
dsinclair7cbe68e2016-10-12 11:56:23 -070054 return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070055}
Bo Xufdc00a72014-10-28 23:03:33 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
58 FPDF_PAGE page) {
Tom Sepez540c4362015-11-24 13:33:57 -080059 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
60 if (!pPage)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 return nullptr;
Tom Sepez0b133982015-07-28 11:23:22 -070062
dsinclairf3fbe832016-10-11 13:08:04 -070063 CPDFSDK_FormFillEnvironment* pFormFillEnv =
64 HandleToCPDFSDKEnvironment(hHandle);
dsinclair7cbe68e2016-10-12 11:56:23 -070065 return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070066}
Bo Xufdc00a72014-10-28 23:03:33 -070067
Tom Sepezab277682016-02-17 10:07:21 -080068#ifdef PDF_ENABLE_XFA
69std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) {
Nicolas Pena46abb662017-05-17 17:23:22 -040070 return static_cast<std::vector<CFX_ByteString>*>(handle);
Tom Sepezab277682016-02-17 10:07:21 -080071}
72
73FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) {
Nicolas Pena46abb662017-05-17 17:23:22 -040074 return static_cast<FPDF_STRINGHANDLE>(strings);
Tom Sepezab277682016-02-17 10:07:21 -080075}
76#endif // PDF_ENABLE_XFA
77
thestigbefa4502016-05-26 20:15:19 -070078void FFLCommon(FPDF_FORMHANDLE hHandle,
79 FPDF_BITMAP bitmap,
80 FPDF_RECORDER recorder,
81 FPDF_PAGE page,
82 int start_x,
83 int start_y,
84 int size_x,
85 int size_y,
86 int rotate,
87 int flags) {
88 if (!hHandle)
89 return;
90
91 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
92 if (!pPage)
93 return;
94
jaepark738766e2016-09-02 18:51:44 -070095#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070096 CPDFXFA_Context* pContext = pPage->GetContext();
97 if (!pContext)
thestigbefa4502016-05-26 20:15:19 -070098 return;
dsinclair521b7502016-11-02 13:02:28 -070099 CPDF_Document* pPDFDoc = pContext->GetPDFDoc();
thestigbefa4502016-05-26 20:15:19 -0700100 if (!pPDFDoc)
101 return;
dsinclairf3fbe832016-10-11 13:08:04 -0700102 CPDFSDK_FormFillEnvironment* pFormFillEnv =
103 HandleToCPDFSDKEnvironment(hHandle);
104 if (!pFormFillEnv)
thestigbefa4502016-05-26 20:15:19 -0700105 return;
106#endif // PDF_ENABLE_XFA
107
Dan Sinclair1b08df12017-02-09 09:17:20 -0500108 CFX_Matrix matrix =
109 pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate);
thestigbefa4502016-05-26 20:15:19 -0700110 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y);
111
Dan Sinclaira5085d42017-05-11 16:26:50 -0400112 auto pDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>();
thestigbefa4502016-05-26 20:15:19 -0700113#ifdef _SKIA_SUPPORT_
114 pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
115#endif
Tom Sepezf0799fe2017-03-28 09:31:32 -0700116 CFX_RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
117 pDevice->Attach(holder, false, nullptr, false);
Tom Sepez1629f602017-04-21 14:11:26 -0700118 {
119 CFX_RenderDevice::StateRestorer restorer(pDevice.get());
120 pDevice->SetClip_Rect(clip);
thestigbefa4502016-05-26 20:15:19 -0700121
Tom Sepez1629f602017-04-21 14:11:26 -0700122 CPDF_RenderOptions options;
123 if (flags & FPDF_LCD_TEXT)
124 options.m_Flags |= RENDER_CLEARTYPE;
125 else
126 options.m_Flags &= ~RENDER_CLEARTYPE;
thestigbefa4502016-05-26 20:15:19 -0700127
Tom Sepez1629f602017-04-21 14:11:26 -0700128 // Grayscale output
129 if (flags & FPDF_GRAYSCALE) {
130 options.m_ColorMode = RENDER_COLOR_GRAY;
131 options.m_ForeColor = 0;
132 options.m_BackColor = 0xffffff;
133 }
134 options.m_AddFlags = flags >> 8;
135 options.m_bDrawAnnots = flags & FPDF_ANNOT;
thestigbefa4502016-05-26 20:15:19 -0700136
jaepark738766e2016-09-02 18:51:44 -0700137#ifdef PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700138 options.m_pOCContext =
139 pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View);
140 if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true))
141 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
jaepark738766e2016-09-02 18:51:44 -0700142#else // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700143 options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>(
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700144 pPage->m_pDocument.Get(), CPDF_OCContext::View);
Tom Sepez1629f602017-04-21 14:11:26 -0700145 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
146 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
thestigbefa4502016-05-26 20:15:19 -0700147#endif // PDF_ENABLE_XFA
Tom Sepez1629f602017-04-21 14:11:26 -0700148 }
caryclark8f875502016-12-06 13:49:34 -0800149#ifdef _SKIA_SUPPORT_PATHS_
150 pDevice->Flush();
Tom Sepezf0799fe2017-03-28 09:31:32 -0700151 holder->UnPreMultiply();
caryclark687fbde2016-11-22 12:44:25 -0800152#endif
thestigbefa4502016-05-26 20:15:19 -0700153}
154
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700155} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -0700156
Lei Zhangbdf72c32015-08-14 19:24:08 -0700157DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
158 FPDF_PAGE page,
159 double page_x,
160 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700161 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700162 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700163 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 if (pPage) {
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700165 CPDF_InterForm interform(pPage->m_pDocument.Get());
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500166 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400167 pPage,
168 CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500169 nullptr);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700170 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800173 return pFormField ? pFormField->GetFieldType() : -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 }
175
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800176#ifdef PDF_ENABLE_XFA
177 CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
178 if (!pXFAPage)
179 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180
dsinclairdf4bc592016-03-31 20:34:43 -0700181 CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800182 if (!pPageView)
183 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184
dsinclairdf4bc592016-03-31 20:34:43 -0700185 CXFA_FFDocView* pDocView = pPageView->GetDocView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800186 if (!pDocView)
187 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188
dsinclairdf4bc592016-03-31 20:34:43 -0700189 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800190 if (!pWidgetHandler)
191 return -1;
192
tsepezcc4d6d82016-05-16 13:21:03 -0700193 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700194 pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form,
195 XFA_WidgetStatus_Viewable));
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800196 if (!pWidgetIterator)
197 return -1;
198
dsinclairdf4bc592016-03-31 20:34:43 -0700199 CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800200 while (pXFAAnnot) {
Dan Sinclair1b08df12017-02-09 09:17:20 -0500201 CFX_RectF rcBBox = pXFAAnnot->GetBBox(0);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800202 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
203 rcBBox.top + rcBBox.height);
204 rcWidget.left -= 1.0f;
205 rcWidget.right += 1.0f;
206 rcWidget.bottom -= 1.0f;
207 rcWidget.top += 1.0f;
208
Dan Sinclair05df0752017-03-14 14:43:42 -0400209 if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x),
210 static_cast<float>(page_y)))) {
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800211 return FPDF_FORMFIELD_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 }
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800213 pXFAAnnot = pWidgetIterator->MoveToNext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800215#endif // PDF_ENABLE_XFA
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800216 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217}
218
Lei Zhangbdf72c32015-08-14 19:24:08 -0700219DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
220 FPDF_PAGE page,
221 double page_x,
222 double page_y) {
223 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y);
224}
225
226DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
227 FPDF_PAGE page,
228 double page_x,
229 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700230 if (!hHandle)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700231 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700232 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
233 if (!pPage)
234 return -1;
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700235 CPDF_InterForm interform(pPage->m_pDocument.Get());
Lei Zhangbdf72c32015-08-14 19:24:08 -0700236 int z_order = -1;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500237 (void)interform.GetControlAtPoint(
Dan Sinclair05df0752017-03-14 14:43:42 -0400238 pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500239 &z_order);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700240 return z_order;
241}
242
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243DLLEXPORT FPDF_FORMHANDLE STDCALL
244FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
245 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800246#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800247 const int kRequiredVersion = 2;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800248#else // PDF_ENABLE_XFA
249 const int kRequiredVersion = 1;
250#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800251 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253
Tom Sepez540c4362015-11-24 13:33:57 -0800254 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
255 if (!pDocument)
256 return nullptr;
257
Tom Sepez40e9ff32015-11-30 12:39:54 -0800258#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700259 // If the CPDFXFA_Context has a FormFillEnvironment already then we've done
dsinclair8779fa82016-10-12 12:05:44 -0700260 // this and can just return the old Env. Otherwise, we'll end up setting a new
261 // environment into the XFADocument and, that could get weird.
dsinclair655fcca2016-10-11 13:53:37 -0700262 if (pDocument->GetFormFillEnv())
263 return pDocument->GetFormFillEnv();
dsinclaira939bfe2016-09-22 13:18:45 -0700264#endif
265
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700266 auto pFormFillEnv =
267 pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>(pDocument, formInfo);
dsinclaira939bfe2016-09-22 13:18:45 -0700268
269#ifdef PDF_ENABLE_XFA
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700270 pDocument->SetFormFillEnv(pFormFillEnv.get());
Tom Sepez40e9ff32015-11-30 12:39:54 -0800271#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700272
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700273 return pFormFillEnv.release(); // Caller takes ownership.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274}
275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276DLLEXPORT void STDCALL
277FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
278 if (!hHandle)
279 return;
dsinclaira939bfe2016-09-22 13:18:45 -0700280
dsinclairf3fbe832016-10-11 13:08:04 -0700281 CPDFSDK_FormFillEnvironment* pFormFillEnv =
282 HandleToCPDFSDKEnvironment(hHandle);
dsinclaira939bfe2016-09-22 13:18:45 -0700283
Tom Sepez40e9ff32015-11-30 12:39:54 -0800284#ifdef PDF_ENABLE_XFA
dsinclair21161052016-10-05 15:46:15 -0700285 // Reset the focused annotations and remove the SDK document from the
286 // XFA document.
dsinclair7cbe68e2016-10-12 11:56:23 -0700287 pFormFillEnv->ClearAllFocusedAnnots();
dsinclairf3fbe832016-10-11 13:08:04 -0700288 // If the document was closed first, it's possible the XFA document
289 // is now a nullptr.
dsinclair521b7502016-11-02 13:02:28 -0700290 if (pFormFillEnv->GetXFAContext())
291 pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800292#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700293
dsinclairf3fbe832016-10-11 13:08:04 -0700294 delete pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295}
296
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
298 FPDF_PAGE page,
299 int modifier,
300 double page_x,
301 double page_y) {
302 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
303 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700304 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500305 return pPageView->OnMouseMove(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700306}
307
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700308DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle,
309 FPDF_PAGE page,
310 int modifier,
311 double page_x,
312 double page_y) {
313 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
314 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700315 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500316 return pPageView->OnLButtonDown(CFX_PointF(page_x, page_y), modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317}
318
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
320 FPDF_PAGE page,
321 int modifier,
322 double page_x,
323 double page_y) {
324 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
325 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700326 return false;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700327
Dan Sinclair05df0752017-03-14 14:43:42 -0400328 CFX_PointF pt((float)page_x, (float)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 return pPageView->OnLButtonUp(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700330}
331
Tom Sepez51da0932015-11-25 16:05:49 -0800332#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
334 FPDF_PAGE page,
335 int modifier,
336 double page_x,
337 double page_y) {
338 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
339 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700340 return false;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500341 return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700342}
343
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
345 FPDF_PAGE page,
346 int modifier,
347 double page_x,
348 double page_y) {
349 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
350 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700351 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700352
Dan Sinclair05df0752017-03-14 14:43:42 -0400353 CFX_PointF pt((float)page_x, (float)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 return pPageView->OnRButtonUp(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700355}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800356#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700357
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
359 FPDF_PAGE page,
360 int nKeyCode,
361 int modifier) {
362 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
363 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700364 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367}
368
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
370 FPDF_PAGE page,
371 int nKeyCode,
372 int modifier) {
373 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
374 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700375 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700376
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700378}
379
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
381 FPDF_PAGE page,
382 int nChar,
383 int modifier) {
384 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
385 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -0700386 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700387
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389}
390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
dsinclairf3fbe832016-10-11 13:08:04 -0700392 CPDFSDK_FormFillEnvironment* pFormFillEnv =
393 HandleToCPDFSDKEnvironment(hHandle);
394 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700395 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700396 return pFormFillEnv->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700397}
398
Cary Clark399be5b2016-03-14 16:51:29 -0400399DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
400 FPDF_BITMAP bitmap,
401 FPDF_PAGE page,
402 int start_x,
403 int start_y,
404 int size_x,
405 int size_y,
406 int rotate,
407 int flags) {
408 FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
409 rotate, flags);
410}
411
412#ifdef _SKIA_SUPPORT_
413DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle,
414 FPDF_RECORDER recorder,
415 FPDF_PAGE page,
416 int start_x,
417 int start_y,
418 int size_x,
419 int size_y,
420 int rotate,
421 int flags) {
422 FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y,
423 rotate, flags);
424}
425#endif
426
Tom Sepez40e9ff32015-11-30 12:39:54 -0800427#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
429 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700430 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700432
dsinclair521b7502016-11-02 13:02:28 -0700433 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400434 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
435 pContext->GetDocType() != XFA_DocType::Static) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 return;
Dan Sinclaircdba7472017-03-23 09:17:10 -0400437 }
Bo Xufdc00a72014-10-28 23:03:33 -0700438
dsinclair221caf62016-04-04 12:08:40 -0700439 static_cast<CXFA_FFWidget*>(hWidget)->Undo();
Bo Xufdc00a72014-10-28 23:03:33 -0700440}
dsinclair521b7502016-11-02 13:02:28 -0700441
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
443 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700444 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700446
dsinclair521b7502016-11-02 13:02:28 -0700447 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400448 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
449 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700451
dsinclair221caf62016-04-04 12:08:40 -0700452 static_cast<CXFA_FFWidget*>(hWidget)->Redo();
Bo Xufdc00a72014-10-28 23:03:33 -0700453}
454
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document,
456 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700457 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700459
dsinclair521b7502016-11-02 13:02:28 -0700460 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400461 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
462 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700464
dsinclair221caf62016-04-04 12:08:40 -0700465 static_cast<CXFA_FFWidget*>(hWidget)->SelectAll();
Bo Xufdc00a72014-10-28 23:03:33 -0700466}
dsinclair521b7502016-11-02 13:02:28 -0700467
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
469 FPDF_WIDGET hWidget,
470 FPDF_WIDESTRING wsText,
471 FPDF_DWORD* size) {
dsinclair221caf62016-04-04 12:08:40 -0700472 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700474
dsinclair521b7502016-11-02 13:02:28 -0700475 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400476 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
477 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700481 static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700482
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700484 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
thestigbefa4502016-05-26 20:15:19 -0700485 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 *size = len;
487 return;
488 }
Bo Xufdc00a72014-10-28 23:03:33 -0700489
weili47ca6922016-03-31 15:08:27 -0700490 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400492 memcpy((void*)wsText,
493 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
494 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
496 }
497 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700498}
Tom Sepezab277682016-02-17 10:07:21 -0800499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
501 FPDF_WIDGET hWidget,
502 FPDF_WIDESTRING wsText,
503 FPDF_DWORD* size) {
thestigbefa4502016-05-26 20:15:19 -0700504 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 return;
thestigbefa4502016-05-26 20:15:19 -0700506
dsinclair521b7502016-11-02 13:02:28 -0700507 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400508 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
509 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700511
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700513 static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700514
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700516 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
dsinclair221caf62016-04-04 12:08:40 -0700517 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 *size = len;
519 return;
520 }
Bo Xufdc00a72014-10-28 23:03:33 -0700521
weili47ca6922016-03-31 15:08:27 -0700522 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 if (real_size > 0) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400524 memcpy((void*)wsText,
525 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
526 real_size * sizeof(unsigned short));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
528 }
529 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700530}
Tom Sepezab277682016-02-17 10:07:21 -0800531
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
533 FPDF_WIDGET hWidget,
534 FPDF_WIDESTRING wsText,
535 FPDF_DWORD size) {
dsinclair221caf62016-04-04 12:08:40 -0700536 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700538
dsinclair521b7502016-11-02 13:02:28 -0700539 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400540 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
541 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700543
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
dsinclair221caf62016-04-04 12:08:40 -0700545 static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700546}
Tom Sepezab277682016-02-17 10:07:21 -0800547
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548DLLEXPORT void STDCALL
549FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
550 FPDF_WIDGET hWidget,
551 float x,
552 float y,
553 FPDF_BYTESTRING bsText) {
dsinclair221caf62016-04-04 12:08:40 -0700554 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700556
dsinclair521b7502016-11-02 13:02:28 -0700557 CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400558 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
559 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700561
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 CFX_PointF ptPopup;
563 ptPopup.x = x;
564 ptPopup.y = y;
565 CFX_ByteStringC bs(bsText);
dsinclair221caf62016-04-04 12:08:40 -0700566 static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700567}
Tom Sepezab277682016-02-17 10:07:21 -0800568
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569DLLEXPORT void STDCALL
570FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
571 FPDF_WIDGET hWidget,
572 float x,
573 float y,
574 FPDF_STRINGHANDLE* stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800575 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700577
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700578 auto* pContext = static_cast<CPDFXFA_Context*>(document);
Dan Sinclaircdba7472017-03-23 09:17:10 -0400579 if (pContext->GetDocType() != XFA_DocType::Dynamic &&
580 pContext->GetDocType() != XFA_DocType::Static)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700582
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 CFX_PointF ptPopup;
584 ptPopup.x = x;
585 ptPopup.y = y;
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700586 auto sSuggestWords = pdfium::MakeUnique<std::vector<CFX_ByteString>>();
587 static_cast<CXFA_FFWidget*>(hWidget)->GetSuggestWords(ptPopup,
588 sSuggestWords.get());
589
590 // Caller takes ownership.
591 *stringHandle = ToFPDFStringHandle(sSuggestWords.release());
Bo Xufdc00a72014-10-28 23:03:33 -0700592}
Tom Sepezab277682016-02-17 10:07:21 -0800593
594DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
595 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
596 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700597}
Tom Sepezab277682016-02-17 10:07:21 -0800598
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599DLLEXPORT FPDF_BOOL STDCALL
Tom Sepezab277682016-02-17 10:07:21 -0800600FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 int index,
602 FPDF_BYTESTRING bsText,
603 FPDF_DWORD* size) {
Tom Sepezab277682016-02-17 10:07:21 -0800604 if (!sHandle || !size)
tsepez4cf55152016-11-02 14:37:54 -0700605 return false;
Tom Sepezab277682016-02-17 10:07:21 -0800606
607 int count = FPDF_StringHandleCounts(sHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 if (index < 0 || index >= count)
tsepez4cf55152016-11-02 14:37:54 -0700609 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700610
Tom Sepezab277682016-02-17 10:07:21 -0800611 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
weili47ca6922016-03-31 15:08:27 -0700612 uint32_t len = (*sSuggestWords)[index].GetLength();
Tom Sepezab277682016-02-17 10:07:21 -0800613 if (!bsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 *size = len;
tsepez4cf55152016-11-02 14:37:54 -0700615 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 }
617
weili47ca6922016-03-31 15:08:27 -0700618 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 if (real_size > 0)
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400620 memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621 *size = real_size;
tsepez4cf55152016-11-02 14:37:54 -0700622 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700623}
Tom Sepezab277682016-02-17 10:07:21 -0800624
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625DLLEXPORT void STDCALL
626FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800627 delete FromFPDFStringHandle(stringHandle);
Bo Xufdc00a72014-10-28 23:03:33 -0700628}
629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630DLLEXPORT FPDF_BOOL STDCALL
631FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
632 FPDF_BYTESTRING bsText,
633 FPDF_DWORD size) {
Tom Sepezab277682016-02-17 10:07:21 -0800634 if (!stringHandle || !bsText || size == 0)
tsepez4cf55152016-11-02 14:37:54 -0700635 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700636
Tom Sepezab277682016-02-17 10:07:21 -0800637 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
tsepez4cf55152016-11-02 14:37:54 -0700638 return true;
Bo Xufdc00a72014-10-28 23:03:33 -0700639}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800640#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700641
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
643 int fieldType,
644 unsigned long color) {
645 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
646 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700647}
648
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
650 unsigned char alpha) {
651 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
652 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653}
654
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
656 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
657 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658}
659
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
661 FPDF_FORMHANDLE hHandle) {
662 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
tsepez4cf55152016-11-02 14:37:54 -0700663 pPageView->SetValid(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
667 FPDF_FORMHANDLE hHandle) {
Tom Sepez540c4362015-11-24 13:33:57 -0800668 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700670
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();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 CPDF_Dictionary* pDic = pDoc->GetRoot();
711 if (!pDic)
712 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700713
dsinclair38fd8442016-09-15 10:15:32 -0700714 CPDF_AAction aa(pDic->GetDictFor("AA"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) {
716 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
717 CPDFSDK_ActionHandler* pActionHandler =
dsinclair79db6092016-09-14 07:27:21 -0700718 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType,
dsinclairf3fbe832016-10-11 13:08:04 -0700720 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) {
Tom Sepez540c4362015-11-24 13:33:57 -0800727 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700729
dsinclairf3fbe832016-10-11 13:08:04 -0700730 CPDFSDK_FormFillEnvironment* pFormFillEnv =
731 HandleToCPDFSDKEnvironment(hHandle);
732 if (!pFormFillEnv)
tonikitoo401d4f22016-08-10 11:37:45 -0700733 return;
734
Tom Sepez540c4362015-11-24 13:33:57 -0800735 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
736 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700737 if (!pPDFPage)
738 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700739
dsinclair7cbe68e2016-10-12 11:56:23 -0700740 if (!pFormFillEnv->GetPageView(pPage, false))
tonikitoo401d4f22016-08-10 11:37:45 -0700741 return;
742
dsinclairf3fbe832016-10-11 13:08:04 -0700743 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700744 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get();
dsinclair38fd8442016-09-15 10:15:32 -0700745 CPDF_AAction aa(pPageDict->GetDictFor("AA"));
tonikitoo401d4f22016-08-10 11:37:45 -0700746 if (FPDFPAGE_AACTION_OPEN == aaType) {
747 if (aa.ActionExist(CPDF_AAction::OpenPage)) {
748 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
dsinclairf3fbe832016-10-11 13:08:04 -0700749 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage,
750 pFormFillEnv);
tonikitoo401d4f22016-08-10 11:37:45 -0700751 }
752 } else {
753 if (aa.ActionExist(CPDF_AAction::ClosePage)) {
754 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
dsinclairf3fbe832016-10-11 13:08:04 -0700755 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage,
756 pFormFillEnv);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700757 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759}