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 #include "fxjs/cjs_eventhandler.h"
8
9 #include "core/fpdfdoc/cpdf_formfield.h"
10 #include "fxjs/JS_Define.h"
11 #include "fxjs/cjs_document.h"
12 #include "fxjs/cjs_event_context.h"
13 #include "fxjs/cjs_field.h"
14 #include "fxjs/cjs_object.h"
15 #include "fxjs/cjs_runtime.h"
16
CJS_EventHandler(CJS_EventContext * pContext)17 CJS_EventHandler::CJS_EventHandler(CJS_EventContext* pContext)
18 : m_pJSEventContext(pContext),
19 m_eEventType(JET_UNKNOWN),
20 m_bValid(false),
21 m_pWideStrChange(nullptr),
22 m_nCommitKey(-1),
23 m_bKeyDown(false),
24 m_bModifier(false),
25 m_bShift(false),
26 m_pISelEnd(nullptr),
27 m_nSelEndDu(0),
28 m_pISelStart(nullptr),
29 m_nSelStartDu(0),
30 m_bWillCommit(false),
31 m_pValue(nullptr),
32 m_bFieldFull(false),
33 m_pbRc(nullptr),
34 m_bRcDu(false),
35 m_pTargetBookMark(nullptr),
36 m_pTargetFormFillEnv(nullptr),
37 m_pTargetAnnot(nullptr) {}
38
~CJS_EventHandler()39 CJS_EventHandler::~CJS_EventHandler() {}
40
OnApp_Init()41 void CJS_EventHandler::OnApp_Init() {
42 Initial(JET_APP_INIT);
43 }
44
OnDoc_Open(CPDFSDK_FormFillEnvironment * pFormFillEnv,const WideString & strTargetName)45 void CJS_EventHandler::OnDoc_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv,
46 const WideString& strTargetName) {
47 Initial(JET_DOC_OPEN);
48 m_pTargetFormFillEnv.Reset(pFormFillEnv);
49 m_strTargetName = strTargetName;
50 }
51
OnDoc_WillPrint(CPDFSDK_FormFillEnvironment * pFormFillEnv)52 void CJS_EventHandler::OnDoc_WillPrint(
53 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
54 Initial(JET_DOC_WILLPRINT);
55 m_pTargetFormFillEnv.Reset(pFormFillEnv);
56 }
57
OnDoc_DidPrint(CPDFSDK_FormFillEnvironment * pFormFillEnv)58 void CJS_EventHandler::OnDoc_DidPrint(
59 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
60 Initial(JET_DOC_DIDPRINT);
61 m_pTargetFormFillEnv.Reset(pFormFillEnv);
62 }
63
OnDoc_WillSave(CPDFSDK_FormFillEnvironment * pFormFillEnv)64 void CJS_EventHandler::OnDoc_WillSave(
65 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
66 Initial(JET_DOC_WILLSAVE);
67 m_pTargetFormFillEnv.Reset(pFormFillEnv);
68 }
69
OnDoc_DidSave(CPDFSDK_FormFillEnvironment * pFormFillEnv)70 void CJS_EventHandler::OnDoc_DidSave(
71 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
72 Initial(JET_DOC_DIDSAVE);
73 m_pTargetFormFillEnv.Reset(pFormFillEnv);
74 }
75
OnDoc_WillClose(CPDFSDK_FormFillEnvironment * pFormFillEnv)76 void CJS_EventHandler::OnDoc_WillClose(
77 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
78 Initial(JET_DOC_WILLCLOSE);
79 m_pTargetFormFillEnv.Reset(pFormFillEnv);
80 }
81
OnPage_Open(CPDFSDK_FormFillEnvironment * pFormFillEnv)82 void CJS_EventHandler::OnPage_Open(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
83 Initial(JET_PAGE_OPEN);
84 m_pTargetFormFillEnv.Reset(pFormFillEnv);
85 }
86
OnPage_Close(CPDFSDK_FormFillEnvironment * pFormFillEnv)87 void CJS_EventHandler::OnPage_Close(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
88 Initial(JET_PAGE_CLOSE);
89 m_pTargetFormFillEnv.Reset(pFormFillEnv);
90 }
91
OnPage_InView(CPDFSDK_FormFillEnvironment * pFormFillEnv)92 void CJS_EventHandler::OnPage_InView(
93 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
94 Initial(JET_PAGE_INVIEW);
95 m_pTargetFormFillEnv.Reset(pFormFillEnv);
96 }
97
OnPage_OutView(CPDFSDK_FormFillEnvironment * pFormFillEnv)98 void CJS_EventHandler::OnPage_OutView(
99 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
100 Initial(JET_PAGE_OUTVIEW);
101 m_pTargetFormFillEnv.Reset(pFormFillEnv);
102 }
103
OnField_MouseEnter(bool bModifier,bool bShift,CPDF_FormField * pTarget)104 void CJS_EventHandler::OnField_MouseEnter(bool bModifier,
105 bool bShift,
106 CPDF_FormField* pTarget) {
107 Initial(JET_FIELD_MOUSEENTER);
108
109 m_bModifier = bModifier;
110 m_bShift = bShift;
111
112 m_strTargetName = pTarget->GetFullName();
113 }
114
OnField_MouseExit(bool bModifier,bool bShift,CPDF_FormField * pTarget)115 void CJS_EventHandler::OnField_MouseExit(bool bModifier,
116 bool bShift,
117 CPDF_FormField* pTarget) {
118 Initial(JET_FIELD_MOUSEEXIT);
119
120 m_bModifier = bModifier;
121 m_bShift = bShift;
122 m_strTargetName = pTarget->GetFullName();
123 }
124
OnField_MouseDown(bool bModifier,bool bShift,CPDF_FormField * pTarget)125 void CJS_EventHandler::OnField_MouseDown(bool bModifier,
126 bool bShift,
127 CPDF_FormField* pTarget) {
128 Initial(JET_FIELD_MOUSEDOWN);
129 m_eEventType = JET_FIELD_MOUSEDOWN;
130
131 m_bModifier = bModifier;
132 m_bShift = bShift;
133 m_strTargetName = pTarget->GetFullName();
134 }
135
OnField_MouseUp(bool bModifier,bool bShift,CPDF_FormField * pTarget)136 void CJS_EventHandler::OnField_MouseUp(bool bModifier,
137 bool bShift,
138 CPDF_FormField* pTarget) {
139 Initial(JET_FIELD_MOUSEUP);
140
141 m_bModifier = bModifier;
142 m_bShift = bShift;
143 m_strTargetName = pTarget->GetFullName();
144 }
145
OnField_Focus(bool bModifier,bool bShift,CPDF_FormField * pTarget,const WideString & Value)146 void CJS_EventHandler::OnField_Focus(bool bModifier,
147 bool bShift,
148 CPDF_FormField* pTarget,
149 const WideString& Value) {
150 Initial(JET_FIELD_FOCUS);
151
152 m_bModifier = bModifier;
153 m_bShift = bShift;
154 m_strTargetName = pTarget->GetFullName();
155 m_pValue = (WideString*)&Value;
156 }
157
OnField_Blur(bool bModifier,bool bShift,CPDF_FormField * pTarget,const WideString & Value)158 void CJS_EventHandler::OnField_Blur(bool bModifier,
159 bool bShift,
160 CPDF_FormField* pTarget,
161 const WideString& Value) {
162 Initial(JET_FIELD_BLUR);
163
164 m_bModifier = bModifier;
165 m_bShift = bShift;
166 m_strTargetName = pTarget->GetFullName();
167 m_pValue = (WideString*)&Value;
168 }
169
OnField_Keystroke(WideString & strChange,const WideString & strChangeEx,bool KeyDown,bool bModifier,int & nSelEnd,int & nSelStart,bool bShift,CPDF_FormField * pTarget,WideString & Value,bool bWillCommit,bool bFieldFull,bool & bRc)170 void CJS_EventHandler::OnField_Keystroke(WideString& strChange,
171 const WideString& strChangeEx,
172 bool KeyDown,
173 bool bModifier,
174 int& nSelEnd,
175 int& nSelStart,
176 bool bShift,
177 CPDF_FormField* pTarget,
178 WideString& Value,
179 bool bWillCommit,
180 bool bFieldFull,
181 bool& bRc) {
182 Initial(JET_FIELD_KEYSTROKE);
183
184 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;
192 m_strTargetName = pTarget->GetFullName();
193 m_pValue = &Value;
194 m_bWillCommit = bWillCommit;
195 m_pbRc = &bRc;
196 m_bFieldFull = bFieldFull;
197 }
198
OnField_Validate(WideString & strChange,const WideString & strChangeEx,bool bKeyDown,bool bModifier,bool bShift,CPDF_FormField * pTarget,WideString & Value,bool & bRc)199 void CJS_EventHandler::OnField_Validate(WideString& strChange,
200 const WideString& strChangeEx,
201 bool bKeyDown,
202 bool bModifier,
203 bool bShift,
204 CPDF_FormField* pTarget,
205 WideString& Value,
206 bool& bRc) {
207 Initial(JET_FIELD_VALIDATE);
208
209 m_pWideStrChange = &strChange;
210 m_WideStrChangeEx = strChangeEx;
211 m_bKeyDown = bKeyDown;
212 m_bModifier = bModifier;
213 m_bShift = bShift;
214 m_strTargetName = pTarget->GetFullName();
215 m_pValue = &Value;
216 m_pbRc = &bRc;
217 }
218
OnField_Calculate(CPDF_FormField * pSource,CPDF_FormField * pTarget,WideString & Value,bool & bRc)219 void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource,
220 CPDF_FormField* pTarget,
221 WideString& Value,
222 bool& bRc) {
223 Initial(JET_FIELD_CALCULATE);
224
225 if (pSource)
226 m_strSourceName = pSource->GetFullName();
227 m_strTargetName = pTarget->GetFullName();
228 m_pValue = &Value;
229 m_pbRc = &bRc;
230 }
231
OnField_Format(CPDF_FormField * pTarget,WideString & Value,bool bWillCommit)232 void CJS_EventHandler::OnField_Format(CPDF_FormField* pTarget,
233 WideString& Value,
234 bool bWillCommit) {
235 Initial(JET_FIELD_FORMAT);
236
237 m_nCommitKey = 0;
238 m_strTargetName = pTarget->GetFullName();
239 m_pValue = &Value;
240 m_bWillCommit = bWillCommit;
241 }
242
OnScreen_Focus(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)243 void CJS_EventHandler::OnScreen_Focus(bool bModifier,
244 bool bShift,
245 CPDFSDK_Annot* pScreen) {
246 Initial(JET_SCREEN_FOCUS);
247
248 m_bModifier = bModifier;
249 m_bShift = bShift;
250 m_pTargetAnnot.Reset(pScreen);
251 }
252
OnScreen_Blur(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)253 void CJS_EventHandler::OnScreen_Blur(bool bModifier,
254 bool bShift,
255 CPDFSDK_Annot* pScreen) {
256 Initial(JET_SCREEN_BLUR);
257
258 m_bModifier = bModifier;
259 m_bShift = bShift;
260 m_pTargetAnnot.Reset(pScreen);
261 }
262
OnScreen_Open(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)263 void CJS_EventHandler::OnScreen_Open(bool bModifier,
264 bool bShift,
265 CPDFSDK_Annot* pScreen) {
266 Initial(JET_SCREEN_OPEN);
267
268 m_bModifier = bModifier;
269 m_bShift = bShift;
270 m_pTargetAnnot.Reset(pScreen);
271 }
272
OnScreen_Close(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)273 void CJS_EventHandler::OnScreen_Close(bool bModifier,
274 bool bShift,
275 CPDFSDK_Annot* pScreen) {
276 Initial(JET_SCREEN_CLOSE);
277
278 m_bModifier = bModifier;
279 m_bShift = bShift;
280 m_pTargetAnnot.Reset(pScreen);
281 }
282
OnScreen_MouseDown(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)283 void CJS_EventHandler::OnScreen_MouseDown(bool bModifier,
284 bool bShift,
285 CPDFSDK_Annot* pScreen) {
286 Initial(JET_SCREEN_MOUSEDOWN);
287
288 m_bModifier = bModifier;
289 m_bShift = bShift;
290 m_pTargetAnnot.Reset(pScreen);
291 }
292
OnScreen_MouseUp(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)293 void CJS_EventHandler::OnScreen_MouseUp(bool bModifier,
294 bool bShift,
295 CPDFSDK_Annot* pScreen) {
296 Initial(JET_SCREEN_MOUSEUP);
297
298 m_bModifier = bModifier;
299 m_bShift = bShift;
300 m_pTargetAnnot.Reset(pScreen);
301 }
302
OnScreen_MouseEnter(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)303 void CJS_EventHandler::OnScreen_MouseEnter(bool bModifier,
304 bool bShift,
305 CPDFSDK_Annot* pScreen) {
306 Initial(JET_SCREEN_MOUSEENTER);
307
308 m_bModifier = bModifier;
309 m_bShift = bShift;
310 m_pTargetAnnot.Reset(pScreen);
311 }
312
OnScreen_MouseExit(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)313 void CJS_EventHandler::OnScreen_MouseExit(bool bModifier,
314 bool bShift,
315 CPDFSDK_Annot* pScreen) {
316 Initial(JET_SCREEN_MOUSEEXIT);
317
318 m_bModifier = bModifier;
319 m_bShift = bShift;
320 m_pTargetAnnot.Reset(pScreen);
321 }
322
OnScreen_InView(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)323 void CJS_EventHandler::OnScreen_InView(bool bModifier,
324 bool bShift,
325 CPDFSDK_Annot* pScreen) {
326 Initial(JET_SCREEN_INVIEW);
327 m_bModifier = bModifier;
328 m_bShift = bShift;
329 m_pTargetAnnot.Reset(pScreen);
330 }
331
OnScreen_OutView(bool bModifier,bool bShift,CPDFSDK_Annot * pScreen)332 void CJS_EventHandler::OnScreen_OutView(bool bModifier,
333 bool bShift,
334 CPDFSDK_Annot* pScreen) {
335 Initial(JET_SCREEN_OUTVIEW);
336 m_bModifier = bModifier;
337 m_bShift = bShift;
338 m_pTargetAnnot.Reset(pScreen);
339 }
340
OnLink_MouseUp(CPDFSDK_FormFillEnvironment * pTargetFormFillEnv)341 void CJS_EventHandler::OnLink_MouseUp(
342 CPDFSDK_FormFillEnvironment* pTargetFormFillEnv) {
343 Initial(JET_LINK_MOUSEUP);
344 m_pTargetFormFillEnv.Reset(pTargetFormFillEnv);
345 }
346
OnBookmark_MouseUp(CPDF_Bookmark * pBookMark)347 void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) {
348 Initial(JET_BOOKMARK_MOUSEUP);
349 m_pTargetBookMark = pBookMark;
350 }
351
OnMenu_Exec(CPDFSDK_FormFillEnvironment * pTargetFormFillEnv,const WideString & strTargetName)352 void CJS_EventHandler::OnMenu_Exec(
353 CPDFSDK_FormFillEnvironment* pTargetFormFillEnv,
354 const WideString& strTargetName) {
355 Initial(JET_MENU_EXEC);
356 m_pTargetFormFillEnv.Reset(pTargetFormFillEnv);
357 m_strTargetName = strTargetName;
358 }
359
OnExternal_Exec()360 void CJS_EventHandler::OnExternal_Exec() {
361 Initial(JET_EXTERNAL_EXEC);
362 }
363
OnBatchExec(CPDFSDK_FormFillEnvironment * pTargetFormFillEnv)364 void CJS_EventHandler::OnBatchExec(
365 CPDFSDK_FormFillEnvironment* pTargetFormFillEnv) {
366 Initial(JET_BATCH_EXEC);
367 m_pTargetFormFillEnv.Reset(pTargetFormFillEnv);
368 }
369
OnConsole_Exec()370 void CJS_EventHandler::OnConsole_Exec() {
371 Initial(JET_CONSOLE_EXEC);
372 }
373
Initial(JS_EVENT_T type)374 void CJS_EventHandler::Initial(JS_EVENT_T type) {
375 m_eEventType = type;
376
377 m_strTargetName = L"";
378 m_strSourceName = L"";
379 m_pWideStrChange = nullptr;
380 m_WideStrChangeDu = L"";
381 m_WideStrChangeEx = L"";
382 m_nCommitKey = -1;
383 m_bKeyDown = false;
384 m_bModifier = false;
385 m_bShift = false;
386 m_pISelEnd = nullptr;
387 m_nSelEndDu = 0;
388 m_pISelStart = nullptr;
389 m_nSelStartDu = 0;
390 m_bWillCommit = false;
391 m_pValue = nullptr;
392 m_bFieldFull = false;
393 m_pbRc = nullptr;
394 m_bRcDu = false;
395
396 m_pTargetBookMark = nullptr;
397 m_pTargetFormFillEnv.Reset();
398 m_pTargetAnnot.Reset();
399
400 m_bValid = true;
401 }
402
Destroy()403 void CJS_EventHandler::Destroy() {
404 m_bValid = false;
405 }
406
IsValid() const407 bool CJS_EventHandler::IsValid() const {
408 return m_bValid;
409 }
410
Change()411 WideString& CJS_EventHandler::Change() {
412 if (m_pWideStrChange) {
413 return *m_pWideStrChange;
414 }
415 return m_WideStrChangeDu;
416 }
417
ChangeEx()418 const WideString& CJS_EventHandler::ChangeEx() {
419 return m_WideStrChangeEx;
420 }
421
CommitKey() const422 int CJS_EventHandler::CommitKey() const {
423 return m_nCommitKey;
424 }
425
FieldFull() const426 bool CJS_EventHandler::FieldFull() const {
427 return m_bFieldFull;
428 }
429
KeyDown() const430 bool CJS_EventHandler::KeyDown() const {
431 return m_bKeyDown;
432 }
433
Modifier() const434 bool CJS_EventHandler::Modifier() const {
435 return m_bModifier;
436 }
437
Name() const438 const wchar_t* CJS_EventHandler::Name() const {
439 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";
462 case JET_FIELD_FOCUS:
463 case JET_SCREEN_FOCUS:
464 return L"Focus";
465 case JET_FIELD_BLUR:
466 case JET_SCREEN_BLUR:
467 return L"Blur";
468 case JET_FIELD_MOUSEDOWN:
469 case JET_SCREEN_MOUSEDOWN:
470 return L"Mouse Down";
471 case JET_FIELD_MOUSEUP:
472 case JET_SCREEN_MOUSEUP:
473 return L"Mouse Up";
474 case JET_FIELD_MOUSEENTER:
475 case JET_SCREEN_MOUSEENTER:
476 return L"Mouse Enter";
477 case JET_FIELD_MOUSEEXIT:
478 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";
492 case JET_PAGE_OPEN:
493 case JET_SCREEN_OPEN:
494 return L"Open";
495 case JET_PAGE_CLOSE:
496 case JET_SCREEN_CLOSE:
497 return L"Close";
498 case JET_SCREEN_INVIEW:
499 case JET_PAGE_INVIEW:
500 return L"InView";
501 case JET_PAGE_OUTVIEW:
502 case JET_SCREEN_OUTVIEW:
503 return L"OutView";
504 default:
505 return L"";
506 }
507 }
508
Type() const509 const wchar_t* CJS_EventHandler::Type() const {
510 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";
519 case JET_DOC_DIDPRINT:
520 case JET_DOC_DIDSAVE:
521 case JET_DOC_OPEN:
522 case JET_DOC_WILLCLOSE:
523 case JET_DOC_WILLPRINT:
524 case JET_DOC_WILLSAVE:
525 return L"Doc";
526 case JET_EXTERNAL_EXEC:
527 return L"External";
528 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:
537 case JET_FIELD_VALIDATE:
538 return L"Field";
539 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:
548 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";
554 case JET_PAGE_OPEN:
555 case JET_PAGE_CLOSE:
556 case JET_PAGE_INVIEW:
557 case JET_PAGE_OUTVIEW:
558 return L"Page";
559 default:
560 return L"";
561 }
562 }
563
Rc()564 bool& CJS_EventHandler::Rc() {
565 return m_pbRc ? *m_pbRc : m_bRcDu;
566 }
567
SelEnd() const568 int CJS_EventHandler::SelEnd() const {
569 return m_pISelEnd ? *m_pISelEnd : m_nSelEndDu;
570 }
571
SelStart() const572 int CJS_EventHandler::SelStart() const {
573 return m_pISelStart ? *m_pISelStart : m_nSelStartDu;
574 }
575
SetSelEnd(int value)576 void CJS_EventHandler::SetSelEnd(int value) {
577 int& target = m_pISelEnd ? *m_pISelEnd : m_nSelEndDu;
578 target = value;
579 }
580
SetSelStart(int value)581 void CJS_EventHandler::SetSelStart(int value) {
582 int& target = m_pISelStart ? *m_pISelStart : m_nSelStartDu;
583 target = value;
584 }
585
Shift() const586 bool CJS_EventHandler::Shift() const {
587 return m_bShift;
588 }
589
Source()590 Field* CJS_EventHandler::Source() {
591 CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime();
592 v8::Local<v8::Object> pDocObj =
593 pRuntime->NewFxDynamicObj(CJS_Document::GetObjDefnID());
594 if (pDocObj.IsEmpty())
595 return nullptr;
596
597 v8::Local<v8::Object> pFieldObj =
598 pRuntime->NewFxDynamicObj(CJS_Field::GetObjDefnID());
599 if (pFieldObj.IsEmpty())
600 return nullptr;
601
602 CJS_Document* pJSDocument =
603 static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj));
604 CJS_Field* pJSField =
605 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
606
607 Document* pDocument = static_cast<Document*>(pJSDocument->GetEmbedObject());
608 pDocument->SetFormFillEnv(m_pTargetFormFillEnv
609 ? m_pTargetFormFillEnv.Get()
610 : m_pJSEventContext->GetFormFillEnv());
611
612 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
613 pField->AttachField(pDocument, m_strSourceName);
614 return pField;
615 }
616
Target_Field()617 Field* CJS_EventHandler::Target_Field() {
618 CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime();
619 v8::Local<v8::Object> pDocObj =
620 pRuntime->NewFxDynamicObj(CJS_Document::GetObjDefnID());
621 if (pDocObj.IsEmpty())
622 return nullptr;
623
624 v8::Local<v8::Object> pFieldObj =
625 pRuntime->NewFxDynamicObj(CJS_Field::GetObjDefnID());
626 if (pFieldObj.IsEmpty())
627 return nullptr;
628
629 CJS_Document* pJSDocument =
630 static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj));
631 CJS_Field* pJSField =
632 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
633
634 Document* pDocument = static_cast<Document*>(pJSDocument->GetEmbedObject());
635 pDocument->SetFormFillEnv(m_pTargetFormFillEnv
636 ? m_pTargetFormFillEnv.Get()
637 : m_pJSEventContext->GetFormFillEnv());
638
639 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
640 pField->AttachField(pDocument, m_strTargetName);
641 return pField;
642 }
643
Value()644 WideString& CJS_EventHandler::Value() {
645 return *m_pValue;
646 }
647
WillCommit() const648 bool CJS_EventHandler::WillCommit() const {
649 return m_bWillCommit;
650 }
651
TargetName() const652 const WideString& CJS_EventHandler::TargetName() const {
653 return m_strTargetName;
654 }
655