| 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 "Document.h" | 7 #include "Document.h" |
| 8 | 8 |
| 9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. | 9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. |
| 10 #include "../../include/javascript/IJavaScript.h" | 10 #include "../../include/javascript/IJavaScript.h" |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 if (params.size() != 1) { | 513 if (params.size() != 1) { |
| 514 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 514 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 515 return FALSE; | 515 return FALSE; |
| 516 } | 516 } |
| 517 | 517 |
| 518 CFX_WideString sFieldName = params[0].ToCFXWideString(); | 518 CFX_WideString sFieldName = params[0].ToCFXWideString(); |
| 519 CPDFSDK_InterForm* pInterForm = | 519 CPDFSDK_InterForm* pInterForm = |
| 520 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | 520 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
| 521 ASSERT(pInterForm != NULL); | 521 ASSERT(pInterForm != NULL); |
| 522 | 522 |
| 523 CFX_PtrArray widgets; | 523 std::vector<CPDFSDK_Widget*> widgets; |
| 524 pInterForm->GetWidgets(sFieldName, widgets); | 524 pInterForm->GetWidgets(sFieldName, &widgets); |
| 525 | 525 |
| 526 int nSize = widgets.GetSize(); | 526 if (widgets.empty()) |
| 527 return TRUE; |
| 527 | 528 |
| 528 if (nSize > 0) { | 529 for (CPDFSDK_Widget* pWidget : widgets) { |
| 529 for (int i = 0; i < nSize; i++) { | 530 CPDF_Rect rcAnnot = pWidget->GetRect(); |
| 530 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i]; | 531 --rcAnnot.left; |
| 531 ASSERT(pWidget != NULL); | 532 --rcAnnot.bottom; |
| 533 ++rcAnnot.right; |
| 534 ++rcAnnot.top; |
| 532 | 535 |
| 533 CPDF_Rect rcAnnot = pWidget->GetRect(); | 536 CFX_RectArray aRefresh; |
| 534 rcAnnot.left -= 1; | 537 aRefresh.Add(rcAnnot); |
| 535 rcAnnot.bottom -= 1; | |
| 536 rcAnnot.right += 1; | |
| 537 rcAnnot.top += 1; | |
| 538 | 538 |
| 539 CFX_RectArray aRefresh; | 539 CPDF_Page* pPage = pWidget->GetPDFPage(); |
| 540 aRefresh.Add(rcAnnot); | 540 ASSERT(pPage); |
| 541 | 541 |
| 542 CPDF_Page* pPage = pWidget->GetPDFPage(); | 542 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); |
| 543 ASSERT(pPage != NULL); | 543 pPageView->DeleteAnnot(pWidget); |
| 544 | 544 pPageView->UpdateRects(aRefresh); |
| 545 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); | |
| 546 pPageView->DeleteAnnot(pWidget); | |
| 547 | |
| 548 pPageView->UpdateRects(aRefresh); | |
| 549 } | |
| 550 m_pDocument->SetChangeMark(); | |
| 551 } | 545 } |
| 546 m_pDocument->SetChangeMark(); |
| 552 | 547 |
| 553 return TRUE; | 548 return TRUE; |
| 554 } | 549 } |
| 555 | 550 |
| 556 // reset filed values within a document. | 551 // reset filed values within a document. |
| 557 // comment: | 552 // comment: |
| 558 // note: if the fields names r not rational, aodbe is dumb for it. | 553 // note: if the fields names r not rational, aodbe is dumb for it. |
| 559 | 554 |
| 560 FX_BOOL Document::resetForm(IJS_Context* cc, | 555 FX_BOOL Document::resetForm(IJS_Context* cc, |
| 561 const CJS_Parameters& params, | 556 const CJS_Parameters& params, |
| 562 CJS_Value& vRet, | 557 CJS_Value& vRet, |
| 563 CFX_WideString& sError) { | 558 CFX_WideString& sError) { |
| 564 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 559 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 565 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | 560 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 566 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) | 561 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
| 567 return FALSE; | 562 return FALSE; |
| 568 | 563 |
| 569 CPDFSDK_InterForm* pInterForm = | 564 CPDFSDK_InterForm* pInterForm = |
| 570 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | 565 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
| 571 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 566 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 572 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 567 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 573 CJS_Array aName(pRuntime); | 568 CJS_Array aName(pRuntime); |
| 574 | 569 |
| 575 if (params.size() > 0) { | 570 // TODO(thestig) Convert CJS_Parameters to a std::vector and use .empty(). |
| 576 switch (params[0].GetType()) { | 571 if (params.size() <= 0) { |
| 577 default: | 572 pPDFForm->ResetForm(TRUE); |
| 578 aName.Attach(params[0].ToV8Array()); | 573 m_pDocument->SetChangeMark(); |
| 579 break; | 574 return TRUE; |
| 580 case CJS_Value::VT_string: | 575 } |
| 581 aName.SetElement(0, params[0]); | |
| 582 break; | |
| 583 } | |
| 584 | 576 |
| 585 CFX_PtrArray aFields; | 577 switch (params[0].GetType()) { |
| 578 default: |
| 579 aName.Attach(params[0].ToV8Array()); |
| 580 break; |
| 581 case CJS_Value::VT_string: |
| 582 aName.SetElement(0, params[0]); |
| 583 break; |
| 584 } |
| 586 | 585 |
| 587 for (int i = 0, isz = aName.GetLength(); i < isz; i++) { | 586 std::vector<CPDF_FormField*> aFields; |
| 588 CJS_Value valElement(pRuntime); | 587 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { |
| 589 aName.GetElement(i, valElement); | 588 CJS_Value valElement(pRuntime); |
| 590 CFX_WideString swVal = valElement.ToCFXWideString(); | 589 aName.GetElement(i, valElement); |
| 591 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; j++) { | 590 CFX_WideString swVal = valElement.ToCFXWideString(); |
| 592 aFields.Add((void*)pPDFForm->GetField(j, swVal)); | 591 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 593 } | 592 aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 594 } | 593 } |
| 595 | 594 |
| 596 if (aFields.GetSize() > 0) { | 595 if (!aFields.empty()) { |
| 597 pPDFForm->ResetForm(aFields, TRUE, TRUE); | 596 pPDFForm->ResetForm(aFields, TRUE, TRUE); |
| 598 m_pDocument->SetChangeMark(); | |
| 599 } | |
| 600 } else { | |
| 601 pPDFForm->ResetForm(TRUE); | |
| 602 m_pDocument->SetChangeMark(); | 597 m_pDocument->SetChangeMark(); |
| 603 } | 598 } |
| 604 | 599 |
| 605 return TRUE; | 600 return TRUE; |
| 606 } | 601 } |
| 607 | 602 |
| 608 FX_BOOL Document::saveAs(IJS_Context* cc, | 603 FX_BOOL Document::saveAs(IJS_Context* cc, |
| 609 const CJS_Parameters& params, | 604 const CJS_Parameters& params, |
| 610 CJS_Value& vRet, | 605 CJS_Value& vRet, |
| 611 CFX_WideString& sError) { | 606 CFX_WideString& sError) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); | 651 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); |
| 657 aFields.Attach( | 652 aFields.Attach( |
| 658 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); | 653 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); |
| 659 } | 654 } |
| 660 | 655 |
| 661 CPDFSDK_InterForm* pInterForm = | 656 CPDFSDK_InterForm* pInterForm = |
| 662 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | 657 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
| 663 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 658 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 664 FX_BOOL bAll = (aFields.GetLength() == 0); | 659 FX_BOOL bAll = (aFields.GetLength() == 0); |
| 665 if (bAll && bEmpty) { | 660 if (bAll && bEmpty) { |
| 666 if (pPDFInterForm->CheckRequiredFields()) { | 661 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
| 667 pRuntime->BeginBlock(); | 662 pRuntime->BeginBlock(); |
| 668 pInterForm->SubmitForm(strURL, FALSE); | 663 pInterForm->SubmitForm(strURL, FALSE); |
| 669 pRuntime->EndBlock(); | 664 pRuntime->EndBlock(); |
| 670 } | 665 } |
| 671 return TRUE; | 666 return TRUE; |
| 672 } | 667 } |
| 673 | 668 |
| 674 CFX_PtrArray fieldObjects; | 669 std::vector<CPDF_FormField*> fieldObjects; |
| 675 for (int i = 0, sz = aFields.GetLength(); i < sz; i++) { | 670 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { |
| 676 CJS_Value valName(pRuntime); | 671 CJS_Value valName(pRuntime); |
| 677 aFields.GetElement(i, valName); | 672 aFields.GetElement(i, valName); |
| 678 | 673 |
| 679 CFX_WideString sName = valName.ToCFXWideString(); | 674 CFX_WideString sName = valName.ToCFXWideString(); |
| 680 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 675 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 681 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { | 676 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { |
| 682 CPDF_FormField* pField = pPDFForm->GetField(j, sName); | 677 CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
| 683 if (!bEmpty && pField->GetValue().IsEmpty()) | 678 if (!bEmpty && pField->GetValue().IsEmpty()) |
| 684 continue; | 679 continue; |
| 685 | 680 |
| 686 fieldObjects.Add(pField); | 681 fieldObjects.push_back(pField); |
| 687 } | 682 } |
| 688 } | 683 } |
| 689 | 684 |
| 690 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) { | 685 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { |
| 691 pRuntime->BeginBlock(); | 686 pRuntime->BeginBlock(); |
| 692 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); | 687 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); |
| 693 pRuntime->EndBlock(); | 688 pRuntime->EndBlock(); |
| 694 } | 689 } |
| 695 return TRUE; | 690 return TRUE; |
| 696 } | 691 } |
| 697 | 692 |
| 698 ////////////////////////////////////////////////////////////////////////////////
////////////// | 693 ////////////////////////////////////////////////////////////////////////////////
////////////// |
| 699 | 694 |
| 700 void Document::AttachDoc(CPDFSDK_Document* pDoc) { | 695 void Document::AttachDoc(CPDFSDK_Document* pDoc) { |
| (...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 CFX_DWordArray DelArray; | 1813 CFX_DWordArray DelArray; |
| 1819 | 1814 |
| 1820 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { | 1815 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { |
| 1821 m_DelayData.RemoveAt(DelArray[j]); | 1816 m_DelayData.RemoveAt(DelArray[j]); |
| 1822 } | 1817 } |
| 1823 } | 1818 } |
| 1824 | 1819 |
| 1825 CJS_Document* Document::GetCJSDoc() const { | 1820 CJS_Document* Document::GetCJSDoc() const { |
| 1826 return static_cast<CJS_Document*>(m_pJSObject); | 1821 return static_cast<CJS_Document*>(m_pJSObject); |
| 1827 } | 1822 } |
| OLD | NEW |