• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_CJS_EVENT_CONTEXT_H_
8 #define FPDFSDK_JAVASCRIPT_CJS_EVENT_CONTEXT_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/fx_string.h"
13 #include "core/fxcrt/fx_system.h"
14 #include "fpdfsdk/javascript/ijs_event_context.h"
15 
16 class CJS_EventHandler;
17 class CJS_Runtime;
18 class CPDFSDK_FormFillEnvironment;
19 
20 class CJS_EventContext : public IJS_EventContext {
21  public:
22   explicit CJS_EventContext(CJS_Runtime* pRuntime);
23   ~CJS_EventContext() override;
24 
25   // IJS_EventContext
26   bool RunScript(const CFX_WideString& script, CFX_WideString* info) override;
27   void OnApp_Init() override;
28   void OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv,
29                   const CFX_WideString& strTargetName) override;
30   void OnDoc_WillPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
31   void OnDoc_DidPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
32   void OnDoc_WillSave(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
33   void OnDoc_DidSave(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
34   void OnDoc_WillClose(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
35   void OnPage_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
36   void OnPage_Close(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
37   void OnPage_InView(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
38   void OnPage_OutView(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
39   void OnField_MouseDown(bool bModifier,
40                          bool bShift,
41                          CPDF_FormField* pTarget) override;
42   void OnField_MouseEnter(bool bModifier,
43                           bool bShift,
44                           CPDF_FormField* pTarget) override;
45   void OnField_MouseExit(bool bModifier,
46                          bool bShift,
47                          CPDF_FormField* pTarget) override;
48   void OnField_MouseUp(bool bModifier,
49                        bool bShift,
50                        CPDF_FormField* pTarget) override;
51   void OnField_Focus(bool bModifier,
52                      bool bShift,
53                      CPDF_FormField* pTarget,
54                      const CFX_WideString& Value) override;
55   void OnField_Blur(bool bModifier,
56                     bool bShift,
57                     CPDF_FormField* pTarget,
58                     const CFX_WideString& Value) override;
59   void OnField_Calculate(CPDF_FormField* pSource,
60                          CPDF_FormField* pTarget,
61                          CFX_WideString& Value,
62                          bool& bRc) override;
63   void OnField_Format(CPDF_FormField* pTarget,
64                       CFX_WideString& Value,
65                       bool bWillCommit) override;
66   void OnField_Keystroke(CFX_WideString& strChange,
67                          const CFX_WideString& strChangeEx,
68                          bool bKeyDown,
69                          bool bModifier,
70                          int& nSelEnd,
71                          int& nSelStart,
72                          bool bShift,
73                          CPDF_FormField* pTarget,
74                          CFX_WideString& Value,
75                          bool bWillCommit,
76                          bool bFieldFull,
77                          bool& bRc) override;
78   void OnField_Validate(CFX_WideString& strChange,
79                         const CFX_WideString& strChangeEx,
80                         bool bKeyDown,
81                         bool bModifier,
82                         bool bShift,
83                         CPDF_FormField* pTarget,
84                         CFX_WideString& Value,
85                         bool& bRc) override;
86   void OnScreen_Focus(bool bModifier,
87                       bool bShift,
88                       CPDFSDK_Annot* pScreen) override;
89   void OnScreen_Blur(bool bModifier,
90                      bool bShift,
91                      CPDFSDK_Annot* pScreen) override;
92   void OnScreen_Open(bool bModifier,
93                      bool bShift,
94                      CPDFSDK_Annot* pScreen) override;
95   void OnScreen_Close(bool bModifier,
96                       bool bShift,
97                       CPDFSDK_Annot* pScreen) override;
98   void OnScreen_MouseDown(bool bModifier,
99                           bool bShift,
100                           CPDFSDK_Annot* pScreen) override;
101   void OnScreen_MouseUp(bool bModifier,
102                         bool bShift,
103                         CPDFSDK_Annot* pScreen) override;
104   void OnScreen_MouseEnter(bool bModifier,
105                            bool bShift,
106                            CPDFSDK_Annot* pScreen) override;
107   void OnScreen_MouseExit(bool bModifier,
108                           bool bShift,
109                           CPDFSDK_Annot* pScreen) override;
110   void OnScreen_InView(bool bModifier,
111                        bool bShift,
112                        CPDFSDK_Annot* pScreen) override;
113   void OnScreen_OutView(bool bModifier,
114                         bool bShift,
115                         CPDFSDK_Annot* pScreen) override;
116   void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) override;
117   void OnLink_MouseUp(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
118   void OnMenu_Exec(CPDFSDK_FormFillEnvironment* pFormFillEnv,
119                    const CFX_WideString& strTargetName) override;
120   void OnBatchExec(CPDFSDK_FormFillEnvironment* pFormFillEnv) override;
121   void OnConsole_Exec() override;
122   void OnExternal_Exec() override;
123 
GetJSRuntime()124   CJS_Runtime* GetJSRuntime() const { return m_pRuntime; }
GetEventHandler()125   CJS_EventHandler* GetEventHandler() const { return m_pEventHandler.get(); }
126 
127   CPDFSDK_FormFillEnvironment* GetFormFillEnv();
128 
129  private:
130   CJS_Runtime* const m_pRuntime;
131   std::unique_ptr<CJS_EventHandler> m_pEventHandler;
132   bool m_bBusy;
133 };
134 
135 #endif  // FPDFSDK_JAVASCRIPT_CJS_EVENT_CONTEXT_H_
136