OLD | NEW |
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 "../../third_party/base/nonstd_unique_ptr.h" | 7 #include "../../third_party/base/nonstd_unique_ptr.h" |
8 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
9 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
10 #include "../include/fpdfxfa/fpdfxfa_util.h" | 10 #include "../include/fpdfxfa/fpdfxfa_util.h" |
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2425 ASSERT(pEnv); | 2425 ASSERT(pEnv); |
2426 if (!pEnv->IsJSInitiated()) | 2426 if (!pEnv->IsJSInitiated()) |
2427 return; | 2427 return; |
2428 | 2428 |
2429 if (m_bBusy) | 2429 if (m_bBusy) |
2430 return; | 2430 return; |
2431 | 2431 |
2432 m_bBusy = TRUE; | 2432 m_bBusy = TRUE; |
2433 | 2433 |
2434 if (IsCalculateEnabled()) { | 2434 if (IsCalculateEnabled()) { |
2435 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); | 2435 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
2436 ASSERT(pRuntime != NULL); | 2436 ASSERT(pRuntime != NULL); |
2437 | 2437 |
2438 pRuntime->SetReaderDocument(m_pDocument); | 2438 pRuntime->SetReaderDocument(m_pDocument); |
2439 | 2439 |
2440 int nSize = m_pInterForm->CountFieldsInCalculationOrder(); | 2440 int nSize = m_pInterForm->CountFieldsInCalculationOrder(); |
2441 for (int i = 0; i < nSize; i++) { | 2441 for (int i = 0; i < nSize; i++) { |
2442 if (CPDF_FormField* pField = | 2442 if (CPDF_FormField* pField = |
2443 m_pInterForm->GetFieldInCalculationOrder(i)) { | 2443 m_pInterForm->GetFieldInCalculationOrder(i)) { |
2444 // ASSERT(pField != NULL); | 2444 // ASSERT(pField != NULL); |
2445 int nType = pField->GetFieldType(); | 2445 int nType = pField->GetFieldType(); |
2446 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { | 2446 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
2447 CPDF_AAction aAction = pField->GetAdditionalAction(); | 2447 CPDF_AAction aAction = pField->GetAdditionalAction(); |
2448 if (aAction && aAction.ActionExist(CPDF_AAction::Calculate)) { | 2448 if (aAction && aAction.ActionExist(CPDF_AAction::Calculate)) { |
2449 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); | 2449 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); |
2450 if (action) { | 2450 if (action) { |
2451 CFX_WideString csJS = action.GetJavaScript(); | 2451 CFX_WideString csJS = action.GetJavaScript(); |
2452 if (!csJS.IsEmpty()) { | 2452 if (!csJS.IsEmpty()) { |
2453 IFXJS_Context* pContext = pRuntime->NewContext(); | 2453 IJS_Context* pContext = pRuntime->NewContext(); |
2454 ASSERT(pContext != NULL); | 2454 ASSERT(pContext != NULL); |
2455 | 2455 |
2456 CFX_WideString sOldValue = pField->GetValue(); | 2456 CFX_WideString sOldValue = pField->GetValue(); |
2457 CFX_WideString sValue = sOldValue; | 2457 CFX_WideString sValue = sOldValue; |
2458 FX_BOOL bRC = TRUE; | 2458 FX_BOOL bRC = TRUE; |
2459 pContext->OnField_Calculate(pFormField, pField, sValue, bRC); | 2459 pContext->OnField_Calculate(pFormField, pField, sValue, bRC); |
2460 | 2460 |
2461 CFX_WideString sInfo; | 2461 CFX_WideString sInfo; |
2462 FX_BOOL bRet = pContext->RunScript(csJS, sInfo); | 2462 FX_BOOL bRet = pContext->RunScript(csJS, sInfo); |
2463 pRuntime->ReleaseContext(pContext); | 2463 pRuntime->ReleaseContext(pContext); |
(...skipping 21 matching lines...) Expand all Loading... |
2485 ASSERT(pFormField != NULL); | 2485 ASSERT(pFormField != NULL); |
2486 | 2486 |
2487 CFX_WideString sValue = pFormField->GetValue(); | 2487 CFX_WideString sValue = pFormField->GetValue(); |
2488 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 2488 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
2489 ASSERT(pEnv); | 2489 ASSERT(pEnv); |
2490 if (!pEnv->IsJSInitiated()) { | 2490 if (!pEnv->IsJSInitiated()) { |
2491 bFormated = FALSE; | 2491 bFormated = FALSE; |
2492 return sValue; | 2492 return sValue; |
2493 } | 2493 } |
2494 | 2494 |
2495 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); | 2495 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
2496 ASSERT(pRuntime != NULL); | 2496 ASSERT(pRuntime != NULL); |
2497 | 2497 |
2498 pRuntime->SetReaderDocument(m_pDocument); | 2498 pRuntime->SetReaderDocument(m_pDocument); |
2499 | 2499 |
2500 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) { | 2500 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) { |
2501 if (pFormField->CountSelectedItems() > 0) { | 2501 if (pFormField->CountSelectedItems() > 0) { |
2502 int index = pFormField->GetSelectedIndex(0); | 2502 int index = pFormField->GetSelectedIndex(0); |
2503 if (index >= 0) | 2503 if (index >= 0) |
2504 sValue = pFormField->GetOptionLabel(index); | 2504 sValue = pFormField->GetOptionLabel(index); |
2505 } | 2505 } |
2506 } | 2506 } |
2507 | 2507 |
2508 bFormated = FALSE; | 2508 bFormated = FALSE; |
2509 | 2509 |
2510 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2510 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
2511 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) { | 2511 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) { |
2512 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); | 2512 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
2513 if (action) { | 2513 if (action) { |
2514 CFX_WideString script = action.GetJavaScript(); | 2514 CFX_WideString script = action.GetJavaScript(); |
2515 if (!script.IsEmpty()) { | 2515 if (!script.IsEmpty()) { |
2516 CFX_WideString Value = sValue; | 2516 CFX_WideString Value = sValue; |
2517 | 2517 |
2518 IFXJS_Context* pContext = pRuntime->NewContext(); | 2518 IJS_Context* pContext = pRuntime->NewContext(); |
2519 ASSERT(pContext != NULL); | 2519 ASSERT(pContext != NULL); |
2520 | 2520 |
2521 pContext->OnField_Format(pFormField, Value, TRUE); | 2521 pContext->OnField_Format(pFormField, Value, TRUE); |
2522 | 2522 |
2523 CFX_WideString sInfo; | 2523 CFX_WideString sInfo; |
2524 FX_BOOL bRet = pContext->RunScript(script, sInfo); | 2524 FX_BOOL bRet = pContext->RunScript(script, sInfo); |
2525 pRuntime->ReleaseContext(pContext); | 2525 pRuntime->ReleaseContext(pContext); |
2526 | 2526 |
2527 if (bRet) { | 2527 if (bRet) { |
2528 sValue = Value; | 2528 sValue = Value; |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3358 ASSERT(pAnnot != NULL); | 3358 ASSERT(pAnnot != NULL); |
3359 | 3359 |
3360 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); | 3360 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); |
3361 ASSERT(pPDFAnnot != NULL); | 3361 ASSERT(pPDFAnnot != NULL); |
3362 | 3362 |
3363 CPDF_Rect rcAnnot; | 3363 CPDF_Rect rcAnnot; |
3364 pPDFAnnot->GetRect(rcAnnot); | 3364 pPDFAnnot->GetRect(rcAnnot); |
3365 | 3365 |
3366 return rcAnnot; | 3366 return rcAnnot; |
3367 } | 3367 } |
OLD | NEW |