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