blob: 4cdbda3f7cdadc394d4471c2f2b310af4921e2ec [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
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080010#include <memory>
Lei Zhang606346f2015-06-19 18:11:07 -070011
dsinclair41872fa2016-10-04 11:29:35 -070012#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070013#include "core/fpdfapi/parser/cpdf_document.h"
dsinclair1727aee2016-09-29 13:12:56 -070014#include "core/fpdfdoc/cpdf_occontext.h"
dsinclaira52ab742016-09-29 13:59:29 -070015#include "core/fxcrt/cfx_observable.h"
dsinclairb9590102016-04-27 06:38:59 -070016#include "fpdfsdk/cfx_systemhandler.h"
dsinclair7cbe68e2016-10-12 11:56:23 -070017#include "fpdfsdk/cpdfsdk_annot.h"
dsinclair114e46a2016-09-29 17:18:21 -070018#include "fpdfsdk/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080019#include "public/fpdf_formfill.h"
Dan Sinclairdf5a1162016-03-09 16:51:34 -050020#include "public/fpdf_fwlevent.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080021
dsinclairb94d7c92016-09-21 12:07:00 -070022class CFFL_InteractiveFormFiller;
dsinclairb9590102016-04-27 06:38:59 -070023class CFX_SystemHandler;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070024class CPDFSDK_ActionHandler;
jaepark98e10192016-08-15 10:51:11 -070025class CPDFSDK_AnnotHandlerMgr;
dsinclair7cbe68e2016-10-12 11:56:23 -070026class CPDFSDK_InterForm;
27class CPDFSDK_PageView;
dsinclair64376be2016-03-31 20:03:24 -070028class IJS_Runtime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029
dsinclair3a7741a2016-10-11 10:39:49 -070030class CPDFSDK_FormFillEnvironment
31 : public CFX_Observable<CPDFSDK_FormFillEnvironment> {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032 public:
dsinclair735606d2016-10-05 15:47:02 -070033 CPDFSDK_FormFillEnvironment(UnderlyingDocumentType* pDoc,
34 FPDF_FORMFILLINFO* pFFinfo);
35 ~CPDFSDK_FormFillEnvironment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
dsinclair6c659ab2016-10-12 13:41:38 -070037 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool renew);
dsinclair7cbe68e2016-10-12 11:56:23 -070038 CPDFSDK_PageView* GetPageView(int nIndex);
39 CPDFSDK_PageView* GetCurrentView();
40 void RemovePageView(UnderlyingPageType* pPage);
41 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
42
43 CPDFSDK_Annot* GetFocusAnnot() { return m_pFocusAnnot.Get(); }
44 FX_BOOL SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot);
45 FX_BOOL KillFocusAnnot(uint32_t nFlag);
46 void ClearAllFocusedAnnots();
47
48 FX_BOOL ExtractPages(const std::vector<uint16_t>& arrExtraPages,
49 CPDF_Document* pDstDoc);
50 FX_BOOL InsertPages(int nInsertAt,
51 const CPDF_Document* pSrcDoc,
52 const std::vector<uint16_t>& arrSrcPages);
53 FX_BOOL ReplacePages(int nPage,
54 const CPDF_Document* pSrcDoc,
55 const std::vector<uint16_t>& arrSrcPages);
56
57 int GetPageCount() { return m_pUnderlyingDoc->GetPageCount(); }
58 FX_BOOL GetPermissions(int nFlag);
59
dsinclair6c659ab2016-10-12 13:41:38 -070060 bool GetChangeMark() const { return m_bChangeMask; }
61 void SetChangeMark() { m_bChangeMask = true; }
62 void ClearChangeMark() { m_bChangeMask = false; }
dsinclair7cbe68e2016-10-12 11:56:23 -070063
64 UnderlyingPageType* GetPage(int nIndex);
65
66 void ProcJavascriptFun();
67 FX_BOOL ProcOpenAction();
68
dsinclair1f248902016-09-14 10:38:17 -070069 void Invalidate(FPDF_PAGE page,
70 double left,
71 double top,
72 double right,
dsinclair577ad2c2016-09-22 10:20:43 -070073 double bottom);
dsinclair1f248902016-09-14 10:38:17 -070074 void OutputSelectedRect(FPDF_PAGE page,
75 double left,
76 double top,
77 double right,
dsinclair577ad2c2016-09-22 10:20:43 -070078 double bottom);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079
dsinclair577ad2c2016-09-22 10:20:43 -070080 void SetCursor(int nCursorType);
81 int SetTimer(int uElapse, TimerCallback lpTimerFunc);
82 void KillTimer(int nTimerID);
83 FX_SYSTEMTIME GetLocalTime() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084
dsinclair577ad2c2016-09-22 10:20:43 -070085 void OnChange();
86 FX_BOOL IsSHIFTKeyDown(uint32_t nFlag) const;
87 FX_BOOL IsCTRLKeyDown(uint32_t nFlag) const;
88 FX_BOOL IsALTKeyDown(uint32_t nFlag) const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089
dsinclair577ad2c2016-09-22 10:20:43 -070090 FPDF_PAGE GetPage(FPDF_DOCUMENT document, int nPageIndex);
91 FPDF_PAGE GetCurrentPage(FPDF_DOCUMENT document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092
dsinclair577ad2c2016-09-22 10:20:43 -070093 void ExecuteNamedAction(const FX_CHAR* namedAction);
94 void OnSetFieldInputFocus(FPDF_WIDESTRING focusText,
dsinclair1f248902016-09-14 10:38:17 -070095 FPDF_DWORD nTextLen,
dsinclair577ad2c2016-09-22 10:20:43 -070096 FX_BOOL bFocus);
97 void DoURIAction(const FX_CHAR* bsURI);
dsinclair1f248902016-09-14 10:38:17 -070098 void DoGoToAction(int nPageIndex,
99 int zoomMode,
100 float* fPosArray,
dsinclair577ad2c2016-09-22 10:20:43 -0700101 int sizeOfArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102
dsinclair6c659ab2016-10-12 13:41:38 -0700103 UnderlyingDocumentType* GetUnderlyingDocument() const {
104 return m_pUnderlyingDoc;
105 }
106
Tom Sepez51da0932015-11-25 16:05:49 -0800107#ifdef PDF_ENABLE_XFA
dsinclair6c659ab2016-10-12 13:41:38 -0700108 CPDF_Document* GetPDFDocument() const {
109 return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr;
110 }
111
112 CPDFXFA_Document* GetXFADocument() const { return m_pUnderlyingDoc; }
113 void ResetXFADocument() { m_pUnderlyingDoc = nullptr; }
114
115 int GetPageViewCount() const { return m_pageMap.size(); }
116
dsinclair1f248902016-09-14 10:38:17 -0700117 void DisplayCaret(FPDF_PAGE page,
118 FPDF_BOOL bVisible,
119 double left,
120 double top,
121 double right,
dsinclair577ad2c2016-09-22 10:20:43 -0700122 double bottom);
123 int GetCurrentPageIndex(FPDF_DOCUMENT document);
124 void SetCurrentPage(FPDF_DOCUMENT document, int iCurPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
dsinclair1f248902016-09-14 10:38:17 -0700126 // TODO(dsinclair): This should probably change to PDFium?
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128
dsinclair577ad2c2016-09-22 10:20:43 -0700129 CFX_WideString GetPlatform();
130 void GotoURL(FPDF_DOCUMENT document, const CFX_WideStringC& wsURL);
131 void GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect);
dsinclair1f248902016-09-14 10:38:17 -0700132 FX_BOOL PopupMenu(FPDF_PAGE page,
133 FPDF_WIDGET hWidget,
134 int menuFlag,
dsinclair577ad2c2016-09-22 10:20:43 -0700135 CFX_PointF pt);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136
dsinclair577ad2c2016-09-22 10:20:43 -0700137 void Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon);
dsinclair1f248902016-09-14 10:38:17 -0700138 void EmailTo(FPDF_FILEHANDLER* fileHandler,
139 FPDF_WIDESTRING pTo,
140 FPDF_WIDESTRING pSubject,
141 FPDF_WIDESTRING pCC,
142 FPDF_WIDESTRING pBcc,
dsinclair577ad2c2016-09-22 10:20:43 -0700143 FPDF_WIDESTRING pMsg);
dsinclair1f248902016-09-14 10:38:17 -0700144 void UploadTo(FPDF_FILEHANDLER* fileHandler,
145 int fileFlag,
dsinclair577ad2c2016-09-22 10:20:43 -0700146 FPDF_WIDESTRING uploadTo);
dsinclair1f248902016-09-14 10:38:17 -0700147 FPDF_FILEHANDLER* OpenFile(int fileType,
148 FPDF_WIDESTRING wsURL,
dsinclair577ad2c2016-09-22 10:20:43 -0700149 const char* mode);
tsepezad2441e2016-10-24 10:19:11 -0700150 IFX_SeekableReadStream* DownloadFromURL(const FX_WCHAR* url);
dsinclair1f248902016-09-14 10:38:17 -0700151 CFX_WideString PostRequestURL(const FX_WCHAR* wsURL,
152 const FX_WCHAR* wsData,
153 const FX_WCHAR* wsContentType,
154 const FX_WCHAR* wsEncode,
dsinclair577ad2c2016-09-22 10:20:43 -0700155 const FX_WCHAR* wsHeader);
dsinclair1f248902016-09-14 10:38:17 -0700156 FPDF_BOOL PutRequestURL(const FX_WCHAR* wsURL,
157 const FX_WCHAR* wsData,
dsinclair577ad2c2016-09-22 10:20:43 -0700158 const FX_WCHAR* wsEncode);
159 CFX_WideString GetLanguage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160
dsinclair577ad2c2016-09-22 10:20:43 -0700161 void PageEvent(int iPageCount, uint32_t dwEventType) const;
dsinclair6c659ab2016-10-12 13:41:38 -0700162#else // PDF_ENABLE_XFA
163 CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800164#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Tom Sepez57028592016-02-01 15:49:11 -0800166 int JS_appAlert(const FX_WCHAR* Msg,
167 const FX_WCHAR* Title,
dsinclair72177da2016-09-15 12:07:23 -0700168 uint32_t Type,
169 uint32_t Icon);
Tom Sepez57028592016-02-01 15:49:11 -0800170 int JS_appResponse(const FX_WCHAR* Question,
171 const FX_WCHAR* Title,
172 const FX_WCHAR* Default,
173 const FX_WCHAR* cLabel,
174 FPDF_BOOL bPassword,
175 void* response,
176 int length);
177 void JS_appBeep(int nType);
178 CFX_WideString JS_fieldBrowse();
179 CFX_WideString JS_docGetFilePath();
180 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
181 void JS_docmailForm(void* mailData,
182 int length,
183 FPDF_BOOL bUI,
184 const FX_WCHAR* To,
185 const FX_WCHAR* Subject,
186 const FX_WCHAR* CC,
187 const FX_WCHAR* BCC,
188 const FX_WCHAR* Msg);
189 void JS_docprint(FPDF_BOOL bUI,
190 int nStart,
191 int nEnd,
192 FPDF_BOOL bSilent,
193 FPDF_BOOL bShrinkToFit,
194 FPDF_BOOL bPrintAsImage,
195 FPDF_BOOL bReverse,
196 FPDF_BOOL bAnnotations);
197 void JS_docgotoPage(int nPageNum);
198
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 CFX_ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700201 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203
dsinclairb94d7c92016-09-21 12:07:00 -0700204 // Creates if not present.
205 CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700207 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
dsinclair6c659ab2016-10-12 13:41:38 -0700209 CPDFSDK_InterForm* GetInterForm(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800210
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800212 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
213 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
214 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 FPDF_FORMFILLINFO* const m_pInfo;
dsinclair6c659ab2016-10-12 13:41:38 -0700216 std::map<UnderlyingPageType*, std::unique_ptr<CPDFSDK_PageView>> m_pageMap;
dsinclair7cbe68e2016-10-12 11:56:23 -0700217 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
218 CPDFSDK_Annot::ObservedPtr m_pFocusAnnot;
219 UnderlyingDocumentType* m_pUnderlyingDoc;
dsinclairb94d7c92016-09-21 12:07:00 -0700220 std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700221 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
dsinclair6c659ab2016-10-12 13:41:38 -0700222 bool m_bChangeMask;
223 bool m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700224};
225
dsinclair735606d2016-10-05 15:47:02 -0700226#endif // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_