summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-22 22:04:12 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-22 22:04:12 +0000
commit9d0d36b7f3e2106bbeb332edf821fc2c637e6ea0 (patch)
tree6d1a17b202cdb73956e768c56c1316c0d163effb /xfa/fxfa
parenta1c4205eff6c8a0bb6a6abf58bbec06cb0fe22c5 (diff)
downloadpdfium-9d0d36b7f3e2106bbeb332edf821fc2c637e6ea0.tar.xz
Cleanup CXFA_ValidateData
This CL removes out-params in favour of returns; Makes params const; Cleans up return types. Change-Id: I2b7c237130a99859b08af0486a95b4c6f6974f62 Reviewed-on: https://pdfium-review.googlesource.com/19130 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/cxfa_widgetacc.cpp20
-rw-r--r--xfa/fxfa/parser/cxfa_validatedata.cpp81
-rw-r--r--xfa/fxfa/parser/cxfa_validatedata.h34
3 files changed, 72 insertions, 63 deletions
diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp
index fcc1e69762..644b1688c0 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -356,10 +356,8 @@ void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_ValidateData validateData,
return;
WideString wsTitle = pAppProvider->GetAppTitle();
- WideString wsScriptMsg;
- validateData.GetScriptMessageText(wsScriptMsg);
- int32_t eScriptTest = validateData.GetScriptTest();
- if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) {
+ WideString wsScriptMsg = validateData.GetScriptMessageText();
+ if (validateData.GetScriptTest() == XFA_ATTRIBUTEENUM_Warning) {
if (GetNode()->IsUserInteractive())
return;
if (wsScriptMsg.IsEmpty())
@@ -386,8 +384,7 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(
bool bVersionFlag) {
WideString wsRawValue = GetRawValue();
if (!wsRawValue.IsEmpty()) {
- WideString wsPicture;
- validateData.GetPicture(wsPicture);
+ WideString wsPicture = validateData.GetPicture();
if (wsPicture.IsEmpty())
return XFA_EVENTERROR_NotExist;
@@ -402,11 +399,9 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(
if (!pAppProvider)
return XFA_EVENTERROR_NotExist;
- WideString wsFormatMsg;
- validateData.GetFormatMessageText(wsFormatMsg);
+ WideString wsFormatMsg = validateData.GetFormatMessageText();
WideString wsTitle = pAppProvider->GetAppTitle();
- int32_t eFormatTest = validateData.GetFormatTest();
- if (eFormatTest == XFA_ATTRIBUTEENUM_Error) {
+ if (validateData.GetFormatTest() == XFA_ATTRIBUTEENUM_Error) {
if (wsFormatMsg.IsEmpty())
wsFormatMsg = GetValidateMessage(true, bVersionFlag);
pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK);
@@ -442,9 +437,8 @@ int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_ValidateData validateData,
if (m_bIsNull && (m_bPreNull == m_bIsNull))
return XFA_EVENTERROR_Success;
- int32_t eNullTest = validateData.GetNullTest();
- WideString wsNullMsg;
- validateData.GetNullMessageText(wsNullMsg);
+ XFA_ATTRIBUTEENUM eNullTest = validateData.GetNullTest();
+ WideString wsNullMsg = validateData.GetNullMessageText();
if (iFlags & 0x01) {
int32_t iRet = XFA_EVENTERROR_Success;
if (eNullTest != XFA_ATTRIBUTEENUM_Disabled)
diff --git a/xfa/fxfa/parser/cxfa_validatedata.cpp b/xfa/fxfa/parser/cxfa_validatedata.cpp
index 94c5829288..8b3f539d48 100644
--- a/xfa/fxfa/parser/cxfa_validatedata.cpp
+++ b/xfa/fxfa/parser/cxfa_validatedata.cpp
@@ -9,35 +9,42 @@
#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) {}
-int32_t CXFA_ValidateData::GetFormatTest() {
+XFA_ATTRIBUTEENUM CXFA_ValidateData::GetFormatTest() const {
return m_pNode->JSNode()->GetEnum(XFA_Attribute::FormatTest);
}
-bool CXFA_ValidateData::SetNullTest(WideString wsValue) {
+void CXFA_ValidateData::SetNullTest(const 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() {
+XFA_ATTRIBUTEENUM CXFA_ValidateData::GetNullTest() const {
return m_pNode->JSNode()->GetEnum(XFA_Attribute::NullTest);
}
-int32_t CXFA_ValidateData::GetScriptTest() {
+XFA_ATTRIBUTEENUM CXFA_ValidateData::GetScriptTest() const {
return m_pNode->JSNode()->GetEnum(XFA_Attribute::ScriptTest);
}
-void CXFA_ValidateData::GetMessageText(WideString& wsMessage,
- const WideString& wsMessageType) {
+WideString CXFA_ValidateData::GetMessageText(
+ const WideString& wsMessageType) const {
CXFA_Node* pNode =
m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, false);
if (!pNode)
- return;
+ return L"";
for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
pItemNode;
@@ -46,38 +53,45 @@ void CXFA_ValidateData::GetMessageText(WideString& wsMessage,
continue;
WideString wsName = pItemNode->JSNode()->GetCData(XFA_Attribute::Name);
- if (wsName.IsEmpty() || wsName == wsMessageType) {
- wsMessage = pItemNode->JSNode()->GetContent(false);
- return;
- }
+ if (wsName.IsEmpty() || wsName == wsMessageType)
+ return pItemNode->JSNode()->GetContent(false);
}
+ return L"";
+}
+
+void CXFA_ValidateData::SetFormatMessageText(const WideString& wsMessage) {
+ SetMessageText(kFormatTest, wsMessage);
}
-void CXFA_ValidateData::SetFormatMessageText(WideString wsMessage) {
- SetMessageText(wsMessage, L"formatTest");
+WideString CXFA_ValidateData::GetFormatMessageText() const {
+ return GetMessageText(kFormatTest);
}
-void CXFA_ValidateData::GetFormatMessageText(WideString& wsMessage) {
- GetMessageText(wsMessage, L"formatTest");
+void CXFA_ValidateData::SetNullMessageText(const WideString& wsMessage) {
+ SetMessageText(kNullTest, wsMessage);
}
-void CXFA_ValidateData::SetNullMessageText(WideString wsMessage) {
- SetMessageText(wsMessage, L"nullTest");
+WideString CXFA_ValidateData::GetNullMessageText() const {
+ return GetMessageText(kNullTest);
}
-void CXFA_ValidateData::GetNullMessageText(WideString& wsMessage) {
- GetMessageText(wsMessage, L"nullTest");
+WideString CXFA_ValidateData::GetScriptMessageText() const {
+ return GetMessageText(kScriptTest);
}
-void CXFA_ValidateData::SetMessageText(WideString& wsMessage,
- const WideString& wsMessageType) {
+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->JSNode()->GetProperty(0, XFA_Element::Message, true);
if (!pNode)
return;
- CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
- for (; pItemNode;
+ for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
+ pItemNode;
pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
if (pItemNode->GetElementType() != XFA_Element::Text)
continue;
@@ -88,6 +102,7 @@ void CXFA_ValidateData::SetMessageText(WideString& wsMessage,
return;
}
}
+
CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text);
pNode->InsertChild(pTextNode, nullptr);
pTextNode->JSNode()->SetCData(XFA_Attribute::Name, wsMessageType, false,
@@ -95,19 +110,13 @@ void CXFA_ValidateData::SetMessageText(WideString& wsMessage,
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))
- wsPicture = pNode->JSNode()->GetContent(false);
+WideString CXFA_ValidateData::GetPicture() const {
+ CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false);
+ if (pNode)
+ return pNode->JSNode()->GetContent(false);
+ return L"";
}
-CXFA_ScriptData CXFA_ValidateData::GetScriptData() {
+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
index a431cbdf20..e18fcadeaf 100644
--- a/xfa/fxfa/parser/cxfa_validatedata.h
+++ b/xfa/fxfa/parser/cxfa_validatedata.h
@@ -18,22 +18,28 @@ class CXFA_ValidateData : public CXFA_DataData {
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();
+ 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:
- void GetMessageText(WideString& wsMessage, const WideString& wsMessageType);
- void SetMessageText(WideString& wsMessage, const WideString& wsMessageType);
+ WideString GetMessageText(const WideString& wsMessageType) const;
+ void SetMessageText(const WideString& wsMessageType,
+ const WideString& wsMessage);
};
#endif // XFA_FXFA_PARSER_CXFA_VALIDATEDATA_H_