1 // Copyright 2016 The PDFium Authors 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 <optional> 11 12 #include "core/fxcrt/widestring.h" 13 #include "fxjs/ijs_runtime.h" 14 15 class CPDF_FormField; 16 17 // Records the details of an event and triggers JS execution for it. There 18 // can be more than one of these at any given time, as JS callbacks to C++ 19 // may trigger new events on top of one another. 20 class IJS_EventContext { 21 public: 22 virtual ~IJS_EventContext() = default; 23 24 virtual std::optional<IJS_Runtime::JS_Error> RunScript( 25 const WideString& script) = 0; 26 27 virtual void OnDoc_Open(const WideString& strTargetName) = 0; 28 virtual void OnDoc_WillPrint() = 0; 29 virtual void OnDoc_DidPrint() = 0; 30 virtual void OnDoc_WillSave() = 0; 31 virtual void OnDoc_DidSave() = 0; 32 virtual void OnDoc_WillClose() = 0; 33 34 virtual void OnPage_Open() = 0; 35 virtual void OnPage_Close() = 0; 36 virtual void OnPage_InView() = 0; 37 virtual void OnPage_OutView() = 0; 38 39 virtual void OnField_MouseDown(bool bModifier, 40 bool bShift, 41 CPDF_FormField* pTarget) = 0; 42 virtual void OnField_MouseEnter(bool bModifier, 43 bool bShift, 44 CPDF_FormField* pTarget) = 0; 45 virtual void OnField_MouseExit(bool bModifier, 46 bool bShift, 47 CPDF_FormField* pTarget) = 0; 48 virtual void OnField_MouseUp(bool bModifier, 49 bool bShift, 50 CPDF_FormField* pTarget) = 0; 51 virtual void OnField_Focus(bool bModifier, 52 bool bShift, 53 CPDF_FormField* pTarget, 54 WideString* Value) = 0; 55 virtual void OnField_Blur(bool bModifier, 56 bool bShift, 57 CPDF_FormField* pTarget, 58 WideString* Value) = 0; 59 virtual void OnField_Calculate(CPDF_FormField* pSource, 60 CPDF_FormField* pTarget, 61 WideString* Value, 62 bool* bRc) = 0; 63 virtual void OnField_Format(CPDF_FormField* pTarget, WideString* Value) = 0; 64 virtual void OnField_Keystroke(WideString* strChange, 65 const WideString& strChangeEx, 66 bool KeyDown, 67 bool bModifier, 68 int* nSelEnd, 69 int* nSelStart, 70 bool bShift, 71 CPDF_FormField* pTarget, 72 WideString* Value, 73 bool bWillCommit, 74 bool bFieldFull, 75 bool* bRc) = 0; 76 virtual void OnField_Validate(WideString* strChange, 77 const WideString& strChangeEx, 78 bool bKeyDown, 79 bool bModifier, 80 bool bShift, 81 CPDF_FormField* pTarget, 82 WideString* Value, 83 bool* bRc) = 0; 84 85 virtual void OnExternal_Exec() = 0; 86 }; 87 88 #endif // FXJS_IJS_EVENT_CONTEXT_H_ 89