blob: 26bc30e07cb34b1a58ac1ff8e8b81a3dd24c11cc [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"
Lei Zhangbde53d22015-11-12 22:21:30 -080015#include "fpdfsdk/include/fsdk_define.h"
16#include "fpdfsdk/include/fsdk_mgr.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080017#include "public/fpdfview.h"
Tom Sepezab277682016-02-17 10:07:21 -080018#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019
Tom Sepez40e9ff32015-11-30 12:39:54 -080020#ifdef PDF_ENABLE_XFA
Lei Zhang875b9c92016-01-08 13:51:10 -080021#include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h"
22#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
23#include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h"
dsinclairdf4bc592016-03-31 20:34:43 -070024#include "xfa/include/fxfa/xfa_ffapp.h"
25#include "xfa/include/fxfa/xfa_ffdocview.h"
26#include "xfa/include/fxfa/xfa_ffpageview.h"
dsinclair221caf62016-04-04 12:08:40 -070027#include "xfa/include/fxfa/xfa_ffwidget.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080028#endif // PDF_ENABLE_XFA
29
Tom Sepezdcbc02f2015-07-17 09:16:17 -070030namespace {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -080033 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070035}
Bo Xufdc00a72014-10-28 23:03:33 -070036
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
38 FPDF_PAGE page) {
Tom Sepez540c4362015-11-24 13:33:57 -080039 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
40 if (!pPage)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 return nullptr;
Tom Sepez0b133982015-07-28 11:23:22 -070042
Tom Sepezfe351db2016-01-29 16:26:27 -080043 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Tom Sepez540c4362015-11-24 13:33:57 -080044 return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070045}
Bo Xufdc00a72014-10-28 23:03:33 -070046
Tom Sepezab277682016-02-17 10:07:21 -080047#ifdef PDF_ENABLE_XFA
48std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) {
49 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle);
50}
51
52FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) {
53 return reinterpret_cast<FPDF_STRINGHANDLE>(strings);
54}
55#endif // PDF_ENABLE_XFA
56
Tom Sepezdcbc02f2015-07-17 09:16:17 -070057} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -070058
Lei Zhangbdf72c32015-08-14 19:24:08 -070059DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
60 FPDF_PAGE page,
61 double page_x,
62 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -070063 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -070064 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -070065 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 if (pPage) {
Lei Zhangbdf72c32015-08-14 19:24:08 -070067 CPDF_InterForm interform(pPage->m_pDocument, FALSE);
Lei Zhang7f9fdde2016-02-22 20:47:13 -080068 CPDF_FormControl* pFormCtrl =
69 interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x),
70 static_cast<FX_FLOAT>(page_y), nullptr);
Lei Zhangbdf72c32015-08-14 19:24:08 -070071 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhang7f9fdde2016-02-22 20:47:13 -080074 return pFormField ? pFormField->GetFieldType() : -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 }
76
Lei Zhang7f9fdde2016-02-22 20:47:13 -080077#ifdef PDF_ENABLE_XFA
78 CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
79 if (!pXFAPage)
80 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081
dsinclairdf4bc592016-03-31 20:34:43 -070082 CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -080083 if (!pPageView)
84 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085
dsinclairdf4bc592016-03-31 20:34:43 -070086 CXFA_FFDocView* pDocView = pPageView->GetDocView();
Lei Zhang7f9fdde2016-02-22 20:47:13 -080087 if (!pDocView)
88 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089
dsinclairdf4bc592016-03-31 20:34:43 -070090 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Lei Zhang7f9fdde2016-02-22 20:47:13 -080091 if (!pWidgetHandler)
92 return -1;
93
94 std::unique_ptr<IXFA_WidgetIterator, ReleaseDeleter<IXFA_WidgetIterator>>
95 pWidgetIterator(pPageView->CreateWidgetIterator(
96 XFA_TRAVERSEWAY_Form,
97 XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType));
98 if (!pWidgetIterator)
99 return -1;
100
dsinclairdf4bc592016-03-31 20:34:43 -0700101 CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800102 while (pXFAAnnot) {
103 CFX_RectF rcBBox;
dsinclair221caf62016-04-04 12:08:40 -0700104 pXFAAnnot->GetBBox(rcBBox, 0);
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800105 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
106 rcBBox.top + rcBBox.height);
107 rcWidget.left -= 1.0f;
108 rcWidget.right += 1.0f;
109 rcWidget.bottom -= 1.0f;
110 rcWidget.top += 1.0f;
111
112 if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x),
113 static_cast<FX_FLOAT>(page_y))) {
114 return FPDF_FORMFIELD_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 }
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800116 pXFAAnnot = pWidgetIterator->MoveToNext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800118#endif // PDF_ENABLE_XFA
Lei Zhang7f9fdde2016-02-22 20:47:13 -0800119 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120}
121
Lei Zhangbdf72c32015-08-14 19:24:08 -0700122DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
123 FPDF_PAGE page,
124 double page_x,
125 double page_y) {
126 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y);
127}
128
129DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
130 FPDF_PAGE page,
131 double page_x,
132 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700133 if (!hHandle)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700134 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700135 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
136 if (!pPage)
137 return -1;
Lei Zhangbdf72c32015-08-14 19:24:08 -0700138 CPDF_InterForm interform(pPage->m_pDocument, FALSE);
139 int z_order = -1;
140 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y,
141 &z_order);
142 return z_order;
143}
144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145DLLEXPORT FPDF_FORMHANDLE STDCALL
146FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
147 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800148#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800149 const int kRequiredVersion = 2;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800150#else // PDF_ENABLE_XFA
151 const int kRequiredVersion = 1;
152#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800153 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155
Tom Sepez540c4362015-11-24 13:33:57 -0800156 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
157 if (!pDocument)
158 return nullptr;
159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800161#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
164 pApp->AddFormFillEnv(pEnv);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800165#else // PDF_ENABLE_XFA
166 pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv));
167#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 return pEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169}
170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171DLLEXPORT void STDCALL
172FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
173 if (!hHandle)
174 return;
Tom Sepez51da0932015-11-25 16:05:49 -0800175 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800176#ifdef PDF_ENABLE_XFA
177 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
178 pApp->RemoveFormFillEnv(pEnv);
179#else // PDF_ENABLE_XFA
Tom Sepez51da0932015-11-25 16:05:49 -0800180 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) {
181 pEnv->SetSDKDocument(NULL);
182 delete pSDKDoc;
183 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800184#endif // PDF_ENABLE_XFA
Tom Sepez51da0932015-11-25 16:05:49 -0800185 delete pEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700186}
187
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
189 FPDF_PAGE page,
190 int modifier,
191 double page_x,
192 double page_y) {
193 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
194 if (!pPageView)
195 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700196
Tom Sepez281a9ea2016-02-26 14:24:28 -0800197 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 return pPageView->OnMouseMove(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199}
200
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle,
202 FPDF_PAGE page,
203 int modifier,
204 double page_x,
205 double page_y) {
206 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
207 if (!pPageView)
208 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700209
Tom Sepez281a9ea2016-02-26 14:24:28 -0800210 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 return pPageView->OnLButtonDown(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212}
213
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
215 FPDF_PAGE page,
216 int modifier,
217 double page_x,
218 double page_y) {
219 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
220 if (!pPageView)
221 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700222
Tom Sepez281a9ea2016-02-26 14:24:28 -0800223 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 return pPageView->OnLButtonUp(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225}
226
Tom Sepez51da0932015-11-25 16:05:49 -0800227#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
229 FPDF_PAGE page,
230 int modifier,
231 double page_x,
232 double page_y) {
233 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
234 if (!pPageView)
235 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700236
Tom Sepez281a9ea2016-02-26 14:24:28 -0800237 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 return pPageView->OnRButtonDown(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700239}
240
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
242 FPDF_PAGE page,
243 int modifier,
244 double page_x,
245 double page_y) {
246 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
247 if (!pPageView)
248 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700249
Tom Sepez281a9ea2016-02-26 14:24:28 -0800250 CFX_FloatPoint pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 return pPageView->OnRButtonUp(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700252}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800253#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700254
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
256 FPDF_PAGE page,
257 int nKeyCode,
258 int modifier) {
259 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
260 if (!pPageView)
261 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700262
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264}
265
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
267 FPDF_PAGE page,
268 int nKeyCode,
269 int modifier) {
270 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
271 if (!pPageView)
272 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700273
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275}
276
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
278 FPDF_PAGE page,
279 int nChar,
280 int modifier) {
281 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
282 if (!pPageView)
283 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286}
287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800289 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 if (!pSDKDoc)
291 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700292
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 return pSDKDoc->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700294}
295
Cary Clark399be5b2016-03-14 16:51:29 -0400296static void FFLCommon(FPDF_FORMHANDLE hHandle,
297 FPDF_BITMAP bitmap,
298 FPDF_RECORDER recorder,
299 FPDF_PAGE page,
300 int start_x,
301 int start_y,
302 int size_x,
303 int size_y,
304 int rotate,
305 int flags) {
Tom Sepez1b246282015-11-25 15:15:31 -0800306 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 return;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700308
Tom Sepez1b246282015-11-25 15:15:31 -0800309 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
310 if (!pPage)
311 return;
312
Tom Sepez51da0932015-11-25 16:05:49 -0800313#ifndef PDF_ENABLE_XFA
314 CPDF_RenderOptions options;
315 if (flags & FPDF_LCD_TEXT)
316 options.m_Flags |= RENDER_CLEARTYPE;
317 else
318 options.m_Flags &= ~RENDER_CLEARTYPE;
Tom Sepez51da0932015-11-25 16:05:49 -0800319 // Grayscale output
320 if (flags & FPDF_GRAYSCALE) {
321 options.m_ColorMode = RENDER_COLOR_GRAY;
322 options.m_ForeColor = 0;
323 options.m_BackColor = 0xffffff;
324 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800325 options.m_AddFlags = flags >> 8;
326 options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument);
327#else // PDF_ENABLE_XFA
328 CPDFXFA_Document* pDocument = pPage->GetDocument();
329 if (!pDocument)
330 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc();
332 if (!pPDFDoc)
333 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
335 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument();
336 if (!pFXDoc)
337 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800338#endif // PDF_ENABLE_XFA
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700339
Tom Sepez60d909e2015-12-10 15:34:55 -0800340 CFX_Matrix matrix;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700342
Tom Sepezbec4ea12016-02-29 13:23:13 -0800343 FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700344
345#ifdef _SKIA_SUPPORT_
Cary Clark399be5b2016-03-14 16:51:29 -0400346 std::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice());
347 pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700348#else
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800349 std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351 pDevice->Attach((CFX_DIBitmap*)bitmap);
352 pDevice->SaveState();
Tom Sepezbec4ea12016-02-29 13:23:13 -0800353 pDevice->SetClip_Rect(clip);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700354
Tom Sepez51da0932015-11-25 16:05:49 -0800355#ifndef PDF_ENABLE_XFA
356 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
357 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800358#else // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 CPDF_RenderOptions options;
360 if (flags & FPDF_LCD_TEXT)
361 options.m_Flags |= RENDER_CLEARTYPE;
362 else
363 options.m_Flags &= ~RENDER_CLEARTYPE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 // Grayscale output
366 if (flags & FPDF_GRAYSCALE) {
367 options.m_ColorMode = RENDER_COLOR_GRAY;
368 options.m_ForeColor = 0;
369 options.m_BackColor = 0xffffff;
370 }
371 options.m_AddFlags = flags >> 8;
Tom Sepezae51c812015-08-05 12:34:06 -0700372 options.m_pOCContext = new CPDF_OCContext(pPDFDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373
Tom Sepez1b246282015-11-25 15:15:31 -0800374 if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800375 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800376#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378 pDevice->RestoreState();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 delete options.m_pOCContext;
Tom Sepez51da0932015-11-25 16:05:49 -0800380#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 options.m_pOCContext = NULL;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800382#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800384
Cary Clark399be5b2016-03-14 16:51:29 -0400385DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
386 FPDF_BITMAP bitmap,
387 FPDF_PAGE page,
388 int start_x,
389 int start_y,
390 int size_x,
391 int size_y,
392 int rotate,
393 int flags) {
394 FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
395 rotate, flags);
396}
397
398#ifdef _SKIA_SUPPORT_
399DLLEXPORT void STDCALL FPDF_FFLRecord(FPDF_FORMHANDLE hHandle,
400 FPDF_RECORDER recorder,
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, nullptr, recorder, page, start_x, start_y, size_x, size_y,
409 rotate, flags);
410}
411#endif
412
Tom Sepez40e9ff32015-11-30 12:39:54 -0800413#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
415 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700416 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700418
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
420 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
421 pDocument->GetDocType() != XFA_DOCTYPE_Static)
422 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700423
dsinclair221caf62016-04-04 12:08:40 -0700424 static_cast<CXFA_FFWidget*>(hWidget)->Undo();
Bo Xufdc00a72014-10-28 23:03:33 -0700425}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
427 FPDF_WIDGET hWidget) {
dsinclair221caf62016-04-04 12:08:40 -0700428 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700430
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
432 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
433 pDocument->GetDocType() != XFA_DOCTYPE_Static)
434 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700435
dsinclair221caf62016-04-04 12:08:40 -0700436 static_cast<CXFA_FFWidget*>(hWidget)->Redo();
Bo Xufdc00a72014-10-28 23:03:33 -0700437}
438
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439DLLEXPORT void STDCALL FPDF_Widget_SelectAll(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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
445 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
446 pDocument->GetDocType() != XFA_DOCTYPE_Static)
447 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700448
dsinclair221caf62016-04-04 12:08:40 -0700449 static_cast<CXFA_FFWidget*>(hWidget)->SelectAll();
Bo Xufdc00a72014-10-28 23:03:33 -0700450}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
452 FPDF_WIDGET hWidget,
453 FPDF_WIDESTRING wsText,
454 FPDF_DWORD* size) {
dsinclair221caf62016-04-04 12:08:40 -0700455 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700457
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
459 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
460 pDocument->GetDocType() != XFA_DOCTYPE_Static)
461 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700462
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700464 static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700465
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700467 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 if (wsText == NULL) {
469 *size = len;
470 return;
471 }
Bo Xufdc00a72014-10-28 23:03:33 -0700472
weili47ca6922016-03-31 15:08:27 -0700473 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 if (real_size > 0) {
475 FXSYS_memcpy((void*)wsText,
476 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
477 real_size * sizeof(unsigned short));
478 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
479 }
480 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700481}
Tom Sepezab277682016-02-17 10:07:21 -0800482
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
484 FPDF_WIDGET hWidget,
485 FPDF_WIDESTRING wsText,
486 FPDF_DWORD* size) {
487 if (NULL == hWidget || NULL == document)
488 return;
489 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
490 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
491 pDocument->GetDocType() != XFA_DOCTYPE_Static)
492 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700493
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 CFX_WideString wsCpText;
dsinclair221caf62016-04-04 12:08:40 -0700495 static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700496
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
weili47ca6922016-03-31 15:08:27 -0700498 uint32_t len = bsCpText.GetLength() / sizeof(unsigned short);
dsinclair221caf62016-04-04 12:08:40 -0700499 if (!wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 *size = len;
501 return;
502 }
Bo Xufdc00a72014-10-28 23:03:33 -0700503
weili47ca6922016-03-31 15:08:27 -0700504 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 if (real_size > 0) {
506 FXSYS_memcpy((void*)wsText,
507 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
508 real_size * sizeof(unsigned short));
509 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
510 }
511 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700512}
Tom Sepezab277682016-02-17 10:07:21 -0800513
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
515 FPDF_WIDGET hWidget,
516 FPDF_WIDESTRING wsText,
517 FPDF_DWORD size) {
dsinclair221caf62016-04-04 12:08:40 -0700518 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700520
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
522 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
523 pDocument->GetDocType() != XFA_DOCTYPE_Static)
524 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700525
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
dsinclair221caf62016-04-04 12:08:40 -0700527 static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700528}
Tom Sepezab277682016-02-17 10:07:21 -0800529
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530DLLEXPORT void STDCALL
531FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
532 FPDF_WIDGET hWidget,
533 float x,
534 float y,
535 FPDF_BYTESTRING bsText) {
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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
540 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
541 pDocument->GetDocType() != XFA_DOCTYPE_Static)
542 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700543
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 CFX_PointF ptPopup;
545 ptPopup.x = x;
546 ptPopup.y = y;
547 CFX_ByteStringC bs(bsText);
dsinclair221caf62016-04-04 12:08:40 -0700548 static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700549}
Tom Sepezab277682016-02-17 10:07:21 -0800550
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551DLLEXPORT void STDCALL
552FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
553 FPDF_WIDGET hWidget,
554 float x,
555 float y,
556 FPDF_STRINGHANDLE* stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800557 if (!hWidget || !document)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700559
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
561 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
562 pDocument->GetDocType() != XFA_DOCTYPE_Static)
563 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700564
Tom Sepezab277682016-02-17 10:07:21 -0800565 std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 CFX_PointF ptPopup;
567 ptPopup.x = x;
568 ptPopup.y = y;
dsinclair221caf62016-04-04 12:08:40 -0700569 static_cast<CXFA_FFWidget*>(hWidget)
570 ->GetSuggestWords(ptPopup, *sSuggestWords);
Tom Sepezab277682016-02-17 10:07:21 -0800571 *stringHandle = ToFPDFStringHandle(sSuggestWords);
Bo Xufdc00a72014-10-28 23:03:33 -0700572}
Tom Sepezab277682016-02-17 10:07:21 -0800573
574DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
575 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
576 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700577}
Tom Sepezab277682016-02-17 10:07:21 -0800578
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579DLLEXPORT FPDF_BOOL STDCALL
Tom Sepezab277682016-02-17 10:07:21 -0800580FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 int index,
582 FPDF_BYTESTRING bsText,
583 FPDF_DWORD* size) {
Tom Sepezab277682016-02-17 10:07:21 -0800584 if (!sHandle || !size)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 return FALSE;
Tom Sepezab277682016-02-17 10:07:21 -0800586
587 int count = FPDF_StringHandleCounts(sHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 if (index < 0 || index >= count)
589 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700590
Tom Sepezab277682016-02-17 10:07:21 -0800591 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
weili47ca6922016-03-31 15:08:27 -0700592 uint32_t len = (*sSuggestWords)[index].GetLength();
Tom Sepezab277682016-02-17 10:07:21 -0800593 if (!bsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 *size = len;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700595 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596 }
597
weili47ca6922016-03-31 15:08:27 -0700598 uint32_t real_size = len < *size ? len : *size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 if (real_size > 0)
Tom Sepezab277682016-02-17 10:07:21 -0800600 FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(*sSuggestWords)[index],
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 real_size);
602 *size = real_size;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -0700604}
Tom Sepezab277682016-02-17 10:07:21 -0800605
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606DLLEXPORT void STDCALL
607FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
Tom Sepezab277682016-02-17 10:07:21 -0800608 delete FromFPDFStringHandle(stringHandle);
Bo Xufdc00a72014-10-28 23:03:33 -0700609}
610
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611DLLEXPORT FPDF_BOOL STDCALL
612FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
613 FPDF_BYTESTRING bsText,
614 FPDF_DWORD size) {
Tom Sepezab277682016-02-17 10:07:21 -0800615 if (!stringHandle || !bsText || size == 0)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700617
Tom Sepezab277682016-02-17 10:07:21 -0800618 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -0700620}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800621#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
624 int fieldType,
625 unsigned long color) {
626 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
627 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628}
629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
631 unsigned char alpha) {
632 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
633 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634}
635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
637 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
638 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700639}
640
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
642 FPDF_FORMHANDLE hHandle) {
643 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
644 pPageView->SetValid(TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
648 FPDF_FORMHANDLE hHandle) {
Tom Sepez540c4362015-11-24 13:33:57 -0800649 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700651
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument();
653 if (!pSDKDoc)
654 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700655
Tom Sepez540c4362015-11-24 13:33:57 -0800656 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
657 if (!pPage)
658 return;
659
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
661 if (pPageView) {
662 pPageView->SetValid(FALSE);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800663 // RemovePageView() takes care of the delete for us.
664 pSDKDoc->RemovePageView(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665 }
666}
667
668DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800669 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
671 pSDKDoc->ProcJavascriptFun();
672}
673
674DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800675 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
677 pSDKDoc->ProcOpenAction();
678}
679
680DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
681 int aaType) {
Tom Sepezfe351db2016-01-29 16:26:27 -0800682 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 if (!pSDKDoc)
684 return;
685
Tom Sepez50d12ad2015-11-24 09:50:51 -0800686 CPDF_Document* pDoc = pSDKDoc->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 CPDF_Dictionary* pDic = pDoc->GetRoot();
688 if (!pDic)
689 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700690
Wei Li0fc6b252016-03-01 16:29:41 -0800691 CPDF_AAction aa(pDic->GetDictBy("AA"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) {
693 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
694 CPDFSDK_ActionHandler* pActionHandler =
695 ((CPDFDoc_Environment*)hHandle)->GetActionHander();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType,
697 pSDKDoc);
698 }
699}
700
701DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
702 FPDF_FORMHANDLE hHandle,
703 int aaType) {
Tom Sepez540c4362015-11-24 13:33:57 -0800704 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 return;
706 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument();
Tom Sepez540c4362015-11-24 13:33:57 -0800707 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
708 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700709 if (!pPDFPage)
710 return;
711 if (pSDKDoc->GetPageView(pPage, FALSE)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv();
713 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
Tom Sepezde4791d2015-10-30 12:13:10 -0700714 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict;
Wei Li0fc6b252016-03-01 16:29:41 -0800715 CPDF_AAction aa(pPageDict->GetDictBy("AA"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 if (FPDFPAGE_AACTION_OPEN == aaType) {
Tom Sepezde4791d2015-10-30 12:13:10 -0700717 if (aa.ActionExist(CPDF_AAction::OpenPage)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
719 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc);
720 }
721 } else {
Tom Sepezde4791d2015-10-30 12:13:10 -0700722 if (aa.ActionExist(CPDF_AAction::ClosePage)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700723 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
724 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc);
725 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700726 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728}