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

Side by Side Diff: fpdfsdk/javascript/Field.cpp

Issue 1834203002: use std::vector in more places in JavaScript bindings code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@util_printx
Patch Set: Nits. Created 4 years, 8 months 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
« no previous file with comments | « fpdfsdk/javascript/Field.h ('k') | fpdfsdk/javascript/JS_GlobalData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "fpdfsdk/javascript/Field.h" 7 #include "fpdfsdk/javascript/Field.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 940
941 FX_BOOL Field::currentValueIndices(IJS_Context* cc, 941 FX_BOOL Field::currentValueIndices(IJS_Context* cc,
942 CJS_PropValue& vp, 942 CJS_PropValue& vp,
943 CFX_WideString& sError) { 943 CFX_WideString& sError) {
944 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 944 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
945 945
946 if (vp.IsSetting()) { 946 if (vp.IsSetting()) {
947 if (!m_bCanSet) 947 if (!m_bCanSet)
948 return FALSE; 948 return FALSE;
949 949
950 CFX_ArrayTemplate<uint32_t> array; 950 std::vector<uint32_t> array;
951
952 if (vp.GetType() == CJS_Value::VT_number) { 951 if (vp.GetType() == CJS_Value::VT_number) {
953 int iSelecting = 0; 952 int iSelecting = 0;
954 vp >> iSelecting; 953 vp >> iSelecting;
955 array.Add(iSelecting); 954 array.push_back(iSelecting);
956 } else if (vp.IsArrayObject()) { 955 } else if (vp.IsArrayObject()) {
957 CJS_Array SelArray(pRuntime); 956 CJS_Array SelArray(pRuntime);
958 CJS_Value SelValue(pRuntime); 957 CJS_Value SelValue(pRuntime);
959 int iSelecting; 958 int iSelecting;
960 vp >> SelArray; 959 vp >> SelArray;
961 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) { 960 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
962 SelArray.GetElement(i, SelValue); 961 SelArray.GetElement(i, SelValue);
963 iSelecting = SelValue.ToInt(); 962 iSelecting = SelValue.ToInt();
964 array.Add(iSelecting); 963 array.push_back(iSelecting);
965 } 964 }
966 } 965 }
967 966
968 if (m_bDelay) { 967 if (m_bDelay) {
969 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); 968 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
970 } else { 969 } else {
971 Field::SetCurrentValueIndices(m_pDocument, m_FieldName, 970 Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
972 m_nFormControlIndex, array); 971 m_nFormControlIndex, array);
973 } 972 }
974 } else { 973 } else {
(...skipping 20 matching lines...) Expand all
995 vp << -1; 994 vp << -1;
996 } 995 }
997 } 996 }
998 997
999 return TRUE; 998 return TRUE;
1000 } 999 }
1001 1000
1002 void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, 1001 void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
1003 const CFX_WideString& swFieldName, 1002 const CFX_WideString& swFieldName,
1004 int nControlIndex, 1003 int nControlIndex,
1005 const CFX_ArrayTemplate<uint32_t>& array) { 1004 const std::vector<uint32_t>& array) {
1006 ASSERT(pDocument); 1005 ASSERT(pDocument);
1007
1008 std::vector<CPDF_FormField*> FieldArray = 1006 std::vector<CPDF_FormField*> FieldArray =
1009 GetFormFields(pDocument, swFieldName); 1007 GetFormFields(pDocument, swFieldName);
1008
1010 for (CPDF_FormField* pFormField : FieldArray) { 1009 for (CPDF_FormField* pFormField : FieldArray) {
1011 int nFieldType = pFormField->GetFieldType(); 1010 int nFieldType = pFormField->GetFieldType();
1012 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) { 1011 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
1013 uint32_t dwFieldFlags = pFormField->GetFieldFlags(); 1012 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
1014 pFormField->ClearSelection(TRUE); 1013 pFormField->ClearSelection(TRUE);
1015 1014 for (size_t i = 0; i < array.size(); ++i) {
1016 for (int i = 0, sz = array.GetSize(); i < sz; i++) { 1015 if (i != 0 && !(dwFieldFlags & (1 << 21)))
1017 if (i > 0 && !(dwFieldFlags & (1 << 21))) {
1018 break; 1016 break;
1017 if (array[i] < pFormField->CountOptions() &&
1018 !pFormField->IsItemSelected(array[i])) {
1019 pFormField->SetItemSelection(array[i], TRUE);
1019 } 1020 }
1020
1021 int iSelecting = (int32_t)array.GetAt(i);
1022 if (iSelecting < pFormField->CountOptions() &&
1023 !pFormField->IsItemSelected(iSelecting))
1024 pFormField->SetItemSelection(iSelecting, TRUE);
1025 } 1021 }
1026 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE); 1022 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1027 } 1023 }
1028 } 1024 }
1029 } 1025 }
1030 1026
1031 FX_BOOL Field::defaultStyle(IJS_Context* cc, 1027 FX_BOOL Field::defaultStyle(IJS_Context* cc,
1032 CJS_PropValue& vp, 1028 CJS_PropValue& vp,
1033 CFX_WideString& sError) { 1029 CFX_WideString& sError) {
1034 return FALSE; 1030 return FALSE;
(...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 2701
2706 FX_BOOL Field::value(IJS_Context* cc, 2702 FX_BOOL Field::value(IJS_Context* cc,
2707 CJS_PropValue& vp, 2703 CJS_PropValue& vp,
2708 CFX_WideString& sError) { 2704 CFX_WideString& sError) {
2709 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 2705 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2710 2706
2711 if (vp.IsSetting()) { 2707 if (vp.IsSetting()) {
2712 if (!m_bCanSet) 2708 if (!m_bCanSet)
2713 return FALSE; 2709 return FALSE;
2714 2710
2715 CJS_WideStringArray strArray; 2711 std::vector<CFX_WideString> strArray;
2716
2717 if (vp.IsArrayObject()) { 2712 if (vp.IsArrayObject()) {
2718 CJS_Array ValueArray(pRuntime); 2713 CJS_Array ValueArray(pRuntime);
2719 vp.ConvertToArray(ValueArray); 2714 vp.ConvertToArray(ValueArray);
2720 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) { 2715 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
2721 CJS_Value ElementValue(pRuntime); 2716 CJS_Value ElementValue(pRuntime);
2722 ValueArray.GetElement(i, ElementValue); 2717 ValueArray.GetElement(i, ElementValue);
2723 strArray.Add(ElementValue.ToCFXWideString()); 2718 strArray.push_back(ElementValue.ToCFXWideString());
2724 } 2719 }
2725 } else { 2720 } else {
2726 CFX_WideString swValue; 2721 CFX_WideString swValue;
2727 vp >> swValue; 2722 vp >> swValue;
2728 strArray.Add(swValue); 2723 strArray.push_back(swValue);
2729 } 2724 }
2730 2725
2731 if (m_bDelay) { 2726 if (m_bDelay) {
2732 AddDelay_WideStringArray(FP_VALUE, strArray); 2727 AddDelay_WideStringArray(FP_VALUE, strArray);
2733 } else { 2728 } else {
2734 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray); 2729 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
2735 } 2730 }
2736 } else { 2731 } else {
2737 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 2732 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2738 if (FieldArray.empty()) 2733 if (FieldArray.empty())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 break; 2776 break;
2782 } 2777 }
2783 } 2778 }
2784 vp.MaybeCoerceToNumber(); 2779 vp.MaybeCoerceToNumber();
2785 return TRUE; 2780 return TRUE;
2786 } 2781 }
2787 2782
2788 void Field::SetValue(CPDFSDK_Document* pDocument, 2783 void Field::SetValue(CPDFSDK_Document* pDocument,
2789 const CFX_WideString& swFieldName, 2784 const CFX_WideString& swFieldName,
2790 int nControlIndex, 2785 int nControlIndex,
2791 const CJS_WideStringArray& strArray) { 2786 const std::vector<CFX_WideString>& strArray) {
2792 ASSERT(pDocument); 2787 ASSERT(pDocument);
2793 2788 if (strArray.empty())
2794 if (strArray.GetSize() < 1)
2795 return; 2789 return;
2796 2790
2797 std::vector<CPDF_FormField*> FieldArray = 2791 std::vector<CPDF_FormField*> FieldArray =
2798 GetFormFields(pDocument, swFieldName); 2792 GetFormFields(pDocument, swFieldName);
2799 2793
2800 for (CPDF_FormField* pFormField : FieldArray) { 2794 for (CPDF_FormField* pFormField : FieldArray) {
2801 if (pFormField->GetFullName().Compare(swFieldName) != 0) 2795 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2802 continue; 2796 continue;
2803 2797
2804 switch (pFormField->GetFieldType()) { 2798 switch (pFormField->GetFieldType()) {
2805 case FIELDTYPE_TEXTFIELD: 2799 case FIELDTYPE_TEXTFIELD:
2806 case FIELDTYPE_COMBOBOX: 2800 case FIELDTYPE_COMBOBOX:
2807 if (pFormField->GetValue() != strArray.GetAt(0)) { 2801 if (pFormField->GetValue() != strArray[0]) {
2808 CFX_WideString WideString = strArray.GetAt(0); 2802 pFormField->SetValue(strArray[0], TRUE);
2809 pFormField->SetValue(strArray.GetAt(0), TRUE);
2810 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); 2803 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2811 } 2804 }
2812 break; 2805 break;
2813 case FIELDTYPE_CHECKBOX: // mantis: 0004493 2806 case FIELDTYPE_CHECKBOX:
2814 case FIELDTYPE_RADIOBUTTON: { 2807 case FIELDTYPE_RADIOBUTTON: {
2815 if (pFormField->GetValue() != strArray.GetAt(0)) { 2808 if (pFormField->GetValue() != strArray[0]) {
2816 pFormField->SetValue(strArray.GetAt(0), TRUE); 2809 pFormField->SetValue(strArray[0], TRUE);
2817 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); 2810 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2818 } 2811 }
2819 } break; 2812 } break;
2820 case FIELDTYPE_LISTBOX: { 2813 case FIELDTYPE_LISTBOX: {
2821 FX_BOOL bModified = FALSE; 2814 FX_BOOL bModified = FALSE;
2822 2815 for (const auto& str : strArray) {
2823 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) { 2816 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
2824 int iIndex = pFormField->FindOption(strArray.GetAt(i));
2825
2826 if (!pFormField->IsItemSelected(iIndex)) {
2827 bModified = TRUE; 2817 bModified = TRUE;
2828 break; 2818 break;
2829 } 2819 }
2830 } 2820 }
2831
2832 if (bModified) { 2821 if (bModified) {
2833 pFormField->ClearSelection(TRUE); 2822 pFormField->ClearSelection(TRUE);
2834 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) { 2823 for (const auto& str : strArray) {
2835 int iIndex = pFormField->FindOption(strArray.GetAt(i)); 2824 int index = pFormField->FindOption(str);
2836 pFormField->SetItemSelection(iIndex, TRUE, TRUE); 2825 if (!pFormField->IsItemSelected(index))
2826 pFormField->SetItemSelection(index, TRUE, TRUE);
2837 } 2827 }
2838
2839 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); 2828 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2840 } 2829 }
2841 } break; 2830 } break;
2842 default: 2831 default:
2843 break; 2832 break;
2844 } 2833 }
2845 } 2834 }
2846 } 2835 }
2847 2836
2848 FX_BOOL Field::valueAsString(IJS_Context* cc, 2837 FX_BOOL Field::valueAsString(IJS_Context* cc,
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
3358 FX_BOOL Field::source(IJS_Context* cc, 3347 FX_BOOL Field::source(IJS_Context* cc,
3359 CJS_PropValue& vp, 3348 CJS_PropValue& vp,
3360 CFX_WideString& sError) { 3349 CFX_WideString& sError) {
3361 if (vp.IsGetting()) { 3350 if (vp.IsGetting()) {
3362 vp << (CJS_Object*)NULL; 3351 vp << (CJS_Object*)NULL;
3363 } 3352 }
3364 3353
3365 return TRUE; 3354 return TRUE;
3366 } 3355 }
3367 3356
3368 void Field::AddDelay_Int(enum FIELD_PROP prop, int32_t n) { 3357 void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3369 CJS_DelayData* pNewData = new CJS_DelayData; 3358 CJS_DelayData* pNewData =
3370 pNewData->sFieldName = m_FieldName; 3359 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3371 pNewData->nControlIndex = m_nFormControlIndex;
3372 pNewData->eProp = prop;
3373 pNewData->num = n; 3360 pNewData->num = n;
3374
3375 m_pJSDoc->AddDelayData(pNewData); 3361 m_pJSDoc->AddDelayData(pNewData);
3376 } 3362 }
3377 3363
3378 void Field::AddDelay_Bool(enum FIELD_PROP prop, bool b) { 3364 void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3379 CJS_DelayData* pNewData = new CJS_DelayData; 3365 CJS_DelayData* pNewData =
3380 pNewData->sFieldName = m_FieldName; 3366 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3381 pNewData->nControlIndex = m_nFormControlIndex;
3382 pNewData->eProp = prop;
3383 pNewData->b = b; 3367 pNewData->b = b;
3384
3385 m_pJSDoc->AddDelayData(pNewData); 3368 m_pJSDoc->AddDelayData(pNewData);
3386 } 3369 }
3387 3370
3388 void Field::AddDelay_String(enum FIELD_PROP prop, 3371 void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
3389 const CFX_ByteString& string) { 3372 CJS_DelayData* pNewData =
3390 CJS_DelayData* pNewData = new CJS_DelayData; 3373 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3391 pNewData->sFieldName = m_FieldName;
3392 pNewData->nControlIndex = m_nFormControlIndex;
3393 pNewData->eProp = prop;
3394 pNewData->string = string; 3374 pNewData->string = string;
3395
3396 m_pJSDoc->AddDelayData(pNewData); 3375 m_pJSDoc->AddDelayData(pNewData);
3397 } 3376 }
3398 3377
3399 void Field::AddDelay_WideString(enum FIELD_PROP prop, 3378 void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3400 const CFX_WideString& string) { 3379 CJS_DelayData* pNewData =
3401 CJS_DelayData* pNewData = new CJS_DelayData; 3380 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3402 pNewData->sFieldName = m_FieldName;
3403 pNewData->nControlIndex = m_nFormControlIndex;
3404 pNewData->eProp = prop;
3405 pNewData->widestring = string; 3381 pNewData->widestring = string;
3406
3407 m_pJSDoc->AddDelayData(pNewData); 3382 m_pJSDoc->AddDelayData(pNewData);
3408 } 3383 }
3409 3384
3410 void Field::AddDelay_Rect(enum FIELD_PROP prop, const CFX_FloatRect& rect) { 3385 void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3411 CJS_DelayData* pNewData = new CJS_DelayData; 3386 CJS_DelayData* pNewData =
3412 pNewData->sFieldName = m_FieldName; 3387 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3413 pNewData->nControlIndex = m_nFormControlIndex;
3414 pNewData->eProp = prop;
3415 pNewData->rect = rect; 3388 pNewData->rect = rect;
3416
3417 m_pJSDoc->AddDelayData(pNewData); 3389 m_pJSDoc->AddDelayData(pNewData);
3418 } 3390 }
3419 3391
3420 void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color) { 3392 void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
3421 CJS_DelayData* pNewData = new CJS_DelayData; 3393 CJS_DelayData* pNewData =
3422 pNewData->sFieldName = m_FieldName; 3394 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3423 pNewData->nControlIndex = m_nFormControlIndex;
3424 pNewData->eProp = prop;
3425 pNewData->color = color; 3395 pNewData->color = color;
3426
3427 m_pJSDoc->AddDelayData(pNewData); 3396 m_pJSDoc->AddDelayData(pNewData);
3428 } 3397 }
3429 3398
3430 void Field::AddDelay_WordArray(enum FIELD_PROP prop, 3399 void Field::AddDelay_WordArray(FIELD_PROP prop,
3431 const CFX_ArrayTemplate<uint32_t>& array) { 3400 const std::vector<uint32_t>& array) {
3432 CJS_DelayData* pNewData = new CJS_DelayData; 3401 CJS_DelayData* pNewData =
3433 pNewData->sFieldName = m_FieldName; 3402 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3434 pNewData->nControlIndex = m_nFormControlIndex; 3403 pNewData->wordarray = array;
3435 pNewData->eProp = prop;
3436
3437 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3438 pNewData->wordarray.Add(array.GetAt(i));
3439
3440 m_pJSDoc->AddDelayData(pNewData); 3404 m_pJSDoc->AddDelayData(pNewData);
3441 } 3405 }
3442 3406
3443 void Field::AddDelay_WideStringArray(enum FIELD_PROP prop, 3407 void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3444 const CJS_WideStringArray& array) { 3408 const std::vector<CFX_WideString>& array) {
3445 CJS_DelayData* pNewData = new CJS_DelayData; 3409 CJS_DelayData* pNewData =
3446 pNewData->sFieldName = m_FieldName; 3410 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3447 pNewData->nControlIndex = m_nFormControlIndex; 3411 pNewData->widestringarray = array;
3448 pNewData->eProp = prop;
3449 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3450 pNewData->widestringarray.Add(array.GetAt(i));
3451
3452 m_pJSDoc->AddDelayData(pNewData); 3412 m_pJSDoc->AddDelayData(pNewData);
3453 } 3413 }
3454 3414
3455 void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) { 3415 void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) {
3456 ASSERT(pDocument); 3416 ASSERT(pDocument);
3457
3458 switch (pData->eProp) { 3417 switch (pData->eProp) {
3459 case FP_ALIGNMENT: 3418 case FP_ALIGNMENT:
3460 Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, 3419 Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex,
3461 pData->string); 3420 pData->string);
3462 break; 3421 break;
3463 case FP_BORDERSTYLE: 3422 case FP_BORDERSTYLE:
3464 Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, 3423 Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3465 pData->string); 3424 pData->string);
3466 break; 3425 break;
3467 case FP_BUTTONALIGNX: 3426 case FP_BUTTONALIGNX:
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
3593 } 3552 }
3594 } 3553 }
3595 3554
3596 void Field::AddField(CPDFSDK_Document* pDocument, 3555 void Field::AddField(CPDFSDK_Document* pDocument,
3597 int nPageIndex, 3556 int nPageIndex,
3598 int nFieldType, 3557 int nFieldType,
3599 const CFX_WideString& sName, 3558 const CFX_WideString& sName,
3600 const CFX_FloatRect& rcCoords) { 3559 const CFX_FloatRect& rcCoords) {
3601 // Not supported. 3560 // Not supported.
3602 } 3561 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/Field.h ('k') | fpdfsdk/javascript/JS_GlobalData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698