blob: 31a1c5156c88e0d009726387834a11fda6dc13c6 [file] [log] [blame]
dsinclairf34518b2016-09-13 12:03:48 -07001// Copyright 2016 PDFium Authors. All rights reserved.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair735606d2016-10-05 15:47:02 -07007#ifndef FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_
8#define FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050010#include <map>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080011#include <memory>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050012#include <vector>
Lei Zhang606346f2015-06-19 18:11:07 -070013
dsinclair41872fa2016-10-04 11:29:35 -070014#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070015#include "core/fpdfapi/parser/cpdf_document.h"
dsinclair1727aee2016-09-29 13:12:56 -070016#include "core/fpdfdoc/cpdf_occontext.h"
Dan Sinclair65ecca42017-09-21 15:25:32 -040017#include "core/fxcrt/observable.h"
dsinclairb9590102016-04-27 06:38:59 -070018#include "fpdfsdk/cfx_systemhandler.h"
dsinclair7cbe68e2016-10-12 11:56:23 -070019#include "fpdfsdk/cpdfsdk_annot.h"
dsinclair114e46a2016-09-29 17:18:21 -070020#include "fpdfsdk/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080021#include "public/fpdf_formfill.h"
Dan Sinclairdf5a1162016-03-09 16:51:34 -050022#include "public/fpdf_fwlevent.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080023
dsinclairb94d7c92016-09-21 12:07:00 -070024class CFFL_InteractiveFormFiller;
dsinclairb9590102016-04-27 06:38:59 -070025class CFX_SystemHandler;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070026class CPDFSDK_ActionHandler;
jaepark98e10192016-08-15 10:51:11 -070027class CPDFSDK_AnnotHandlerMgr;
dsinclair7cbe68e2016-10-12 11:56:23 -070028class CPDFSDK_InterForm;
29class CPDFSDK_PageView;
dsinclair64376be2016-03-31 20:03:24 -070030class IJS_Runtime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Tom Sepez940967d2017-05-18 12:32:20 -070032// The CPDFSDK_FormFillEnvironment is "owned" by the embedder across the
33// C API as a FPDF_FormHandle, and may pop out of existence at any time,
34// so long as the associated embedder-owned FPDF_Document outlives it.
35// Pointers from objects in the FPDF_Document ownership hierarchy should
36// be ObservedPtr<> so as to clear themselves when the embedder "exits"
37// the form fill environment. Pointers from objects in this ownership
38// heirarcy to objects in the FPDF_Document ownership hierarcy should be
39// UnownedPtr<>, as should pointers from objects in this ownership
40// hierarcy back to the form fill environment itself, so as to flag any
41// lingering lifetime issues via the memory tools.
42
dsinclair3a7741a2016-10-11 10:39:49 -070043class CPDFSDK_FormFillEnvironment
Dan Sinclair65ecca42017-09-21 15:25:32 -040044 : public Observable<CPDFSDK_FormFillEnvironment> {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 public:
dsinclair735606d2016-10-05 15:47:02 -070046 CPDFSDK_FormFillEnvironment(UnderlyingDocumentType* pDoc,
47 FPDF_FORMFILLINFO* pFFinfo);
48 ~CPDFSDK_FormFillEnvironment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049
Lei Zhang60fa2fc2017-07-21 17:42:19 -070050 static bool IsSHIFTKeyDown(uint32_t nFlag) {
51 return !!(nFlag & FWL_EVENTFLAG_ShiftKey);
52 }
53 static bool IsCTRLKeyDown(uint32_t nFlag) {
54 return !!(nFlag & FWL_EVENTFLAG_ControlKey);
55 }
56 static bool IsALTKeyDown(uint32_t nFlag) {
57 return !!(nFlag & FWL_EVENTFLAG_AltKey);
58 }
59
dsinclair6c659ab2016-10-12 13:41:38 -070060 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool renew);
dsinclair7cbe68e2016-10-12 11:56:23 -070061 CPDFSDK_PageView* GetPageView(int nIndex);
62 CPDFSDK_PageView* GetCurrentView();
63 void RemovePageView(UnderlyingPageType* pPage);
64 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
65
66 CPDFSDK_Annot* GetFocusAnnot() { return m_pFocusAnnot.Get(); }
tsepez4cf55152016-11-02 14:37:54 -070067 bool SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot);
68 bool KillFocusAnnot(uint32_t nFlag);
dsinclair7cbe68e2016-10-12 11:56:23 -070069 void ClearAllFocusedAnnots();
70
tsepez4cf55152016-11-02 14:37:54 -070071 bool ExtractPages(const std::vector<uint16_t>& arrExtraPages,
72 CPDF_Document* pDstDoc);
73 bool InsertPages(int nInsertAt,
74 const CPDF_Document* pSrcDoc,
75 const std::vector<uint16_t>& arrSrcPages);
76 bool ReplacePages(int nPage,
77 const CPDF_Document* pSrcDoc,
78 const std::vector<uint16_t>& arrSrcPages);
dsinclair7cbe68e2016-10-12 11:56:23 -070079
Lei Zhangad0982a2017-06-16 19:30:38 -070080 int GetPageCount() const { return m_pUnderlyingDoc->GetPageCount(); }
81 bool GetPermissions(int nFlag) const;
dsinclair7cbe68e2016-10-12 11:56:23 -070082
dsinclair6c659ab2016-10-12 13:41:38 -070083 bool GetChangeMark() const { return m_bChangeMask; }
84 void SetChangeMark() { m_bChangeMask = true; }
85 void ClearChangeMark() { m_bChangeMask = false; }
dsinclair7cbe68e2016-10-12 11:56:23 -070086
dsinclair7cbe68e2016-10-12 11:56:23 -070087 void ProcJavascriptFun();
tsepez4cf55152016-11-02 14:37:54 -070088 bool ProcOpenAction();
dsinclair7cbe68e2016-10-12 11:56:23 -070089
Lei Zhang671630e2017-05-19 19:25:16 -070090 void Invalidate(UnderlyingPageType* page, const FX_RECT& rect);
91 void OutputSelectedRect(UnderlyingPageType* page, const CFX_FloatRect& rect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092
dsinclair577ad2c2016-09-22 10:20:43 -070093 void SetCursor(int nCursorType);
94 int SetTimer(int uElapse, TimerCallback lpTimerFunc);
95 void KillTimer(int nTimerID);
96 FX_SYSTEMTIME GetLocalTime() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097
dsinclair577ad2c2016-09-22 10:20:43 -070098 void OnChange();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099
Lei Zhang671630e2017-05-19 19:25:16 -0700100 FPDF_PAGE GetCurrentPage(UnderlyingDocumentType* document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101
Dan Sinclair812e96c2017-03-13 16:43:37 -0400102 void ExecuteNamedAction(const char* namedAction);
dsinclair577ad2c2016-09-22 10:20:43 -0700103 void OnSetFieldInputFocus(FPDF_WIDESTRING focusText,
dsinclair1f248902016-09-14 10:38:17 -0700104 FPDF_DWORD nTextLen,
tsepez4cf55152016-11-02 14:37:54 -0700105 bool bFocus);
Dan Sinclair812e96c2017-03-13 16:43:37 -0400106 void DoURIAction(const char* bsURI);
dsinclair1f248902016-09-14 10:38:17 -0700107 void DoGoToAction(int nPageIndex,
108 int zoomMode,
109 float* fPosArray,
dsinclair577ad2c2016-09-22 10:20:43 -0700110 int sizeOfArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111
dsinclair6c659ab2016-10-12 13:41:38 -0700112 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez940967d2017-05-18 12:32:20 -0700113 return m_pUnderlyingDoc.Get();
dsinclair6c659ab2016-10-12 13:41:38 -0700114 }
115
Tom Sepez51da0932015-11-25 16:05:49 -0800116#ifdef PDF_ENABLE_XFA
dsinclair6c659ab2016-10-12 13:41:38 -0700117 CPDF_Document* GetPDFDocument() const {
118 return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr;
119 }
120
Tom Sepez940967d2017-05-18 12:32:20 -0700121 CPDFXFA_Context* GetXFAContext() const { return m_pUnderlyingDoc.Get(); }
dsinclair6c659ab2016-10-12 13:41:38 -0700122 void ResetXFADocument() { m_pUnderlyingDoc = nullptr; }
123
tsepez2599ff72016-11-08 14:38:59 -0800124 int GetPageViewCount() const { return m_PageMap.size(); }
dsinclair6c659ab2016-10-12 13:41:38 -0700125
Lei Zhang671630e2017-05-19 19:25:16 -0700126 void DisplayCaret(CPDFXFA_Page* page,
dsinclair1f248902016-09-14 10:38:17 -0700127 FPDF_BOOL bVisible,
128 double left,
129 double top,
130 double right,
dsinclair577ad2c2016-09-22 10:20:43 -0700131 double bottom);
Lei Zhang671630e2017-05-19 19:25:16 -0700132 int GetCurrentPageIndex(CPDFXFA_Context* document);
133 void SetCurrentPage(CPDFXFA_Context* document, int iCurPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
dsinclair1f248902016-09-14 10:38:17 -0700135 // TODO(dsinclair): This should probably change to PDFium?
Ryan Harrison275e2602017-09-18 14:23:18 -0400136 WideString FFI_GetAppName() const { return WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137
Ryan Harrison275e2602017-09-18 14:23:18 -0400138 WideString GetPlatform();
139 void GotoURL(CPDFXFA_Context* document, const WideStringView& wsURL);
Lei Zhang671630e2017-05-19 19:25:16 -0700140 void GetPageViewRect(CPDFXFA_Page* page, FS_RECTF& dstRect);
141 bool PopupMenu(CPDFXFA_Page* page,
tsepez4cf55152016-11-02 14:37:54 -0700142 FPDF_WIDGET hWidget,
143 int menuFlag,
144 CFX_PointF pt);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145
dsinclair577ad2c2016-09-22 10:20:43 -0700146 void Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon);
dsinclair1f248902016-09-14 10:38:17 -0700147 void EmailTo(FPDF_FILEHANDLER* fileHandler,
148 FPDF_WIDESTRING pTo,
149 FPDF_WIDESTRING pSubject,
150 FPDF_WIDESTRING pCC,
151 FPDF_WIDESTRING pBcc,
dsinclair577ad2c2016-09-22 10:20:43 -0700152 FPDF_WIDESTRING pMsg);
dsinclair1f248902016-09-14 10:38:17 -0700153 void UploadTo(FPDF_FILEHANDLER* fileHandler,
154 int fileFlag,
dsinclair577ad2c2016-09-22 10:20:43 -0700155 FPDF_WIDESTRING uploadTo);
dsinclair1f248902016-09-14 10:38:17 -0700156 FPDF_FILEHANDLER* OpenFile(int fileType,
157 FPDF_WIDESTRING wsURL,
dsinclair577ad2c2016-09-22 10:20:43 -0700158 const char* mode);
Dan Sinclair0b950422017-09-21 15:49:49 -0400159 RetainPtr<IFX_SeekableReadStream> DownloadFromURL(const wchar_t* url);
Ryan Harrison275e2602017-09-18 14:23:18 -0400160 WideString PostRequestURL(const wchar_t* wsURL,
161 const wchar_t* wsData,
162 const wchar_t* wsContentType,
163 const wchar_t* wsEncode,
164 const wchar_t* wsHeader);
Dan Sinclair812e96c2017-03-13 16:43:37 -0400165 FPDF_BOOL PutRequestURL(const wchar_t* wsURL,
166 const wchar_t* wsData,
167 const wchar_t* wsEncode);
Ryan Harrison275e2602017-09-18 14:23:18 -0400168 WideString GetLanguage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169
dsinclair577ad2c2016-09-22 10:20:43 -0700170 void PageEvent(int iPageCount, uint32_t dwEventType) const;
dsinclair6c659ab2016-10-12 13:41:38 -0700171#else // PDF_ENABLE_XFA
Tom Sepez940967d2017-05-18 12:32:20 -0700172 CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc.Get(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800173#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174
Dan Sinclair812e96c2017-03-13 16:43:37 -0400175 int JS_appAlert(const wchar_t* Msg,
176 const wchar_t* Title,
dsinclair72177da2016-09-15 12:07:23 -0700177 uint32_t Type,
178 uint32_t Icon);
Dan Sinclair812e96c2017-03-13 16:43:37 -0400179 int JS_appResponse(const wchar_t* Question,
180 const wchar_t* Title,
181 const wchar_t* Default,
182 const wchar_t* cLabel,
Tom Sepez57028592016-02-01 15:49:11 -0800183 FPDF_BOOL bPassword,
184 void* response,
185 int length);
186 void JS_appBeep(int nType);
Ryan Harrison275e2602017-09-18 14:23:18 -0400187 WideString JS_fieldBrowse();
188 WideString JS_docGetFilePath();
Dan Sinclair812e96c2017-03-13 16:43:37 -0400189 void JS_docSubmitForm(void* formData, int length, const wchar_t* URL);
Tom Sepez57028592016-02-01 15:49:11 -0800190 void JS_docmailForm(void* mailData,
191 int length,
192 FPDF_BOOL bUI,
Dan Sinclair812e96c2017-03-13 16:43:37 -0400193 const wchar_t* To,
194 const wchar_t* Subject,
195 const wchar_t* CC,
196 const wchar_t* BCC,
197 const wchar_t* Msg);
Tom Sepez57028592016-02-01 15:49:11 -0800198 void JS_docprint(FPDF_BOOL bUI,
199 int nStart,
200 int nEnd,
201 FPDF_BOOL bSilent,
202 FPDF_BOOL bShrinkToFit,
203 FPDF_BOOL bPrintAsImage,
204 FPDF_BOOL bReverse,
205 FPDF_BOOL bAnnotations);
206 void JS_docgotoPage(int nPageNum);
207
tsepez4cf55152016-11-02 14:37:54 -0700208 bool IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
Ryan Harrison275e2602017-09-18 14:23:18 -0400209 ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700210 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212
dsinclairb94d7c92016-09-21 12:07:00 -0700213 // Creates if not present.
214 CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700216 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700217 CPDFSDK_ActionHandler* GetActionHandler(); // Creates if not present.
dsinclair6c659ab2016-10-12 13:41:38 -0700218 CPDFSDK_InterForm* GetInterForm(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800219
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 private:
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700221 UnderlyingPageType* GetPage(int nIndex);
222
Tom Sepez940967d2017-05-18 12:32:20 -0700223 FPDF_FORMFILLINFO* const m_pInfo;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800224 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
225 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
226 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
tsepez2599ff72016-11-08 14:38:59 -0800227 std::map<UnderlyingPageType*, std::unique_ptr<CPDFSDK_PageView>> m_PageMap;
dsinclair7cbe68e2016-10-12 11:56:23 -0700228 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
229 CPDFSDK_Annot::ObservedPtr m_pFocusAnnot;
Dan Sinclairaee0db02017-09-21 16:53:58 -0400230 UnownedPtr<UnderlyingDocumentType> m_pUnderlyingDoc;
dsinclairb94d7c92016-09-21 12:07:00 -0700231 std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700232 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
dsinclair6c659ab2016-10-12 13:41:38 -0700233 bool m_bChangeMask;
234 bool m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235};
236
dsinclair735606d2016-10-05 15:47:02 -0700237#endif // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_