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