blob: 8c5025ed88c8d0726b71d6a3ddefbaa51b3d74af [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
dsinclair735606d2016-10-05 15:47:02 -0700223CPDFSDK_ActionHandler* CPDFSDK_FormFillEnvironment::GetActionHander() {
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);
411
412 dstRect.left = static_cast<float>(left);
413 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
414 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
415 dstRect.right = static_cast<float>(right);
416}
417
Lei Zhang671630e2017-05-19 19:25:16 -0700418bool CPDFSDK_FormFillEnvironment::PopupMenu(CPDFXFA_Page* page,
tsepez4cf55152016-11-02 14:37:54 -0700419 FPDF_WIDGET hWidget,
420 int menuFlag,
421 CFX_PointF pt) {
tsepezdc0401a2016-10-28 13:10:35 -0700422 return m_pInfo && m_pInfo->FFI_PopupMenu &&
423 m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, pt.x, pt.y);
dsinclair577ad2c2016-09-22 10:20:43 -0700424}
425
dsinclair735606d2016-10-05 15:47:02 -0700426void CPDFSDK_FormFillEnvironment::Alert(FPDF_WIDESTRING Msg,
427 FPDF_WIDESTRING Title,
428 int Type,
429 int Icon) {
dsinclair577ad2c2016-09-22 10:20:43 -0700430 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) {
431 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type,
432 Icon);
433 }
434}
435
dsinclair735606d2016-10-05 15:47:02 -0700436void CPDFSDK_FormFillEnvironment::EmailTo(FPDF_FILEHANDLER* fileHandler,
437 FPDF_WIDESTRING pTo,
438 FPDF_WIDESTRING pSubject,
439 FPDF_WIDESTRING pCC,
440 FPDF_WIDESTRING pBcc,
441 FPDF_WIDESTRING pMsg) {
dsinclair577ad2c2016-09-22 10:20:43 -0700442 if (m_pInfo && m_pInfo->FFI_EmailTo)
443 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg);
444}
445
dsinclair735606d2016-10-05 15:47:02 -0700446void CPDFSDK_FormFillEnvironment::UploadTo(FPDF_FILEHANDLER* fileHandler,
447 int fileFlag,
448 FPDF_WIDESTRING uploadTo) {
dsinclair577ad2c2016-09-22 10:20:43 -0700449 if (m_pInfo && m_pInfo->FFI_UploadTo)
450 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
451}
452
dsinclair735606d2016-10-05 15:47:02 -0700453FPDF_FILEHANDLER* CPDFSDK_FormFillEnvironment::OpenFile(int fileType,
454 FPDF_WIDESTRING wsURL,
455 const char* mode) {
dsinclair577ad2c2016-09-22 10:20:43 -0700456 if (m_pInfo && m_pInfo->FFI_OpenFile)
457 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
458 return nullptr;
459}
460
tsepez833619b2016-12-07 09:21:17 -0800461CFX_RetainPtr<IFX_SeekableReadStream>
Dan Sinclair812e96c2017-03-13 16:43:37 -0400462CPDFSDK_FormFillEnvironment::DownloadFromURL(const wchar_t* url) {
dsinclair577ad2c2016-09-22 10:20:43 -0700463 if (!m_pInfo || !m_pInfo->FFI_DownloadFromURL)
464 return nullptr;
465
466 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
467 FPDF_WIDESTRING wsURL =
468 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
469
470 FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
tsepezfa89a202016-12-02 09:48:30 -0800471 return MakeSeekableStream(fileHandler);
dsinclair577ad2c2016-09-22 10:20:43 -0700472}
473
dsinclair735606d2016-10-05 15:47:02 -0700474CFX_WideString CPDFSDK_FormFillEnvironment::PostRequestURL(
Dan Sinclair812e96c2017-03-13 16:43:37 -0400475 const wchar_t* wsURL,
476 const wchar_t* wsData,
477 const wchar_t* wsContentType,
478 const wchar_t* wsEncode,
479 const wchar_t* wsHeader) {
dsinclair577ad2c2016-09-22 10:20:43 -0700480 if (!m_pInfo || !m_pInfo->FFI_PostRequestURL)
481 return L"";
482
483 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
484 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
485
486 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
487 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
488
489 CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode();
490 FPDF_WIDESTRING contentType =
491 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
492
493 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
494 FPDF_WIDESTRING encode =
495 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
496
497 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
498 FPDF_WIDESTRING header =
499 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
500
501 FPDF_BSTR response;
502 FPDF_BStr_Init(&response);
503 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header,
504 &response);
505
506 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
507 (FPDF_WIDESTRING)response.str, response.len / sizeof(FPDF_WIDESTRING));
508 FPDF_BStr_Clear(&response);
509
510 return wsRet;
511}
512
Dan Sinclair812e96c2017-03-13 16:43:37 -0400513FPDF_BOOL CPDFSDK_FormFillEnvironment::PutRequestURL(const wchar_t* wsURL,
514 const wchar_t* wsData,
515 const wchar_t* wsEncode) {
dsinclair577ad2c2016-09-22 10:20:43 -0700516 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL)
tsepez4cf55152016-11-02 14:37:54 -0700517 return false;
dsinclair577ad2c2016-09-22 10:20:43 -0700518
519 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
520 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
521
522 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
523 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
524
525 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
526 FPDF_WIDESTRING encode =
527 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
528
529 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
530}
531
dsinclair735606d2016-10-05 15:47:02 -0700532CFX_WideString CPDFSDK_FormFillEnvironment::GetLanguage() {
dsinclair577ad2c2016-09-22 10:20:43 -0700533 if (!m_pInfo || !m_pInfo->FFI_GetLanguage)
Tom Sepez4ad46902017-05-02 13:19:56 -0700534 return CFX_WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700535
536 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
537 if (nRequiredLen <= 0)
Tom Sepez4ad46902017-05-02 13:19:56 -0700538 return CFX_WideString();
dsinclair577ad2c2016-09-22 10:20:43 -0700539
Tom Sepez4ad46902017-05-02 13:19:56 -0700540 std::vector<uint8_t> pBuff(nRequiredLen);
541 int nActualLen =
542 m_pInfo->FFI_GetLanguage(m_pInfo, pBuff.data(), nRequiredLen);
543 if (nActualLen <= 0 || nActualLen > nRequiredLen)
544 return CFX_WideString();
545
546 return CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
547 nActualLen / sizeof(uint16_t));
dsinclair577ad2c2016-09-22 10:20:43 -0700548}
549
dsinclair735606d2016-10-05 15:47:02 -0700550void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount,
551 uint32_t dwEventType) const {
dsinclair577ad2c2016-09-22 10:20:43 -0700552 if (m_pInfo && m_pInfo->FFI_PageEvent)
553 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
554}
555#endif // PDF_ENABLE_XFA
dsinclair7cbe68e2016-10-12 11:56:23 -0700556
557void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() {
tsepez2599ff72016-11-08 14:38:59 -0800558 for (auto& it : m_PageMap) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700559 if (it.second->IsValidSDKAnnot(GetFocusAnnot()))
560 KillFocusAnnot(0);
561 }
562}
563
564CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(
565 UnderlyingPageType* pUnderlyingPage,
dsinclair6c659ab2016-10-12 13:41:38 -0700566 bool renew) {
tsepez2599ff72016-11-08 14:38:59 -0800567 auto it = m_PageMap.find(pUnderlyingPage);
568 if (it != m_PageMap.end())
dsinclair6c659ab2016-10-12 13:41:38 -0700569 return it->second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700570
dsinclair6c659ab2016-10-12 13:41:38 -0700571 if (!renew)
dsinclair7cbe68e2016-10-12 11:56:23 -0700572 return nullptr;
573
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700574 auto pNew = pdfium::MakeUnique<CPDFSDK_PageView>(this, pUnderlyingPage);
575 CPDFSDK_PageView* pPageView = pNew.get();
576 m_PageMap[pUnderlyingPage] = std::move(pNew);
577
dsinclair7cbe68e2016-10-12 11:56:23 -0700578 // Delay to load all the annotations, to avoid endless loop.
579 pPageView->LoadFXAnnots();
580 return pPageView;
581}
582
583CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() {
584 UnderlyingPageType* pPage =
Tom Sepez940967d2017-05-18 12:32:20 -0700585 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc.Get()));
dsinclair7cbe68e2016-10-12 11:56:23 -0700586 return pPage ? GetPageView(pPage, true) : nullptr;
587}
588
589CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) {
590 UnderlyingPageType* pTempPage =
Tom Sepez940967d2017-05-18 12:32:20 -0700591 UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc.Get(), nIndex));
dsinclair7cbe68e2016-10-12 11:56:23 -0700592 if (!pTempPage)
593 return nullptr;
594
tsepez2599ff72016-11-08 14:38:59 -0800595 auto it = m_PageMap.find(pTempPage);
596 return it != m_PageMap.end() ? it->second.get() : nullptr;
dsinclair7cbe68e2016-10-12 11:56:23 -0700597}
598
599void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() {
600 CPDF_Document* pPDFDoc = GetPDFDocument();
601 CPDF_DocJSActions docJS(pPDFDoc);
602 int iCount = docJS.CountJSActions();
603 if (iCount < 1)
604 return;
605 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);
dsinclair7cbe68e2016-10-12 11:56:23 -0700608 if (GetActionHander()) {
609 GetActionHander()->DoAction_JavaScript(
610 jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this);
611 }
612 }
613}
614
tsepez4cf55152016-11-02 14:37:54 -0700615bool CPDFSDK_FormFillEnvironment::ProcOpenAction() {
dsinclair7cbe68e2016-10-12 11:56:23 -0700616 if (!m_pUnderlyingDoc)
tsepez4cf55152016-11-02 14:37:54 -0700617 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700618
619 CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot();
620 if (!pRoot)
tsepez4cf55152016-11-02 14:37:54 -0700621 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700622
623 CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction");
624 if (!pOpenAction)
625 pOpenAction = pRoot->GetArrayFor("OpenAction");
626
627 if (!pOpenAction)
tsepez4cf55152016-11-02 14:37:54 -0700628 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700629
630 if (pOpenAction->IsArray())
tsepez4cf55152016-11-02 14:37:54 -0700631 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700632
633 if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) {
634 CPDF_Action action(pDict);
635 if (GetActionHander())
636 GetActionHander()->DoAction_DocOpen(action, this);
tsepez4cf55152016-11-02 14:37:54 -0700637 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700638 }
tsepez4cf55152016-11-02 14:37:54 -0700639 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700640}
641
642void CPDFSDK_FormFillEnvironment::RemovePageView(
643 UnderlyingPageType* pUnderlyingPage) {
tsepez2599ff72016-11-08 14:38:59 -0800644 auto it = m_PageMap.find(pUnderlyingPage);
645 if (it == m_PageMap.end())
dsinclair7cbe68e2016-10-12 11:56:23 -0700646 return;
647
dsinclair6c659ab2016-10-12 13:41:38 -0700648 CPDFSDK_PageView* pPageView = it->second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700649 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed())
650 return;
651
652 // Mark the page view so we do not come into |RemovePageView| a second
653 // time while we're in the process of removing.
654 pPageView->SetBeingDestroyed();
655
656 // This must happen before we remove |pPageView| from the map because
657 // |KillFocusAnnot| can call into the |GetPage| method which will
658 // look for this page view in the map, if it doesn't find it a new one will
659 // be created. We then have two page views pointing to the same page and
660 // bad things happen.
661 if (pPageView->IsValidSDKAnnot(GetFocusAnnot()))
662 KillFocusAnnot(0);
663
664 // Remove the page from the map to make sure we don't accidentally attempt
665 // to use the |pPageView| while we're cleaning it up.
tsepez2599ff72016-11-08 14:38:59 -0800666 m_PageMap.erase(it);
dsinclair7cbe68e2016-10-12 11:56:23 -0700667}
668
669UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) {
Tom Sepez940967d2017-05-18 12:32:20 -0700670 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc.Get(), nIndex));
dsinclair7cbe68e2016-10-12 11:56:23 -0700671}
672
673CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() {
674 if (!m_pInterForm)
675 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this);
676 return m_pInterForm.get();
677}
678
679void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender,
680 CPDFSDK_Annot* pAnnot) {
tsepez2599ff72016-11-08 14:38:59 -0800681 for (const auto& it : m_PageMap) {
dsinclair6c659ab2016-10-12 13:41:38 -0700682 CPDFSDK_PageView* pPageView = it.second.get();
dsinclair7cbe68e2016-10-12 11:56:23 -0700683 if (pPageView != pSender)
684 pPageView->UpdateView(pAnnot);
685 }
686}
687
tsepez4cf55152016-11-02 14:37:54 -0700688bool CPDFSDK_FormFillEnvironment::SetFocusAnnot(
dsinclair7cbe68e2016-10-12 11:56:23 -0700689 CPDFSDK_Annot::ObservedPtr* pAnnot) {
690 if (m_bBeingDestroyed)
tsepez4cf55152016-11-02 14:37:54 -0700691 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700692 if (m_pFocusAnnot == *pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700693 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700694 if (m_pFocusAnnot && !KillFocusAnnot(0))
tsepez4cf55152016-11-02 14:37:54 -0700695 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700696 if (!*pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700697 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700698
699#ifdef PDF_ENABLE_XFA
700 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get());
701#endif // PDF_ENABLE_XFA
702 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView();
703 if (pPageView && pPageView->IsValid()) {
704 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
705 if (!m_pFocusAnnot) {
706#ifdef PDF_ENABLE_XFA
707 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700708 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700709#endif // PDF_ENABLE_XFA
710 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0))
tsepez4cf55152016-11-02 14:37:54 -0700711 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700712 if (!m_pFocusAnnot) {
713 m_pFocusAnnot.Reset(pAnnot->Get());
tsepez4cf55152016-11-02 14:37:54 -0700714 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700715 }
716 }
717 }
tsepez4cf55152016-11-02 14:37:54 -0700718 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700719}
720
tsepez4cf55152016-11-02 14:37:54 -0700721bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700722 if (m_pFocusAnnot) {
723 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
724 CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get());
725 m_pFocusAnnot.Reset();
726
727#ifdef PDF_ENABLE_XFA
728 CPDFSDK_Annot::ObservedPtr pNull;
729 if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700730 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700731#endif // PDF_ENABLE_XFA
732
733 if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) {
734 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) {
735 CPDFSDK_Widget* pWidget =
736 static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get());
737 int nFieldType = pWidget->GetFieldType();
738 if (FIELDTYPE_TEXTFIELD == nFieldType ||
739 FIELDTYPE_COMBOBOX == nFieldType) {
tsepez4cf55152016-11-02 14:37:54 -0700740 OnSetFieldInputFocus(nullptr, 0, false);
dsinclair7cbe68e2016-10-12 11:56:23 -0700741 }
742 }
743 if (!m_pFocusAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700744 return true;
dsinclair7cbe68e2016-10-12 11:56:23 -0700745 } else {
746 m_pFocusAnnot.Reset(pFocusAnnot.Get());
747 }
748 }
tsepez4cf55152016-11-02 14:37:54 -0700749 return false;
dsinclair7cbe68e2016-10-12 11:56:23 -0700750}
751
tsepez4cf55152016-11-02 14:37:54 -0700752bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) {
tsepez95e58342016-10-28 11:34:42 -0700753 return !!(GetPDFDocument()->GetUserPermissions() & nFlag);
dsinclair7cbe68e2016-10-12 11:56:23 -0700754}