1 // Copyright 2016 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 FXJS_IJS_EVENT_CONTEXT_H_
8 #define FXJS_IJS_EVENT_CONTEXT_H_
9 
10 #include "core/fxcrt/fx_string.h"
11 #include "core/fxcrt/fx_system.h"
12 #include "fxjs/ijs_runtime.h"
13 #include "third_party/base/optional.h"
14 
15 class CPDF_Bookmark;
16 class CPDF_FormField;
17 class CPDFSDK_Annot;
18 class CPDFSDK_FormFillEnvironment;
19 
20 // Records the details of an event and triggers JS execution for it. There
21 // can be more than one of these at any given time, as JS callbacks to C++
22 // may trigger new events on top of one another.
23 class IJS_EventContext {
24  public:
25   virtual ~IJS_EventContext() = default;
26 
27   virtual Optional<IJS_Runtime::JS_Error> RunScript(
28       const WideString& script) = 0;
29 
30   virtual void OnApp_Init() = 0;
31 
32   virtual void OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv,
33                           const WideString& strTargetName) = 0;
34   virtual void OnDoc_WillPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
35   virtual void OnDoc_DidPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
36   virtual void OnDoc_WillSave(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
37   virtual void OnDoc_DidSave(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
38   virtual void OnDoc_WillClose(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
39 
40   virtual void OnPage_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
41   virtual void OnPage_Close(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
42   virtual void OnPage_InView(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
43   virtual void OnPage_OutView(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
44 
45   virtual void OnField_MouseDown(bool bModifier,
46                                  bool bShift,
47                                  CPDF_FormField* pTarget) = 0;
48   virtual void OnField_MouseEnter(bool bModifier,
49                                   bool bShift,
50                                   CPDF_FormField* pTarget) = 0;
51   virtual void OnField_MouseExit(bool bModifier,
52                                  bool bShift,
53                                  CPDF_FormField* pTarget) = 0;
54   virtual void OnField_MouseUp(bool bModifier,
55                                bool bShift,
56                                CPDF_FormField* pTarget) = 0;
57   virtual void OnField_Focus(bool bModifier,
58                              bool bShift,
59                              CPDF_FormField* pTarget,
60                              WideString* Value) = 0;
61   virtual void OnField_Blur(bool bModifier,
62                             bool bShift,
63                             CPDF_FormField* pTarget,
64                             WideString* Value) = 0;
65   virtual void OnField_Calculate(CPDF_FormField* pSource,
66                                  CPDF_FormField* pTarget,
67                                  WideString* Value,
68                                  bool* bRc) = 0;
69   virtual void OnField_Format(CPDF_FormField* pTarget, WideString* Value) = 0;
70   virtual void OnField_Keystroke(WideString* strChange,
71                                  const WideString& strChangeEx,
72                                  bool KeyDown,
73                                  bool bModifier,
74                                  int* nSelEnd,
75                                  int* nSelStart,
76                                  bool bShift,
77                                  CPDF_FormField* pTarget,
78                                  WideString* Value,
79                                  bool bWillCommit,
80                                  bool bFieldFull,
81                                  bool* bRc) = 0;
82   virtual void OnField_Validate(WideString* strChange,
83                                 const WideString& strChangeEx,
84                                 bool bKeyDown,
85                                 bool bModifier,
86                                 bool bShift,
87                                 CPDF_FormField* pTarget,
88                                 WideString* Value,
89                                 bool* bRc) = 0;
90 
91   virtual void OnScreen_Focus(bool bModifier,
92                               bool bShift,
93                               CPDFSDK_Annot* pScreen) = 0;
94   virtual void OnScreen_Blur(bool bModifier,
95                              bool bShift,
96                              CPDFSDK_Annot* pScreen) = 0;
97   virtual void OnScreen_Open(bool bModifier,
98                              bool bShift,
99                              CPDFSDK_Annot* pScreen) = 0;
100   virtual void OnScreen_Close(bool bModifier,
101                               bool bShift,
102                               CPDFSDK_Annot* pScreen) = 0;
103   virtual void OnScreen_MouseDown(bool bModifier,
104                                   bool bShift,
105                                   CPDFSDK_Annot* pScreen) = 0;
106   virtual void OnScreen_MouseUp(bool bModifier,
107                                 bool bShift,
108                                 CPDFSDK_Annot* pScreen) = 0;
109   virtual void OnScreen_MouseEnter(bool bModifier,
110                                    bool bShift,
111                                    CPDFSDK_Annot* pScreen) = 0;
112   virtual void OnScreen_MouseExit(bool bModifier,
113                                   bool bShift,
114                                   CPDFSDK_Annot* pScreen) = 0;
115   virtual void OnScreen_InView(bool bModifier,
116                                bool bShift,
117                                CPDFSDK_Annot* pScreen) = 0;
118   virtual void OnScreen_OutView(bool bModifier,
119                                 bool bShift,
120                                 CPDFSDK_Annot* pScreen) = 0;
121 
122   virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) = 0;
123   virtual void OnLink_MouseUp(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
124 
125   virtual void OnMenu_Exec(CPDFSDK_FormFillEnvironment* pFormFillEnv,
126                            const WideString&) = 0;
127   virtual void OnBatchExec(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
128   virtual void OnConsole_Exec() = 0;
129   virtual void OnExternal_Exec() = 0;
130 };
131 
132 #endif  // FXJS_IJS_EVENT_CONTEXT_H_
133