• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EVENTHANDLER_H_
8 #define FXJS_CJS_EVENTHANDLER_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_formfillenvironment.h"
14 
15 class CJS_EventContext;
16 class CPDFSDK_Annot;
17 class CPDF_Bookmark;
18 class CPDF_FormField;
19 class Field;
20 
21 enum JS_EVENT_T {
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  public:
64   explicit CJS_EventHandler(CJS_EventContext* pContext);
65   virtual ~CJS_EventHandler();
66 
67   void OnApp_Init();
68 
69   void OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv,
70                   const WideString& strTargetName);
71   void OnDoc_WillPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv);
72   void OnDoc_DidPrint(CPDFSDK_FormFillEnvironment* pFormFillEnv);
73   void OnDoc_WillSave(CPDFSDK_FormFillEnvironment* pFormFillEnv);
74   void OnDoc_DidSave(CPDFSDK_FormFillEnvironment* pFormFillEnv);
75   void OnDoc_WillClose(CPDFSDK_FormFillEnvironment* pFormFillEnv);
76 
77   void OnPage_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv);
78   void OnPage_Close(CPDFSDK_FormFillEnvironment* pFormFillEnv);
79   void OnPage_InView(CPDFSDK_FormFillEnvironment* pFormFillEnv);
80   void OnPage_OutView(CPDFSDK_FormFillEnvironment* pFormFillEnv);
81 
82   void OnField_Calculate(CPDF_FormField* pSource,
83                          CPDF_FormField* pTarget,
84                          WideString& Value,
85                          bool& bRc);
86   void OnField_Format(CPDF_FormField* pTarget,
87                       WideString& Value,
88                       bool bWillCommit);
89   void OnField_Keystroke(WideString& strChange,
90                          const WideString& strChangeEx,
91                          bool KeyDown,
92                          bool bModifier,
93                          int& nSelEnd,
94                          int& nSelStart,
95                          bool bShift,
96                          CPDF_FormField* pTarget,
97                          WideString& Value,
98                          bool bWillCommit,
99                          bool bFieldFull,
100                          bool& bRc);
101   void OnField_Validate(WideString& strChange,
102                         const WideString& strChangeEx,
103                         bool bKeyDown,
104                         bool bModifier,
105                         bool bShift,
106                         CPDF_FormField* pTarget,
107                         WideString& Value,
108                         bool& bRc);
109 
110   void OnField_MouseDown(bool bModifier, bool bShift, CPDF_FormField* pTarget);
111   void OnField_MouseEnter(bool bModifier, bool bShift, CPDF_FormField* pTarget);
112   void OnField_MouseExit(bool bModifier, bool bShift, CPDF_FormField* pTarget);
113   void OnField_MouseUp(bool bModifier, bool bShift, CPDF_FormField* pTarget);
114   void OnField_Blur(bool bModifier,
115                     bool bShift,
116                     CPDF_FormField* pTarget,
117                     const WideString& Value);
118   void OnField_Focus(bool bModifier,
119                      bool bShift,
120                      CPDF_FormField* pTarget,
121                      const WideString& Value);
122 
123   void OnScreen_Focus(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
124   void OnScreen_Blur(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
125   void OnScreen_Open(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
126   void OnScreen_Close(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
127   void OnScreen_MouseDown(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
128   void OnScreen_MouseUp(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
129   void OnScreen_MouseEnter(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
130   void OnScreen_MouseExit(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
131   void OnScreen_InView(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
132   void OnScreen_OutView(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
133 
134   void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark);
135   void OnLink_MouseUp(CPDFSDK_FormFillEnvironment* pFormFillEnv);
136 
137   void OnMenu_Exec(CPDFSDK_FormFillEnvironment* pFormFillEnv,
138                    const WideString& strTargetName);
139   void OnBatchExec(CPDFSDK_FormFillEnvironment* pFormFillEnv);
140   void OnConsole_Exec();
141   void OnExternal_Exec();
142 
143   void Initial(JS_EVENT_T type);
144   void Destroy();
145   bool IsValid() const;
146 
147   WideString& Change();
148   const WideString& ChangeEx();
149   int CommitKey() const;
150   bool FieldFull() const;
151   bool KeyDown() const;
152   bool Modifier() const;
153   const wchar_t* Name() const;
154   const wchar_t* Type() const;
155   bool& Rc();
156   int SelEnd() const;
157   int SelStart() const;
158   void SetSelEnd(int value);
159   void SetSelStart(int value);
160   bool Shift() const;
161   Field* Source();
162   Field* Target_Field();
163   WideString& Value();
164   bool WillCommit() const;
165   const WideString& TargetName() const;
166 
EventType()167   JS_EVENT_T EventType() const { return m_eEventType; }
168 
169   UnownedPtr<CJS_EventContext> const m_pJSEventContext;
170   JS_EVENT_T m_eEventType;
171   bool m_bValid;
172 
173   WideString m_strTargetName;
174   WideString m_strSourceName;
175   UnownedPtr<WideString> m_pWideStrChange;
176   WideString m_WideStrChangeDu;
177   WideString m_WideStrChangeEx;
178   int m_nCommitKey;
179   bool m_bKeyDown;
180   bool m_bModifier;
181   bool m_bShift;
182   int* m_pISelEnd;
183   int m_nSelEndDu;
184   int* m_pISelStart;
185   int m_nSelStartDu;
186   bool m_bWillCommit;
187   UnownedPtr<WideString> m_pValue;
188   bool m_bFieldFull;
189   bool* m_pbRc;
190   bool m_bRcDu;
191 
192   UnownedPtr<CPDF_Bookmark> m_pTargetBookMark;
193   CPDFSDK_FormFillEnvironment::ObservedPtr m_pTargetFormFillEnv;
194   CPDFSDK_Annot::ObservedPtr m_pTargetAnnot;
195 };
196 
197 #endif  // FXJS_CJS_EVENTHANDLER_H_
198