From 71335de2577ae27d00f03aeb007bf6b9c90d9391 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 7 Nov 2017 21:27:00 +0000 Subject: Rename CXFA_Script to CXFA_ScriptData This CL renames CXFA_Script to CXFA_ScriptData to show it is part of the data hierarchy. Change-Id: Idba3618af6a95eae2ff4541184e5a17f1457e1cb Reviewed-on: https://pdfium-review.googlesource.com/18012 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- BUILD.gn | 4 ++-- xfa/fxfa/cxfa_ffdocview.cpp | 4 +--- xfa/fxfa/cxfa_fffield.cpp | 6 +++--- xfa/fxfa/cxfa_ffnotify.cpp | 2 +- xfa/fxfa/cxfa_ffwidgethandler.cpp | 6 +++--- xfa/fxfa/cxfa_widgetacc.cpp | 27 +++++++++++++-------------- xfa/fxfa/cxfa_widgetacc.h | 7 ++++--- xfa/fxfa/parser/cxfa_calculatedata.cpp | 4 ++-- xfa/fxfa/parser/cxfa_calculatedata.h | 4 ++-- xfa/fxfa/parser/cxfa_eventdata.cpp | 4 ++-- xfa/fxfa/parser/cxfa_eventdata.h | 4 ++-- xfa/fxfa/parser/cxfa_script.cpp | 31 ------------------------------- xfa/fxfa/parser/cxfa_script.h | 32 -------------------------------- xfa/fxfa/parser/cxfa_scriptdata.cpp | 31 +++++++++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_scriptdata.h | 32 ++++++++++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_validate.cpp | 4 ++-- xfa/fxfa/parser/cxfa_validate.h | 4 ++-- 17 files changed, 102 insertions(+), 104 deletions(-) delete mode 100644 xfa/fxfa/parser/cxfa_script.cpp delete mode 100644 xfa/fxfa/parser/cxfa_script.h create mode 100644 xfa/fxfa/parser/cxfa_scriptdata.cpp create mode 100644 xfa/fxfa/parser/cxfa_scriptdata.h diff --git a/BUILD.gn b/BUILD.gn index e64fe8a11a..508b748a98 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1863,8 +1863,8 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_paradata.cpp", "xfa/fxfa/parser/cxfa_paradata.h", "xfa/fxfa/parser/cxfa_rectangledata.h", - "xfa/fxfa/parser/cxfa_script.cpp", - "xfa/fxfa/parser/cxfa_script.h", + "xfa/fxfa/parser/cxfa_scriptdata.cpp", + "xfa/fxfa/parser/cxfa_scriptdata.h", "xfa/fxfa/parser/cxfa_simple_parser.cpp", "xfa/fxfa/parser/cxfa_simple_parser.h", "xfa/fxfa/parser/cxfa_stroke.cpp", diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index ae277f05e4..d39f7f48be 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -417,9 +417,7 @@ static int32_t XFA_ProcessEvent(CXFA_FFDocView* pDocView, return XFA_EVENTERROR_NotExist; if (pWidgetAcc->GetNode()->IsUserInteractive()) return XFA_EVENTERROR_Disabled; - - CXFA_Script script = calcData.GetScript(); - return pWidgetAcc->ExecuteScript(script, pParam); + return pWidgetAcc->ExecuteScript(calcData.GetScriptData(), pParam); } default: break; diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index 010af86897..67a4cb1aca 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -682,12 +682,12 @@ int32_t CXFA_FFField::CalculateWidgetAcc(CXFA_WidgetAcc* pAcc) { } case XFA_ATTRIBUTEENUM_Warning: { if (version <= XFA_VERSION_204) { - CXFA_Script script = calcData.GetScript(); - if (!script) + CXFA_ScriptData scriptData = calcData.GetScriptData(); + if (!scriptData) return 1; WideString wsExpression; - script.GetExpression(wsExpression); + scriptData.GetExpression(wsExpression); if (wsExpression.IsEmpty()) return 1; } diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index 3cad913d0a..9c2f475e51 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -221,7 +221,7 @@ bool CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) { int32_t iRet; bool bRet; std::tie(iRet, bRet) = - pWidgetAcc->ExecuteBoolScript(CXFA_Script(pScript), &EventParam); + pWidgetAcc->ExecuteBoolScript(CXFA_ScriptData(pScript), &EventParam); return iRet == XFA_EVENTERROR_Success && bRet; } diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp index 7de7d27748..9ab19623c2 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -190,11 +190,11 @@ bool CXFA_FFWidgetHandler::HasEvent(CXFA_WidgetAcc* pWidgetAcc, switch (eEventType) { case XFA_EVENT_Calculate: { CXFA_CalculateData calcData = pWidgetAcc->GetCalculateData(); - return calcData && calcData.GetScript(); + return calcData && calcData.GetScriptData(); } case XFA_EVENT_Validate: { CXFA_Validate val = pWidgetAcc->GetValidate(false); - return val && val.GetScript(); + return val && val.GetScriptData(); } default: break; @@ -226,7 +226,7 @@ int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, if (pWidgetAcc->GetNode()->IsUserInteractive()) return XFA_EVENTERROR_Disabled; - CXFA_Script script = calcData.GetScript(); + CXFA_ScriptData script = calcData.GetScriptData(); return pWidgetAcc->ExecuteScript(script, pParam); } default: diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 681ecbf0f8..59df6c9f4d 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -306,7 +306,7 @@ int32_t CXFA_WidgetAcc::ProcessEvent(const CXFA_EventData& eventData, case XFA_Element::Execute: break; case XFA_Element::Script: - return ExecuteScript(eventData.GetScript(), pEventParam); + return ExecuteScript(eventData.GetScriptData(), pEventParam); case XFA_Element::SignData: break; case XFA_Element::Submit: @@ -330,8 +330,7 @@ int32_t CXFA_WidgetAcc::ProcessCalculate() { CXFA_EventParam EventParam; EventParam.m_eType = XFA_EVENT_Calculate; - CXFA_Script script = calcData.GetScript(); - int32_t iRet = ExecuteScript(script, &EventParam); + int32_t iRet = ExecuteScript(calcData.GetScriptData(), &EventParam); if (iRet != XFA_EVENTERROR_Success) return iRet; @@ -548,14 +547,14 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { bool bStatus = m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; int32_t iFormat = 0; int32_t iRet = XFA_EVENTERROR_NotExist; - CXFA_Script script = validate.GetScript(); + CXFA_ScriptData scriptData = validate.GetScriptData(); bool bRet = false; bool hasBoolResult = (bInitDoc || bStatus) && GetRawValue().IsEmpty(); - if (script) { + if (scriptData) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Validate; eParam.m_pTarget = this; - std::tie(iRet, bRet) = ExecuteBoolScript(script, &eParam); + std::tie(iRet, bRet) = ExecuteBoolScript(scriptData, &eParam); } XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); @@ -579,40 +578,40 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { return iRet | iFormat; } -int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, +int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_ScriptData scriptData, CXFA_EventParam* pEventParam) { bool bRet; int32_t iRet; - std::tie(iRet, bRet) = ExecuteBoolScript(script, pEventParam); + std::tie(iRet, bRet) = ExecuteBoolScript(scriptData, pEventParam); return iRet; } std::pair CXFA_WidgetAcc::ExecuteBoolScript( - CXFA_Script script, + CXFA_ScriptData scriptData, CXFA_EventParam* pEventParam) { static const uint32_t MAX_RECURSION_DEPTH = 2; if (m_nRecursionDepth > MAX_RECURSION_DEPTH) return {XFA_EVENTERROR_Success, false}; ASSERT(pEventParam); - if (!script) + if (!scriptData) return {XFA_EVENTERROR_NotExist, false}; - if (script.GetRunAt() == XFA_ATTRIBUTEENUM_Server) + if (scriptData.GetRunAt() == XFA_ATTRIBUTEENUM_Server) return {XFA_EVENTERROR_Disabled, false}; WideString wsExpression; - script.GetExpression(wsExpression); + scriptData.GetExpression(wsExpression); if (wsExpression.IsEmpty()) return {XFA_EVENTERROR_NotExist, false}; - XFA_SCRIPTTYPE eScriptType = script.GetContentType(); + XFA_SCRIPTTYPE eScriptType = scriptData.GetContentType(); if (eScriptType == XFA_SCRIPTTYPE_Unkown) return {XFA_EVENTERROR_Success, false}; CXFA_FFDoc* pDoc = GetDoc(); CFXJSE_Engine* pContext = pDoc->GetXFADoc()->GetScriptContext(); pContext->SetEventParam(*pEventParam); - pContext->SetRunAtType((XFA_ATTRIBUTEENUM)script.GetRunAt()); + pContext->SetRunAtType((XFA_ATTRIBUTEENUM)scriptData.GetRunAt()); std::vector refNodes; if (pEventParam->m_eType == XFA_EVENT_InitCalculate || diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index 8b750a2b9e..9191ac963c 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -18,7 +18,7 @@ #include "xfa/fxfa/parser/cxfa_eventdata.h" #include "xfa/fxfa/parser/cxfa_imagedata.h" #include "xfa/fxfa/parser/cxfa_margindata.h" -#include "xfa/fxfa/parser/cxfa_script.h" +#include "xfa/fxfa/parser/cxfa_scriptdata.h" #include "xfa/fxfa/parser/cxfa_value.h" #include "xfa/fxfa/parser/cxfa_widgetdata.h" @@ -49,8 +49,9 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { CXFA_EventParam* pEventParam); int32_t ProcessCalculate(); int32_t ProcessValidate(int32_t iFlags); - int32_t ExecuteScript(CXFA_Script script, CXFA_EventParam* pEventParam); - std::pair ExecuteBoolScript(CXFA_Script script, + int32_t ExecuteScript(CXFA_ScriptData scriptData, + CXFA_EventParam* pEventParam); + std::pair ExecuteBoolScript(CXFA_ScriptData scriptData, CXFA_EventParam* pEventParam); CXFA_FFWidget* GetNextWidget(CXFA_FFWidget* pWidget); diff --git a/xfa/fxfa/parser/cxfa_calculatedata.cpp b/xfa/fxfa/parser/cxfa_calculatedata.cpp index 1db5779486..599ffe3c8f 100644 --- a/xfa/fxfa/parser/cxfa_calculatedata.cpp +++ b/xfa/fxfa/parser/cxfa_calculatedata.cpp @@ -17,8 +17,8 @@ int32_t CXFA_CalculateData::GetOverride() { return eAtt; } -CXFA_Script CXFA_CalculateData::GetScript() { - return CXFA_Script(m_pNode->GetChild(0, XFA_Element::Script, false)); +CXFA_ScriptData CXFA_CalculateData::GetScriptData() { + return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); } void CXFA_CalculateData::GetMessageText(WideString& wsMessage) { diff --git a/xfa/fxfa/parser/cxfa_calculatedata.h b/xfa/fxfa/parser/cxfa_calculatedata.h index 0c1a8220c1..d610e1bbce 100644 --- a/xfa/fxfa/parser/cxfa_calculatedata.h +++ b/xfa/fxfa/parser/cxfa_calculatedata.h @@ -9,7 +9,7 @@ #include "core/fxcrt/fx_string.h" #include "xfa/fxfa/parser/cxfa_data.h" -#include "xfa/fxfa/parser/cxfa_script.h" +#include "xfa/fxfa/parser/cxfa_scriptdata.h" class CXFA_Node; @@ -18,7 +18,7 @@ class CXFA_CalculateData : public CXFA_Data { explicit CXFA_CalculateData(CXFA_Node* pNode); int32_t GetOverride(); - CXFA_Script GetScript(); + CXFA_ScriptData GetScriptData(); void GetMessageText(WideString& wsMessage); }; diff --git a/xfa/fxfa/parser/cxfa_eventdata.cpp b/xfa/fxfa/parser/cxfa_eventdata.cpp index 5b48df6d88..22943216c4 100644 --- a/xfa/fxfa/parser/cxfa_eventdata.cpp +++ b/xfa/fxfa/parser/cxfa_eventdata.cpp @@ -30,8 +30,8 @@ void CXFA_EventData::GetRef(WideStringView& wsRef) { m_pNode->JSNode()->TryCData(XFA_ATTRIBUTE_Ref, wsRef, true); } -CXFA_Script CXFA_EventData::GetScript() const { - return CXFA_Script(m_pNode->GetChild(0, XFA_Element::Script, false)); +CXFA_ScriptData CXFA_EventData::GetScriptData() const { + return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); } CXFA_Submit CXFA_EventData::GetSubmit() const { diff --git a/xfa/fxfa/parser/cxfa_eventdata.h b/xfa/fxfa/parser/cxfa_eventdata.h index b6fdc48e99..e9a79f008f 100644 --- a/xfa/fxfa/parser/cxfa_eventdata.h +++ b/xfa/fxfa/parser/cxfa_eventdata.h @@ -11,7 +11,7 @@ #include "core/fxcrt/fx_string.h" #include "xfa/fxfa/parser/cxfa_data.h" -#include "xfa/fxfa/parser/cxfa_script.h" +#include "xfa/fxfa/parser/cxfa_scriptdata.h" #include "xfa/fxfa/parser/cxfa_submit.h" class CXFA_Node; @@ -22,7 +22,7 @@ class CXFA_EventData : public CXFA_Data { int32_t GetActivity(); XFA_Element GetEventType() const; - CXFA_Script GetScript() const; + CXFA_ScriptData GetScriptData() const; CXFA_Submit GetSubmit() const; void GetRef(WideStringView& wsRef); void GetSignDataTarget(WideString& wsTarget); diff --git a/xfa/fxfa/parser/cxfa_script.cpp b/xfa/fxfa/parser/cxfa_script.cpp deleted file mode 100644 index fcb0f95af1..0000000000 --- a/xfa/fxfa/parser/cxfa_script.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/cxfa_script.h" - -#include "xfa/fxfa/parser/cxfa_node.h" - -CXFA_Script::CXFA_Script(CXFA_Node* pNode) : CXFA_Data(pNode) {} - -XFA_SCRIPTTYPE CXFA_Script::GetContentType() { - WideStringView cData; - if (m_pNode->JSNode()->TryCData(XFA_ATTRIBUTE_ContentType, cData, false)) { - if (cData == L"application/x-javascript") - return XFA_SCRIPTTYPE_Javascript; - if (cData == L"application/x-formcalc") - return XFA_SCRIPTTYPE_Formcalc; - return XFA_SCRIPTTYPE_Unkown; - } - return XFA_SCRIPTTYPE_Formcalc; -} - -int32_t CXFA_Script::GetRunAt() { - return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_RunAt); -} - -void CXFA_Script::GetExpression(WideString& wsExpression) { - m_pNode->JSNode()->TryContent(wsExpression, false, true); -} diff --git a/xfa/fxfa/parser/cxfa_script.h b/xfa/fxfa/parser/cxfa_script.h deleted file mode 100644 index bb98f58abc..0000000000 --- a/xfa/fxfa/parser/cxfa_script.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_CXFA_SCRIPT_H_ -#define XFA_FXFA_PARSER_CXFA_SCRIPT_H_ - -#include - -#include "core/fxcrt/fx_string.h" -#include "xfa/fxfa/parser/cxfa_data.h" - -enum XFA_SCRIPTTYPE { - XFA_SCRIPTTYPE_Formcalc = 0, - XFA_SCRIPTTYPE_Javascript, - XFA_SCRIPTTYPE_Unkown, -}; - -class CXFA_Node; - -class CXFA_Script : public CXFA_Data { - public: - explicit CXFA_Script(CXFA_Node* pNode); - - XFA_SCRIPTTYPE GetContentType(); - int32_t GetRunAt(); - void GetExpression(WideString& wsExpression); -}; - -#endif // XFA_FXFA_PARSER_CXFA_SCRIPT_H_ diff --git a/xfa/fxfa/parser/cxfa_scriptdata.cpp b/xfa/fxfa/parser/cxfa_scriptdata.cpp new file mode 100644 index 0000000000..4f17a8394a --- /dev/null +++ b/xfa/fxfa/parser/cxfa_scriptdata.cpp @@ -0,0 +1,31 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_scriptdata.h" + +#include "xfa/fxfa/parser/cxfa_node.h" + +CXFA_ScriptData::CXFA_ScriptData(CXFA_Node* pNode) : CXFA_Data(pNode) {} + +XFA_SCRIPTTYPE CXFA_ScriptData::GetContentType() { + WideStringView cData; + if (m_pNode->JSNode()->TryCData(XFA_ATTRIBUTE_ContentType, cData, false)) { + if (cData == L"application/x-javascript") + return XFA_SCRIPTTYPE_Javascript; + if (cData == L"application/x-formcalc") + return XFA_SCRIPTTYPE_Formcalc; + return XFA_SCRIPTTYPE_Unkown; + } + return XFA_SCRIPTTYPE_Formcalc; +} + +int32_t CXFA_ScriptData::GetRunAt() { + return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_RunAt); +} + +void CXFA_ScriptData::GetExpression(WideString& wsExpression) { + m_pNode->JSNode()->TryContent(wsExpression, false, true); +} diff --git a/xfa/fxfa/parser/cxfa_scriptdata.h b/xfa/fxfa/parser/cxfa_scriptdata.h new file mode 100644 index 0000000000..f7b8d741fc --- /dev/null +++ b/xfa/fxfa/parser/cxfa_scriptdata.h @@ -0,0 +1,32 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_SCRIPTDATA_H_ +#define XFA_FXFA_PARSER_CXFA_SCRIPTDATA_H_ + +#include + +#include "core/fxcrt/fx_string.h" +#include "xfa/fxfa/parser/cxfa_data.h" + +enum XFA_SCRIPTTYPE { + XFA_SCRIPTTYPE_Formcalc = 0, + XFA_SCRIPTTYPE_Javascript, + XFA_SCRIPTTYPE_Unkown, +}; + +class CXFA_Node; + +class CXFA_ScriptData : public CXFA_Data { + public: + explicit CXFA_ScriptData(CXFA_Node* pNode); + + XFA_SCRIPTTYPE GetContentType(); + int32_t GetRunAt(); + void GetExpression(WideString& wsExpression); +}; + +#endif // XFA_FXFA_PARSER_CXFA_SCRIPTDATA_H_ diff --git a/xfa/fxfa/parser/cxfa_validate.cpp b/xfa/fxfa/parser/cxfa_validate.cpp index 2f97a02a51..2f38d82290 100644 --- a/xfa/fxfa/parser/cxfa_validate.cpp +++ b/xfa/fxfa/parser/cxfa_validate.cpp @@ -110,6 +110,6 @@ void CXFA_Validate::GetPicture(WideString& wsPicture) { pNode->JSNode()->TryContent(wsPicture, false, true); } -CXFA_Script CXFA_Validate::GetScript() { - return CXFA_Script(m_pNode->GetChild(0, XFA_Element::Script, false)); +CXFA_ScriptData CXFA_Validate::GetScriptData() { + return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); } diff --git a/xfa/fxfa/parser/cxfa_validate.h b/xfa/fxfa/parser/cxfa_validate.h index ebe3eaee56..bf6b807b7e 100644 --- a/xfa/fxfa/parser/cxfa_validate.h +++ b/xfa/fxfa/parser/cxfa_validate.h @@ -10,7 +10,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "xfa/fxfa/parser/cxfa_data.h" -#include "xfa/fxfa/parser/cxfa_script.h" +#include "xfa/fxfa/parser/cxfa_scriptdata.h" class CXFA_Node; @@ -29,7 +29,7 @@ class CXFA_Validate : public CXFA_Data { void GetScriptMessageText(WideString& wsMessage); void SetScriptMessageText(WideString wsMessage); void GetPicture(WideString& wsPicture); - CXFA_Script GetScript(); + CXFA_ScriptData GetScriptData(); private: void GetMessageText(WideString& wsMessage, const WideString& wsMessageType); -- cgit v1.2.3