• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
7 #ifndef FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_
8 #define FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fpdfapi/page/cpdf_page.h"
15 #include "core/fpdfapi/parser/cpdf_document.h"
16 #include "core/fpdfdoc/cpdf_occontext.h"
17 #include "core/fxcrt/cfx_observable.h"
18 #include "fpdfsdk/cfx_systemhandler.h"
19 #include "fpdfsdk/cpdfsdk_annot.h"
20 #include "fpdfsdk/fsdk_define.h"
21 #include "public/fpdf_formfill.h"
22 #include "public/fpdf_fwlevent.h"
23 
24 class CFFL_InteractiveFormFiller;
25 class CFX_SystemHandler;
26 class CPDFSDK_ActionHandler;
27 class CPDFSDK_AnnotHandlerMgr;
28 class CPDFSDK_InterForm;
29 class CPDFSDK_PageView;
30 class IJS_Runtime;
31 
32 class CPDFSDK_FormFillEnvironment
33     : public CFX_Observable<CPDFSDK_FormFillEnvironment> {
34  public:
35   CPDFSDK_FormFillEnvironment(UnderlyingDocumentType* pDoc,
36                               FPDF_FORMFILLINFO* pFFinfo);
37   ~CPDFSDK_FormFillEnvironment();
38 
39   CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool renew);
40   CPDFSDK_PageView* GetPageView(int nIndex);
41   CPDFSDK_PageView* GetCurrentView();
42   void RemovePageView(UnderlyingPageType* pPage);
43   void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
44 
GetFocusAnnot()45   CPDFSDK_Annot* GetFocusAnnot() { return m_pFocusAnnot.Get(); }
46   bool SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot);
47   bool KillFocusAnnot(uint32_t nFlag);
48   void ClearAllFocusedAnnots();
49 
50   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);
58 
GetPageCount()59   int GetPageCount() { return m_pUnderlyingDoc->GetPageCount(); }
60   bool GetPermissions(int nFlag);
61 
GetChangeMark()62   bool GetChangeMark() const { return m_bChangeMask; }
SetChangeMark()63   void SetChangeMark() { m_bChangeMask = true; }
ClearChangeMark()64   void ClearChangeMark() { m_bChangeMask = false; }
65 
66   UnderlyingPageType* GetPage(int nIndex);
67 
68   void ProcJavascriptFun();
69   bool ProcOpenAction();
70 
71   void Invalidate(FPDF_PAGE page, const FX_RECT& rect);
72   void OutputSelectedRect(FPDF_PAGE page, const CFX_FloatRect& rect);
73 
74   void SetCursor(int nCursorType);
75   int SetTimer(int uElapse, TimerCallback lpTimerFunc);
76   void KillTimer(int nTimerID);
77   FX_SYSTEMTIME GetLocalTime() const;
78 
79   void OnChange();
80   bool IsSHIFTKeyDown(uint32_t nFlag) const;
81   bool IsCTRLKeyDown(uint32_t nFlag) const;
82   bool IsALTKeyDown(uint32_t nFlag) const;
83 
84   FPDF_PAGE GetPage(FPDF_DOCUMENT document, int nPageIndex);
85   FPDF_PAGE GetCurrentPage(FPDF_DOCUMENT document);
86 
87   void ExecuteNamedAction(const FX_CHAR* namedAction);
88   void OnSetFieldInputFocus(FPDF_WIDESTRING focusText,
89                             FPDF_DWORD nTextLen,
90                             bool bFocus);
91   void DoURIAction(const FX_CHAR* bsURI);
92   void DoGoToAction(int nPageIndex,
93                     int zoomMode,
94                     float* fPosArray,
95                     int sizeOfArray);
96 
GetUnderlyingDocument()97   UnderlyingDocumentType* GetUnderlyingDocument() const {
98     return m_pUnderlyingDoc;
99   }
100 
101 #ifdef PDF_ENABLE_XFA
GetPDFDocument()102   CPDF_Document* GetPDFDocument() const {
103     return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr;
104   }
105 
GetXFAContext()106   CPDFXFA_Context* GetXFAContext() const { return m_pUnderlyingDoc; }
ResetXFADocument()107   void ResetXFADocument() { m_pUnderlyingDoc = nullptr; }
108 
GetPageViewCount()109   int GetPageViewCount() const { return m_PageMap.size(); }
110 
111   void DisplayCaret(FPDF_PAGE page,
112                     FPDF_BOOL bVisible,
113                     double left,
114                     double top,
115                     double right,
116                     double bottom);
117   int GetCurrentPageIndex(FPDF_DOCUMENT document);
118   void SetCurrentPage(FPDF_DOCUMENT document, int iCurPage);
119 
120   // TODO(dsinclair): This should probably change to PDFium?
FFI_GetAppName()121   CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
122 
123   CFX_WideString GetPlatform();
124   void GotoURL(FPDF_DOCUMENT document, const CFX_WideStringC& wsURL);
125   void GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect);
126   bool PopupMenu(FPDF_PAGE page,
127                  FPDF_WIDGET hWidget,
128                  int menuFlag,
129                  CFX_PointF pt);
130 
131   void Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon);
132   void EmailTo(FPDF_FILEHANDLER* fileHandler,
133                FPDF_WIDESTRING pTo,
134                FPDF_WIDESTRING pSubject,
135                FPDF_WIDESTRING pCC,
136                FPDF_WIDESTRING pBcc,
137                FPDF_WIDESTRING pMsg);
138   void UploadTo(FPDF_FILEHANDLER* fileHandler,
139                 int fileFlag,
140                 FPDF_WIDESTRING uploadTo);
141   FPDF_FILEHANDLER* OpenFile(int fileType,
142                              FPDF_WIDESTRING wsURL,
143                              const char* mode);
144   CFX_RetainPtr<IFX_SeekableReadStream> DownloadFromURL(const FX_WCHAR* url);
145   CFX_WideString PostRequestURL(const FX_WCHAR* wsURL,
146                                 const FX_WCHAR* wsData,
147                                 const FX_WCHAR* wsContentType,
148                                 const FX_WCHAR* wsEncode,
149                                 const FX_WCHAR* wsHeader);
150   FPDF_BOOL PutRequestURL(const FX_WCHAR* wsURL,
151                           const FX_WCHAR* wsData,
152                           const FX_WCHAR* wsEncode);
153   CFX_WideString GetLanguage();
154 
155   void PageEvent(int iPageCount, uint32_t dwEventType) const;
156 #else   // PDF_ENABLE_XFA
GetPDFDocument()157   CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc; }
158 #endif  // PDF_ENABLE_XFA
159 
160   int JS_appAlert(const FX_WCHAR* Msg,
161                   const FX_WCHAR* Title,
162                   uint32_t Type,
163                   uint32_t Icon);
164   int JS_appResponse(const FX_WCHAR* Question,
165                      const FX_WCHAR* Title,
166                      const FX_WCHAR* Default,
167                      const FX_WCHAR* cLabel,
168                      FPDF_BOOL bPassword,
169                      void* response,
170                      int length);
171   void JS_appBeep(int nType);
172   CFX_WideString JS_fieldBrowse();
173   CFX_WideString JS_docGetFilePath();
174   void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
175   void JS_docmailForm(void* mailData,
176                       int length,
177                       FPDF_BOOL bUI,
178                       const FX_WCHAR* To,
179                       const FX_WCHAR* Subject,
180                       const FX_WCHAR* CC,
181                       const FX_WCHAR* BCC,
182                       const FX_WCHAR* Msg);
183   void JS_docprint(FPDF_BOOL bUI,
184                    int nStart,
185                    int nEnd,
186                    FPDF_BOOL bSilent,
187                    FPDF_BOOL bShrinkToFit,
188                    FPDF_BOOL bPrintAsImage,
189                    FPDF_BOOL bReverse,
190                    FPDF_BOOL bAnnotations);
191   void JS_docgotoPage(int nPageNum);
192 
IsJSInitiated()193   bool IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
GetAppName()194   CFX_ByteString GetAppName() const { return ""; }
GetSysHandler()195   CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
GetFormFillInfo()196   FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
197 
198   // Creates if not present.
199   CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
200   CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();  // Creates if not present.
201   IJS_Runtime* GetJSRuntime();                    // Creates if not present.
202   CPDFSDK_ActionHandler* GetActionHander();       // Creates if not present.
203   CPDFSDK_InterForm* GetInterForm();              // Creates if not present.
204 
205  private:
206   std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
207   std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
208   std::unique_ptr<IJS_Runtime> m_pJSRuntime;
209   FPDF_FORMFILLINFO* const m_pInfo;
210   std::map<UnderlyingPageType*, std::unique_ptr<CPDFSDK_PageView>> m_PageMap;
211   std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
212   CPDFSDK_Annot::ObservedPtr m_pFocusAnnot;
213   UnderlyingDocumentType* m_pUnderlyingDoc;
214   std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller;
215   std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
216   bool m_bChangeMask;
217   bool m_bBeingDestroyed;
218 };
219 
220 #endif  // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_
221