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