1 // Copyright 2014 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 _JS_CONTEXT_H_ 8 #define _JS_CONTEXT_H_ 9 10 class CJS_EventHandler; 11 class CJS_Runtime; 12 13 class CJS_Context : public IFXJS_Context 14 { 15 public: 16 CJS_Context(CJS_Runtime* pRuntime); 17 virtual ~CJS_Context(); 18 19 public: 20 virtual FX_BOOL Compile(const CFX_WideString& script, CFX_WideString& info); 21 virtual FX_BOOL RunScript(const CFX_WideString& script, CFX_WideString& info); 22 23 public: 24 virtual void OnApp_Init(); 25 26 virtual void OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName); 27 virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc); 28 virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc); 29 virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc); 30 virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc); 31 virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc); 32 33 virtual void OnPage_Open(CPDFSDK_Document* pTarget); 34 virtual void OnPage_Close(CPDFSDK_Document* pTarget); 35 virtual void OnPage_InView(CPDFSDK_Document* pTarget); 36 virtual void OnPage_OutView(CPDFSDK_Document* pTarget); 37 38 virtual void OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); 39 virtual void OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); 40 virtual void OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); 41 virtual void OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget); 42 virtual void OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value); 43 virtual void OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value); 44 45 virtual void OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc); 46 virtual void OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit); 47 virtual void OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx, 48 FX_BOOL bKeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart, FX_BOOL bShift, 49 CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit, 50 FX_BOOL bFieldFull, FX_BOOL &bRc); 51 virtual void OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, 52 FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc); 53 54 virtual void OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 55 virtual void OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 56 virtual void OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 57 virtual void OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 58 virtual void OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 59 virtual void OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 60 virtual void OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 61 virtual void OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 62 virtual void OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 63 virtual void OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 64 65 virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark); 66 virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget); 67 68 virtual void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName); 69 virtual void OnBatchExec(CPDFSDK_Document* pTarget); 70 virtual void OnConsole_Exec(); 71 virtual void OnExternal_Exec(); 72 EnableMessageBox(FX_BOOL bEnable)73 virtual void EnableMessageBox(FX_BOOL bEnable) {m_bMsgBoxEnable = bEnable;} IsMsgBoxEnabled()74 FX_BOOL IsMsgBoxEnabled() const {return m_bMsgBoxEnable;} 75 76 public: 77 CPDFDoc_Environment* GetReaderApp(); GetJSRuntime()78 CJS_Runtime* GetJSRuntime(){return m_pRuntime;} 79 80 FX_BOOL DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info); 81 GetEventHandler()82 CJS_EventHandler* GetEventHandler(){return m_pEventHandler;}; 83 CPDFSDK_Document* GetReaderDocument(); 84 85 private: 86 CJS_Runtime* m_pRuntime; 87 CJS_EventHandler* m_pEventHandler; 88 89 FX_BOOL m_bBusy; 90 FX_BOOL m_bMsgBoxEnable; 91 }; 92 93 // static CFX_WideString JSGetStringFromID(CJS_Context* pContext, UINT ID) 94 // { 95 // ASSERT(pContext != NULL); 96 // 97 // return JS_LoadString(pContext->GetReaderApp(), ID); 98 // } 99 100 #endif //_JS_CONTEXT_H_ 101 102