blob: 262a56e2d1498f82344038b3f16b62075eb49816 [file] [log] [blame]
dsinclairf34518b2016-09-13 12:03:48 -07001// Copyright 2016 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.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair735606d2016-10-05 15:47:02 -07007#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclairf34518b2016-09-13 12:03:48 -07008
thestigd4c34f22016-09-28 17:04:51 -07009#include <memory>
Tom Sepezfe91c6c2017-05-16 15:33:20 -070010#include <utility>
thestigd4c34f22016-09-28 17:04:51 -070011
dsinclair7cbe68e2016-10-12 11:56:23 -070012#include "core/fpdfapi/parser/cpdf_array.h"
13#include "core/fpdfdoc/cpdf_docjsactions.h"
Dan Sinclair7d125322018-03-28 18:49:34 +000014#include "fpdfsdk/cpdfsdk_actionhandler.h"
dsinclair114e46a2016-09-29 17:18:21 -070015#include "fpdfsdk/cpdfsdk_annothandlermgr.h"
dsinclair7cbe68e2016-10-12 11:56:23 -070016#include "fpdfsdk/cpdfsdk_interform.h"
17#include "fpdfsdk/cpdfsdk_pageview.h"
18#include "fpdfsdk/cpdfsdk_widget.h"
dsinclairb94d7c92016-09-21 12:07:00 -070019#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000020#include "fxjs/ijs_runtime.h"
tsepez36eb4bd2016-10-03 15:24:27 -070021#include "third_party/base/ptr_util.h"
dsinclairf34518b2016-09-13 12:03:48 -070022
Ryan Harrison275e2602017-09-18 14:23:18 -040023FPDF_WIDESTRING AsFPDFWideString(ByteString* bsUTF16LE) {
Tom Sepez1e934f62018-04-11 21:11:28 +000024 // Force a private version of the string, since we're about to hand it off
25 // to the embedder. Should the embedder modify it by accident, it won't
26 // corrupt other shares of the string beyond |bsUTF16LE|.
dsinclairf34518b2016-09-13 12:03:48 -070027 return reinterpret_cast<FPDF_WIDESTRING>(
Tom Sepez1dbfe992018-04-17 17:19:30 +000028 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength()).data());
dsinclairf34518b2016-09-13 12:03:48 -070029}
30
dsinclair735606d2016-10-05 15:47:02 -070031CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment(
32 UnderlyingDocumentType* pDoc,
33 FPDF_FORMFILLINFO* pFFinfo)
dsinclaira939bfe2016-09-22 13:18:45 -070034 : m_pInfo(pFFinfo),
dsinclaira939bfe2016-09-22 13:18:45 -070035 m_pUnderlyingDoc(pDoc),
Dan Sinclair0bb13332017-03-30 16:12:02 -040036 m_pSysHandler(pdfium::MakeUnique<CFX_SystemHandler>(this)),
dsinclair6c659ab2016-10-12 13:41:38 -070037 m_bChangeMask(false),
38 m_bBeingDestroyed(false) {}
dsinclairf34518b2016-09-13 12:03:48 -070039
dsinclair735606d2016-10-05 15:47:02 -070040CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() {
dsinclair6c659ab2016-10-12 13:41:38 -070041 m_bBeingDestroyed = true;
dsinclair7cbe68e2016-10-12 11:56:23 -070042 ClearAllFocusedAnnots();
dsinclair7cbe68e2016-10-12 11:56:23 -070043
tsepez2599ff72016-11-08 14:38:59 -080044 // |m_PageMap| will try to access |m_pInterForm| when it cleans itself up.
45 // Make sure it is deleted before |m_pInterForm|.
46 m_PageMap.clear();
47
48 // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| when it cleans
49 // itself up. Make sure it is deleted before |m_pFormFiller|.
dsinclair709f5a92016-10-11 14:21:16 -070050 m_pAnnotHandlerMgr.reset();
51
52 // Must destroy the |m_pFormFiller| before the environment (|this|)
53 // because any created form widgets hold a pointer to the environment.
54 // Those widgets may call things like KillTimer() as they are shutdown.
55 m_pFormFiller.reset();
56
dsinclairf34518b2016-09-13 12:03:48 -070057 if (m_pInfo && m_pInfo->Release)
58 m_pInfo->Release(m_pInfo);
59}
60
Dan Sinclair812e96c2017-03-13 16:43:37 -040061int CPDFSDK_FormFillEnvironment::JS_appAlert(const wchar_t* Msg,
62 const wchar_t* Title,
dsinclair735606d2016-10-05 15:47:02 -070063 uint32_t Type,
64 uint32_t Icon) {
dsinclairf34518b2016-09-13 12:03:48 -070065 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
66 !m_pInfo->m_pJsPlatform->app_alert) {
67 return -1;
68 }
Ryan Harrison275e2602017-09-18 14:23:18 -040069 ByteString bsMsg = WideString(Msg).UTF16LE_Encode();
70 ByteString bsTitle = WideString(Title).UTF16LE_Encode();
dsinclairf34518b2016-09-13 12:03:48 -070071 return m_pInfo->m_pJsPlatform->app_alert(
72 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg),
73 AsFPDFWideString(&bsTitle), Type, Icon);
74}
75
Dan Sinclair812e96c2017-03-13 16:43:37 -040076int CPDFSDK_FormFillEnvironment::JS_appResponse(const wchar_t* Question,
77 const wchar_t* Title,
78 const wchar_t* Default,
79 const wchar_t* cLabel,
dsinclair735606d2016-10-05 15:47:02 -070080 FPDF_BOOL bPassword,
81 void* response,
82 int length) {
dsinclairf34518b2016-09-13 12:03:48 -070083 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
84 !m_pInfo->m_pJsPlatform->app_response) {
85 return -1;
86 }
Ryan Harrison275e2602017-09-18 14:23:18 -040087 ByteString bsQuestion = WideString(Question).UTF16LE_Encode();
88 ByteString bsTitle = WideString(Title).UTF16LE_Encode();
89 ByteString bsDefault = WideString(Default).UTF16LE_Encode();
90 ByteString bsLabel = WideString(cLabel).UTF16LE_Encode();
dsinclairf34518b2016-09-13 12:03:48 -070091 return m_pInfo->m_pJsPlatform->app_response(
92 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion),
93 AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault),
94 AsFPDFWideString(&bsLabel), bPassword, response, length);
95}
96
dsinclair735606d2016-10-05 15:47:02 -070097void CPDFSDK_FormFillEnvironment::JS_appBeep(int nType) {
dsinclairf34518b2016-09-13 12:03:48 -070098 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
99 !m_pInfo->m_pJsPlatform->app_beep) {
100 return;
101 }
102 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
103}
104
Ryan Harrison275e2602017-09-18 14:23:18 -0400105WideString CPDFSDK_FormFillEnvironment::JS_fieldBrowse() {
dsinclairf34518b2016-09-13 12:03:48 -0700106 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
107 !m_pInfo->m_pJsPlatform->Field_browse) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400108 return WideString();
dsinclairf34518b2016-09-13 12:03:48 -0700109 }
110 const int nRequiredLen =
111 m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0);
112 if (nRequiredLen <= 0)
Ryan Harrison275e2602017-09-18 14:23:18 -0400113 return WideString();
dsinclairf34518b2016-09-13 12:03:48 -0700114
Tom Sepez4ad46902017-05-02 13:19:56 -0700115 std::vector<uint8_t> pBuff(nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700116 const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse(
Tom Sepez4ad46902017-05-02 13:19:56 -0700117 m_pInfo->m_pJsPlatform, pBuff.data(), nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700118 if (nActualLen <= 0 || nActualLen > nRequiredLen)
Ryan Harrison275e2602017-09-18 14:23:18 -0400119 return WideString();
dsinclairf34518b2016-09-13 12:03:48 -0700120
Tom Sepez4ad46902017-05-02 13:19:56 -0700121 pBuff.resize(nActualLen);
Ryan Harrison275e2602017-09-18 14:23:18 -0400122 return WideString::FromLocal(ByteStringView(pBuff));
dsinclairf34518b2016-09-13 12:03:48 -0700123}
124
Ryan Harrison275e2602017-09-18 14:23:18 -0400125WideString CPDFSDK_FormFillEnvironment::JS_docGetFilePath() {
dsinclairf34518b2016-09-13 12:03:48 -0700126 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
127 !m_pInfo->m_pJsPlatform->Doc_getFilePath) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400128 return WideString();
dsinclairf34518b2016-09-13 12:03:48 -0700129 }
130 const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(
131 m_pInfo->m_pJsPlatform, nullptr, 0);
132 if (nRequiredLen <= 0)
Ryan Harrison275e2602017-09-18 14:23:18 -0400133 return WideString();
dsinclairf34518b2016-09-13 12:03:48 -0700134
Tom Sepez4ad46902017-05-02 13:19:56 -0700135 std::vector<uint8_t> pBuff(nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700136 const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(
Tom Sepez4ad46902017-05-02 13:19:56 -0700137 m_pInfo->m_pJsPlatform, pBuff.data(), nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700138 if (nActualLen <= 0 || nActualLen > nRequiredLen)
Ryan Harrison275e2602017-09-18 14:23:18 -0400139 return WideString();
dsinclairf34518b2016-09-13 12:03:48 -0700140
Tom Sepez4ad46902017-05-02 13:19:56 -0700141 pBuff.resize(nActualLen);
Ryan Harrison275e2602017-09-18 14:23:18 -0400142 return WideString::FromLocal(ByteStringView(pBuff));
dsinclairf34518b2016-09-13 12:03:48 -0700143}
144
dsinclair735606d2016-10-05 15:47:02 -0700145void CPDFSDK_FormFillEnvironment::JS_docSubmitForm(void* formData,
146 int length,
Dan Sinclair812e96c2017-03-13 16:43:37 -0400147 const wchar_t* URL) {
dsinclairf34518b2016-09-13 12:03:48 -0700148 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
149 !m_pInfo->m_pJsPlatform->Doc_submitForm) {
150 return;
151 }
Ryan Harrison275e2602017-09-18 14:23:18 -0400152 ByteString bsDestination = WideString(URL).UTF16LE_Encode();
dsinclairf34518b2016-09-13 12:03:48 -0700153 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData,
154 length,
155 AsFPDFWideString(&bsDestination));
156}
157
dsinclair735606d2016-10-05 15:47:02 -0700158void CPDFSDK_FormFillEnvironment::JS_docmailForm(void* mailData,
159 int length,
160 FPDF_BOOL bUI,
Dan Sinclair812e96c2017-03-13 16:43:37 -0400161 const wchar_t* To,
162 const wchar_t* Subject,
163 const wchar_t* CC,
164 const wchar_t* BCC,
165 const wchar_t* Msg) {
dsinclairf34518b2016-09-13 12:03:48 -0700166 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
167 !m_pInfo->m_pJsPlatform->Doc_mail) {
168 return;
169 }
Ryan Harrison275e2602017-09-18 14:23:18 -0400170 ByteString bsTo = WideString(To).UTF16LE_Encode();
171 ByteString bsSubject = WideString(Subject).UTF16LE_Encode();
172 ByteString bsCC = WideString(CC).UTF16LE_Encode();
173 ByteString bsBcc = WideString(BCC).UTF16LE_Encode();
174 ByteString bsMsg = WideString(Msg).UTF16LE_Encode();
dsinclairf34518b2016-09-13 12:03:48 -0700175 m_pInfo->m_pJsPlatform->Doc_mail(
176 m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo),
177 AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC),
178 AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg));
179}
180
dsinclair735606d2016-10-05 15:47:02 -0700181void CPDFSDK_FormFillEnvironment::JS_docprint(FPDF_BOOL bUI,
182 int nStart,
183 int nEnd,
184 FPDF_BOOL bSilent,
185 FPDF_BOOL bShrinkToFit,
186 FPDF_BOOL bPrintAsImage,
187 FPDF_BOOL bReverse,
188 FPDF_BOOL bAnnotations) {
dsinclairf34518b2016-09-13 12:03:48 -0700189 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
190 !m_pInfo->m_pJsPlatform->Doc_print) {
191 return;
192 }
193 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd,
194 bSilent, bShrinkToFit, bPrintAsImage,
195 bReverse, bAnnotations);
196}
197
dsinclair735606d2016-10-05 15:47:02 -0700198void CPDFSDK_FormFillEnvironment::JS_docgotoPage(int nPageNum) {
dsinclairf34518b2016-09-13 12:03:48 -0700199 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
200 !m_pInfo->m_pJsPlatform->Doc_gotoPage) {
201 return;
202 }
203 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
204}
205
Tom Sepezf5ca90c2018-02-01 02:15:44 +0000206IJS_Runtime* CPDFSDK_FormFillEnvironment::GetIJSRuntime() {
207 if (!IsJSPlatformPresent())
dsinclairf34518b2016-09-13 12:03:48 -0700208 return nullptr;
Tom Sepezf5ca90c2018-02-01 02:15:44 +0000209 if (!m_pIJSRuntime)
210 m_pIJSRuntime = IJS_Runtime::Create(this);
211 return m_pIJSRuntime.get();
dsinclairf34518b2016-09-13 12:03:48 -0700212}
213
dsinclair735606d2016-10-05 15:47:02 -0700214CPDFSDK_AnnotHandlerMgr* CPDFSDK_FormFillEnvironment::GetAnnotHandlerMgr() {
dsinclairf34518b2016-09-13 12:03:48 -0700215 if (!m_pAnnotHandlerMgr)
tsepez36eb4bd2016-10-03 15:24:27 -0700216 m_pAnnotHandlerMgr = pdfium::MakeUnique<CPDFSDK_AnnotHandlerMgr>(this);
dsinclairf34518b2016-09-13 12:03:48 -0700217 return m_pAnnotHandlerMgr.get();
218}
219
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700220CPDFSDK_ActionHandler* CPDFSDK_FormFillEnvironment::GetActionHandler() {
dsinclairf34518b2016-09-13 12:03:48 -0700221 if (!m_pActionHandler)
tsepez36eb4bd2016-10-03 15:24:27 -0700222 m_pActionHandler = pdfium::MakeUnique<CPDFSDK_ActionHandler>();
dsinclairf34518b2016-09-13 12:03:48 -0700223 return m_pActionHandler.get();
224}
225
dsinclair735606d2016-10-05 15:47:02 -0700226CFFL_InteractiveFormFiller*
227CPDFSDK_FormFillEnvironment::GetInteractiveFormFiller() {
dsinclairb94d7c92016-09-21 12:07:00 -0700228 if (!m_pFormFiller)
tsepez36eb4bd2016-10-03 15:24:27 -0700229 m_pFormFiller = pdfium::MakeUnique<CFFL_InteractiveFormFiller>(this);
dsinclairb94d7c92016-09-21 12:07:00 -0700230 return m_pFormFiller.get();
dsinclairf34518b2016-09-13 12:03:48 -0700231}
dsinclair577ad2c2016-09-22 10:20:43 -0700232
Lei Zhang671630e2017-05-19 19:25:16 -0700233void CPDFSDK_FormFillEnvironment::Invalidate(UnderlyingPageType* page,
Dan Sinclair6eec1c42017-02-21 17:20:43 -0500234 const FX_RECT& rect) {
235 if (m_pInfo && m_pInfo->FFI_Invalidate) {
236 m_pInfo->FFI_Invalidate(m_pInfo, page, rect.left, rect.top, rect.right,
237 rect.bottom);
238 }
dsinclair735606d2016-10-05 15:47:02 -0700239}
240
Dan Sinclair60fd9fc2017-02-21 17:21:08 -0500241void CPDFSDK_FormFillEnvironment::OutputSelectedRect(
Lei Zhang671630e2017-05-19 19:25:16 -0700242 UnderlyingPageType* page,
Dan Sinclair60fd9fc2017-02-21 17:21:08 -0500243 const CFX_FloatRect& rect) {
244 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) {
245 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, rect.left, rect.top,
246 rect.right, rect.bottom);
247 }
dsinclair577ad2c2016-09-22 10:20:43 -0700248}
249
dsinclair735606d2016-10-05 15:47:02 -0700250void CPDFSDK_FormFillEnvironment::SetCursor(int nCursorType) {
dsinclair577ad2c2016-09-22 10:20:43 -0700251 if (m_pInfo && m_pInfo->FFI_SetCursor)
252 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
253}
254
dsinclair735606d2016-10-05 15:47:02 -0700255int CPDFSDK_FormFillEnvironment::SetTimer(int uElapse,
256 TimerCallback lpTimerFunc) {
dsinclair577ad2c2016-09-22 10:20:43 -0700257 if (m_pInfo && m_pInfo->FFI_SetTimer)
258 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
259 return -1;
260}
261
dsinclair735606d2016-10-05 15:47:02 -0700262void CPDFSDK_FormFillEnvironment::KillTimer(int nTimerID) {
dsinclair577ad2c2016-09-22 10:20:43 -0700263 if (m_pInfo && m_pInfo->FFI_KillTimer)
264 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
265}
266
dsinclair735606d2016-10-05 15:47:02 -0700267FX_SYSTEMTIME CPDFSDK_FormFillEnvironment::GetLocalTime() const {
dsinclair577ad2c2016-09-22 10:20:43 -0700268 FX_SYSTEMTIME fxtime;
269 if (!m_pInfo || !m_pInfo->FFI_GetLocalTime)
270 return fxtime;
271
272 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
273 fxtime.wDay = systime.wDay;
274 fxtime.wDayOfWeek = systime.wDayOfWeek;
275 fxtime.wHour = systime.wHour;
276 fxtime.wMilliseconds = systime.wMilliseconds;
277 fxtime.wMinute = systime.wMinute;
278 fxtime.wMonth = systime.wMonth;
279 fxtime.wSecond = systime.wSecond;
280 fxtime.wYear = systime.wYear;
281 return fxtime;
282}
283
dsinclair735606d2016-10-05 15:47:02 -0700284void CPDFSDK_FormFillEnvironment::OnChange() {
dsinclair577ad2c2016-09-22 10:20:43 -0700285 if (m_pInfo && m_pInfo->FFI_OnChange)
286 m_pInfo->FFI_OnChange(m_pInfo);
287}
288
Lei Zhang671630e2017-05-19 19:25:16 -0700289FPDF_PAGE CPDFSDK_FormFillEnvironment::GetCurrentPage(
290 UnderlyingDocumentType* document) {
dsinclair577ad2c2016-09-22 10:20:43 -0700291 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
292 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
293 return nullptr;
294}
295
Dan Sinclair812e96c2017-03-13 16:43:37 -0400296void CPDFSDK_FormFillEnvironment::ExecuteNamedAction(const char* namedAction) {
dsinclair577ad2c2016-09-22 10:20:43 -0700297 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
298 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
299}
300
dsinclair735606d2016-10-05 15:47:02 -0700301void CPDFSDK_FormFillEnvironment::OnSetFieldInputFocus(
302 FPDF_WIDESTRING focusText,
303 FPDF_DWORD nTextLen,
tsepez4cf55152016-11-02 14:37:54 -0700304 bool bFocus) {
dsinclair577ad2c2016-09-22 10:20:43 -0700305 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
306 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
307}
308
Dan Sinclair812e96c2017-03-13 16:43:37 -0400309void CPDFSDK_FormFillEnvironment::DoURIAction(const char* bsURI) {
dsinclair577ad2c2016-09-22 10:20:43 -0700310 if (m_pInfo && m_pInfo->FFI_DoURIAction)
311 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
312}
313
dsinclair735606d2016-10-05 15:47:02 -0700314void CPDFSDK_FormFillEnvironment::DoGoToAction(int nPageIndex,
315 int zoomMode,
316 float* fPosArray,
317 int sizeOfArray) {
dsinclair577ad2c2016-09-22 10:20:43 -0700318 if (m_pInfo && m_pInfo->FFI_DoGoToAction) {
319 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
320 sizeOfArray);
321 }
322}
323
324#ifdef PDF_ENABLE_XFA
Lei Zhang671630e2017-05-19 19:25:16 -0700325void CPDFSDK_FormFillEnvironment::DisplayCaret(CPDFXFA_Page* page,
dsinclair735606d2016-10-05 15:47:02 -0700326 FPDF_BOOL bVisible,
327 double left,
328 double top,
329 double right,
330 double bottom) {
dsinclair577ad2c2016-09-22 10:20:43 -0700331 if (m_pInfo && m_pInfo->FFI_DisplayCaret) {
332 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
333 bottom);
334 }
335}
336
Lei Zhang671630e2017-05-19 19:25:16 -0700337int CPDFSDK_FormFillEnvironment::GetCurrentPageIndex(
338 CPDFXFA_Context* document) {
dsinclair577ad2c2016-09-22 10:20:43 -0700339 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex)
340 return -1;
341 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
342}
343
Lei Zhang671630e2017-05-19 19:25:16 -0700344void CPDFSDK_FormFillEnvironment::SetCurrentPage(CPDFXFA_Context* document,
dsinclair735606d2016-10-05 15:47:02 -0700345 int iCurPage) {
dsinclair577ad2c2016-09-22 10:20:43 -0700346 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
347 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
348}
349
Ryan Harrison275e2602017-09-18 14:23:18 -0400350WideString CPDFSDK_FormFillEnvironment::GetPlatform() {
dsinclair577ad2c2016-09-22 10:20:43 -0700351 if (!m_pInfo || !m_pInfo->FFI_GetPlatform)
Ryan Harrison275e2602017-09-18 14:23:18 -0400352 return WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700353
354 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
355 if (nRequiredLen <= 0)
Ryan Harrison275e2602017-09-18 14:23:18 -0400356 return WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700357
Tom Sepez4ad46902017-05-02 13:19:56 -0700358 std::vector<uint8_t> pBuff(nRequiredLen);
359 int nActualLen =
360 m_pInfo->FFI_GetPlatform(m_pInfo, pBuff.data(), nRequiredLen);
361 if (nActualLen <= 0 || nActualLen > nRequiredLen)
Ryan Harrison275e2602017-09-18 14:23:18 -0400362 return WideString();
Tom Sepez4ad46902017-05-02 13:19:56 -0700363
Ryan Harrison275e2602017-09-18 14:23:18 -0400364 return WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
365 nActualLen / sizeof(uint16_t));
dsinclair577ad2c2016-09-22 10:20:43 -0700366}
367
Lei Zhang671630e2017-05-19 19:25:16 -0700368void CPDFSDK_FormFillEnvironment::GotoURL(CPDFXFA_Context* document,
Ryan Harrison275e2602017-09-18 14:23:18 -0400369 const WideStringView& wsURL) {
dsinclair577ad2c2016-09-22 10:20:43 -0700370 if (!m_pInfo || !m_pInfo->FFI_GotoURL)
371 return;
372
Ryan Harrison275e2602017-09-18 14:23:18 -0400373 ByteString bsTo = WideString(wsURL).UTF16LE_Encode();
Tom Sepez1e934f62018-04-11 21:11:28 +0000374 m_pInfo->FFI_GotoURL(m_pInfo, document, AsFPDFWideString(&bsTo));
dsinclair577ad2c2016-09-22 10:20:43 -0700375}
376
Lei Zhang671630e2017-05-19 19:25:16 -0700377void CPDFSDK_FormFillEnvironment::GetPageViewRect(CPDFXFA_Page* page,
dsinclair735606d2016-10-05 15:47:02 -0700378 FS_RECTF& dstRect) {
dsinclair577ad2c2016-09-22 10:20:43 -0700379 if (!m_pInfo || !m_pInfo->FFI_GetPageViewRect)
380 return;
381
382 double left;
383 double top;
384 double right;
385 double bottom;
386 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
387
388 dstRect.left = static_cast<float>(left);
Lei Zhang222e1a42017-06-20 14:47:00 -0700389 dstRect.top = static_cast<float>(top);
390 dstRect.bottom = static_cast<float>(bottom);
dsinclair577ad2c2016-09-22 10:20:43 -0700391 dstRect.right = static_cast<float>(right);
392}
393
Lei Zhang671630e2017-05-19 19:25:16 -0700394bool CPDFSDK_FormFillEnvironment::PopupMenu(CPDFXFA_Page* page,
tsepez4cf55152016-11-02 14:37:54 -0700395 FPDF_WIDGET hWidget,
396 int menuFlag,
397 CFX_PointF pt) {
tsepezdc0401a2016-10-28 13:10:35 -0700398 return m_pInfo && m_pInfo->FFI_PopupMenu &&
399 m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, pt.x, pt.y);
dsinclair577ad2c2016-09-22 10:20:43 -0700400}
401
dsinclair735606d2016-10-05 15:47:02 -0700402void CPDFSDK_FormFillEnvironment::Alert(FPDF_WIDESTRING Msg,
403 FPDF_WIDESTRING Title,
404 int Type,
405 int Icon) {
dsinclair577ad2c2016-09-22 10:20:43 -0700406 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) {
407 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type,
408 Icon);
409 }
410}
411
dsinclair735606d2016-10-05 15:47:02 -0700412void CPDFSDK_FormFillEnvironment::EmailTo(FPDF_FILEHANDLER* fileHandler,
413 FPDF_WIDESTRING pTo,
414 FPDF_WIDESTRING pSubject,
415 FPDF_WIDESTRING pCC,
416 FPDF_WIDESTRING pBcc,
417 FPDF_WIDESTRING pMsg) {
dsinclair577ad2c2016-09-22 10:20:43 -0700418 if (m_pInfo && m_pInfo->FFI_EmailTo)
419 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg);
420}
421
dsinclair735606d2016-10-05 15:47:02 -0700422void CPDFSDK_FormFillEnvironment::UploadTo(FPDF_FILEHANDLER* fileHandler,
423 int fileFlag,
424 FPDF_WIDESTRING uploadTo) {
dsinclair577ad2c2016-09-22 10:20:43 -0700425 if (m_pInfo && m_pInfo->FFI_UploadTo)
426 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
427}
428
dsinclair735606d2016-10-05 15:47:02 -0700429FPDF_FILEHANDLER* CPDFSDK_FormFillEnvironment::OpenFile(int fileType,
430 FPDF_WIDESTRING wsURL,
431 const char* mode) {
dsinclair577ad2c2016-09-22 10:20:43 -0700432 if (m_pInfo && m_pInfo->FFI_OpenFile)
433 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
434 return nullptr;
435}
436
Dan Sinclair0b950422017-09-21 15:49:49 -0400437RetainPtr<IFX_SeekableReadStream> CPDFSDK_FormFillEnvironment::DownloadFromURL(
438 const wchar_t* url) {
dsinclair577ad2c2016-09-22 10:20:43 -0700439 if (!m_pInfo || !m_pInfo->FFI_DownloadFromURL)
440 return nullptr;
441
Ryan Harrison275e2602017-09-18 14:23:18 -0400442 ByteString bstrURL = WideString(url).UTF16LE_Encode();
Tom Sepez1e934f62018-04-11 21:11:28 +0000443 FPDF_LPFILEHANDLER fileHandler =
444 m_pInfo->FFI_DownloadFromURL(m_pInfo, AsFPDFWideString(&bstrURL));
dsinclair577ad2c2016-09-22 10:20:43 -0700445
tsepezfa89a202016-12-02 09:48:30 -0800446 return MakeSeekableStream(fileHandler);
dsinclair577ad2c2016-09-22 10:20:43 -0700447}
448
Ryan Harrison275e2602017-09-18 14:23:18 -0400449WideString CPDFSDK_FormFillEnvironment::PostRequestURL(
Dan Sinclair812e96c2017-03-13 16:43:37 -0400450 const wchar_t* wsURL,
451 const wchar_t* wsData,
452 const wchar_t* wsContentType,
453 const wchar_t* wsEncode,
454 const wchar_t* wsHeader) {
dsinclair577ad2c2016-09-22 10:20:43 -0700455 if (!m_pInfo || !m_pInfo->FFI_PostRequestURL)
456 return L"";
457
Ryan Harrison275e2602017-09-18 14:23:18 -0400458 ByteString bsURL = WideString(wsURL).UTF16LE_Encode();
Ryan Harrison275e2602017-09-18 14:23:18 -0400459 ByteString bsData = WideString(wsData).UTF16LE_Encode();
Ryan Harrison275e2602017-09-18 14:23:18 -0400460 ByteString bsContentType = WideString(wsContentType).UTF16LE_Encode();
Ryan Harrison275e2602017-09-18 14:23:18 -0400461 ByteString bsEncode = WideString(wsEncode).UTF16LE_Encode();
Ryan Harrison275e2602017-09-18 14:23:18 -0400462 ByteString bsHeader = WideString(wsHeader).UTF16LE_Encode();
dsinclair577ad2c2016-09-22 10:20:43 -0700463
464 FPDF_BSTR response;
465 FPDF_BStr_Init(&response);
Tom Sepez1e934f62018-04-11 21:11:28 +0000466 m_pInfo->FFI_PostRequestURL(
467 m_pInfo, AsFPDFWideString(&bsURL), AsFPDFWideString(&bsData),
468 AsFPDFWideString(&bsContentType), AsFPDFWideString(&bsEncode),
469 AsFPDFWideString(&bsHeader), &response);
dsinclair577ad2c2016-09-22 10:20:43 -0700470
Tom Sepez1e934f62018-04-11 21:11:28 +0000471 WideString wsRet =
472 WideString::FromUTF16LE(reinterpret_cast<FPDF_WIDESTRING>(response.str),
473 response.len / sizeof(FPDF_WIDESTRING));
474
dsinclair577ad2c2016-09-22 10:20:43 -0700475 FPDF_BStr_Clear(&response);
dsinclair577ad2c2016-09-22 10:20:43 -0700476 return wsRet;
477}
478
Dan Sinclair812e96c2017-03-13 16:43:37 -0400479FPDF_BOOL CPDFSDK_FormFillEnvironment::PutRequestURL(const wchar_t* wsURL,
480 const wchar_t* wsData,
481 const wchar_t* wsEncode) {
dsinclair577ad2c2016-09-22 10:20:43 -0700482 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL)
tsepez4cf55152016-11-02 14:37:54 -0700483 return false;
dsinclair577ad2c2016-09-22 10:20:43 -0700484
Ryan Harrison275e2602017-09-18 14:23:18 -0400485 ByteString bsURL = WideString(wsURL).UTF16LE_Encode();
Ryan Harrison275e2602017-09-18 14:23:18 -0400486 ByteString bsData = WideString(wsData).UTF16LE_Encode();
Ryan Harrison275e2602017-09-18 14:23:18 -0400487 ByteString bsEncode = WideString(wsEncode).UTF16LE_Encode();
dsinclair577ad2c2016-09-22 10:20:43 -0700488
Tom Sepez1e934f62018-04-11 21:11:28 +0000489 return m_pInfo->FFI_PutRequestURL(m_pInfo, AsFPDFWideString(&bsURL),
490 AsFPDFWideString(&bsData),
491 AsFPDFWideString(&bsEncode));
dsinclair577ad2c2016-09-22 10:20:43 -0700492}
493
Ryan Harrison275e2602017-09-18 14:23:18 -0400494WideString CPDFSDK_FormFillEnvironment::GetLanguage() {
dsinclair577ad2c2016-09-22 10:20:43 -0700495 if (!m_pInfo || !m_pInfo->FFI_GetLanguage)
Ryan Harrison275e2602017-09-18 14:23:18 -0400496 return WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700497
498 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
499 if (nRequiredLen <= 0)
Ryan Harrison275e2602017-09-18 14:23:18 -0400500 return WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700501
Tom Sepez4ad46902017-05-02 13:19:56 -0700502 std::vector<uint8_t> pBuff(nRequiredLen);
503 int nActualLen =
504 m_pInfo->FFI_GetLanguage(m_pInfo, pBuff.data(), nRequiredLen);
505 if (nActualLen <= 0 || nActualLen > nRequiredLen)
Ryan Harrison275e2602017-09-18 14:23:18 -0400506 return WideString();
Tom Sepez4ad46902017-05-02 13:19:56 -0700507
Ryan Harrison275e2602017-09-18 14:23:18 -0400508 return WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
509 nActualLen / sizeof(uint16_t));
dsinclair577ad2c2016-09-22 10:20:43 -0700510}
511
dsinclair735606d2016-10-05 15:47:02 -0700512void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount,
513 uint32_t dwEventType) const {
dsinclair577ad2c2016-09-22 10:20:43 -0700514 if (m_pInfo && m_pInfo->FFI_PageEvent)
515 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
516}
517#endif // PDF_ENABLE_XFA
dsinclair7cbe68e2016-10-12 11:56:23 -0700518
519void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() {
tsepez2599ff72016-11-08 14:38:59 -0800520 for (auto& it : m_PageMap) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700521 if (it.second->IsValidSDKAnnot(GetFocusAnnot()))
522 KillFocusAnnot(0);
523 }
524}
525
526CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(
527 UnderlyingPageType* pUnderlyingPage,
dsinclair6c659ab2016-10-12 13:41:38 -0700528 bool renew) {
tsepez2599ff72016-11-08 14:38:59 -0800529 auto it = m_PageMap.find(pUnderlyingPage);
530 if (it != m_PageMap.end())
dsinclair6c659ab2016-10-12 13:41:38 -0700531 return it->second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700532
dsinclair6c659ab2016-10-12 13:41:38 -0700533 if (!renew)
dsinclair7cbe68e2016-10-12 11:56:23 -0700534 return nullptr;
535
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700536 auto pNew = pdfium::MakeUnique<CPDFSDK_PageView>(this, pUnderlyingPage);
537 CPDFSDK_PageView* pPageView = pNew.get();
538 m_PageMap[pUnderlyingPage] = std::move(pNew);
539
dsinclair7cbe68e2016-10-12 11:56:23 -0700540 // Delay to load all the annotations, to avoid endless loop.
541 pPageView->LoadFXAnnots();
542 return pPageView;
543}
544
545CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() {
546 UnderlyingPageType* pPage =
Tom Sepez940967d2017-05-18 12:32:20 -0700547 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc.Get()));
dsinclair7cbe68e2016-10-12 11:56:23 -0700548 return pPage ? GetPageView(pPage, true) : nullptr;
549}
550
551CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700552 UnderlyingPageType* pTempPage = GetPage(nIndex);
dsinclair7cbe68e2016-10-12 11:56:23 -0700553 if (!pTempPage)
554 return nullptr;
555
tsepez2599ff72016-11-08 14:38:59 -0800556 auto it = m_PageMap.find(pTempPage);
557 return it != m_PageMap.end() ? it->second.get() : nullptr;
dsinclair7cbe68e2016-10-12 11:56:23 -0700558}
559
560void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() {
561 CPDF_Document* pPDFDoc = GetPDFDocument();
562 CPDF_DocJSActions docJS(pPDFDoc);
563 int iCount = docJS.CountJSActions();
dsinclair7cbe68e2016-10-12 11:56:23 -0700564 for (int i = 0; i < iCount; i++) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400565 WideString csJSName;
Tom Sepezc4a2b752017-04-07 13:56:13 -0700566 CPDF_Action jsAction = docJS.GetJSActionAndName(i, &csJSName);
Jane Liu67ccef72017-07-19 13:10:50 -0400567 GetActionHandler()->DoAction_JavaScript(jsAction, csJSName, this);
dsinclair7cbe68e2016-10-12 11:56:23 -0700568 }
569}
570
tsepez4cf55152016-11-02 14:37:54 -0700571bool CPDFSDK_FormFillEnvironment::ProcOpenAction() {
dsinclair7cbe68e2016-10-12 11:56:23 -0700572 if (!m_pUnderlyingDoc)
tsepez4cf55152016-11-02 14:37:54 -0700573 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700574
Lei Zhang01581062017-08-30 14:19:26 -0700575 const CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot();
dsinclair7cbe68e2016-10-12 11:56:23 -0700576 if (!pRoot)
tsepez4cf55152016-11-02 14:37:54 -0700577 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700578
579 CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction");
580 if (!pOpenAction)
581 pOpenAction = pRoot->GetArrayFor("OpenAction");
dsinclair7cbe68e2016-10-12 11:56:23 -0700582 if (!pOpenAction)
tsepez4cf55152016-11-02 14:37:54 -0700583 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700584
585 if (pOpenAction->IsArray())
tsepez4cf55152016-11-02 14:37:54 -0700586 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700587
Lei Zhang222e1a42017-06-20 14:47:00 -0700588 CPDF_Dictionary* pDict = pOpenAction->AsDictionary();
589 if (!pDict)
590 return false;
591
592 CPDF_Action action(pDict);
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700593 GetActionHandler()->DoAction_DocOpen(action, this);
Lei Zhang222e1a42017-06-20 14:47:00 -0700594 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700595}
596
597void CPDFSDK_FormFillEnvironment::RemovePageView(
598 UnderlyingPageType* pUnderlyingPage) {
tsepez2599ff72016-11-08 14:38:59 -0800599 auto it = m_PageMap.find(pUnderlyingPage);
600 if (it == m_PageMap.end())
dsinclair7cbe68e2016-10-12 11:56:23 -0700601 return;
602
dsinclair6c659ab2016-10-12 13:41:38 -0700603 CPDFSDK_PageView* pPageView = it->second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700604 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed())
605 return;
606
607 // Mark the page view so we do not come into |RemovePageView| a second
608 // time while we're in the process of removing.
609 pPageView->SetBeingDestroyed();
610
611 // This must happen before we remove |pPageView| from the map because
612 // |KillFocusAnnot| can call into the |GetPage| method which will
613 // look for this page view in the map, if it doesn't find it a new one will
614 // be created. We then have two page views pointing to the same page and
615 // bad things happen.
616 if (pPageView->IsValidSDKAnnot(GetFocusAnnot()))
617 KillFocusAnnot(0);
618
619 // Remove the page from the map to make sure we don't accidentally attempt
620 // to use the |pPageView| while we're cleaning it up.
tsepez2599ff72016-11-08 14:38:59 -0800621 m_PageMap.erase(it);
dsinclair7cbe68e2016-10-12 11:56:23 -0700622}
623
624UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700625 if (!m_pInfo || !m_pInfo->FFI_GetPage)
626 return nullptr;
627 return UnderlyingFromFPDFPage(
628 m_pInfo->FFI_GetPage(m_pInfo, m_pUnderlyingDoc.Get(), nIndex));
dsinclair7cbe68e2016-10-12 11:56:23 -0700629}
630
631CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() {
632 if (!m_pInterForm)
633 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this);
634 return m_pInterForm.get();
635}
636
637void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender,
638 CPDFSDK_Annot* pAnnot) {
tsepez2599ff72016-11-08 14:38:59 -0800639 for (const auto& it : m_PageMap) {
dsinclair6c659ab2016-10-12 13:41:38 -0700640 CPDFSDK_PageView* pPageView = it.second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700641 if (pPageView != pSender)
642 pPageView->UpdateView(pAnnot);
643 }
644}
645
tsepez4cf55152016-11-02 14:37:54 -0700646bool CPDFSDK_FormFillEnvironment::SetFocusAnnot(
dsinclair7cbe68e2016-10-12 11:56:23 -0700647 CPDFSDK_Annot::ObservedPtr* pAnnot) {
648 if (m_bBeingDestroyed)
tsepez4cf55152016-11-02 14:37:54 -0700649 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700650 if (m_pFocusAnnot == *pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700651 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700652 if (m_pFocusAnnot && !KillFocusAnnot(0))
tsepez4cf55152016-11-02 14:37:54 -0700653 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700654 if (!*pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700655 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700656
Lei Zhang222e1a42017-06-20 14:47:00 -0700657 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView();
658 if (!pPageView || !pPageView->IsValid())
659 return false;
660
661 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
662 if (m_pFocusAnnot)
663 return false;
664
dsinclair7cbe68e2016-10-12 11:56:23 -0700665#ifdef PDF_ENABLE_XFA
666 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get());
Lei Zhang222e1a42017-06-20 14:47:00 -0700667 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot))
668 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700669#endif // PDF_ENABLE_XFA
Lei Zhang222e1a42017-06-20 14:47:00 -0700670 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0))
671 return false;
672 if (m_pFocusAnnot)
673 return false;
674
675 m_pFocusAnnot.Reset(pAnnot->Get());
676 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700677}
678
tsepez4cf55152016-11-02 14:37:54 -0700679bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) {
Lei Zhang222e1a42017-06-20 14:47:00 -0700680 if (!m_pFocusAnnot)
681 return false;
682
683 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
684 CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get());
685 m_pFocusAnnot.Reset();
dsinclair7cbe68e2016-10-12 11:56:23 -0700686
687#ifdef PDF_ENABLE_XFA
Lei Zhang222e1a42017-06-20 14:47:00 -0700688 CPDFSDK_Annot::ObservedPtr pNull;
689 if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot))
690 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700691#endif // PDF_ENABLE_XFA
692
Lei Zhang222e1a42017-06-20 14:47:00 -0700693 if (!pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) {
694 m_pFocusAnnot.Reset(pFocusAnnot.Get());
695 return false;
696 }
697
698 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) {
699 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get());
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000700 FormFieldType fieldType = pWidget->GetFieldType();
701 if (fieldType == FormFieldType::kTextField ||
702 fieldType == FormFieldType::kComboBox) {
Lei Zhang222e1a42017-06-20 14:47:00 -0700703 OnSetFieldInputFocus(nullptr, 0, false);
dsinclair7cbe68e2016-10-12 11:56:23 -0700704 }
705 }
Lei Zhang222e1a42017-06-20 14:47:00 -0700706 return !m_pFocusAnnot;
dsinclair7cbe68e2016-10-12 11:56:23 -0700707}
708
Lei Zhangad0982a2017-06-16 19:30:38 -0700709bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) const {
tsepez95e58342016-10-28 11:34:42 -0700710 return !!(GetPDFDocument()->GetUserPermissions() & nFlag);
dsinclair7cbe68e2016-10-12 11:56:23 -0700711}