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

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

Issue 1394103002: Wean CJS_Value off of v8::Isolate. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 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 "PublicMethods.h" 7 #include "PublicMethods.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"
11 #include "Field.h" 11 #include "Field.h"
12 #include "JS_Context.h" 12 #include "JS_Context.h"
13 #include "JS_Define.h" 13 #include "JS_Define.h"
14 #include "JS_EventHandler.h" 14 #include "JS_EventHandler.h"
15 #include "JS_Object.h" 15 #include "JS_Object.h"
16 #include "JS_Runtime.h" 16 #include "JS_Runtime.h"
17 #include "JS_Value.h" 17 #include "JS_Value.h"
18 #include "color.h" 18 #include "color.h"
19 #include "resource.h" 19 #include "resource.h"
20 #include "util.h" 20 #include "util.h"
21 21
22 static v8::Isolate* GetIsolate(IJS_Context* cc) {
23 CJS_Context* pContext = (CJS_Context*)cc;
24 ASSERT(pContext != NULL);
25
26 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
27 ASSERT(pRuntime != NULL);
28
29 return pRuntime->GetIsolate();
30 }
31
32 /* -------------------------------- CJS_PublicMethods
33 * -------------------------------- */
34
35 #define DOUBLE_CORRECT 0.000000000000001 22 #define DOUBLE_CORRECT 0.000000000000001
36 23
37 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) 24 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
38 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) 25 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format)
39 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) 26 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke)
40 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) 27 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format)
41 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke) 28 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke)
42 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx) 29 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx)
43 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx) 30 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx)
44 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format) 31 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format)
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 FX_BOOL& bDot) { 326 FX_BOOL& bDot) {
340 FX_BOOL bAllDigits = FALSE; 327 FX_BOOL bAllDigits = FALSE;
341 FX_BOOL bSign = FALSE; 328 FX_BOOL bSign = FALSE;
342 FX_BOOL bKXJS = FALSE; 329 FX_BOOL bKXJS = FALSE;
343 330
344 dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); 331 dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
345 332
346 return bAllDigits; 333 return bAllDigits;
347 } 334 }
348 335
349 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, 336 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
350 CJS_Value val) { 337 CJS_Value val) {
351 CJS_Array StrArray(isolate); 338 CJS_Array StrArray(pRuntime);
352 if (val.IsArrayObject()) { 339 if (val.IsArrayObject()) {
353 val.ConvertToArray(StrArray); 340 val.ConvertToArray(StrArray);
354 return StrArray; 341 return StrArray;
355 } 342 }
356 CFX_WideString wsStr = val.ToCFXWideString(); 343 CFX_WideString wsStr = val.ToCFXWideString();
357 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); 344 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
358 const char* p = (const char*)t; 345 const char* p = (const char*)t;
359 346
360 int ch = ','; 347 int ch = ',';
361 int nIndex = 0; 348 int nIndex = 0;
362 349
363 while (*p) { 350 while (*p) {
364 const char* pTemp = strchr(p, ch); 351 const char* pTemp = strchr(p, ch);
365 if (pTemp == NULL) { 352 if (pTemp == NULL) {
366 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str())); 353 StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(p).c_str()));
367 break; 354 break;
368 } else { 355 } else {
369 char* pSub = new char[pTemp - p + 1]; 356 char* pSub = new char[pTemp - p + 1];
370 strncpy(pSub, p, pTemp - p); 357 strncpy(pSub, p, pTemp - p);
371 *(pSub + (pTemp - p)) = '\0'; 358 *(pSub + (pTemp - p)) = '\0';
372 359
373 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str())); 360 StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str()));
374 delete[] pSub; 361 delete[] pSub;
375 362
376 nIndex++; 363 nIndex++;
377 p = ++pTemp; 364 p = ++pTemp;
378 } 365 }
379 } 366 }
380 return StrArray; 367 return StrArray;
381 } 368 }
382 369
383 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string, 370 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 891
905 /* -------------------------------------------------------------------------- */ 892 /* -------------------------------------------------------------------------- */
906 893
907 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, 894 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency,
908 // bCurrencyPrepend) 895 // bCurrencyPrepend)
909 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, 896 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
910 const CJS_Parameters& params, 897 const CJS_Parameters& params,
911 CJS_Value& vRet, 898 CJS_Value& vRet,
912 CFX_WideString& sError) { 899 CFX_WideString& sError) {
913 #if _FX_OS_ != _FX_ANDROID_ 900 #if _FX_OS_ != _FX_ANDROID_
914 v8::Isolate* isolate = ::GetIsolate(cc);
915 CJS_Context* pContext = (CJS_Context*)cc; 901 CJS_Context* pContext = (CJS_Context*)cc;
916 ASSERT(pContext != NULL);
917 CJS_EventHandler* pEvent = pContext->GetEventHandler();
918 ASSERT(pEvent != NULL);
919
920 if (params.size() != 6) { 902 if (params.size() != 6) {
921 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 903 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
922 return FALSE; 904 return FALSE;
923 } 905 }
906
907 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
908 CJS_EventHandler* pEvent = pContext->GetEventHandler();
924 if (!pEvent->m_pValue) 909 if (!pEvent->m_pValue)
925 return FALSE; 910 return FALSE;
911
926 CFX_WideString& Value = pEvent->Value(); 912 CFX_WideString& Value = pEvent->Value();
927 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); 913 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
928
929 if (strValue.IsEmpty()) 914 if (strValue.IsEmpty())
930 return TRUE; 915 return TRUE;
931 916
932 int iDec = params[0].ToInt(); 917 int iDec = params[0].ToInt();
933 int iSepStyle = params[1].ToInt(); 918 int iSepStyle = params[1].ToInt();
934 int iNegStyle = params[2].ToInt(); 919 int iNegStyle = params[2].ToInt();
935 // params[3] is iCurrStyle, it's not used. 920 // params[3] is iCurrStyle, it's not used.
936 std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); 921 std::wstring wstrCurrency(params[4].ToCFXWideString().c_str());
937 FX_BOOL bCurrencyPrepend = params[5].ToBool(); 922 FX_BOOL bCurrencyPrepend = params[5].ToBool();
938 923
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 if (iNegative) { 1009 if (iNegative) {
1025 if (iNegStyle == 0) { 1010 if (iNegStyle == 0) {
1026 strValue2.insert(0, L"-"); 1011 strValue2.insert(0, L"-");
1027 } 1012 }
1028 if (iNegStyle == 2 || iNegStyle == 3) { 1013 if (iNegStyle == 2 || iNegStyle == 3) {
1029 strValue2.insert(0, L"("); 1014 strValue2.insert(0, L"(");
1030 strValue2.insert(strValue2.length(), L")"); 1015 strValue2.insert(strValue2.length(), L")");
1031 } 1016 }
1032 if (iNegStyle == 1 || iNegStyle == 3) { 1017 if (iNegStyle == 1 || iNegStyle == 3) {
1033 if (Field* fTarget = pEvent->Target_Field()) { 1018 if (Field* fTarget = pEvent->Target_Field()) {
1034 CJS_Array arColor(isolate); 1019 CJS_Array arColor(pRuntime);
1035 CJS_Value vColElm(isolate); 1020 CJS_Value vColElm(pRuntime);
1036 vColElm = L"RGB"; 1021 vColElm = L"RGB";
1037 arColor.SetElement(0, vColElm); 1022 arColor.SetElement(0, vColElm);
1038 vColElm = 1; 1023 vColElm = 1;
1039 arColor.SetElement(1, vColElm); 1024 arColor.SetElement(1, vColElm);
1040 vColElm = 0; 1025 vColElm = 0;
1041 arColor.SetElement(2, vColElm); 1026 arColor.SetElement(2, vColElm);
1042 1027
1043 arColor.SetElement(3, vColElm); 1028 arColor.SetElement(3, vColElm);
1044 1029
1045 CJS_PropValue vProp(isolate); 1030 CJS_PropValue vProp(pRuntime);
1046 vProp.StartGetting(); 1031 vProp.StartGetting();
1047 vProp << arColor; 1032 vProp << arColor;
1048 vProp.StartSetting(); 1033 vProp.StartSetting();
1049 fTarget->textColor(cc, vProp, sError); // red 1034 fTarget->textColor(cc, vProp, sError); // red
1050 } 1035 }
1051 } 1036 }
1052 } else { 1037 } else {
1053 if (iNegStyle == 1 || iNegStyle == 3) { 1038 if (iNegStyle == 1 || iNegStyle == 3) {
1054 if (Field* fTarget = pEvent->Target_Field()) { 1039 if (Field* fTarget = pEvent->Target_Field()) {
1055 CJS_Array arColor(isolate); 1040 CJS_Array arColor(pRuntime);
1056 CJS_Value vColElm(isolate); 1041 CJS_Value vColElm(pRuntime);
1057 vColElm = L"RGB"; 1042 vColElm = L"RGB";
1058 arColor.SetElement(0, vColElm); 1043 arColor.SetElement(0, vColElm);
1059 vColElm = 0; 1044 vColElm = 0;
1060 arColor.SetElement(1, vColElm); 1045 arColor.SetElement(1, vColElm);
1061 arColor.SetElement(2, vColElm); 1046 arColor.SetElement(2, vColElm);
1062 arColor.SetElement(3, vColElm); 1047 arColor.SetElement(3, vColElm);
1063 1048
1064 CJS_PropValue vProp(isolate); 1049 CJS_PropValue vProp(pRuntime);
1065 vProp.StartGetting(); 1050 vProp.StartGetting();
1066 fTarget->textColor(cc, vProp, sError); 1051 fTarget->textColor(cc, vProp, sError);
1067 1052
1068 CJS_Array aProp(isolate); 1053 CJS_Array aProp(pRuntime);
1069 vProp.ConvertToArray(aProp); 1054 vProp.ConvertToArray(aProp);
1070 1055
1071 CPWL_Color crProp; 1056 CPWL_Color crProp;
1072 CPWL_Color crColor; 1057 CPWL_Color crColor;
1073 color::ConvertArrayToPWLColor(aProp, crProp); 1058 color::ConvertArrayToPWLColor(aProp, crProp);
1074 color::ConvertArrayToPWLColor(arColor, crColor); 1059 color::ConvertArrayToPWLColor(arColor, crColor);
1075 1060
1076 if (crColor != crProp) { 1061 if (crColor != crProp) {
1077 CJS_PropValue vProp2(isolate); 1062 CJS_PropValue vProp2(pRuntime);
1078 vProp2.StartGetting(); 1063 vProp2.StartGetting();
1079 vProp2 << arColor; 1064 vProp2 << arColor;
1080 vProp2.StartSetting(); 1065 vProp2.StartSetting();
1081 fTarget->textColor(cc, vProp2, sError); 1066 fTarget->textColor(cc, vProp2, sError);
1082 } 1067 }
1083 } 1068 }
1084 } 1069 }
1085 } 1070 }
1086 Value = strValue2.c_str(); 1071 Value = strValue2.c_str();
1087 #endif 1072 #endif
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 return TRUE; 1448 return TRUE;
1464 } 1449 }
1465 } 1450 }
1466 return TRUE; 1451 return TRUE;
1467 } 1452 }
1468 1453
1469 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, 1454 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc,
1470 const CJS_Parameters& params, 1455 const CJS_Parameters& params,
1471 CJS_Value& vRet, 1456 CJS_Value& vRet,
1472 CFX_WideString& sError) { 1457 CFX_WideString& sError) {
1473 v8::Isolate* isolate = ::GetIsolate(cc); 1458 CJS_Context* pContext = (CJS_Context*)cc;
1474
1475 if (params.size() != 1) { 1459 if (params.size() != 1) {
1476 CJS_Context* pContext = (CJS_Context*)cc;
1477 ASSERT(pContext != NULL);
1478
1479 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1460 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1480 return FALSE; 1461 return FALSE;
1481 } 1462 }
1482 1463
1483 int iIndex = params[0].ToInt(); 1464 int iIndex = params[0].ToInt();
1484 const FX_WCHAR* cFormats[] = {L"m/d", 1465 const FX_WCHAR* cFormats[] = {L"m/d",
1485 L"m/d/yy", 1466 L"m/d/yy",
1486 L"mm/dd/yy", 1467 L"mm/dd/yy",
1487 L"mm/yy", 1468 L"mm/yy",
1488 L"d-mmm", 1469 L"d-mmm",
1489 L"d-mmm-yy", 1470 L"d-mmm-yy",
1490 L"dd-mmm-yy", 1471 L"dd-mmm-yy",
1491 L"yy-mm-dd", 1472 L"yy-mm-dd",
1492 L"mmm-yy", 1473 L"mmm-yy",
1493 L"mmmm-yy", 1474 L"mmmm-yy",
1494 L"mmm d, yyyy", 1475 L"mmm d, yyyy",
1495 L"mmmm d, yyyy", 1476 L"mmmm d, yyyy",
1496 L"m/d/yy h:MM tt", 1477 L"m/d/yy h:MM tt",
1497 L"m/d/yy HH:MM"}; 1478 L"m/d/yy HH:MM"};
1498 1479
1499 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) 1480 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1500 iIndex = 0; 1481 iIndex = 0;
1501 1482
1502 CJS_Parameters newParams; 1483 CJS_Parameters newParams;
1503 CJS_Value val(isolate, cFormats[iIndex]); 1484 newParams.push_back(
1504 newParams.push_back(val); 1485 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
1505 return AFDate_FormatEx(cc, newParams, vRet, sError); 1486 return AFDate_FormatEx(cc, newParams, vRet, sError);
1506 } 1487 }
1507 1488
1508 // AFDate_KeystrokeEx(cFormat) 1489 // AFDate_KeystrokeEx(cFormat)
1509 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc, 1490 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc,
1510 const CJS_Parameters& params, 1491 const CJS_Parameters& params,
1511 CJS_Value& vRet, 1492 CJS_Value& vRet,
1512 CFX_WideString& sError) { 1493 CFX_WideString& sError) {
1513 v8::Isolate* isolate = ::GetIsolate(cc); 1494 CJS_Context* pContext = (CJS_Context*)cc;
1514
1515 if (params.size() != 1) { 1495 if (params.size() != 1) {
1516 CJS_Context* pContext = (CJS_Context*)cc;
1517 ASSERT(pContext != NULL);
1518
1519 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1496 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1520 return FALSE; 1497 return FALSE;
1521 } 1498 }
1522 1499
1523 int iIndex = params[0].ToInt(); 1500 int iIndex = params[0].ToInt();
1524 const FX_WCHAR* cFormats[] = {L"m/d", 1501 const FX_WCHAR* cFormats[] = {L"m/d",
1525 L"m/d/yy", 1502 L"m/d/yy",
1526 L"mm/dd/yy", 1503 L"mm/dd/yy",
1527 L"mm/yy", 1504 L"mm/yy",
1528 L"d-mmm", 1505 L"d-mmm",
1529 L"d-mmm-yy", 1506 L"d-mmm-yy",
1530 L"dd-mmm-yy", 1507 L"dd-mmm-yy",
1531 L"yy-mm-dd", 1508 L"yy-mm-dd",
1532 L"mmm-yy", 1509 L"mmm-yy",
1533 L"mmmm-yy", 1510 L"mmmm-yy",
1534 L"mmm d, yyyy", 1511 L"mmm d, yyyy",
1535 L"mmmm d, yyyy", 1512 L"mmmm d, yyyy",
1536 L"m/d/yy h:MM tt", 1513 L"m/d/yy h:MM tt",
1537 L"m/d/yy HH:MM"}; 1514 L"m/d/yy HH:MM"};
1538 1515
1539 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) 1516 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1540 iIndex = 0; 1517 iIndex = 0;
1541 1518
1542 CJS_Parameters newParams; 1519 CJS_Parameters newParams;
1543 CJS_Value val(isolate, cFormats[iIndex]); 1520 newParams.push_back(
1544 newParams.push_back(val); 1521 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
1545 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); 1522 return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
1546 } 1523 }
1547 1524
1548 // function AFTime_Format(ptf) 1525 // function AFTime_Format(ptf)
1549 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, 1526 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc,
1550 const CJS_Parameters& params, 1527 const CJS_Parameters& params,
1551 CJS_Value& vRet, 1528 CJS_Value& vRet,
1552 CFX_WideString& sError) { 1529 CFX_WideString& sError) {
1553 v8::Isolate* isolate = ::GetIsolate(cc); 1530 CJS_Context* pContext = (CJS_Context*)cc;
1554
1555 if (params.size() != 1) { 1531 if (params.size() != 1) {
1556 CJS_Context* pContext = (CJS_Context*)cc;
1557 ASSERT(pContext != NULL);
1558 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1532 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1559 return FALSE; 1533 return FALSE;
1560 } 1534 }
1561 1535
1562 int iIndex = params[0].ToInt(); 1536 int iIndex = params[0].ToInt();
1563 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", 1537 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss",
1564 L"h:MM:ss tt"}; 1538 L"h:MM:ss tt"};
1565 1539
1566 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) 1540 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1567 iIndex = 0; 1541 iIndex = 0;
1568 1542
1569 CJS_Parameters newParams; 1543 CJS_Parameters newParams;
1570 CJS_Value val(isolate, cFormats[iIndex]); 1544 newParams.push_back(
1571 newParams.push_back(val); 1545 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
1572 return AFDate_FormatEx(cc, newParams, vRet, sError); 1546 return AFDate_FormatEx(cc, newParams, vRet, sError);
1573 } 1547 }
1574 1548
1575 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc, 1549 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc,
1576 const CJS_Parameters& params, 1550 const CJS_Parameters& params,
1577 CJS_Value& vRet, 1551 CJS_Value& vRet,
1578 CFX_WideString& sError) { 1552 CFX_WideString& sError) {
1579 v8::Isolate* isolate = ::GetIsolate(cc); 1553 CJS_Context* pContext = (CJS_Context*)cc;
1580 if (params.size() != 1) { 1554 if (params.size() != 1) {
1581 CJS_Context* pContext = (CJS_Context*)cc;
1582 ASSERT(pContext != NULL);
1583 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1555 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1584 return FALSE; 1556 return FALSE;
1585 } 1557 }
1586 1558
1587 int iIndex = params[0].ToInt(); 1559 int iIndex = params[0].ToInt();
1588 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", 1560 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss",
1589 L"h:MM:ss tt"}; 1561 L"h:MM:ss tt"};
1590 1562
1591 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) 1563 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1592 iIndex = 0; 1564 iIndex = 0;
1593 1565
1594 CJS_Parameters newParams; 1566 CJS_Parameters newParams;
1595 CJS_Value val(isolate, cFormats[iIndex]); 1567 newParams.push_back(
1596 newParams.push_back(val); 1568 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
1597 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); 1569 return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
1598 } 1570 }
1599 1571
1600 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IJS_Context* cc, 1572 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IJS_Context* cc,
1601 const CJS_Parameters& params, 1573 const CJS_Parameters& params,
1602 CJS_Value& vRet, 1574 CJS_Value& vRet,
1603 CFX_WideString& sError) { 1575 CFX_WideString& sError) {
1604 return AFDate_FormatEx(cc, params, vRet, sError); 1576 return AFDate_FormatEx(cc, params, vRet, sError);
1605 } 1577 }
1606 1578
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 1725
1754 wideChange = wChange.c_str(); 1726 wideChange = wChange.c_str();
1755 return TRUE; 1727 return TRUE;
1756 } 1728 }
1757 1729
1758 // function AFSpecial_Keystroke(psf) 1730 // function AFSpecial_Keystroke(psf)
1759 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc, 1731 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc,
1760 const CJS_Parameters& params, 1732 const CJS_Parameters& params,
1761 CJS_Value& vRet, 1733 CJS_Value& vRet,
1762 CFX_WideString& sError) { 1734 CFX_WideString& sError) {
1763 v8::Isolate* isolate = ::GetIsolate(cc);
1764
1765 CJS_Context* pContext = (CJS_Context*)cc; 1735 CJS_Context* pContext = (CJS_Context*)cc;
1766 ASSERT(pContext != NULL);
1767 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1768 ASSERT(pEvent != NULL);
1769
1770 if (params.size() != 1) { 1736 if (params.size() != 1) {
1771 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1737 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1772 return FALSE; 1738 return FALSE;
1773 } 1739 }
1774 1740
1741 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1742 if (!pEvent->m_pValue)
1743 return FALSE;
1744
1775 std::string cFormat; 1745 std::string cFormat;
1776 int iIndex = params[0].ToInt(); 1746 int iIndex = params[0].ToInt();
1777
1778 if (!pEvent->m_pValue)
1779 return FALSE;
1780 // CJS_Value val = pEvent->Value();
1781 CFX_WideString& val = pEvent->Value(); 1747 CFX_WideString& val = pEvent->Value();
1782 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); 1748 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str();
1783 std::wstring wstrChange = pEvent->Change().c_str(); 1749 std::wstring wstrChange = pEvent->Change().c_str();
1784 1750
1785 switch (iIndex) { 1751 switch (iIndex) {
1786 case 0: 1752 case 0:
1787 cFormat = "99999"; 1753 cFormat = "99999";
1788 break; 1754 break;
1789 case 1: 1755 case 1:
1790 // cFormat = "99999-9999"; 1756 // cFormat = "99999-9999";
(...skipping 10 matching lines...) Expand all
1801 cFormat = "9999999"; 1767 cFormat = "9999999";
1802 break; 1768 break;
1803 } 1769 }
1804 case 3: 1770 case 3:
1805 // cFormat = "999-99-9999"; 1771 // cFormat = "999-99-9999";
1806 cFormat = "999999999"; 1772 cFormat = "999999999";
1807 break; 1773 break;
1808 } 1774 }
1809 1775
1810 CJS_Parameters params2; 1776 CJS_Parameters params2;
1811 CJS_Value vMask(isolate, cFormat.c_str()); 1777 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str()));
1812 params2.push_back(vMask);
1813
1814 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); 1778 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError);
1815 } 1779 }
1816 1780
1817 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, 1781 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc,
1818 const CJS_Parameters& params, 1782 const CJS_Parameters& params,
1819 CJS_Value& vRet, 1783 CJS_Value& vRet,
1820 CFX_WideString& sError) { 1784 CFX_WideString& sError) {
1821 CJS_Context* pContext = (CJS_Context*)cc; 1785 CJS_Context* pContext = (CJS_Context*)cc;
1822 ASSERT(pContext != NULL); 1786 ASSERT(pContext != NULL);
1823 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); 1787 CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 return FALSE; 1879 return FALSE;
1916 } 1880 }
1917 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); 1881 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str());
1918 return TRUE; 1882 return TRUE;
1919 } 1883 }
1920 1884
1921 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc, 1885 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc,
1922 const CJS_Parameters& params, 1886 const CJS_Parameters& params,
1923 CJS_Value& vRet, 1887 CJS_Value& vRet,
1924 CFX_WideString& sError) { 1888 CFX_WideString& sError) {
1925 v8::Isolate* isolate = ::GetIsolate(cc);
1926
1927 CJS_Context* pContext = (CJS_Context*)cc; 1889 CJS_Context* pContext = (CJS_Context*)cc;
1928 ASSERT(pContext != NULL);
1929
1930 if (params.size() != 2) { 1890 if (params.size() != 2) {
1931 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1891 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1932 return FALSE; 1892 return FALSE;
1933 } 1893 }
1934 1894
1935 CJS_Value params1 = params[1]; 1895 CJS_Value params1 = params[1];
1936
1937 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { 1896 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) {
1938 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1897 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1939 return FALSE; 1898 return FALSE;
1940 } 1899 }
1941 1900
1942 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); 1901 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
1943 ASSERT(pReaderDoc != NULL); 1902 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
1903 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
1944 1904
1945 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); 1905 CFX_WideString sFunction = params[0].ToCFXWideString();
1946 ASSERT(pReaderInterForm != NULL); 1906 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0;
1947 1907
1948 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); 1908 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1949 ASSERT(pInterForm != NULL); 1909 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1);
1950
1951 double dValue;
1952 CFX_WideString sFunction = params[0].ToCFXWideString();
1953 if (wcscmp(sFunction.c_str(), L"PRD") == 0)
1954 dValue = 1.0;
1955 else
1956 dValue = 0.0;
1957
1958 CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate, params1);
1959
1960 int nFieldsCount = 0; 1910 int nFieldsCount = 0;
1961 1911
1962 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { 1912 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) {
1963 CJS_Value jsValue(isolate); 1913 CJS_Value jsValue(pRuntime);
1964 FieldNameArray.GetElement(i, jsValue); 1914 FieldNameArray.GetElement(i, jsValue);
1965 CFX_WideString wsFieldName = jsValue.ToCFXWideString(); 1915 CFX_WideString wsFieldName = jsValue.ToCFXWideString();
1966 1916
1967 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { 1917 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) {
1968 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { 1918 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) {
1969 double dTemp = 0.0; 1919 double dTemp = 0.0;
1970 1920
1971 switch (pFormField->GetFieldType()) { 1921 switch (pFormField->GetFieldType()) {
1972 case FIELDTYPE_TEXTFIELD: 1922 case FIELDTYPE_TEXTFIELD:
1973 case FIELDTYPE_COMBOBOX: { 1923 case FIELDTYPE_COMBOBOX: {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 nFieldsCount++; 1965 nFieldsCount++;
2016 } 1966 }
2017 } 1967 }
2018 } 1968 }
2019 1969
2020 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) 1970 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0)
2021 dValue /= nFieldsCount; 1971 dValue /= nFieldsCount;
2022 1972
2023 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / 1973 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) /
2024 FXSYS_pow((double)10, (double)6); 1974 FXSYS_pow((double)10, (double)6);
2025 CJS_Value jsValue(isolate, dValue); 1975 CJS_Value jsValue(pRuntime, dValue);
2026 if (pContext->GetEventHandler()->m_pValue) 1976 if (pContext->GetEventHandler()->m_pValue)
2027 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(); 1977 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString();
2028 1978
2029 return TRUE; 1979 return TRUE;
2030 } 1980 }
2031 1981
2032 /* This function validates the current event to ensure that its value is 1982 /* This function validates the current event to ensure that its value is
2033 ** within the specified range. */ 1983 ** within the specified range. */
2034 1984
2035 FX_BOOL CJS_PublicMethods::AFRange_Validate(IJS_Context* cc, 1985 FX_BOOL CJS_PublicMethods::AFRange_Validate(IJS_Context* cc,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 Alert(pContext, swMsg.c_str()); 2026 Alert(pContext, swMsg.c_str());
2077 pEvent->Rc() = FALSE; 2027 pEvent->Rc() = FALSE;
2078 } 2028 }
2079 return TRUE; 2029 return TRUE;
2080 } 2030 }
2081 2031
2082 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, 2032 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
2083 const CJS_Parameters& params, 2033 const CJS_Parameters& params,
2084 CJS_Value& vRet, 2034 CJS_Value& vRet,
2085 CFX_WideString& sError) { 2035 CFX_WideString& sError) {
2086 v8::Isolate* isolate = ::GetIsolate(cc);
2087 CJS_Context* pContext = (CJS_Context*)cc; 2036 CJS_Context* pContext = (CJS_Context*)cc;
2088 ASSERT(pContext != NULL);
2089
2090 if (params.size() != 1) { 2037 if (params.size() != 1) {
2091 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2038 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2092 return FALSE; 2039 return FALSE;
2093 } 2040 }
2094 2041
2095 CJS_Array nums(isolate); 2042 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2043 CJS_Array nums(pRuntime);
2096 2044
2097 CFX_WideString str = params[0].ToCFXWideString(); 2045 CFX_WideString str = params[0].ToCFXWideString();
2098 CFX_WideString sPart; 2046 CFX_WideString sPart;
2099 2047
2100 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') 2048 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
2101 str = L"0" + str; 2049 str = L"0" + str;
2102 2050
2103 int nIndex = 0; 2051 int nIndex = 0;
2104 for (int i = 0, sz = str.GetLength(); i < sz; i++) { 2052 for (int i = 0, sz = str.GetLength(); i < sz; i++) {
2105 FX_WCHAR wc = str.GetAt(i); 2053 FX_WCHAR wc = str.GetAt(i);
2106 if (IsDigit((wchar_t)wc)) { 2054 if (IsDigit((wchar_t)wc)) {
2107 sPart += wc; 2055 sPart += wc;
2108 } else { 2056 } else {
2109 if (sPart.GetLength() > 0) { 2057 if (sPart.GetLength() > 0) {
2110 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); 2058 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
2111 sPart = L""; 2059 sPart = L"";
2112 nIndex++; 2060 nIndex++;
2113 } 2061 }
2114 } 2062 }
2115 } 2063 }
2116 2064
2117 if (sPart.GetLength() > 0) { 2065 if (sPart.GetLength() > 0) {
2118 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); 2066 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
2119 } 2067 }
2120 2068
2121 if (nums.GetLength() > 0) 2069 if (nums.GetLength() > 0)
2122 vRet = nums; 2070 vRet = nums;
2123 else 2071 else
2124 vRet.SetNull(); 2072 vRet.SetNull();
2125 2073
2126 return TRUE; 2074 return TRUE;
2127 } 2075 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698