John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "../include/fsdk_define.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 8 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | #include "../include/fsdk_mgr.h" |
| 10 | #include "../include/fsdk_actionhandler.h" |
| 11 | #include "../include/javascript/IJavaScript.h" |
| 12 | |
| 13 | /* -------------------------- CBA_ActionHandler -------------------------- */ |
| 14 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 15 | CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) : |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 16 | m_pFormActionHandler(NULL), |
| 17 | m_pMediaActionHandler(NULL) |
| 18 | { |
| 19 | m_pFormActionHandler = new CPDFSDK_FormActionHandler; |
| 20 | } |
| 21 | |
| 22 | CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler() |
| 23 | { |
| 24 | if(m_pFormActionHandler) |
| 25 | { |
| 26 | delete m_pFormActionHandler; |
| 27 | m_pFormActionHandler = NULL; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | void CPDFSDK_ActionHandler::SetFormActionHandler(CPDFSDK_FormActionHandler* pHandler) |
| 32 | { |
| 33 | ASSERT(pHandler != NULL); |
| 34 | ASSERT(m_pFormActionHandler == NULL); |
| 35 | m_pFormActionHandler = pHandler; |
| 36 | } |
| 37 | |
| 38 | void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler) |
| 39 | { |
| 40 | ASSERT(pHandler != NULL); |
| 41 | ASSERT(m_pMediaActionHandler == NULL); |
| 42 | m_pMediaActionHandler = pHandler; |
| 43 | } |
| 44 | |
| 45 | void CPDFSDK_ActionHandler::Destroy() |
| 46 | { |
| 47 | delete this; |
| 48 | } |
| 49 | |
| 50 | //document open |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 51 | FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | { |
| 53 | CFX_PtrList list; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 54 | return ExecuteDocumentOpenAction(action, pDocument, list); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | //document open |
| 58 | FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName, |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 59 | CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 74 | FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type, |
| 75 | CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | |
| 92 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType, |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 93 | CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 94 | { |
| 95 | CFX_PtrList list; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 96 | return ExecuteDocumentPageAction(action, eType, pDocument, list); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType, |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 100 | CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | { |
| 102 | CFX_PtrList list; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 103 | return ExecuteDocumentPageAction(action, eType, pDocument, list); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 106 | FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type, |
| 107 | CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 108 | { |
| 109 | CFX_PtrList list; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 110 | return this->ExecuteBookMark(action, pDocument, pBookMark, list); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 113 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type, |
| 114 | CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 115 | { |
| 116 | CFX_PtrList list; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 117 | return this->ExecuteScreenAction(action, type, pDocument, pScreen, list); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 120 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action, |
| 121 | CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 122 | { |
| 123 | CFX_PtrList list; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 124 | return ExecuteLinkAction(action, pDocument, list); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 127 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type, |
| 128 | CPDFSDK_Document* pDocument, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | CPDF_FormField* pFormField, PDFSDK_FieldAction& data) |
| 130 | { |
| 131 | CFX_PtrList list; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 132 | return ExecuteFieldAction(action, type, pDocument, pFormField, data, list); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument, |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 136 | CFX_PtrList& list) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 138 | CPDF_Dictionary* pDict = action.GetDict(); |
| 139 | if (list.Find(pDict)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 140 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 141 | |
| 142 | list.AddTail(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 159 | DoAction_NoJs(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 162 | for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 163 | { |
| 164 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 165 | if (!ExecuteDocumentOpenAction(subaction, pDocument, list)) return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | return TRUE; |
| 169 | } |
| 170 | |
| 171 | FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action, CPDFSDK_Document* pDocument, |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 172 | CFX_PtrList& list) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 173 | { |
| 174 | ASSERT(pDocument != NULL); |
| 175 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 176 | CPDF_Dictionary* pDict = action.GetDict(); |
| 177 | if (list.Find(pDict)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 178 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 179 | |
| 180 | list.AddTail(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 181 | |
| 182 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 183 | ASSERT(pEnv); |
| 184 | if (action.GetType() == CPDF_Action::JavaScript) |
| 185 | { |
| 186 | if(pEnv->IsJSInitiated()) |
| 187 | { |
| 188 | CFX_WideString swJS = action.GetJavaScript(); |
| 189 | if (!swJS.IsEmpty()) |
| 190 | { |
| 191 | IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //???? |
| 192 | ASSERT(pRuntime != NULL); |
| 193 | |
| 194 | pRuntime->SetReaderDocument(pDocument); |
| 195 | |
| 196 | IFXJS_Context* pContext = pRuntime->NewContext(); |
| 197 | ASSERT(pContext != NULL); |
| 198 | |
| 199 | pContext->OnLink_MouseUp(pDocument); |
| 200 | |
| 201 | CFX_WideString csInfo; |
| 202 | FX_BOOL bRet = pContext->RunScript(swJS, csInfo); |
| 203 | if (!bRet) |
| 204 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 205 | // FIXME: return error. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | pRuntime->ReleaseContext(pContext); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | else |
| 213 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 214 | DoAction_NoJs(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 217 | for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 218 | { |
| 219 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 220 | if (!ExecuteLinkAction(subaction, pDocument, list)) return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | return TRUE; |
| 224 | } |
| 225 | |
| 226 | FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& action, CPDF_AAction::AActionType type, |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 227 | CPDFSDK_Document* pDocument, CFX_PtrList& list) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 228 | { |
| 229 | ASSERT(pDocument != NULL); |
| 230 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 231 | CPDF_Dictionary* pDict = action.GetDict(); |
| 232 | if (list.Find(pDict)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 234 | |
| 235 | list.AddTail(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 236 | |
| 237 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 238 | ASSERT(pEnv); |
| 239 | if (action.GetType() == CPDF_Action::JavaScript) |
| 240 | { |
| 241 | if(pEnv->IsJSInitiated()) |
| 242 | { |
| 243 | CFX_WideString swJS = action.GetJavaScript(); |
| 244 | if (!swJS.IsEmpty()) |
| 245 | { |
| 246 | RunDocumentPageJavaScript(pDocument, type, swJS); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | else |
| 251 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 252 | DoAction_NoJs(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 255 | if (!IsValidDocView(pDocument)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 256 | return FALSE; |
| 257 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 258 | for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 259 | { |
| 260 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 261 | if (!ExecuteDocumentPageAction(subaction, type, pDocument, list)) return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | return TRUE; |
| 265 | } |
| 266 | |
| 267 | FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict) |
| 268 | { |
Chris Palmer | 9047b8b | 2014-08-06 14:17:45 -0700 | [diff] [blame] | 269 | ASSERT(pDocument != NULL); |
| 270 | ASSERT(pFieldDict != NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 271 | |
Chris Palmer | 9047b8b | 2014-08-06 14:17:45 -0700 | [diff] [blame] | 272 | CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
| 273 | ASSERT(pInterForm != NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 274 | |
Chris Palmer | 9047b8b | 2014-08-06 14:17:45 -0700 | [diff] [blame] | 275 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 276 | ASSERT(pPDFInterForm != NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 277 | |
Chris Palmer | 9047b8b | 2014-08-06 14:17:45 -0700 | [diff] [blame] | 278 | return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 281 | FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type, |
| 282 | CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 283 | PDFSDK_FieldAction& data, CFX_PtrList& list) |
| 284 | { |
| 285 | ASSERT(pDocument != NULL); |
| 286 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 287 | CPDF_Dictionary* pDict = action.GetDict(); |
| 288 | if (list.Find(pDict)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 289 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 290 | |
| 291 | list.AddTail(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 310 | DoAction_NoJs(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 313 | for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 314 | { |
| 315 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 316 | if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, list)) return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | return TRUE; |
| 320 | } |
| 321 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 322 | FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type, |
| 323 | CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen, CFX_PtrList& list) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 324 | { |
| 325 | ASSERT(pDocument != NULL); |
| 326 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 327 | CPDF_Dictionary* pDict = action.GetDict(); |
| 328 | if (list.Find(pDict)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 329 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 330 | |
| 331 | list.AddTail(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 400 | DoAction_NoJs(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 403 | for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 404 | { |
| 405 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 406 | if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, list)) return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | return TRUE; |
| 410 | } |
| 411 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 412 | FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument, |
| 413 | CPDF_Bookmark* pBookmark, CFX_PtrList& list) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 414 | { |
| 415 | ASSERT(pDocument != NULL); |
| 416 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 417 | CPDF_Dictionary* pDict = action.GetDict(); |
| 418 | if (list.Find(pDict)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 419 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 420 | |
| 421 | list.AddTail(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 422 | |
| 423 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 424 | ASSERT(pEnv); |
| 425 | if (action.GetType() == CPDF_Action::JavaScript) |
| 426 | { |
| 427 | if(pEnv->IsJSInitiated()) |
| 428 | { |
| 429 | CFX_WideString swJS = action.GetJavaScript(); |
| 430 | if (!swJS.IsEmpty()) |
| 431 | { |
| 432 | IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
| 433 | ASSERT(pRuntime != NULL); |
| 434 | |
| 435 | pRuntime->SetReaderDocument(pDocument); |
| 436 | |
| 437 | IFXJS_Context* pContext = pRuntime->NewContext(); |
| 438 | ASSERT(pContext != NULL); |
| 439 | |
| 440 | pContext->OnBookmark_MouseUp(pBookmark); |
| 441 | |
| 442 | CFX_WideString csInfo; |
| 443 | FX_BOOL bRet = pContext->RunScript(swJS, csInfo); |
| 444 | if (!bRet) |
| 445 | { |
| 446 | //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); |
| 447 | } |
| 448 | |
| 449 | pRuntime->ReleaseContext(pContext); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | else |
| 454 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 455 | DoAction_NoJs(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 458 | for (int32_t i=0,sz=action.GetSubActionsCount(); i<sz; i++) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 459 | { |
| 460 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 461 | if (!ExecuteBookMark(subaction, pDocument, pBookmark, list)) return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | return TRUE; |
| 465 | } |
| 466 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 467 | void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 468 | { |
| 469 | ASSERT(pDocument != NULL); |
| 470 | |
| 471 | switch (action.GetType()) |
| 472 | { |
| 473 | case CPDF_Action::GoTo: |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 474 | DoAction_GoTo(pDocument, action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 475 | break; |
| 476 | case CPDF_Action::GoToR: |
| 477 | DoAction_GoToR(pDocument, action); |
| 478 | break; |
| 479 | case CPDF_Action::GoToE: |
| 480 | break; |
| 481 | case CPDF_Action::Launch: |
| 482 | DoAction_Launch(pDocument, action); |
| 483 | break; |
| 484 | case CPDF_Action::Thread: |
| 485 | break; |
| 486 | case CPDF_Action::URI: |
| 487 | DoAction_URI(pDocument, action); |
| 488 | break; |
| 489 | case CPDF_Action::Sound: |
| 490 | if (m_pMediaActionHandler) |
| 491 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 492 | m_pMediaActionHandler->DoAction_Sound(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 493 | } |
| 494 | break; |
| 495 | case CPDF_Action::Movie: |
| 496 | if (m_pMediaActionHandler) |
| 497 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 498 | m_pMediaActionHandler->DoAction_Movie(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 499 | } |
| 500 | break; |
| 501 | case CPDF_Action::Hide: |
| 502 | if (m_pFormActionHandler) |
| 503 | { |
| 504 | m_pFormActionHandler->DoAction_Hide(action, pDocument); |
| 505 | } |
| 506 | break; |
| 507 | case CPDF_Action::Named: |
| 508 | DoAction_Named(pDocument, action); |
| 509 | break; |
| 510 | case CPDF_Action::SubmitForm: |
| 511 | if (m_pFormActionHandler) |
| 512 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 513 | m_pFormActionHandler->DoAction_SubmitForm(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 514 | } |
| 515 | break; |
| 516 | case CPDF_Action::ResetForm: |
| 517 | if (m_pFormActionHandler) |
| 518 | { |
| 519 | m_pFormActionHandler->DoAction_ResetForm(action, pDocument); |
| 520 | } |
| 521 | break; |
| 522 | case CPDF_Action::ImportData: |
| 523 | if (m_pFormActionHandler) |
| 524 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 525 | m_pFormActionHandler->DoAction_ImportData(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 526 | } |
| 527 | break; |
| 528 | case CPDF_Action::JavaScript: |
| 529 | ASSERT(FALSE); |
| 530 | break; |
| 531 | case CPDF_Action::SetOCGState: |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 532 | DoAction_SetOCGState(pDocument, action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 533 | break; |
| 534 | case CPDF_Action::Rendition: |
| 535 | if (m_pMediaActionHandler) |
| 536 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 537 | m_pMediaActionHandler->DoAction_Rendition(action, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 538 | } |
| 539 | break; |
| 540 | case CPDF_Action::Trans: |
| 541 | break; |
| 542 | case CPDF_Action::GoTo3DView: |
| 543 | break; |
| 544 | default: |
| 545 | break; |
| 546 | } |
| 547 | } |
| 548 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 549 | FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 550 | { |
| 551 | ASSERT(pDocument != NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 552 | return TRUE; |
| 553 | } |
| 554 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 555 | void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 556 | const CPDF_Action& action) |
| 557 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 558 | ASSERT(action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 559 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 560 | CPDF_Document* pPDFDocument = pDocument->GetDocument()->GetPDFDoc(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 561 | ASSERT(pPDFDocument != NULL); |
| 562 | CPDFDoc_Environment* pApp = pDocument->GetEnv(); |
| 563 | ASSERT(pApp != NULL); |
| 564 | |
| 565 | CPDF_Dest MyDest = action.GetDest(pPDFDocument); |
| 566 | int nPageIndex = MyDest.GetPageIndex(pPDFDocument); |
| 567 | int nFitType = MyDest.GetZoomMode(); |
Tom Sepez | ac8d1e7 | 2015-03-06 10:52:05 -0800 | [diff] [blame] | 568 | const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 569 | float* pPosAry = NULL; |
| 570 | int sizeOfAry = 0; |
| 571 | if (pMyArray != NULL) |
| 572 | { |
| 573 | pPosAry = new float[pMyArray->GetCount()]; |
| 574 | int j = 0; |
| 575 | for (int i = 2; i < (int)pMyArray->GetCount(); i++) |
| 576 | { |
| 577 | pPosAry[j++] = pMyArray->GetFloat(i); |
| 578 | } |
| 579 | sizeOfAry = j; |
| 580 | } |
| 581 | pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry); |
| 582 | if(pPosAry) |
| 583 | delete[] pPosAry; |
| 584 | } |
| 585 | |
| 586 | void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action) |
| 587 | { |
| 588 | |
| 589 | } |
| 590 | |
| 591 | void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action) |
| 592 | { |
| 593 | |
| 594 | } |
| 595 | |
| 596 | void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action) |
| 597 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 598 | ASSERT(action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 599 | |
| 600 | CPDFDoc_Environment* pApp = pDocument->GetEnv(); |
| 601 | ASSERT(pApp != NULL); |
Tom Sepez | d7e5cc7 | 2015-06-10 14:33:37 -0700 | [diff] [blame] | 602 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 603 | CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc()); |
Tom Sepez | d7e5cc7 | 2015-06-10 14:33:37 -0700 | [diff] [blame] | 604 | pApp->FFI_DoURIAction(sURI.c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action) |
| 608 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 609 | ASSERT(action); |
| 610 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 611 | CFX_ByteString csName = action.GetNamedAction(); |
| 612 | pDocument->GetEnv()->FFI_ExecuteNamedAction(csName); |
| 613 | } |
| 614 | |
| 615 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 616 | void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, const CPDF_Action& action) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 617 | { |
| 618 | } |
| 619 | |
| 620 | void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type, |
| 621 | PDFSDK_FieldAction& data, const CFX_WideString& script) |
| 622 | { |
| 623 | ASSERT(type != CPDF_AAction::Calculate); |
| 624 | ASSERT(type != CPDF_AAction::Format); |
| 625 | |
| 626 | ASSERT(pDocument != NULL); |
| 627 | |
| 628 | IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
| 629 | ASSERT(pRuntime != NULL); |
| 630 | |
| 631 | pRuntime->SetReaderDocument(pDocument); |
| 632 | |
| 633 | IFXJS_Context* pContext = pRuntime->NewContext(); |
| 634 | ASSERT(pContext != NULL); |
| 635 | |
| 636 | switch (type) |
| 637 | { |
| 638 | case CPDF_AAction::CursorEnter: |
| 639 | pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField); |
| 640 | break; |
| 641 | case CPDF_AAction::CursorExit: |
| 642 | pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField); |
| 643 | break; |
| 644 | case CPDF_AAction::ButtonDown: |
| 645 | pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField); |
| 646 | break; |
| 647 | case CPDF_AAction::ButtonUp: |
| 648 | pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField); |
| 649 | break; |
| 650 | case CPDF_AAction::GetFocus: |
| 651 | pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue); |
| 652 | break; |
| 653 | case CPDF_AAction::LoseFocus: |
| 654 | pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue); |
| 655 | break; |
| 656 | case CPDF_AAction::KeyStroke: |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 657 | pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 658 | data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue, |
| 659 | data.bWillCommit, data.bFieldFull, data.bRC); |
| 660 | break; |
| 661 | case CPDF_AAction::Validate: |
| 662 | pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier, |
| 663 | data.bShift, pFormField, data.sValue, data.bRC); |
| 664 | break; |
| 665 | default: |
| 666 | ASSERT(FALSE); |
| 667 | break; |
| 668 | } |
| 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::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, 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 | pContext->OnDoc_Open(pDocument, sScriptName); |
| 693 | |
| 694 | CFX_WideString csInfo; |
| 695 | FX_BOOL bRet = pContext->RunScript(script, csInfo); |
| 696 | if (!bRet) |
| 697 | { |
| 698 | //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); |
| 699 | } |
| 700 | |
| 701 | pRuntime->ReleaseContext(pContext); |
| 702 | } |
| 703 | |
| 704 | void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script) |
| 705 | { |
| 706 | ASSERT(pDocument != NULL); |
| 707 | |
| 708 | IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
| 709 | ASSERT(pRuntime != NULL); |
| 710 | |
| 711 | pRuntime->SetReaderDocument(pDocument); |
| 712 | |
| 713 | IFXJS_Context* pContext = pRuntime->NewContext(); |
| 714 | ASSERT(pContext != NULL); |
| 715 | |
| 716 | switch (type) |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 717 | { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 718 | case CPDF_AAction::OpenPage: |
| 719 | pContext->OnPage_Open(pDocument); |
| 720 | break; |
| 721 | case CPDF_AAction::ClosePage: |
| 722 | pContext->OnPage_Close(pDocument); |
| 723 | break; |
| 724 | case CPDF_AAction::CloseDocument: |
| 725 | pContext->OnDoc_WillClose(pDocument); |
| 726 | break; |
| 727 | case CPDF_AAction::SaveDocument: |
| 728 | pContext->OnDoc_WillSave(pDocument); |
| 729 | break; |
| 730 | case CPDF_AAction::DocumentSaved: |
| 731 | pContext->OnDoc_DidSave(pDocument); |
| 732 | break; |
| 733 | case CPDF_AAction::PrintDocument: |
| 734 | pContext->OnDoc_WillPrint(pDocument); |
| 735 | break; |
| 736 | case CPDF_AAction::DocumentPrinted: |
| 737 | pContext->OnDoc_DidPrint(pDocument); |
| 738 | break; |
| 739 | case CPDF_AAction::PageVisible: |
| 740 | pContext->OnPage_InView(pDocument); |
| 741 | break; |
| 742 | case CPDF_AAction::PageInvisible: |
| 743 | pContext->OnPage_OutView(pDocument); |
| 744 | break; |
| 745 | default: |
| 746 | ASSERT(FALSE); |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | CFX_WideString csInfo; |
| 751 | FX_BOOL bRet = pContext->RunScript(script, csInfo); |
| 752 | if (!bRet) |
| 753 | { |
| 754 | //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); |
| 755 | } |
| 756 | |
| 757 | pRuntime->ReleaseContext(pContext); |
| 758 | } |
| 759 | |
| 760 | |
| 761 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
| 762 | { |
| 763 | ASSERT(pDocument != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 764 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 765 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
| 766 | ASSERT(pInterForm != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 767 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 768 | if (pInterForm->DoAction_Hide(action)) |
| 769 | { |
| 770 | pDocument->SetChangeMark(); |
| 771 | return TRUE; |
| 772 | } |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 773 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 774 | return FALSE; |
| 775 | } |
| 776 | |
| 777 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
| 778 | { |
| 779 | ASSERT(pDocument != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 780 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 781 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
| 782 | ASSERT(pInterForm != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 783 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 784 | return pInterForm->DoAction_SubmitForm(action); |
| 785 | } |
| 786 | |
| 787 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
| 788 | { |
| 789 | ASSERT(pDocument != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 790 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 791 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
| 792 | ASSERT(pInterForm != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 793 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 794 | if (pInterForm->DoAction_ResetForm(action)) |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 795 | { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 796 | return TRUE; |
| 797 | } |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 798 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 799 | return FALSE; |
| 800 | } |
| 801 | |
| 802 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
| 803 | { |
| 804 | ASSERT(pDocument != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 805 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 806 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
| 807 | ASSERT(pInterForm != NULL); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 808 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 809 | if (pInterForm->DoAction_ImportData(action)) |
| 810 | { |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 811 | pDocument->SetChangeMark(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 812 | return TRUE; |
| 813 | } |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 814 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 815 | return FALSE; |
| 816 | } |
| 817 | |
| 818 | FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
| 819 | { |
| 820 | return FALSE; |
| 821 | } |
| 822 | |
| 823 | FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
| 824 | { |
| 825 | return FALSE; |
| 826 | } |
| 827 | |
| 828 | FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument) |
| 829 | { |
| 830 | return FALSE; |
| 831 | } |