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