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

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

Issue 2217253002: Remove backpointer to runtime from CJS_Array. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove non-const refs 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
« no previous file with comments | « fpdfsdk/javascript/Document.cpp ('k') | fpdfsdk/javascript/JS_Value.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 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 if (vp.IsSetting()) { 953 if (vp.IsSetting()) {
954 if (!m_bCanSet) 954 if (!m_bCanSet)
955 return FALSE; 955 return FALSE;
956 956
957 std::vector<uint32_t> array; 957 std::vector<uint32_t> array;
958 if (vp.GetType() == CJS_Value::VT_number) { 958 if (vp.GetType() == CJS_Value::VT_number) {
959 int iSelecting = 0; 959 int iSelecting = 0;
960 vp >> iSelecting; 960 vp >> iSelecting;
961 array.push_back(iSelecting); 961 array.push_back(iSelecting);
962 } else if (vp.IsArrayObject()) { 962 } else if (vp.IsArrayObject()) {
963 CJS_Array SelArray(pRuntime); 963 CJS_Array SelArray;
964 CJS_Value SelValue(pRuntime); 964 CJS_Value SelValue(pRuntime);
965 int iSelecting; 965 int iSelecting;
966 vp >> SelArray; 966 vp >> SelArray;
967 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) { 967 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
968 SelArray.GetElement(i, SelValue); 968 SelArray.GetElement(pRuntime->GetIsolate(), i, SelValue);
969 iSelecting = SelValue.ToInt(); 969 iSelecting = SelValue.ToInt();
970 array.push_back(iSelecting); 970 array.push_back(iSelecting);
971 } 971 }
972 } 972 }
973 973
974 if (m_bDelay) { 974 if (m_bDelay) {
975 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); 975 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
976 } else { 976 } else {
977 Field::SetCurrentValueIndices(m_pDocument, m_FieldName, 977 Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
978 m_nFormControlIndex, array); 978 m_nFormControlIndex, array);
979 } 979 }
980 } else { 980 } else {
981 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 981 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
982 if (FieldArray.empty()) 982 if (FieldArray.empty())
983 return FALSE; 983 return FALSE;
984 984
985 CPDF_FormField* pFormField = FieldArray[0]; 985 CPDF_FormField* pFormField = FieldArray[0];
986 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && 986 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
987 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { 987 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
988 return FALSE; 988 return FALSE;
989 } 989 }
990 990
991 if (pFormField->CountSelectedItems() == 1) { 991 if (pFormField->CountSelectedItems() == 1) {
992 vp << pFormField->GetSelectedIndex(0); 992 vp << pFormField->GetSelectedIndex(0);
993 } else if (pFormField->CountSelectedItems() > 1) { 993 } else if (pFormField->CountSelectedItems() > 1) {
994 CJS_Array SelArray(pRuntime); 994 CJS_Array SelArray;
995 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { 995 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
996 SelArray.SetElement( 996 SelArray.SetElement(
997 i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); 997 pRuntime->GetIsolate(), i,
998 CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
998 } 999 }
999 vp << SelArray; 1000 vp << SelArray;
1000 } else { 1001 } else {
1001 vp << -1; 1002 vp << -1;
1002 } 1003 }
1003 } 1004 }
1004 1005
1005 return TRUE; 1006 return TRUE;
1006 } 1007 }
1007 1008
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 } 1372 }
1372 1373
1373 if (vp.IsSetting()) { 1374 if (vp.IsSetting()) {
1374 if (!m_bCanSet) 1375 if (!m_bCanSet)
1375 return FALSE; 1376 return FALSE;
1376 1377
1377 if (!vp.IsArrayObject()) 1378 if (!vp.IsArrayObject())
1378 return FALSE; 1379 return FALSE;
1379 } else { 1380 } else {
1380 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1381 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1381 CJS_Array ExportValusArray(pRuntime); 1382 CJS_Array ExportValusArray;
1382 if (m_nFormControlIndex < 0) { 1383 if (m_nFormControlIndex < 0) {
1383 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 1384 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1384 CPDF_FormControl* pFormControl = pFormField->GetControl(i); 1385 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1385 ExportValusArray.SetElement( 1386 ExportValusArray.SetElement(
1386 i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); 1387 pRuntime->GetIsolate(), i,
1388 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
1387 } 1389 }
1388 } else { 1390 } else {
1389 if (m_nFormControlIndex >= pFormField->CountControls()) 1391 if (m_nFormControlIndex >= pFormField->CountControls())
1390 return FALSE; 1392 return FALSE;
1391 1393
1392 CPDF_FormControl* pFormControl = 1394 CPDF_FormControl* pFormControl =
1393 pFormField->GetControl(m_nFormControlIndex); 1395 pFormField->GetControl(m_nFormControlIndex);
1394 if (!pFormControl) 1396 if (!pFormControl)
1395 return FALSE; 1397 return FALSE;
1396 1398
1397 ExportValusArray.SetElement( 1399 ExportValusArray.SetElement(
1398 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); 1400 pRuntime->GetIsolate(), 0,
1401 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
1399 } 1402 }
1400 vp << ExportValusArray; 1403 vp << ExportValusArray;
1401 } 1404 }
1402 return TRUE; 1405 return TRUE;
1403 } 1406 }
1404 1407
1405 FX_BOOL Field::fileSelect(IJS_Context* cc, 1408 FX_BOOL Field::fileSelect(IJS_Context* cc,
1406 CJS_PropValue& vp, 1409 CJS_PropValue& vp,
1407 CFX_WideString& sError) { 1410 CFX_WideString& sError) {
1408 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 1411 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
(...skipping 16 matching lines...) Expand all
1425 else 1428 else
1426 vp << false; 1429 vp << false;
1427 } 1430 }
1428 return TRUE; 1431 return TRUE;
1429 } 1432 }
1430 1433
1431 FX_BOOL Field::fillColor(IJS_Context* cc, 1434 FX_BOOL Field::fillColor(IJS_Context* cc,
1432 CJS_PropValue& vp, 1435 CJS_PropValue& vp,
1433 CFX_WideString& sError) { 1436 CFX_WideString& sError) {
1434 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1437 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1435 CJS_Array crArray(pRuntime); 1438 CJS_Array crArray;
1436 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 1439 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1437 if (FieldArray.empty()) 1440 if (FieldArray.empty())
1438 return FALSE; 1441 return FALSE;
1439 1442
1440 if (vp.IsSetting()) { 1443 if (vp.IsSetting()) {
1441 if (!m_bCanSet) 1444 if (!m_bCanSet)
1442 return FALSE; 1445 return FALSE;
1443 1446
1444 if (!vp.IsArrayObject()) 1447 if (!vp.IsArrayObject())
1445 return FALSE; 1448 return FALSE;
1446 1449
1447 vp >> crArray; 1450 vp >> crArray;
1448 1451
1449 CPWL_Color color; 1452 CPWL_Color color;
1450 color::ConvertArrayToPWLColor(crArray, color); 1453 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
1451 if (m_bDelay) { 1454 if (m_bDelay) {
1452 AddDelay_Color(FP_FILLCOLOR, color); 1455 AddDelay_Color(FP_FILLCOLOR, color);
1453 } else { 1456 } else {
1454 Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color); 1457 Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
1455 } 1458 }
1456 } else { 1459 } else {
1457 CPDF_FormField* pFormField = FieldArray[0]; 1460 CPDF_FormField* pFormField = FieldArray[0];
1458 ASSERT(pFormField); 1461 ASSERT(pFormField);
1459 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); 1462 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1460 if (!pFormControl) 1463 if (!pFormControl)
(...skipping 16 matching lines...) Expand all
1477 } else if (iColorType == COLORTYPE_CMYK) { 1480 } else if (iColorType == COLORTYPE_CMYK) {
1478 color = CPWL_Color(COLORTYPE_CMYK, 1481 color = CPWL_Color(COLORTYPE_CMYK,
1479 pFormControl->GetOriginalBackgroundColor(0), 1482 pFormControl->GetOriginalBackgroundColor(0),
1480 pFormControl->GetOriginalBackgroundColor(1), 1483 pFormControl->GetOriginalBackgroundColor(1),
1481 pFormControl->GetOriginalBackgroundColor(2), 1484 pFormControl->GetOriginalBackgroundColor(2),
1482 pFormControl->GetOriginalBackgroundColor(3)); 1485 pFormControl->GetOriginalBackgroundColor(3));
1483 } else { 1486 } else {
1484 return FALSE; 1487 return FALSE;
1485 } 1488 }
1486 1489
1487 color::ConvertPWLColorToArray(color, crArray); 1490 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
1488 vp << crArray; 1491 vp << crArray;
1489 } 1492 }
1490 1493
1491 return TRUE; 1494 return TRUE;
1492 } 1495 }
1493 1496
1494 void Field::SetFillColor(CPDFSDK_Document* pDocument, 1497 void Field::SetFillColor(CPDFSDK_Document* pDocument,
1495 const CFX_WideString& swFieldName, 1498 const CFX_WideString& swFieldName,
1496 int nControlIndex, 1499 int nControlIndex,
1497 const CPWL_Color& color) { 1500 const CPWL_Color& color) {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 1881
1879 std::vector<CPDFSDK_Widget*> widgets; 1882 std::vector<CPDFSDK_Widget*> widgets;
1880 m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets); 1883 m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets);
1881 1884
1882 if (widgets.empty()) { 1885 if (widgets.empty()) {
1883 vp << (int32_t)-1; 1886 vp << (int32_t)-1;
1884 return TRUE; 1887 return TRUE;
1885 } 1888 }
1886 1889
1887 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1890 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1888 CJS_Array PageArray(pRuntime); 1891 CJS_Array PageArray;
1889 for (size_t i = 0; i < widgets.size(); ++i) { 1892 for (size_t i = 0; i < widgets.size(); ++i) {
1890 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); 1893 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1891 if (!pPageView) 1894 if (!pPageView)
1892 return FALSE; 1895 return FALSE;
1893 1896
1894 PageArray.SetElement( 1897 PageArray.SetElement(
1895 i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); 1898 pRuntime->GetIsolate(), i,
1899 CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1896 } 1900 }
1897 1901
1898 vp << PageArray; 1902 vp << PageArray;
1899 return TRUE; 1903 return TRUE;
1900 } 1904 }
1901 1905
1902 FX_BOOL Field::password(IJS_Context* cc, 1906 FX_BOOL Field::password(IJS_Context* cc,
1903 CJS_PropValue& vp, 1907 CJS_PropValue& vp,
1904 CFX_WideString& sError) { 1908 CFX_WideString& sError) {
1905 ASSERT(m_pDocument); 1909 ASSERT(m_pDocument);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 CJS_Value Upper_Lefty(pRuntime); 2080 CJS_Value Upper_Lefty(pRuntime);
2077 CJS_Value Lower_Rightx(pRuntime); 2081 CJS_Value Lower_Rightx(pRuntime);
2078 CJS_Value Lower_Righty(pRuntime); 2082 CJS_Value Lower_Righty(pRuntime);
2079 2083
2080 if (vp.IsSetting()) { 2084 if (vp.IsSetting()) {
2081 if (!m_bCanSet) 2085 if (!m_bCanSet)
2082 return FALSE; 2086 return FALSE;
2083 if (!vp.IsArrayObject()) 2087 if (!vp.IsArrayObject())
2084 return FALSE; 2088 return FALSE;
2085 2089
2086 CJS_Array rcArray(pRuntime); 2090 CJS_Array rcArray;
2087 vp >> rcArray; 2091 vp >> rcArray;
2088 rcArray.GetElement(0, Upper_Leftx); 2092 rcArray.GetElement(pRuntime->GetIsolate(), 0, Upper_Leftx);
2089 rcArray.GetElement(1, Upper_Lefty); 2093 rcArray.GetElement(pRuntime->GetIsolate(), 1, Upper_Lefty);
2090 rcArray.GetElement(2, Lower_Rightx); 2094 rcArray.GetElement(pRuntime->GetIsolate(), 2, Lower_Rightx);
2091 rcArray.GetElement(3, Lower_Righty); 2095 rcArray.GetElement(pRuntime->GetIsolate(), 3, Lower_Righty);
2092 2096
2093 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f}; 2097 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2094 pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt(); 2098 pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
2095 pArray[1] = (FX_FLOAT)Lower_Righty.ToInt(); 2099 pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
2096 pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt(); 2100 pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
2097 pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt(); 2101 pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
2098 2102
2099 CFX_FloatRect crRect(pArray); 2103 CFX_FloatRect crRect(pArray);
2100 if (m_bDelay) { 2104 if (m_bDelay) {
2101 AddDelay_Rect(FP_RECT, crRect); 2105 AddDelay_Rect(FP_RECT, crRect);
(...skipping 11 matching lines...) Expand all
2113 pInterForm->GetWidget(GetSmartFieldControl(pFormField)); 2117 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2114 if (!pWidget) 2118 if (!pWidget)
2115 return FALSE; 2119 return FALSE;
2116 2120
2117 CFX_FloatRect crRect = pWidget->GetRect(); 2121 CFX_FloatRect crRect = pWidget->GetRect();
2118 Upper_Leftx = (int32_t)crRect.left; 2122 Upper_Leftx = (int32_t)crRect.left;
2119 Upper_Lefty = (int32_t)crRect.top; 2123 Upper_Lefty = (int32_t)crRect.top;
2120 Lower_Rightx = (int32_t)crRect.right; 2124 Lower_Rightx = (int32_t)crRect.right;
2121 Lower_Righty = (int32_t)crRect.bottom; 2125 Lower_Righty = (int32_t)crRect.bottom;
2122 2126
2123 CJS_Array rcArray(pRuntime); 2127 CJS_Array rcArray;
2124 rcArray.SetElement(0, Upper_Leftx); 2128 rcArray.SetElement(pRuntime->GetIsolate(), 0, Upper_Leftx);
2125 rcArray.SetElement(1, Upper_Lefty); 2129 rcArray.SetElement(pRuntime->GetIsolate(), 1, Upper_Lefty);
2126 rcArray.SetElement(2, Lower_Rightx); 2130 rcArray.SetElement(pRuntime->GetIsolate(), 2, Lower_Rightx);
2127 rcArray.SetElement(3, Lower_Righty); 2131 rcArray.SetElement(pRuntime->GetIsolate(), 3, Lower_Righty);
2128 vp << rcArray; 2132 vp << rcArray;
2129 } 2133 }
2130 return TRUE; 2134 return TRUE;
2131 } 2135 }
2132 2136
2133 void Field::SetRect(CPDFSDK_Document* pDocument, 2137 void Field::SetRect(CPDFSDK_Document* pDocument,
2134 const CFX_WideString& swFieldName, 2138 const CFX_WideString& swFieldName,
2135 int nControlIndex, 2139 int nControlIndex,
2136 const CFX_FloatRect& rect) { 2140 const CFX_FloatRect& rect) {
2137 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); 2141 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 const CFX_WideString& swFieldName, 2296 const CFX_WideString& swFieldName,
2293 int nControlIndex, 2297 int nControlIndex,
2294 int number) { 2298 int number) {
2295 // Not supported. 2299 // Not supported.
2296 } 2300 }
2297 2301
2298 FX_BOOL Field::strokeColor(IJS_Context* cc, 2302 FX_BOOL Field::strokeColor(IJS_Context* cc,
2299 CJS_PropValue& vp, 2303 CJS_PropValue& vp,
2300 CFX_WideString& sError) { 2304 CFX_WideString& sError) {
2301 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 2305 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2302 CJS_Array crArray(pRuntime); 2306 CJS_Array crArray;
2303 2307
2304 if (vp.IsSetting()) { 2308 if (vp.IsSetting()) {
2305 if (!m_bCanSet) 2309 if (!m_bCanSet)
2306 return FALSE; 2310 return FALSE;
2307 2311
2308 if (!vp.IsArrayObject()) 2312 if (!vp.IsArrayObject())
2309 return FALSE; 2313 return FALSE;
2310 2314
2311 vp >> crArray; 2315 vp >> crArray;
2312 2316
2313 CPWL_Color color; 2317 CPWL_Color color;
2314 color::ConvertArrayToPWLColor(crArray, color); 2318 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
2315 2319
2316 if (m_bDelay) { 2320 if (m_bDelay) {
2317 AddDelay_Color(FP_STROKECOLOR, color); 2321 AddDelay_Color(FP_STROKECOLOR, color);
2318 } else { 2322 } else {
2319 Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, 2323 Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex,
2320 color); 2324 color);
2321 } 2325 }
2322 } else { 2326 } else {
2323 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 2327 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2324 if (FieldArray.empty()) 2328 if (FieldArray.empty())
(...skipping 20 matching lines...) Expand all
2345 } else if (iColorType == COLORTYPE_CMYK) { 2349 } else if (iColorType == COLORTYPE_CMYK) {
2346 color = 2350 color =
2347 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0), 2351 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2348 pFormControl->GetOriginalBorderColor(1), 2352 pFormControl->GetOriginalBorderColor(1),
2349 pFormControl->GetOriginalBorderColor(2), 2353 pFormControl->GetOriginalBorderColor(2),
2350 pFormControl->GetOriginalBorderColor(3)); 2354 pFormControl->GetOriginalBorderColor(3));
2351 } else { 2355 } else {
2352 return FALSE; 2356 return FALSE;
2353 } 2357 }
2354 2358
2355 color::ConvertPWLColorToArray(color, crArray); 2359 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
2356 vp << crArray; 2360 vp << crArray;
2357 } 2361 }
2358 return TRUE; 2362 return TRUE;
2359 } 2363 }
2360 2364
2361 void Field::SetStrokeColor(CPDFSDK_Document* pDocument, 2365 void Field::SetStrokeColor(CPDFSDK_Document* pDocument,
2362 const CFX_WideString& swFieldName, 2366 const CFX_WideString& swFieldName,
2363 int nControlIndex, 2367 int nControlIndex,
2364 const CPWL_Color& color) { 2368 const CPWL_Color& color) {
2365 // Not supported. 2369 // Not supported.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 FX_BOOL Field::submitName(IJS_Context* cc, 2441 FX_BOOL Field::submitName(IJS_Context* cc,
2438 CJS_PropValue& vp, 2442 CJS_PropValue& vp,
2439 CFX_WideString& sError) { 2443 CFX_WideString& sError) {
2440 return TRUE; 2444 return TRUE;
2441 } 2445 }
2442 2446
2443 FX_BOOL Field::textColor(IJS_Context* cc, 2447 FX_BOOL Field::textColor(IJS_Context* cc,
2444 CJS_PropValue& vp, 2448 CJS_PropValue& vp,
2445 CFX_WideString& sError) { 2449 CFX_WideString& sError) {
2446 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 2450 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2447 CJS_Array crArray(pRuntime); 2451 CJS_Array crArray;
2448 2452
2449 if (vp.IsSetting()) { 2453 if (vp.IsSetting()) {
2450 if (!m_bCanSet) 2454 if (!m_bCanSet)
2451 return FALSE; 2455 return FALSE;
2452 2456
2453 if (!vp.IsArrayObject()) 2457 if (!vp.IsArrayObject())
2454 return FALSE; 2458 return FALSE;
2455 2459
2456 vp >> crArray; 2460 vp >> crArray;
2457 2461
2458 CPWL_Color color; 2462 CPWL_Color color;
2459 color::ConvertArrayToPWLColor(crArray, color); 2463 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
2460 2464
2461 if (m_bDelay) { 2465 if (m_bDelay) {
2462 AddDelay_Color(FP_TEXTCOLOR, color); 2466 AddDelay_Color(FP_TEXTCOLOR, color);
2463 } else { 2467 } else {
2464 Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color); 2468 Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2465 } 2469 }
2466 } else { 2470 } else {
2467 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 2471 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2468 if (FieldArray.empty()) 2472 if (FieldArray.empty())
2469 return FALSE; 2473 return FALSE;
(...skipping 10 matching lines...) Expand all
2480 FieldAppearance.GetColor(color, iColorType); 2484 FieldAppearance.GetColor(color, iColorType);
2481 int32_t a, r, g, b; 2485 int32_t a, r, g, b;
2482 ArgbDecode(color, a, r, g, b); 2486 ArgbDecode(color, a, r, g, b);
2483 2487
2484 CPWL_Color crRet = 2488 CPWL_Color crRet =
2485 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f); 2489 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2486 2490
2487 if (iColorType == COLORTYPE_TRANSPARENT) 2491 if (iColorType == COLORTYPE_TRANSPARENT)
2488 crRet = CPWL_Color(COLORTYPE_TRANSPARENT); 2492 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2489 2493
2490 color::ConvertPWLColorToArray(crRet, crArray); 2494 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
2491 vp << crArray; 2495 vp << crArray;
2492 } 2496 }
2493 return TRUE; 2497 return TRUE;
2494 } 2498 }
2495 2499
2496 void Field::SetTextColor(CPDFSDK_Document* pDocument, 2500 void Field::SetTextColor(CPDFSDK_Document* pDocument,
2497 const CFX_WideString& swFieldName, 2501 const CFX_WideString& swFieldName,
2498 int nControlIndex, 2502 int nControlIndex,
2499 const CPWL_Color& color) { 2503 const CPWL_Color& color) {
2500 // Not supported. 2504 // Not supported.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 CJS_PropValue& vp, 2692 CJS_PropValue& vp,
2689 CFX_WideString& sError) { 2693 CFX_WideString& sError) {
2690 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 2694 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2691 2695
2692 if (vp.IsSetting()) { 2696 if (vp.IsSetting()) {
2693 if (!m_bCanSet) 2697 if (!m_bCanSet)
2694 return FALSE; 2698 return FALSE;
2695 2699
2696 std::vector<CFX_WideString> strArray; 2700 std::vector<CFX_WideString> strArray;
2697 if (vp.IsArrayObject()) { 2701 if (vp.IsArrayObject()) {
2698 CJS_Array ValueArray(pRuntime); 2702 CJS_Array ValueArray;
2699 vp.ConvertToArray(ValueArray); 2703 vp.ConvertToArray(ValueArray);
2700 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) { 2704 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
2701 CJS_Value ElementValue(pRuntime); 2705 CJS_Value ElementValue(pRuntime);
2702 ValueArray.GetElement(i, ElementValue); 2706 ValueArray.GetElement(pRuntime->GetIsolate(), i, ElementValue);
2703 strArray.push_back(ElementValue.ToCFXWideString()); 2707 strArray.push_back(ElementValue.ToCFXWideString());
2704 } 2708 }
2705 } else { 2709 } else {
2706 CFX_WideString swValue; 2710 CFX_WideString swValue;
2707 vp >> swValue; 2711 vp >> swValue;
2708 strArray.push_back(swValue); 2712 strArray.push_back(swValue);
2709 } 2713 }
2710 2714
2711 if (m_bDelay) { 2715 if (m_bDelay) {
2712 AddDelay_WideStringArray(FP_VALUE, strArray); 2716 AddDelay_WideStringArray(FP_VALUE, strArray);
2713 } else { 2717 } else {
2714 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray); 2718 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
2715 } 2719 }
2716 } else { 2720 } else {
2717 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 2721 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2718 if (FieldArray.empty()) 2722 if (FieldArray.empty())
2719 return FALSE; 2723 return FALSE;
2720 2724
2721 CPDF_FormField* pFormField = FieldArray[0]; 2725 CPDF_FormField* pFormField = FieldArray[0];
2722 switch (pFormField->GetFieldType()) { 2726 switch (pFormField->GetFieldType()) {
2723 case FIELDTYPE_PUSHBUTTON: 2727 case FIELDTYPE_PUSHBUTTON:
2724 return FALSE; 2728 return FALSE;
2725 case FIELDTYPE_COMBOBOX: 2729 case FIELDTYPE_COMBOBOX:
2726 case FIELDTYPE_TEXTFIELD: { 2730 case FIELDTYPE_TEXTFIELD: {
2727 vp << pFormField->GetValue(); 2731 vp << pFormField->GetValue();
2728 } break; 2732 } break;
2729 case FIELDTYPE_LISTBOX: { 2733 case FIELDTYPE_LISTBOX: {
2730 if (pFormField->CountSelectedItems() > 1) { 2734 if (pFormField->CountSelectedItems() > 1) {
2731 CJS_Array ValueArray(pRuntime); 2735 CJS_Array ValueArray;
2732 CJS_Value ElementValue(pRuntime); 2736 CJS_Value ElementValue(pRuntime);
2733 int iIndex; 2737 int iIndex;
2734 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { 2738 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2735 iIndex = pFormField->GetSelectedIndex(i); 2739 iIndex = pFormField->GetSelectedIndex(i);
2736 ElementValue = pFormField->GetOptionValue(iIndex).c_str(); 2740 ElementValue = pFormField->GetOptionValue(iIndex).c_str();
2737 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0) 2741 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
2738 ElementValue = pFormField->GetOptionLabel(iIndex).c_str(); 2742 ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
2739 ValueArray.SetElement(i, ElementValue); 2743 ValueArray.SetElement(pRuntime->GetIsolate(), i, ElementValue);
2740 } 2744 }
2741 vp << ValueArray; 2745 vp << ValueArray;
2742 } else { 2746 } else {
2743 vp << pFormField->GetValue(); 2747 vp << pFormField->GetValue();
2744 } 2748 }
2745 } break; 2749 } break;
2746 case FIELDTYPE_CHECKBOX: 2750 case FIELDTYPE_CHECKBOX:
2747 case FIELDTYPE_RADIOBUTTON: { 2751 case FIELDTYPE_RADIOBUTTON: {
2748 bool bFind = false; 2752 bool bFind = false;
2749 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 2753 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
3079 new CFX_WideString(pFormField->GetFullName()))); 3083 new CFX_WideString(pFormField->GetFullName())));
3080 } 3084 }
3081 3085
3082 std::sort( 3086 std::sort(
3083 swSort.begin(), swSort.end(), 3087 swSort.begin(), swSort.end(),
3084 [](const std::unique_ptr<CFX_WideString>& p1, 3088 [](const std::unique_ptr<CFX_WideString>& p1,
3085 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; }); 3089 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
3086 3090
3087 CJS_Context* pContext = (CJS_Context*)cc; 3091 CJS_Context* pContext = (CJS_Context*)cc;
3088 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 3092 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
3089 CJS_Array FormFieldArray(pRuntime); 3093 CJS_Array FormFieldArray;
3090 3094
3091 int j = 0; 3095 int j = 0;
3092 for (const auto& pStr : swSort) { 3096 for (const auto& pStr : swSort) {
3093 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 3097 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
3094 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); 3098 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
3095 ASSERT(!pObj.IsEmpty()); 3099 ASSERT(!pObj.IsEmpty());
3096 3100
3097 CJS_Field* pJSField = 3101 CJS_Field* pJSField =
3098 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj)); 3102 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj));
3099 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); 3103 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
3100 pField->AttachField(m_pJSDoc, *pStr); 3104 pField->AttachField(m_pJSDoc, *pStr);
3101 3105
3102 CJS_Value FormFieldValue(pRuntime); 3106 CJS_Value FormFieldValue(pRuntime);
3103 FormFieldValue = pJSField; 3107 FormFieldValue = pJSField;
3104 FormFieldArray.SetElement(j++, FormFieldValue); 3108 FormFieldArray.SetElement(pRuntime->GetIsolate(), j++, FormFieldValue);
3105 } 3109 }
3106 3110
3107 vRet = FormFieldArray; 3111 vRet = CJS_Value(pRuntime, FormFieldArray);
3108 return TRUE; 3112 return TRUE;
3109 } 3113 }
3110 3114
3111 FX_BOOL Field::getItemAt(IJS_Context* cc, 3115 FX_BOOL Field::getItemAt(IJS_Context* cc,
3112 const std::vector<CJS_Value>& params, 3116 const std::vector<CJS_Value>& params,
3113 CJS_Value& vRet, 3117 CJS_Value& vRet,
3114 CFX_WideString& sError) { 3118 CFX_WideString& sError) {
3115 int iSize = params.size(); 3119 int iSize = params.size();
3116 3120
3117 int nIdx = -1; 3121 int nIdx = -1;
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
3536 } 3540 }
3537 } 3541 }
3538 3542
3539 void Field::AddField(CPDFSDK_Document* pDocument, 3543 void Field::AddField(CPDFSDK_Document* pDocument,
3540 int nPageIndex, 3544 int nPageIndex,
3541 int nFieldType, 3545 int nFieldType,
3542 const CFX_WideString& sName, 3546 const CFX_WideString& sName,
3543 const CFX_FloatRect& rcCoords) { 3547 const CFX_FloatRect& rcCoords) {
3544 // Not supported. 3548 // Not supported.
3545 } 3549 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/Document.cpp ('k') | fpdfsdk/javascript/JS_Value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698