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

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

Issue 2245863002: Push v8::Isolate into CFXJS_Engine class (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Make members private Created 4 years, 4 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
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 IMPLEMENT_JS_CLASS(CJS_Field, Field) 116 IMPLEMENT_JS_CLASS(CJS_Field, Field)
117 117
118 CJS_DelayData::CJS_DelayData(FIELD_PROP prop, 118 CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
119 int idx, 119 int idx,
120 const CFX_WideString& name) 120 const CFX_WideString& name)
121 : eProp(prop), nControlIndex(idx), sFieldName(name) {} 121 : eProp(prop), nControlIndex(idx), sFieldName(name) {}
122 122
123 CJS_DelayData::~CJS_DelayData() {} 123 CJS_DelayData::~CJS_DelayData() {}
124 124
125 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { 125 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
126 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
127 Field* pField = static_cast<Field*>(GetEmbedObject());
128 pField->SetIsolate(pRuntime->GetIsolate());
129 } 126 }
130 127
131 Field::Field(CJS_Object* pJSObject) 128 Field::Field(CJS_Object* pJSObject)
132 : CJS_EmbedObj(pJSObject), 129 : CJS_EmbedObj(pJSObject),
133 m_pJSDoc(nullptr), 130 m_pJSDoc(nullptr),
134 m_pDocument(nullptr), 131 m_pDocument(nullptr),
135 m_nFormControlIndex(-1), 132 m_nFormControlIndex(-1),
136 m_bCanSet(FALSE), 133 m_bCanSet(FALSE),
137 m_bDelay(FALSE), 134 m_bDelay(FALSE) {}
138 m_isolate(nullptr) {}
139 135
140 Field::~Field() {} 136 Field::~Field() {}
141 137
142 // note: iControlNo = -1, means not a widget. 138 // note: iControlNo = -1, means not a widget.
143 void Field::ParseFieldName(const std::wstring& strFieldNameParsed, 139 void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
144 std::wstring& strFieldName, 140 std::wstring& strFieldName,
145 int& iControlNo) { 141 int& iControlNo) {
146 int iStart = strFieldNameParsed.find_last_of(L'.'); 142 int iStart = strFieldNameParsed.find_last_of(L'.');
147 if (iStart == -1) { 143 if (iStart == -1) {
148 strFieldName = strFieldNameParsed; 144 strFieldName = strFieldNameParsed;
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 std::vector<uint32_t> array; 953 std::vector<uint32_t> array;
958 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) { 954 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
959 int iSelecting = 0; 955 int iSelecting = 0;
960 vp >> iSelecting; 956 vp >> iSelecting;
961 array.push_back(iSelecting); 957 array.push_back(iSelecting);
962 } else if (vp.GetJSValue()->IsArrayObject()) { 958 } else if (vp.GetJSValue()->IsArrayObject()) {
963 CJS_Array SelArray; 959 CJS_Array SelArray;
964 CJS_Value SelValue(pRuntime); 960 CJS_Value SelValue(pRuntime);
965 int iSelecting; 961 int iSelecting;
966 vp >> SelArray; 962 vp >> SelArray;
967 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) { 963 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
968 SelArray.GetElement(pRuntime->GetIsolate(), i, SelValue); 964 SelArray.GetElement(pRuntime, i, SelValue);
969 iSelecting = SelValue.ToInt(pRuntime->GetIsolate()); 965 iSelecting = SelValue.ToInt(pRuntime);
970 array.push_back(iSelecting); 966 array.push_back(iSelecting);
971 } 967 }
972 } 968 }
973 969
974 if (m_bDelay) { 970 if (m_bDelay) {
975 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); 971 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
976 } else { 972 } else {
977 Field::SetCurrentValueIndices(m_pDocument, m_FieldName, 973 Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
978 m_nFormControlIndex, array); 974 m_nFormControlIndex, array);
979 } 975 }
980 } else { 976 } else {
981 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 977 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
982 if (FieldArray.empty()) 978 if (FieldArray.empty())
983 return FALSE; 979 return FALSE;
984 980
985 CPDF_FormField* pFormField = FieldArray[0]; 981 CPDF_FormField* pFormField = FieldArray[0];
986 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && 982 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
987 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { 983 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
988 return FALSE; 984 return FALSE;
989 } 985 }
990 986
991 if (pFormField->CountSelectedItems() == 1) { 987 if (pFormField->CountSelectedItems() == 1) {
992 vp << pFormField->GetSelectedIndex(0); 988 vp << pFormField->GetSelectedIndex(0);
993 } else if (pFormField->CountSelectedItems() > 1) { 989 } else if (pFormField->CountSelectedItems() > 1) {
994 CJS_Array SelArray; 990 CJS_Array SelArray;
995 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { 991 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
996 SelArray.SetElement( 992 SelArray.SetElement(
997 pRuntime->GetIsolate(), i, 993 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
998 CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
999 } 994 }
1000 vp << SelArray; 995 vp << SelArray;
1001 } else { 996 } else {
1002 vp << -1; 997 vp << -1;
1003 } 998 }
1004 } 999 }
1005 1000
1006 return TRUE; 1001 return TRUE;
1007 } 1002 }
1008 1003
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1372
1378 if (!vp.GetJSValue()->IsArrayObject()) 1373 if (!vp.GetJSValue()->IsArrayObject())
1379 return FALSE; 1374 return FALSE;
1380 } else { 1375 } else {
1381 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1376 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1382 CJS_Array ExportValusArray; 1377 CJS_Array ExportValusArray;
1383 if (m_nFormControlIndex < 0) { 1378 if (m_nFormControlIndex < 0) {
1384 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 1379 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1385 CPDF_FormControl* pFormControl = pFormField->GetControl(i); 1380 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1386 ExportValusArray.SetElement( 1381 ExportValusArray.SetElement(
1387 pRuntime->GetIsolate(), i, 1382 pRuntime, i,
1388 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); 1383 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
1389 } 1384 }
1390 } else { 1385 } else {
1391 if (m_nFormControlIndex >= pFormField->CountControls()) 1386 if (m_nFormControlIndex >= pFormField->CountControls())
1392 return FALSE; 1387 return FALSE;
1393 1388
1394 CPDF_FormControl* pFormControl = 1389 CPDF_FormControl* pFormControl =
1395 pFormField->GetControl(m_nFormControlIndex); 1390 pFormField->GetControl(m_nFormControlIndex);
1396 if (!pFormControl) 1391 if (!pFormControl)
1397 return FALSE; 1392 return FALSE;
1398 1393
1399 ExportValusArray.SetElement( 1394 ExportValusArray.SetElement(
1400 pRuntime->GetIsolate(), 0, 1395 pRuntime, 0,
1401 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); 1396 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
1402 } 1397 }
1403 vp << ExportValusArray; 1398 vp << ExportValusArray;
1404 } 1399 }
1405 return TRUE; 1400 return TRUE;
1406 } 1401 }
1407 1402
1408 FX_BOOL Field::fileSelect(IJS_Context* cc, 1403 FX_BOOL Field::fileSelect(IJS_Context* cc,
1409 CJS_PropValue& vp, 1404 CJS_PropValue& vp,
1410 CFX_WideString& sError) { 1405 CFX_WideString& sError) {
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 } 1883 }
1889 1884
1890 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1885 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1891 CJS_Array PageArray; 1886 CJS_Array PageArray;
1892 for (size_t i = 0; i < widgets.size(); ++i) { 1887 for (size_t i = 0; i < widgets.size(); ++i) {
1893 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); 1888 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1894 if (!pPageView) 1889 if (!pPageView)
1895 return FALSE; 1890 return FALSE;
1896 1891
1897 PageArray.SetElement( 1892 PageArray.SetElement(
1898 pRuntime->GetIsolate(), i, 1893 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1899 CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1900 } 1894 }
1901 1895
1902 vp << PageArray; 1896 vp << PageArray;
1903 return TRUE; 1897 return TRUE;
1904 } 1898 }
1905 1899
1906 FX_BOOL Field::password(IJS_Context* cc, 1900 FX_BOOL Field::password(IJS_Context* cc,
1907 CJS_PropValue& vp, 1901 CJS_PropValue& vp,
1908 CFX_WideString& sError) { 1902 CFX_WideString& sError) {
1909 ASSERT(m_pDocument); 1903 ASSERT(m_pDocument);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 CJS_Value Lower_Righty(pRuntime); 2076 CJS_Value Lower_Righty(pRuntime);
2083 2077
2084 if (vp.IsSetting()) { 2078 if (vp.IsSetting()) {
2085 if (!m_bCanSet) 2079 if (!m_bCanSet)
2086 return FALSE; 2080 return FALSE;
2087 if (!vp.GetJSValue()->IsArrayObject()) 2081 if (!vp.GetJSValue()->IsArrayObject())
2088 return FALSE; 2082 return FALSE;
2089 2083
2090 CJS_Array rcArray; 2084 CJS_Array rcArray;
2091 vp >> rcArray; 2085 vp >> rcArray;
2092 rcArray.GetElement(pRuntime->GetIsolate(), 0, Upper_Leftx); 2086 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
2093 rcArray.GetElement(pRuntime->GetIsolate(), 1, Upper_Lefty); 2087 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
2094 rcArray.GetElement(pRuntime->GetIsolate(), 2, Lower_Rightx); 2088 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
2095 rcArray.GetElement(pRuntime->GetIsolate(), 3, Lower_Righty); 2089 rcArray.GetElement(pRuntime, 3, Lower_Righty);
2096 2090
2097 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f}; 2091 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2098 pArray[0] = 2092 pArray[0] = static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime));
2099 static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime->GetIsolate())); 2093 pArray[1] = static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime));
2100 pArray[1] = 2094 pArray[2] = static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime));
2101 static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime->GetIsolate())); 2095 pArray[3] = static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime));
2102 pArray[2] =
2103 static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime->GetIsolate()));
2104 pArray[3] =
2105 static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime->GetIsolate()));
2106 2096
2107 CFX_FloatRect crRect(pArray); 2097 CFX_FloatRect crRect(pArray);
2108 if (m_bDelay) { 2098 if (m_bDelay) {
2109 AddDelay_Rect(FP_RECT, crRect); 2099 AddDelay_Rect(FP_RECT, crRect);
2110 } else { 2100 } else {
2111 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect); 2101 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
2112 } 2102 }
2113 } else { 2103 } else {
2114 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 2104 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2115 if (FieldArray.empty()) 2105 if (FieldArray.empty())
2116 return FALSE; 2106 return FALSE;
2117 2107
2118 CPDF_FormField* pFormField = FieldArray[0]; 2108 CPDF_FormField* pFormField = FieldArray[0];
2119 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); 2109 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
2120 CPDFSDK_Widget* pWidget = 2110 CPDFSDK_Widget* pWidget =
2121 pInterForm->GetWidget(GetSmartFieldControl(pFormField)); 2111 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2122 if (!pWidget) 2112 if (!pWidget)
2123 return FALSE; 2113 return FALSE;
2124 2114
2125 CFX_FloatRect crRect = pWidget->GetRect(); 2115 CFX_FloatRect crRect = pWidget->GetRect();
2126 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)); 2116 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
2127 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)); 2117 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
2128 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)); 2118 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
2129 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)); 2119 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
2130 2120
2131 CJS_Array rcArray; 2121 CJS_Array rcArray;
2132 rcArray.SetElement(pRuntime->GetIsolate(), 0, Upper_Leftx); 2122 rcArray.SetElement(pRuntime, 0, Upper_Leftx);
2133 rcArray.SetElement(pRuntime->GetIsolate(), 1, Upper_Lefty); 2123 rcArray.SetElement(pRuntime, 1, Upper_Lefty);
2134 rcArray.SetElement(pRuntime->GetIsolate(), 2, Lower_Rightx); 2124 rcArray.SetElement(pRuntime, 2, Lower_Rightx);
2135 rcArray.SetElement(pRuntime->GetIsolate(), 3, Lower_Righty); 2125 rcArray.SetElement(pRuntime, 3, Lower_Righty);
2136 vp << rcArray; 2126 vp << rcArray;
2137 } 2127 }
2138 return TRUE; 2128 return TRUE;
2139 } 2129 }
2140 2130
2141 void Field::SetRect(CPDFSDK_Document* pDocument, 2131 void Field::SetRect(CPDFSDK_Document* pDocument,
2142 const CFX_WideString& swFieldName, 2132 const CFX_WideString& swFieldName,
2143 int nControlIndex, 2133 int nControlIndex,
2144 const CFX_FloatRect& rect) { 2134 const CFX_FloatRect& rect) {
2145 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); 2135 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 CFX_WideString& sError) { 2687 CFX_WideString& sError) {
2698 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 2688 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2699 2689
2700 if (vp.IsSetting()) { 2690 if (vp.IsSetting()) {
2701 if (!m_bCanSet) 2691 if (!m_bCanSet)
2702 return FALSE; 2692 return FALSE;
2703 2693
2704 std::vector<CFX_WideString> strArray; 2694 std::vector<CFX_WideString> strArray;
2705 if (vp.GetJSValue()->IsArrayObject()) { 2695 if (vp.GetJSValue()->IsArrayObject()) {
2706 CJS_Array ValueArray; 2696 CJS_Array ValueArray;
2707 vp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), ValueArray); 2697 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
2708 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) { 2698 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
2709 CJS_Value ElementValue(pRuntime); 2699 CJS_Value ElementValue(pRuntime);
2710 ValueArray.GetElement(pRuntime->GetIsolate(), i, ElementValue); 2700 ValueArray.GetElement(pRuntime, i, ElementValue);
2711 strArray.push_back( 2701 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
2712 ElementValue.ToCFXWideString(pRuntime->GetIsolate()));
2713 } 2702 }
2714 } else { 2703 } else {
2715 CFX_WideString swValue; 2704 CFX_WideString swValue;
2716 vp >> swValue; 2705 vp >> swValue;
2717 strArray.push_back(swValue); 2706 strArray.push_back(swValue);
2718 } 2707 }
2719 2708
2720 if (m_bDelay) { 2709 if (m_bDelay) {
2721 AddDelay_WideStringArray(FP_VALUE, strArray); 2710 AddDelay_WideStringArray(FP_VALUE, strArray);
2722 } else { 2711 } else {
(...skipping 14 matching lines...) Expand all
2737 } break; 2726 } break;
2738 case FIELDTYPE_LISTBOX: { 2727 case FIELDTYPE_LISTBOX: {
2739 if (pFormField->CountSelectedItems() > 1) { 2728 if (pFormField->CountSelectedItems() > 1) {
2740 CJS_Array ValueArray; 2729 CJS_Array ValueArray;
2741 CJS_Value ElementValue(pRuntime); 2730 CJS_Value ElementValue(pRuntime);
2742 int iIndex; 2731 int iIndex;
2743 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { 2732 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2744 iIndex = pFormField->GetSelectedIndex(i); 2733 iIndex = pFormField->GetSelectedIndex(i);
2745 ElementValue = 2734 ElementValue =
2746 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str()); 2735 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
2747 if (FXSYS_wcslen( 2736 if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) ==
2748 ElementValue.ToCFXWideString(pRuntime->GetIsolate()) 2737 0) {
2749 .c_str()) == 0) {
2750 ElementValue = CJS_Value( 2738 ElementValue = CJS_Value(
2751 pRuntime, pFormField->GetOptionLabel(iIndex).c_str()); 2739 pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
2752 } 2740 }
2753 ValueArray.SetElement(pRuntime->GetIsolate(), i, ElementValue); 2741 ValueArray.SetElement(pRuntime, i, ElementValue);
2754 } 2742 }
2755 vp << ValueArray; 2743 vp << ValueArray;
2756 } else { 2744 } else {
2757 vp << pFormField->GetValue(); 2745 vp << pFormField->GetValue();
2758 } 2746 }
2759 } break; 2747 } break;
2760 case FIELDTYPE_CHECKBOX: 2748 case FIELDTYPE_CHECKBOX:
2761 case FIELDTYPE_RADIOBUTTON: { 2749 case FIELDTYPE_RADIOBUTTON: {
2762 bool bFind = false; 2750 bool bFind = false;
2763 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 2751 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2764 if (pFormField->GetControl(i)->IsChecked()) { 2752 if (pFormField->GetControl(i)->IsChecked()) {
2765 vp << pFormField->GetControl(i)->GetExportValue(); 2753 vp << pFormField->GetControl(i)->GetExportValue();
2766 bFind = true; 2754 bFind = true;
2767 break; 2755 break;
2768 } 2756 }
2769 } 2757 }
2770 if (!bFind) 2758 if (!bFind)
2771 vp << L"Off"; 2759 vp << L"Off";
2772 } break; 2760 } break;
2773 default: 2761 default:
2774 vp << pFormField->GetValue(); 2762 vp << pFormField->GetValue();
2775 break; 2763 break;
2776 } 2764 }
2777 } 2765 }
2778 vp.GetJSValue()->MaybeCoerceToNumber(m_isolate); 2766 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
2779 return TRUE; 2767 return TRUE;
2780 } 2768 }
2781 2769
2782 void Field::SetValue(CPDFSDK_Document* pDocument, 2770 void Field::SetValue(CPDFSDK_Document* pDocument,
2783 const CFX_WideString& swFieldName, 2771 const CFX_WideString& swFieldName,
2784 int nControlIndex, 2772 int nControlIndex,
2785 const std::vector<CFX_WideString>& strArray) { 2773 const std::vector<CFX_WideString>& strArray) {
2786 ASSERT(pDocument); 2774 ASSERT(pDocument);
2787 if (strArray.empty()) 2775 if (strArray.empty())
2788 return; 2776 return;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 2887
2900 FX_BOOL Field::buttonGetCaption(IJS_Context* cc, 2888 FX_BOOL Field::buttonGetCaption(IJS_Context* cc,
2901 const std::vector<CJS_Value>& params, 2889 const std::vector<CJS_Value>& params,
2902 CJS_Value& vRet, 2890 CJS_Value& vRet,
2903 CFX_WideString& sError) { 2891 CFX_WideString& sError) {
2904 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 2892 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2905 2893
2906 int nface = 0; 2894 int nface = 0;
2907 int iSize = params.size(); 2895 int iSize = params.size();
2908 if (iSize >= 1) 2896 if (iSize >= 1)
2909 nface = params[0].ToInt(pRuntime->GetIsolate()); 2897 nface = params[0].ToInt(pRuntime);
2910 2898
2911 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 2899 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2912 if (FieldArray.empty()) 2900 if (FieldArray.empty())
2913 return FALSE; 2901 return FALSE;
2914 2902
2915 CPDF_FormField* pFormField = FieldArray[0]; 2903 CPDF_FormField* pFormField = FieldArray[0];
2916 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) 2904 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2917 return FALSE; 2905 return FALSE;
2918 2906
2919 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); 2907 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
(...skipping 15 matching lines...) Expand all
2935 FX_BOOL Field::buttonGetIcon(IJS_Context* cc, 2923 FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
2936 const std::vector<CJS_Value>& params, 2924 const std::vector<CJS_Value>& params,
2937 CJS_Value& vRet, 2925 CJS_Value& vRet,
2938 CFX_WideString& sError) { 2926 CFX_WideString& sError) {
2939 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 2927 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
2940 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 2928 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
2941 2929
2942 int nface = 0; 2930 int nface = 0;
2943 int iSize = params.size(); 2931 int iSize = params.size();
2944 if (iSize >= 1) 2932 if (iSize >= 1)
2945 nface = params[0].ToInt(pRuntime->GetIsolate()); 2933 nface = params[0].ToInt(pRuntime);
2946 2934
2947 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 2935 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2948 if (FieldArray.empty()) 2936 if (FieldArray.empty())
2949 return FALSE; 2937 return FALSE;
2950 2938
2951 CPDF_FormField* pFormField = FieldArray[0]; 2939 CPDF_FormField* pFormField = FieldArray[0];
2952 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) 2940 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2953 return FALSE; 2941 return FALSE;
2954 2942
2955 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); 2943 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2956 if (!pFormControl) 2944 if (!pFormControl)
2957 return FALSE; 2945 return FALSE;
2958 2946
2959 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 2947 v8::Local<v8::Object> pObj =
2960 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); 2948 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
2961 ASSERT(pObj.IsEmpty() == FALSE); 2949 ASSERT(pObj.IsEmpty() == FALSE);
2962 2950
2963 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); 2951 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
2964 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); 2952 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
2965 2953
2966 CPDF_Stream* pIconStream = nullptr; 2954 CPDF_Stream* pIconStream = nullptr;
2967 if (nface == 0) 2955 if (nface == 0)
2968 pIconStream = pFormControl->GetNormalIcon(); 2956 pIconStream = pFormControl->GetNormalIcon();
2969 else if (nface == 1) 2957 else if (nface == 1)
2970 pIconStream = pFormControl->GetDownIcon(); 2958 pIconStream = pFormControl->GetDownIcon();
2971 else if (nface == 2) 2959 else if (nface == 2)
2972 pIconStream = pFormControl->GetRolloverIcon(); 2960 pIconStream = pFormControl->GetRolloverIcon();
2973 else 2961 else
(...skipping 30 matching lines...) Expand all
3004 CJS_Value& vRet, 2992 CJS_Value& vRet,
3005 CFX_WideString& sError) { 2993 CFX_WideString& sError) {
3006 int iSize = params.size(); 2994 int iSize = params.size();
3007 if (iSize < 1) 2995 if (iSize < 1)
3008 return FALSE; 2996 return FALSE;
3009 2997
3010 if (!m_bCanSet) 2998 if (!m_bCanSet)
3011 return FALSE; 2999 return FALSE;
3012 3000
3013 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 3001 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
3014 int nWidget = params[0].ToInt(pRuntime->GetIsolate()); 3002 int nWidget = params[0].ToInt(pRuntime);
3015 3003
3016 bool bCheckit = true; 3004 bool bCheckit = true;
3017 if (iSize >= 2) 3005 if (iSize >= 2)
3018 bCheckit = params[1].ToBool(pRuntime->GetIsolate()); 3006 bCheckit = params[1].ToBool(pRuntime);
3019 3007
3020 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 3008 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3021 if (FieldArray.empty()) 3009 if (FieldArray.empty())
3022 return FALSE; 3010 return FALSE;
3023 3011
3024 CPDF_FormField* pFormField = FieldArray[0]; 3012 CPDF_FormField* pFormField = FieldArray[0];
3025 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && 3013 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
3026 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) 3014 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
3027 return FALSE; 3015 return FALSE;
3028 if (nWidget < 0 || nWidget >= pFormField->CountControls()) 3016 if (nWidget < 0 || nWidget >= pFormField->CountControls())
(...skipping 21 matching lines...) Expand all
3050 CJS_Value& vRet, 3038 CJS_Value& vRet,
3051 CFX_WideString& sError) { 3039 CFX_WideString& sError) {
3052 if (!m_bCanSet) 3040 if (!m_bCanSet)
3053 return FALSE; 3041 return FALSE;
3054 3042
3055 int iSize = params.size(); 3043 int iSize = params.size();
3056 if (iSize < 1) 3044 if (iSize < 1)
3057 return FALSE; 3045 return FALSE;
3058 3046
3059 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 3047 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
3060 int nWidget = params[0].ToInt(pRuntime->GetIsolate()); 3048 int nWidget = params[0].ToInt(pRuntime);
3061 3049
3062 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 3050 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3063 if (FieldArray.empty()) 3051 if (FieldArray.empty())
3064 return FALSE; 3052 return FALSE;
3065 3053
3066 CPDF_FormField* pFormField = FieldArray[0]; 3054 CPDF_FormField* pFormField = FieldArray[0];
3067 if (nWidget < 0 || nWidget >= pFormField->CountControls()) 3055 if (nWidget < 0 || nWidget >= pFormField->CountControls())
3068 return FALSE; 3056 return FALSE;
3069 3057
3070 vRet = CJS_Value(pRuntime, 3058 vRet = CJS_Value(pRuntime,
(...skipping 28 matching lines...) Expand all
3099 swSort.begin(), swSort.end(), 3087 swSort.begin(), swSort.end(),
3100 [](const std::unique_ptr<CFX_WideString>& p1, 3088 [](const std::unique_ptr<CFX_WideString>& p1,
3101 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; }); 3089 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
3102 3090
3103 CJS_Context* pContext = (CJS_Context*)cc; 3091 CJS_Context* pContext = (CJS_Context*)cc;
3104 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 3092 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
3105 CJS_Array FormFieldArray; 3093 CJS_Array FormFieldArray;
3106 3094
3107 int j = 0; 3095 int j = 0;
3108 for (const auto& pStr : swSort) { 3096 for (const auto& pStr : swSort) {
3109 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 3097 v8::Local<v8::Object> pObj =
3110 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); 3098 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
3111 ASSERT(!pObj.IsEmpty()); 3099 ASSERT(!pObj.IsEmpty());
3112 3100
3113 CJS_Field* pJSField = 3101 CJS_Field* pJSField =
3114 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj)); 3102 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
3115 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); 3103 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
3116 pField->AttachField(m_pJSDoc, *pStr); 3104 pField->AttachField(m_pJSDoc, *pStr);
3117 FormFieldArray.SetElement(pRuntime->GetIsolate(), j++, 3105 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
3118 CJS_Value(pRuntime, pJSField));
3119 } 3106 }
3120 3107
3121 vRet = CJS_Value(pRuntime, FormFieldArray); 3108 vRet = CJS_Value(pRuntime, FormFieldArray);
3122 return TRUE; 3109 return TRUE;
3123 } 3110 }
3124 3111
3125 FX_BOOL Field::getItemAt(IJS_Context* cc, 3112 FX_BOOL Field::getItemAt(IJS_Context* cc,
3126 const std::vector<CJS_Value>& params, 3113 const std::vector<CJS_Value>& params,
3127 CJS_Value& vRet, 3114 CJS_Value& vRet,
3128 CFX_WideString& sError) { 3115 CFX_WideString& sError) {
3129 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 3116 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
3130 3117
3131 int iSize = params.size(); 3118 int iSize = params.size();
3132 int nIdx = -1; 3119 int nIdx = -1;
3133 if (iSize >= 1) 3120 if (iSize >= 1)
3134 nIdx = params[0].ToInt(pRuntime->GetIsolate()); 3121 nIdx = params[0].ToInt(pRuntime);
3135 3122
3136 FX_BOOL bExport = TRUE; 3123 FX_BOOL bExport = TRUE;
3137 if (iSize >= 2) 3124 if (iSize >= 2)
3138 bExport = params[1].ToBool(pRuntime->GetIsolate()); 3125 bExport = params[1].ToBool(pRuntime);
3139 3126
3140 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 3127 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3141 if (FieldArray.empty()) 3128 if (FieldArray.empty())
3142 return FALSE; 3129 return FALSE;
3143 3130
3144 CPDF_FormField* pFormField = FieldArray[0]; 3131 CPDF_FormField* pFormField = FieldArray[0];
3145 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) || 3132 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3146 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) { 3133 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3147 if (nIdx == -1 || nIdx > pFormField->CountOptions()) 3134 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3148 nIdx = pFormField->CountOptions() - 1; 3135 nIdx = pFormField->CountOptions() - 1;
(...skipping 28 matching lines...) Expand all
3177 } 3164 }
3178 3165
3179 FX_BOOL Field::isBoxChecked(IJS_Context* cc, 3166 FX_BOOL Field::isBoxChecked(IJS_Context* cc,
3180 const std::vector<CJS_Value>& params, 3167 const std::vector<CJS_Value>& params,
3181 CJS_Value& vRet, 3168 CJS_Value& vRet,
3182 CFX_WideString& sError) { 3169 CFX_WideString& sError) {
3183 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 3170 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
3184 3171
3185 int nIndex = -1; 3172 int nIndex = -1;
3186 if (params.size() >= 1) 3173 if (params.size() >= 1)
3187 nIndex = params[0].ToInt(pRuntime->GetIsolate()); 3174 nIndex = params[0].ToInt(pRuntime);
3188 3175
3189 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 3176 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3190 if (FieldArray.empty()) 3177 if (FieldArray.empty())
3191 return FALSE; 3178 return FALSE;
3192 3179
3193 CPDF_FormField* pFormField = FieldArray[0]; 3180 CPDF_FormField* pFormField = FieldArray[0];
3194 if (nIndex < 0 || nIndex >= pFormField->CountControls()) { 3181 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3195 return FALSE; 3182 return FALSE;
3196 } 3183 }
3197 3184
3198 vRet = CJS_Value(pRuntime, 3185 vRet = CJS_Value(pRuntime,
3199 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || 3186 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3200 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) && 3187 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3201 pFormField->GetControl(nIndex)->IsChecked() != 0)); 3188 pFormField->GetControl(nIndex)->IsChecked() != 0));
3202 return TRUE; 3189 return TRUE;
3203 } 3190 }
3204 3191
3205 FX_BOOL Field::isDefaultChecked(IJS_Context* cc, 3192 FX_BOOL Field::isDefaultChecked(IJS_Context* cc,
3206 const std::vector<CJS_Value>& params, 3193 const std::vector<CJS_Value>& params,
3207 CJS_Value& vRet, 3194 CJS_Value& vRet,
3208 CFX_WideString& sError) { 3195 CFX_WideString& sError) {
3209 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 3196 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
3210 3197
3211 int nIndex = -1; 3198 int nIndex = -1;
3212 if (params.size() >= 1) 3199 if (params.size() >= 1)
3213 nIndex = params[0].ToInt(pRuntime->GetIsolate()); 3200 nIndex = params[0].ToInt(pRuntime);
3214 3201
3215 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 3202 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3216 if (FieldArray.empty()) 3203 if (FieldArray.empty())
3217 return FALSE; 3204 return FALSE;
3218 3205
3219 CPDF_FormField* pFormField = FieldArray[0]; 3206 CPDF_FormField* pFormField = FieldArray[0];
3220 if (nIndex < 0 || nIndex >= pFormField->CountControls()) 3207 if (nIndex < 0 || nIndex >= pFormField->CountControls())
3221 return FALSE; 3208 return FALSE;
3222 3209
3223 vRet = CJS_Value(pRuntime, 3210 vRet = CJS_Value(pRuntime,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3541 } 3528 }
3542 } 3529 }
3543 3530
3544 void Field::AddField(CPDFSDK_Document* pDocument, 3531 void Field::AddField(CPDFSDK_Document* pDocument,
3545 int nPageIndex, 3532 int nPageIndex,
3546 int nFieldType, 3533 int nFieldType,
3547 const CFX_WideString& sName, 3534 const CFX_WideString& sName,
3548 const CFX_FloatRect& rcCoords) { 3535 const CFX_FloatRect& rcCoords) {
3549 // Not supported. 3536 // Not supported.
3550 } 3537 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/Field.h ('k') | fpdfsdk/javascript/JS_Define.h » ('j') | fxjs/fxjs_v8.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698