From dcbb8e53e604178dc97d12846ddbdef88be41297 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 14 Dec 2017 19:48:44 +0000 Subject: Fold CXFA_ValidateData into CXFA_Validate The ValidateData class is a thin wrapper around the Validate class. Now that the Validate class exists we can fold the methods from ValidateData into Validate. Change-Id: I1e72f4b7bddeb22a311f4fe9a5940204221b6d2a Reviewed-on: https://pdfium-review.googlesource.com/21150 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- BUILD.gn | 2 - fxjs/xfa/cjx_object.cpp | 32 +++++---- xfa/fxfa/cxfa_ffdocview.cpp | 12 ++-- xfa/fxfa/cxfa_ffwidgethandler.cpp | 6 +- xfa/fxfa/cxfa_widgetacc.cpp | 40 +++++------ xfa/fxfa/cxfa_widgetacc.h | 7 +- xfa/fxfa/parser/cxfa_validate.cpp | 100 +++++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_validate.h | 22 ++++++ xfa/fxfa/parser/cxfa_validatedata.cpp | 123 ---------------------------------- xfa/fxfa/parser/cxfa_validatedata.h | 45 ------------- xfa/fxfa/parser/cxfa_widgetdata.cpp | 5 +- xfa/fxfa/parser/cxfa_widgetdata.h | 4 +- 12 files changed, 178 insertions(+), 220 deletions(-) delete mode 100644 xfa/fxfa/parser/cxfa_validatedata.cpp delete mode 100644 xfa/fxfa/parser/cxfa_validatedata.h diff --git a/BUILD.gn b/BUILD.gn index e1e2871739..69adfa9627 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2736,8 +2736,6 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_validate.h", "xfa/fxfa/parser/cxfa_validateapprovalsignatures.cpp", "xfa/fxfa/parser/cxfa_validateapprovalsignatures.h", - "xfa/fxfa/parser/cxfa_validatedata.cpp", - "xfa/fxfa/parser/cxfa_validatedata.h", "xfa/fxfa/parser/cxfa_validationmessaging.cpp", "xfa/fxfa/parser/cxfa_validationmessaging.h", "xfa/fxfa/parser/cxfa_value.cpp", diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index c1503af22d..77de53ec64 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -27,6 +27,7 @@ #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_object.h" #include "xfa/fxfa/parser/cxfa_occurdata.h" +#include "xfa/fxfa/parser/cxfa_validate.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { @@ -1403,31 +1404,31 @@ void CJX_Object::Script_Som_Message(CFXJSE_Value* pValue, return; bool bNew = false; - CXFA_ValidateData validateData = widget_data_->GetValidateData(false); - if (!validateData.HasValidNode()) { - validateData = widget_data_->GetValidateData(true); + CXFA_Validate* validate = widget_data_->GetValidate(false); + if (!validate) { + validate = widget_data_->GetValidate(true); bNew = true; } if (bSetting) { switch (iMessageType) { case XFA_SOM_ValidationMessage: - validateData.SetScriptMessageText(pValue->ToWideString()); + validate->SetScriptMessageText(pValue->ToWideString()); break; case XFA_SOM_FormatMessage: - validateData.SetFormatMessageText(pValue->ToWideString()); + validate->SetFormatMessageText(pValue->ToWideString()); break; case XFA_SOM_MandatoryMessage: - validateData.SetNullMessageText(pValue->ToWideString()); + validate->SetNullMessageText(pValue->ToWideString()); break; default: break; } if (!bNew) { CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) { + if (!pNotify) return; - } + pNotify->AddCalcValidate(ToNode(GetXFAObject())); } return; @@ -1436,13 +1437,13 @@ void CJX_Object::Script_Som_Message(CFXJSE_Value* pValue, WideString wsMessage; switch (iMessageType) { case XFA_SOM_ValidationMessage: - wsMessage = validateData.GetScriptMessageText(); + wsMessage = validate->GetScriptMessageText(); break; case XFA_SOM_FormatMessage: - wsMessage = validateData.GetFormatMessageText(); + wsMessage = validate->GetFormatMessageText(); break; case XFA_SOM_MandatoryMessage: - wsMessage = validateData.GetNullMessageText(); + wsMessage = validate->GetNullMessageText(); break; default: break; @@ -1589,13 +1590,16 @@ void CJX_Object::Script_Som_Mandatory(CFXJSE_Value* pValue, if (!widget_data_) return; - CXFA_ValidateData validateData = widget_data_->GetValidateData(true); + CXFA_Validate* validate = widget_data_->GetValidate(true); + if (!validate) + return; + if (bSetting) { - validateData.SetNullTest(pValue->ToWideString()); + validate->SetNullTest(pValue->ToWideString()); return; } - WideString str = CXFA_Node::AttributeEnumToName(validateData.GetNullTest()); + WideString str = CXFA_Node::AttributeEnumToName(validate->GetNullTest()); pValue->SetString(str.UTF8Encode().AsStringView()); } diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index 5b1dc82223..25a357bc46 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -31,6 +31,7 @@ #include "xfa/fxfa/cxfa_widgetacciterator.h" #include "xfa/fxfa/parser/cxfa_binditemsdata.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_validate.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" const XFA_AttributeEnum gs_EventActivity[] = { @@ -221,11 +222,12 @@ bool CXFA_FFDocView::ResetSingleWidgetAccData(CXFA_WidgetAcc* pWidgetAcc) { pWidgetAcc->ResetData(); pWidgetAcc->UpdateUIDisplay(); - CXFA_ValidateData validateData = pWidgetAcc->GetValidateData(false); - if (validateData.HasValidNode()) { - AddValidateWidget(pWidgetAcc); - validateData.GetNode()->SetFlag(XFA_NodeFlag_NeedsInitApp, false); - } + CXFA_Validate* validate = pWidgetAcc->GetValidate(false); + if (!validate) + return true; + + AddValidateWidget(pWidgetAcc); + validate->SetFlag(XFA_NodeFlag_NeedsInitApp, false); return true; } diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp index c4483c6a1e..39919bc1e7 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -16,6 +16,7 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_validate.h" CXFA_FFWidgetHandler::CXFA_FFWidgetHandler(CXFA_FFDocView* pDocView) : m_pDocView(pDocView) {} @@ -193,9 +194,8 @@ bool CXFA_FFWidgetHandler::HasEvent(CXFA_WidgetAcc* pWidgetAcc, return calcData.HasValidNode() && calcData.GetScriptData().HasValidNode(); } case XFA_EVENT_Validate: { - CXFA_ValidateData validateData = pWidgetAcc->GetValidateData(false); - return validateData.HasValidNode() && - validateData.GetScriptData().HasValidNode(); + CXFA_Validate* validate = pWidgetAcc->GetValidate(false); + return validate && validate->GetScriptData().HasValidNode(); } default: break; diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index c43ab6560a..74717b998c 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -24,6 +24,7 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_validate.h" #include "xfa/fxfa/parser/xfa_utils.h" class CXFA_WidgetLayoutData { @@ -338,7 +339,7 @@ int32_t CXFA_WidgetAcc::ProcessCalculate() { return XFA_EVENTERROR_Success; } -void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_ValidateData validateData, +void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate* validate, int32_t iRet, bool bRetValue, bool bVersionFlag) { @@ -352,8 +353,8 @@ void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_ValidateData validateData, return; WideString wsTitle = pAppProvider->GetAppTitle(); - WideString wsScriptMsg = validateData.GetScriptMessageText(); - if (validateData.GetScriptTest() == XFA_AttributeEnum::Warning) { + WideString wsScriptMsg = validate->GetScriptMessageText(); + if (validate->GetScriptTest() == XFA_AttributeEnum::Warning) { if (GetNode()->IsUserInteractive()) return; if (wsScriptMsg.IsEmpty()) @@ -375,12 +376,11 @@ void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_ValidateData validateData, pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); } -int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( - CXFA_ValidateData validateData, - bool bVersionFlag) { +int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate* validate, + bool bVersionFlag) { WideString wsRawValue = GetRawValue(); if (!wsRawValue.IsEmpty()) { - WideString wsPicture = validateData.GetPicture(); + WideString wsPicture = validate->GetPicture(); if (wsPicture.IsEmpty()) return XFA_EVENTERROR_NotExist; @@ -395,9 +395,9 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( if (!pAppProvider) return XFA_EVENTERROR_NotExist; - WideString wsFormatMsg = validateData.GetFormatMessageText(); + WideString wsFormatMsg = validate->GetFormatMessageText(); WideString wsTitle = pAppProvider->GetAppTitle(); - if (validateData.GetFormatTest() == XFA_AttributeEnum::Error) { + if (validate->GetFormatTest() == XFA_AttributeEnum::Error) { if (wsFormatMsg.IsEmpty()) wsFormatMsg = GetValidateMessage(true, bVersionFlag); pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); @@ -423,7 +423,7 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( return XFA_EVENTERROR_NotExist; } -int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_ValidateData validateData, +int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate* validate, int32_t iFlags, bool bVersionFlag) { if (!GetValue(XFA_VALUEPICTURE_Raw).IsEmpty()) @@ -431,8 +431,8 @@ int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_ValidateData validateData, if (IsNull() && IsPreNull()) return XFA_EVENTERROR_Success; - XFA_AttributeEnum eNullTest = validateData.GetNullTest(); - WideString wsNullMsg = validateData.GetNullMessageText(); + XFA_AttributeEnum eNullTest = validate->GetNullTest(); + WideString wsNullMsg = validate->GetNullMessageText(); if (iFlags & 0x01) { int32_t iRet = XFA_EVENTERROR_Success; if (eNullTest != XFA_AttributeEnum::Disabled) @@ -528,15 +528,15 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { if (GetElementType() == XFA_Element::Draw) return XFA_EVENTERROR_NotExist; - CXFA_ValidateData validateData = GetValidateData(false); - if (!validateData.HasValidNode()) + CXFA_Validate* validate = GetValidate(false); + if (!validate) return XFA_EVENTERROR_NotExist; - bool bInitDoc = validateData.GetNode()->NeedsInitApp(); + bool bInitDoc = validate->NeedsInitApp(); bool bStatus = m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; int32_t iFormat = 0; int32_t iRet = XFA_EVENTERROR_NotExist; - CXFA_ScriptData scriptData = validateData.GetScriptData(); + CXFA_ScriptData scriptData = validate->GetScriptData(); bool bRet = false; bool hasBoolResult = (bInitDoc || bStatus) && GetRawValue().IsEmpty(); if (scriptData.HasValidNode()) { @@ -552,17 +552,17 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { bVersionFlag = true; if (bInitDoc) { - validateData.GetNode()->ClearFlag(XFA_NodeFlag_NeedsInitApp); + validate->ClearFlag(XFA_NodeFlag_NeedsInitApp); } else { - iFormat = ProcessFormatTestValidate(validateData, bVersionFlag); + iFormat = ProcessFormatTestValidate(validate, bVersionFlag); if (!bVersionFlag) bVersionFlag = GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting); - iRet |= ProcessNullTestValidate(validateData, iFlags, bVersionFlag); + iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag); } if (iFormat != XFA_EVENTERROR_Success && hasBoolResult) - ProcessScriptTestValidate(validateData, iRet, bRet, bVersionFlag); + ProcessScriptTestValidate(validate, iRet, bRet, bVersionFlag); return iRet | iFormat; } diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index 7b046b4670..96afeb4bde 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -87,13 +87,12 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { private: IXFA_AppProvider* GetAppProvider(); - void ProcessScriptTestValidate(CXFA_ValidateData validateData, + void ProcessScriptTestValidate(CXFA_Validate* validate, int32_t iRet, bool pRetValue, bool bVersionFlag); - int32_t ProcessFormatTestValidate(CXFA_ValidateData validateData, - bool bVersionFlag); - int32_t ProcessNullTestValidate(CXFA_ValidateData validateData, + int32_t ProcessFormatTestValidate(CXFA_Validate* validate, bool bVersionFlag); + int32_t ProcessNullTestValidate(CXFA_Validate* validate, 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 index b532067157..9b31a17434 100644 --- a/xfa/fxfa/parser/cxfa_validate.cpp +++ b/xfa/fxfa/parser/cxfa_validate.cpp @@ -31,6 +31,9 @@ const CXFA_Node::AttributeData kAttributeData[] = { {XFA_Attribute::Unknown, XFA_AttributeType::Integer, nullptr}}; constexpr wchar_t kName[] = L"validate"; +constexpr wchar_t kFormatTest[] = L"formatTest"; +constexpr wchar_t kNullTest[] = L"nullTest"; +constexpr wchar_t kScriptTest[] = L"scriptTest"; } // namespace @@ -47,3 +50,100 @@ CXFA_Validate::CXFA_Validate(CXFA_Document* doc, XFA_PacketType packet) pdfium::MakeUnique(this)) {} CXFA_Validate::~CXFA_Validate() {} + +XFA_AttributeEnum CXFA_Validate::GetFormatTest() { + return JSObject()->GetEnum(XFA_Attribute::FormatTest); +} + +void CXFA_Validate::SetNullTest(const WideString& wsValue) { + pdfium::Optional item = + CXFA_Node::NameToAttributeEnum(wsValue.AsStringView()); + JSObject()->SetEnum(XFA_Attribute::NullTest, + item ? *item : XFA_AttributeEnum::Disabled, false); +} + +XFA_AttributeEnum CXFA_Validate::GetNullTest() { + return JSObject()->GetEnum(XFA_Attribute::NullTest); +} + +XFA_AttributeEnum CXFA_Validate::GetScriptTest() { + return JSObject()->GetEnum(XFA_Attribute::ScriptTest); +} + +WideString CXFA_Validate::GetMessageText(const WideString& wsMessageType) { + CXFA_Node* pNode = JSObject()->GetProperty(0, XFA_Element::Message, false); + if (!pNode) + return L""; + + for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pItemNode; + pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItemNode->GetElementType() != XFA_Element::Text) + continue; + + WideString wsName = pItemNode->JSObject()->GetCData(XFA_Attribute::Name); + if (wsName.IsEmpty() || wsName == wsMessageType) + return pItemNode->JSObject()->GetContent(false); + } + return L""; +} + +void CXFA_Validate::SetFormatMessageText(const WideString& wsMessage) { + SetMessageText(kFormatTest, wsMessage); +} + +WideString CXFA_Validate::GetFormatMessageText() { + return GetMessageText(kFormatTest); +} + +void CXFA_Validate::SetNullMessageText(const WideString& wsMessage) { + SetMessageText(kNullTest, wsMessage); +} + +WideString CXFA_Validate::GetNullMessageText() { + return GetMessageText(kNullTest); +} + +WideString CXFA_Validate::GetScriptMessageText() { + return GetMessageText(kScriptTest); +} + +void CXFA_Validate::SetScriptMessageText(const WideString& wsMessage) { + SetMessageText(kScriptTest, wsMessage); +} + +void CXFA_Validate::SetMessageText(const WideString& wsMessageType, + const WideString& wsMessage) { + CXFA_Node* pNode = JSObject()->GetProperty(0, XFA_Element::Message, true); + if (!pNode) + return; + + for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pItemNode; + pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItemNode->GetElementType() != XFA_Element::Text) + continue; + + WideString wsName = pItemNode->JSObject()->GetCData(XFA_Attribute::Name); + if (wsName.IsEmpty() || wsName == wsMessageType) { + pItemNode->JSObject()->SetContent(wsMessage, wsMessage, false, false, + true); + return; + } + } + + CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text); + pNode->InsertChild(pTextNode, nullptr); + pTextNode->JSObject()->SetCData(XFA_Attribute::Name, wsMessageType, false, + false); + pTextNode->JSObject()->SetContent(wsMessage, wsMessage, false, false, true); +} + +WideString CXFA_Validate::GetPicture() { + CXFA_Node* pNode = GetChild(0, XFA_Element::Picture, false); + return pNode ? pNode->JSObject()->GetContent(false) : L""; +} + +CXFA_ScriptData CXFA_Validate::GetScriptData() { + return CXFA_ScriptData(GetChild(0, XFA_Element::Script, false)); +} diff --git a/xfa/fxfa/parser/cxfa_validate.h b/xfa/fxfa/parser/cxfa_validate.h index d19850cd77..9e2be9c959 100644 --- a/xfa/fxfa/parser/cxfa_validate.h +++ b/xfa/fxfa/parser/cxfa_validate.h @@ -13,6 +13,28 @@ class CXFA_Validate : public CXFA_Node { public: CXFA_Validate(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Validate() override; + + XFA_AttributeEnum GetFormatTest(); + WideString GetFormatMessageText(); + void SetFormatMessageText(const WideString& wsMessage); + + XFA_AttributeEnum GetNullTest(); + void SetNullTest(const WideString& wsValue); + + WideString GetNullMessageText(); + void SetNullMessageText(const WideString& wsMessage); + + XFA_AttributeEnum GetScriptTest(); + WideString GetScriptMessageText(); + void SetScriptMessageText(const WideString& wsMessage); + + WideString GetPicture(); + CXFA_ScriptData GetScriptData(); + + private: + WideString GetMessageText(const WideString& wsMessageType); + void SetMessageText(const WideString& wsMessageType, + const WideString& wsMessage); }; #endif // XFA_FXFA_PARSER_CXFA_VALIDATE_H_ diff --git a/xfa/fxfa/parser/cxfa_validatedata.cpp b/xfa/fxfa/parser/cxfa_validatedata.cpp deleted file mode 100644 index 934edba764..0000000000 --- a/xfa/fxfa/parser/cxfa_validatedata.cpp +++ /dev/null @@ -1,123 +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_validatedata.h" - -#include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -namespace { - -constexpr wchar_t kFormatTest[] = L"formatTest"; -constexpr wchar_t kNullTest[] = L"nullTest"; -constexpr wchar_t kScriptTest[] = L"scriptTest"; - -} // namespace - -CXFA_ValidateData::CXFA_ValidateData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} - -XFA_AttributeEnum CXFA_ValidateData::GetFormatTest() const { - return m_pNode->JSObject()->GetEnum(XFA_Attribute::FormatTest); -} - -void CXFA_ValidateData::SetNullTest(const WideString& wsValue) { - pdfium::Optional item = - CXFA_Node::NameToAttributeEnum(wsValue.AsStringView()); - m_pNode->JSObject()->SetEnum(XFA_Attribute::NullTest, - item ? *item : XFA_AttributeEnum::Disabled, - false); -} - -XFA_AttributeEnum CXFA_ValidateData::GetNullTest() const { - return m_pNode->JSObject()->GetEnum(XFA_Attribute::NullTest); -} - -XFA_AttributeEnum CXFA_ValidateData::GetScriptTest() const { - return m_pNode->JSObject()->GetEnum(XFA_Attribute::ScriptTest); -} - -WideString CXFA_ValidateData::GetMessageText( - const WideString& wsMessageType) const { - CXFA_Node* pNode = - m_pNode->JSObject()->GetProperty(0, XFA_Element::Message, false); - if (!pNode) - return L""; - - for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - pItemNode; - pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItemNode->GetElementType() != XFA_Element::Text) - continue; - - WideString wsName = pItemNode->JSObject()->GetCData(XFA_Attribute::Name); - if (wsName.IsEmpty() || wsName == wsMessageType) - return pItemNode->JSObject()->GetContent(false); - } - return L""; -} - -void CXFA_ValidateData::SetFormatMessageText(const WideString& wsMessage) { - SetMessageText(kFormatTest, wsMessage); -} - -WideString CXFA_ValidateData::GetFormatMessageText() const { - return GetMessageText(kFormatTest); -} - -void CXFA_ValidateData::SetNullMessageText(const WideString& wsMessage) { - SetMessageText(kNullTest, wsMessage); -} - -WideString CXFA_ValidateData::GetNullMessageText() const { - return GetMessageText(kNullTest); -} - -WideString CXFA_ValidateData::GetScriptMessageText() const { - return GetMessageText(kScriptTest); -} - -void CXFA_ValidateData::SetScriptMessageText(const WideString& wsMessage) { - SetMessageText(kScriptTest, wsMessage); -} - -void CXFA_ValidateData::SetMessageText(const WideString& wsMessageType, - const WideString& wsMessage) { - CXFA_Node* pNode = - m_pNode->JSObject()->GetProperty(0, XFA_Element::Message, true); - if (!pNode) - return; - - for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - pItemNode; - pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItemNode->GetElementType() != XFA_Element::Text) - continue; - - WideString wsName = pItemNode->JSObject()->GetCData(XFA_Attribute::Name); - if (wsName.IsEmpty() || wsName == wsMessageType) { - pItemNode->JSObject()->SetContent(wsMessage, wsMessage, false, false, - true); - return; - } - } - - CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text); - pNode->InsertChild(pTextNode, nullptr); - pTextNode->JSObject()->SetCData(XFA_Attribute::Name, wsMessageType, false, - false); - pTextNode->JSObject()->SetContent(wsMessage, wsMessage, false, false, true); -} - -WideString CXFA_ValidateData::GetPicture() const { - CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false); - if (pNode) - return pNode->JSObject()->GetContent(false); - return L""; -} - -CXFA_ScriptData CXFA_ValidateData::GetScriptData() const { - 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 deleted file mode 100644 index 309db62ab6..0000000000 --- a/xfa/fxfa/parser/cxfa_validatedata.h +++ /dev/null @@ -1,45 +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_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_datadata.h" -#include "xfa/fxfa/parser/cxfa_scriptdata.h" - -class CXFA_Node; - -class CXFA_ValidateData : public CXFA_DataData { - public: - explicit CXFA_ValidateData(CXFA_Node* pNode); - - XFA_AttributeEnum GetFormatTest() const; - WideString GetFormatMessageText() const; - void SetFormatMessageText(const WideString& wsMessage); - - XFA_AttributeEnum GetNullTest() const; - void SetNullTest(const WideString& wsValue); - - WideString GetNullMessageText() const; - void SetNullMessageText(const WideString& wsMessage); - - XFA_AttributeEnum GetScriptTest() const; - WideString GetScriptMessageText() const; - void SetScriptMessageText(const WideString& wsMessage); - - WideString GetPicture() const; - - CXFA_ScriptData GetScriptData() const; - - private: - WideString GetMessageText(const WideString& wsMessageType) const; - void SetMessageText(const WideString& wsMessageType, - const WideString& wsMessage); -}; - -#endif // XFA_FXFA_PARSER_CXFA_VALIDATEDATA_H_ diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index 4ba6b418de..58c934132c 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -15,6 +15,7 @@ #include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_validate.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { @@ -311,8 +312,8 @@ CXFA_CalculateData CXFA_WidgetData::GetCalculateData() { m_pNode->JSObject()->GetProperty(0, XFA_Element::Calculate, false)); } -CXFA_ValidateData CXFA_WidgetData::GetValidateData(bool bModified) { - return CXFA_ValidateData( +CXFA_Validate* CXFA_WidgetData::GetValidate(bool bModified) { + return static_cast( m_pNode->JSObject()->GetProperty(0, XFA_Element::Validate, bModified)); } diff --git a/xfa/fxfa/parser/cxfa_widgetdata.h b/xfa/fxfa/parser/cxfa_widgetdata.h index fab11ce235..592226cb0b 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.h +++ b/xfa/fxfa/parser/cxfa_widgetdata.h @@ -22,7 +22,6 @@ #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_validatedata.h" enum XFA_CHECKSTATE { XFA_CHECKSTATE_On = 0, @@ -38,6 +37,7 @@ enum XFA_VALUEPICTURE { }; class CXFA_Node; +class CXFA_Validate; class IFX_Locale; class CXFA_WidgetData : public CXFA_DataData { @@ -66,7 +66,7 @@ class CXFA_WidgetData : public CXFA_DataData { CXFA_ValueData GetDefaultValueData(); CXFA_ValueData GetFormValueData(); CXFA_CalculateData GetCalculateData(); - CXFA_ValidateData GetValidateData(bool bModified); + CXFA_Validate* GetValidate(bool bModified); CXFA_BorderData GetUIBorderData(); std::vector GetEventByActivity(XFA_AttributeEnum iActivity, -- cgit v1.2.3