Add type cast definitions for CPDF_Array.
[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 CPDFDoc_Environment;
14 class CPDFSDK_Annot;
15 class CPDFSDK_Document;
16 class CPDF_Bookmark;
17 class CPDF_FormField;
18
19 // Records the details of an event and triggers JS execution for it.
20 class IJS_Context {
21  public:
22   virtual FX_BOOL RunScript(const CFX_WideString& script,
23                             CFX_WideString* info) = 0;
24
25   virtual void OnApp_Init() = 0;
26
27   virtual void OnDoc_Open(CPDFSDK_Document* pDoc,
28                           const CFX_WideString& strTargetName) = 0;
29   virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc) = 0;
30   virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc) = 0;
31   virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc) = 0;
32   virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc) = 0;
33   virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc) = 0;
34
35   virtual void OnPage_Open(CPDFSDK_Document* pTarget) = 0;
36   virtual void OnPage_Close(CPDFSDK_Document* pTarget) = 0;
37   virtual void OnPage_InView(CPDFSDK_Document* pTarget) = 0;
38   virtual void OnPage_OutView(CPDFSDK_Document* pTarget) = 0;
39
40   virtual void OnField_MouseDown(FX_BOOL bModifier,
41                                  FX_BOOL bShift,
42                                  CPDF_FormField* pTarget) = 0;
43   virtual void OnField_MouseEnter(FX_BOOL bModifier,
44                                   FX_BOOL bShift,
45                                   CPDF_FormField* pTarget) = 0;
46   virtual void OnField_MouseExit(FX_BOOL bModifier,
47                                  FX_BOOL bShift,
48                                  CPDF_FormField* pTarget) = 0;
49   virtual void OnField_MouseUp(FX_BOOL bModifier,
50                                FX_BOOL bShift,
51                                CPDF_FormField* pTarget) = 0;
52   virtual void OnField_Focus(FX_BOOL bModifier,
53                              FX_BOOL bShift,
54                              CPDF_FormField* pTarget,
55                              const CFX_WideString& Value) = 0;
56   virtual void OnField_Blur(FX_BOOL bModifier,
57                             FX_BOOL bShift,
58                             CPDF_FormField* pTarget,
59                             const CFX_WideString& Value) = 0;
60
61   virtual void OnField_Calculate(CPDF_FormField* pSource,
62                                  CPDF_FormField* pTarget,
63                                  CFX_WideString& Value,
64                                  FX_BOOL& bRc) = 0;
65   virtual void OnField_Format(CPDF_FormField* pTarget,
66                               CFX_WideString& Value,
67                               FX_BOOL bWillCommit) = 0;
68   virtual void OnField_Keystroke(CFX_WideString& strChange,
69                                  const CFX_WideString& strChangeEx,
70                                  FX_BOOL KeyDown,
71                                  FX_BOOL bModifier,
72                                  int& nSelEnd,
73                                  int& nSelStart,
74                                  FX_BOOL bShift,
75                                  CPDF_FormField* pTarget,
76                                  CFX_WideString& Value,
77                                  FX_BOOL bWillCommit,
78                                  FX_BOOL bFieldFull,
79                                  FX_BOOL& bRc) = 0;
80   virtual void OnField_Validate(CFX_WideString& strChange,
81                                 const CFX_WideString& strChangeEx,
82                                 FX_BOOL bKeyDown,
83                                 FX_BOOL bModifier,
84                                 FX_BOOL bShift,
85                                 CPDF_FormField* pTarget,
86                                 CFX_WideString& Value,
87                                 FX_BOOL& bRc) = 0;
88
89   virtual void OnScreen_Focus(FX_BOOL bModifier,
90                               FX_BOOL bShift,
91                               CPDFSDK_Annot* pScreen) = 0;
92   virtual void OnScreen_Blur(FX_BOOL bModifier,
93                              FX_BOOL bShift,
94                              CPDFSDK_Annot* pScreen) = 0;
95   virtual void OnScreen_Open(FX_BOOL bModifier,
96                              FX_BOOL bShift,
97                              CPDFSDK_Annot* pScreen) = 0;
98   virtual void OnScreen_Close(FX_BOOL bModifier,
99                               FX_BOOL bShift,
100                               CPDFSDK_Annot* pScreen) = 0;
101   virtual void OnScreen_MouseDown(FX_BOOL bModifier,
102                                   FX_BOOL bShift,
103                                   CPDFSDK_Annot* pScreen) = 0;
104   virtual void OnScreen_MouseUp(FX_BOOL bModifier,
105                                 FX_BOOL bShift,
106                                 CPDFSDK_Annot* pScreen) = 0;
107   virtual void OnScreen_MouseEnter(FX_BOOL bModifier,
108                                    FX_BOOL bShift,
109                                    CPDFSDK_Annot* pScreen) = 0;
110   virtual void OnScreen_MouseExit(FX_BOOL bModifier,
111                                   FX_BOOL bShift,
112                                   CPDFSDK_Annot* pScreen) = 0;
113   virtual void OnScreen_InView(FX_BOOL bModifier,
114                                FX_BOOL bShift,
115                                CPDFSDK_Annot* pScreen) = 0;
116   virtual void OnScreen_OutView(FX_BOOL bModifier,
117                                 FX_BOOL bShift,
118                                 CPDFSDK_Annot* pScreen) = 0;
119
120   virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) = 0;
121   virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget) = 0;
122
123   virtual void OnMenu_Exec(CPDFSDK_Document* pTarget,
124                            const CFX_WideString&) = 0;
125   virtual void OnBatchExec(CPDFSDK_Document* pTarget) = 0;
126   virtual void OnConsole_Exec() = 0;
127   virtual void OnExternal_Exec() = 0;
128
129   virtual void EnableMessageBox(FX_BOOL bEnable) = 0;
130
131  protected:
132   virtual ~IJS_Context() {}
133 };
134
135 // Owns the FJXS objects needed to actually execute JS.
136 class IJS_Runtime {
137  public:
138   static void Initialize(unsigned int slot, void* isolate);
139   static IJS_Runtime* Create(CPDFDoc_Environment* pEnv);
140   virtual ~IJS_Runtime() {}
141
142   virtual IJS_Context* NewContext() = 0;
143   virtual void ReleaseContext(IJS_Context* pContext) = 0;
144   virtual IJS_Context* GetCurrentContext() = 0;
145   virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0;
146   virtual CPDFSDK_Document* GetReaderDocument() = 0;
147   virtual int Execute(IJS_Context* cc,
148                       const wchar_t* script,
149                       CFX_WideString* info) = 0;
150
151  protected:
152   IJS_Runtime() {}
153 };
154
155 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_