diff options
-rw-r--r-- | xfa/fxfa/cxfa_ffdocview.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffnotify.cpp | 20 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffwidgethandler.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 137 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.h | 34 |
5 files changed, 86 insertions, 109 deletions
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index 6cb550e10d..28517089ee 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -689,7 +689,7 @@ bool CXFA_FFDocView::RunValidate() { for (CXFA_WidgetAcc* pAcc : m_ValidateAccs) { if (!pAcc->GetNode()->HasRemovedChildren()) - pAcc->ProcessValidate(); + pAcc->ProcessValidate(0); } m_ValidateAccs.clear(); return true; diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index df28aac0c1..3cad913d0a 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -6,7 +6,6 @@ #include "xfa/fxfa/cxfa_ffnotify.h" -#include "fxjs/cfxjse_value.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffarc.h" #include "xfa/fxfa/cxfa_ffbarcode.h" @@ -208,25 +207,22 @@ bool CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem, } bool CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) { - bool bRet = false; CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); if (!pDocView) - return bRet; + return false; CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pFormItem->GetWidgetData()); if (!pWidgetAcc) - return bRet; + return false; CXFA_EventParam EventParam; EventParam.m_eType = XFA_EVENT_Unknown; - CFXJSE_Value* pRetValue = nullptr; - int32_t iRet = - pWidgetAcc->ExecuteScript(CXFA_Script(pScript), &EventParam, &pRetValue); - if (iRet == XFA_EVENTERROR_Success && pRetValue) { - bRet = pRetValue->ToBoolean(); - delete pRetValue; - } - return bRet; + + int32_t iRet; + bool bRet; + std::tie(iRet, bRet) = + pWidgetAcc->ExecuteBoolScript(CXFA_Script(pScript), &EventParam); + return iRet == XFA_EVENTERROR_Success && bRet; } int32_t CXFA_FFNotify::ExecEventByDeepFirst(CXFA_Node* pFormNode, diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp index 7d0649b140..e68b2192e9 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -216,7 +216,7 @@ int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, case XFA_EVENT_Validate: if (m_pDocView->GetDoc()->GetDocEnvironment()->IsValidationsEnabled( m_pDocView->GetDoc())) { - return pWidgetAcc->ProcessValidate(); + return pWidgetAcc->ProcessValidate(0); } return XFA_EVENTERROR_Disabled; case XFA_EVENT_InitCalculate: { diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index e76d1af988..c4ecd6db9e 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -160,20 +160,6 @@ CXFA_WidgetAcc::CXFA_WidgetAcc(CXFA_FFDocView* pDocView, CXFA_Node* pNode) CXFA_WidgetAcc::~CXFA_WidgetAcc() {} -bool CXFA_WidgetAcc::GetName(WideString& wsName, int32_t iNameType) { - if (iNameType == 0) { - m_pNode->JSNode()->TryCData(XFA_ATTRIBUTE_Name, wsName, true); - return !wsName.IsEmpty(); - } - m_pNode->GetSOMExpression(wsName); - if (iNameType == 2 && wsName.GetLength() >= 15) { - WideStringView wsPre = L"xfa[0].form[0]."; - if (wsPre == WideStringView(wsName.c_str(), wsPre.GetLength())) - wsName.Delete(0, wsPre.GetLength()); - } - return true; -} - CXFA_Node* CXFA_WidgetAcc::GetDatasets() { return m_pNode->GetBindData(); } @@ -282,20 +268,12 @@ CXFA_WidgetAcc* CXFA_WidgetAcc::GetExclGroup() { return static_cast<CXFA_WidgetAcc*>(pExcl->GetWidgetData()); } -CXFA_FFDocView* CXFA_WidgetAcc::GetDocView() { - return m_pDocView; -} - CXFA_FFDoc* CXFA_WidgetAcc::GetDoc() { return m_pDocView->GetDoc(); } -CXFA_FFApp* CXFA_WidgetAcc::GetApp() { - return GetDoc()->GetApp(); -} - IXFA_AppProvider* CXFA_WidgetAcc::GetAppProvider() { - return GetApp()->GetAppProvider(); + return GetDoc()->GetApp()->GetAppProvider(); } int32_t CXFA_WidgetAcc::ProcessEvent(int32_t iActivity, @@ -363,40 +341,41 @@ int32_t CXFA_WidgetAcc::ProcessCalculate() { void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, int32_t iRet, - CFXJSE_Value* pRetValue, + bool bRetValue, bool bVersionFlag) { - if (iRet == XFA_EVENTERROR_Success && pRetValue) { - if (pRetValue->IsBoolean() && !pRetValue->ToBoolean()) { - IXFA_AppProvider* pAppProvider = GetAppProvider(); - if (!pAppProvider) { - return; - } - WideString wsTitle = pAppProvider->GetAppTitle(); - WideString wsScriptMsg; - validate.GetScriptMessageText(wsScriptMsg); - int32_t eScriptTest = validate.GetScriptTest(); - if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) { - if (GetNode()->IsUserInteractive()) - return; - if (wsScriptMsg.IsEmpty()) - wsScriptMsg = GetValidateMessage(false, bVersionFlag); - - if (bVersionFlag) { - pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_OK); - return; - } - if (pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_YesNo) == XFA_IDYes) { - GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); - } - } else { - if (wsScriptMsg.IsEmpty()) - wsScriptMsg = GetValidateMessage(true, bVersionFlag); - pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); - } + if (iRet != XFA_EVENTERROR_Success) + return; + if (bRetValue) + return; + + IXFA_AppProvider* pAppProvider = GetAppProvider(); + if (!pAppProvider) + return; + + WideString wsTitle = pAppProvider->GetAppTitle(); + WideString wsScriptMsg; + validate.GetScriptMessageText(wsScriptMsg); + int32_t eScriptTest = validate.GetScriptTest(); + if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) { + if (GetNode()->IsUserInteractive()) + return; + if (wsScriptMsg.IsEmpty()) + wsScriptMsg = GetValidateMessage(false, bVersionFlag); + + if (bVersionFlag) { + pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, XFA_MB_OK); + return; + } + if (pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, + XFA_MB_YesNo) == XFA_IDYes) { + GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); } + return; } + + if (wsScriptMsg.IsEmpty()) + wsScriptMsg = GetValidateMessage(true, bVersionFlag); + pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); } int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, @@ -530,7 +509,7 @@ WideString CXFA_WidgetAcc::GetValidateCaptionName(bool bVersionFlag) { } } if (wsCaptionName.IsEmpty()) - GetName(wsCaptionName); + m_pNode->JSNode()->TryCData(XFA_ATTRIBUTE_Name, wsCaptionName, true); return wsCaptionName; } @@ -565,18 +544,17 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { bool bInitDoc = validate.GetNode()->NeedsInitApp(); bool bStatus = m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; int32_t iFormat = 0; - CFXJSE_Value* pRetValue = nullptr; int32_t iRet = XFA_EVENTERROR_NotExist; CXFA_Script script = validate.GetScript(); + bool bRet = false; + bool hasBoolResult = (bInitDoc || bStatus) && GetRawValue().IsEmpty(); if (script) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Validate; eParam.m_pTarget = this; - iRet = ExecuteScript(script, &eParam, - ((bInitDoc || bStatus) && GetRawValue().IsEmpty()) - ? nullptr - : &pRetValue); + std::tie(iRet, bRet) = ExecuteBoolScript(script, &eParam); } + XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); bool bVersionFlag = false; if (version < XFA_VERSION_208) @@ -591,45 +569,54 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag); } - if (iFormat != XFA_EVENTERROR_Success) - ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag); - delete pRetValue; + if (iFormat != XFA_EVENTERROR_Success && hasBoolResult) + ProcessScriptTestValidate(validate, iRet, bRet, bVersionFlag); return iRet | iFormat; } int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, - CXFA_EventParam* pEventParam, - CFXJSE_Value** pRetValue) { + CXFA_EventParam* pEventParam) { + bool bRet; + int32_t iRet; + std::tie(iRet, bRet) = ExecuteBoolScript(script, pEventParam); + return iRet; +} + +std::pair<int32_t, bool> CXFA_WidgetAcc::ExecuteBoolScript( + CXFA_Script script, + CXFA_EventParam* pEventParam) { static const uint32_t MAX_RECURSION_DEPTH = 2; if (m_nRecursionDepth > MAX_RECURSION_DEPTH) - return XFA_EVENTERROR_Success; + return {XFA_EVENTERROR_Success, false}; ASSERT(pEventParam); if (!script) - return XFA_EVENTERROR_NotExist; + return {XFA_EVENTERROR_NotExist, false}; if (script.GetRunAt() == XFA_ATTRIBUTEENUM_Server) - return XFA_EVENTERROR_Disabled; + return {XFA_EVENTERROR_Disabled, false}; WideString wsExpression; script.GetExpression(wsExpression); if (wsExpression.IsEmpty()) - return XFA_EVENTERROR_NotExist; + return {XFA_EVENTERROR_NotExist, false}; XFA_SCRIPTTYPE eScriptType = script.GetContentType(); if (eScriptType == XFA_SCRIPTTYPE_Unkown) - return XFA_EVENTERROR_Success; + return {XFA_EVENTERROR_Success, false}; CXFA_FFDoc* pDoc = GetDoc(); CFXJSE_Engine* pContext = pDoc->GetXFADoc()->GetScriptContext(); pContext->SetEventParam(*pEventParam); pContext->SetRunAtType((XFA_ATTRIBUTEENUM)script.GetRunAt()); + std::vector<CXFA_Node*> refNodes; if (pEventParam->m_eType == XFA_EVENT_InitCalculate || pEventParam->m_eType == XFA_EVENT_Calculate) { pContext->SetNodesOfRunScript(&refNodes); } + auto pTmpRetValue = pdfium::MakeUnique<CFXJSE_Value>(pContext->GetRuntime()); ++m_nRecursionDepth; bool bRet = pContext->RunScript((XFA_SCRIPTLANGTYPE)eScriptType, @@ -672,11 +659,9 @@ int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, } } } - if (pRetValue) - *pRetValue = pTmpRetValue.release(); - pContext->SetNodesOfRunScript(nullptr); - return iRet; + + return {iRet, pTmpRetValue->IsBoolean() ? pTmpRetValue->ToBoolean() : false}; } CXFA_FFWidget* CXFA_WidgetAcc::GetNextWidget(CXFA_FFWidget* pWidget) { @@ -1493,10 +1478,6 @@ void CXFA_WidgetAcc::SetImageEditImage( pData->m_pDIBitmap = newImage; } -CXFA_WidgetLayoutData* CXFA_WidgetAcc::GetWidgetLayoutData() { - return m_pLayoutData.get(); -} - RetainPtr<CFGAS_GEFont> CXFA_WidgetAcc::GetFDEFont() { WideStringView wsFontName = L"Courier"; uint32_t dwFontStyle = 0; diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index be26b94806..d1aa1df5c6 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -8,6 +8,7 @@ #define XFA_FXFA_CXFA_WIDGETACC_H_ #include <memory> +#include <utility> #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/retain_ptr.h" @@ -37,41 +38,40 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { CXFA_WidgetAcc(CXFA_FFDocView* pDocView, CXFA_Node* pNode); ~CXFA_WidgetAcc(); - bool GetName(WideString& wsName, int32_t iNameType = 0); - bool ProcessValueChanged(); void ResetData(); - void SetImageEdit(const WideString& wsContentType, - const WideString& wsHref, - const WideString& wsData); - CXFA_WidgetAcc* GetExclGroup(); - CXFA_FFDocView* GetDocView(); CXFA_FFDoc* GetDoc(); - CXFA_FFApp* GetApp(); - IXFA_AppProvider* GetAppProvider(); + bool ProcessValueChanged(); int32_t ProcessEvent(int32_t iActivity, CXFA_EventParam* pEventParam); int32_t ProcessEvent(const CXFA_Event& event, CXFA_EventParam* pEventParam); int32_t ProcessCalculate(); - int32_t ProcessValidate(int32_t iFlags = 0); - int32_t ExecuteScript(CXFA_Script script, - CXFA_EventParam* pEventParam, - CFXJSE_Value** pRetValue = nullptr); + int32_t ProcessValidate(int32_t iFlags); + int32_t ExecuteScript(CXFA_Script script, CXFA_EventParam* pEventParam); + std::pair<int32_t, bool> ExecuteBoolScript(CXFA_Script script, + CXFA_EventParam* pEventParam); CXFA_FFWidget* GetNextWidget(CXFA_FFWidget* pWidget); void StartWidgetLayout(float& fCalcWidth, float& fCalcHeight); bool FindSplitPos(int32_t iBlockIndex, float& fCalcHeight); + bool LoadCaption(); + CXFA_TextLayout* GetCaptionTextLayout(); + void LoadText(); + CXFA_TextLayout* GetTextLayout(); + bool LoadImageImage(); bool LoadImageEditImage(); void GetImageDpi(int32_t& iImageXDpi, int32_t& iImageYDpi); void GetImageEditDpi(int32_t& iImageXDpi, int32_t& iImageYDpi); - CXFA_TextLayout* GetCaptionTextLayout(); - CXFA_TextLayout* GetTextLayout(); + RetainPtr<CFX_DIBitmap> GetImageImage(); RetainPtr<CFX_DIBitmap> GetImageEditImage(); + void SetImageEdit(const WideString& wsContentType, + const WideString& wsHref, + const WideString& wsData); void SetImageImage(const RetainPtr<CFX_DIBitmap>& newImage); void SetImageEditImage(const RetainPtr<CFX_DIBitmap>& newImage); void UpdateUIDisplay(CXFA_FFWidget* pExcept = nullptr); @@ -81,12 +81,12 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { float GetFontSize(); FX_ARGB GetTextColor(); float GetLineHeight(); - CXFA_WidgetLayoutData* GetWidgetLayoutData(); private: + IXFA_AppProvider* GetAppProvider(); void ProcessScriptTestValidate(CXFA_Validate validate, int32_t iRet, - CFXJSE_Value* pRetValue, + bool pRetValue, bool bVersionFlag); int32_t ProcessFormatTestValidate(CXFA_Validate validate, bool bVersionFlag); int32_t ProcessNullTestValidate(CXFA_Validate validate, |