OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/include/cpdfsdk_interform.h" | 7 #include "fpdfsdk/include/cpdfsdk_interform.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
16 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
17 #include "core/fpdfdoc/include/cpdf_actionfields.h" | 17 #include "core/fpdfdoc/include/cpdf_actionfields.h" |
18 #include "core/fpdfdoc/include/cpdf_interform.h" | 18 #include "core/fpdfdoc/include/cpdf_interform.h" |
19 #include "core/fxge/include/cfx_graphstatedata.h" | 19 #include "core/fxge/include/cfx_graphstatedata.h" |
20 #include "core/fxge/include/cfx_pathdata.h" | 20 #include "core/fxge/include/cfx_pathdata.h" |
21 #include "core/fxge/include/cfx_renderdevice.h" | 21 #include "core/fxge/include/cfx_renderdevice.h" |
22 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 22 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
23 #include "fpdfsdk/fxedit/include/fxet_edit.h" | 23 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
24 #include "fpdfsdk/include/cba_annotiterator.h" | 24 #include "fpdfsdk/include/cba_annotiterator.h" |
25 #include "fpdfsdk/include/cpdfdoc_environment.h" | |
26 #include "fpdfsdk/include/cpdfsdk_annot.h" | 25 #include "fpdfsdk/include/cpdfsdk_annot.h" |
27 #include "fpdfsdk/include/cpdfsdk_document.h" | 26 #include "fpdfsdk/include/cpdfsdk_document.h" |
| 27 #include "fpdfsdk/include/cpdfsdk_environment.h" |
28 #include "fpdfsdk/include/cpdfsdk_pageview.h" | 28 #include "fpdfsdk/include/cpdfsdk_pageview.h" |
29 #include "fpdfsdk/include/cpdfsdk_widget.h" | 29 #include "fpdfsdk/include/cpdfsdk_widget.h" |
30 #include "fpdfsdk/include/fsdk_actionhandler.h" | 30 #include "fpdfsdk/include/fsdk_actionhandler.h" |
31 #include "fpdfsdk/include/fsdk_define.h" | 31 #include "fpdfsdk/include/fsdk_define.h" |
32 #include "fpdfsdk/include/ipdfsdk_annothandler.h" | 32 #include "fpdfsdk/include/ipdfsdk_annothandler.h" |
33 #include "fpdfsdk/javascript/ijs_context.h" | 33 #include "fpdfsdk/javascript/ijs_context.h" |
34 #include "fpdfsdk/javascript/ijs_runtime.h" | 34 #include "fpdfsdk/javascript/ijs_runtime.h" |
35 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 35 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
36 #include "third_party/base/stl_util.h" | 36 #include "third_party/base/stl_util.h" |
37 | 37 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 FX_BOOL bSynchronizeElse) { | 213 FX_BOOL bSynchronizeElse) { |
214 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 214 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
215 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); | 215 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
216 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) | 216 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) |
217 pWidget->Synchronize(bSynchronizeElse); | 217 pWidget->Synchronize(bSynchronizeElse); |
218 } | 218 } |
219 } | 219 } |
220 #endif // PDF_ENABLE_XFA | 220 #endif // PDF_ENABLE_XFA |
221 | 221 |
222 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { | 222 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { |
223 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 223 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
224 ASSERT(pEnv); | 224 ASSERT(pEnv); |
225 if (!pEnv->IsJSInitiated()) | 225 if (!pEnv->IsJSInitiated()) |
226 return; | 226 return; |
227 | 227 |
228 if (m_bBusy) | 228 if (m_bBusy) |
229 return; | 229 return; |
230 | 230 |
231 m_bBusy = TRUE; | 231 m_bBusy = TRUE; |
232 | 232 |
233 if (!IsCalculateEnabled()) { | 233 if (!IsCalculateEnabled()) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (bRet && bRC && sValue.Compare(sOldValue) != 0) | 273 if (bRet && bRC && sValue.Compare(sOldValue) != 0) |
274 pField->SetValue(sValue, TRUE); | 274 pField->SetValue(sValue, TRUE); |
275 } | 275 } |
276 | 276 |
277 m_bBusy = FALSE; | 277 m_bBusy = FALSE; |
278 } | 278 } |
279 | 279 |
280 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, | 280 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, |
281 FX_BOOL& bFormatted) { | 281 FX_BOOL& bFormatted) { |
282 CFX_WideString sValue = pFormField->GetValue(); | 282 CFX_WideString sValue = pFormField->GetValue(); |
283 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 283 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
284 ASSERT(pEnv); | 284 ASSERT(pEnv); |
285 if (!pEnv->IsJSInitiated()) { | 285 if (!pEnv->IsJSInitiated()) { |
286 bFormatted = FALSE; | 286 bFormatted = FALSE; |
287 return sValue; | 287 return sValue; |
288 } | 288 } |
289 | 289 |
290 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); | 290 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
291 pRuntime->SetReaderDocument(m_pDocument); | 291 pRuntime->SetReaderDocument(m_pDocument); |
292 | 292 |
293 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX && | 293 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX && |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 pWidget->ResetAppearance(sValue, bValueChanged); | 334 pWidget->ResetAppearance(sValue, bValueChanged); |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { | 338 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { |
339 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 339 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
340 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); | 340 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
341 ASSERT(pFormCtrl); | 341 ASSERT(pFormCtrl); |
342 | 342 |
343 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { | 343 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { |
344 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 344 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
345 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); | 345 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); |
346 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 346 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
347 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); | 347 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); |
348 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); | 348 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); |
349 | 349 |
350 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, | 350 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
351 rcBBox.bottom); | 351 rcBBox.bottom); |
352 } | 352 } |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, | 356 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
357 const CFX_WideString& csValue) { | 357 const CFX_WideString& csValue) { |
358 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 358 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
359 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) | 359 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) |
360 return TRUE; | 360 return TRUE; |
361 | 361 |
362 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); | 362 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); |
363 if (!action.GetDict()) | 363 if (!action.GetDict()) |
364 return TRUE; | 364 return TRUE; |
365 | 365 |
366 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 366 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
367 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 367 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
368 PDFSDK_FieldAction fa; | 368 PDFSDK_FieldAction fa; |
369 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); | 369 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
370 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); | 370 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
371 fa.sValue = csValue; | 371 fa.sValue = csValue; |
372 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, | 372 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, |
373 m_pDocument, pFormField, fa); | 373 m_pDocument, pFormField, fa); |
374 return fa.bRC; | 374 return fa.bRC; |
375 } | 375 } |
376 | 376 |
377 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, | 377 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, |
378 const CFX_WideString& csValue) { | 378 const CFX_WideString& csValue) { |
379 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 379 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
380 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) | 380 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) |
381 return TRUE; | 381 return TRUE; |
382 | 382 |
383 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); | 383 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); |
384 if (!action.GetDict()) | 384 if (!action.GetDict()) |
385 return TRUE; | 385 return TRUE; |
386 | 386 |
387 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 387 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
388 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 388 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
389 PDFSDK_FieldAction fa; | 389 PDFSDK_FieldAction fa; |
390 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); | 390 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
391 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); | 391 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
392 fa.sValue = csValue; | 392 fa.sValue = csValue; |
393 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, | 393 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, |
394 m_pDocument, pFormField, fa); | 394 m_pDocument, pFormField, fa); |
395 return fa.bRC; | 395 return fa.bRC; |
396 } | 396 } |
397 | 397 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 return FALSE; | 451 return FALSE; |
452 | 452 |
453 return SubmitForm(sDestination, FALSE); | 453 return SubmitForm(sDestination, FALSE); |
454 } | 454 } |
455 | 455 |
456 FX_BOOL CPDFSDK_InterForm::SubmitFields( | 456 FX_BOOL CPDFSDK_InterForm::SubmitFields( |
457 const CFX_WideString& csDestination, | 457 const CFX_WideString& csDestination, |
458 const std::vector<CPDF_FormField*>& fields, | 458 const std::vector<CPDF_FormField*>& fields, |
459 bool bIncludeOrExclude, | 459 bool bIncludeOrExclude, |
460 bool bUrlEncoded) { | 460 bool bUrlEncoded) { |
461 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 461 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
462 | 462 |
463 CFX_ByteTextBuf textBuf; | 463 CFX_ByteTextBuf textBuf; |
464 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); | 464 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); |
465 | 465 |
466 uint8_t* pBuffer = textBuf.GetBuffer(); | 466 uint8_t* pBuffer = textBuf.GetBuffer(); |
467 FX_STRSIZE nBufSize = textBuf.GetLength(); | 467 FX_STRSIZE nBufSize = textBuf.GetLength(); |
468 | 468 |
469 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) | 469 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) |
470 return FALSE; | 470 return FALSE; |
471 | 471 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 } | 534 } |
535 | 535 |
536 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, | 536 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
537 FX_BOOL bUrlEncoded) { | 537 FX_BOOL bUrlEncoded) { |
538 if (sDestination.IsEmpty()) | 538 if (sDestination.IsEmpty()) |
539 return FALSE; | 539 return FALSE; |
540 | 540 |
541 if (!m_pDocument || !m_pInterForm) | 541 if (!m_pDocument || !m_pInterForm) |
542 return FALSE; | 542 return FALSE; |
543 | 543 |
544 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 544 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); |
545 CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); | 545 CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); |
546 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC()); | 546 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC()); |
547 if (!pFDFDoc) | 547 if (!pFDFDoc) |
548 return FALSE; | 548 return FALSE; |
549 | 549 |
550 CFX_ByteTextBuf FdfBuffer; | 550 CFX_ByteTextBuf FdfBuffer; |
551 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); | 551 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); |
552 delete pFDFDoc; | 552 delete pFDFDoc; |
553 if (!bRet) | 553 if (!bRet) |
554 return FALSE; | 554 return FALSE; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 } | 719 } |
720 } | 720 } |
721 | 721 |
722 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { | 722 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
723 if (nFieldType < 0 || nFieldType > kNumFieldTypes) | 723 if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
724 return FXSYS_RGB(255, 255, 255); | 724 return FXSYS_RGB(255, 255, 255); |
725 if (nFieldType == 0) | 725 if (nFieldType == 0) |
726 return m_aHighlightColor[0]; | 726 return m_aHighlightColor[0]; |
727 return m_aHighlightColor[nFieldType - 1]; | 727 return m_aHighlightColor[nFieldType - 1]; |
728 } | 728 } |
OLD | NEW |