Remove JavaScript.h
[pdfium.git] / fpdfsdk / src / javascript / JS_EventHandler.cpp
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 "../../include/javascript/IJavaScript.h"
8 #include "../../include/javascript/JS_EventHandler.h"
9 #include "../../include/javascript/JS_Context.h"
10 #include "../../include/javascript/JS_Runtime.h"
11 #include "../../include/javascript/JS_Define.h"
12 #include "../../include/javascript/JS_Object.h"
13 #include "../../include/javascript/JS_Value.h"
14 #include "../../include/javascript/Document.h"
15 #include "../../include/javascript/Field.h"
16
17 /* ---------------------------- CJS_EventHandler ---------------------------- */
18
19 CJS_EventHandler::CJS_EventHandler(CJS_Context* pContext)
20     : m_pJSContext(pContext),
21       m_eEventType(JET_UNKNOWN),
22       m_bValid(FALSE),
23       m_pWideStrChange(NULL),
24       m_nCommitKey(-1),
25       m_bKeyDown(FALSE),
26       m_bModifier(FALSE),
27       m_bShift(FALSE),
28       m_pISelEnd(NULL),
29       m_nSelEndDu(0),
30       m_pISelStart(NULL),
31       m_nSelStartDu(0),
32       m_bWillCommit(FALSE),
33       m_pValue(NULL),
34       m_bFieldFull(FALSE),
35       m_pbRc(NULL),
36       m_bRcDu(FALSE),
37       m_pSourceDoc(NULL),
38       m_pTargetBookMark(NULL),
39       m_pTargetDoc(NULL),
40       m_pTargetAnnot(NULL) {}
41
42 CJS_EventHandler::~CJS_EventHandler() {}
43
44 void CJS_EventHandler::OnApp_Init() {
45   Initial(JET_APP_INIT);
46 }
47
48 void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc,
49                                   const CFX_WideString& strTargetName) {
50   Initial(JET_DOC_OPEN);
51
52   m_pTargetDoc = pDoc;
53   m_strTargetName = strTargetName;
54 }
55
56 void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc) {
57   Initial(JET_DOC_WILLPRINT);
58
59   m_pTargetDoc = pDoc;
60 }
61
62 void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc) {
63   Initial(JET_DOC_DIDPRINT);
64
65   m_pTargetDoc = pDoc;
66 }
67
68 void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc) {
69   Initial(JET_DOC_WILLSAVE);
70   m_pTargetDoc = pDoc;
71 }
72
73 void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc) {
74   Initial(JET_DOC_DIDSAVE);
75
76   m_pTargetDoc = pDoc;
77 }
78
79 void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc) {
80   Initial(JET_DOC_WILLCLOSE);
81
82   m_pTargetDoc = pDoc;
83 }
84
85 void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc) {
86   Initial(JET_PAGE_OPEN);
87
88   m_pTargetDoc = pDoc;
89 }
90
91 void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc) {
92   Initial(JET_PAGE_CLOSE);
93
94   m_pTargetDoc = pDoc;
95 }
96
97 void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc) {
98   Initial(JET_PAGE_INVIEW);
99
100   m_pTargetDoc = pDoc;
101 }
102
103 void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc) {
104   Initial(JET_PAGE_OUTVIEW);
105
106   m_pTargetDoc = pDoc;
107 }
108
109 void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier,
110                                           FX_BOOL bShift,
111                                           CPDF_FormField* pTarget) {
112   Initial(JET_FIELD_MOUSEENTER);
113
114   m_bModifier = bModifier;
115   m_bShift = bShift;
116
117   ASSERT(pTarget != NULL);
118   m_strTargetName = pTarget->GetFullName();
119 }
120
121 void CJS_EventHandler::OnField_MouseExit(FX_BOOL bModifier,
122                                          FX_BOOL bShift,
123                                          CPDF_FormField* pTarget) {
124   Initial(JET_FIELD_MOUSEEXIT);
125
126   m_bModifier = bModifier;
127   m_bShift = bShift;
128   ASSERT(pTarget != NULL);
129   m_strTargetName = pTarget->GetFullName();
130 }
131
132 void CJS_EventHandler::OnField_MouseDown(FX_BOOL bModifier,
133                                          FX_BOOL bShift,
134                                          CPDF_FormField* pTarget) {
135   Initial(JET_FIELD_MOUSEDOWN);
136   m_eEventType = JET_FIELD_MOUSEDOWN;
137
138   m_bModifier = bModifier;
139   m_bShift = bShift;
140   ASSERT(pTarget != NULL);
141   m_strTargetName = pTarget->GetFullName();
142 }
143
144 void CJS_EventHandler::OnField_MouseUp(FX_BOOL bModifier,
145                                        FX_BOOL bShift,
146                                        CPDF_FormField* pTarget) {
147   Initial(JET_FIELD_MOUSEUP);
148
149   m_bModifier = bModifier;
150   m_bShift = bShift;
151   ASSERT(pTarget != NULL);
152   m_strTargetName = pTarget->GetFullName();
153 }
154
155 void CJS_EventHandler::OnField_Focus(FX_BOOL bModifier,
156                                      FX_BOOL bShift,
157                                      CPDF_FormField* pTarget,
158                                      const CFX_WideString& Value) {
159   Initial(JET_FIELD_FOCUS);
160
161   m_bModifier = bModifier;
162   m_bShift = bShift;
163   ASSERT(pTarget != NULL);
164   m_strTargetName = pTarget->GetFullName();
165   m_pValue = (CFX_WideString*)&Value;
166 }
167
168 void CJS_EventHandler::OnField_Blur(FX_BOOL bModifier,
169                                     FX_BOOL bShift,
170                                     CPDF_FormField* pTarget,
171                                     const CFX_WideString& Value) {
172   Initial(JET_FIELD_BLUR);
173
174   m_bModifier = bModifier;
175   m_bShift = bShift;
176   ASSERT(pTarget != NULL);
177   m_strTargetName = pTarget->GetFullName();
178   m_pValue = (CFX_WideString*)&Value;
179 }
180
181 void CJS_EventHandler::OnField_Keystroke(CFX_WideString& strChange,
182                                          const CFX_WideString& strChangeEx,
183                                          FX_BOOL KeyDown,
184                                          FX_BOOL bModifier,
185                                          int& nSelEnd,
186                                          int& nSelStart,
187                                          FX_BOOL bShift,
188                                          CPDF_FormField* pTarget,
189                                          CFX_WideString& Value,
190                                          FX_BOOL bWillCommit,
191                                          FX_BOOL bFieldFull,
192                                          FX_BOOL& bRc) {
193   Initial(JET_FIELD_KEYSTROKE);
194
195   m_nCommitKey = 0;
196   m_pWideStrChange = &strChange;
197   m_WideStrChangeEx = strChangeEx;
198   m_bKeyDown = KeyDown;
199   m_bModifier = bModifier;
200   m_pISelEnd = &nSelEnd;
201   m_pISelStart = &nSelStart;
202   m_bShift = bShift;
203   ASSERT(pTarget != NULL);
204   m_strTargetName = pTarget->GetFullName();
205   m_pValue = &Value;
206   m_bWillCommit = bWillCommit;
207   m_pbRc = &bRc;
208   m_bFieldFull = bFieldFull;
209 }
210
211 void CJS_EventHandler::OnField_Validate(CFX_WideString& strChange,
212                                         const CFX_WideString& strChangeEx,
213                                         FX_BOOL bKeyDown,
214                                         FX_BOOL bModifier,
215                                         FX_BOOL bShift,
216                                         CPDF_FormField* pTarget,
217                                         CFX_WideString& Value,
218                                         FX_BOOL& bRc) {
219   Initial(JET_FIELD_VALIDATE);
220
221   m_pWideStrChange = &strChange;
222   m_WideStrChangeEx = strChangeEx;
223   m_bKeyDown = bKeyDown;
224   m_bModifier = bModifier;
225   m_bShift = bShift;
226   ASSERT(pTarget != NULL);
227   m_strTargetName = pTarget->GetFullName();
228   m_pValue = &Value;
229   m_pbRc = &bRc;
230 }
231
232 void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource,
233                                          CPDF_FormField* pTarget,
234                                          CFX_WideString& Value,
235                                          FX_BOOL& bRc) {
236   Initial(JET_FIELD_CALCULATE);
237
238   if (pSource)
239     m_strSourceName = pSource->GetFullName();
240   ASSERT(pTarget != NULL);
241   m_strTargetName = pTarget->GetFullName();
242   m_pValue = &Value;
243   m_pbRc = &bRc;
244 }
245
246 void CJS_EventHandler::OnField_Format(CPDF_FormField* pTarget,
247                                       CFX_WideString& Value,
248                                       FX_BOOL bWillCommit) {
249   Initial(JET_FIELD_FORMAT);
250
251   m_nCommitKey = 0;
252   ASSERT(pTarget != NULL);
253   m_strTargetName = pTarget->GetFullName();
254   m_pValue = &Value;
255   m_bWillCommit = bWillCommit;
256 }
257
258 void CJS_EventHandler::OnScreen_Focus(FX_BOOL bModifier,
259                                       FX_BOOL bShift,
260                                       CPDFSDK_Annot* pScreen) {
261   Initial(JET_SCREEN_FOCUS);
262
263   m_bModifier = bModifier;
264   m_bShift = bShift;
265   m_pTargetAnnot = pScreen;
266 }
267
268 void CJS_EventHandler::OnScreen_Blur(FX_BOOL bModifier,
269                                      FX_BOOL bShift,
270                                      CPDFSDK_Annot* pScreen) {
271   Initial(JET_SCREEN_BLUR);
272
273   m_bModifier = bModifier;
274   m_bShift = bShift;
275   m_pTargetAnnot = pScreen;
276 }
277
278 void CJS_EventHandler::OnScreen_Open(FX_BOOL bModifier,
279                                      FX_BOOL bShift,
280                                      CPDFSDK_Annot* pScreen) {
281   Initial(JET_SCREEN_OPEN);
282
283   m_bModifier = bModifier;
284   m_bShift = bShift;
285   m_pTargetAnnot = pScreen;
286 }
287
288 void CJS_EventHandler::OnScreen_Close(FX_BOOL bModifier,
289                                       FX_BOOL bShift,
290                                       CPDFSDK_Annot* pScreen) {
291   Initial(JET_SCREEN_CLOSE);
292
293   m_bModifier = bModifier;
294   m_bShift = bShift;
295   m_pTargetAnnot = pScreen;
296 }
297
298 void CJS_EventHandler::OnScreen_MouseDown(FX_BOOL bModifier,
299                                           FX_BOOL bShift,
300                                           CPDFSDK_Annot* pScreen) {
301   Initial(JET_SCREEN_MOUSEDOWN);
302
303   m_bModifier = bModifier;
304   m_bShift = bShift;
305   m_pTargetAnnot = pScreen;
306 }
307
308 void CJS_EventHandler::OnScreen_MouseUp(FX_BOOL bModifier,
309                                         FX_BOOL bShift,
310                                         CPDFSDK_Annot* pScreen) {
311   Initial(JET_SCREEN_MOUSEUP);
312
313   m_bModifier = bModifier;
314   m_bShift = bShift;
315   m_pTargetAnnot = pScreen;
316 }
317
318 void CJS_EventHandler::OnScreen_MouseEnter(FX_BOOL bModifier,
319                                            FX_BOOL bShift,
320                                            CPDFSDK_Annot* pScreen) {
321   Initial(JET_SCREEN_MOUSEENTER);
322
323   m_bModifier = bModifier;
324   m_bShift = bShift;
325   m_pTargetAnnot = pScreen;
326 }
327
328 void CJS_EventHandler::OnScreen_MouseExit(FX_BOOL bModifier,
329                                           FX_BOOL bShift,
330                                           CPDFSDK_Annot* pScreen) {
331   Initial(JET_SCREEN_MOUSEEXIT);
332
333   m_bModifier = bModifier;
334   m_bShift = bShift;
335   m_pTargetAnnot = pScreen;
336 }
337
338 void CJS_EventHandler::OnScreen_InView(FX_BOOL bModifier,
339                                        FX_BOOL bShift,
340                                        CPDFSDK_Annot* pScreen) {
341   Initial(JET_SCREEN_INVIEW);
342
343   m_bModifier = bModifier;
344   m_bShift = bShift;
345   m_pTargetAnnot = pScreen;
346 }
347
348 void CJS_EventHandler::OnScreen_OutView(FX_BOOL bModifier,
349                                         FX_BOOL bShift,
350                                         CPDFSDK_Annot* pScreen) {
351   Initial(JET_SCREEN_OUTVIEW);
352
353   m_bModifier = bModifier;
354   m_bShift = bShift;
355   m_pTargetAnnot = pScreen;
356 }
357
358 void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget) {
359   Initial(JET_LINK_MOUSEUP);
360
361   m_pTargetDoc = pTarget;
362 }
363
364 void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) {
365   Initial(JET_BOOKMARK_MOUSEUP);
366
367   m_pTargetBookMark = pBookMark;
368 }
369
370 void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget,
371                                    const CFX_WideString& strTargetName) {
372   Initial(JET_MENU_EXEC);
373
374   m_pTargetDoc = pTarget;
375   m_strTargetName = strTargetName;
376 }
377
378 void CJS_EventHandler::OnExternal_Exec() {
379   Initial(JET_EXTERNAL_EXEC);
380 }
381
382 void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget) {
383   Initial(JET_BATCH_EXEC);
384
385   m_pTargetDoc = pTarget;
386 }
387
388 void CJS_EventHandler::OnConsole_Exec() {
389   Initial(JET_CONSOLE_EXEC);
390 }
391
392 void CJS_EventHandler::Initial(JS_EVENT_T type) {
393   m_eEventType = type;
394
395   m_strTargetName = L"";
396   m_strSourceName = L"";
397   m_pWideStrChange = NULL;
398   m_WideStrChangeDu = L"";
399   m_WideStrChangeEx = L"";
400   m_nCommitKey = -1;
401   m_bKeyDown = FALSE;
402   m_bModifier = FALSE;
403   m_bShift = FALSE;
404   m_pISelEnd = NULL;
405   m_nSelEndDu = 0;
406   m_pISelStart = NULL;
407   m_nSelStartDu = 0;
408   m_bWillCommit = FALSE;
409   m_pValue = NULL;
410   m_bFieldFull = FALSE;
411   m_pbRc = NULL;
412   m_bRcDu = FALSE;
413
414   m_pSourceDoc = NULL;
415   m_pTargetBookMark = NULL;
416   m_pTargetDoc = NULL;
417   m_pTargetAnnot = NULL;
418
419   m_bValid = TRUE;
420 }
421
422 void CJS_EventHandler::Destroy() {
423   m_bValid = FALSE;
424 }
425
426 FX_BOOL CJS_EventHandler::IsValid() {
427   return m_bValid;
428 }
429
430 CFX_WideString& CJS_EventHandler::Change() {
431   if (m_pWideStrChange) {
432     return *m_pWideStrChange;
433   }
434   return m_WideStrChangeDu;
435 }
436
437 CFX_WideString CJS_EventHandler::ChangeEx() {
438   return m_WideStrChangeEx;
439 }
440
441 int CJS_EventHandler::CommitKey() {
442   return m_nCommitKey;
443 }
444
445 FX_BOOL CJS_EventHandler::FieldFull() {
446   return m_bFieldFull;
447 }
448
449 FX_BOOL CJS_EventHandler::KeyDown() {
450   return m_bKeyDown;
451 }
452
453 FX_BOOL CJS_EventHandler::Modifier() {
454   return m_bModifier;
455 }
456
457 const FX_WCHAR* CJS_EventHandler::Name() {
458   switch (m_eEventType) {
459     case JET_APP_INIT:
460       return L"Init";
461     case JET_BATCH_EXEC:
462       return L"Exec";
463     case JET_BOOKMARK_MOUSEUP:
464       return L"Mouse Up";
465     case JET_CONSOLE_EXEC:
466       return L"Exec";
467     case JET_DOC_DIDPRINT:
468       return L"DidPrint";
469     case JET_DOC_DIDSAVE:
470       return L"DidSave";
471     case JET_DOC_OPEN:
472       return L"Open";
473     case JET_DOC_WILLCLOSE:
474       return L"WillClose";
475     case JET_DOC_WILLPRINT:
476       return L"WillPrint";
477     case JET_DOC_WILLSAVE:
478       return L"WillSave";
479     case JET_EXTERNAL_EXEC:
480       return L"Exec";
481     case JET_FIELD_FOCUS:
482     case JET_SCREEN_FOCUS:
483       return L"Focus";
484     case JET_FIELD_BLUR:
485     case JET_SCREEN_BLUR:
486       return L"Blur";
487     case JET_FIELD_MOUSEDOWN:
488     case JET_SCREEN_MOUSEDOWN:
489       return L"Mouse Down";
490     case JET_FIELD_MOUSEUP:
491     case JET_SCREEN_MOUSEUP:
492       return L"Mouse Up";
493     case JET_FIELD_MOUSEENTER:
494     case JET_SCREEN_MOUSEENTER:
495       return L"Mouse Enter";
496     case JET_FIELD_MOUSEEXIT:
497     case JET_SCREEN_MOUSEEXIT:
498       return L"Mouse Exit";
499     case JET_FIELD_CALCULATE:
500       return L"Calculate";
501     case JET_FIELD_FORMAT:
502       return L"Format";
503     case JET_FIELD_KEYSTROKE:
504       return L"Keystroke";
505     case JET_FIELD_VALIDATE:
506       return L"Validate";
507     case JET_LINK_MOUSEUP:
508       return L"Mouse Up";
509     case JET_MENU_EXEC:
510       return L"Exec";
511     case JET_PAGE_OPEN:
512     case JET_SCREEN_OPEN:
513       return L"Open";
514     case JET_PAGE_CLOSE:
515     case JET_SCREEN_CLOSE:
516       return L"Close";
517     case JET_SCREEN_INVIEW:
518     case JET_PAGE_INVIEW:
519       return L"InView";
520     case JET_PAGE_OUTVIEW:
521     case JET_SCREEN_OUTVIEW:
522       return L"OutView";
523     default:
524       return L"";
525   }
526
527   return L"";
528 }
529
530 const FX_WCHAR* CJS_EventHandler::Type() {
531   switch (m_eEventType) {
532     case JET_APP_INIT:
533       return L"App";
534     case JET_BATCH_EXEC:
535       return L"Batch";
536     case JET_BOOKMARK_MOUSEUP:
537       return L"BookMark";
538     case JET_CONSOLE_EXEC:
539       return L"Console";
540     case JET_DOC_DIDPRINT:
541     case JET_DOC_DIDSAVE:
542     case JET_DOC_OPEN:
543     case JET_DOC_WILLCLOSE:
544     case JET_DOC_WILLPRINT:
545     case JET_DOC_WILLSAVE:
546       return L"Doc";
547     case JET_EXTERNAL_EXEC:
548       return L"External";
549     case JET_FIELD_BLUR:
550     case JET_FIELD_FOCUS:
551     case JET_FIELD_MOUSEDOWN:
552     case JET_FIELD_MOUSEENTER:
553     case JET_FIELD_MOUSEEXIT:
554     case JET_FIELD_MOUSEUP:
555     case JET_FIELD_CALCULATE:
556     case JET_FIELD_FORMAT:
557     case JET_FIELD_KEYSTROKE:
558     case JET_FIELD_VALIDATE:
559       return L"Field";
560     case JET_SCREEN_FOCUS:
561     case JET_SCREEN_BLUR:
562     case JET_SCREEN_OPEN:
563     case JET_SCREEN_CLOSE:
564     case JET_SCREEN_MOUSEDOWN:
565     case JET_SCREEN_MOUSEUP:
566     case JET_SCREEN_MOUSEENTER:
567     case JET_SCREEN_MOUSEEXIT:
568     case JET_SCREEN_INVIEW:
569     case JET_SCREEN_OUTVIEW:
570       return L"Screen";
571     case JET_LINK_MOUSEUP:
572       return L"Link";
573     case JET_MENU_EXEC:
574       return L"Menu";
575     case JET_PAGE_OPEN:
576     case JET_PAGE_CLOSE:
577     case JET_PAGE_INVIEW:
578     case JET_PAGE_OUTVIEW:
579       return L"Page";
580     default:
581       return L"";
582   }
583
584   return L"";
585 }
586
587 FX_BOOL& CJS_EventHandler::Rc() {
588   if (m_pbRc) {
589     return *m_pbRc;
590   }
591   return m_bRcDu;
592 }
593
594 int& CJS_EventHandler::SelEnd() {
595   if (m_pISelEnd) {
596     return *m_pISelEnd;
597   }
598   return m_nSelEndDu;
599 }
600
601 int& CJS_EventHandler::SelStart() {
602   if (m_pISelStart) {
603     return *m_pISelStart;
604   }
605   return m_nSelStartDu;
606 }
607
608 FX_BOOL CJS_EventHandler::Shift() {
609   return m_bShift;
610 }
611
612 Field* CJS_EventHandler::Source() {
613   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
614   v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
615       pRuntime->GetIsolate(), m_pJSContext,
616       FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
617   ASSERT(pDocObj.IsEmpty() == FALSE);
618   v8::Local<v8::Object> pFieldObj =
619       FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
620                            FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
621   ASSERT(pFieldObj.IsEmpty() == FALSE);
622
623   CJS_Document* pJSDocument =
624       (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
625   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
626   pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
627                                     : m_pJSContext->GetReaderDocument());
628
629   CJS_Field* pJSField =
630       (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
631   Field* pField = (Field*)pJSField->GetEmbedObject();
632   pField->AttachField(pDocument, m_strSourceName);
633   return pField;
634 }
635
636 Field* CJS_EventHandler::Target_Field() {
637   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
638   v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
639       pRuntime->GetIsolate(), m_pJSContext,
640       FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
641   ASSERT(pDocObj.IsEmpty() == FALSE);
642   v8::Local<v8::Object> pFieldObj =
643       FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
644                            FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
645   ASSERT(pFieldObj.IsEmpty() == FALSE);
646
647   CJS_Document* pJSDocument =
648       (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
649   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
650   pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
651                                     : m_pJSContext->GetReaderDocument());
652
653   CJS_Field* pJSField =
654       (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
655   Field* pField = (Field*)pJSField->GetEmbedObject();
656   pField->AttachField(pDocument, m_strTargetName);
657   return pField;
658 }
659
660 CFX_WideString& CJS_EventHandler::Value() {
661   return *m_pValue;
662 }
663
664 FX_BOOL CJS_EventHandler::WillCommit() {
665   return m_bWillCommit;
666 }
667
668 CFX_WideString CJS_EventHandler::TargetName() {
669   return m_strTargetName;
670 }