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_EventRecorder; 18 class CJS_Field; 19 class CJS_Runtime; 20 class CPDFSDK_FormFillEnvironment; 21 22 class CJS_EventContext final : public IJS_EventContext { 23 public: 24 explicit CJS_EventContext(CJS_Runtime* pRuntime); 25 ~CJS_EventContext() override; 26 27 // IJS_EventContext 28 Optional<IJS_Runtime::JS_Error> RunScript(const WideString& script) override; 29 void OnApp_Init() override; 30 void OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv, 31 const WideString& strTargetName) override; 32 void OnDoc_WillPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 33 void OnDoc_DidPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 34 void OnDoc_WillSave(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 35 void OnDoc_DidSave(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 36 void OnDoc_WillClose(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 37 void OnPage_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 38 void OnPage_Close(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 39 void OnPage_InView(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 40 void OnPage_OutView(CPDFSDK_FormFillEnvironment* pFormFillEnv) override; 41 void OnField_MouseDown(bool bModifier, 42 bool bShift, 43 CPDF_FormField* pTarget) override; 44 void OnField_MouseEnter(bool bModifier, 45 bool bShift, 46 CPDF_FormField* pTarget) override; 47 void OnField_MouseExit(bool bModifier, 48 bool bShift, 49 CPDF_FormField* pTarget) override; 50 void OnField_MouseUp(bool bModifier, 51 bool bShift, 52 CPDF_FormField* pTarget) override; 53 void OnField_Focus(bool bModifier, 54 bool bShift, 55 CPDF_FormField* pTarget, 56 WideString* Value) override; 57 void OnField_Blur(bool bModifier, 58 bool bShift, 59 CPDF_FormField* pTarget, 60 WideString* Value) override; 61 void OnField_Calculate(CPDF_FormField* pSource, 62 CPDF_FormField* pTarget, 63 WideString* pValue, 64 bool* pRc) override; 65 void OnField_Format(CPDF_FormField* pTarget, WideString* Value) override; 66 void OnField_Keystroke(WideString* strChange, 67 const WideString& strChangeEx, 68 bool bKeyDown, 69 bool bModifier, 70 int* nSelEnd, 71 int* nSelStart, 72 bool bShift, 73 CPDF_FormField* pTarget, 74 WideString* Value, 75 bool bWillCommit, 76 bool bFieldFull, 77 bool* bRc) override; 78 void OnField_Validate(WideString* strChange, 79 const WideString& strChangeEx, 80 bool bKeyDown, 81 bool bModifier, 82 bool bShift, 83 CPDF_FormField* pTarget, 84 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 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.Get(); } GetEventRecorder()125 CJS_EventRecorder* GetEventRecorder() const { return m_pEventRecorder.get(); } 126 CPDFSDK_FormFillEnvironment* GetFormFillEnv(); 127 CJS_Field* SourceField(); 128 CJS_Field* TargetField(); 129 130 private: 131 UnownedPtr<CJS_Runtime> const m_pRuntime; 132 std::unique_ptr<CJS_EventRecorder> m_pEventRecorder; 133 bool m_bBusy = false; 134 }; 135 136 #endif // FXJS_CJS_EVENT_CONTEXT_H_ 137