Remove trailing whitespaces in fpdfsdk.
[pdfium.git] / fpdfsdk / src / fsdk_actionhandler.cpp
index 2a3898c..b790585 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../include/fsdk_define.h"\r
-#include "../include/fsdk_mgr.h"\r
-#include "../include/fsdk_actionhandler.h"\r
-#include "../include/javascript/IJavaScript.h"\r
-\r
-/* -------------------------- CBA_ActionHandler -------------------------- */\r
-\r
-CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) : \r
-       m_pEvi(pEvi),\r
-       m_pFormActionHandler(NULL),\r
-       m_pMediaActionHandler(NULL)\r
-{\r
-               m_pFormActionHandler = new CPDFSDK_FormActionHandler;\r
-}\r
-\r
-CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler()\r
-{\r
-       if(m_pFormActionHandler)\r
-       {\r
-               delete m_pFormActionHandler;\r
-               m_pFormActionHandler = NULL;\r
-       }\r
-}\r
-\r
-void CPDFSDK_ActionHandler::SetFormActionHandler(CPDFSDK_FormActionHandler* pHandler)\r
-{\r
-       ASSERT(pHandler != NULL);\r
-       ASSERT(m_pFormActionHandler == NULL);\r
-       m_pFormActionHandler = pHandler;\r
-}\r
-\r
-void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler)\r
-{\r
-       ASSERT(pHandler != NULL);\r
-       ASSERT(m_pMediaActionHandler == NULL);\r
-       m_pMediaActionHandler = pHandler;\r
-}\r
-\r
-void CPDFSDK_ActionHandler::Destroy()\r
-{\r
-       delete this;\r
-}\r
-\r
-//document open\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument\r
-                                                                                               /*CReader_Document* pDocument, CReader_DocView *pDocView*/)\r
-{\r
-       CFX_PtrList list;\r
-       return ExecuteDocumentOpenAction(action, pDocument, /*pDocView, */list);\r
-}\r
-\r
-//document open\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName,\r
-                                                       CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)\r
-{\r
-       if (JsAction.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               CFX_WideString swJS = JsAction.GetJavaScript();\r
-               if (!swJS.IsEmpty())\r
-               {\r
-                       RunDocumentOpenJavaScript(pDocument, csJSName, swJS);\r
-                       return TRUE;\r
-               }\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type, \r
-                                                                       CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, \r
-                                                                       PDFSDK_FieldAction& data)\r
-{\r
-       CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               CFX_WideString swJS = JsAction.GetJavaScript();\r
-               if (!swJS.IsEmpty())\r
-               {\r
-                       RunFieldJavaScript(pDocument, pFormField, type, data, swJS);\r
-                       return TRUE;\r
-               }\r
-       }\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,\r
-                                                                               CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)\r
-{\r
-       CFX_PtrList list;\r
-       return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list);\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,\r
-                                                                                        CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)\r
-{\r
-       CFX_PtrList list;\r
-       return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list);\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type, \r
-                                                       CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)\r
-{\r
-       CFX_PtrList list;\r
-       return this->ExecuteBookMark(action, pDocument,/* pDocView,*/ pBookMark, list);\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type, \r
-                                                                               CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ CPDFSDK_Annot* pScreen)\r
-{\r
-       CFX_PtrList list;\r
-       return this->ExecuteScreenAction(action, type, pDocument,/* pDocView,*/ pScreen, list);\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action, \r
-                                                                               CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)\r
-{\r
-       CFX_PtrList list;\r
-       return ExecuteLinkAction(action, pDocument,/* pDocView,*/ list);\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type, \r
-                                                                               CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ \r
-                                                                               CPDF_FormField* pFormField, PDFSDK_FieldAction& data)\r
-{\r
-       CFX_PtrList list;\r
-       return ExecuteFieldAction(action, type, pDocument,/* pDocView,*/ pFormField, data, list);\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument,\r
-                                                                                                        /*CReader_DocView *pDocView,*/ CFX_PtrList& list)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       if (list.Find((CPDF_Dictionary*)action))\r
-               return FALSE;\r
-       list.AddTail((CPDF_Dictionary*)action);\r
-\r
-       CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if (action.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               if(pEnv->IsJSInitiated())\r
-               {\r
-                       CFX_WideString swJS = action.GetJavaScript();\r
-                       if (!swJS.IsEmpty())\r
-                       {\r
-                               RunDocumentOpenJavaScript(pDocument, L"", swJS);\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               DoAction_NoJs(action, pDocument/*, pDocView*/);\r
-       }\r
-\r
-//     if (!IsValidDocView(pDocument, pDocView))\r
-//             return FALSE;\r
-\r
-       for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)\r
-       {\r
-               CPDF_Action subaction = action.GetSubAction(i);\r
-               if (!ExecuteDocumentOpenAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action,    CPDFSDK_Document* pDocument,\r
-                                                                                                /*CReader_DocView* pDocView,*/ CFX_PtrList& list)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       if (list.Find((CPDF_Dictionary*)action))\r
-               return FALSE;\r
-       list.AddTail((CPDF_Dictionary*)action);\r
-\r
-       CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if (action.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               if(pEnv->IsJSInitiated())\r
-               {\r
-                       CFX_WideString swJS = action.GetJavaScript();\r
-                       if (!swJS.IsEmpty())\r
-                       {\r
-                               IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //????\r
-                               ASSERT(pRuntime != NULL);\r
-\r
-                               pRuntime->SetReaderDocument(pDocument);\r
-\r
-                               IFXJS_Context* pContext = pRuntime->NewContext();\r
-                               ASSERT(pContext != NULL);\r
-\r
-                               pContext->OnLink_MouseUp(pDocument);\r
-\r
-                               CFX_WideString csInfo;\r
-                               FX_BOOL bRet = pContext->RunScript(swJS, csInfo);\r
-                               if (!bRet)\r
-                               {\r
-                                       //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);\r
-                               }\r
-\r
-                               pRuntime->ReleaseContext(pContext);\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               DoAction_NoJs(action, pDocument/*, pDocView*/);\r
-       }\r
-\r
-//     if (!IsValidDocView(pDocument, pDocView))\r
-//             return FALSE;\r
-\r
-       for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)\r
-       {\r
-               CPDF_Action subaction = action.GetSubAction(i);\r
-               if (!ExecuteLinkAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& action, CPDF_AAction::AActionType type,\r
-                                                                                                CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CFX_PtrList& list)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       if (list.Find((CPDF_Dictionary*)action))\r
-               return FALSE;\r
-       list.AddTail((CPDF_Dictionary*)action);\r
-\r
-       CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if (action.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               if(pEnv->IsJSInitiated())\r
-               {\r
-                       CFX_WideString swJS = action.GetJavaScript();\r
-                       if (!swJS.IsEmpty())\r
-                       {\r
-                               RunDocumentPageJavaScript(pDocument, type, swJS);\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               DoAction_NoJs(action, pDocument/*, pDocView*/);\r
-       }\r
-\r
-       if (!IsValidDocView(pDocument/*, pDocView*/))\r
-               return FALSE;\r
-\r
-       for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)\r
-       {\r
-               CPDF_Action subaction = action.GetSubAction(i);\r
-               if (!ExecuteDocumentPageAction(subaction, type, pDocument,/* pDocView,*/ list)) return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict)\r
-{\r
-       ASSERT(m_pEvi != NULL);\r
-       ASSERT(pDocument != NULL);\r
-       ASSERT(pFieldDict != NULL);\r
-\r
-       if (1/*m_pApp->IsValidDocument(pDocument)*/)\r
-       {\r
-               CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();\r
-               ASSERT(pInterForm != NULL);\r
-\r
-               CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();\r
-               ASSERT(pPDFInterForm != NULL);\r
-\r
-               return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type, \r
-                                                                                 CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDF_FormField* pFormField, \r
-                                                                                 PDFSDK_FieldAction& data, CFX_PtrList& list)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       if (list.Find((CPDF_Dictionary*)action))\r
-               return FALSE;\r
-       list.AddTail((CPDF_Dictionary*)action);\r
-\r
-       CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if (action.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               if(pEnv->IsJSInitiated())\r
-               {\r
-                       CFX_WideString swJS = action.GetJavaScript();\r
-                       if (!swJS.IsEmpty())\r
-                       {\r
-                               RunFieldJavaScript(pDocument, pFormField, type, data, swJS);\r
-                               if (!IsValidField(pDocument, pFormField->GetFieldDict()))\r
-                                       return FALSE;\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               DoAction_NoJs(action, pDocument/*, pDocView*/);\r
-//             if (!IsValidDocView(pDocument, pDocView))\r
-//                     return FALSE;\r
-       }\r
-\r
-       for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)\r
-       {\r
-               CPDF_Action subaction = action.GetSubAction(i);\r
-               if (!ExecuteFieldAction(subaction, type, pDocument,/* pDocView,*/ pFormField, data, list)) return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type, \r
-                                                                               CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDFSDK_Annot* pScreen, CFX_PtrList& list)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       if (list.Find((CPDF_Dictionary*)action))\r
-               return FALSE;\r
-       list.AddTail((CPDF_Dictionary*)action);\r
-\r
-       CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if (action.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               if(pEnv->IsJSInitiated())\r
-               {\r
-                       CFX_WideString swJS = action.GetJavaScript();\r
-                       if (!swJS.IsEmpty())\r
-                       {\r
-                               IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();\r
-                               ASSERT(pRuntime != NULL);\r
-\r
-                               pRuntime->SetReaderDocument(pDocument);\r
-\r
-                               IFXJS_Context* pContext = pRuntime->NewContext();\r
-                               ASSERT(pContext != NULL);\r
-\r
-       //                      switch (type)\r
-       //                      {\r
-       //                      case CPDF_AAction::CursorEnter:\r
-       //                              pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::CursorExit:\r
-       //                              pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::ButtonDown:\r
-       //                              pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::ButtonUp:\r
-       //                              pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::GetFocus:\r
-       //                              pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::LoseFocus:\r
-       //                              pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::PageOpen:\r
-       //                              pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::PageClose:\r
-       //                              pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::PageVisible:\r
-       //                              pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      case CPDF_AAction::PageInvisible:\r
-       //                              pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);\r
-       //                              break;\r
-       //                      default:\r
-       //                              ASSERT(FALSE);\r
-       //                              break;\r
-       //                      }\r
-\r
-                               CFX_WideString csInfo;\r
-                               FX_BOOL bRet = pContext->RunScript(swJS, csInfo);\r
-                               if (!bRet)\r
-                               {\r
-                                       //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);\r
-                               }\r
-\r
-                               pRuntime->ReleaseContext(pContext);\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               DoAction_NoJs(action, pDocument/*, pDocView*/);\r
-       }\r
-\r
-//     if (!IsValidDocView(pDocument, pDocView))\r
-//             return FALSE;\r
-\r
-       for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)\r
-       {\r
-               CPDF_Action subaction = action.GetSubAction(i);\r
-               if (!ExecuteScreenAction(subaction, type, pDocument,/* pDocView,*/ pScreen, list)) return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument, \r
-                                                                               /*CReader_DocView* pDocView,*/ CPDF_Bookmark* pBookmark, CFX_PtrList& list)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       if (list.Find((CPDF_Dictionary*)action))\r
-               return FALSE;\r
-       list.AddTail((CPDF_Dictionary*)action);\r
-\r
-       CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if (action.GetType() == CPDF_Action::JavaScript)\r
-       {\r
-               if(pEnv->IsJSInitiated())\r
-               {\r
-                       CFX_WideString swJS = action.GetJavaScript();\r
-                       if (!swJS.IsEmpty())\r
-                       {\r
-                               IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();\r
-                               ASSERT(pRuntime != NULL);\r
-\r
-                               pRuntime->SetReaderDocument(pDocument);\r
-\r
-                               IFXJS_Context* pContext = pRuntime->NewContext();\r
-                               ASSERT(pContext != NULL);\r
-\r
-                               pContext->OnBookmark_MouseUp(pBookmark);\r
-\r
-                               CFX_WideString csInfo;\r
-                               FX_BOOL bRet = pContext->RunScript(swJS, csInfo);\r
-                               if (!bRet)\r
-                               {\r
-                                       //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);\r
-                               }\r
-\r
-                               pRuntime->ReleaseContext(pContext);\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               DoAction_NoJs(action, pDocument/*, pDocView*/);\r
-       }\r
-\r
-//     if (!IsValidDocView(pDocument, pDocView))\r
-//             return FALSE;\r
-\r
-       for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)\r
-       {\r
-               CPDF_Action subaction = action.GetSubAction(i);\r
-               if (!ExecuteBookMark(subaction, pDocument,/* pDocView,*/ pBookmark, list)) return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       switch (action.GetType())\r
-       {\r
-       case CPDF_Action::GoTo:\r
-               DoAction_GoTo(pDocument,/* pDocView,*/ action);\r
-               break;\r
-       case CPDF_Action::GoToR:\r
-               DoAction_GoToR(pDocument, action);\r
-               break;\r
-       case CPDF_Action::GoToE:\r
-               break;\r
-       case CPDF_Action::Launch:\r
-               DoAction_Launch(pDocument, action);\r
-               break;\r
-       case CPDF_Action::Thread:\r
-               break;\r
-       case CPDF_Action::URI:\r
-               DoAction_URI(pDocument, action);\r
-               break;\r
-       case CPDF_Action::Sound:\r
-               if (m_pMediaActionHandler)\r
-               {\r
-                       m_pMediaActionHandler->DoAction_Sound(action, pDocument/*, pDocView*/);\r
-               }\r
-               break;\r
-       case CPDF_Action::Movie:\r
-               if (m_pMediaActionHandler)\r
-               {\r
-                       m_pMediaActionHandler->DoAction_Movie(action, pDocument/*, pDocView*/);\r
-               }\r
-               break;\r
-       case CPDF_Action::Hide:\r
-               if (m_pFormActionHandler)\r
-               {\r
-                       m_pFormActionHandler->DoAction_Hide(action, pDocument);\r
-               }\r
-               break;\r
-       case CPDF_Action::Named:\r
-               DoAction_Named(pDocument, action);\r
-               break;\r
-       case CPDF_Action::SubmitForm:\r
-               if (m_pFormActionHandler)\r
-               {\r
-                       m_pFormActionHandler->DoAction_SubmitForm(action, pDocument/*, pDocView*/);\r
-               }\r
-               break;\r
-       case CPDF_Action::ResetForm:\r
-               if (m_pFormActionHandler)\r
-               {\r
-                       m_pFormActionHandler->DoAction_ResetForm(action, pDocument);\r
-               }\r
-               break;\r
-       case CPDF_Action::ImportData:\r
-               if (m_pFormActionHandler)\r
-               {\r
-                       m_pFormActionHandler->DoAction_ImportData(action, pDocument/*, pDocView*/);\r
-               }\r
-               break;\r
-       case CPDF_Action::JavaScript:\r
-               ASSERT(FALSE);\r
-               break;\r
-       case CPDF_Action::SetOCGState:\r
-               DoAction_SetOCGState(pDocument, /*pDocView,*/ action);\r
-               break;\r
-       case CPDF_Action::Rendition:\r
-               if (m_pMediaActionHandler)\r
-               {\r
-                       m_pMediaActionHandler->DoAction_Rendition(action, pDocument/*, pDocView*/);\r
-               }\r
-               break;\r
-       case CPDF_Action::Trans:\r
-               break;\r
-       case CPDF_Action::GoTo3DView:\r
-               break;\r
-       default:\r
-               break;\r
-       }\r
-}\r
-\r
-FX_BOOL        CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       //ASSERT(pDocView != NULL);\r
-\r
-       //return pDocument->IsValidDocView(pDocView);\r
-       return TRUE;\r
-}\r
-\r
-void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, /*CReader_DocView* pDocView,*/\r
-                                                                 const CPDF_Action& action)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-//     ASSERT(pDocView != NULL);\r
-       ASSERT(action != NULL);\r
-\r
-       CPDF_Document* pPDFDocument = pDocument->GetDocument();\r
-       ASSERT(pPDFDocument != NULL);\r
-       CPDFDoc_Environment* pApp = pDocument->GetEnv();\r
-       ASSERT(pApp != NULL);\r
-\r
-       CPDF_Dest MyDest = action.GetDest(pPDFDocument);\r
-       int nPageIndex = MyDest.GetPageIndex(pPDFDocument);\r
-       int nFitType = MyDest.GetZoomMode();\r
-       const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.m_pObj;\r
-       float* pPosAry = NULL;\r
-       int sizeOfAry = 0;\r
-       if (pMyArray != NULL)\r
-       {\r
-               pPosAry = new float[pMyArray->GetCount()];\r
-               int j = 0;\r
-               for (int i = 2; i < (int)pMyArray->GetCount(); i++)\r
-               {\r
-                       pPosAry[j++] = pMyArray->GetFloat(i);\r
-               }\r
-               sizeOfAry = j;\r
-       }\r
-       pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);\r
-       if(pPosAry)\r
-               delete[] pPosAry;\r
-}\r
-\r
-void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action)\r
-{\r
-\r
-}\r
-\r
-void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action)\r
-{\r
-\r
-}\r
-\r
-void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       ASSERT(action != NULL);\r
-\r
-       CPDFDoc_Environment* pApp = pDocument->GetEnv();\r
-       ASSERT(pApp != NULL);\r
\r
-       CFX_ByteString sURI = action.GetURI(pDocument->GetDocument());\r
-       pApp->FFI_DoURIAction(FX_LPCSTR(sURI));\r
-}\r
-\r
-void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       ASSERT(action != NULL);\r
\r
-       CFX_ByteString csName = action.GetNamedAction();\r
-       pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);\r
-}\r
-\r
-\r
-void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ const CPDF_Action& action)\r
-{\r
-}\r
-\r
-void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type,\r
-                                                                               PDFSDK_FieldAction& data, const CFX_WideString& script)\r
-{\r
-       ASSERT(type != CPDF_AAction::Calculate);\r
-       ASSERT(type != CPDF_AAction::Format);\r
-\r
-       ASSERT(pDocument != NULL);\r
-\r
-       IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       pRuntime->SetReaderDocument(pDocument);\r
-\r
-       IFXJS_Context* pContext = pRuntime->NewContext();\r
-       ASSERT(pContext != NULL);\r
-\r
-       switch (type)\r
-       {\r
-       case CPDF_AAction::CursorEnter:\r
-               pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);\r
-               break;\r
-       case CPDF_AAction::CursorExit:\r
-               pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);\r
-               break;\r
-       case CPDF_AAction::ButtonDown:\r
-               pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);\r
-               break;\r
-       case CPDF_AAction::ButtonUp:\r
-               pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);\r
-               break;\r
-       case CPDF_AAction::GetFocus:\r
-               pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue);\r
-               break;\r
-       case CPDF_AAction::LoseFocus:\r
-               pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue);\r
-               break;\r
-       case CPDF_AAction::KeyStroke:\r
-               pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown, \r
-                       data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue,\r
-                       data.bWillCommit, data.bFieldFull, data.bRC);\r
-               break;\r
-       case CPDF_AAction::Validate:\r
-               pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier,\r
-                       data.bShift, pFormField, data.sValue, data.bRC);\r
-               break;\r
-       default:\r
-               ASSERT(FALSE);\r
-               break;\r
-       }\r
-\r
-       CFX_WideString csInfo;\r
-       FX_BOOL bRet = pContext->RunScript(script, csInfo);\r
-       if (!bRet)\r
-       {\r
-               //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);\r
-       }\r
-\r
-       pRuntime->ReleaseContext(pContext);\r
-}\r
-\r
-void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, const CFX_WideString& script)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       pRuntime->SetReaderDocument(pDocument);\r
-\r
-       IFXJS_Context* pContext = pRuntime->NewContext();\r
-       ASSERT(pContext != NULL);\r
-\r
-       pContext->OnDoc_Open(pDocument, sScriptName);\r
-\r
-       CFX_WideString csInfo;\r
-       FX_BOOL bRet = pContext->RunScript(script, csInfo);\r
-       if (!bRet)\r
-       {\r
-               //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);\r
-       }\r
-\r
-       pRuntime->ReleaseContext(pContext);\r
-}\r
-\r
-void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-\r
-       IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       pRuntime->SetReaderDocument(pDocument);\r
-\r
-       IFXJS_Context* pContext = pRuntime->NewContext();\r
-       ASSERT(pContext != NULL);\r
-\r
-       switch (type)\r
-       {       \r
-       case CPDF_AAction::OpenPage:\r
-               pContext->OnPage_Open(pDocument);\r
-               break;\r
-       case CPDF_AAction::ClosePage:\r
-               pContext->OnPage_Close(pDocument);\r
-               break;\r
-       case CPDF_AAction::CloseDocument:\r
-               pContext->OnDoc_WillClose(pDocument);\r
-               break;\r
-       case CPDF_AAction::SaveDocument:\r
-               pContext->OnDoc_WillSave(pDocument);\r
-               break;\r
-       case CPDF_AAction::DocumentSaved:\r
-               pContext->OnDoc_DidSave(pDocument);\r
-               break;\r
-       case CPDF_AAction::PrintDocument:\r
-               pContext->OnDoc_WillPrint(pDocument);\r
-               break;\r
-       case CPDF_AAction::DocumentPrinted:\r
-               pContext->OnDoc_DidPrint(pDocument);\r
-               break;\r
-       case CPDF_AAction::PageVisible:\r
-               pContext->OnPage_InView(pDocument);\r
-               break;\r
-       case CPDF_AAction::PageInvisible:\r
-               pContext->OnPage_OutView(pDocument);\r
-               break;\r
-       default:\r
-               ASSERT(FALSE);\r
-               break;\r
-       }\r
-\r
-       CFX_WideString csInfo;\r
-       FX_BOOL bRet = pContext->RunScript(script, csInfo);\r
-       if (!bRet)\r
-       {\r
-               //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);\r
-       }\r
-\r
-       pRuntime->ReleaseContext(pContext);\r
-}\r
-\r
-\r
-FX_BOOL        CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       \r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-       \r
-       if (pInterForm->DoAction_Hide(action))\r
-       {\r
-               pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       \r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-       \r
-       return pInterForm->DoAction_SubmitForm(action);\r
-}\r
-\r
-FX_BOOL        CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       \r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-       \r
-       if (pInterForm->DoAction_ResetForm(action))\r
-       {       \r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument)\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       \r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-       \r
-       if (pInterForm->DoAction_ImportData(action))\r
-       {\r
-               pDocument->SetChangeMark();     \r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument)\r
-{\r
-       return FALSE;\r
-}\r
-\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+#include "../include/fsdk_actionhandler.h"
+#include "../include/javascript/IJavaScript.h"
+
+/* -------------------------- CBA_ActionHandler -------------------------- */
+
+CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) :
+       m_pFormActionHandler(NULL),
+       m_pMediaActionHandler(NULL)
+{
+               m_pFormActionHandler = new CPDFSDK_FormActionHandler;
+}
+
+CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler()
+{
+       if(m_pFormActionHandler)
+       {
+               delete m_pFormActionHandler;
+               m_pFormActionHandler = NULL;
+       }
+}
+
+void CPDFSDK_ActionHandler::SetFormActionHandler(CPDFSDK_FormActionHandler* pHandler)
+{
+       ASSERT(pHandler != NULL);
+       ASSERT(m_pFormActionHandler == NULL);
+       m_pFormActionHandler = pHandler;
+}
+
+void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler)
+{
+       ASSERT(pHandler != NULL);
+       ASSERT(m_pMediaActionHandler == NULL);
+       m_pMediaActionHandler = pHandler;
+}
+
+void CPDFSDK_ActionHandler::Destroy()
+{
+       delete this;
+}
+
+//document open
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       CFX_PtrList list;
+       return ExecuteDocumentOpenAction(action, pDocument, list);
+}
+
+//document open
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName,
+                                                       CPDFSDK_Document* pDocument)
+{
+       if (JsAction.GetType() == CPDF_Action::JavaScript)
+       {
+               CFX_WideString swJS = JsAction.GetJavaScript();
+               if (!swJS.IsEmpty())
+               {
+                       RunDocumentOpenJavaScript(pDocument, csJSName, swJS);
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type,
+                                                                       CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
+                                                                       PDFSDK_FieldAction& data)
+{
+       CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+       ASSERT(pEnv);
+       if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript)
+       {
+               CFX_WideString swJS = JsAction.GetJavaScript();
+               if (!swJS.IsEmpty())
+               {
+                       RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
+                       return TRUE;
+               }
+       }
+       return FALSE;
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
+                                                                               CPDFSDK_Document* pDocument)
+{
+       CFX_PtrList list;
+       return ExecuteDocumentPageAction(action, eType, pDocument, list);
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
+                                                                                        CPDFSDK_Document* pDocument)
+{
+       CFX_PtrList list;
+       return ExecuteDocumentPageAction(action, eType, pDocument, list);
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type,
+                                                       CPDFSDK_Document* pDocument)
+{
+       CFX_PtrList list;
+       return ExecuteBookMark(action, pDocument, pBookMark, list);
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type,
+                                                                               CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen)
+{
+       CFX_PtrList list;
+       return ExecuteScreenAction(action, type, pDocument, pScreen, list);
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action,
+                                                                               CPDFSDK_Document* pDocument)
+{
+       CFX_PtrList list;
+       return ExecuteLinkAction(action, pDocument, list);
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type,
+                                                                               CPDFSDK_Document* pDocument,
+                                                                               CPDF_FormField* pFormField, PDFSDK_FieldAction& data)
+{
+       CFX_PtrList list;
+       return ExecuteFieldAction(action, type, pDocument, pFormField, data, list);
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument,
+                                                         CFX_PtrList& list)
+{
+       CPDF_Dictionary* pDict = action.GetDict();
+       if (list.Find(pDict))
+               return FALSE;
+
+       list.AddTail(pDict);
+
+       CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+       ASSERT(pEnv);
+       if (action.GetType() == CPDF_Action::JavaScript)
+       {
+               if(pEnv->IsJSInitiated())
+               {
+                       CFX_WideString swJS = action.GetJavaScript();
+                       if (!swJS.IsEmpty())
+                       {
+                               RunDocumentOpenJavaScript(pDocument, L"", swJS);
+                       }
+               }
+       }
+       else
+       {
+               DoAction_NoJs(action, pDocument);
+       }
+
+       for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+       {
+               CPDF_Action subaction = action.GetSubAction(i);
+               if (!ExecuteDocumentOpenAction(subaction, pDocument, list)) return FALSE;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action,    CPDFSDK_Document* pDocument,
+                                                                                                 CFX_PtrList& list)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDF_Dictionary* pDict = action.GetDict();
+       if (list.Find(pDict))
+               return FALSE;
+
+       list.AddTail(pDict);
+
+       CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+       ASSERT(pEnv);
+       if (action.GetType() == CPDF_Action::JavaScript)
+       {
+               if(pEnv->IsJSInitiated())
+               {
+                       CFX_WideString swJS = action.GetJavaScript();
+                       if (!swJS.IsEmpty())
+                       {
+                               IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //????
+                               ASSERT(pRuntime != NULL);
+
+                               pRuntime->SetReaderDocument(pDocument);
+
+                               IFXJS_Context* pContext = pRuntime->NewContext();
+                               ASSERT(pContext != NULL);
+
+                               pContext->OnLink_MouseUp(pDocument);
+
+                               CFX_WideString csInfo;
+                               FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
+                               if (!bRet)
+                               {
+                                       // FIXME: return error.
+                               }
+
+                               pRuntime->ReleaseContext(pContext);
+                       }
+               }
+       }
+       else
+       {
+               DoAction_NoJs(action, pDocument);
+       }
+
+       for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+       {
+               CPDF_Action subaction = action.GetSubAction(i);
+               if (!ExecuteLinkAction(subaction, pDocument, list)) return FALSE;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
+                                                                                                CPDFSDK_Document* pDocument, CFX_PtrList& list)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDF_Dictionary* pDict = action.GetDict();
+       if (list.Find(pDict))
+               return FALSE;
+
+       list.AddTail(pDict);
+
+       CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+       ASSERT(pEnv);
+       if (action.GetType() == CPDF_Action::JavaScript)
+       {
+               if(pEnv->IsJSInitiated())
+               {
+                       CFX_WideString swJS = action.GetJavaScript();
+                       if (!swJS.IsEmpty())
+                       {
+                               RunDocumentPageJavaScript(pDocument, type, swJS);
+                       }
+               }
+       }
+       else
+       {
+               DoAction_NoJs(action, pDocument);
+       }
+
+       if (!IsValidDocView(pDocument))
+               return FALSE;
+
+       for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+       {
+               CPDF_Action subaction = action.GetSubAction(i);
+               if (!ExecuteDocumentPageAction(subaction, type, pDocument, list)) return FALSE;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict)
+{
+  ASSERT(pDocument != NULL);
+  ASSERT(pFieldDict != NULL);
+
+  CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
+  ASSERT(pInterForm != NULL);
+
+  CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+  ASSERT(pPDFInterForm != NULL);
+
+  return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
+                                                                                 CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
+                                                                                 PDFSDK_FieldAction& data, CFX_PtrList& list)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDF_Dictionary* pDict = action.GetDict();
+       if (list.Find(pDict))
+               return FALSE;
+
+       list.AddTail(pDict);
+
+       CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+       ASSERT(pEnv);
+       if (action.GetType() == CPDF_Action::JavaScript)
+       {
+               if(pEnv->IsJSInitiated())
+               {
+                       CFX_WideString swJS = action.GetJavaScript();
+                       if (!swJS.IsEmpty())
+                       {
+                               RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
+                               if (!IsValidField(pDocument, pFormField->GetFieldDict()))
+                                       return FALSE;
+                       }
+               }
+       }
+       else
+       {
+               DoAction_NoJs(action, pDocument);
+       }
+
+       for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+       {
+               CPDF_Action subaction = action.GetSubAction(i);
+               if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, list)) return FALSE;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
+                                                                               CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen, CFX_PtrList& list)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDF_Dictionary* pDict = action.GetDict();
+       if (list.Find(pDict))
+               return FALSE;
+
+       list.AddTail(pDict);
+
+       CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+       ASSERT(pEnv);
+       if (action.GetType() == CPDF_Action::JavaScript)
+       {
+               if(pEnv->IsJSInitiated())
+               {
+                       CFX_WideString swJS = action.GetJavaScript();
+                       if (!swJS.IsEmpty())
+                       {
+                               IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+                               ASSERT(pRuntime != NULL);
+
+                               pRuntime->SetReaderDocument(pDocument);
+
+                               IFXJS_Context* pContext = pRuntime->NewContext();
+                               ASSERT(pContext != NULL);
+
+       //                      switch (type)
+       //                      {
+       //                      case CPDF_AAction::CursorEnter:
+       //                              pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::CursorExit:
+       //                              pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::ButtonDown:
+       //                              pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::ButtonUp:
+       //                              pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::GetFocus:
+       //                              pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::LoseFocus:
+       //                              pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::PageOpen:
+       //                              pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::PageClose:
+       //                              pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::PageVisible:
+       //                              pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      case CPDF_AAction::PageInvisible:
+       //                              pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+       //                              break;
+       //                      default:
+       //                              ASSERT(FALSE);
+       //                              break;
+       //                      }
+
+                               CFX_WideString csInfo;
+                               FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
+                               if (!bRet)
+                               {
+                                       //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+                               }
+
+                               pRuntime->ReleaseContext(pContext);
+                       }
+               }
+       }
+       else
+       {
+               DoAction_NoJs(action, pDocument);
+       }
+
+       for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+       {
+               CPDF_Action subaction = action.GetSubAction(i);
+               if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, list)) return FALSE;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument,
+                                                                                CPDF_Bookmark* pBookmark, CFX_PtrList& list)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDF_Dictionary* pDict = action.GetDict();
+       if (list.Find(pDict))
+               return FALSE;
+
+       list.AddTail(pDict);
+
+       CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+       ASSERT(pEnv);
+       if (action.GetType() == CPDF_Action::JavaScript)
+       {
+               if(pEnv->IsJSInitiated())
+               {
+                       CFX_WideString swJS = action.GetJavaScript();
+                       if (!swJS.IsEmpty())
+                       {
+                               IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+                               ASSERT(pRuntime != NULL);
+
+                               pRuntime->SetReaderDocument(pDocument);
+
+                               IFXJS_Context* pContext = pRuntime->NewContext();
+                               ASSERT(pContext != NULL);
+
+                               pContext->OnBookmark_MouseUp(pBookmark);
+
+                               CFX_WideString csInfo;
+                               FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
+                               if (!bRet)
+                               {
+                                       //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+                               }
+
+                               pRuntime->ReleaseContext(pContext);
+                       }
+               }
+       }
+       else
+       {
+               DoAction_NoJs(action, pDocument);
+       }
+
+       for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+       {
+               CPDF_Action subaction = action.GetSubAction(i);
+               if (!ExecuteBookMark(subaction, pDocument, pBookmark, list)) return FALSE;
+       }
+
+       return TRUE;
+}
+
+void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       ASSERT(pDocument != NULL);
+
+       switch (action.GetType())
+       {
+       case CPDF_Action::GoTo:
+               DoAction_GoTo(pDocument, action);
+               break;
+       case CPDF_Action::GoToR:
+               DoAction_GoToR(pDocument, action);
+               break;
+       case CPDF_Action::GoToE:
+               break;
+       case CPDF_Action::Launch:
+               DoAction_Launch(pDocument, action);
+               break;
+       case CPDF_Action::Thread:
+               break;
+       case CPDF_Action::URI:
+               DoAction_URI(pDocument, action);
+               break;
+       case CPDF_Action::Sound:
+               if (m_pMediaActionHandler)
+               {
+                       m_pMediaActionHandler->DoAction_Sound(action, pDocument);
+               }
+               break;
+       case CPDF_Action::Movie:
+               if (m_pMediaActionHandler)
+               {
+                       m_pMediaActionHandler->DoAction_Movie(action, pDocument);
+               }
+               break;
+       case CPDF_Action::Hide:
+               if (m_pFormActionHandler)
+               {
+                       m_pFormActionHandler->DoAction_Hide(action, pDocument);
+               }
+               break;
+       case CPDF_Action::Named:
+               DoAction_Named(pDocument, action);
+               break;
+       case CPDF_Action::SubmitForm:
+               if (m_pFormActionHandler)
+               {
+                       m_pFormActionHandler->DoAction_SubmitForm(action, pDocument);
+               }
+               break;
+       case CPDF_Action::ResetForm:
+               if (m_pFormActionHandler)
+               {
+                       m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
+               }
+               break;
+       case CPDF_Action::ImportData:
+               if (m_pFormActionHandler)
+               {
+                       m_pFormActionHandler->DoAction_ImportData(action, pDocument);
+               }
+               break;
+       case CPDF_Action::JavaScript:
+               ASSERT(FALSE);
+               break;
+       case CPDF_Action::SetOCGState:
+               DoAction_SetOCGState(pDocument,  action);
+               break;
+       case CPDF_Action::Rendition:
+               if (m_pMediaActionHandler)
+               {
+                       m_pMediaActionHandler->DoAction_Rendition(action, pDocument);
+               }
+               break;
+       case CPDF_Action::Trans:
+               break;
+       case CPDF_Action::GoTo3DView:
+               break;
+       default:
+               break;
+       }
+}
+
+FX_BOOL        CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument)
+{
+       ASSERT(pDocument != NULL);
+       return TRUE;
+}
+
+void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument,
+                                                                 const CPDF_Action& action)
+{
+       ASSERT(action);
+
+       CPDF_Document* pPDFDocument = pDocument->GetDocument();
+       ASSERT(pPDFDocument != NULL);
+       CPDFDoc_Environment* pApp = pDocument->GetEnv();
+       ASSERT(pApp != NULL);
+
+       CPDF_Dest MyDest = action.GetDest(pPDFDocument);
+       int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
+       int nFitType = MyDest.GetZoomMode();
+       const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.GetObject();
+       float* pPosAry = NULL;
+       int sizeOfAry = 0;
+       if (pMyArray != NULL)
+       {
+               pPosAry = new float[pMyArray->GetCount()];
+               int j = 0;
+               for (int i = 2; i < (int)pMyArray->GetCount(); i++)
+               {
+                       pPosAry[j++] = pMyArray->GetFloat(i);
+               }
+               sizeOfAry = j;
+       }
+       pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
+       if(pPosAry)
+               delete[] pPosAry;
+}
+
+void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+
+}
+
+void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+
+}
+
+void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+       ASSERT(action);
+
+       CPDFDoc_Environment* pApp = pDocument->GetEnv();
+       ASSERT(pApp != NULL);
+
+       CFX_ByteString sURI = action.GetURI(pDocument->GetDocument());
+       pApp->FFI_DoURIAction(sURI.c_str());
+}
+
+void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+       ASSERT(action);
+
+       CFX_ByteString csName = action.GetNamedAction();
+       pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
+}
+
+
+void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+}
+
+void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type,
+                                                                               PDFSDK_FieldAction& data, const CFX_WideString& script)
+{
+       ASSERT(type != CPDF_AAction::Calculate);
+       ASSERT(type != CPDF_AAction::Format);
+
+       ASSERT(pDocument != NULL);
+
+       IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+       ASSERT(pRuntime != NULL);
+
+       pRuntime->SetReaderDocument(pDocument);
+
+       IFXJS_Context* pContext = pRuntime->NewContext();
+       ASSERT(pContext != NULL);
+
+       switch (type)
+       {
+       case CPDF_AAction::CursorEnter:
+               pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
+               break;
+       case CPDF_AAction::CursorExit:
+               pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
+               break;
+       case CPDF_AAction::ButtonDown:
+               pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
+               break;
+       case CPDF_AAction::ButtonUp:
+               pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
+               break;
+       case CPDF_AAction::GetFocus:
+               pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue);
+               break;
+       case CPDF_AAction::LoseFocus:
+               pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue);
+               break;
+       case CPDF_AAction::KeyStroke:
+               pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
+                       data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue,
+                       data.bWillCommit, data.bFieldFull, data.bRC);
+               break;
+       case CPDF_AAction::Validate:
+               pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier,
+                       data.bShift, pFormField, data.sValue, data.bRC);
+               break;
+       default:
+               ASSERT(FALSE);
+               break;
+       }
+
+       CFX_WideString csInfo;
+       FX_BOOL bRet = pContext->RunScript(script, csInfo);
+       if (!bRet)
+       {
+               //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+       }
+
+       pRuntime->ReleaseContext(pContext);
+}
+
+void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, const CFX_WideString& script)
+{
+       ASSERT(pDocument != NULL);
+
+       IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+       ASSERT(pRuntime != NULL);
+
+       pRuntime->SetReaderDocument(pDocument);
+
+       IFXJS_Context* pContext = pRuntime->NewContext();
+       ASSERT(pContext != NULL);
+
+       pContext->OnDoc_Open(pDocument, sScriptName);
+
+       CFX_WideString csInfo;
+       FX_BOOL bRet = pContext->RunScript(script, csInfo);
+       if (!bRet)
+       {
+               //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+       }
+
+       pRuntime->ReleaseContext(pContext);
+}
+
+void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script)
+{
+       ASSERT(pDocument != NULL);
+
+       IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+       ASSERT(pRuntime != NULL);
+
+       pRuntime->SetReaderDocument(pDocument);
+
+       IFXJS_Context* pContext = pRuntime->NewContext();
+       ASSERT(pContext != NULL);
+
+       switch (type)
+       {
+       case CPDF_AAction::OpenPage:
+               pContext->OnPage_Open(pDocument);
+               break;
+       case CPDF_AAction::ClosePage:
+               pContext->OnPage_Close(pDocument);
+               break;
+       case CPDF_AAction::CloseDocument:
+               pContext->OnDoc_WillClose(pDocument);
+               break;
+       case CPDF_AAction::SaveDocument:
+               pContext->OnDoc_WillSave(pDocument);
+               break;
+       case CPDF_AAction::DocumentSaved:
+               pContext->OnDoc_DidSave(pDocument);
+               break;
+       case CPDF_AAction::PrintDocument:
+               pContext->OnDoc_WillPrint(pDocument);
+               break;
+       case CPDF_AAction::DocumentPrinted:
+               pContext->OnDoc_DidPrint(pDocument);
+               break;
+       case CPDF_AAction::PageVisible:
+               pContext->OnPage_InView(pDocument);
+               break;
+       case CPDF_AAction::PageInvisible:
+               pContext->OnPage_OutView(pDocument);
+               break;
+       default:
+               ASSERT(FALSE);
+               break;
+       }
+
+       CFX_WideString csInfo;
+       FX_BOOL bRet = pContext->RunScript(script, csInfo);
+       if (!bRet)
+       {
+               //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+       }
+
+       pRuntime->ReleaseContext(pContext);
+}
+
+
+FX_BOOL        CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+       ASSERT(pInterForm != NULL);
+
+       if (pInterForm->DoAction_Hide(action))
+       {
+               pDocument->SetChangeMark();
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL        CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+       ASSERT(pInterForm != NULL);
+
+       return pInterForm->DoAction_SubmitForm(action);
+}
+
+FX_BOOL        CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+       ASSERT(pInterForm != NULL);
+
+       if (pInterForm->DoAction_ResetForm(action))
+       {
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL        CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       ASSERT(pDocument != NULL);
+
+       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+       ASSERT(pInterForm != NULL);
+
+       if (pInterForm->DoAction_ImportData(action))
+       {
+               pDocument->SetChangeMark();
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL        CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       return FALSE;
+}
+
+FX_BOOL        CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       return FALSE;
+}
+
+FX_BOOL        CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+       return FALSE;
+}