summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-12-14 19:48:44 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-14 19:48:44 +0000
commitdcbb8e53e604178dc97d12846ddbdef88be41297 (patch)
treedc58158143f2a6a590007dfe137e7053b25357e5 /xfa/fxfa/parser
parentfe9d640ea90cfccac39b6475dad9df62072542fc (diff)
downloadpdfium-dcbb8e53e604178dc97d12846ddbdef88be41297.tar.xz
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 <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_validate.cpp100
-rw-r--r--xfa/fxfa/parser/cxfa_validate.h22
-rw-r--r--xfa/fxfa/parser/cxfa_validatedata.cpp123
-rw-r--r--xfa/fxfa/parser/cxfa_validatedata.h45
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp5
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.h4
6 files changed, 127 insertions, 172 deletions
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<CJX_Validate>(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<XFA_AttributeEnum> 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<XFA_AttributeEnum> 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<CXFA_Validate*>(
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<CXFA_Node*> GetEventByActivity(XFA_AttributeEnum iActivity,