clang-format all pdfium code.
[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 ~IFXJS_Context() {}
21   virtual FX_BOOL Compile(const CFX_WideString& script,
22                           CFX_WideString& info) = 0;
23   virtual FX_BOOL RunScript(const CFX_WideString& script,
24                             CFX_WideString& info) = 0;
25
26   virtual void OnApp_Init() = 0;
27
28   virtual void OnDoc_Open(CPDFSDK_Document* pDoc,
29                           const CFX_WideString& strTargetName) = 0;
30   virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc) = 0;
31   virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc) = 0;
32   virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc) = 0;
33   virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc) = 0;
34   virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc) = 0;
35
36   virtual void OnPage_Open(CPDFSDK_Document* pTarget) = 0;
37   virtual void OnPage_Close(CPDFSDK_Document* pTarget) = 0;
38   virtual void OnPage_InView(CPDFSDK_Document* pTarget) = 0;
39   virtual void OnPage_OutView(CPDFSDK_Document* pTarget) = 0;
40
41   virtual void OnField_MouseDown(FX_BOOL bModifier,
42                                  FX_BOOL bShift,
43                                  CPDF_FormField* pTarget) = 0;
44   virtual void OnField_MouseEnter(FX_BOOL bModifier,
45                                   FX_BOOL bShift,
46                                   CPDF_FormField* pTarget) = 0;
47   virtual void OnField_MouseExit(FX_BOOL bModifier,
48                                  FX_BOOL bShift,
49                                  CPDF_FormField* pTarget) = 0;
50   virtual void OnField_MouseUp(FX_BOOL bModifier,
51                                FX_BOOL bShift,
52                                CPDF_FormField* pTarget) = 0;
53   virtual void OnField_Focus(FX_BOOL bModifier,
54                              FX_BOOL bShift,
55                              CPDF_FormField* pTarget,
56                              const CFX_WideString& Value) = 0;
57   virtual void OnField_Blur(FX_BOOL bModifier,
58                             FX_BOOL bShift,
59                             CPDF_FormField* pTarget,
60                             const CFX_WideString& Value) = 0;
61
62   virtual void OnField_Calculate(CPDF_FormField* pSource,
63                                  CPDF_FormField* pTarget,
64                                  CFX_WideString& Value,
65                                  FX_BOOL& bRc) = 0;
66   virtual void OnField_Format(CPDF_FormField* pTarget,
67                               CFX_WideString& Value,
68                               FX_BOOL bWillCommit) = 0;
69   virtual void OnField_Keystroke(CFX_WideString& strChange,
70                                  const CFX_WideString& strChangeEx,
71                                  FX_BOOL KeyDown,
72                                  FX_BOOL bModifier,
73                                  int& nSelEnd,
74                                  int& nSelStart,
75                                  FX_BOOL bShift,
76                                  CPDF_FormField* pTarget,
77                                  CFX_WideString& Value,
78                                  FX_BOOL bWillCommit,
79                                  FX_BOOL bFieldFull,
80                                  FX_BOOL& bRc) = 0;
81   virtual void OnField_Validate(CFX_WideString& strChange,
82                                 const CFX_WideString& strChangeEx,
83                                 FX_BOOL bKeyDown,
84                                 FX_BOOL bModifier,
85                                 FX_BOOL bShift,
86                                 CPDF_FormField* pTarget,
87                                 CFX_WideString& Value,
88                                 FX_BOOL& bRc) = 0;
89
90   virtual void OnScreen_Focus(FX_BOOL bModifier,
91                               FX_BOOL bShift,
92                               CPDFSDK_Annot* pScreen) = 0;
93   virtual void OnScreen_Blur(FX_BOOL bModifier,
94                              FX_BOOL bShift,
95                              CPDFSDK_Annot* pScreen) = 0;
96   virtual void OnScreen_Open(FX_BOOL bModifier,
97                              FX_BOOL bShift,
98                              CPDFSDK_Annot* pScreen) = 0;
99   virtual void OnScreen_Close(FX_BOOL bModifier,
100                               FX_BOOL bShift,
101                               CPDFSDK_Annot* pScreen) = 0;
102   virtual void OnScreen_MouseDown(FX_BOOL bModifier,
103                                   FX_BOOL bShift,
104                                   CPDFSDK_Annot* pScreen) = 0;
105   virtual void OnScreen_MouseUp(FX_BOOL bModifier,
106                                 FX_BOOL bShift,
107                                 CPDFSDK_Annot* pScreen) = 0;
108   virtual void OnScreen_MouseEnter(FX_BOOL bModifier,
109                                    FX_BOOL bShift,
110                                    CPDFSDK_Annot* pScreen) = 0;
111   virtual void OnScreen_MouseExit(FX_BOOL bModifier,
112                                   FX_BOOL bShift,
113                                   CPDFSDK_Annot* pScreen) = 0;
114   virtual void OnScreen_InView(FX_BOOL bModifier,
115                                FX_BOOL bShift,
116                                CPDFSDK_Annot* pScreen) = 0;
117   virtual void OnScreen_OutView(FX_BOOL bModifier,
118                                 FX_BOOL bShift,
119                                 CPDFSDK_Annot* pScreen) = 0;
120
121   virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) = 0;
122   virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget) = 0;
123
124   virtual void OnMenu_Exec(CPDFSDK_Document* pTarget,
125                            const CFX_WideString&) = 0;
126   virtual void OnBatchExec(CPDFSDK_Document* pTarget) = 0;
127   virtual void OnConsole_Exec() = 0;
128   virtual void OnExternal_Exec() = 0;
129
130   virtual void EnableMessageBox(FX_BOOL bEnable) = 0;
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   ~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_