blob: 9baabc4de4632587a138958cfbc8cb6decfcdfc1 [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
Dan Sinclair455a4192016-03-16 09:48:56 -040012#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040013#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
14#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h"
dsinclaircac704d2016-07-28 12:59:09 -070015#include "core/fpdfdoc/include/cpdf_formcontrol.h"
16#include "core/fpdfdoc/include/cpdf_formfield.h"
17#include "core/fpdfdoc/include/cpdf_interform.h"
dsinclairf34518b2016-09-13 12:03:48 -070018#include "core/fpdfdoc/include/cpdf_occontext.h"
npm9ada2d82016-08-10 07:51:38 -070019#include "core/fxge/include/cfx_fxgedevice.h"
dsinclairf34518b2016-09-13 12:03:48 -070020#include "fpdfsdk/include/cpdfsdk_document.h"
dsinclair79db6092016-09-14 07:27:21 -070021#include "fpdfsdk/include/cpdfsdk_environment.h"
jaepark611adb82016-08-17 11:34:36 -070022#include "fpdfsdk/include/cpdfsdk_interform.h"
dsinclairf34518b2016-09-13 12:03:48 -070023#include "fpdfsdk/include/cpdfsdk_pageview.h"
24#include "fpdfsdk/include/fsdk_actionhandler.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080025#include "fpdfsdk/include/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080026#include "public/fpdfview.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
dsinclair89bdd082016-04-06 10:47:54 -070030#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h"
31#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
32#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
dsinclair7222ea62016-04-06 14:33:07 -070033#include "xfa/fxfa/include/xfa_ffdocview.h"
34#include "xfa/fxfa/include/xfa_ffpageview.h"
35#include "xfa/fxfa/include/xfa_ffwidget.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080036#endif // PDF_ENABLE_XFA
37
Tom Sepezdcbc02f2015-07-17 09:16:17 -070038namespace {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
dsinclair79db6092016-09-14 07:27:21 -070040CPDFSDK_Environment* HandleToCPDFSDKEnvironment(FPDF_FORMHANDLE handle) {
41 return static_cast<CPDFSDK_Environment*>(handle);
42}
43
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -080045 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070047}
Bo Xufdc00a72014-10-28 23:03:33 -070048
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
50 FPDF_PAGE page) {
Tom Sepez540c4362015-11-24 13:33:57 -080051 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
52 if (!pPage)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 return nullptr;
Tom Sepez0b133982015-07-28 11:23:22 -070054
Tom Sepezfe351db2016-01-29 16:26:27 -080055 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
dsinclair461eeaf2016-07-27 07:40:05 -070056 return pSDKDoc ? pSDKDoc->GetPageView(pPage, true) : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070057}
Bo Xufdc00a72014-10-28 23:03:33 -070058
Tom Sepezab277682016-02-17 10:07:21 -080059#ifdef PDF_ENABLE_XFA
60std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) {
61 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle);
62}
63
64FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) {
65 return reinterpret_cast<FPDF_STRINGHANDLE>(strings);
66}
67#endif // PDF_ENABLE_XFA
68
thestigbefa4502016-05-26 20:15:19 -070069void FFLCommon(FPDF_FORMHANDLE hHandle,
70 FPDF_BITMAP bitmap,
71 FPDF_RECORDER recorder,
72 FPDF_PAGE page,
73 int start_x,
74 int start_y,
75 int size_x,
76 int size_y,
77 int rotate,
78 int flags) {
79 if (!hHandle)
80 return;
81
82 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
83 if (!pPage)
84 return;
85
jaepark738766e2016-09-02 18:51:44 -070086#ifdef PDF_ENABLE_XFA
thestigbefa4502016-05-26 20:15:19 -070087 CPDFXFA_Document* pDocument = pPage->GetDocument();
88 if (!pDocument)
89 return;
90 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc();
91 if (!pPDFDoc)
92 return;
dsinclair79db6092016-09-14 07:27:21 -070093 CPDFSDK_Environment* pEnv = HandleToCPDFSDKEnvironment(hHandle);
thestigbefa4502016-05-26 20:15:19 -070094 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument();
95 if (!pFXDoc)
96 return;
97#endif // PDF_ENABLE_XFA
98
99 CFX_Matrix matrix;
100 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
101
102 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y);
103
104 std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice);
105#ifdef _SKIA_SUPPORT_
106 pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
107#endif
108 pDevice->Attach(CFXBitmapFromFPDFBitmap(bitmap), false, nullptr, false);
109 pDevice->SaveState();
110 pDevice->SetClip_Rect(clip);
111
thestigbefa4502016-05-26 20:15:19 -0700112 CPDF_RenderOptions options;
113 if (flags & FPDF_LCD_TEXT)
114 options.m_Flags |= RENDER_CLEARTYPE;
115 else
116 options.m_Flags &= ~RENDER_CLEARTYPE;
117
118 // Grayscale output
119 if (flags & FPDF_GRAYSCALE) {
120 options.m_ColorMode = RENDER_COLOR_GRAY;
121 options.m_ForeColor = 0;
122 options.m_BackColor = 0xffffff;
123 }
124 options.m_AddFlags = flags >> 8;
jaepark75f84a52016-09-09 15:39:09 -0700125 options.m_bDrawAnnots = flags & FPDF_ANNOT;
thestigbefa4502016-05-26 20:15:19 -0700126
jaepark738766e2016-09-02 18:51:44 -0700127#ifdef PDF_ENABLE_XFA
128 options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View);
dsinclair461eeaf2016-07-27 07:40:05 -0700129 if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage, true))
thestigbefa4502016-05-26 20:15:19 -0700130 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
jaepark738766e2016-09-02 18:51:44 -0700131#else // PDF_ENABLE_XFA
132 options.m_pOCContext =
133 new CPDF_OCContext(pPage->m_pDocument, CPDF_OCContext::View);
134 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
135 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
thestigbefa4502016-05-26 20:15:19 -0700136#endif // PDF_ENABLE_XFA
137
138 pDevice->RestoreState(false);
139 delete options.m_pOCContext;
thestig1cd352e2016-06-07 17:53:06 -0700140 options.m_pOCContext = nullptr;
thestigbefa4502016-05-26 20:15:19 -0700141}
142
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700143} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -0700144
Lei Zhangbdf72c32015-08-14 19:24:08 -0700145DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
146 FPDF_PAGE page,
147 double page_x,
148 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700149 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700150 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700151 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 if (pPage) {
thestigdb1a24e2016-05-23 16:55:09 -0700153 CPDF_InterForm interform(pPage->m_pDocument);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800154 CPDF_FormControl* pFormCtrl =
155 interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x),
156 static_cast<FX_FLOAT>(page_y), nullptr);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700157 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800160 return pFormField ? pFormField->GetFieldType() : -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 }
162
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800163#ifdef PDF_ENABLE_XFA
164 CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
165 if (!pXFAPage)
166 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167
dsinclairdf4bc592016-03-31 20:34:43 -0700168 CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800169 if (!pPageView)
170 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171
dsinclairdf4bc592016-03-31 20:34:43 -0700172 CXFA_FFDocView* pDocView = pPageView->GetDocView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800173 if (!pDocView)
174 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175
dsinclairdf4bc592016-03-31 20:34:43 -0700176 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800177 if (!pWidgetHandler)
178 return -1;
179
tsepezcc4d6d82016-05-16 13:21:03 -0700180 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700181 pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form,
182 XFA_WidgetStatus_Viewable));
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800183 if (!pWidgetIterator)
184 return -1;
185
dsinclairdf4bc592016-03-31 20:34:43 -0700186 CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800187 while (pXFAAnnot) {
188 CFX_RectF rcBBox;
dsinclair221caf62016-04-04 12:08:40 -0700189 pXFAAnnot->GetBBox(rcBBox, 0);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800190 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
191 rcBBox.top + rcBBox.height);
192 rcWidget.left -= 1.0f;
193 rcWidget.right += 1.0f;
194 rcWidget.bottom -= 1.0f;
195 rcWidget.top += 1.0f;
196
197 if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x),
198 static_cast<FX_FLOAT>(page_y))) {
199 return FPDF_FORMFIELD_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 }
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800201 pXFAAnnot = pWidgetIterator->MoveToNext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800203#endif // PDF_ENABLE_XFA
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800204 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205}
206
Lei Zhangbdf72c32015-08-14 19:24:08 -0700207DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
208 FPDF_PAGE page,
209 double page_x,
210 double page_y) {
211 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y);
212}
213
214DLLEXPORT 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;
thestigdb1a24e2016-05-23 16:55:09 -0700223 CPDF_InterForm interform(pPage->m_pDocument);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700224 int z_order = -1;
225 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y,
226 &z_order);
227 return z_order;
228}
229
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230DLLEXPORT FPDF_FORMHANDLE STDCALL
231FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
232 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800233#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800234 const int kRequiredVersion = 2;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800235#else // PDF_ENABLE_XFA
236 const int kRequiredVersion = 1;
237#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800238 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700240
Tom Sepez540c4362015-11-24 13:33:57 -0800241 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
242 if (!pDocument)
243 return nullptr;
244
Tom Sepez40e9ff32015-11-30 12:39:54 -0800245#ifdef PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700246 // If the CPDFXFA_Document has a SDKDocument already then we've done this
247 // and can just return the old Env. Otherwise, we'll end up setting a new
248 // SDKDocument into the XFADocument and, that could get weird.
249 if (pDocument->GetSDKDoc())
250 return pDocument->GetSDKDoc()->GetEnv();
251#endif
252
253 CPDFSDK_Environment* pEnv = new CPDFSDK_Environment(pDocument, formInfo);
254
255#ifdef PDF_ENABLE_XFA
256 // Ownership of the SDKDocument is passed to the CPDFXFA_Document.
257 pDocument->SetSDKDoc(WrapUnique(pEnv->GetSDKDocument()));
258 CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800259#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 return pEnv;
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) {
266 if (!hHandle)
267 return;
dsinclaira939bfe2016-09-22 13:18:45 -0700268
dsinclair79db6092016-09-14 07:27:21 -0700269 CPDFSDK_Environment* pEnv = HandleToCPDFSDKEnvironment(hHandle);
dsinclaira939bfe2016-09-22 13:18:45 -0700270
Tom Sepez40e9ff32015-11-30 12:39:54 -0800271#ifdef PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700272 CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800273#else // PDF_ENABLE_XFA
Tom Sepez51da0932015-11-25 16:05:49 -0800274 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) {
thestig1cd352e2016-06-07 17:53:06 -0700275 pEnv->SetSDKDocument(nullptr);
Tom Sepez51da0932015-11-25 16:05:49 -0800276 delete pSDKDoc;
277 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800278#endif // PDF_ENABLE_XFA
dsinclaira939bfe2016-09-22 13:18:45 -0700279
Tom Sepez51da0932015-11-25 16:05:49 -0800280 delete pEnv;
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)
290 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700291
Tom Sepez281a9ea2016-02-26 14:24:28 -0800292 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 return pPageView->OnMouseMove(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700294}
295
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle,
297 FPDF_PAGE page,
298 int modifier,
299 double page_x,
300 double page_y) {
301 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
302 if (!pPageView)
303 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700304
Tom Sepez281a9ea2016-02-26 14:24:28 -0800305 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 return pPageView->OnLButtonDown(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700307}
308
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
310 FPDF_PAGE page,
311 int modifier,
312 double page_x,
313 double page_y) {
314 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
315 if (!pPageView)
316 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700317
Tom Sepez281a9ea2016-02-26 14:24:28 -0800318 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 return pPageView->OnLButtonUp(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700320}
321
Tom Sepez51da0932015-11-25 16:05:49 -0800322#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
324 FPDF_PAGE page,
325 int modifier,
326 double page_x,
327 double page_y) {
328 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
329 if (!pPageView)
330 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700331
Tom Sepez281a9ea2016-02-26 14:24:28 -0800332 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 return pPageView->OnRButtonDown(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700334}
335
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
337 FPDF_PAGE page,
338 int modifier,
339 double page_x,
340 double page_y) {
341 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
342 if (!pPageView)
343 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700344
Tom Sepez281a9ea2016-02-26 14:24:28 -0800345 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 return pPageView->OnRButtonUp(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700347}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800348#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700349
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
351 FPDF_PAGE page,
352 int nKeyCode,
353 int modifier) {
354 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
355 if (!pPageView)
356 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700357
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359}
360
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
362 FPDF_PAGE page,
363 int nKeyCode,
364 int modifier) {
365 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
366 if (!pPageView)
367 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700368
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700370}
371
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
373 FPDF_PAGE page,
374 int nChar,
375 int modifier) {
376 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
377 if (!pPageView)
378 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700379
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700381}
382
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800384 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385 if (!pSDKDoc)
386 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700387
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 return pSDKDoc->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389}
390
Cary Clark399be5b2016-03-14 16:51:29 -0400391DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
392 FPDF_BITMAP bitmap,
393 FPDF_PAGE page,
394 int start_x,
395 int start_y,
396 int size_x,
397 int size_y,
398 int rotate,
399 int flags) {
400 FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
401 rotate, flags);
402}
403
404#ifdef _SKIA_SUPPORT_
405DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle,
406 FPDF_RECORDER recorder,
407 FPDF_PAGE page,
408 int start_x,
409 int start_y,
410 int size_x,
411 int size_y,
412 int rotate,
413 int flags) {
414 FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y,
415 rotate, flags);
416}
417#endif
418
Tom Sepez40e9ff32015-11-30 12:39:54 -0800419#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
421 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700422 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700424
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
426 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
427 pDocument->GetDocType() != XFA_DOCTYPE_Static)
428 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700429
dsinclair221caf62016-04-04 12:08:40 -0700430 static_cast<CXFA_FFWidget*>(hWidget)->Undo();
Bo Xufdc00a72014-10-28 23:03:33 -0700431}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
433 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700434 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700436
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
438 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
439 pDocument->GetDocType() != XFA_DOCTYPE_Static)
440 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700441
dsinclair221caf62016-04-04 12:08:40 -0700442 static_cast<CXFA_FFWidget*>(hWidget)->Redo();
Bo Xufdc00a72014-10-28 23:03:33 -0700443}
444
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445DLLEXPORT void STDCALL FPDF_Widget_SelectAll(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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
451 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
452 pDocument->GetDocType() != XFA_DOCTYPE_Static)
453 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700454
dsinclair221caf62016-04-04 12:08:40 -0700455 static_cast<CXFA_FFWidget*>(hWidget)->SelectAll();
Bo Xufdc00a72014-10-28 23:03:33 -0700456}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
458 FPDF_WIDGET hWidget,
459 FPDF_WIDESTRING wsText,
460 FPDF_DWORD* size) {
dsinclair221caf62016-04-04 12:08:40 -0700461 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700463
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
465 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
466 pDocument->GetDocType() != XFA_DOCTYPE_Static)
467 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700470 static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700471
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700473 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
thestigbefa4502016-05-26 20:15:19 -0700474 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 *size = len;
476 return;
477 }
Bo Xufdc00a72014-10-28 23:03:33 -0700478
weili47ca6922016-03-31 15:08:27 -0700479 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 if (real_size > 0) {
481 FXSYS_memcpy((void*)wsText,
482 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
483 real_size * sizeof(unsigned short));
484 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
485 }
486 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700487}
Tom Sepezab277682016-02-17 10:07:21 -0800488
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
490 FPDF_WIDGET hWidget,
491 FPDF_WIDESTRING wsText,
492 FPDF_DWORD* size) {
thestigbefa4502016-05-26 20:15:19 -0700493 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 return;
thestigbefa4502016-05-26 20:15:19 -0700495
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
497 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
498 pDocument->GetDocType() != XFA_DOCTYPE_Static)
499 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700500
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700502 static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700503
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700505 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
dsinclair221caf62016-04-04 12:08:40 -0700506 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 *size = len;
508 return;
509 }
Bo Xufdc00a72014-10-28 23:03:33 -0700510
weili47ca6922016-03-31 15:08:27 -0700511 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 if (real_size > 0) {
513 FXSYS_memcpy((void*)wsText,
514 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
515 real_size * sizeof(unsigned short));
516 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
517 }
518 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700519}
Tom Sepezab277682016-02-17 10:07:21 -0800520
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
522 FPDF_WIDGET hWidget,
523 FPDF_WIDESTRING wsText,
524 FPDF_DWORD size) {
dsinclair221caf62016-04-04 12:08:40 -0700525 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700527
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
529 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
530 pDocument->GetDocType() != XFA_DOCTYPE_Static)
531 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700532
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
dsinclair221caf62016-04-04 12:08:40 -0700534 static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700535}
Tom Sepezab277682016-02-17 10:07:21 -0800536
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537DLLEXPORT void STDCALL
538FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
539 FPDF_WIDGET hWidget,
540 float x,
541 float y,
542 FPDF_BYTESTRING bsText) {
dsinclair221caf62016-04-04 12:08:40 -0700543 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700545
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
547 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
548 pDocument->GetDocType() != XFA_DOCTYPE_Static)
549 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700550
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 CFX_PointF ptPopup;
552 ptPopup.x = x;
553 ptPopup.y = y;
554 CFX_ByteStringC bs(bsText);
dsinclair221caf62016-04-04 12:08:40 -0700555 static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700556}
Tom Sepezab277682016-02-17 10:07:21 -0800557
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558DLLEXPORT void STDCALL
559FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
560 FPDF_WIDGET hWidget,
561 float x,
562 float y,
563 FPDF_STRINGHANDLE* stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800564 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700566
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
568 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
569 pDocument->GetDocType() != XFA_DOCTYPE_Static)
570 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700571
Tom Sepezab277682016-02-17 10:07:21 -0800572 std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 CFX_PointF ptPopup;
574 ptPopup.x = x;
575 ptPopup.y = y;
dsinclair221caf62016-04-04 12:08:40 -0700576 static_cast<CXFA_FFWidget*>(hWidget)
577 ->GetSuggestWords(ptPopup, *sSuggestWords);
Tom Sepezab277682016-02-17 10:07:21 -0800578 *stringHandle = ToFPDFStringHandle(sSuggestWords);
Bo Xufdc00a72014-10-28 23:03:33 -0700579}
Tom Sepezab277682016-02-17 10:07:21 -0800580
581DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
582 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
583 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700584}
Tom Sepezab277682016-02-17 10:07:21 -0800585
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586DLLEXPORT FPDF_BOOL STDCALL
Tom Sepezab277682016-02-17 10:07:21 -0800587FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 int index,
589 FPDF_BYTESTRING bsText,
590 FPDF_DWORD* size) {
Tom Sepezab277682016-02-17 10:07:21 -0800591 if (!sHandle || !size)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 return FALSE;
Tom Sepezab277682016-02-17 10:07:21 -0800593
594 int count = FPDF_StringHandleCounts(sHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 if (index < 0 || index >= count)
596 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700597
Tom Sepezab277682016-02-17 10:07:21 -0800598 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
weili47ca6922016-03-31 15:08:27 -0700599 uint32_t len = (*sSuggestWords)[index].GetLength();
Tom Sepezab277682016-02-17 10:07:21 -0800600 if (!bsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 *size = len;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700602 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 }
604
weili47ca6922016-03-31 15:08:27 -0700605 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 if (real_size > 0)
tsepezb4c9f3f2016-04-13 15:41:21 -0700607 FXSYS_memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 *size = real_size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -0700610}
Tom Sepezab277682016-02-17 10:07:21 -0800611
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612DLLEXPORT void STDCALL
613FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800614 delete FromFPDFStringHandle(stringHandle);
Bo Xufdc00a72014-10-28 23:03:33 -0700615}
616
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617DLLEXPORT FPDF_BOOL STDCALL
618FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
619 FPDF_BYTESTRING bsText,
620 FPDF_DWORD size) {
Tom Sepezab277682016-02-17 10:07:21 -0800621 if (!stringHandle || !bsText || size == 0)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700623
Tom Sepezab277682016-02-17 10:07:21 -0800624 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -0700626}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800627#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
630 int fieldType,
631 unsigned long color) {
632 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
633 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634}
635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
637 unsigned char alpha) {
638 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
639 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700640}
641
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
643 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
644 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
648 FPDF_FORMHANDLE hHandle) {
649 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
650 pPageView->SetValid(TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651}
652
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
654 FPDF_FORMHANDLE hHandle) {
Tom Sepez540c4362015-11-24 13:33:57 -0800655 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700657
dsinclair79db6092016-09-14 07:27:21 -0700658 CPDFSDK_Document* pSDKDoc =
659 HandleToCPDFSDKEnvironment(hHandle)->GetSDKDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 if (!pSDKDoc)
661 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700662
Tom Sepez540c4362015-11-24 13:33:57 -0800663 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
664 if (!pPage)
665 return;
666
dsinclair461eeaf2016-07-27 07:40:05 -0700667 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 if (pPageView) {
669 pPageView->SetValid(FALSE);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800670 // RemovePageView() takes care of the delete for us.
671 pSDKDoc->RemovePageView(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672 }
673}
674
675DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800676 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
dsinclair79db6092016-09-14 07:27:21 -0700677 if (pSDKDoc && HandleToCPDFSDKEnvironment(hHandle)->IsJSInitiated())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 pSDKDoc->ProcJavascriptFun();
679}
680
681DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800682 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
dsinclair79db6092016-09-14 07:27:21 -0700683 if (pSDKDoc && HandleToCPDFSDKEnvironment(hHandle)->IsJSInitiated())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 pSDKDoc->ProcOpenAction();
685}
686
687DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
688 int aaType) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800689 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 if (!pSDKDoc)
691 return;
692
Tom Sepez50d12ad2015-11-24 09:50:51 -0800693 CPDF_Document* pDoc = pSDKDoc->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694 CPDF_Dictionary* pDic = pDoc->GetRoot();
695 if (!pDic)
696 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700697
dsinclair38fd8442016-09-15 10:15:32 -0700698 CPDF_AAction aa(pDic->GetDictFor("AA"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) {
700 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
701 CPDFSDK_ActionHandler* pActionHandler =
dsinclair79db6092016-09-14 07:27:21 -0700702 HandleToCPDFSDKEnvironment(hHandle)->GetActionHander();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType,
704 pSDKDoc);
705 }
706}
707
708DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
709 FPDF_FORMHANDLE hHandle,
710 int aaType) {
Tom Sepez540c4362015-11-24 13:33:57 -0800711 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700713
714 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
715 if (!pSDKDoc)
716 return;
717
Tom Sepez540c4362015-11-24 13:33:57 -0800718 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
719 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700720 if (!pPDFPage)
721 return;
tonikitoo401d4f22016-08-10 11:37:45 -0700722
723 if (!pSDKDoc->GetPageView(pPage, false))
724 return;
725
dsinclair79db6092016-09-14 07:27:21 -0700726 CPDFSDK_Environment* pEnv = pSDKDoc->GetEnv();
tonikitoo401d4f22016-08-10 11:37:45 -0700727 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
728 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict;
dsinclair38fd8442016-09-15 10:15:32 -0700729 CPDF_AAction aa(pPageDict->GetDictFor("AA"));
tonikitoo401d4f22016-08-10 11:37:45 -0700730 if (FPDFPAGE_AACTION_OPEN == aaType) {
731 if (aa.ActionExist(CPDF_AAction::OpenPage)) {
732 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
733 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc);
734 }
735 } else {
736 if (aa.ActionExist(CPDF_AAction::ClosePage)) {
737 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
738 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700739 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741}