Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: fpdfsdk/src/javascript/Document.cpp

Issue 1430213002: Remove CFX_PtrArray usage in fpdfsdk. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 -= 1;
Tom Sepez 2015/11/09 21:25:32 nit: some would say --.
Lei Zhang 2015/11/09 22:45:28 Done.
531 ASSERT(pWidget != NULL); 532 rcAnnot.bottom -= 1;
533 rcAnnot.right += 1;
534 rcAnnot.top += 1;
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 != NULL);
Tom Sepez 2015/11/09 21:25:32 nit: ASSERT(pPage)
Lei Zhang 2015/11/09 22:45:28 Done.
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
Tom Sepez 2015/11/09 21:25:32 nit: blank line probably not needed here.
Lei Zhang 2015/11/09 22:45:28 Done.
545 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); 545 pPageView->UpdateRects(aRefresh);
546 pPageView->DeleteAnnot(pWidget);
547
548 pPageView->UpdateRects(aRefresh);
549 }
550 m_pDocument->SetChangeMark();
551 } 546 }
547 m_pDocument->SetChangeMark();
552 548
553 return TRUE; 549 return TRUE;
554 } 550 }
555 551
556 // reset filed values within a document. 552 // reset filed values within a document.
557 // comment: 553 // comment:
558 // note: if the fields names r not rational, aodbe is dumb for it. 554 // note: if the fields names r not rational, aodbe is dumb for it.
559 555
560 FX_BOOL Document::resetForm(IJS_Context* cc, 556 FX_BOOL Document::resetForm(IJS_Context* cc,
561 const CJS_Parameters& params, 557 const CJS_Parameters& params,
(...skipping 13 matching lines...) Expand all
575 if (params.size() > 0) { 571 if (params.size() > 0) {
576 switch (params[0].GetType()) { 572 switch (params[0].GetType()) {
577 default: 573 default:
578 aName.Attach(params[0].ToV8Array()); 574 aName.Attach(params[0].ToV8Array());
579 break; 575 break;
580 case CJS_Value::VT_string: 576 case CJS_Value::VT_string:
581 aName.SetElement(0, params[0]); 577 aName.SetElement(0, params[0]);
582 break; 578 break;
583 } 579 }
584 580
585 CFX_PtrArray aFields; 581 std::vector<CPDF_FormField*> aFields;
586 582 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) {
587 for (int i = 0, isz = aName.GetLength(); i < isz; i++) {
588 CJS_Value valElement(pRuntime); 583 CJS_Value valElement(pRuntime);
589 aName.GetElement(i, valElement); 584 aName.GetElement(i, valElement);
590 CFX_WideString swVal = valElement.ToCFXWideString(); 585 CFX_WideString swVal = valElement.ToCFXWideString();
591 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; j++) { 586 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j)
592 aFields.Add((void*)pPDFForm->GetField(j, swVal)); 587 aFields.push_back(pPDFForm->GetField(j, swVal));
593 }
594 } 588 }
595 589
596 if (aFields.GetSize() > 0) { 590 if (!aFields.empty()) {
597 pPDFForm->ResetForm(aFields, TRUE, TRUE); 591 pPDFForm->ResetForm(aFields, TRUE, TRUE);
598 m_pDocument->SetChangeMark(); 592 m_pDocument->SetChangeMark();
599 } 593 }
600 } else { 594 } else {
601 pPDFForm->ResetForm(TRUE); 595 pPDFForm->ResetForm(TRUE);
Tom Sepez 2015/11/09 21:25:32 nit: maybe early return instead of else. (Someone
Lei Zhang 2015/11/09 22:45:28 Done.
602 m_pDocument->SetChangeMark(); 596 m_pDocument->SetChangeMark();
603 } 597 }
604 598
605 return TRUE; 599 return TRUE;
606 } 600 }
607 601
608 FX_BOOL Document::saveAs(IJS_Context* cc, 602 FX_BOOL Document::saveAs(IJS_Context* cc,
609 const CJS_Parameters& params, 603 const CJS_Parameters& params,
610 CJS_Value& vRet, 604 CJS_Value& vRet,
611 CFX_WideString& sError) { 605 CFX_WideString& sError) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); 650 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields");
657 aFields.Attach( 651 aFields.Attach(
658 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); 652 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
659 } 653 }
660 654
661 CPDFSDK_InterForm* pInterForm = 655 CPDFSDK_InterForm* pInterForm =
662 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); 656 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
663 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); 657 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
664 FX_BOOL bAll = (aFields.GetLength() == 0); 658 FX_BOOL bAll = (aFields.GetLength() == 0);
665 if (bAll && bEmpty) { 659 if (bAll && bEmpty) {
666 if (pPDFInterForm->CheckRequiredFields()) { 660 if (pPDFInterForm->CheckRequiredFields(nullptr, TRUE)) {
667 pRuntime->BeginBlock(); 661 pRuntime->BeginBlock();
668 pInterForm->SubmitForm(strURL, FALSE); 662 pInterForm->SubmitForm(strURL, FALSE);
669 pRuntime->EndBlock(); 663 pRuntime->EndBlock();
670 } 664 }
671 return TRUE; 665 return TRUE;
672 } 666 }
673 667
674 CFX_PtrArray fieldObjects; 668 std::vector<CPDF_FormField*> fieldObjects;
675 for (int i = 0, sz = aFields.GetLength(); i < sz; i++) { 669 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) {
676 CJS_Value valName(pRuntime); 670 CJS_Value valName(pRuntime);
677 aFields.GetElement(i, valName); 671 aFields.GetElement(i, valName);
678 672
679 CFX_WideString sName = valName.ToCFXWideString(); 673 CFX_WideString sName = valName.ToCFXWideString();
680 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); 674 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
681 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { 675 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) {
682 CPDF_FormField* pField = pPDFForm->GetField(j, sName); 676 CPDF_FormField* pField = pPDFForm->GetField(j, sName);
683 if (!bEmpty && pField->GetValue().IsEmpty()) 677 if (!bEmpty && pField->GetValue().IsEmpty())
684 continue; 678 continue;
685 679
686 fieldObjects.Add(pField); 680 fieldObjects.push_back(pField);
687 } 681 }
688 } 682 }
689 683
690 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) { 684 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) {
691 pRuntime->BeginBlock(); 685 pRuntime->BeginBlock();
692 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); 686 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
693 pRuntime->EndBlock(); 687 pRuntime->EndBlock();
694 } 688 }
695 return TRUE; 689 return TRUE;
696 } 690 }
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 CFX_DWordArray DelArray; 1812 CFX_DWordArray DelArray;
1819 1813
1820 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { 1814 for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
1821 m_DelayData.RemoveAt(DelArray[j]); 1815 m_DelayData.RemoveAt(DelArray[j]);
1822 } 1816 }
1823 } 1817 }
1824 1818
1825 CJS_Document* Document::GetCJSDoc() const { 1819 CJS_Document* Document::GetCJSDoc() const {
1826 return static_cast<CJS_Document*>(m_pJSObject); 1820 return static_cast<CJS_Document*>(m_pJSObject);
1827 } 1821 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698