blob: b1e095a0c2d8616484c7b2b7e2a1f8cfd7ea3454 [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"
dsinclaira52ab742016-09-29 13:59:29 -070017#include "core/fxcrt/cfx_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
44 : public CFX_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
dsinclair6c659ab2016-10-12 13:41:38 -070050 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool renew);
dsinclair7cbe68e2016-10-12 11:56:23 -070051 CPDFSDK_PageView* GetPageView(int nIndex);
52 CPDFSDK_PageView* GetCurrentView();
53 void RemovePageView(UnderlyingPageType* pPage);
54 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
55
56 CPDFSDK_Annot* GetFocusAnnot() { return m_pFocusAnnot.Get(); }
tsepez4cf55152016-11-02 14:37:54 -070057 bool SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot);
58 bool KillFocusAnnot(uint32_t nFlag);
dsinclair7cbe68e2016-10-12 11:56:23 -070059 void ClearAllFocusedAnnots();
60
tsepez4cf55152016-11-02 14:37:54 -070061 bool ExtractPages(const std::vector<uint16_t>& arrExtraPages,
62 CPDF_Document* pDstDoc);
63 bool InsertPages(int nInsertAt,
64 const CPDF_Document* pSrcDoc,
65 const std::vector<uint16_t>& arrSrcPages);
66 bool ReplacePages(int nPage,
67 const CPDF_Document* pSrcDoc,
68 const std::vector<uint16_t>& arrSrcPages);
dsinclair7cbe68e2016-10-12 11:56:23 -070069
Lei Zhangad0982a2017-06-16 19:30:38 -070070 int GetPageCount() const { return m_pUnderlyingDoc->GetPageCount(); }
71 bool GetPermissions(int nFlag) const;
dsinclair7cbe68e2016-10-12 11:56:23 -070072
dsinclair6c659ab2016-10-12 13:41:38 -070073 bool GetChangeMark() const { return m_bChangeMask; }
74 void SetChangeMark() { m_bChangeMask = true; }
75 void ClearChangeMark() { m_bChangeMask = false; }
dsinclair7cbe68e2016-10-12 11:56:23 -070076
77 UnderlyingPageType* GetPage(int nIndex);
78
79 void ProcJavascriptFun();
tsepez4cf55152016-11-02 14:37:54 -070080 bool ProcOpenAction();
dsinclair7cbe68e2016-10-12 11:56:23 -070081
Lei Zhang671630e2017-05-19 19:25:16 -070082 void Invalidate(UnderlyingPageType* page, const FX_RECT& rect);
83 void OutputSelectedRect(UnderlyingPageType* page, const CFX_FloatRect& rect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084
dsinclair577ad2c2016-09-22 10:20:43 -070085 void SetCursor(int nCursorType);
86 int SetTimer(int uElapse, TimerCallback lpTimerFunc);
87 void KillTimer(int nTimerID);
88 FX_SYSTEMTIME GetLocalTime() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089
dsinclair577ad2c2016-09-22 10:20:43 -070090 void OnChange();
tsepez4cf55152016-11-02 14:37:54 -070091 bool IsSHIFTKeyDown(uint32_t nFlag) const;
92 bool IsCTRLKeyDown(uint32_t nFlag) const;
93 bool IsALTKeyDown(uint32_t nFlag) const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094
Lei Zhang671630e2017-05-19 19:25:16 -070095 FPDF_PAGE GetPage(UnderlyingDocumentType* document, int nPageIndex);
96 FPDF_PAGE GetCurrentPage(UnderlyingDocumentType* document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097
Dan Sinclair812e96c2017-03-13 16:43:37 -040098 void ExecuteNamedAction(const char* namedAction);
dsinclair577ad2c2016-09-22 10:20:43 -070099 void OnSetFieldInputFocus(FPDF_WIDESTRING focusText,
dsinclair1f248902016-09-14 10:38:17 -0700100 FPDF_DWORD nTextLen,
tsepez4cf55152016-11-02 14:37:54 -0700101 bool bFocus);
Dan Sinclair812e96c2017-03-13 16:43:37 -0400102 void DoURIAction(const char* bsURI);
dsinclair1f248902016-09-14 10:38:17 -0700103 void DoGoToAction(int nPageIndex,
104 int zoomMode,
105 float* fPosArray,
dsinclair577ad2c2016-09-22 10:20:43 -0700106 int sizeOfArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
dsinclair6c659ab2016-10-12 13:41:38 -0700108 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez940967d2017-05-18 12:32:20 -0700109 return m_pUnderlyingDoc.Get();
dsinclair6c659ab2016-10-12 13:41:38 -0700110 }
111
Tom Sepez51da0932015-11-25 16:05:49 -0800112#ifdef PDF_ENABLE_XFA
dsinclair6c659ab2016-10-12 13:41:38 -0700113 CPDF_Document* GetPDFDocument() const {
114 return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr;
115 }
116
Tom Sepez940967d2017-05-18 12:32:20 -0700117 CPDFXFA_Context* GetXFAContext() const { return m_pUnderlyingDoc.Get(); }
dsinclair6c659ab2016-10-12 13:41:38 -0700118 void ResetXFADocument() { m_pUnderlyingDoc = nullptr; }
119
tsepez2599ff72016-11-08 14:38:59 -0800120 int GetPageViewCount() const { return m_PageMap.size(); }
dsinclair6c659ab2016-10-12 13:41:38 -0700121
Lei Zhang671630e2017-05-19 19:25:16 -0700122 void DisplayCaret(CPDFXFA_Page* page,
dsinclair1f248902016-09-14 10:38:17 -0700123 FPDF_BOOL bVisible,
124 double left,
125 double top,
126 double right,
dsinclair577ad2c2016-09-22 10:20:43 -0700127 double bottom);
Lei Zhang671630e2017-05-19 19:25:16 -0700128 int GetCurrentPageIndex(CPDFXFA_Context* document);
129 void SetCurrentPage(CPDFXFA_Context* document, int iCurPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
dsinclair1f248902016-09-14 10:38:17 -0700131 // TODO(dsinclair): This should probably change to PDFium?
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133
dsinclair577ad2c2016-09-22 10:20:43 -0700134 CFX_WideString GetPlatform();
Lei Zhang671630e2017-05-19 19:25:16 -0700135 void GotoURL(CPDFXFA_Context* document, const CFX_WideStringC& wsURL);
136 void GetPageViewRect(CPDFXFA_Page* page, FS_RECTF& dstRect);
137 bool PopupMenu(CPDFXFA_Page* page,
tsepez4cf55152016-11-02 14:37:54 -0700138 FPDF_WIDGET hWidget,
139 int menuFlag,
140 CFX_PointF pt);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
dsinclair577ad2c2016-09-22 10:20:43 -0700142 void Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon);
dsinclair1f248902016-09-14 10:38:17 -0700143 void EmailTo(FPDF_FILEHANDLER* fileHandler,
144 FPDF_WIDESTRING pTo,
145 FPDF_WIDESTRING pSubject,
146 FPDF_WIDESTRING pCC,
147 FPDF_WIDESTRING pBcc,
dsinclair577ad2c2016-09-22 10:20:43 -0700148 FPDF_WIDESTRING pMsg);
dsinclair1f248902016-09-14 10:38:17 -0700149 void UploadTo(FPDF_FILEHANDLER* fileHandler,
150 int fileFlag,
dsinclair577ad2c2016-09-22 10:20:43 -0700151 FPDF_WIDESTRING uploadTo);
dsinclair1f248902016-09-14 10:38:17 -0700152 FPDF_FILEHANDLER* OpenFile(int fileType,
153 FPDF_WIDESTRING wsURL,
dsinclair577ad2c2016-09-22 10:20:43 -0700154 const char* mode);
Dan Sinclair812e96c2017-03-13 16:43:37 -0400155 CFX_RetainPtr<IFX_SeekableReadStream> DownloadFromURL(const wchar_t* url);
156 CFX_WideString PostRequestURL(const wchar_t* wsURL,
157 const wchar_t* wsData,
158 const wchar_t* wsContentType,
159 const wchar_t* wsEncode,
160 const wchar_t* wsHeader);
161 FPDF_BOOL PutRequestURL(const wchar_t* wsURL,
162 const wchar_t* wsData,
163 const wchar_t* wsEncode);
dsinclair577ad2c2016-09-22 10:20:43 -0700164 CFX_WideString GetLanguage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165
dsinclair577ad2c2016-09-22 10:20:43 -0700166 void PageEvent(int iPageCount, uint32_t dwEventType) const;
dsinclair6c659ab2016-10-12 13:41:38 -0700167#else // PDF_ENABLE_XFA
Tom Sepez940967d2017-05-18 12:32:20 -0700168 CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc.Get(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800169#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170
Dan Sinclair812e96c2017-03-13 16:43:37 -0400171 int JS_appAlert(const wchar_t* Msg,
172 const wchar_t* Title,
dsinclair72177da2016-09-15 12:07:23 -0700173 uint32_t Type,
174 uint32_t Icon);
Dan Sinclair812e96c2017-03-13 16:43:37 -0400175 int JS_appResponse(const wchar_t* Question,
176 const wchar_t* Title,
177 const wchar_t* Default,
178 const wchar_t* cLabel,
Tom Sepez57028592016-02-01 15:49:11 -0800179 FPDF_BOOL bPassword,
180 void* response,
181 int length);
182 void JS_appBeep(int nType);
183 CFX_WideString JS_fieldBrowse();
184 CFX_WideString JS_docGetFilePath();
Dan Sinclair812e96c2017-03-13 16:43:37 -0400185 void JS_docSubmitForm(void* formData, int length, const wchar_t* URL);
Tom Sepez57028592016-02-01 15:49:11 -0800186 void JS_docmailForm(void* mailData,
187 int length,
188 FPDF_BOOL bUI,
Dan Sinclair812e96c2017-03-13 16:43:37 -0400189 const wchar_t* To,
190 const wchar_t* Subject,
191 const wchar_t* CC,
192 const wchar_t* BCC,
193 const wchar_t* Msg);
Tom Sepez57028592016-02-01 15:49:11 -0800194 void JS_docprint(FPDF_BOOL bUI,
195 int nStart,
196 int nEnd,
197 FPDF_BOOL bSilent,
198 FPDF_BOOL bShrinkToFit,
199 FPDF_BOOL bPrintAsImage,
200 FPDF_BOOL bReverse,
201 FPDF_BOOL bAnnotations);
202 void JS_docgotoPage(int nPageNum);
203
tsepez4cf55152016-11-02 14:37:54 -0700204 bool IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 CFX_ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700206 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208
dsinclairb94d7c92016-09-21 12:07:00 -0700209 // Creates if not present.
210 CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700212 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Lei Zhangcddc8ed2017-06-20 17:26:44 -0700213 CPDFSDK_ActionHandler* GetActionHandler(); // Creates if not present.
dsinclair6c659ab2016-10-12 13:41:38 -0700214 CPDFSDK_InterForm* GetInterForm(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800215
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 private:
Tom Sepez940967d2017-05-18 12:32:20 -0700217 FPDF_FORMFILLINFO* const m_pInfo;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800218 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
219 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
220 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
tsepez2599ff72016-11-08 14:38:59 -0800221 std::map<UnderlyingPageType*, std::unique_ptr<CPDFSDK_PageView>> m_PageMap;
dsinclair7cbe68e2016-10-12 11:56:23 -0700222 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
223 CPDFSDK_Annot::ObservedPtr m_pFocusAnnot;
Tom Sepez940967d2017-05-18 12:32:20 -0700224 CFX_UnownedPtr<UnderlyingDocumentType> m_pUnderlyingDoc;
dsinclairb94d7c92016-09-21 12:07:00 -0700225 std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700226 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
dsinclair6c659ab2016-10-12 13:41:38 -0700227 bool m_bChangeMask;
228 bool m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229};
230
dsinclair735606d2016-10-05 15:47:02 -0700231#endif // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_