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