blob: 670d43ef7c1092f4cfd7f94b7974ee9c9218b765 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#include "fpdfsdk/javascript/JS_EventHandler.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Dan Sinclairf766ad22016-03-14 13:51:24 -04009#include "fpdfsdk/javascript/Document.h"
10#include "fpdfsdk/javascript/Field.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040011#include "fpdfsdk/javascript/JS_Define.h"
12#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040013#include "fpdfsdk/javascript/JS_Value.h"
Tom Sepezd6ae2af2017-02-16 11:49:55 -080014#include "fpdfsdk/javascript/cjs_event_context.h"
dsinclair64376be2016-03-31 20:03:24 -070015#include "fpdfsdk/javascript/cjs_runtime.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016
Tom Sepezd6ae2af2017-02-16 11:49:55 -080017CJS_EventHandler::CJS_EventHandler(CJS_EventContext* pContext)
18 : m_pJSEventContext(pContext),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019 m_eEventType(JET_UNKNOWN),
tsepez4cf55152016-11-02 14:37:54 -070020 m_bValid(false),
thestig1cd352e2016-06-07 17:53:06 -070021 m_pWideStrChange(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022 m_nCommitKey(-1),
tsepez4cf55152016-11-02 14:37:54 -070023 m_bKeyDown(false),
24 m_bModifier(false),
25 m_bShift(false),
thestig1cd352e2016-06-07 17:53:06 -070026 m_pISelEnd(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027 m_nSelEndDu(0),
thestig1cd352e2016-06-07 17:53:06 -070028 m_pISelStart(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 m_nSelStartDu(0),
tsepez4cf55152016-11-02 14:37:54 -070030 m_bWillCommit(false),
thestig1cd352e2016-06-07 17:53:06 -070031 m_pValue(nullptr),
tsepez4cf55152016-11-02 14:37:54 -070032 m_bFieldFull(false),
thestig1cd352e2016-06-07 17:53:06 -070033 m_pbRc(nullptr),
tsepez4cf55152016-11-02 14:37:54 -070034 m_bRcDu(false),
thestig1cd352e2016-06-07 17:53:06 -070035 m_pTargetBookMark(nullptr),
dsinclair4526faf2016-10-11 10:54:49 -070036 m_pTargetFormFillEnv(nullptr),
thestig1cd352e2016-06-07 17:53:06 -070037 m_pTargetAnnot(nullptr) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038
39CJS_EventHandler::~CJS_EventHandler() {}
40
41void CJS_EventHandler::OnApp_Init() {
42 Initial(JET_APP_INIT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043}
44
dsinclair4526faf2016-10-11 10:54:49 -070045void CJS_EventHandler::OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -040046 const WideString& strTargetName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 Initial(JET_DOC_OPEN);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080048 m_pTargetFormFillEnv.Reset(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 m_strTargetName = strTargetName;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050}
51
dsinclair4526faf2016-10-11 10:54:49 -070052void CJS_EventHandler::OnDoc_WillPrint(
53 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 Initial(JET_DOC_WILLPRINT);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080055 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056}
57
dsinclair4526faf2016-10-11 10:54:49 -070058void CJS_EventHandler::OnDoc_DidPrint(
59 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 Initial(JET_DOC_DIDPRINT);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080061 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
dsinclair4526faf2016-10-11 10:54:49 -070064void CJS_EventHandler::OnDoc_WillSave(
65 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 Initial(JET_DOC_WILLSAVE);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080067 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068}
69
dsinclair4526faf2016-10-11 10:54:49 -070070void CJS_EventHandler::OnDoc_DidSave(
71 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 Initial(JET_DOC_DIDSAVE);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080073 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074}
75
dsinclair4526faf2016-10-11 10:54:49 -070076void CJS_EventHandler::OnDoc_WillClose(
77 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 Initial(JET_DOC_WILLCLOSE);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080079 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080}
81
dsinclair4526faf2016-10-11 10:54:49 -070082void CJS_EventHandler::OnPage_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 Initial(JET_PAGE_OPEN);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080084 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085}
86
dsinclair4526faf2016-10-11 10:54:49 -070087void CJS_EventHandler::OnPage_Close(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 Initial(JET_PAGE_CLOSE);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080089 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090}
91
dsinclair4526faf2016-10-11 10:54:49 -070092void CJS_EventHandler::OnPage_InView(
93 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 Initial(JET_PAGE_INVIEW);
Tom Sepez77f6d0f2017-02-23 12:14:10 -080095 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070096}
97
dsinclair4526faf2016-10-11 10:54:49 -070098void CJS_EventHandler::OnPage_OutView(
99 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 Initial(JET_PAGE_OUTVIEW);
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800101 m_pTargetFormFillEnv.Reset(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102}
103
tsepez4cf55152016-11-02 14:37:54 -0700104void CJS_EventHandler::OnField_MouseEnter(bool bModifier,
105 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 CPDF_FormField* pTarget) {
107 Initial(JET_FIELD_MOUSEENTER);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 m_bModifier = bModifier;
110 m_bShift = bShift;
111
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 m_strTargetName = pTarget->GetFullName();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113}
114
tsepez4cf55152016-11-02 14:37:54 -0700115void CJS_EventHandler::OnField_MouseExit(bool bModifier,
116 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 CPDF_FormField* pTarget) {
118 Initial(JET_FIELD_MOUSEEXIT);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 m_bModifier = bModifier;
121 m_bShift = bShift;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 m_strTargetName = pTarget->GetFullName();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123}
124
tsepez4cf55152016-11-02 14:37:54 -0700125void CJS_EventHandler::OnField_MouseDown(bool bModifier,
126 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 CPDF_FormField* pTarget) {
128 Initial(JET_FIELD_MOUSEDOWN);
129 m_eEventType = JET_FIELD_MOUSEDOWN;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 m_bModifier = bModifier;
132 m_bShift = bShift;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 m_strTargetName = pTarget->GetFullName();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134}
135
tsepez4cf55152016-11-02 14:37:54 -0700136void CJS_EventHandler::OnField_MouseUp(bool bModifier,
137 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 CPDF_FormField* pTarget) {
139 Initial(JET_FIELD_MOUSEUP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 m_bModifier = bModifier;
142 m_bShift = bShift;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 m_strTargetName = pTarget->GetFullName();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144}
145
tsepez4cf55152016-11-02 14:37:54 -0700146void CJS_EventHandler::OnField_Focus(bool bModifier,
147 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 CPDF_FormField* pTarget,
Ryan Harrison275e2602017-09-18 14:23:18 -0400149 const WideString& Value) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 Initial(JET_FIELD_FOCUS);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700151
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 m_bModifier = bModifier;
153 m_bShift = bShift;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 m_strTargetName = pTarget->GetFullName();
Ryan Harrison275e2602017-09-18 14:23:18 -0400155 m_pValue = (WideString*)&Value;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156}
157
tsepez4cf55152016-11-02 14:37:54 -0700158void CJS_EventHandler::OnField_Blur(bool bModifier,
159 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 CPDF_FormField* pTarget,
Ryan Harrison275e2602017-09-18 14:23:18 -0400161 const WideString& Value) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 Initial(JET_FIELD_BLUR);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 m_bModifier = bModifier;
165 m_bShift = bShift;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 m_strTargetName = pTarget->GetFullName();
Ryan Harrison275e2602017-09-18 14:23:18 -0400167 m_pValue = (WideString*)&Value;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168}
169
Ryan Harrison275e2602017-09-18 14:23:18 -0400170void CJS_EventHandler::OnField_Keystroke(WideString& strChange,
171 const WideString& strChangeEx,
tsepez4cf55152016-11-02 14:37:54 -0700172 bool KeyDown,
173 bool bModifier,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 int& nSelEnd,
175 int& nSelStart,
tsepez4cf55152016-11-02 14:37:54 -0700176 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 CPDF_FormField* pTarget,
Ryan Harrison275e2602017-09-18 14:23:18 -0400178 WideString& Value,
tsepez4cf55152016-11-02 14:37:54 -0700179 bool bWillCommit,
180 bool bFieldFull,
181 bool& bRc) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 Initial(JET_FIELD_KEYSTROKE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 m_nCommitKey = 0;
185 m_pWideStrChange = &strChange;
186 m_WideStrChangeEx = strChangeEx;
187 m_bKeyDown = KeyDown;
188 m_bModifier = bModifier;
189 m_pISelEnd = &nSelEnd;
190 m_pISelStart = &nSelStart;
191 m_bShift = bShift;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 m_strTargetName = pTarget->GetFullName();
193 m_pValue = &Value;
194 m_bWillCommit = bWillCommit;
195 m_pbRc = &bRc;
196 m_bFieldFull = bFieldFull;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197}
198
Ryan Harrison275e2602017-09-18 14:23:18 -0400199void CJS_EventHandler::OnField_Validate(WideString& strChange,
200 const WideString& strChangeEx,
tsepez4cf55152016-11-02 14:37:54 -0700201 bool bKeyDown,
202 bool bModifier,
203 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 CPDF_FormField* pTarget,
Ryan Harrison275e2602017-09-18 14:23:18 -0400205 WideString& Value,
tsepez4cf55152016-11-02 14:37:54 -0700206 bool& bRc) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 Initial(JET_FIELD_VALIDATE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 m_pWideStrChange = &strChange;
210 m_WideStrChangeEx = strChangeEx;
211 m_bKeyDown = bKeyDown;
212 m_bModifier = bModifier;
213 m_bShift = bShift;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 m_strTargetName = pTarget->GetFullName();
215 m_pValue = &Value;
216 m_pbRc = &bRc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217}
218
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource,
220 CPDF_FormField* pTarget,
Ryan Harrison275e2602017-09-18 14:23:18 -0400221 WideString& Value,
tsepez4cf55152016-11-02 14:37:54 -0700222 bool& bRc) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 Initial(JET_FIELD_CALCULATE);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700224
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 if (pSource)
226 m_strSourceName = pSource->GetFullName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 m_strTargetName = pTarget->GetFullName();
228 m_pValue = &Value;
229 m_pbRc = &bRc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700230}
231
Lei Zhang0aa0e732015-06-10 15:23:23 -0700232void CJS_EventHandler::OnField_Format(CPDF_FormField* pTarget,
Ryan Harrison275e2602017-09-18 14:23:18 -0400233 WideString& Value,
tsepez4cf55152016-11-02 14:37:54 -0700234 bool bWillCommit) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235 Initial(JET_FIELD_FORMAT);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700236
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 m_nCommitKey = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 m_strTargetName = pTarget->GetFullName();
239 m_pValue = &Value;
240 m_bWillCommit = bWillCommit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241}
242
tsepez4cf55152016-11-02 14:37:54 -0700243void CJS_EventHandler::OnScreen_Focus(bool bModifier,
244 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 CPDFSDK_Annot* pScreen) {
246 Initial(JET_SCREEN_FOCUS);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700247
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 m_bModifier = bModifier;
249 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800250 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700251}
252
tsepez4cf55152016-11-02 14:37:54 -0700253void CJS_EventHandler::OnScreen_Blur(bool bModifier,
254 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 CPDFSDK_Annot* pScreen) {
256 Initial(JET_SCREEN_BLUR);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700257
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 m_bModifier = bModifier;
259 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800260 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261}
262
tsepez4cf55152016-11-02 14:37:54 -0700263void CJS_EventHandler::OnScreen_Open(bool bModifier,
264 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265 CPDFSDK_Annot* pScreen) {
266 Initial(JET_SCREEN_OPEN);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700267
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 m_bModifier = bModifier;
269 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800270 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700271}
272
tsepez4cf55152016-11-02 14:37:54 -0700273void CJS_EventHandler::OnScreen_Close(bool bModifier,
274 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 CPDFSDK_Annot* pScreen) {
276 Initial(JET_SCREEN_CLOSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 m_bModifier = bModifier;
279 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800280 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700281}
282
tsepez4cf55152016-11-02 14:37:54 -0700283void CJS_EventHandler::OnScreen_MouseDown(bool bModifier,
284 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 CPDFSDK_Annot* pScreen) {
286 Initial(JET_SCREEN_MOUSEDOWN);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 m_bModifier = bModifier;
289 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800290 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291}
292
tsepez4cf55152016-11-02 14:37:54 -0700293void CJS_EventHandler::OnScreen_MouseUp(bool bModifier,
294 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295 CPDFSDK_Annot* pScreen) {
296 Initial(JET_SCREEN_MOUSEUP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 m_bModifier = bModifier;
299 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800300 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700301}
302
tsepez4cf55152016-11-02 14:37:54 -0700303void CJS_EventHandler::OnScreen_MouseEnter(bool bModifier,
304 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305 CPDFSDK_Annot* pScreen) {
306 Initial(JET_SCREEN_MOUSEENTER);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700307
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700308 m_bModifier = bModifier;
309 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800310 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311}
312
tsepez4cf55152016-11-02 14:37:54 -0700313void CJS_EventHandler::OnScreen_MouseExit(bool bModifier,
314 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 CPDFSDK_Annot* pScreen) {
316 Initial(JET_SCREEN_MOUSEEXIT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 m_bModifier = bModifier;
319 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800320 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700321}
322
tsepez4cf55152016-11-02 14:37:54 -0700323void CJS_EventHandler::OnScreen_InView(bool bModifier,
324 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 CPDFSDK_Annot* pScreen) {
326 Initial(JET_SCREEN_INVIEW);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 m_bModifier = bModifier;
328 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800329 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700330}
331
tsepez4cf55152016-11-02 14:37:54 -0700332void CJS_EventHandler::OnScreen_OutView(bool bModifier,
333 bool bShift,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 CPDFSDK_Annot* pScreen) {
335 Initial(JET_SCREEN_OUTVIEW);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 m_bModifier = bModifier;
337 m_bShift = bShift;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800338 m_pTargetAnnot.Reset(pScreen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700339}
340
dsinclair4526faf2016-10-11 10:54:49 -0700341void CJS_EventHandler::OnLink_MouseUp(
342 CPDFSDK_FormFillEnvironment* pTargetFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343 Initial(JET_LINK_MOUSEUP);
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800344 m_pTargetFormFillEnv.Reset(pTargetFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700345}
346
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) {
348 Initial(JET_BOOKMARK_MOUSEUP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 m_pTargetBookMark = pBookMark;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350}
351
dsinclair4526faf2016-10-11 10:54:49 -0700352void CJS_EventHandler::OnMenu_Exec(
353 CPDFSDK_FormFillEnvironment* pTargetFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400354 const WideString& strTargetName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 Initial(JET_MENU_EXEC);
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800356 m_pTargetFormFillEnv.Reset(pTargetFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 m_strTargetName = strTargetName;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358}
359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360void CJS_EventHandler::OnExternal_Exec() {
361 Initial(JET_EXTERNAL_EXEC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700362}
363
dsinclair4526faf2016-10-11 10:54:49 -0700364void CJS_EventHandler::OnBatchExec(
365 CPDFSDK_FormFillEnvironment* pTargetFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 Initial(JET_BATCH_EXEC);
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800367 m_pTargetFormFillEnv.Reset(pTargetFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700368}
369
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370void CJS_EventHandler::OnConsole_Exec() {
371 Initial(JET_CONSOLE_EXEC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372}
373
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374void CJS_EventHandler::Initial(JS_EVENT_T type) {
375 m_eEventType = type;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700376
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377 m_strTargetName = L"";
378 m_strSourceName = L"";
thestig1cd352e2016-06-07 17:53:06 -0700379 m_pWideStrChange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 m_WideStrChangeDu = L"";
381 m_WideStrChangeEx = L"";
382 m_nCommitKey = -1;
tsepez4cf55152016-11-02 14:37:54 -0700383 m_bKeyDown = false;
384 m_bModifier = false;
385 m_bShift = false;
thestig1cd352e2016-06-07 17:53:06 -0700386 m_pISelEnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 m_nSelEndDu = 0;
thestig1cd352e2016-06-07 17:53:06 -0700388 m_pISelStart = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 m_nSelStartDu = 0;
tsepez4cf55152016-11-02 14:37:54 -0700390 m_bWillCommit = false;
thestig1cd352e2016-06-07 17:53:06 -0700391 m_pValue = nullptr;
tsepez4cf55152016-11-02 14:37:54 -0700392 m_bFieldFull = false;
thestig1cd352e2016-06-07 17:53:06 -0700393 m_pbRc = nullptr;
tsepez4cf55152016-11-02 14:37:54 -0700394 m_bRcDu = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700395
thestig1cd352e2016-06-07 17:53:06 -0700396 m_pTargetBookMark = nullptr;
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800397 m_pTargetFormFillEnv.Reset();
398 m_pTargetAnnot.Reset();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700399
tsepez4cf55152016-11-02 14:37:54 -0700400 m_bValid = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401}
402
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403void CJS_EventHandler::Destroy() {
tsepez4cf55152016-11-02 14:37:54 -0700404 m_bValid = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700405}
406
tsepez4cf55152016-11-02 14:37:54 -0700407bool CJS_EventHandler::IsValid() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 return m_bValid;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700409}
410
Ryan Harrison275e2602017-09-18 14:23:18 -0400411WideString& CJS_EventHandler::Change() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 if (m_pWideStrChange) {
413 return *m_pWideStrChange;
414 }
415 return m_WideStrChangeDu;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700416}
417
Ryan Harrison275e2602017-09-18 14:23:18 -0400418WideString CJS_EventHandler::ChangeEx() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 return m_WideStrChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700420}
421
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422int CJS_EventHandler::CommitKey() {
423 return m_nCommitKey;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700424}
425
tsepez4cf55152016-11-02 14:37:54 -0700426bool CJS_EventHandler::FieldFull() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 return m_bFieldFull;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700428}
429
tsepez4cf55152016-11-02 14:37:54 -0700430bool CJS_EventHandler::KeyDown() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 return m_bKeyDown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432}
433
tsepez4cf55152016-11-02 14:37:54 -0700434bool CJS_EventHandler::Modifier() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 return m_bModifier;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436}
437
Dan Sinclair812e96c2017-03-13 16:43:37 -0400438const wchar_t* CJS_EventHandler::Name() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 switch (m_eEventType) {
440 case JET_APP_INIT:
441 return L"Init";
442 case JET_BATCH_EXEC:
443 return L"Exec";
444 case JET_BOOKMARK_MOUSEUP:
445 return L"Mouse Up";
446 case JET_CONSOLE_EXEC:
447 return L"Exec";
448 case JET_DOC_DIDPRINT:
449 return L"DidPrint";
450 case JET_DOC_DIDSAVE:
451 return L"DidSave";
452 case JET_DOC_OPEN:
453 return L"Open";
454 case JET_DOC_WILLCLOSE:
455 return L"WillClose";
456 case JET_DOC_WILLPRINT:
457 return L"WillPrint";
458 case JET_DOC_WILLSAVE:
459 return L"WillSave";
460 case JET_EXTERNAL_EXEC:
461 return L"Exec";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700462 case JET_FIELD_FOCUS:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 case JET_SCREEN_FOCUS:
464 return L"Focus";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700465 case JET_FIELD_BLUR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 case JET_SCREEN_BLUR:
467 return L"Blur";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700468 case JET_FIELD_MOUSEDOWN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 case JET_SCREEN_MOUSEDOWN:
470 return L"Mouse Down";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700471 case JET_FIELD_MOUSEUP:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 case JET_SCREEN_MOUSEUP:
473 return L"Mouse Up";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700474 case JET_FIELD_MOUSEENTER:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 case JET_SCREEN_MOUSEENTER:
476 return L"Mouse Enter";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700477 case JET_FIELD_MOUSEEXIT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 case JET_SCREEN_MOUSEEXIT:
479 return L"Mouse Exit";
480 case JET_FIELD_CALCULATE:
481 return L"Calculate";
482 case JET_FIELD_FORMAT:
483 return L"Format";
484 case JET_FIELD_KEYSTROKE:
485 return L"Keystroke";
486 case JET_FIELD_VALIDATE:
487 return L"Validate";
488 case JET_LINK_MOUSEUP:
489 return L"Mouse Up";
490 case JET_MENU_EXEC:
491 return L"Exec";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700492 case JET_PAGE_OPEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 case JET_SCREEN_OPEN:
494 return L"Open";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700495 case JET_PAGE_CLOSE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 case JET_SCREEN_CLOSE:
497 return L"Close";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700498 case JET_SCREEN_INVIEW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 case JET_PAGE_INVIEW:
500 return L"InView";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700501 case JET_PAGE_OUTVIEW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 case JET_SCREEN_OUTVIEW:
503 return L"OutView";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700504 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 return L"";
506 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507}
508
Dan Sinclair812e96c2017-03-13 16:43:37 -0400509const wchar_t* CJS_EventHandler::Type() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 switch (m_eEventType) {
511 case JET_APP_INIT:
512 return L"App";
513 case JET_BATCH_EXEC:
514 return L"Batch";
515 case JET_BOOKMARK_MOUSEUP:
516 return L"BookMark";
517 case JET_CONSOLE_EXEC:
518 return L"Console";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700519 case JET_DOC_DIDPRINT:
520 case JET_DOC_DIDSAVE:
521 case JET_DOC_OPEN:
522 case JET_DOC_WILLCLOSE:
523 case JET_DOC_WILLPRINT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 case JET_DOC_WILLSAVE:
525 return L"Doc";
526 case JET_EXTERNAL_EXEC:
527 return L"External";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700528 case JET_FIELD_BLUR:
529 case JET_FIELD_FOCUS:
530 case JET_FIELD_MOUSEDOWN:
531 case JET_FIELD_MOUSEENTER:
532 case JET_FIELD_MOUSEEXIT:
533 case JET_FIELD_MOUSEUP:
534 case JET_FIELD_CALCULATE:
535 case JET_FIELD_FORMAT:
536 case JET_FIELD_KEYSTROKE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 case JET_FIELD_VALIDATE:
538 return L"Field";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700539 case JET_SCREEN_FOCUS:
540 case JET_SCREEN_BLUR:
541 case JET_SCREEN_OPEN:
542 case JET_SCREEN_CLOSE:
543 case JET_SCREEN_MOUSEDOWN:
544 case JET_SCREEN_MOUSEUP:
545 case JET_SCREEN_MOUSEENTER:
546 case JET_SCREEN_MOUSEEXIT:
547 case JET_SCREEN_INVIEW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548 case JET_SCREEN_OUTVIEW:
549 return L"Screen";
550 case JET_LINK_MOUSEUP:
551 return L"Link";
552 case JET_MENU_EXEC:
553 return L"Menu";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700554 case JET_PAGE_OPEN:
555 case JET_PAGE_CLOSE:
556 case JET_PAGE_INVIEW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 case JET_PAGE_OUTVIEW:
558 return L"Page";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700559 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 return L"";
561 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562}
563
tsepez4cf55152016-11-02 14:37:54 -0700564bool& CJS_EventHandler::Rc() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 if (m_pbRc) {
566 return *m_pbRc;
567 }
568 return m_bRcDu;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569}
570
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571int& CJS_EventHandler::SelEnd() {
572 if (m_pISelEnd) {
573 return *m_pISelEnd;
574 }
575 return m_nSelEndDu;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576}
577
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578int& CJS_EventHandler::SelStart() {
579 if (m_pISelStart) {
580 return *m_pISelStart;
581 }
582 return m_nSelStartDu;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
tsepez4cf55152016-11-02 14:37:54 -0700585bool CJS_EventHandler::Shift() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 return m_bShift;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700587}
588
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589Field* CJS_EventHandler::Source() {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800590 CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime();
tsepezb4694242016-08-15 16:44:55 -0700591 v8::Local<v8::Object> pDocObj =
592 pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800593 if (pDocObj.IsEmpty())
594 return nullptr;
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700595
tsepezb4694242016-08-15 16:44:55 -0700596 v8::Local<v8::Object> pFieldObj =
597 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800598 if (pFieldObj.IsEmpty())
599 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700600
Tom Sepezd5a0e952015-09-17 15:40:06 -0700601 CJS_Document* pJSDocument =
tsepezb4694242016-08-15 16:44:55 -0700602 static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj));
Tom Sepezc5a14722017-02-24 15:31:12 -0800603 CJS_Field* pJSField =
604 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
605
606 Document* pDocument = static_cast<Document*>(pJSDocument->GetEmbedObject());
dsinclair82e17672016-10-11 12:38:01 -0700607 pDocument->SetFormFillEnv(m_pTargetFormFillEnv
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800608 ? m_pTargetFormFillEnv.Get()
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800609 : m_pJSEventContext->GetFormFillEnv());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700610
Tom Sepezc5a14722017-02-24 15:31:12 -0800611 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 pField->AttachField(pDocument, m_strSourceName);
613 return pField;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614}
615
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616Field* CJS_EventHandler::Target_Field() {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800617 CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime();
tsepezb4694242016-08-15 16:44:55 -0700618 v8::Local<v8::Object> pDocObj =
619 pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800620 if (pDocObj.IsEmpty())
621 return nullptr;
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700622
tsepezb4694242016-08-15 16:44:55 -0700623 v8::Local<v8::Object> pFieldObj =
624 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800625 if (pFieldObj.IsEmpty())
626 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700627
Tom Sepezd5a0e952015-09-17 15:40:06 -0700628 CJS_Document* pJSDocument =
tsepezb4694242016-08-15 16:44:55 -0700629 static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj));
Tom Sepezc5a14722017-02-24 15:31:12 -0800630 CJS_Field* pJSField =
631 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
632
633 Document* pDocument = static_cast<Document*>(pJSDocument->GetEmbedObject());
dsinclair82e17672016-10-11 12:38:01 -0700634 pDocument->SetFormFillEnv(m_pTargetFormFillEnv
Tom Sepez77f6d0f2017-02-23 12:14:10 -0800635 ? m_pTargetFormFillEnv.Get()
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800636 : m_pJSEventContext->GetFormFillEnv());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700637
Tom Sepezc5a14722017-02-24 15:31:12 -0800638 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 pField->AttachField(pDocument, m_strTargetName);
640 return pField;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700641}
642
Ryan Harrison275e2602017-09-18 14:23:18 -0400643WideString& CJS_EventHandler::Value() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 return *m_pValue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
tsepez4cf55152016-11-02 14:37:54 -0700647bool CJS_EventHandler::WillCommit() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 return m_bWillCommit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700649}
650
Ryan Harrison275e2602017-09-18 14:23:18 -0400651WideString CJS_EventHandler::TargetName() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 return m_strTargetName;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653}