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 FPDFSDK_JAVASCRIPT_JS_EVENTHANDLER_H_ 8 #define FPDFSDK_JAVASCRIPT_JS_EVENTHANDLER_H_ 9 10 #include "core/fxcrt/fx_string.h" 11 #include "core/fxcrt/fx_system.h" 12 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" 13 14 class CJS_EventContext; 15 class CPDFSDK_Annot; 16 class CPDF_Bookmark; 17 class CPDF_FormField; 18 class Field; 19 20 enum JS_EVENT_T { 21 JET_UNKNOWN, 22 JET_APP_INIT, 23 JET_DOC_OPEN, 24 JET_DOC_WILLPRINT, 25 JET_DOC_DIDPRINT, 26 JET_DOC_WILLSAVE, 27 JET_DOC_DIDSAVE, 28 JET_DOC_WILLCLOSE, 29 JET_PAGE_OPEN, 30 JET_PAGE_CLOSE, 31 JET_PAGE_INVIEW, 32 JET_PAGE_OUTVIEW, 33 JET_FIELD_MOUSEDOWN, 34 JET_FIELD_MOUSEUP, 35 JET_FIELD_MOUSEENTER, 36 JET_FIELD_MOUSEEXIT, 37 JET_FIELD_FOCUS, 38 JET_FIELD_BLUR, 39 JET_FIELD_KEYSTROKE, 40 JET_FIELD_VALIDATE, 41 JET_FIELD_CALCULATE, 42 JET_FIELD_FORMAT, 43 JET_SCREEN_FOCUS, 44 JET_SCREEN_BLUR, 45 JET_SCREEN_OPEN, 46 JET_SCREEN_CLOSE, 47 JET_SCREEN_MOUSEDOWN, 48 JET_SCREEN_MOUSEUP, 49 JET_SCREEN_MOUSEENTER, 50 JET_SCREEN_MOUSEEXIT, 51 JET_SCREEN_INVIEW, 52 JET_SCREEN_OUTVIEW, 53 JET_BATCH_EXEC, 54 JET_MENU_EXEC, 55 JET_CONSOLE_EXEC, 56 JET_EXTERNAL_EXEC, 57 JET_BOOKMARK_MOUSEUP, 58 JET_LINK_MOUSEUP 59 }; 60 61 class CJS_EventHandler { 62 public: 63 explicit CJS_EventHandler(CJS_EventContext* pContext); 64 virtual ~CJS_EventHandler(); 65 66 void OnApp_Init(); 67 68 void OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv, 69 const CFX_WideString& strTargetName); 70 void OnDoc_WillPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv); 71 void OnDoc_DidPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv); 72 void OnDoc_WillSave(CPDFSDK_FormFillEnvironment* pFormFillEnv); 73 void OnDoc_DidSave(CPDFSDK_FormFillEnvironment* pFormFillEnv); 74 void OnDoc_WillClose(CPDFSDK_FormFillEnvironment* pFormFillEnv); 75 76 void OnPage_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv); 77 void OnPage_Close(CPDFSDK_FormFillEnvironment* pFormFillEnv); 78 void OnPage_InView(CPDFSDK_FormFillEnvironment* pFormFillEnv); 79 void OnPage_OutView(CPDFSDK_FormFillEnvironment* pFormFillEnv); 80 81 void OnField_Calculate(CPDF_FormField* pSource, 82 CPDF_FormField* pTarget, 83 CFX_WideString& Value, 84 bool& bRc); 85 void OnField_Format(CPDF_FormField* pTarget, 86 CFX_WideString& Value, 87 bool bWillCommit); 88 void OnField_Keystroke(CFX_WideString& strChange, 89 const CFX_WideString& strChangeEx, 90 bool KeyDown, 91 bool bModifier, 92 int& nSelEnd, 93 int& nSelStart, 94 bool bShift, 95 CPDF_FormField* pTarget, 96 CFX_WideString& Value, 97 bool bWillCommit, 98 bool bFieldFull, 99 bool& bRc); 100 void OnField_Validate(CFX_WideString& strChange, 101 const CFX_WideString& strChangeEx, 102 bool bKeyDown, 103 bool bModifier, 104 bool bShift, 105 CPDF_FormField* pTarget, 106 CFX_WideString& Value, 107 bool& bRc); 108 109 void OnField_MouseDown(bool bModifier, bool bShift, CPDF_FormField* pTarget); 110 void OnField_MouseEnter(bool bModifier, bool bShift, CPDF_FormField* pTarget); 111 void OnField_MouseExit(bool bModifier, bool bShift, CPDF_FormField* pTarget); 112 void OnField_MouseUp(bool bModifier, bool bShift, CPDF_FormField* pTarget); 113 void OnField_Blur(bool bModifier, 114 bool bShift, 115 CPDF_FormField* pTarget, 116 const CFX_WideString& Value); 117 void OnField_Focus(bool bModifier, 118 bool bShift, 119 CPDF_FormField* pTarget, 120 const CFX_WideString& Value); 121 122 void OnScreen_Focus(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 123 void OnScreen_Blur(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 124 void OnScreen_Open(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 125 void OnScreen_Close(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 126 void OnScreen_MouseDown(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 127 void OnScreen_MouseUp(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 128 void OnScreen_MouseEnter(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 129 void OnScreen_MouseExit(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 130 void OnScreen_InView(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 131 void OnScreen_OutView(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen); 132 133 void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark); 134 void OnLink_MouseUp(CPDFSDK_FormFillEnvironment* pFormFillEnv); 135 136 void OnMenu_Exec(CPDFSDK_FormFillEnvironment* pFormFillEnv, 137 const CFX_WideString& strTargetName); 138 void OnBatchExec(CPDFSDK_FormFillEnvironment* pFormFillEnv); 139 void OnConsole_Exec(); 140 void OnExternal_Exec(); 141 142 public: 143 void Initial(JS_EVENT_T type); 144 void Destroy(); 145 bool IsValid(); 146 147 CFX_WideString& Change(); 148 CFX_WideString ChangeEx(); 149 int CommitKey(); 150 bool FieldFull(); 151 bool KeyDown(); 152 bool Modifier(); 153 const FX_WCHAR* Name(); 154 const FX_WCHAR* Type(); 155 bool& Rc(); 156 int& SelEnd(); 157 int& SelStart(); 158 bool Shift(); 159 Field* Source(); 160 Field* Target_Field(); 161 CFX_WideString& Value(); 162 bool WillCommit(); 163 CFX_WideString TargetName(); 164 EventType()165 JS_EVENT_T EventType() { return m_eEventType; } 166 167 public: 168 CJS_EventContext* const m_pJSEventContext; // Not Owned. 169 JS_EVENT_T m_eEventType; 170 bool m_bValid; 171 172 CFX_WideString m_strTargetName; 173 CFX_WideString m_strSourceName; 174 CFX_WideString* m_pWideStrChange; 175 CFX_WideString m_WideStrChangeDu; 176 CFX_WideString m_WideStrChangeEx; 177 int m_nCommitKey; 178 bool m_bKeyDown; 179 bool m_bModifier; 180 bool m_bShift; 181 int* m_pISelEnd; 182 int m_nSelEndDu; 183 int* m_pISelStart; 184 int m_nSelStartDu; 185 bool m_bWillCommit; 186 CFX_WideString* m_pValue; 187 bool m_bFieldFull; 188 bool* m_pbRc; 189 bool m_bRcDu; 190 191 CPDF_Bookmark* m_pTargetBookMark; 192 CPDFSDK_FormFillEnvironment::ObservedPtr m_pTargetFormFillEnv; 193 CPDFSDK_Annot::ObservedPtr m_pTargetAnnot; 194 }; 195 196 #endif // FPDFSDK_JAVASCRIPT_JS_EVENTHANDLER_H_ 197