summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-04 15:10:00 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 19:54:55 +0000
commit93bfc262074abf003ba4ab0ff1d9767d8dfa9a3d (patch)
treefd2c2c9d0a99923d397501f85e780498928a7e35 /xfa/fxfa
parentb2fb20e0f8e7ea368c541d35ccb61506041f7ddd (diff)
downloadpdfium-93bfc262074abf003ba4ab0ff1d9767d8dfa9a3d.tar.xz
Cleanup CFDE_XMLCharData and CFDE_XMLText
This Cl switchs CFDE_XMLCharData to subclass CFDE_XMLText and cleans up the code which was the same except for the accessor names. Change-Id: I85ebf4f3f19f0d15be4dd77a71b89ca8083f4b1e Reviewed-on: https://pdfium-review.googlesource.com/3672 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/app/cxfa_textlayout.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp111
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp55
-rw-r--r--xfa/fxfa/parser/xfa_utils.cpp18
4 files changed, 74 insertions, 112 deletions
diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp
index 718f90b9ea..c32717b523 100644
--- a/xfa/fxfa/app/cxfa_textlayout.cpp
+++ b/xfa/fxfa/app/cxfa_textlayout.cpp
@@ -773,7 +773,7 @@ bool CXFA_TextLayout::LoadRichText(
bContentNode ? pParentStyle.Get() : pStyle.Get());
CFX_WideString wsText;
if (bContentNode && iTabCount == 0) {
- static_cast<CFDE_XMLText*>(pXMLNode)->GetText(wsText);
+ wsText = static_cast<CFDE_XMLText*>(pXMLNode)->GetText();
} else if (wsName == L"br") {
wsText = L'\n';
} else if (wsName == L"li") {
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 61107bf156..2079127dc9 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -517,22 +517,21 @@ CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
MergeAllData(pClone);
pClone->UpdateNameHash();
if (IsNeedSavingXMLNode()) {
- CFDE_XMLNode* pCloneXML = nullptr;
+ std::unique_ptr<CFDE_XMLNode> pCloneXML;
if (IsAttributeInXML()) {
CFX_WideString wsName;
GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
- CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
+ auto pCloneXMLElement = pdfium::MakeUnique<CFDE_XMLElement>(wsName);
CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
if (!wsValue.IsEmpty()) {
pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
}
- pCloneXML = pCloneXMLElement;
- pCloneXMLElement = nullptr;
+ pCloneXML.reset(pCloneXMLElement.release());
pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
} else {
- pCloneXML = m_pXMLNode->Clone(false);
+ pCloneXML = m_pXMLNode->Clone();
}
- pClone->SetXMLMappingNode(pCloneXML);
+ pClone->SetXMLMappingNode(pCloneXML.release());
pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
}
if (bRecursive) {
@@ -1303,13 +1302,16 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
CFX_WideString(wsContentType));
}
- CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
+
+ std::unique_ptr<CFDE_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode());
if (!pFakeXMLRoot) {
CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
- pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
+ pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr;
+ }
+ if (!pFakeXMLRoot) {
+ pFakeXMLRoot =
+ pdfium::MakeUnique<CFDE_XMLElement>(CFX_WideString(GetClassName()));
}
- if (!pFakeXMLRoot)
- pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
if (bIgnoreRoot) {
CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
@@ -1327,57 +1329,54 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
}
pFakeXMLRoot->InsertChildNode(pXMLNode);
}
- pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
+ pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get());
pFakeRoot = pParser->GetRootNode();
- if (pFakeRoot) {
- if (bOverwrite) {
- CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
- CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
- int32_t index = 0;
- while (pNewChild) {
- CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
- pFakeRoot->RemoveChild(pNewChild);
- InsertChild(index++, pNewChild);
- pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
- pNewChild = pItem;
- }
- while (pChild) {
- CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
- RemoveChild(pChild);
- pFakeRoot->InsertChild(pChild);
- pChild = pItem;
- }
- if (GetPacketID() == XFA_XDPPACKET_Form &&
- GetElementType() == XFA_Element::ExData) {
- CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
- SetXMLMappingNode(pFakeXMLRoot);
- SetFlag(XFA_NodeFlag_OwnXMLNode, false);
- if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
- pFakeXMLRoot = pTempXMLNode;
- } else {
- pFakeXMLRoot = nullptr;
- }
- }
- MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
- } else {
- CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
- while (pChild) {
- CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
- pFakeRoot->RemoveChild(pChild);
- InsertChild(pChild);
- pChild->SetFlag(XFA_NodeFlag_Initialized, true);
- pChild = pItem;
- }
+ if (!pFakeRoot)
+ return;
+
+ if (bOverwrite) {
+ CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
+ CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
+ int32_t index = 0;
+ while (pNewChild) {
+ CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
+ pFakeRoot->RemoveChild(pNewChild);
+ InsertChild(index++, pNewChild);
+ pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
+ pNewChild = pItem;
+ }
+ while (pChild) {
+ CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
+ RemoveChild(pChild);
+ pFakeRoot->InsertChild(pChild);
+ pChild = pItem;
}
- if (pFakeXMLRoot) {
- pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
- pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
+ if (GetPacketID() == XFA_XDPPACKET_Form &&
+ GetElementType() == XFA_Element::ExData) {
+ CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
+ SetXMLMappingNode(pFakeXMLRoot.release());
+ SetFlag(XFA_NodeFlag_OwnXMLNode, false);
+ if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent))
+ pFakeXMLRoot.reset(pTempXMLNode);
+ else
+ pFakeXMLRoot = nullptr;
}
- pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
+ MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
} else {
- delete pFakeXMLRoot;
- pFakeXMLRoot = nullptr;
+ CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
+ while (pChild) {
+ CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
+ pFakeRoot->RemoveChild(pChild);
+ InsertChild(pChild);
+ pChild->SetFlag(XFA_NodeFlag_Initialized, true);
+ pChild = pItem;
+ }
+ }
+ if (pFakeXMLRoot) {
+ pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release());
+ pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
}
+ pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
}
void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 06e2e5d704..cb6a90d2a5 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -213,24 +213,16 @@ void ConvertXMLToPlainText(CFDE_XMLElement* pRootXMLNode,
wsOutput += wsTextData;
break;
}
- case FDE_XMLNODE_Text: {
- CFX_WideString wsText;
- static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsText);
+ case FDE_XMLNODE_Text:
+ case FDE_XMLNODE_CharData: {
+ CFX_WideString wsText =
+ static_cast<CFDE_XMLText*>(pXMLChild)->GetText();
if (IsStringAllWhitespace(wsText))
continue;
wsOutput = wsText;
break;
}
- case FDE_XMLNODE_CharData: {
- CFX_WideString wsCharData;
- static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsCharData);
- if (IsStringAllWhitespace(wsCharData))
- continue;
-
- wsOutput = wsCharData;
- break;
- }
default:
ASSERT(false);
break;
@@ -1004,10 +996,8 @@ void CXFA_SimpleParser::ParseContentNode(CXFA_Node* pXFANode,
} else {
if (eNodeType == FDE_XMLNODE_Element)
break;
- if (eNodeType == FDE_XMLNODE_Text)
- static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsValue);
- else if (eNodeType == FDE_XMLNODE_CharData)
- static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsValue);
+ if (eNodeType == FDE_XMLNODE_Text || eNodeType == FDE_XMLNODE_CharData)
+ wsValue = static_cast<CFDE_XMLText*>(pXMLChild)->GetText();
}
break;
}
@@ -1140,29 +1130,10 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode,
pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false);
continue;
}
- case FDE_XMLNODE_CharData: {
- CFDE_XMLCharData* pXMLCharData =
- static_cast<CFDE_XMLCharData*>(pXMLChild);
- CFX_WideString wsCharData;
- pXMLCharData->GetCharData(wsCharData);
- if (IsStringAllWhitespace(wsCharData))
- continue;
-
- CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets,
- XFA_Element::DataValue);
- if (!pXFAChild)
- return;
-
- pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData);
- pXFANode->InsertChild(pXFAChild);
- pXFAChild->SetXMLMappingNode(pXMLCharData);
- pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false);
- continue;
- }
+ case FDE_XMLNODE_CharData:
case FDE_XMLNODE_Text: {
CFDE_XMLText* pXMLText = static_cast<CFDE_XMLText*>(pXMLChild);
- CFX_WideString wsText;
- pXMLText->GetText(wsText);
+ CFX_WideString wsText = pXMLText->GetText();
if (IsStringAllWhitespace(wsText))
continue;
@@ -1199,14 +1170,8 @@ void CXFA_SimpleParser::ParseDataValue(CXFA_Node* pXFANode,
continue;
CFX_WideString wsText;
- if (eNodeType == FDE_XMLNODE_Text) {
- static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsText);
- if (!pXMLCurValueNode)
- pXMLCurValueNode = pXMLChild;
-
- wsCurValueTextBuf << wsText;
- } else if (eNodeType == FDE_XMLNODE_CharData) {
- static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsText);
+ if (eNodeType == FDE_XMLNODE_Text || eNodeType == FDE_XMLNODE_CharData) {
+ wsText = static_cast<CFDE_XMLText*>(pXMLChild)->GetText();
if (!pXMLCurValueNode)
pXMLCurValueNode = pXMLChild;
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index df180f2183..57d97519a1 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -192,17 +192,15 @@ void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode,
wsPlainText += L"\n";
}
}
- } break;
- case FDE_XMLNODE_Text: {
- CFX_WideString wsContent;
- static_cast<CFDE_XMLText*>(pXMLNode)->GetText(wsContent);
- wsPlainText += wsContent;
- } break;
+ break;
+ }
+ case FDE_XMLNODE_Text:
case FDE_XMLNODE_CharData: {
- CFX_WideString wsCharData;
- static_cast<CFDE_XMLCharData*>(pXMLNode)->GetCharData(wsCharData);
- wsPlainText += wsCharData;
- } break;
+ CFX_WideString wsContent =
+ static_cast<CFDE_XMLText*>(pXMLNode)->GetText();
+ wsPlainText += wsContent;
+ break;
+ }
default:
break;
}