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