blob: b0ee903ead1e79aaab23dcfcc0b7263917c79125 [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"
dsinclair114e46a2016-09-29 17:18:21 -070014#include "fpdfsdk/cpdfsdk_annothandlermgr.h"
dsinclair7cbe68e2016-10-12 11:56:23 -070015#include "fpdfsdk/cpdfsdk_interform.h"
16#include "fpdfsdk/cpdfsdk_pageview.h"
17#include "fpdfsdk/cpdfsdk_widget.h"
dsinclairb94d7c92016-09-21 12:07:00 -070018#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/fsdk_actionhandler.h"
dsinclairf34518b2016-09-13 12:03:48 -070020#include "fpdfsdk/javascript/ijs_runtime.h"
tsepez36eb4bd2016-10-03 15:24:27 -070021#include "third_party/base/ptr_util.h"
dsinclairf34518b2016-09-13 12:03:48 -070022
dsinclairf34518b2016-09-13 12:03:48 -070023namespace {
24
25// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken
26// since modifying the result would impact |bsUTF16LE|.
27FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) {
28 return reinterpret_cast<FPDF_WIDESTRING>(
29 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength()));
30}
31
32} // namespace
33
dsinclair735606d2016-10-05 15:47:02 -070034CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment(
35 UnderlyingDocumentType* pDoc,
36 FPDF_FORMFILLINFO* pFFinfo)
dsinclaira939bfe2016-09-22 13:18:45 -070037 : m_pInfo(pFFinfo),
dsinclaira939bfe2016-09-22 13:18:45 -070038 m_pUnderlyingDoc(pDoc),
Dan Sinclair0bb13332017-03-30 16:12:02 -040039 m_pSysHandler(pdfium::MakeUnique<CFX_SystemHandler>(this)),
dsinclair6c659ab2016-10-12 13:41:38 -070040 m_bChangeMask(false),
41 m_bBeingDestroyed(false) {}
dsinclairf34518b2016-09-13 12:03:48 -070042
dsinclair735606d2016-10-05 15:47:02 -070043CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() {
dsinclair6c659ab2016-10-12 13:41:38 -070044 m_bBeingDestroyed = true;
dsinclair7cbe68e2016-10-12 11:56:23 -070045 ClearAllFocusedAnnots();
dsinclair7cbe68e2016-10-12 11:56:23 -070046
tsepez2599ff72016-11-08 14:38:59 -080047 // |m_PageMap| will try to access |m_pInterForm| when it cleans itself up.
48 // Make sure it is deleted before |m_pInterForm|.
49 m_PageMap.clear();
50
51 // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| when it cleans
52 // itself up. Make sure it is deleted before |m_pFormFiller|.
dsinclair709f5a92016-10-11 14:21:16 -070053 m_pAnnotHandlerMgr.reset();
54
55 // Must destroy the |m_pFormFiller| before the environment (|this|)
56 // because any created form widgets hold a pointer to the environment.
57 // Those widgets may call things like KillTimer() as they are shutdown.
58 m_pFormFiller.reset();
59
dsinclairf34518b2016-09-13 12:03:48 -070060 if (m_pInfo && m_pInfo->Release)
61 m_pInfo->Release(m_pInfo);
62}
63
Dan Sinclair812e96c2017-03-13 16:43:37 -040064int CPDFSDK_FormFillEnvironment::JS_appAlert(const wchar_t* Msg,
65 const wchar_t* Title,
dsinclair735606d2016-10-05 15:47:02 -070066 uint32_t Type,
67 uint32_t Icon) {
dsinclairf34518b2016-09-13 12:03:48 -070068 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
69 !m_pInfo->m_pJsPlatform->app_alert) {
70 return -1;
71 }
72 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
73 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
74 return m_pInfo->m_pJsPlatform->app_alert(
75 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg),
76 AsFPDFWideString(&bsTitle), Type, Icon);
77}
78
Dan Sinclair812e96c2017-03-13 16:43:37 -040079int CPDFSDK_FormFillEnvironment::JS_appResponse(const wchar_t* Question,
80 const wchar_t* Title,
81 const wchar_t* Default,
82 const wchar_t* cLabel,
dsinclair735606d2016-10-05 15:47:02 -070083 FPDF_BOOL bPassword,
84 void* response,
85 int length) {
dsinclairf34518b2016-09-13 12:03:48 -070086 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
87 !m_pInfo->m_pJsPlatform->app_response) {
88 return -1;
89 }
90 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode();
91 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
92 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode();
93 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode();
94 return m_pInfo->m_pJsPlatform->app_response(
95 m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion),
96 AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault),
97 AsFPDFWideString(&bsLabel), bPassword, response, length);
98}
99
dsinclair735606d2016-10-05 15:47:02 -0700100void CPDFSDK_FormFillEnvironment::JS_appBeep(int nType) {
dsinclairf34518b2016-09-13 12:03:48 -0700101 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
102 !m_pInfo->m_pJsPlatform->app_beep) {
103 return;
104 }
105 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
106}
107
dsinclair735606d2016-10-05 15:47:02 -0700108CFX_WideString CPDFSDK_FormFillEnvironment::JS_fieldBrowse() {
dsinclairf34518b2016-09-13 12:03:48 -0700109 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
110 !m_pInfo->m_pJsPlatform->Field_browse) {
111 return CFX_WideString();
112 }
113 const int nRequiredLen =
114 m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0);
115 if (nRequiredLen <= 0)
116 return CFX_WideString();
117
Tom Sepez4ad46902017-05-02 13:19:56 -0700118 std::vector<uint8_t> pBuff(nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700119 const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse(
Tom Sepez4ad46902017-05-02 13:19:56 -0700120 m_pInfo->m_pJsPlatform, pBuff.data(), nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700121 if (nActualLen <= 0 || nActualLen > nRequiredLen)
122 return CFX_WideString();
123
Tom Sepez4ad46902017-05-02 13:19:56 -0700124 pBuff.resize(nActualLen);
125 return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff));
dsinclairf34518b2016-09-13 12:03:48 -0700126}
127
dsinclair735606d2016-10-05 15:47:02 -0700128CFX_WideString CPDFSDK_FormFillEnvironment::JS_docGetFilePath() {
dsinclairf34518b2016-09-13 12:03:48 -0700129 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
130 !m_pInfo->m_pJsPlatform->Doc_getFilePath) {
131 return CFX_WideString();
132 }
133 const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(
134 m_pInfo->m_pJsPlatform, nullptr, 0);
135 if (nRequiredLen <= 0)
136 return CFX_WideString();
137
Tom Sepez4ad46902017-05-02 13:19:56 -0700138 std::vector<uint8_t> pBuff(nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700139 const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(
Tom Sepez4ad46902017-05-02 13:19:56 -0700140 m_pInfo->m_pJsPlatform, pBuff.data(), nRequiredLen);
dsinclairf34518b2016-09-13 12:03:48 -0700141 if (nActualLen <= 0 || nActualLen > nRequiredLen)
142 return CFX_WideString();
143
Tom Sepez4ad46902017-05-02 13:19:56 -0700144 pBuff.resize(nActualLen);
145 return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff));
dsinclairf34518b2016-09-13 12:03:48 -0700146}
147
dsinclair735606d2016-10-05 15:47:02 -0700148void CPDFSDK_FormFillEnvironment::JS_docSubmitForm(void* formData,
149 int length,
Dan Sinclair812e96c2017-03-13 16:43:37 -0400150 const wchar_t* URL) {
dsinclairf34518b2016-09-13 12:03:48 -0700151 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
152 !m_pInfo->m_pJsPlatform->Doc_submitForm) {
153 return;
154 }
155 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode();
156 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData,
157 length,
158 AsFPDFWideString(&bsDestination));
159}
160
dsinclair735606d2016-10-05 15:47:02 -0700161void CPDFSDK_FormFillEnvironment::JS_docmailForm(void* mailData,
162 int length,
163 FPDF_BOOL bUI,
Dan Sinclair812e96c2017-03-13 16:43:37 -0400164 const wchar_t* To,
165 const wchar_t* Subject,
166 const wchar_t* CC,
167 const wchar_t* BCC,
168 const wchar_t* Msg) {
dsinclairf34518b2016-09-13 12:03:48 -0700169 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
170 !m_pInfo->m_pJsPlatform->Doc_mail) {
171 return;
172 }
173 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode();
174 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode();
175 CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode();
176 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
177 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
178 m_pInfo->m_pJsPlatform->Doc_mail(
179 m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo),
180 AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC),
181 AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg));
182}
183
dsinclair735606d2016-10-05 15:47:02 -0700184void CPDFSDK_FormFillEnvironment::JS_docprint(FPDF_BOOL bUI,
185 int nStart,
186 int nEnd,
187 FPDF_BOOL bSilent,
188 FPDF_BOOL bShrinkToFit,
189 FPDF_BOOL bPrintAsImage,
190 FPDF_BOOL bReverse,
191 FPDF_BOOL bAnnotations) {
dsinclairf34518b2016-09-13 12:03:48 -0700192 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
193 !m_pInfo->m_pJsPlatform->Doc_print) {
194 return;
195 }
196 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd,
197 bSilent, bShrinkToFit, bPrintAsImage,
198 bReverse, bAnnotations);
199}
200
dsinclair735606d2016-10-05 15:47:02 -0700201void CPDFSDK_FormFillEnvironment::JS_docgotoPage(int nPageNum) {
dsinclairf34518b2016-09-13 12:03:48 -0700202 if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
203 !m_pInfo->m_pJsPlatform->Doc_gotoPage) {
204 return;
205 }
206 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
207}
208
dsinclair735606d2016-10-05 15:47:02 -0700209IJS_Runtime* CPDFSDK_FormFillEnvironment::GetJSRuntime() {
dsinclairf34518b2016-09-13 12:03:48 -0700210 if (!IsJSInitiated())
211 return nullptr;
212 if (!m_pJSRuntime)
213 m_pJSRuntime.reset(IJS_Runtime::Create(this));
214 return m_pJSRuntime.get();
215}
216
dsinclair735606d2016-10-05 15:47:02 -0700217CPDFSDK_AnnotHandlerMgr* CPDFSDK_FormFillEnvironment::GetAnnotHandlerMgr() {
dsinclairf34518b2016-09-13 12:03:48 -0700218 if (!m_pAnnotHandlerMgr)
tsepez36eb4bd2016-10-03 15:24:27 -0700219 m_pAnnotHandlerMgr = pdfium::MakeUnique<CPDFSDK_AnnotHandlerMgr>(this);
dsinclairf34518b2016-09-13 12:03:48 -0700220 return m_pAnnotHandlerMgr.get();
221}
222
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700223CPDFSDK_ActionHandler* CPDFSDK_FormFillEnvironment::GetActionHandler() {
dsinclairf34518b2016-09-13 12:03:48 -0700224 if (!m_pActionHandler)
tsepez36eb4bd2016-10-03 15:24:27 -0700225 m_pActionHandler = pdfium::MakeUnique<CPDFSDK_ActionHandler>();
dsinclairf34518b2016-09-13 12:03:48 -0700226 return m_pActionHandler.get();
227}
228
dsinclair735606d2016-10-05 15:47:02 -0700229CFFL_InteractiveFormFiller*
230CPDFSDK_FormFillEnvironment::GetInteractiveFormFiller() {
dsinclairb94d7c92016-09-21 12:07:00 -0700231 if (!m_pFormFiller)
tsepez36eb4bd2016-10-03 15:24:27 -0700232 m_pFormFiller = pdfium::MakeUnique<CFFL_InteractiveFormFiller>(this);
dsinclairb94d7c92016-09-21 12:07:00 -0700233 return m_pFormFiller.get();
dsinclairf34518b2016-09-13 12:03:48 -0700234}
dsinclair577ad2c2016-09-22 10:20:43 -0700235
Lei Zhang671630e2017-05-19 19:25:16 -0700236void CPDFSDK_FormFillEnvironment::Invalidate(UnderlyingPageType* page,
Dan Sinclair6eec1c42017-02-21 17:20:43 -0500237 const FX_RECT& rect) {
238 if (m_pInfo && m_pInfo->FFI_Invalidate) {
239 m_pInfo->FFI_Invalidate(m_pInfo, page, rect.left, rect.top, rect.right,
240 rect.bottom);
241 }
dsinclair735606d2016-10-05 15:47:02 -0700242}
243
Dan Sinclair60fd9fc2017-02-21 17:21:08 -0500244void CPDFSDK_FormFillEnvironment::OutputSelectedRect(
Lei Zhang671630e2017-05-19 19:25:16 -0700245 UnderlyingPageType* page,
Dan Sinclair60fd9fc2017-02-21 17:21:08 -0500246 const CFX_FloatRect& rect) {
247 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) {
248 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, rect.left, rect.top,
249 rect.right, rect.bottom);
250 }
dsinclair577ad2c2016-09-22 10:20:43 -0700251}
252
dsinclair735606d2016-10-05 15:47:02 -0700253void CPDFSDK_FormFillEnvironment::SetCursor(int nCursorType) {
dsinclair577ad2c2016-09-22 10:20:43 -0700254 if (m_pInfo && m_pInfo->FFI_SetCursor)
255 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
256}
257
dsinclair735606d2016-10-05 15:47:02 -0700258int CPDFSDK_FormFillEnvironment::SetTimer(int uElapse,
259 TimerCallback lpTimerFunc) {
dsinclair577ad2c2016-09-22 10:20:43 -0700260 if (m_pInfo && m_pInfo->FFI_SetTimer)
261 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
262 return -1;
263}
264
dsinclair735606d2016-10-05 15:47:02 -0700265void CPDFSDK_FormFillEnvironment::KillTimer(int nTimerID) {
dsinclair577ad2c2016-09-22 10:20:43 -0700266 if (m_pInfo && m_pInfo->FFI_KillTimer)
267 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
268}
269
dsinclair735606d2016-10-05 15:47:02 -0700270FX_SYSTEMTIME CPDFSDK_FormFillEnvironment::GetLocalTime() const {
dsinclair577ad2c2016-09-22 10:20:43 -0700271 FX_SYSTEMTIME fxtime;
272 if (!m_pInfo || !m_pInfo->FFI_GetLocalTime)
273 return fxtime;
274
275 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
276 fxtime.wDay = systime.wDay;
277 fxtime.wDayOfWeek = systime.wDayOfWeek;
278 fxtime.wHour = systime.wHour;
279 fxtime.wMilliseconds = systime.wMilliseconds;
280 fxtime.wMinute = systime.wMinute;
281 fxtime.wMonth = systime.wMonth;
282 fxtime.wSecond = systime.wSecond;
283 fxtime.wYear = systime.wYear;
284 return fxtime;
285}
286
dsinclair735606d2016-10-05 15:47:02 -0700287void CPDFSDK_FormFillEnvironment::OnChange() {
dsinclair577ad2c2016-09-22 10:20:43 -0700288 if (m_pInfo && m_pInfo->FFI_OnChange)
289 m_pInfo->FFI_OnChange(m_pInfo);
290}
291
tsepez4cf55152016-11-02 14:37:54 -0700292bool CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(uint32_t nFlag) const {
dsinclair577ad2c2016-09-22 10:20:43 -0700293 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
294}
295
tsepez4cf55152016-11-02 14:37:54 -0700296bool CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(uint32_t nFlag) const {
dsinclair577ad2c2016-09-22 10:20:43 -0700297 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
298}
299
tsepez4cf55152016-11-02 14:37:54 -0700300bool CPDFSDK_FormFillEnvironment::IsALTKeyDown(uint32_t nFlag) const {
dsinclair577ad2c2016-09-22 10:20:43 -0700301 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
302}
303
Lei Zhang671630e2017-05-19 19:25:16 -0700304FPDF_PAGE CPDFSDK_FormFillEnvironment::GetPage(UnderlyingDocumentType* document,
dsinclair735606d2016-10-05 15:47:02 -0700305 int nPageIndex) {
dsinclair577ad2c2016-09-22 10:20:43 -0700306 if (m_pInfo && m_pInfo->FFI_GetPage)
307 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
308 return nullptr;
309}
310
Lei Zhang671630e2017-05-19 19:25:16 -0700311FPDF_PAGE CPDFSDK_FormFillEnvironment::GetCurrentPage(
312 UnderlyingDocumentType* document) {
dsinclair577ad2c2016-09-22 10:20:43 -0700313 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
314 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
315 return nullptr;
316}
317
Dan Sinclair812e96c2017-03-13 16:43:37 -0400318void CPDFSDK_FormFillEnvironment::ExecuteNamedAction(const char* namedAction) {
dsinclair577ad2c2016-09-22 10:20:43 -0700319 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
320 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
321}
322
dsinclair735606d2016-10-05 15:47:02 -0700323void CPDFSDK_FormFillEnvironment::OnSetFieldInputFocus(
324 FPDF_WIDESTRING focusText,
325 FPDF_DWORD nTextLen,
tsepez4cf55152016-11-02 14:37:54 -0700326 bool bFocus) {
dsinclair577ad2c2016-09-22 10:20:43 -0700327 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
328 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
329}
330
Dan Sinclair812e96c2017-03-13 16:43:37 -0400331void CPDFSDK_FormFillEnvironment::DoURIAction(const char* bsURI) {
dsinclair577ad2c2016-09-22 10:20:43 -0700332 if (m_pInfo && m_pInfo->FFI_DoURIAction)
333 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
334}
335
dsinclair735606d2016-10-05 15:47:02 -0700336void CPDFSDK_FormFillEnvironment::DoGoToAction(int nPageIndex,
337 int zoomMode,
338 float* fPosArray,
339 int sizeOfArray) {
dsinclair577ad2c2016-09-22 10:20:43 -0700340 if (m_pInfo && m_pInfo->FFI_DoGoToAction) {
341 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
342 sizeOfArray);
343 }
344}
345
346#ifdef PDF_ENABLE_XFA
Lei Zhang671630e2017-05-19 19:25:16 -0700347void CPDFSDK_FormFillEnvironment::DisplayCaret(CPDFXFA_Page* page,
dsinclair735606d2016-10-05 15:47:02 -0700348 FPDF_BOOL bVisible,
349 double left,
350 double top,
351 double right,
352 double bottom) {
dsinclair577ad2c2016-09-22 10:20:43 -0700353 if (m_pInfo && m_pInfo->FFI_DisplayCaret) {
354 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
355 bottom);
356 }
357}
358
Lei Zhang671630e2017-05-19 19:25:16 -0700359int CPDFSDK_FormFillEnvironment::GetCurrentPageIndex(
360 CPDFXFA_Context* document) {
dsinclair577ad2c2016-09-22 10:20:43 -0700361 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex)
362 return -1;
363 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
364}
365
Lei Zhang671630e2017-05-19 19:25:16 -0700366void CPDFSDK_FormFillEnvironment::SetCurrentPage(CPDFXFA_Context* document,
dsinclair735606d2016-10-05 15:47:02 -0700367 int iCurPage) {
dsinclair577ad2c2016-09-22 10:20:43 -0700368 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
369 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
370}
371
dsinclair735606d2016-10-05 15:47:02 -0700372CFX_WideString CPDFSDK_FormFillEnvironment::GetPlatform() {
dsinclair577ad2c2016-09-22 10:20:43 -0700373 if (!m_pInfo || !m_pInfo->FFI_GetPlatform)
Tom Sepez4ad46902017-05-02 13:19:56 -0700374 return CFX_WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700375
376 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
377 if (nRequiredLen <= 0)
Tom Sepez4ad46902017-05-02 13:19:56 -0700378 return CFX_WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700379
Tom Sepez4ad46902017-05-02 13:19:56 -0700380 std::vector<uint8_t> pBuff(nRequiredLen);
381 int nActualLen =
382 m_pInfo->FFI_GetPlatform(m_pInfo, pBuff.data(), nRequiredLen);
383 if (nActualLen <= 0 || nActualLen > nRequiredLen)
384 return CFX_WideString();
385
386 return CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
387 nActualLen / sizeof(uint16_t));
dsinclair577ad2c2016-09-22 10:20:43 -0700388}
389
Lei Zhang671630e2017-05-19 19:25:16 -0700390void CPDFSDK_FormFillEnvironment::GotoURL(CPDFXFA_Context* document,
dsinclair735606d2016-10-05 15:47:02 -0700391 const CFX_WideStringC& wsURL) {
dsinclair577ad2c2016-09-22 10:20:43 -0700392 if (!m_pInfo || !m_pInfo->FFI_GotoURL)
393 return;
394
395 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
396 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
397 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
398 bsTo.ReleaseBuffer();
399}
400
Lei Zhang671630e2017-05-19 19:25:16 -0700401void CPDFSDK_FormFillEnvironment::GetPageViewRect(CPDFXFA_Page* page,
dsinclair735606d2016-10-05 15:47:02 -0700402 FS_RECTF& dstRect) {
dsinclair577ad2c2016-09-22 10:20:43 -0700403 if (!m_pInfo || !m_pInfo->FFI_GetPageViewRect)
404 return;
405
406 double left;
407 double top;
408 double right;
409 double bottom;
410 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
Lei Zhang222e1a42017-06-20 14:47:00 -0700411 if (top < bottom)
412 std::swap(top, bottom);
dsinclair577ad2c2016-09-22 10:20:43 -0700413
414 dstRect.left = static_cast<float>(left);
Lei Zhang222e1a42017-06-20 14:47:00 -0700415 dstRect.top = static_cast<float>(top);
416 dstRect.bottom = static_cast<float>(bottom);
dsinclair577ad2c2016-09-22 10:20:43 -0700417 dstRect.right = static_cast<float>(right);
418}
419
Lei Zhang671630e2017-05-19 19:25:16 -0700420bool CPDFSDK_FormFillEnvironment::PopupMenu(CPDFXFA_Page* page,
tsepez4cf55152016-11-02 14:37:54 -0700421 FPDF_WIDGET hWidget,
422 int menuFlag,
423 CFX_PointF pt) {
tsepezdc0401a2016-10-28 13:10:35 -0700424 return m_pInfo && m_pInfo->FFI_PopupMenu &&
425 m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, pt.x, pt.y);
dsinclair577ad2c2016-09-22 10:20:43 -0700426}
427
dsinclair735606d2016-10-05 15:47:02 -0700428void CPDFSDK_FormFillEnvironment::Alert(FPDF_WIDESTRING Msg,
429 FPDF_WIDESTRING Title,
430 int Type,
431 int Icon) {
dsinclair577ad2c2016-09-22 10:20:43 -0700432 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) {
433 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type,
434 Icon);
435 }
436}
437
dsinclair735606d2016-10-05 15:47:02 -0700438void CPDFSDK_FormFillEnvironment::EmailTo(FPDF_FILEHANDLER* fileHandler,
439 FPDF_WIDESTRING pTo,
440 FPDF_WIDESTRING pSubject,
441 FPDF_WIDESTRING pCC,
442 FPDF_WIDESTRING pBcc,
443 FPDF_WIDESTRING pMsg) {
dsinclair577ad2c2016-09-22 10:20:43 -0700444 if (m_pInfo && m_pInfo->FFI_EmailTo)
445 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg);
446}
447
dsinclair735606d2016-10-05 15:47:02 -0700448void CPDFSDK_FormFillEnvironment::UploadTo(FPDF_FILEHANDLER* fileHandler,
449 int fileFlag,
450 FPDF_WIDESTRING uploadTo) {
dsinclair577ad2c2016-09-22 10:20:43 -0700451 if (m_pInfo && m_pInfo->FFI_UploadTo)
452 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
453}
454
dsinclair735606d2016-10-05 15:47:02 -0700455FPDF_FILEHANDLER* CPDFSDK_FormFillEnvironment::OpenFile(int fileType,
456 FPDF_WIDESTRING wsURL,
457 const char* mode) {
dsinclair577ad2c2016-09-22 10:20:43 -0700458 if (m_pInfo && m_pInfo->FFI_OpenFile)
459 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
460 return nullptr;
461}
462
tsepez833619b2016-12-07 09:21:17 -0800463CFX_RetainPtr<IFX_SeekableReadStream>
Dan Sinclair812e96c2017-03-13 16:43:37 -0400464CPDFSDK_FormFillEnvironment::DownloadFromURL(const wchar_t* url) {
dsinclair577ad2c2016-09-22 10:20:43 -0700465 if (!m_pInfo || !m_pInfo->FFI_DownloadFromURL)
466 return nullptr;
467
468 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
469 FPDF_WIDESTRING wsURL =
470 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
471
472 FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
tsepezfa89a202016-12-02 09:48:30 -0800473 return MakeSeekableStream(fileHandler);
dsinclair577ad2c2016-09-22 10:20:43 -0700474}
475
dsinclair735606d2016-10-05 15:47:02 -0700476CFX_WideString CPDFSDK_FormFillEnvironment::PostRequestURL(
Dan Sinclair812e96c2017-03-13 16:43:37 -0400477 const wchar_t* wsURL,
478 const wchar_t* wsData,
479 const wchar_t* wsContentType,
480 const wchar_t* wsEncode,
481 const wchar_t* wsHeader) {
dsinclair577ad2c2016-09-22 10:20:43 -0700482 if (!m_pInfo || !m_pInfo->FFI_PostRequestURL)
483 return L"";
484
485 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
486 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
487
488 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
489 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
490
491 CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode();
492 FPDF_WIDESTRING contentType =
493 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
494
495 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
496 FPDF_WIDESTRING encode =
497 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
498
499 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
500 FPDF_WIDESTRING header =
501 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
502
503 FPDF_BSTR response;
504 FPDF_BStr_Init(&response);
505 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header,
506 &response);
507
508 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
509 (FPDF_WIDESTRING)response.str, response.len / sizeof(FPDF_WIDESTRING));
510 FPDF_BStr_Clear(&response);
511
512 return wsRet;
513}
514
Dan Sinclair812e96c2017-03-13 16:43:37 -0400515FPDF_BOOL CPDFSDK_FormFillEnvironment::PutRequestURL(const wchar_t* wsURL,
516 const wchar_t* wsData,
517 const wchar_t* wsEncode) {
dsinclair577ad2c2016-09-22 10:20:43 -0700518 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL)
tsepez4cf55152016-11-02 14:37:54 -0700519 return false;
dsinclair577ad2c2016-09-22 10:20:43 -0700520
521 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
522 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
523
524 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
525 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
526
527 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
528 FPDF_WIDESTRING encode =
529 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
530
531 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
532}
533
dsinclair735606d2016-10-05 15:47:02 -0700534CFX_WideString CPDFSDK_FormFillEnvironment::GetLanguage() {
dsinclair577ad2c2016-09-22 10:20:43 -0700535 if (!m_pInfo || !m_pInfo->FFI_GetLanguage)
Tom Sepez4ad46902017-05-02 13:19:56 -0700536 return CFX_WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700537
538 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
539 if (nRequiredLen <= 0)
Tom Sepez4ad46902017-05-02 13:19:56 -0700540 return CFX_WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700541
Tom Sepez4ad46902017-05-02 13:19:56 -0700542 std::vector<uint8_t> pBuff(nRequiredLen);
543 int nActualLen =
544 m_pInfo->FFI_GetLanguage(m_pInfo, pBuff.data(), nRequiredLen);
545 if (nActualLen <= 0 || nActualLen > nRequiredLen)
546 return CFX_WideString();
547
548 return CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
549 nActualLen / sizeof(uint16_t));
dsinclair577ad2c2016-09-22 10:20:43 -0700550}
551
dsinclair735606d2016-10-05 15:47:02 -0700552void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount,
553 uint32_t dwEventType) const {
dsinclair577ad2c2016-09-22 10:20:43 -0700554 if (m_pInfo && m_pInfo->FFI_PageEvent)
555 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
556}
557#endif // PDF_ENABLE_XFA
dsinclair7cbe68e2016-10-12 11:56:23 -0700558
559void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() {
tsepez2599ff72016-11-08 14:38:59 -0800560 for (auto& it : m_PageMap) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700561 if (it.second->IsValidSDKAnnot(GetFocusAnnot()))
562 KillFocusAnnot(0);
563 }
564}
565
566CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(
567 UnderlyingPageType* pUnderlyingPage,
dsinclair6c659ab2016-10-12 13:41:38 -0700568 bool renew) {
tsepez2599ff72016-11-08 14:38:59 -0800569 auto it = m_PageMap.find(pUnderlyingPage);
570 if (it != m_PageMap.end())
dsinclair6c659ab2016-10-12 13:41:38 -0700571 return it->second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700572
dsinclair6c659ab2016-10-12 13:41:38 -0700573 if (!renew)
dsinclair7cbe68e2016-10-12 11:56:23 -0700574 return nullptr;
575
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700576 auto pNew = pdfium::MakeUnique<CPDFSDK_PageView>(this, pUnderlyingPage);
577 CPDFSDK_PageView* pPageView = pNew.get();
578 m_PageMap[pUnderlyingPage] = std::move(pNew);
579
dsinclair7cbe68e2016-10-12 11:56:23 -0700580 // Delay to load all the annotations, to avoid endless loop.
581 pPageView->LoadFXAnnots();
582 return pPageView;
583}
584
585CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() {
586 UnderlyingPageType* pPage =
Tom Sepez940967d2017-05-18 12:32:20 -0700587 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc.Get()));
dsinclair7cbe68e2016-10-12 11:56:23 -0700588 return pPage ? GetPageView(pPage, true) : nullptr;
589}
590
591CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) {
592 UnderlyingPageType* pTempPage =
Tom Sepez940967d2017-05-18 12:32:20 -0700593 UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc.Get(), nIndex));
dsinclair7cbe68e2016-10-12 11:56:23 -0700594 if (!pTempPage)
595 return nullptr;
596
tsepez2599ff72016-11-08 14:38:59 -0800597 auto it = m_PageMap.find(pTempPage);
598 return it != m_PageMap.end() ? it->second.get() : nullptr;
dsinclair7cbe68e2016-10-12 11:56:23 -0700599}
600
601void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() {
602 CPDF_Document* pPDFDoc = GetPDFDocument();
603 CPDF_DocJSActions docJS(pPDFDoc);
604 int iCount = docJS.CountJSActions();
dsinclair7cbe68e2016-10-12 11:56:23 -0700605 for (int i = 0; i < iCount; i++) {
606 CFX_ByteString csJSName;
Tom Sepezc4a2b752017-04-07 13:56:13 -0700607 CPDF_Action jsAction = docJS.GetJSActionAndName(i, &csJSName);
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700608 GetActionHandler()->DoAction_JavaScript(
Lei Zhang222e1a42017-06-20 14:47:00 -0700609 jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this);
dsinclair7cbe68e2016-10-12 11:56:23 -0700610 }
611}
612
tsepez4cf55152016-11-02 14:37:54 -0700613bool CPDFSDK_FormFillEnvironment::ProcOpenAction() {
dsinclair7cbe68e2016-10-12 11:56:23 -0700614 if (!m_pUnderlyingDoc)
tsepez4cf55152016-11-02 14:37:54 -0700615 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700616
617 CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot();
618 if (!pRoot)
tsepez4cf55152016-11-02 14:37:54 -0700619 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700620
621 CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction");
622 if (!pOpenAction)
623 pOpenAction = pRoot->GetArrayFor("OpenAction");
dsinclair7cbe68e2016-10-12 11:56:23 -0700624 if (!pOpenAction)
tsepez4cf55152016-11-02 14:37:54 -0700625 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700626
627 if (pOpenAction->IsArray())
tsepez4cf55152016-11-02 14:37:54 -0700628 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700629
Lei Zhang222e1a42017-06-20 14:47:00 -0700630 CPDF_Dictionary* pDict = pOpenAction->AsDictionary();
631 if (!pDict)
632 return false;
633
634 CPDF_Action action(pDict);
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700635 GetActionHandler()->DoAction_DocOpen(action, this);
Lei Zhang222e1a42017-06-20 14:47:00 -0700636 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700637}
638
639void CPDFSDK_FormFillEnvironment::RemovePageView(
640 UnderlyingPageType* pUnderlyingPage) {
tsepez2599ff72016-11-08 14:38:59 -0800641 auto it = m_PageMap.find(pUnderlyingPage);
642 if (it == m_PageMap.end())
dsinclair7cbe68e2016-10-12 11:56:23 -0700643 return;
644
dsinclair6c659ab2016-10-12 13:41:38 -0700645 CPDFSDK_PageView* pPageView = it->second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700646 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed())
647 return;
648
649 // Mark the page view so we do not come into |RemovePageView| a second
650 // time while we're in the process of removing.
651 pPageView->SetBeingDestroyed();
652
653 // This must happen before we remove |pPageView| from the map because
654 // |KillFocusAnnot| can call into the |GetPage| method which will
655 // look for this page view in the map, if it doesn't find it a new one will
656 // be created. We then have two page views pointing to the same page and
657 // bad things happen.
658 if (pPageView->IsValidSDKAnnot(GetFocusAnnot()))
659 KillFocusAnnot(0);
660
661 // Remove the page from the map to make sure we don't accidentally attempt
662 // to use the |pPageView| while we're cleaning it up.
tsepez2599ff72016-11-08 14:38:59 -0800663 m_PageMap.erase(it);
dsinclair7cbe68e2016-10-12 11:56:23 -0700664}
665
666UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) {
Tom Sepez940967d2017-05-18 12:32:20 -0700667 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc.Get(), nIndex));
dsinclair7cbe68e2016-10-12 11:56:23 -0700668}
669
670CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() {
671 if (!m_pInterForm)
672 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this);
673 return m_pInterForm.get();
674}
675
676void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender,
677 CPDFSDK_Annot* pAnnot) {
tsepez2599ff72016-11-08 14:38:59 -0800678 for (const auto& it : m_PageMap) {
dsinclair6c659ab2016-10-12 13:41:38 -0700679 CPDFSDK_PageView* pPageView = it.second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700680 if (pPageView != pSender)
681 pPageView->UpdateView(pAnnot);
682 }
683}
684
tsepez4cf55152016-11-02 14:37:54 -0700685bool CPDFSDK_FormFillEnvironment::SetFocusAnnot(
dsinclair7cbe68e2016-10-12 11:56:23 -0700686 CPDFSDK_Annot::ObservedPtr* pAnnot) {
687 if (m_bBeingDestroyed)
tsepez4cf55152016-11-02 14:37:54 -0700688 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700689 if (m_pFocusAnnot == *pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700690 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700691 if (m_pFocusAnnot && !KillFocusAnnot(0))
tsepez4cf55152016-11-02 14:37:54 -0700692 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700693 if (!*pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700694 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700695
Lei Zhang222e1a42017-06-20 14:47:00 -0700696 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView();
697 if (!pPageView || !pPageView->IsValid())
698 return false;
699
700 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
701 if (m_pFocusAnnot)
702 return false;
703
dsinclair7cbe68e2016-10-12 11:56:23 -0700704#ifdef PDF_ENABLE_XFA
705 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get());
Lei Zhang222e1a42017-06-20 14:47:00 -0700706 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot))
707 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700708#endif // PDF_ENABLE_XFA
Lei Zhang222e1a42017-06-20 14:47:00 -0700709 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0))
710 return false;
711 if (m_pFocusAnnot)
712 return false;
713
714 m_pFocusAnnot.Reset(pAnnot->Get());
715 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700716}
717
tsepez4cf55152016-11-02 14:37:54 -0700718bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) {
Lei Zhang222e1a42017-06-20 14:47:00 -0700719 if (!m_pFocusAnnot)
720 return false;
721
722 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
723 CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get());
724 m_pFocusAnnot.Reset();
dsinclair7cbe68e2016-10-12 11:56:23 -0700725
726#ifdef PDF_ENABLE_XFA
Lei Zhang222e1a42017-06-20 14:47:00 -0700727 CPDFSDK_Annot::ObservedPtr pNull;
728 if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot))
729 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700730#endif // PDF_ENABLE_XFA
731
Lei Zhang222e1a42017-06-20 14:47:00 -0700732 if (!pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) {
733 m_pFocusAnnot.Reset(pFocusAnnot.Get());
734 return false;
735 }
736
737 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) {
738 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get());
739 int nFieldType = pWidget->GetFieldType();
740 if (FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType) {
741 OnSetFieldInputFocus(nullptr, 0, false);
dsinclair7cbe68e2016-10-12 11:56:23 -0700742 }
743 }
Lei Zhang222e1a42017-06-20 14:47:00 -0700744 return !m_pFocusAnnot;
dsinclair7cbe68e2016-10-12 11:56:23 -0700745}
746
Lei Zhangad0982a2017-06-16 19:30:38 -0700747bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) const {
tsepez95e58342016-10-28 11:34:42 -0700748 return !!(GetPDFDocument()->GetUserPermissions() & nFlag);
dsinclair7cbe68e2016-10-12 11:56:23 -0700749}