summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-04-09 16:06:24 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-09 16:06:24 +0000
commita0706f0c904673ea9f679829ff87e730e5800765 (patch)
treea803e20f27cc18a1daa5d6d7ef3244c1d160735c
parent6058efdbdc186e120e7e2121c290ac4d820ffbf8 (diff)
downloadpdfium-a0706f0c904673ea9f679829ff87e730e5800765.tar.xz
Move code to set XML value to CXFA_Node
This CL moves the code to set the XML node data from CJX_Node to CXFA_Node. The XML node is owned by the XFA node, not the CJX node so it makes more sense to have the modifications happen there. This combines the duplicate code in CJX_Node into a single SetToXML method. Bug: chromium:813155 Change-Id: I493725d1412688cb1a0d04bd9ae9fa5a36caebf3 Reviewed-on: https://pdfium-review.googlesource.com/29858 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--fxjs/xfa/cjx_object.cpp72
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp35
-rw-r--r--xfa/fxfa/parser/cxfa_node.h2
3 files changed, 44 insertions, 65 deletions
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index bb8eef123e..ab22e8b7e7 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -475,41 +475,12 @@ bool CJX_Object::SetCData(XFA_Attribute eAttr,
return true;
}
- auto* elem = static_cast<CFX_XMLElement*>(xfaObj->GetXMLMappingNode());
if (eAttr == XFA_Attribute::Value) {
- FX_XMLNODETYPE eXMLType = elem->GetType();
- switch (eXMLType) {
- case FX_XMLNODE_Element:
- if (xfaObj->IsAttributeInXML()) {
- elem->SetString(WideString(GetCData(XFA_Attribute::QualifiedName)),
- wsValue);
- } else {
- bool bDeleteChildren = true;
- if (xfaObj->GetPacketType() == XFA_PacketType::Datasets) {
- for (CXFA_Node* pChildDataNode = xfaObj->GetFirstChild();
- pChildDataNode;
- pChildDataNode = pChildDataNode->GetNextSibling()) {
- if (!pChildDataNode->GetBindItems()->empty()) {
- bDeleteChildren = false;
- break;
- }
- }
- }
- if (bDeleteChildren)
- elem->DeleteChildren();
-
- elem->SetTextData(wsValue);
- }
- break;
- case FX_XMLNODE_Text:
- static_cast<CFX_XMLText*>(xfaObj->GetXMLMappingNode())
- ->SetText(wsValue);
- break;
- default:
- NOTREACHED();
- }
+ xfaObj->SetToXML(wsValue);
return true;
}
+
+ auto* elem = static_cast<CFX_XMLElement*>(xfaObj->GetXMLMappingNode());
ASSERT(elem->GetType() == FX_XMLNODE_Element);
WideString wsAttrName = CXFA_Node::AttributeToName(eAttr);
@@ -525,48 +496,19 @@ void CJX_Object::SetAttributeValue(const WideString& wsValue,
bool bNotify,
bool bScriptModify) {
auto* xfaObj = ToNode(GetXFAObject());
-
void* pKey =
GetMapKey_Element(xfaObj->GetElementType(), XFA_Attribute::Value);
+
OnChanging(XFA_Attribute::Value, bNotify);
WideString* pClone = new WideString(wsValue);
+
SetUserData(pKey, pClone, &deleteWideStringCallBack);
OnChanged(XFA_Attribute::Value, bNotify, bScriptModify);
+
if (!xfaObj->IsNeedSavingXMLNode())
return;
- auto* elem = static_cast<CFX_XMLElement*>(xfaObj->GetXMLMappingNode());
- FX_XMLNODETYPE eXMLType = elem->GetType();
- switch (eXMLType) {
- case FX_XMLNODE_Element:
- if (xfaObj->IsAttributeInXML()) {
- elem->SetString(WideString(GetCData(XFA_Attribute::QualifiedName)),
- wsXMLValue);
- } else {
- bool bDeleteChildren = true;
- if (xfaObj->GetPacketType() == XFA_PacketType::Datasets) {
- for (CXFA_Node* pChildDataNode = xfaObj->GetFirstChild();
- pChildDataNode;
- pChildDataNode = pChildDataNode->GetNextSibling()) {
- if (!pChildDataNode->GetBindItems()->empty()) {
- bDeleteChildren = false;
- break;
- }
- }
- }
- if (bDeleteChildren)
- elem->DeleteChildren();
-
- elem->SetTextData(wsXMLValue);
- }
- break;
- case FX_XMLNODE_Text:
- static_cast<CFX_XMLText*>(xfaObj->GetXMLMappingNode())
- ->SetText(wsXMLValue);
- break;
- default:
- ASSERT(0);
- }
+ xfaObj->SetToXML(wsXMLValue);
}
Optional<WideString> CJX_Object::TryCData(XFA_Attribute eAttr,
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index b2535aee8c..3823d2eae0 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -4656,3 +4656,38 @@ bool CXFA_Node::PresenceRequiresSpace() const {
return ePresence == XFA_AttributeEnum::Visible ||
ePresence == XFA_AttributeEnum::Invisible;
}
+
+void CXFA_Node::SetToXML(const WideString& value) {
+ auto* elem = static_cast<CFX_XMLElement*>(GetXMLMappingNode());
+ FX_XMLNODETYPE eXMLType = elem->GetType();
+ switch (eXMLType) {
+ case FX_XMLNODE_Element: {
+ if (IsAttributeInXML()) {
+ elem->SetString(JSObject()->GetCData(XFA_Attribute::QualifiedName),
+ value);
+ return;
+ }
+
+ bool bDeleteChildren = true;
+ if (GetPacketType() == XFA_PacketType::Datasets) {
+ for (CXFA_Node* pChildDataNode = GetFirstChild(); pChildDataNode;
+ pChildDataNode = pChildDataNode->GetNextSibling()) {
+ if (!pChildDataNode->GetBindItems()->empty()) {
+ bDeleteChildren = false;
+ break;
+ }
+ }
+ }
+ if (bDeleteChildren)
+ elem->DeleteChildren();
+
+ elem->SetTextData(value);
+ break;
+ }
+ case FX_XMLNODE_Text:
+ static_cast<CFX_XMLText*>(GetXMLMappingNode())->SetText(value);
+ break;
+ default:
+ NOTREACHED();
+ }
+}
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 697320dcbb..cca03ee401 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -169,6 +169,8 @@ class CXFA_Node : public CXFA_Object {
CFX_XMLNode* CreateXMLMappingNode();
bool IsNeedSavingXMLNode();
+ void SetToXML(const WideString& value);
+
uint32_t GetNameHash() const { return m_dwNameHash; }
bool IsUnnamed() const { return m_dwNameHash == 0; }
CXFA_Node* GetModelNode();