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_SRC_JAVASCRIPT_JS_EVENTHANDLER_H_ 8 #define FPDFSDK_SRC_JAVASCRIPT_JS_EVENTHANDLER_H_ 9 10 #include "core/include/fxcrt/fx_string.h" 11 #include "core/include/fxcrt/fx_system.h" 12 13 class CJS_Context; 14 class CPDFSDK_Annot; 15 class CPDFSDK_Document; 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 CJS_EventHandler(CJS_Context* pContext); 64 virtual ~CJS_EventHandler(); 65 66 void OnApp_Init(); 67 68 void OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName); 69 void OnDoc_WillPrint(CPDFSDK_Document* pDoc); 70 void OnDoc_DidPrint(CPDFSDK_Document* pDoc); 71 void OnDoc_WillSave(CPDFSDK_Document* pDoc); 72 void OnDoc_DidSave(CPDFSDK_Document* pDoc); 73 void OnDoc_WillClose(CPDFSDK_Document* pDoc); 74 75 void OnPage_Open(CPDFSDK_Document* pDoc); 76 void OnPage_Close(CPDFSDK_Document* pDoc); 77 void OnPage_InView(CPDFSDK_Document* pTarget); 78 void OnPage_OutView(CPDFSDK_Document* pTarget); 79 80 void OnField_Calculate(CPDF_FormField* pSource, 81 CPDF_FormField* pTarget, 82 CFX_WideString& Value, 83 FX_BOOL& bRc); 84 void OnField_Format(CPDF_FormField* pTarget, 85 CFX_WideString& Value, 86 FX_BOOL bWillCommit); 87 void OnField_Keystroke(CFX_WideString& strChange, 88 const CFX_WideString& strChangeEx, 89 FX_BOOL KeyDown, 90 FX_BOOL bModifier, 91 int& nSelEnd, 92 int& nSelStart, 93 FX_BOOL bShift, 94 CPDF_FormField* pTarget, 95 CFX_WideString& Value, 96 FX_BOOL bWillCommit, 97 FX_BOOL bFieldFull, 98 FX_BOOL& bRc); 99 void OnField_Validate(CFX_WideString& strChange, 100 const CFX_WideString& strChangeEx, 101 FX_BOOL bKeyDown, 102 FX_BOOL bModifier, 103 FX_BOOL bShift, 104 CPDF_FormField* pTarget, 105 CFX_WideString& Value, 106 FX_BOOL& bRc); 107 108 void OnField_MouseDown(FX_BOOL bModifier, 109 FX_BOOL bShift, 110 CPDF_FormField* pTarget); 111 void OnField_MouseEnter(FX_BOOL bModifier, 112 FX_BOOL bShift, 113 CPDF_FormField* pTarget); 114 void OnField_MouseExit(FX_BOOL bModifier, 115 FX_BOOL bShift, 116 CPDF_FormField* pTarget); 117 void OnField_MouseUp(FX_BOOL bModifier, 118 FX_BOOL bShift, 119 CPDF_FormField* pTarget); 120 void OnField_Blur(FX_BOOL bModifier, 121 FX_BOOL bShift, 122 CPDF_FormField* pTarget, 123 const CFX_WideString& Value); 124 void OnField_Focus(FX_BOOL bModifier, 125 FX_BOOL bShift, 126 CPDF_FormField* pTarget, 127 const CFX_WideString& Value); 128 129 void OnScreen_Focus(FX_BOOL bModifier, 130 FX_BOOL bShift, 131 CPDFSDK_Annot* pScreen); 132 void OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 133 void OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen); 134 void OnScreen_Close(FX_BOOL bModifier, 135 FX_BOOL bShift, 136 CPDFSDK_Annot* pScreen); 137 void OnScreen_MouseDown(FX_BOOL bModifier, 138 FX_BOOL bShift, 139 CPDFSDK_Annot* pScreen); 140 void OnScreen_MouseUp(FX_BOOL bModifier, 141 FX_BOOL bShift, 142 CPDFSDK_Annot* pScreen); 143 void OnScreen_MouseEnter(FX_BOOL bModifier, 144 FX_BOOL bShift, 145 CPDFSDK_Annot* pScreen); 146 void OnScreen_MouseExit(FX_BOOL bModifier, 147 FX_BOOL bShift, 148 CPDFSDK_Annot* pScreen); 149 void OnScreen_InView(FX_BOOL bModifier, 150 FX_BOOL bShift, 151 CPDFSDK_Annot* pScreen); 152 void OnScreen_OutView(FX_BOOL bModifier, 153 FX_BOOL bShift, 154 CPDFSDK_Annot* pScreen); 155 156 void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark); 157 void OnLink_MouseUp(CPDFSDK_Document* pTarget); 158 159 void OnMenu_Exec(CPDFSDK_Document* pTarget, 160 const CFX_WideString& strTargetName); 161 void OnBatchExec(CPDFSDK_Document* pTarget); 162 void OnConsole_Exec(); 163 void OnExternal_Exec(); 164 165 public: 166 void Initial(JS_EVENT_T type); 167 void Destroy(); 168 FX_BOOL IsValid(); 169 170 CFX_WideString& Change(); 171 CFX_WideString ChangeEx(); 172 int CommitKey(); 173 FX_BOOL FieldFull(); 174 FX_BOOL KeyDown(); 175 FX_BOOL Modifier(); 176 const FX_WCHAR* Name(); 177 const FX_WCHAR* Type(); 178 FX_BOOL& Rc(); 179 int& SelEnd(); 180 int& SelStart(); 181 FX_BOOL Shift(); 182 Field* Source(); 183 Field* Target_Field(); 184 CFX_WideString& Value(); 185 FX_BOOL WillCommit(); 186 CFX_WideString TargetName(); 187 188 JS_EVENT_T EventType() { return m_eEventType; } 189 190 public: 191 CJS_Context* m_pJSContext; 192 JS_EVENT_T m_eEventType; 193 FX_BOOL m_bValid; 194 195 CFX_WideString m_strTargetName; 196 CFX_WideString m_strSourceName; 197 CFX_WideString* m_pWideStrChange; 198 CFX_WideString m_WideStrChangeDu; 199 CFX_WideString m_WideStrChangeEx; 200 int m_nCommitKey; 201 FX_BOOL m_bKeyDown; 202 FX_BOOL m_bModifier; 203 FX_BOOL m_bShift; 204 int* m_pISelEnd; 205 int m_nSelEndDu; 206 int* m_pISelStart; 207 int m_nSelStartDu; 208 FX_BOOL m_bWillCommit; 209 CFX_WideString* m_pValue; 210 FX_BOOL m_bFieldFull; 211 FX_BOOL* m_pbRc; 212 FX_BOOL m_bRcDu; 213 214 CPDFSDK_Document* m_pSourceDoc; 215 CPDF_Bookmark* m_pTargetBookMark; 216 CPDFSDK_Document* m_pTargetDoc; 217 CPDFSDK_Annot* m_pTargetAnnot; 218 }; 219 220 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_EVENTHANDLER_H_ 221