blob: b180e98104790d7289ee81a68f91ff55d05e2649 [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
dsinclair3a7741a2016-10-11 10:39:49 -070032class CPDFSDK_FormFillEnvironment
33 : public CFX_Observable<CPDFSDK_FormFillEnvironment> {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 public:
dsinclair735606d2016-10-05 15:47:02 -070035 CPDFSDK_FormFillEnvironment(UnderlyingDocumentType* pDoc,
36 FPDF_FORMFILLINFO* pFFinfo);
37 ~CPDFSDK_FormFillEnvironment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038
dsinclair6c659ab2016-10-12 13:41:38 -070039 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool renew);
dsinclair7cbe68e2016-10-12 11:56:23 -070040 CPDFSDK_PageView* GetPageView(int nIndex);
41 CPDFSDK_PageView* GetCurrentView();
42 void RemovePageView(UnderlyingPageType* pPage);
43 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
44
45 CPDFSDK_Annot* GetFocusAnnot() { return m_pFocusAnnot.Get(); }
tsepez4cf55152016-11-02 14:37:54 -070046 bool SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot);
47 bool KillFocusAnnot(uint32_t nFlag);
dsinclair7cbe68e2016-10-12 11:56:23 -070048 void ClearAllFocusedAnnots();
49
tsepez4cf55152016-11-02 14:37:54 -070050 bool ExtractPages(const std::vector<uint16_t>& arrExtraPages,
51 CPDF_Document* pDstDoc);
52 bool InsertPages(int nInsertAt,
53 const CPDF_Document* pSrcDoc,
54 const std::vector<uint16_t>& arrSrcPages);
55 bool ReplacePages(int nPage,
56 const CPDF_Document* pSrcDoc,
57 const std::vector<uint16_t>& arrSrcPages);
dsinclair7cbe68e2016-10-12 11:56:23 -070058
59 int GetPageCount() { return m_pUnderlyingDoc->GetPageCount(); }
tsepez4cf55152016-11-02 14:37:54 -070060 bool GetPermissions(int nFlag);
dsinclair7cbe68e2016-10-12 11:56:23 -070061
dsinclair6c659ab2016-10-12 13:41:38 -070062 bool GetChangeMark() const { return m_bChangeMask; }
63 void SetChangeMark() { m_bChangeMask = true; }
64 void ClearChangeMark() { m_bChangeMask = false; }
dsinclair7cbe68e2016-10-12 11:56:23 -070065
66 UnderlyingPageType* GetPage(int nIndex);
67
68 void ProcJavascriptFun();
tsepez4cf55152016-11-02 14:37:54 -070069 bool ProcOpenAction();
dsinclair7cbe68e2016-10-12 11:56:23 -070070
Dan Sinclair6eec1c42017-02-21 17:20:43 -050071 void Invalidate(FPDF_PAGE page, const FX_RECT& rect);
dsinclair1f248902016-09-14 10:38:17 -070072 void OutputSelectedRect(FPDF_PAGE page,
73 double left,
74 double top,
75 double right,
dsinclair577ad2c2016-09-22 10:20:43 -070076 double bottom);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077
dsinclair577ad2c2016-09-22 10:20:43 -070078 void SetCursor(int nCursorType);
79 int SetTimer(int uElapse, TimerCallback lpTimerFunc);
80 void KillTimer(int nTimerID);
81 FX_SYSTEMTIME GetLocalTime() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082
dsinclair577ad2c2016-09-22 10:20:43 -070083 void OnChange();
tsepez4cf55152016-11-02 14:37:54 -070084 bool IsSHIFTKeyDown(uint32_t nFlag) const;
85 bool IsCTRLKeyDown(uint32_t nFlag) const;
86 bool IsALTKeyDown(uint32_t nFlag) const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087
dsinclair577ad2c2016-09-22 10:20:43 -070088 FPDF_PAGE GetPage(FPDF_DOCUMENT document, int nPageIndex);
89 FPDF_PAGE GetCurrentPage(FPDF_DOCUMENT document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090
dsinclair577ad2c2016-09-22 10:20:43 -070091 void ExecuteNamedAction(const FX_CHAR* namedAction);
92 void OnSetFieldInputFocus(FPDF_WIDESTRING focusText,
dsinclair1f248902016-09-14 10:38:17 -070093 FPDF_DWORD nTextLen,
tsepez4cf55152016-11-02 14:37:54 -070094 bool bFocus);
dsinclair577ad2c2016-09-22 10:20:43 -070095 void DoURIAction(const FX_CHAR* bsURI);
dsinclair1f248902016-09-14 10:38:17 -070096 void DoGoToAction(int nPageIndex,
97 int zoomMode,
98 float* fPosArray,
dsinclair577ad2c2016-09-22 10:20:43 -070099 int sizeOfArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
dsinclair6c659ab2016-10-12 13:41:38 -0700101 UnderlyingDocumentType* GetUnderlyingDocument() const {
102 return m_pUnderlyingDoc;
103 }
104
Tom Sepez51da0932015-11-25 16:05:49 -0800105#ifdef PDF_ENABLE_XFA
dsinclair6c659ab2016-10-12 13:41:38 -0700106 CPDF_Document* GetPDFDocument() const {
107 return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr;
108 }
109
dsinclair521b7502016-11-02 13:02:28 -0700110 CPDFXFA_Context* GetXFAContext() const { return m_pUnderlyingDoc; }
dsinclair6c659ab2016-10-12 13:41:38 -0700111 void ResetXFADocument() { m_pUnderlyingDoc = nullptr; }
112
tsepez2599ff72016-11-08 14:38:59 -0800113 int GetPageViewCount() const { return m_PageMap.size(); }
dsinclair6c659ab2016-10-12 13:41:38 -0700114
dsinclair1f248902016-09-14 10:38:17 -0700115 void DisplayCaret(FPDF_PAGE page,
116 FPDF_BOOL bVisible,
117 double left,
118 double top,
119 double right,
dsinclair577ad2c2016-09-22 10:20:43 -0700120 double bottom);
121 int GetCurrentPageIndex(FPDF_DOCUMENT document);
122 void SetCurrentPage(FPDF_DOCUMENT document, int iCurPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
dsinclair1f248902016-09-14 10:38:17 -0700124 // TODO(dsinclair): This should probably change to PDFium?
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126
dsinclair577ad2c2016-09-22 10:20:43 -0700127 CFX_WideString GetPlatform();
128 void GotoURL(FPDF_DOCUMENT document, const CFX_WideStringC& wsURL);
129 void GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect);
tsepez4cf55152016-11-02 14:37:54 -0700130 bool PopupMenu(FPDF_PAGE page,
131 FPDF_WIDGET hWidget,
132 int menuFlag,
133 CFX_PointF pt);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
dsinclair577ad2c2016-09-22 10:20:43 -0700135 void Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon);
dsinclair1f248902016-09-14 10:38:17 -0700136 void EmailTo(FPDF_FILEHANDLER* fileHandler,
137 FPDF_WIDESTRING pTo,
138 FPDF_WIDESTRING pSubject,
139 FPDF_WIDESTRING pCC,
140 FPDF_WIDESTRING pBcc,
dsinclair577ad2c2016-09-22 10:20:43 -0700141 FPDF_WIDESTRING pMsg);
dsinclair1f248902016-09-14 10:38:17 -0700142 void UploadTo(FPDF_FILEHANDLER* fileHandler,
143 int fileFlag,
dsinclair577ad2c2016-09-22 10:20:43 -0700144 FPDF_WIDESTRING uploadTo);
dsinclair1f248902016-09-14 10:38:17 -0700145 FPDF_FILEHANDLER* OpenFile(int fileType,
146 FPDF_WIDESTRING wsURL,
dsinclair577ad2c2016-09-22 10:20:43 -0700147 const char* mode);
tsepez833619b2016-12-07 09:21:17 -0800148 CFX_RetainPtr<IFX_SeekableReadStream> DownloadFromURL(const FX_WCHAR* url);
dsinclair1f248902016-09-14 10:38:17 -0700149 CFX_WideString PostRequestURL(const FX_WCHAR* wsURL,
150 const FX_WCHAR* wsData,
151 const FX_WCHAR* wsContentType,
152 const FX_WCHAR* wsEncode,
dsinclair577ad2c2016-09-22 10:20:43 -0700153 const FX_WCHAR* wsHeader);
dsinclair1f248902016-09-14 10:38:17 -0700154 FPDF_BOOL PutRequestURL(const FX_WCHAR* wsURL,
155 const FX_WCHAR* wsData,
dsinclair577ad2c2016-09-22 10:20:43 -0700156 const FX_WCHAR* wsEncode);
157 CFX_WideString GetLanguage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158
dsinclair577ad2c2016-09-22 10:20:43 -0700159 void PageEvent(int iPageCount, uint32_t dwEventType) const;
dsinclair6c659ab2016-10-12 13:41:38 -0700160#else // PDF_ENABLE_XFA
161 CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800162#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Tom Sepez57028592016-02-01 15:49:11 -0800164 int JS_appAlert(const FX_WCHAR* Msg,
165 const FX_WCHAR* Title,
dsinclair72177da2016-09-15 12:07:23 -0700166 uint32_t Type,
167 uint32_t Icon);
Tom Sepez57028592016-02-01 15:49:11 -0800168 int JS_appResponse(const FX_WCHAR* Question,
169 const FX_WCHAR* Title,
170 const FX_WCHAR* Default,
171 const FX_WCHAR* cLabel,
172 FPDF_BOOL bPassword,
173 void* response,
174 int length);
175 void JS_appBeep(int nType);
176 CFX_WideString JS_fieldBrowse();
177 CFX_WideString JS_docGetFilePath();
178 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
179 void JS_docmailForm(void* mailData,
180 int length,
181 FPDF_BOOL bUI,
182 const FX_WCHAR* To,
183 const FX_WCHAR* Subject,
184 const FX_WCHAR* CC,
185 const FX_WCHAR* BCC,
186 const FX_WCHAR* Msg);
187 void JS_docprint(FPDF_BOOL bUI,
188 int nStart,
189 int nEnd,
190 FPDF_BOOL bSilent,
191 FPDF_BOOL bShrinkToFit,
192 FPDF_BOOL bPrintAsImage,
193 FPDF_BOOL bReverse,
194 FPDF_BOOL bAnnotations);
195 void JS_docgotoPage(int nPageNum);
196
tsepez4cf55152016-11-02 14:37:54 -0700197 bool IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 CFX_ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700199 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
dsinclairb94d7c92016-09-21 12:07:00 -0700202 // Creates if not present.
203 CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700205 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
dsinclair6c659ab2016-10-12 13:41:38 -0700207 CPDFSDK_InterForm* GetInterForm(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800208
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800210 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
211 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
212 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 FPDF_FORMFILLINFO* const m_pInfo;
tsepez2599ff72016-11-08 14:38:59 -0800214 std::map<UnderlyingPageType*, std::unique_ptr<CPDFSDK_PageView>> m_PageMap;
dsinclair7cbe68e2016-10-12 11:56:23 -0700215 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
216 CPDFSDK_Annot::ObservedPtr m_pFocusAnnot;
217 UnderlyingDocumentType* m_pUnderlyingDoc;
dsinclairb94d7c92016-09-21 12:07:00 -0700218 std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700219 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
dsinclair6c659ab2016-10-12 13:41:38 -0700220 bool m_bChangeMask;
221 bool m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700222};
223
dsinclair735606d2016-10-05 15:47:02 -0700224#endif // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_