summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/parser/cxfa_node.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp90
1 files changed, 71 insertions, 19 deletions
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 2ab0b18cf5..c906d26bda 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -199,10 +199,10 @@ CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
WideString wsName;
JSNode()->GetAttribute(XFA_Attribute::Name, wsName, false);
auto pCloneXMLElement = pdfium::MakeUnique<CFX_XMLElement>(wsName);
- WideStringView wsValue = JSNode()->GetCData(XFA_Attribute::Value);
- if (!wsValue.IsEmpty()) {
+ WideString wsValue = JSNode()->GetCData(XFA_Attribute::Value);
+ if (!wsValue.IsEmpty())
pCloneXMLElement->SetTextData(WideString(wsValue));
- }
+
pCloneXML.reset(pCloneXMLElement.release());
pClone->JSNode()->SetEnum(XFA_Attribute::Contains,
XFA_ATTRIBUTEENUM_Unknown, false);
@@ -852,18 +852,17 @@ bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
if (pNode->m_pXMLNode->GetType() == FX_XMLNODE_Element) {
CFX_XMLElement* pXMLElement =
static_cast<CFX_XMLElement*>(pNode->m_pXMLNode);
- WideStringView wsAttributeName =
+ WideString wsAttributeName =
pNode->JSNode()->GetCData(XFA_Attribute::QualifiedName);
- // TODO(tsepez): check usage of c_str() below.
- pXMLElement->RemoveAttribute(wsAttributeName.unterminated_c_str());
+ pXMLElement->RemoveAttribute(wsAttributeName.c_str());
}
WideString wsName;
pNode->JSNode()->GetAttribute(XFA_Attribute::Name, wsName, false);
CFX_XMLElement* pNewXMLElement = new CFX_XMLElement(wsName);
- WideStringView wsValue = JSNode()->GetCData(XFA_Attribute::Value);
- if (!wsValue.IsEmpty()) {
+ WideString wsValue = JSNode()->GetCData(XFA_Attribute::Value);
+ if (!wsValue.IsEmpty())
pNewXMLElement->SetTextData(WideString(wsValue));
- }
+
pNode->m_pXMLNode = pNewXMLElement;
pNode->JSNode()->SetEnum(XFA_Attribute::Contains,
XFA_ATTRIBUTEENUM_Unknown, false);
@@ -963,9 +962,8 @@ CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
break;
}
if (eType == XFA_Element::InstanceManager) {
- WideStringView wsName = JSNode()->GetCData(XFA_Attribute::Name);
- WideStringView wsInstName =
- pNode->JSNode()->GetCData(XFA_Attribute::Name);
+ WideString wsName = JSNode()->GetCData(XFA_Attribute::Name);
+ WideString wsInstName = pNode->JSNode()->GetCData(XFA_Attribute::Name);
if (wsInstName.GetLength() > 0 && wsInstName[0] == '_' &&
wsInstName.Right(wsInstName.GetLength() - 1) == wsName) {
pInstanceMgr = pNode;
@@ -1020,14 +1018,14 @@ void CXFA_Node::OnRemoved(bool bNotify) {
void CXFA_Node::UpdateNameHash() {
const XFA_NOTSUREATTRIBUTE* pNotsure =
XFA_GetNotsureAttribute(GetElementType(), XFA_Attribute::Name);
- WideStringView wsName;
+ WideString wsName;
if (!pNotsure || pNotsure->eType == XFA_AttributeType::CData) {
wsName = JSNode()->GetCData(XFA_Attribute::Name);
- m_dwNameHash = FX_HashCode_GetW(wsName, false);
+ m_dwNameHash = FX_HashCode_GetW(wsName.AsStringView(), false);
} else if (pNotsure->eType == XFA_AttributeType::Enum) {
wsName =
GetAttributeEnumByID(JSNode()->GetEnum(XFA_Attribute::Name))->pName;
- m_dwNameHash = FX_HashCode_GetW(wsName, false);
+ m_dwNameHash = FX_HashCode_GetW(wsName.AsStringView(), false);
}
}
@@ -1058,8 +1056,8 @@ CXFA_Node* CXFA_Node::GetItem(int32_t iIndex) {
continue;
}
if (iCount == 0) {
- WideStringView wsName = pNode->JSNode()->GetCData(XFA_Attribute::Name);
- WideStringView wsInstName = JSNode()->GetCData(XFA_Attribute::Name);
+ WideString wsName = pNode->JSNode()->GetCData(XFA_Attribute::Name);
+ WideString wsInstName = JSNode()->GetCData(XFA_Attribute::Name);
if (wsInstName.GetLength() < 1 || wsInstName[0] != '_' ||
wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return nullptr;
@@ -1089,8 +1087,8 @@ int32_t CXFA_Node::GetCount() {
continue;
}
if (iCount == 0) {
- WideStringView wsName = pNode->JSNode()->GetCData(XFA_Attribute::Name);
- WideStringView wsInstName = JSNode()->GetCData(XFA_Attribute::Name);
+ WideString wsName = pNode->JSNode()->GetCData(XFA_Attribute::Name);
+ WideString wsInstName = JSNode()->GetCData(XFA_Attribute::Name);
if (wsInstName.GetLength() < 1 || wsInstName[0] != '_' ||
wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return iCount;
@@ -1229,3 +1227,57 @@ CXFA_Node* CXFA_Node::CreateInstance(bool bDataMerge) {
return pInstance;
}
+pdfium::Optional<bool> CXFA_Node::GetDefaultBoolean(XFA_Attribute attr) const {
+ void* pValue = nullptr;
+ if (!XFA_GetAttributeDefaultValue(pValue, GetElementType(), attr,
+ XFA_AttributeType::Boolean,
+ GetPacketID())) {
+ return {};
+ }
+ return {!!pValue};
+}
+
+pdfium::Optional<int32_t> CXFA_Node::GetDefaultInteger(
+ XFA_Attribute attr) const {
+ void* pValue = nullptr;
+ if (!XFA_GetAttributeDefaultValue(pValue, GetElementType(), attr,
+ XFA_AttributeType::Integer,
+ GetPacketID())) {
+ return {};
+ }
+ return {static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue))};
+}
+
+pdfium::Optional<CXFA_Measurement> CXFA_Node::GetDefaultMeasurement(
+ XFA_Attribute attr) const {
+ void* pValue = nullptr;
+ if (!XFA_GetAttributeDefaultValue(pValue, GetElementType(), attr,
+ XFA_AttributeType::Measure,
+ GetPacketID())) {
+ return {};
+ }
+ CXFA_Measurement measure;
+ memcpy(&measure, pValue, sizeof(measure));
+ return {measure};
+}
+
+pdfium::Optional<WideString> CXFA_Node::GetDefaultCData(
+ XFA_Attribute attr) const {
+ void* pValue = nullptr;
+ if (!XFA_GetAttributeDefaultValue(pValue, GetElementType(), attr,
+ XFA_AttributeType::CData, GetPacketID())) {
+ return {};
+ }
+ WideStringView view((const wchar_t*)pValue);
+ return {WideString(view)};
+}
+
+pdfium::Optional<XFA_ATTRIBUTEENUM> CXFA_Node::GetDefaultEnum(
+ XFA_Attribute attr) const {
+ void* pValue = nullptr;
+ if (!XFA_GetAttributeDefaultValue(pValue, GetElementType(), attr,
+ XFA_AttributeType::Enum, GetPacketID())) {
+ return {};
+ }
+ return {static_cast<XFA_ATTRIBUTEENUM>(reinterpret_cast<uintptr_t>(pValue))};
+}