| 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 "xfa/fxfa/app/xfa_ffwidgetacc.h" | 7 #include "xfa/fxfa/app/xfa_ffwidgetacc.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 359 |
| 360 if (GetRawValue() != EventParam.m_wsResult) { | 360 if (GetRawValue() != EventParam.m_wsResult) { |
| 361 SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw); | 361 SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw); |
| 362 UpdateUIDisplay(); | 362 UpdateUIDisplay(); |
| 363 } | 363 } |
| 364 return XFA_EVENTERROR_Success; | 364 return XFA_EVENTERROR_Success; |
| 365 } | 365 } |
| 366 | 366 |
| 367 void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, | 367 void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, |
| 368 int32_t iRet, | 368 int32_t iRet, |
| 369 FXJSE_HVALUE pRetValue, | 369 CFXJSE_Value* pRetValue, |
| 370 FX_BOOL bVersionFlag) { | 370 FX_BOOL bVersionFlag) { |
| 371 if (iRet == XFA_EVENTERROR_Success && pRetValue) { | 371 if (iRet == XFA_EVENTERROR_Success && pRetValue) { |
| 372 if (FXJSE_Value_IsBoolean(pRetValue) && !FXJSE_Value_ToBoolean(pRetValue)) { | 372 if (FXJSE_Value_IsBoolean(pRetValue) && !FXJSE_Value_ToBoolean(pRetValue)) { |
| 373 IXFA_AppProvider* pAppProvider = GetAppProvider(); | 373 IXFA_AppProvider* pAppProvider = GetAppProvider(); |
| 374 if (!pAppProvider) { | 374 if (!pAppProvider) { |
| 375 return; | 375 return; |
| 376 } | 376 } |
| 377 CFX_WideString wsTitle; | 377 CFX_WideString wsTitle; |
| 378 pAppProvider->LoadString(XFA_IDS_AppName, wsTitle); | 378 pAppProvider->LoadString(XFA_IDS_AppName, wsTitle); |
| 379 CFX_WideString wsScriptMsg; | 379 CFX_WideString wsScriptMsg; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 return XFA_EVENTERROR_NotExist; | 573 return XFA_EVENTERROR_NotExist; |
| 574 } | 574 } |
| 575 CXFA_Validate validate = GetValidate(); | 575 CXFA_Validate validate = GetValidate(); |
| 576 if (!validate) { | 576 if (!validate) { |
| 577 return XFA_EVENTERROR_NotExist; | 577 return XFA_EVENTERROR_NotExist; |
| 578 } | 578 } |
| 579 FX_BOOL bInitDoc = validate.GetNode()->HasFlag(XFA_NODEFLAG_NeedsInitApp); | 579 FX_BOOL bInitDoc = validate.GetNode()->HasFlag(XFA_NODEFLAG_NeedsInitApp); |
| 580 FX_BOOL bStatus = | 580 FX_BOOL bStatus = |
| 581 m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; | 581 m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; |
| 582 int32_t iFormat = 0; | 582 int32_t iFormat = 0; |
| 583 FXJSE_HVALUE pRetValue = NULL; | 583 CFXJSE_Value* pRetValue = nullptr; |
| 584 int32_t iRet = XFA_EVENTERROR_NotExist; | 584 int32_t iRet = XFA_EVENTERROR_NotExist; |
| 585 CXFA_Script script = validate.GetScript(); | 585 CXFA_Script script = validate.GetScript(); |
| 586 if (script) { | 586 if (script) { |
| 587 CXFA_EventParam eParam; | 587 CXFA_EventParam eParam; |
| 588 eParam.m_eType = XFA_EVENT_Validate; | 588 eParam.m_eType = XFA_EVENT_Validate; |
| 589 eParam.m_pTarget = this; | 589 eParam.m_pTarget = this; |
| 590 iRet = ExecuteScript(script, &eParam, | 590 iRet = ExecuteScript(script, &eParam, |
| 591 ((bInitDoc || bStatus) && GetRawValue().IsEmpty()) | 591 ((bInitDoc || bStatus) && GetRawValue().IsEmpty()) |
| 592 ? nullptr | 592 ? nullptr |
| 593 : &pRetValue); | 593 : &pRetValue); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 609 if (iFormat != XFA_EVENTERROR_Success) { | 609 if (iFormat != XFA_EVENTERROR_Success) { |
| 610 ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag); | 610 ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag); |
| 611 } | 611 } |
| 612 if (pRetValue) { | 612 if (pRetValue) { |
| 613 FXJSE_Value_Release(pRetValue); | 613 FXJSE_Value_Release(pRetValue); |
| 614 } | 614 } |
| 615 return iRet | iFormat; | 615 return iRet | iFormat; |
| 616 } | 616 } |
| 617 int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, | 617 int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, |
| 618 CXFA_EventParam* pEventParam, | 618 CXFA_EventParam* pEventParam, |
| 619 FXJSE_HVALUE* pRetValue) { | 619 CFXJSE_Value** pRetValue) { |
| 620 static const uint32_t MAX_RECURSION_DEPTH = 2; | 620 static const uint32_t MAX_RECURSION_DEPTH = 2; |
| 621 if (m_nRecursionDepth > MAX_RECURSION_DEPTH) | 621 if (m_nRecursionDepth > MAX_RECURSION_DEPTH) |
| 622 return XFA_EVENTERROR_Success; | 622 return XFA_EVENTERROR_Success; |
| 623 ASSERT(pEventParam); | 623 ASSERT(pEventParam); |
| 624 if (!script) { | 624 if (!script) { |
| 625 return XFA_EVENTERROR_NotExist; | 625 return XFA_EVENTERROR_NotExist; |
| 626 } | 626 } |
| 627 if (script.GetRunAt() == XFA_ATTRIBUTEENUM_Server) { | 627 if (script.GetRunAt() == XFA_ATTRIBUTEENUM_Server) { |
| 628 return XFA_EVENTERROR_Disabled; | 628 return XFA_EVENTERROR_Disabled; |
| 629 } | 629 } |
| 630 CFX_WideString wsExpression; | 630 CFX_WideString wsExpression; |
| 631 script.GetExpression(wsExpression); | 631 script.GetExpression(wsExpression); |
| 632 if (wsExpression.IsEmpty()) { | 632 if (wsExpression.IsEmpty()) { |
| 633 return XFA_EVENTERROR_NotExist; | 633 return XFA_EVENTERROR_NotExist; |
| 634 } | 634 } |
| 635 XFA_SCRIPTTYPE eScriptType = script.GetContentType(); | 635 XFA_SCRIPTTYPE eScriptType = script.GetContentType(); |
| 636 if (eScriptType == XFA_SCRIPTTYPE_Unkown) { | 636 if (eScriptType == XFA_SCRIPTTYPE_Unkown) { |
| 637 return XFA_EVENTERROR_Success; | 637 return XFA_EVENTERROR_Success; |
| 638 } | 638 } |
| 639 CXFA_FFDoc* pDoc = GetDoc(); | 639 CXFA_FFDoc* pDoc = GetDoc(); |
| 640 CXFA_ScriptContext* pContext = pDoc->GetXFADoc()->GetScriptContext(); | 640 CXFA_ScriptContext* pContext = pDoc->GetXFADoc()->GetScriptContext(); |
| 641 pContext->SetEventParam(*pEventParam); | 641 pContext->SetEventParam(*pEventParam); |
| 642 pContext->SetRunAtType((XFA_ATTRIBUTEENUM)script.GetRunAt()); | 642 pContext->SetRunAtType((XFA_ATTRIBUTEENUM)script.GetRunAt()); |
| 643 CXFA_NodeArray refNodes; | 643 CXFA_NodeArray refNodes; |
| 644 if (pEventParam->m_eType == XFA_EVENT_InitCalculate || | 644 if (pEventParam->m_eType == XFA_EVENT_InitCalculate || |
| 645 pEventParam->m_eType == XFA_EVENT_Calculate) { | 645 pEventParam->m_eType == XFA_EVENT_Calculate) { |
| 646 pContext->SetNodesOfRunScript(&refNodes); | 646 pContext->SetNodesOfRunScript(&refNodes); |
| 647 } | 647 } |
| 648 FXJSE_HVALUE hRetValue = FXJSE_Value_Create(pContext->GetRuntime()); | 648 CFXJSE_Value* pTmpRetValue = FXJSE_Value_Create(pContext->GetRuntime()); |
| 649 ++m_nRecursionDepth; | 649 ++m_nRecursionDepth; |
| 650 FX_BOOL bRet = | 650 FX_BOOL bRet = |
| 651 pContext->RunScript((XFA_SCRIPTLANGTYPE)eScriptType, | 651 pContext->RunScript((XFA_SCRIPTLANGTYPE)eScriptType, |
| 652 wsExpression.AsStringC(), hRetValue, m_pNode); | 652 wsExpression.AsStringC(), pTmpRetValue, m_pNode); |
| 653 --m_nRecursionDepth; | 653 --m_nRecursionDepth; |
| 654 int32_t iRet = XFA_EVENTERROR_Error; | 654 int32_t iRet = XFA_EVENTERROR_Error; |
| 655 if (bRet) { | 655 if (bRet) { |
| 656 iRet = XFA_EVENTERROR_Success; | 656 iRet = XFA_EVENTERROR_Success; |
| 657 if (pEventParam->m_eType == XFA_EVENT_Calculate || | 657 if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 658 pEventParam->m_eType == XFA_EVENT_InitCalculate) { | 658 pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 659 if (!FXJSE_Value_IsUndefined(hRetValue)) { | 659 if (!FXJSE_Value_IsUndefined(pTmpRetValue)) { |
| 660 if (!FXJSE_Value_IsNull(hRetValue)) { | 660 if (!FXJSE_Value_IsNull(pTmpRetValue)) { |
| 661 CFX_ByteString bsString; | 661 CFX_ByteString bsString; |
| 662 FXJSE_Value_ToUTF8String(hRetValue, bsString); | 662 FXJSE_Value_ToUTF8String(pTmpRetValue, bsString); |
| 663 pEventParam->m_wsResult = | 663 pEventParam->m_wsResult = |
| 664 CFX_WideString::FromUTF8(bsString.AsStringC()); | 664 CFX_WideString::FromUTF8(bsString.AsStringC()); |
| 665 } | 665 } |
| 666 iRet = XFA_EVENTERROR_Success; | 666 iRet = XFA_EVENTERROR_Success; |
| 667 } else { | 667 } else { |
| 668 iRet = XFA_EVENTERROR_Error; | 668 iRet = XFA_EVENTERROR_Error; |
| 669 } | 669 } |
| 670 if (pEventParam->m_eType == XFA_EVENT_InitCalculate) { | 670 if (pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 671 if ((iRet == XFA_EVENTERROR_Success) && | 671 if ((iRet == XFA_EVENTERROR_Success) && |
| 672 (GetRawValue() != pEventParam->m_wsResult)) { | 672 (GetRawValue() != pEventParam->m_wsResult)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 688 pRefNode->SetUserData(XFA_CalcData, pGlobalData, | 688 pRefNode->SetUserData(XFA_CalcData, pGlobalData, |
| 689 &gs_XFADeleteCalcData); | 689 &gs_XFADeleteCalcData); |
| 690 } | 690 } |
| 691 if (pGlobalData->m_Globals.Find(this) < 0) { | 691 if (pGlobalData->m_Globals.Find(this) < 0) { |
| 692 pGlobalData->m_Globals.Add(this); | 692 pGlobalData->m_Globals.Add(this); |
| 693 } | 693 } |
| 694 } | 694 } |
| 695 } | 695 } |
| 696 } | 696 } |
| 697 if (pRetValue) { | 697 if (pRetValue) { |
| 698 *pRetValue = hRetValue; | 698 *pRetValue = pTmpRetValue; |
| 699 } else { | 699 } else { |
| 700 FXJSE_Value_Release(hRetValue); | 700 FXJSE_Value_Release(pTmpRetValue); |
| 701 } | 701 } |
| 702 pContext->SetNodesOfRunScript(NULL); | 702 pContext->SetNodesOfRunScript(NULL); |
| 703 return iRet; | 703 return iRet; |
| 704 } | 704 } |
| 705 CXFA_FFWidget* CXFA_WidgetAcc::GetNextWidget(CXFA_FFWidget* pWidget) { | 705 CXFA_FFWidget* CXFA_WidgetAcc::GetNextWidget(CXFA_FFWidget* pWidget) { |
| 706 CXFA_LayoutItem* pLayout = nullptr; | 706 CXFA_LayoutItem* pLayout = nullptr; |
| 707 if (pWidget) { | 707 if (pWidget) { |
| 708 pLayout = pWidget->GetNext(); | 708 pLayout = pWidget->GetNext(); |
| 709 } else { | 709 } else { |
| 710 pLayout = m_pDocView->GetXFALayout()->GetLayoutItem(m_pNode); | 710 pLayout = m_pDocView->GetXFALayout()->GetLayoutItem(m_pNode); |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 if (pIDNode) { | 1691 if (pIDNode) { |
| 1692 pEmbAcc = (CXFA_WidgetAcc*)pIDNode->GetWidgetData(); | 1692 pEmbAcc = (CXFA_WidgetAcc*)pIDNode->GetWidgetData(); |
| 1693 } | 1693 } |
| 1694 if (pEmbAcc) { | 1694 if (pEmbAcc) { |
| 1695 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); | 1695 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
| 1696 return TRUE; | 1696 return TRUE; |
| 1697 } | 1697 } |
| 1698 } | 1698 } |
| 1699 return FALSE; | 1699 return FALSE; |
| 1700 } | 1700 } |
| OLD | NEW |