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