| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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/javascript/Document.h" | 7 #include "fpdfsdk/javascript/Document.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 372 |
| 373 int iLength = params.size(); | 373 int iLength = params.size(); |
| 374 | 374 |
| 375 FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; | 375 FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; |
| 376 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; | 376 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; |
| 377 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; | 377 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; |
| 378 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; | 378 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; |
| 379 CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; | 379 CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; |
| 380 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; | 380 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; |
| 381 | 381 |
| 382 CPDFSDK_InterForm* pInterForm = | 382 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 383 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
| 384 CFX_ByteTextBuf textBuf; | 383 CFX_ByteTextBuf textBuf; |
| 385 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) | 384 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 386 return FALSE; | 385 return FALSE; |
| 387 | 386 |
| 388 CJS_Context* pContext = (CJS_Context*)cc; | 387 CJS_Context* pContext = (CJS_Context*)cc; |
| 389 CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); | 388 CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); |
| 390 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 389 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 391 | 390 |
| 392 pRuntime->BeginBlock(); | 391 pRuntime->BeginBlock(); |
| 393 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, | 392 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) | 470 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) |
| 472 return FALSE; | 471 return FALSE; |
| 473 | 472 |
| 474 CJS_Context* pContext = (CJS_Context*)cc; | 473 CJS_Context* pContext = (CJS_Context*)cc; |
| 475 if (params.size() != 1) { | 474 if (params.size() != 1) { |
| 476 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 475 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 477 return FALSE; | 476 return FALSE; |
| 478 } | 477 } |
| 479 | 478 |
| 480 CFX_WideString sFieldName = params[0].ToCFXWideString(); | 479 CFX_WideString sFieldName = params[0].ToCFXWideString(); |
| 481 CPDFSDK_InterForm* pInterForm = | 480 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 482 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
| 483 | |
| 484 std::vector<CPDFSDK_Widget*> widgets; | 481 std::vector<CPDFSDK_Widget*> widgets; |
| 485 pInterForm->GetWidgets(sFieldName, &widgets); | 482 pInterForm->GetWidgets(sFieldName, &widgets); |
| 486 | |
| 487 if (widgets.empty()) | 483 if (widgets.empty()) |
| 488 return TRUE; | 484 return TRUE; |
| 489 | 485 |
| 490 for (CPDFSDK_Widget* pWidget : widgets) { | 486 for (CPDFSDK_Widget* pWidget : widgets) { |
| 491 CFX_FloatRect rcAnnot = pWidget->GetRect(); | 487 CFX_FloatRect rcAnnot = pWidget->GetRect(); |
| 492 --rcAnnot.left; | 488 --rcAnnot.left; |
| 493 --rcAnnot.bottom; | 489 --rcAnnot.bottom; |
| 494 ++rcAnnot.right; | 490 ++rcAnnot.right; |
| 495 ++rcAnnot.top; | 491 ++rcAnnot.top; |
| 496 | 492 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 513 | 509 |
| 514 FX_BOOL Document::resetForm(IJS_Context* cc, | 510 FX_BOOL Document::resetForm(IJS_Context* cc, |
| 515 const std::vector<CJS_Value>& params, | 511 const std::vector<CJS_Value>& params, |
| 516 CJS_Value& vRet, | 512 CJS_Value& vRet, |
| 517 CFX_WideString& sError) { | 513 CFX_WideString& sError) { |
| 518 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 514 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 519 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | 515 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 520 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) | 516 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
| 521 return FALSE; | 517 return FALSE; |
| 522 | 518 |
| 523 CPDFSDK_InterForm* pInterForm = | 519 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 524 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
| 525 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 520 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 526 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 521 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 527 CJS_Array aName(pRuntime); | 522 CJS_Array aName(pRuntime); |
| 528 | 523 |
| 529 if (params.empty()) { | 524 if (params.empty()) { |
| 530 pPDFForm->ResetForm(TRUE); | 525 pPDFForm->ResetForm(TRUE); |
| 531 m_pDocument->SetChangeMark(); | 526 m_pDocument->SetChangeMark(); |
| 532 return TRUE; | 527 return TRUE; |
| 533 } | 528 } |
| 534 | 529 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); | 599 bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); |
| 605 | 600 |
| 606 pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty"); | 601 pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty"); |
| 607 bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); | 602 bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); |
| 608 | 603 |
| 609 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); | 604 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); |
| 610 aFields.Attach( | 605 aFields.Attach( |
| 611 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); | 606 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); |
| 612 } | 607 } |
| 613 | 608 |
| 614 CPDFSDK_InterForm* pInterForm = | 609 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 615 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
| 616 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 610 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 617 if (aFields.GetLength() == 0 && bEmpty) { | 611 if (aFields.GetLength() == 0 && bEmpty) { |
| 618 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { | 612 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
| 619 pRuntime->BeginBlock(); | 613 pRuntime->BeginBlock(); |
| 620 pInterForm->SubmitForm(strURL, FALSE); | 614 pInterForm->SubmitForm(strURL, FALSE); |
| 621 pRuntime->EndBlock(); | 615 pRuntime->EndBlock(); |
| 622 } | 616 } |
| 623 return TRUE; | 617 return TRUE; |
| 624 } | 618 } |
| 625 | 619 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 vp << m_cwBaseURL; | 1015 vp << m_cwBaseURL; |
| 1022 } else { | 1016 } else { |
| 1023 vp >> m_cwBaseURL; | 1017 vp >> m_cwBaseURL; |
| 1024 } | 1018 } |
| 1025 return TRUE; | 1019 return TRUE; |
| 1026 } | 1020 } |
| 1027 | 1021 |
| 1028 FX_BOOL Document::calculate(IJS_Context* cc, | 1022 FX_BOOL Document::calculate(IJS_Context* cc, |
| 1029 CJS_PropValue& vp, | 1023 CJS_PropValue& vp, |
| 1030 CFX_WideString& sError) { | 1024 CFX_WideString& sError) { |
| 1031 CPDFSDK_InterForm* pInterForm = | 1025 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 1032 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
| 1033 | |
| 1034 if (vp.IsGetting()) { | 1026 if (vp.IsGetting()) { |
| 1035 if (pInterForm->IsCalculateEnabled()) | 1027 if (pInterForm->IsCalculateEnabled()) |
| 1036 vp << true; | 1028 vp << true; |
| 1037 else | 1029 else |
| 1038 vp << false; | 1030 vp << false; |
| 1039 } else { | 1031 } else { |
| 1040 bool bCalculate; | 1032 bool bCalculate; |
| 1041 vp >> bCalculate; | 1033 vp >> bCalculate; |
| 1042 | 1034 |
| 1043 pInterForm->EnableCalculate(bCalculate); | 1035 pInterForm->EnableCalculate(bCalculate); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 | 1296 |
| 1305 FX_BOOL Document::calculateNow(IJS_Context* cc, | 1297 FX_BOOL Document::calculateNow(IJS_Context* cc, |
| 1306 const std::vector<CJS_Value>& params, | 1298 const std::vector<CJS_Value>& params, |
| 1307 CJS_Value& vRet, | 1299 CJS_Value& vRet, |
| 1308 CFX_WideString& sError) { | 1300 CFX_WideString& sError) { |
| 1309 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 1301 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 1310 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | 1302 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 1311 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) | 1303 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
| 1312 return FALSE; | 1304 return FALSE; |
| 1313 | 1305 |
| 1314 CPDFSDK_InterForm* pInterForm = | 1306 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 1315 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
| 1316 pInterForm->OnCalculate(); | 1307 pInterForm->OnCalculate(); |
| 1317 return TRUE; | 1308 return TRUE; |
| 1318 } | 1309 } |
| 1319 | 1310 |
| 1320 FX_BOOL Document::Collab(IJS_Context* cc, | 1311 FX_BOOL Document::Collab(IJS_Context* cc, |
| 1321 CJS_PropValue& vp, | 1312 CJS_PropValue& vp, |
| 1322 CFX_WideString& sError) { | 1313 CFX_WideString& sError) { |
| 1323 return TRUE; | 1314 return TRUE; |
| 1324 } | 1315 } |
| 1325 | 1316 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 } | 1573 } |
| 1583 } | 1574 } |
| 1584 | 1575 |
| 1585 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1576 for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1586 Field::DoDelay(m_pDocument, pData.get()); | 1577 Field::DoDelay(m_pDocument, pData.get()); |
| 1587 } | 1578 } |
| 1588 | 1579 |
| 1589 CJS_Document* Document::GetCJSDoc() const { | 1580 CJS_Document* Document::GetCJSDoc() const { |
| 1590 return static_cast<CJS_Document*>(m_pJSObject); | 1581 return static_cast<CJS_Document*>(m_pJSObject); |
| 1591 } | 1582 } |
| OLD | NEW |