From 255e61ed20e42917e0055710fb5be56b2ad40afc Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 7 Nov 2017 21:42:05 +0000 Subject: Rename CXFA_Validate to CXFA_ValidateData This CL renames CXFA_Validate to CXFA_ValidateData to signify it is part of the data hierarchy. Change-Id: Ib6f743513160990b6d64c4b10618f16554dc5c08 Reviewed-on: https://pdfium-review.googlesource.com/18017 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- BUILD.gn | 4 +- fxjs/cjx_node.cpp | 28 ++++----- xfa/fxfa/cxfa_ffdocview.cpp | 4 +- xfa/fxfa/cxfa_ffwidgethandler.cpp | 4 +- xfa/fxfa/cxfa_widgetacc.cpp | 39 ++++++------ xfa/fxfa/cxfa_widgetacc.h | 7 ++- xfa/fxfa/parser/cxfa_validate.cpp | 115 ---------------------------------- xfa/fxfa/parser/cxfa_validate.h | 39 ------------ xfa/fxfa/parser/cxfa_validatedata.cpp | 115 ++++++++++++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_validatedata.h | 39 ++++++++++++ xfa/fxfa/parser/cxfa_widgetdata.cpp | 4 +- xfa/fxfa/parser/cxfa_widgetdata.h | 4 +- 12 files changed, 202 insertions(+), 200 deletions(-) delete mode 100644 xfa/fxfa/parser/cxfa_validate.cpp delete mode 100644 xfa/fxfa/parser/cxfa_validate.h create mode 100644 xfa/fxfa/parser/cxfa_validatedata.cpp create mode 100644 xfa/fxfa/parser/cxfa_validatedata.h diff --git a/BUILD.gn b/BUILD.gn index 6df5f9c4a7..7f7ea5b324 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1884,8 +1884,8 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_traversestrategy_layoutitem.h", "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h", "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h", - "xfa/fxfa/parser/cxfa_validate.cpp", - "xfa/fxfa/parser/cxfa_validate.h", + "xfa/fxfa/parser/cxfa_validatedata.cpp", + "xfa/fxfa/parser/cxfa_validatedata.h", "xfa/fxfa/parser/cxfa_value.cpp", "xfa/fxfa/parser/cxfa_value.h", "xfa/fxfa/parser/cxfa_valuearray.cpp", diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 2422a0f9b6..1e76790f54 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -1355,21 +1355,21 @@ void CJX_Node::Script_Som_Message(CFXJSE_Value* pValue, return; } bool bNew = false; - CXFA_Validate validate = pWidgetData->GetValidate(false); - if (!validate) { - validate = pWidgetData->GetValidate(true); + CXFA_ValidateData validateData = pWidgetData->GetValidateData(false); + if (!validateData) { + validateData = pWidgetData->GetValidateData(true); bNew = true; } if (bSetting) { switch (iMessageType) { case XFA_SOM_ValidationMessage: - validate.SetScriptMessageText(pValue->ToWideString()); + validateData.SetScriptMessageText(pValue->ToWideString()); break; case XFA_SOM_FormatMessage: - validate.SetFormatMessageText(pValue->ToWideString()); + validateData.SetFormatMessageText(pValue->ToWideString()); break; case XFA_SOM_MandatoryMessage: - validate.SetNullMessageText(pValue->ToWideString()); + validateData.SetNullMessageText(pValue->ToWideString()); break; default: break; @@ -1385,13 +1385,13 @@ void CJX_Node::Script_Som_Message(CFXJSE_Value* pValue, WideString wsMessage; switch (iMessageType) { case XFA_SOM_ValidationMessage: - validate.GetScriptMessageText(wsMessage); + validateData.GetScriptMessageText(wsMessage); break; case XFA_SOM_FormatMessage: - validate.GetFormatMessageText(wsMessage); + validateData.GetFormatMessageText(wsMessage); break; case XFA_SOM_MandatoryMessage: - validate.GetNullMessageText(wsMessage); + validateData.GetNullMessageText(wsMessage); break; default: break; @@ -1789,14 +1789,14 @@ void CJX_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) { + if (!pWidgetData) return; - } - CXFA_Validate validate = pWidgetData->GetValidate(true); + + CXFA_ValidateData validateData = pWidgetData->GetValidateData(true); if (bSetting) { - validate.SetNullTest(pValue->ToWideString()); + validateData.SetNullTest(pValue->ToWideString()); } else { - int32_t iValue = validate.GetNullTest(); + int32_t iValue = validateData.GetNullTest(); const XFA_ATTRIBUTEENUMINFO* pInfo = GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); WideString wsValue; diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index 1779b9e2f0..57cd7d2f95 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -225,9 +225,9 @@ bool CXFA_FFDocView::ResetSingleWidgetAccData(CXFA_WidgetAcc* pWidgetAcc) { pWidgetAcc->ResetData(); pWidgetAcc->UpdateUIDisplay(); - if (CXFA_Validate validate = pWidgetAcc->GetValidate(false)) { + if (CXFA_ValidateData validateData = pWidgetAcc->GetValidateData(false)) { AddValidateWidget(pWidgetAcc); - validate.GetNode()->SetFlag(XFA_NodeFlag_NeedsInitApp, false); + validateData.GetNode()->SetFlag(XFA_NodeFlag_NeedsInitApp, false); } return true; } diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp index 9ab19623c2..4a2bf08222 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -193,8 +193,8 @@ bool CXFA_FFWidgetHandler::HasEvent(CXFA_WidgetAcc* pWidgetAcc, return calcData && calcData.GetScriptData(); } case XFA_EVENT_Validate: { - CXFA_Validate val = pWidgetAcc->GetValidate(false); - return val && val.GetScriptData(); + CXFA_ValidateData validateData = pWidgetAcc->GetValidateData(false); + return validateData && validateData.GetScriptData(); } default: break; diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index e9ccaaa218..1e005791a2 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -341,7 +341,7 @@ int32_t CXFA_WidgetAcc::ProcessCalculate() { return XFA_EVENTERROR_Success; } -void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, +void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_ValidateData validateData, int32_t iRet, bool bRetValue, bool bVersionFlag) { @@ -356,8 +356,8 @@ void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, WideString wsTitle = pAppProvider->GetAppTitle(); WideString wsScriptMsg; - validate.GetScriptMessageText(wsScriptMsg); - int32_t eScriptTest = validate.GetScriptTest(); + validateData.GetScriptMessageText(wsScriptMsg); + int32_t eScriptTest = validateData.GetScriptTest(); if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) { if (GetNode()->IsUserInteractive()) return; @@ -380,12 +380,13 @@ void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); } -int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, - bool bVersionFlag) { +int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( + CXFA_ValidateData validateData, + bool bVersionFlag) { WideString wsRawValue = GetRawValue(); if (!wsRawValue.IsEmpty()) { WideString wsPicture; - validate.GetPicture(wsPicture); + validateData.GetPicture(wsPicture); if (wsPicture.IsEmpty()) return XFA_EVENTERROR_NotExist; @@ -401,9 +402,9 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, return XFA_EVENTERROR_NotExist; WideString wsFormatMsg; - validate.GetFormatMessageText(wsFormatMsg); + validateData.GetFormatMessageText(wsFormatMsg); WideString wsTitle = pAppProvider->GetAppTitle(); - int32_t eFormatTest = validate.GetFormatTest(); + int32_t eFormatTest = validateData.GetFormatTest(); if (eFormatTest == XFA_ATTRIBUTEENUM_Error) { if (wsFormatMsg.IsEmpty()) wsFormatMsg = GetValidateMessage(true, bVersionFlag); @@ -430,7 +431,7 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, return XFA_EVENTERROR_NotExist; } -int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate validate, +int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_ValidateData validateData, int32_t iFlags, bool bVersionFlag) { WideString wsValue; @@ -440,9 +441,9 @@ int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate validate, if (m_bIsNull && (m_bPreNull == m_bIsNull)) return XFA_EVENTERROR_Success; - int32_t eNullTest = validate.GetNullTest(); + int32_t eNullTest = validateData.GetNullTest(); WideString wsNullMsg; - validate.GetNullMessageText(wsNullMsg); + validateData.GetNullMessageText(wsNullMsg); if (iFlags & 0x01) { int32_t iRet = XFA_EVENTERROR_Success; if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) @@ -539,15 +540,15 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { if (GetElementType() == XFA_Element::Draw) return XFA_EVENTERROR_NotExist; - CXFA_Validate validate = GetValidate(false); - if (!validate) + CXFA_ValidateData validateData = GetValidateData(false); + if (!validateData) return XFA_EVENTERROR_NotExist; - bool bInitDoc = validate.GetNode()->NeedsInitApp(); + bool bInitDoc = validateData.GetNode()->NeedsInitApp(); bool bStatus = m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; int32_t iFormat = 0; int32_t iRet = XFA_EVENTERROR_NotExist; - CXFA_ScriptData scriptData = validate.GetScriptData(); + CXFA_ScriptData scriptData = validateData.GetScriptData(); bool bRet = false; bool hasBoolResult = (bInitDoc || bStatus) && GetRawValue().IsEmpty(); if (scriptData) { @@ -563,17 +564,17 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { bVersionFlag = true; if (bInitDoc) { - validate.GetNode()->ClearFlag(XFA_NodeFlag_NeedsInitApp); + validateData.GetNode()->ClearFlag(XFA_NodeFlag_NeedsInitApp); } else { - iFormat = ProcessFormatTestValidate(validate, bVersionFlag); + iFormat = ProcessFormatTestValidate(validateData, bVersionFlag); if (!bVersionFlag) bVersionFlag = GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting); - iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag); + iRet |= ProcessNullTestValidate(validateData, iFlags, bVersionFlag); } if (iFormat != XFA_EVENTERROR_Success && hasBoolResult) - ProcessScriptTestValidate(validate, iRet, bRet, bVersionFlag); + ProcessScriptTestValidate(validateData, iRet, bRet, bVersionFlag); return iRet | iFormat; } diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index 9191ac963c..036a6734b2 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -86,12 +86,13 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { private: IXFA_AppProvider* GetAppProvider(); - void ProcessScriptTestValidate(CXFA_Validate validate, + void ProcessScriptTestValidate(CXFA_ValidateData validateData, int32_t iRet, bool pRetValue, bool bVersionFlag); - int32_t ProcessFormatTestValidate(CXFA_Validate validate, bool bVersionFlag); - int32_t ProcessNullTestValidate(CXFA_Validate validate, + int32_t ProcessFormatTestValidate(CXFA_ValidateData validateData, + bool bVersionFlag); + int32_t ProcessNullTestValidate(CXFA_ValidateData validateData, int32_t iFlags, bool bVersionFlag); WideString GetValidateCaptionName(bool bVersionFlag); diff --git a/xfa/fxfa/parser/cxfa_validate.cpp b/xfa/fxfa/parser/cxfa_validate.cpp deleted file mode 100644 index 2f38d82290..0000000000 --- a/xfa/fxfa/parser/cxfa_validate.cpp +++ /dev/null @@ -1,115 +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_validate.h" - -#include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CXFA_Validate::CXFA_Validate(CXFA_Node* pNode) : CXFA_Data(pNode) {} - -int32_t CXFA_Validate::GetFormatTest() { - return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_FormatTest); -} - -bool CXFA_Validate::SetNullTest(WideString wsValue) { - const XFA_ATTRIBUTEENUMINFO* pInfo = - XFA_GetAttributeEnumByName(wsValue.AsStringView()); - m_pNode->JSNode()->SetEnum(XFA_ATTRIBUTE_NullTest, - pInfo ? pInfo->eName : XFA_ATTRIBUTEENUM_Disabled, - false); - return true; -} - -int32_t CXFA_Validate::GetNullTest() { - return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_NullTest); -} - -int32_t CXFA_Validate::GetScriptTest() { - return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_ScriptTest); -} - -void CXFA_Validate::GetMessageText(WideString& wsMessage, - const WideString& wsMessageType) { - CXFA_Node* pNode = - m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, false); - if (!pNode) - return; - - CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItemNode; - pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItemNode->GetElementType() != XFA_Element::Text) - continue; - - WideStringView wsName; - pItemNode->JSNode()->TryCData(XFA_ATTRIBUTE_Name, wsName, true); - if (wsName.IsEmpty() || wsName == wsMessageType) { - pItemNode->JSNode()->TryContent(wsMessage, false, true); - return; - } - } -} - -void CXFA_Validate::SetFormatMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"formatTest"); -} - -void CXFA_Validate::GetFormatMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"formatTest"); -} - -void CXFA_Validate::SetNullMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"nullTest"); -} - -void CXFA_Validate::GetNullMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"nullTest"); -} - -void CXFA_Validate::SetMessageText(WideString& wsMessage, - const WideString& wsMessageType) { - CXFA_Node* pNode = - m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, true); - if (!pNode) - return; - - CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItemNode; - pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItemNode->GetElementType() != XFA_Element::Text) - continue; - - WideStringView wsName; - pItemNode->JSNode()->TryCData(XFA_ATTRIBUTE_Name, wsName, true); - if (wsName.IsEmpty() || wsName == wsMessageType) { - pItemNode->JSNode()->SetContent(wsMessage, wsMessage, false, false, true); - return; - } - } - CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text); - pNode->InsertChild(pTextNode, nullptr); - pTextNode->JSNode()->SetCData(XFA_ATTRIBUTE_Name, wsMessageType, false, - false); - pTextNode->JSNode()->SetContent(wsMessage, wsMessage, false, false, true); -} - -void CXFA_Validate::GetScriptMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"scriptTest"); -} - -void CXFA_Validate::SetScriptMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"scriptTest"); -} - -void CXFA_Validate::GetPicture(WideString& wsPicture) { - if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false)) - pNode->JSNode()->TryContent(wsPicture, false, true); -} - -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 deleted file mode 100644 index bf6b807b7e..0000000000 --- a/xfa/fxfa/parser/cxfa_validate.h +++ /dev/null @@ -1,39 +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_VALIDATE_H_ -#define XFA_FXFA_PARSER_CXFA_VALIDATE_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fxfa/parser/cxfa_data.h" -#include "xfa/fxfa/parser/cxfa_scriptdata.h" - -class CXFA_Node; - -class CXFA_Validate : public CXFA_Data { - public: - explicit CXFA_Validate(CXFA_Node* pNode); - - int32_t GetFormatTest(); - int32_t GetNullTest(); - bool SetNullTest(WideString wsValue); - int32_t GetScriptTest(); - void GetFormatMessageText(WideString& wsMessage); - void SetFormatMessageText(WideString wsMessage); - void GetNullMessageText(WideString& wsMessage); - void SetNullMessageText(WideString wsMessage); - void GetScriptMessageText(WideString& wsMessage); - void SetScriptMessageText(WideString wsMessage); - void GetPicture(WideString& wsPicture); - CXFA_ScriptData GetScriptData(); - - private: - void GetMessageText(WideString& wsMessage, const WideString& wsMessageType); - void SetMessageText(WideString& wsMessage, const WideString& wsMessageType); -}; - -#endif // XFA_FXFA_PARSER_CXFA_VALIDATE_H_ diff --git a/xfa/fxfa/parser/cxfa_validatedata.cpp b/xfa/fxfa/parser/cxfa_validatedata.cpp new file mode 100644 index 0000000000..756ddf23bf --- /dev/null +++ b/xfa/fxfa/parser/cxfa_validatedata.cpp @@ -0,0 +1,115 @@ +// 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_validatedata.h" + +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CXFA_ValidateData::CXFA_ValidateData(CXFA_Node* pNode) : CXFA_Data(pNode) {} + +int32_t CXFA_ValidateData::GetFormatTest() { + return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_FormatTest); +} + +bool CXFA_ValidateData::SetNullTest(WideString wsValue) { + const XFA_ATTRIBUTEENUMINFO* pInfo = + XFA_GetAttributeEnumByName(wsValue.AsStringView()); + m_pNode->JSNode()->SetEnum(XFA_ATTRIBUTE_NullTest, + pInfo ? pInfo->eName : XFA_ATTRIBUTEENUM_Disabled, + false); + return true; +} + +int32_t CXFA_ValidateData::GetNullTest() { + return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_NullTest); +} + +int32_t CXFA_ValidateData::GetScriptTest() { + return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_ScriptTest); +} + +void CXFA_ValidateData::GetMessageText(WideString& wsMessage, + const WideString& wsMessageType) { + CXFA_Node* pNode = + m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, false); + if (!pNode) + return; + + CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pItemNode; + pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItemNode->GetElementType() != XFA_Element::Text) + continue; + + WideStringView wsName; + pItemNode->JSNode()->TryCData(XFA_ATTRIBUTE_Name, wsName, true); + if (wsName.IsEmpty() || wsName == wsMessageType) { + pItemNode->JSNode()->TryContent(wsMessage, false, true); + return; + } + } +} + +void CXFA_ValidateData::SetFormatMessageText(WideString wsMessage) { + SetMessageText(wsMessage, L"formatTest"); +} + +void CXFA_ValidateData::GetFormatMessageText(WideString& wsMessage) { + GetMessageText(wsMessage, L"formatTest"); +} + +void CXFA_ValidateData::SetNullMessageText(WideString wsMessage) { + SetMessageText(wsMessage, L"nullTest"); +} + +void CXFA_ValidateData::GetNullMessageText(WideString& wsMessage) { + GetMessageText(wsMessage, L"nullTest"); +} + +void CXFA_ValidateData::SetMessageText(WideString& wsMessage, + const WideString& wsMessageType) { + CXFA_Node* pNode = + m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, true); + if (!pNode) + return; + + CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pItemNode; + pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItemNode->GetElementType() != XFA_Element::Text) + continue; + + WideStringView wsName; + pItemNode->JSNode()->TryCData(XFA_ATTRIBUTE_Name, wsName, true); + if (wsName.IsEmpty() || wsName == wsMessageType) { + pItemNode->JSNode()->SetContent(wsMessage, wsMessage, false, false, true); + return; + } + } + CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text); + pNode->InsertChild(pTextNode, nullptr); + pTextNode->JSNode()->SetCData(XFA_ATTRIBUTE_Name, wsMessageType, false, + false); + pTextNode->JSNode()->SetContent(wsMessage, wsMessage, false, false, true); +} + +void CXFA_ValidateData::GetScriptMessageText(WideString& wsMessage) { + GetMessageText(wsMessage, L"scriptTest"); +} + +void CXFA_ValidateData::SetScriptMessageText(WideString wsMessage) { + SetMessageText(wsMessage, L"scriptTest"); +} + +void CXFA_ValidateData::GetPicture(WideString& wsPicture) { + if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false)) + pNode->JSNode()->TryContent(wsPicture, false, true); +} + +CXFA_ScriptData CXFA_ValidateData::GetScriptData() { + return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); +} diff --git a/xfa/fxfa/parser/cxfa_validatedata.h b/xfa/fxfa/parser/cxfa_validatedata.h new file mode 100644 index 0000000000..53df39429d --- /dev/null +++ b/xfa/fxfa/parser/cxfa_validatedata.h @@ -0,0 +1,39 @@ +// 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_VALIDATEDATA_H_ +#define XFA_FXFA_PARSER_CXFA_VALIDATEDATA_H_ + +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fxfa/parser/cxfa_data.h" +#include "xfa/fxfa/parser/cxfa_scriptdata.h" + +class CXFA_Node; + +class CXFA_ValidateData : public CXFA_Data { + public: + explicit CXFA_ValidateData(CXFA_Node* pNode); + + int32_t GetFormatTest(); + int32_t GetNullTest(); + bool SetNullTest(WideString wsValue); + int32_t GetScriptTest(); + void GetFormatMessageText(WideString& wsMessage); + void SetFormatMessageText(WideString wsMessage); + void GetNullMessageText(WideString& wsMessage); + void SetNullMessageText(WideString wsMessage); + void GetScriptMessageText(WideString& wsMessage); + void SetScriptMessageText(WideString wsMessage); + void GetPicture(WideString& wsPicture); + CXFA_ScriptData GetScriptData(); + + private: + void GetMessageText(WideString& wsMessage, const WideString& wsMessageType); + void SetMessageText(WideString& wsMessage, const WideString& wsMessageType); +}; + +#endif // XFA_FXFA_PARSER_CXFA_VALIDATEDATA_H_ diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index b9a54bd447..d5b1609aea 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -349,8 +349,8 @@ CXFA_CalculateData CXFA_WidgetData::GetCalculateData() { m_pNode->JSNode()->GetProperty(0, XFA_Element::Calculate, false)); } -CXFA_Validate CXFA_WidgetData::GetValidate(bool bModified) { - return CXFA_Validate( +CXFA_ValidateData CXFA_WidgetData::GetValidateData(bool bModified) { + return CXFA_ValidateData( m_pNode->JSNode()->GetProperty(0, XFA_Element::Validate, bModified)); } diff --git a/xfa/fxfa/parser/cxfa_widgetdata.h b/xfa/fxfa/parser/cxfa_widgetdata.h index d076b9b01e..40ee92d299 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.h +++ b/xfa/fxfa/parser/cxfa_widgetdata.h @@ -21,7 +21,7 @@ #include "xfa/fxfa/parser/cxfa_fontdata.h" #include "xfa/fxfa/parser/cxfa_margindata.h" #include "xfa/fxfa/parser/cxfa_paradata.h" -#include "xfa/fxfa/parser/cxfa_validate.h" +#include "xfa/fxfa/parser/cxfa_validatedata.h" enum XFA_CHECKSTATE { XFA_CHECKSTATE_On = 0, @@ -61,7 +61,7 @@ class CXFA_WidgetData : public CXFA_Data { CXFA_Value GetDefaultValue(); CXFA_Value GetFormValue(); CXFA_CalculateData GetCalculateData(); - CXFA_Validate GetValidate(bool bModified); + CXFA_ValidateData GetValidateData(bool bModified); bool GetWidth(float& fWidth); bool GetHeight(float& fHeight); -- cgit v1.2.3