Replace some Release() calls with virtual destructors.
[pdfium.git] / fpdfsdk / src / fsdk_actionhandler.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/fsdk_define.h"
8 #include "../include/fpdfxfa/fpdfxfa_doc.h"
9 #include "../include/fsdk_mgr.h"
10 #include "../include/fsdk_actionhandler.h"
11 #include "../include/javascript/IJavaScript.h"
12
13 /* -------------------------- CBA_ActionHandler -------------------------- */
14
15 CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi)
16     : m_pFormActionHandler(new CPDFSDK_FormActionHandler),
17       m_pMediaActionHandler(NULL) {
18 }
19
20 void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler)
21 {
22         ASSERT(pHandler != NULL);
23         ASSERT(m_pMediaActionHandler == NULL);
24         m_pMediaActionHandler = pHandler;
25 }
26
27 //document open
28 FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument)
29 {
30         CFX_PtrList list;
31         return ExecuteDocumentOpenAction(action, pDocument, list);
32 }
33
34 //document open
35 FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName,
36                                                         CPDFSDK_Document* pDocument)
37 {
38         if (JsAction.GetType() == CPDF_Action::JavaScript)
39         {
40                 CFX_WideString swJS = JsAction.GetJavaScript();
41                 if (!swJS.IsEmpty())
42                 {
43                         RunDocumentOpenJavaScript(pDocument, csJSName, swJS);
44                         return TRUE;
45                 }
46         }
47
48         return FALSE;
49 }
50
51 FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type,
52                                                                         CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
53                                                                         PDFSDK_FieldAction& data)
54 {
55         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
56         ASSERT(pEnv);
57         if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript)
58         {
59                 CFX_WideString swJS = JsAction.GetJavaScript();
60                 if (!swJS.IsEmpty())
61                 {
62                         RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
63                         return TRUE;
64                 }
65         }
66         return FALSE;
67 }
68
69 FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
70                                                                                 CPDFSDK_Document* pDocument)
71 {
72         CFX_PtrList list;
73         return ExecuteDocumentPageAction(action, eType, pDocument, list);
74 }
75
76 FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
77                                                                                          CPDFSDK_Document* pDocument)
78 {
79         CFX_PtrList list;
80         return ExecuteDocumentPageAction(action, eType, pDocument, list);
81 }
82
83 FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type,
84                                                         CPDFSDK_Document* pDocument)
85 {
86         CFX_PtrList list;
87         return ExecuteBookMark(action, pDocument, pBookMark, list);
88 }
89
90 FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type,
91                                                                                 CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen)
92 {
93         CFX_PtrList list;
94         return ExecuteScreenAction(action, type, pDocument, pScreen, list);
95 }
96
97 FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action,
98                                                                                 CPDFSDK_Document* pDocument)
99 {
100         CFX_PtrList list;
101         return ExecuteLinkAction(action, pDocument, list);
102 }
103
104 FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type,
105                                                                                 CPDFSDK_Document* pDocument,
106                                                                                 CPDF_FormField* pFormField, PDFSDK_FieldAction& data)
107 {
108         CFX_PtrList list;
109         return ExecuteFieldAction(action, type, pDocument, pFormField, data, list);
110 }
111
112 FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument,
113                                                          CFX_PtrList& list)
114 {
115         CPDF_Dictionary* pDict = action.GetDict();
116         if (list.Find(pDict))
117                 return FALSE;
118
119         list.AddTail(pDict);
120
121         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
122         ASSERT(pEnv);
123         if (action.GetType() == CPDF_Action::JavaScript)
124         {
125                 if(pEnv->IsJSInitiated())
126                 {
127                         CFX_WideString swJS = action.GetJavaScript();
128                         if (!swJS.IsEmpty())
129                         {
130                                 RunDocumentOpenJavaScript(pDocument, L"", swJS);
131                         }
132                 }
133         }
134         else
135         {
136                 DoAction_NoJs(action, pDocument);
137         }
138
139         for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
140         {
141                 CPDF_Action subaction = action.GetSubAction(i);
142                 if (!ExecuteDocumentOpenAction(subaction, pDocument, list)) return FALSE;
143         }
144
145         return TRUE;
146 }
147
148 FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action,     CPDFSDK_Document* pDocument,
149                                                                                                   CFX_PtrList& list)
150 {
151         ASSERT(pDocument != NULL);
152
153         CPDF_Dictionary* pDict = action.GetDict();
154         if (list.Find(pDict))
155                 return FALSE;
156
157         list.AddTail(pDict);
158
159         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
160         ASSERT(pEnv);
161         if (action.GetType() == CPDF_Action::JavaScript)
162         {
163                 if(pEnv->IsJSInitiated())
164                 {
165                         CFX_WideString swJS = action.GetJavaScript();
166                         if (!swJS.IsEmpty())
167                         {
168                                 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //????
169                                 ASSERT(pRuntime != NULL);
170
171                                 pRuntime->SetReaderDocument(pDocument);
172
173                                 IFXJS_Context* pContext = pRuntime->NewContext();
174                                 ASSERT(pContext != NULL);
175
176                                 pContext->OnLink_MouseUp(pDocument);
177
178                                 CFX_WideString csInfo;
179                                 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
180                                 if (!bRet)
181                                 {
182                                         // FIXME: return error.
183                                 }
184
185                                 pRuntime->ReleaseContext(pContext);
186                         }
187                 }
188         }
189         else
190         {
191                 DoAction_NoJs(action, pDocument);
192         }
193
194         for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
195         {
196                 CPDF_Action subaction = action.GetSubAction(i);
197                 if (!ExecuteLinkAction(subaction, pDocument, list)) return FALSE;
198         }
199
200         return TRUE;
201 }
202
203 FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
204                                                                                                  CPDFSDK_Document* pDocument, CFX_PtrList& list)
205 {
206         ASSERT(pDocument != NULL);
207
208         CPDF_Dictionary* pDict = action.GetDict();
209         if (list.Find(pDict))
210                 return FALSE;
211
212         list.AddTail(pDict);
213
214         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
215         ASSERT(pEnv);
216         if (action.GetType() == CPDF_Action::JavaScript)
217         {
218                 if(pEnv->IsJSInitiated())
219                 {
220                         CFX_WideString swJS = action.GetJavaScript();
221                         if (!swJS.IsEmpty())
222                         {
223                                 RunDocumentPageJavaScript(pDocument, type, swJS);
224                         }
225                 }
226         }
227         else
228         {
229                 DoAction_NoJs(action, pDocument);
230         }
231
232         if (!IsValidDocView(pDocument))
233                 return FALSE;
234
235         for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
236         {
237                 CPDF_Action subaction = action.GetSubAction(i);
238                 if (!ExecuteDocumentPageAction(subaction, type, pDocument, list)) return FALSE;
239         }
240
241         return TRUE;
242 }
243
244 FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict)
245 {
246   ASSERT(pDocument != NULL);
247   ASSERT(pFieldDict != NULL);
248
249   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
250   ASSERT(pInterForm != NULL);
251
252   CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
253   ASSERT(pPDFInterForm != NULL);
254
255   return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
256 }
257
258 FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
259                                                                                   CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
260                                                                                   PDFSDK_FieldAction& data, CFX_PtrList& list)
261 {
262         ASSERT(pDocument != NULL);
263
264         CPDF_Dictionary* pDict = action.GetDict();
265         if (list.Find(pDict))
266                 return FALSE;
267
268         list.AddTail(pDict);
269
270         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
271         ASSERT(pEnv);
272         if (action.GetType() == CPDF_Action::JavaScript)
273         {
274                 if(pEnv->IsJSInitiated())
275                 {
276                         CFX_WideString swJS = action.GetJavaScript();
277                         if (!swJS.IsEmpty())
278                         {
279                                 RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
280                                 if (!IsValidField(pDocument, pFormField->GetFieldDict()))
281                                         return FALSE;
282                         }
283                 }
284         }
285         else
286         {
287                 DoAction_NoJs(action, pDocument);
288         }
289
290         for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
291         {
292                 CPDF_Action subaction = action.GetSubAction(i);
293                 if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, list)) return FALSE;
294         }
295
296         return TRUE;
297 }
298
299 FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
300                                                                                 CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen, CFX_PtrList& list)
301 {
302         ASSERT(pDocument != NULL);
303
304         CPDF_Dictionary* pDict = action.GetDict();
305         if (list.Find(pDict))
306                 return FALSE;
307
308         list.AddTail(pDict);
309
310         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
311         ASSERT(pEnv);
312         if (action.GetType() == CPDF_Action::JavaScript)
313         {
314                 if(pEnv->IsJSInitiated())
315                 {
316                         CFX_WideString swJS = action.GetJavaScript();
317                         if (!swJS.IsEmpty())
318                         {
319                                 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
320                                 ASSERT(pRuntime != NULL);
321
322                                 pRuntime->SetReaderDocument(pDocument);
323
324                                 IFXJS_Context* pContext = pRuntime->NewContext();
325                                 ASSERT(pContext != NULL);
326
327         //                      switch (type)
328         //                      {
329         //                      case CPDF_AAction::CursorEnter:
330         //                              pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
331         //                              break;
332         //                      case CPDF_AAction::CursorExit:
333         //                              pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
334         //                              break;
335         //                      case CPDF_AAction::ButtonDown:
336         //                              pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
337         //                              break;
338         //                      case CPDF_AAction::ButtonUp:
339         //                              pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
340         //                              break;
341         //                      case CPDF_AAction::GetFocus:
342         //                              pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
343         //                              break;
344         //                      case CPDF_AAction::LoseFocus:
345         //                              pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
346         //                              break;
347         //                      case CPDF_AAction::PageOpen:
348         //                              pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
349         //                              break;
350         //                      case CPDF_AAction::PageClose:
351         //                              pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
352         //                              break;
353         //                      case CPDF_AAction::PageVisible:
354         //                              pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
355         //                              break;
356         //                      case CPDF_AAction::PageInvisible:
357         //                              pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
358         //                              break;
359         //                      default:
360         //                              ASSERT(FALSE);
361         //                              break;
362         //                      }
363
364                                 CFX_WideString csInfo;
365                                 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
366                                 if (!bRet)
367                                 {
368                                         //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
369                                 }
370
371                                 pRuntime->ReleaseContext(pContext);
372                         }
373                 }
374         }
375         else
376         {
377                 DoAction_NoJs(action, pDocument);
378         }
379
380         for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
381         {
382                 CPDF_Action subaction = action.GetSubAction(i);
383                 if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, list)) return FALSE;
384         }
385
386         return TRUE;
387 }
388
389 FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument,
390                                                                                  CPDF_Bookmark* pBookmark, CFX_PtrList& list)
391 {
392         ASSERT(pDocument != NULL);
393
394         CPDF_Dictionary* pDict = action.GetDict();
395         if (list.Find(pDict))
396                 return FALSE;
397
398         list.AddTail(pDict);
399
400         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
401         ASSERT(pEnv);
402         if (action.GetType() == CPDF_Action::JavaScript)
403         {
404                 if(pEnv->IsJSInitiated())
405                 {
406                         CFX_WideString swJS = action.GetJavaScript();
407                         if (!swJS.IsEmpty())
408                         {
409                                 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
410                                 ASSERT(pRuntime != NULL);
411
412                                 pRuntime->SetReaderDocument(pDocument);
413
414                                 IFXJS_Context* pContext = pRuntime->NewContext();
415                                 ASSERT(pContext != NULL);
416
417                                 pContext->OnBookmark_MouseUp(pBookmark);
418
419                                 CFX_WideString csInfo;
420                                 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
421                                 if (!bRet)
422                                 {
423                                         //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
424                                 }
425
426                                 pRuntime->ReleaseContext(pContext);
427                         }
428                 }
429         }
430         else
431         {
432                 DoAction_NoJs(action, pDocument);
433         }
434
435         for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
436         {
437                 CPDF_Action subaction = action.GetSubAction(i);
438                 if (!ExecuteBookMark(subaction, pDocument, pBookmark, list)) return FALSE;
439         }
440
441         return TRUE;
442 }
443
444 void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument)
445 {
446         ASSERT(pDocument != NULL);
447
448         switch (action.GetType())
449         {
450         case CPDF_Action::GoTo:
451                 DoAction_GoTo(pDocument, action);
452                 break;
453         case CPDF_Action::GoToR:
454                 DoAction_GoToR(pDocument, action);
455                 break;
456         case CPDF_Action::GoToE:
457                 break;
458         case CPDF_Action::Launch:
459                 DoAction_Launch(pDocument, action);
460                 break;
461         case CPDF_Action::Thread:
462                 break;
463         case CPDF_Action::URI:
464                 DoAction_URI(pDocument, action);
465                 break;
466         case CPDF_Action::Sound:
467                 if (m_pMediaActionHandler)
468                 {
469                         m_pMediaActionHandler->DoAction_Sound(action, pDocument);
470                 }
471                 break;
472         case CPDF_Action::Movie:
473                 if (m_pMediaActionHandler)
474                 {
475                         m_pMediaActionHandler->DoAction_Movie(action, pDocument);
476                 }
477                 break;
478         case CPDF_Action::Hide:
479                 if (m_pFormActionHandler)
480                 {
481                         m_pFormActionHandler->DoAction_Hide(action, pDocument);
482                 }
483                 break;
484         case CPDF_Action::Named:
485                 DoAction_Named(pDocument, action);
486                 break;
487         case CPDF_Action::SubmitForm:
488                 if (m_pFormActionHandler)
489                 {
490                         m_pFormActionHandler->DoAction_SubmitForm(action, pDocument);
491                 }
492                 break;
493         case CPDF_Action::ResetForm:
494                 if (m_pFormActionHandler)
495                 {
496                         m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
497                 }
498                 break;
499         case CPDF_Action::ImportData:
500                 if (m_pFormActionHandler)
501                 {
502                         m_pFormActionHandler->DoAction_ImportData(action, pDocument);
503                 }
504                 break;
505         case CPDF_Action::JavaScript:
506                 ASSERT(FALSE);
507                 break;
508         case CPDF_Action::SetOCGState:
509                 DoAction_SetOCGState(pDocument,  action);
510                 break;
511         case CPDF_Action::Rendition:
512                 if (m_pMediaActionHandler)
513                 {
514                         m_pMediaActionHandler->DoAction_Rendition(action, pDocument);
515                 }
516                 break;
517         case CPDF_Action::Trans:
518                 break;
519         case CPDF_Action::GoTo3DView:
520                 break;
521         default:
522                 break;
523         }
524 }
525
526 FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument)
527 {
528         ASSERT(pDocument != NULL);
529         return TRUE;
530 }
531
532 void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument,
533                                                                   const CPDF_Action& action)
534 {
535         ASSERT(action);
536
537         CPDF_Document* pPDFDocument = pDocument->GetDocument()->GetPDFDoc();
538         ASSERT(pPDFDocument != NULL);
539         CPDFDoc_Environment* pApp = pDocument->GetEnv();
540         ASSERT(pApp != NULL);
541
542         CPDF_Dest MyDest = action.GetDest(pPDFDocument);
543         int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
544         int nFitType = MyDest.GetZoomMode();
545         const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.GetObject();
546         float* pPosAry = NULL;
547         int sizeOfAry = 0;
548         if (pMyArray != NULL)
549         {
550                 pPosAry = new float[pMyArray->GetCount()];
551                 int j = 0;
552                 for (int i = 2; i < (int)pMyArray->GetCount(); i++)
553                 {
554                         pPosAry[j++] = pMyArray->GetFloat(i);
555                 }
556                 sizeOfAry = j;
557         }
558         pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
559         if(pPosAry)
560                 delete[] pPosAry;
561 }
562
563 void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action)
564 {
565
566 }
567
568 void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action)
569 {
570
571 }
572
573 void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action)
574 {
575         ASSERT(action);
576
577         CPDFDoc_Environment* pApp = pDocument->GetEnv();
578         ASSERT(pApp != NULL);
579
580         CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc());
581         pApp->FFI_DoURIAction(sURI.c_str());
582 }
583
584 void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action)
585 {
586         ASSERT(action);
587
588         CFX_ByteString csName = action.GetNamedAction();
589         pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
590 }
591
592
593 void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, const CPDF_Action& action)
594 {
595 }
596
597 void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type,
598                                                                                 PDFSDK_FieldAction& data, const CFX_WideString& script)
599 {
600         ASSERT(type != CPDF_AAction::Calculate);
601         ASSERT(type != CPDF_AAction::Format);
602
603         ASSERT(pDocument != NULL);
604
605         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
606         ASSERT(pRuntime != NULL);
607
608         pRuntime->SetReaderDocument(pDocument);
609
610         IFXJS_Context* pContext = pRuntime->NewContext();
611         ASSERT(pContext != NULL);
612
613         switch (type)
614         {
615         case CPDF_AAction::CursorEnter:
616                 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
617                 break;
618         case CPDF_AAction::CursorExit:
619                 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
620                 break;
621         case CPDF_AAction::ButtonDown:
622                 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
623                 break;
624         case CPDF_AAction::ButtonUp:
625                 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
626                 break;
627         case CPDF_AAction::GetFocus:
628                 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue);
629                 break;
630         case CPDF_AAction::LoseFocus:
631                 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue);
632                 break;
633         case CPDF_AAction::KeyStroke:
634                 pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
635                         data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue,
636                         data.bWillCommit, data.bFieldFull, data.bRC);
637                 break;
638         case CPDF_AAction::Validate:
639                 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier,
640                         data.bShift, pFormField, data.sValue, data.bRC);
641                 break;
642         default:
643                 ASSERT(FALSE);
644                 break;
645         }
646
647         CFX_WideString csInfo;
648         FX_BOOL bRet = pContext->RunScript(script, csInfo);
649         if (!bRet)
650         {
651                 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
652         }
653
654         pRuntime->ReleaseContext(pContext);
655 }
656
657 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, const CFX_WideString& script)
658 {
659         ASSERT(pDocument != NULL);
660
661         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
662         ASSERT(pRuntime != NULL);
663
664         pRuntime->SetReaderDocument(pDocument);
665
666         IFXJS_Context* pContext = pRuntime->NewContext();
667         ASSERT(pContext != NULL);
668
669         pContext->OnDoc_Open(pDocument, sScriptName);
670
671         CFX_WideString csInfo;
672         FX_BOOL bRet = pContext->RunScript(script, csInfo);
673         if (!bRet)
674         {
675                 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
676         }
677
678         pRuntime->ReleaseContext(pContext);
679 }
680
681 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script)
682 {
683         ASSERT(pDocument != NULL);
684
685         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
686         ASSERT(pRuntime != NULL);
687
688         pRuntime->SetReaderDocument(pDocument);
689
690         IFXJS_Context* pContext = pRuntime->NewContext();
691         ASSERT(pContext != NULL);
692
693         switch (type)
694         {
695         case CPDF_AAction::OpenPage:
696                 pContext->OnPage_Open(pDocument);
697                 break;
698         case CPDF_AAction::ClosePage:
699                 pContext->OnPage_Close(pDocument);
700                 break;
701         case CPDF_AAction::CloseDocument:
702                 pContext->OnDoc_WillClose(pDocument);
703                 break;
704         case CPDF_AAction::SaveDocument:
705                 pContext->OnDoc_WillSave(pDocument);
706                 break;
707         case CPDF_AAction::DocumentSaved:
708                 pContext->OnDoc_DidSave(pDocument);
709                 break;
710         case CPDF_AAction::PrintDocument:
711                 pContext->OnDoc_WillPrint(pDocument);
712                 break;
713         case CPDF_AAction::DocumentPrinted:
714                 pContext->OnDoc_DidPrint(pDocument);
715                 break;
716         case CPDF_AAction::PageVisible:
717                 pContext->OnPage_InView(pDocument);
718                 break;
719         case CPDF_AAction::PageInvisible:
720                 pContext->OnPage_OutView(pDocument);
721                 break;
722         default:
723                 ASSERT(FALSE);
724                 break;
725         }
726
727         CFX_WideString csInfo;
728         FX_BOOL bRet = pContext->RunScript(script, csInfo);
729         if (!bRet)
730         {
731                 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
732         }
733
734         pRuntime->ReleaseContext(pContext);
735 }
736
737
738 FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument)
739 {
740         ASSERT(pDocument != NULL);
741
742         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
743         ASSERT(pInterForm != NULL);
744
745         if (pInterForm->DoAction_Hide(action))
746         {
747                 pDocument->SetChangeMark();
748                 return TRUE;
749         }
750
751         return FALSE;
752 }
753
754 FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
755 {
756         ASSERT(pDocument != NULL);
757
758         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
759         ASSERT(pInterForm != NULL);
760
761         return pInterForm->DoAction_SubmitForm(action);
762 }
763
764 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
765 {
766         ASSERT(pDocument != NULL);
767
768         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
769         ASSERT(pInterForm != NULL);
770
771         if (pInterForm->DoAction_ResetForm(action))
772         {
773                 return TRUE;
774         }
775
776         return FALSE;
777 }
778
779 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument)
780 {
781         ASSERT(pDocument != NULL);
782
783         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
784         ASSERT(pInterForm != NULL);
785
786         if (pInterForm->DoAction_ImportData(action))
787         {
788                 pDocument->SetChangeMark();
789                 return TRUE;
790         }
791
792         return FALSE;
793 }
794
795 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument)
796 {
797         return FALSE;
798 }
799
800 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument)
801 {
802         return FALSE;
803 }
804
805 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument)
806 {
807         return FALSE;
808 }