clang-format all pdfium code.
[pdfium.git] / fpdfsdk / include / javascript / JS_Context.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_JS_CONTEXT_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_CONTEXT_H_
9
10 #include "../../../core/include/fxcrt/fx_system.h"
11 #include "../../../core/include/fxcrt/fx_string.h"
12 #include "IJavaScript.h"
13
14 class CJS_EventHandler;
15 class CJS_Runtime;
16
17 class CJS_Context : public IFXJS_Context {
18  public:
19   CJS_Context(CJS_Runtime* pRuntime);
20   virtual ~CJS_Context();
21
22  public:
23   virtual FX_BOOL Compile(const CFX_WideString& script, CFX_WideString& info);
24   virtual FX_BOOL RunScript(const CFX_WideString& script, CFX_WideString& info);
25
26  public:
27   virtual void OnApp_Init();
28
29   virtual void OnDoc_Open(CPDFSDK_Document* pDoc,
30                           const CFX_WideString& strTargetName);
31   virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc);
32   virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc);
33   virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc);
34   virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc);
35   virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc);
36
37   virtual void OnPage_Open(CPDFSDK_Document* pTarget);
38   virtual void OnPage_Close(CPDFSDK_Document* pTarget);
39   virtual void OnPage_InView(CPDFSDK_Document* pTarget);
40   virtual void OnPage_OutView(CPDFSDK_Document* pTarget);
41
42   virtual void OnField_MouseDown(FX_BOOL bModifier,
43                                  FX_BOOL bShift,
44                                  CPDF_FormField* pTarget);
45   virtual void OnField_MouseEnter(FX_BOOL bModifier,
46                                   FX_BOOL bShift,
47                                   CPDF_FormField* pTarget);
48   virtual void OnField_MouseExit(FX_BOOL bModifier,
49                                  FX_BOOL bShift,
50                                  CPDF_FormField* pTarget);
51   virtual void OnField_MouseUp(FX_BOOL bModifier,
52                                FX_BOOL bShift,
53                                CPDF_FormField* pTarget);
54   virtual void OnField_Focus(FX_BOOL bModifier,
55                              FX_BOOL bShift,
56                              CPDF_FormField* pTarget,
57                              const CFX_WideString& Value);
58   virtual void OnField_Blur(FX_BOOL bModifier,
59                             FX_BOOL bShift,
60                             CPDF_FormField* pTarget,
61                             const CFX_WideString& Value);
62
63   virtual void OnField_Calculate(CPDF_FormField* pSource,
64                                  CPDF_FormField* pTarget,
65                                  CFX_WideString& Value,
66                                  FX_BOOL& bRc);
67   virtual void OnField_Format(CPDF_FormField* pTarget,
68                               CFX_WideString& Value,
69                               FX_BOOL bWillCommit);
70   virtual void OnField_Keystroke(CFX_WideString& strChange,
71                                  const CFX_WideString& strChangeEx,
72                                  FX_BOOL bKeyDown,
73                                  FX_BOOL bModifier,
74                                  int& nSelEnd,
75                                  int& nSelStart,
76                                  FX_BOOL bShift,
77                                  CPDF_FormField* pTarget,
78                                  CFX_WideString& Value,
79                                  FX_BOOL bWillCommit,
80                                  FX_BOOL bFieldFull,
81                                  FX_BOOL& bRc);
82   virtual void OnField_Validate(CFX_WideString& strChange,
83                                 const CFX_WideString& strChangeEx,
84                                 FX_BOOL bKeyDown,
85                                 FX_BOOL bModifier,
86                                 FX_BOOL bShift,
87                                 CPDF_FormField* pTarget,
88                                 CFX_WideString& Value,
89                                 FX_BOOL& bRc);
90
91   virtual void OnScreen_Focus(FX_BOOL bModifier,
92                               FX_BOOL bShift,
93                               CPDFSDK_Annot* pScreen);
94   virtual void OnScreen_Blur(FX_BOOL bModifier,
95                              FX_BOOL bShift,
96                              CPDFSDK_Annot* pScreen);
97   virtual void OnScreen_Open(FX_BOOL bModifier,
98                              FX_BOOL bShift,
99                              CPDFSDK_Annot* pScreen);
100   virtual void OnScreen_Close(FX_BOOL bModifier,
101                               FX_BOOL bShift,
102                               CPDFSDK_Annot* pScreen);
103   virtual void OnScreen_MouseDown(FX_BOOL bModifier,
104                                   FX_BOOL bShift,
105                                   CPDFSDK_Annot* pScreen);
106   virtual void OnScreen_MouseUp(FX_BOOL bModifier,
107                                 FX_BOOL bShift,
108                                 CPDFSDK_Annot* pScreen);
109   virtual void OnScreen_MouseEnter(FX_BOOL bModifier,
110                                    FX_BOOL bShift,
111                                    CPDFSDK_Annot* pScreen);
112   virtual void OnScreen_MouseExit(FX_BOOL bModifier,
113                                   FX_BOOL bShift,
114                                   CPDFSDK_Annot* pScreen);
115   virtual void OnScreen_InView(FX_BOOL bModifier,
116                                FX_BOOL bShift,
117                                CPDFSDK_Annot* pScreen);
118   virtual void OnScreen_OutView(FX_BOOL bModifier,
119                                 FX_BOOL bShift,
120                                 CPDFSDK_Annot* pScreen);
121
122   virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark);
123   virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget);
124
125   virtual void OnMenu_Exec(CPDFSDK_Document* pTarget,
126                            const CFX_WideString& strTargetName);
127   virtual void OnBatchExec(CPDFSDK_Document* pTarget);
128   virtual void OnConsole_Exec();
129   virtual void OnExternal_Exec();
130
131   virtual void EnableMessageBox(FX_BOOL bEnable) { m_bMsgBoxEnable = bEnable; }
132   FX_BOOL IsMsgBoxEnabled() const { return m_bMsgBoxEnable; }
133
134  public:
135   CPDFDoc_Environment* GetReaderApp();
136   CJS_Runtime* GetJSRuntime() { return m_pRuntime; }
137
138   FX_BOOL DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info);
139
140   CJS_EventHandler* GetEventHandler() { return m_pEventHandler; };
141   CPDFSDK_Document* GetReaderDocument();
142
143  private:
144   CJS_Runtime* m_pRuntime;
145   CJS_EventHandler* m_pEventHandler;
146
147   FX_BOOL m_bBusy;
148   FX_BOOL m_bMsgBoxEnable;
149 };
150
151 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_JS_CONTEXT_H_