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