Rename Init methods to more accurately describe purpose
[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 FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_
9
10 #include "../../../core/include/fxcrt/fx_string.h"
11 #include "../../../core/include/fxcrt/fx_system.h"
12
13 class CPDF_Bookmark;
14 class CPDF_FormField;
15 class CPDFSDK_Annot;
16 class CPDFSDK_Document;
17
18 class IFXJS_Context {
19  public:
20   virtual FX_BOOL RunScript(const CFX_WideString& script,
21                             CFX_WideString& info) = 0;
22
23   virtual void OnApp_Init() = 0;
24
25   virtual void OnDoc_Open(CPDFSDK_Document* pDoc,
26                           const CFX_WideString& strTargetName) = 0;
27   virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc) = 0;
28   virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc) = 0;
29   virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc) = 0;
30   virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc) = 0;
31   virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc) = 0;
32
33   virtual void OnPage_Open(CPDFSDK_Document* pTarget) = 0;
34   virtual void OnPage_Close(CPDFSDK_Document* pTarget) = 0;
35   virtual void OnPage_InView(CPDFSDK_Document* pTarget) = 0;
36   virtual void OnPage_OutView(CPDFSDK_Document* pTarget) = 0;
37
38   virtual void OnField_MouseDown(FX_BOOL bModifier,
39                                  FX_BOOL bShift,
40                                  CPDF_FormField* pTarget) = 0;
41   virtual void OnField_MouseEnter(FX_BOOL bModifier,
42                                   FX_BOOL bShift,
43                                   CPDF_FormField* pTarget) = 0;
44   virtual void OnField_MouseExit(FX_BOOL bModifier,
45                                  FX_BOOL bShift,
46                                  CPDF_FormField* pTarget) = 0;
47   virtual void OnField_MouseUp(FX_BOOL bModifier,
48                                FX_BOOL bShift,
49                                CPDF_FormField* pTarget) = 0;
50   virtual void OnField_Focus(FX_BOOL bModifier,
51                              FX_BOOL bShift,
52                              CPDF_FormField* pTarget,
53                              const CFX_WideString& Value) = 0;
54   virtual void OnField_Blur(FX_BOOL bModifier,
55                             FX_BOOL bShift,
56                             CPDF_FormField* pTarget,
57                             const CFX_WideString& Value) = 0;
58
59   virtual void OnField_Calculate(CPDF_FormField* pSource,
60                                  CPDF_FormField* pTarget,
61                                  CFX_WideString& Value,
62                                  FX_BOOL& bRc) = 0;
63   virtual void OnField_Format(CPDF_FormField* pTarget,
64                               CFX_WideString& Value,
65                               FX_BOOL bWillCommit) = 0;
66   virtual void OnField_Keystroke(CFX_WideString& strChange,
67                                  const CFX_WideString& strChangeEx,
68                                  FX_BOOL KeyDown,
69                                  FX_BOOL bModifier,
70                                  int& nSelEnd,
71                                  int& nSelStart,
72                                  FX_BOOL bShift,
73                                  CPDF_FormField* pTarget,
74                                  CFX_WideString& Value,
75                                  FX_BOOL bWillCommit,
76                                  FX_BOOL bFieldFull,
77                                  FX_BOOL& bRc) = 0;
78   virtual void OnField_Validate(CFX_WideString& strChange,
79                                 const CFX_WideString& strChangeEx,
80                                 FX_BOOL bKeyDown,
81                                 FX_BOOL bModifier,
82                                 FX_BOOL bShift,
83                                 CPDF_FormField* pTarget,
84                                 CFX_WideString& Value,
85                                 FX_BOOL& bRc) = 0;
86
87   virtual void OnScreen_Focus(FX_BOOL bModifier,
88                               FX_BOOL bShift,
89                               CPDFSDK_Annot* pScreen) = 0;
90   virtual void OnScreen_Blur(FX_BOOL bModifier,
91                              FX_BOOL bShift,
92                              CPDFSDK_Annot* pScreen) = 0;
93   virtual void OnScreen_Open(FX_BOOL bModifier,
94                              FX_BOOL bShift,
95                              CPDFSDK_Annot* pScreen) = 0;
96   virtual void OnScreen_Close(FX_BOOL bModifier,
97                               FX_BOOL bShift,
98                               CPDFSDK_Annot* pScreen) = 0;
99   virtual void OnScreen_MouseDown(FX_BOOL bModifier,
100                                   FX_BOOL bShift,
101                                   CPDFSDK_Annot* pScreen) = 0;
102   virtual void OnScreen_MouseUp(FX_BOOL bModifier,
103                                 FX_BOOL bShift,
104                                 CPDFSDK_Annot* pScreen) = 0;
105   virtual void OnScreen_MouseEnter(FX_BOOL bModifier,
106                                    FX_BOOL bShift,
107                                    CPDFSDK_Annot* pScreen) = 0;
108   virtual void OnScreen_MouseExit(FX_BOOL bModifier,
109                                   FX_BOOL bShift,
110                                   CPDFSDK_Annot* pScreen) = 0;
111   virtual void OnScreen_InView(FX_BOOL bModifier,
112                                FX_BOOL bShift,
113                                CPDFSDK_Annot* pScreen) = 0;
114   virtual void OnScreen_OutView(FX_BOOL bModifier,
115                                 FX_BOOL bShift,
116                                 CPDFSDK_Annot* pScreen) = 0;
117
118   virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) = 0;
119   virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget) = 0;
120
121   virtual void OnMenu_Exec(CPDFSDK_Document* pTarget,
122                            const CFX_WideString&) = 0;
123   virtual void OnBatchExec(CPDFSDK_Document* pTarget) = 0;
124   virtual void OnConsole_Exec() = 0;
125   virtual void OnExternal_Exec() = 0;
126
127   virtual void EnableMessageBox(FX_BOOL bEnable) = 0;
128
129  protected:
130   virtual ~IFXJS_Context() {}
131 };
132
133 class IFXJS_Runtime {
134  public:
135   virtual IFXJS_Context* NewContext() = 0;
136   virtual void ReleaseContext(IFXJS_Context* pContext) = 0;
137   virtual IFXJS_Context* GetCurrentContext() = 0;
138
139   virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0;
140   virtual CPDFSDK_Document* GetReaderDocument() = 0;
141
142  protected:
143   virtual ~IFXJS_Runtime() {}
144 };
145
146 class CPDFDoc_Environment;
147 class CJS_GlobalData;
148
149 class CJS_RuntimeFactory {
150  public:
151   CJS_RuntimeFactory()
152       : m_bInit(FALSE), m_nRef(0), m_pGlobalData(NULL), m_nGlobalDataCount(0) {}
153   ~CJS_RuntimeFactory();
154   IFXJS_Runtime* NewJSRuntime(CPDFDoc_Environment* pApp);
155   void DeleteJSRuntime(IFXJS_Runtime* pRuntime);
156   void AddRef();
157   void Release();
158
159   CJS_GlobalData* NewGlobalData(CPDFDoc_Environment* pApp);
160   void ReleaseGlobalData();
161
162  private:
163   FX_BOOL m_bInit;
164   int m_nRef;
165   CJS_GlobalData* m_pGlobalData;
166   int32_t m_nGlobalDataCount;
167 };
168
169 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_