Merge to XFA: Return error information from pdfium to JS.
[pdfium.git] / fpdfsdk / include / javascript / IJavaScript.h
1 // Copyright 2014 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 _IJAVASCRIPT_H_
8 #define _IJAVASCRIPT_H_
9
10 #include "../../../core/include/fxcrt/fx_basic.h"
11 #include "../../../xfa/include/fxjse/fxjse.h"
12
13 class CPDF_Bookmark;
14 class CPDF_FormField;
15 class CPDFSDK_Annot;
16 class CPDFSDK_Document;
17
18 class IFXJS_Context
19 {
20 public:
21         virtual ~IFXJS_Context() { }
22         virtual FX_BOOL                         Compile(const CFX_WideString& script, CFX_WideString& info) = 0;
23         virtual FX_BOOL                         RunScript(const CFX_WideString& script, CFX_WideString& info) = 0;
24
25         virtual void                            OnApp_Init() = 0;
26
27         virtual void                            OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName) = 0;
28         virtual void                            OnDoc_WillPrint(CPDFSDK_Document* pDoc) = 0;
29         virtual void                            OnDoc_DidPrint(CPDFSDK_Document* pDoc) = 0;
30         virtual void                            OnDoc_WillSave(CPDFSDK_Document* pDoc) = 0;
31         virtual void                            OnDoc_DidSave(CPDFSDK_Document* pDoc) = 0;
32         virtual void                            OnDoc_WillClose(CPDFSDK_Document* pDoc) = 0;
33
34         virtual void                            OnPage_Open(CPDFSDK_Document* pTarget) = 0;
35         virtual void                            OnPage_Close(CPDFSDK_Document* pTarget) = 0;
36         virtual void                            OnPage_InView(CPDFSDK_Document* pTarget) = 0;
37         virtual void                            OnPage_OutView(CPDFSDK_Document* pTarget) = 0;
38
39         virtual void                            OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0;
40         virtual void                            OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0;
41         virtual void                            OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0;
42         virtual void                            OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) = 0;
43         virtual void                            OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value) = 0;
44         virtual void                            OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value) = 0;
45
46         virtual void                            OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc) = 0;
47         virtual void                            OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit) = 0;
48         virtual void                            OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx,
49                                                                         FX_BOOL KeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart, FX_BOOL bShift,
50                                                                         CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit, 
51                                                                         FX_BOOL bFieldFull, FX_BOOL &bRc) = 0;
52         virtual void                            OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx, FX_BOOL bKeyDown,
53                                                                         FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc) = 0;
54
55         virtual void                            OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
56         virtual void                            OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
57         virtual void                            OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
58         virtual void                            OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
59         virtual void                            OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
60         virtual void                            OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
61         virtual void                            OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
62         virtual void                            OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
63         virtual void                            OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
64         virtual void                            OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) = 0;
65
66         virtual void                            OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) = 0;
67         virtual void                            OnLink_MouseUp(CPDFSDK_Document* pTarget) = 0;
68
69         virtual void                            OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString &) = 0;
70         virtual void                            OnBatchExec(CPDFSDK_Document* pTarget) = 0;
71         virtual void                            OnConsole_Exec() = 0;
72         virtual void                            OnExternal_Exec() = 0;
73
74         virtual void                            EnableMessageBox(FX_BOOL bEnable) = 0;
75 };
76
77 class IFXJS_Runtime
78 {
79 public:
80         virtual IFXJS_Context*          NewContext() = 0;
81         virtual void                            ReleaseContext(IFXJS_Context * pContext) = 0;
82         virtual IFXJS_Context*          GetCurrentContext() = 0;
83
84         virtual void                            SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0;
85
86         virtual CPDFSDK_Document*       GetReaderDocument() = 0;
87
88         virtual FX_BOOL                         GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue) = 0;
89         virtual FX_BOOL                         SetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue) = 0;
90
91 protected:
92          ~IFXJS_Runtime() { }
93 };
94
95 class CPDFDoc_Environment;
96 class CJS_GlobalData;
97
98 class CJS_RuntimeFactory
99 {
100 public:
101         CJS_RuntimeFactory():m_bInit(FALSE),m_nRef(0),m_pGlobalData(NULL),m_nGlobalDataCount(0) {}
102         ~CJS_RuntimeFactory();
103         IFXJS_Runtime*                                  NewJSRuntime(CPDFDoc_Environment* pApp);
104         void                                                    DeleteJSRuntime(IFXJS_Runtime* pRuntime);
105         void                                                    AddRef();
106         void                                                    Release();
107
108         CJS_GlobalData*                                 NewGlobalData(CPDFDoc_Environment* pApp);
109         void                                                    ReleaseGlobalData();
110 private:
111         FX_BOOL m_bInit;
112         int m_nRef;
113         CJS_GlobalData*                                 m_pGlobalData;
114         FX_INT32                                                m_nGlobalDataCount;
115 };
116
117 #endif //_IJAVASCRIPT_H_
118