diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-27 18:28:06 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-27 18:28:06 +0000 |
commit | f351ba03ebf31103c0a6a0c00b1477d39c060139 (patch) | |
tree | df924970828054a2ec8c1fa00c7546a15de106c8 /fxjs | |
parent | 9f0bba48c208722c8d05eaa5382254f3183c65b7 (diff) | |
download | pdfium-f351ba03ebf31103c0a6a0c00b1477d39c060139.tar.xz |
Add some helpers for attribute lookup
This CL adds helpers to CXFA_Node to convert from strings to attributes
and from attributes to their string names. A static_assert was added to
make sure the list of attributes is the same size as the attribute data
so the checks can be removed.
Change-Id: Idebc65021d71f604bcf498e4cf42252af00d802b
Reviewed-on: https://pdfium-review.googlesource.com/19270
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cjx_node.cpp | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 5e00d525db..f01ead60a9 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -191,8 +191,6 @@ bool CJX_Node::SetAttribute(XFA_Attribute eAttr, const WideStringView& wsValue, bool bNotify) { const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); - if (!pAttr) - return false; XFA_AttributeType eType = pAttr->eType; if (eType == XFA_AttributeType::NotSure) { @@ -228,9 +226,9 @@ bool CJX_Node::SetAttribute(XFA_Attribute eAttr, bool CJX_Node::SetAttribute(const WideStringView& wsAttr, const WideStringView& wsValue, bool bNotify) { - const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); - if (pAttributeInfo) - return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); + XFA_Attribute attr = CXFA_Node::NameToAttribute(wsValue); + if (attr != XFA_Attribute::Unknown) + return SetAttribute(attr, wsValue, bNotify); void* pKey = GetMapKey_Custom(wsAttr); SetMapModuleString(pKey, wsValue); @@ -248,8 +246,6 @@ WideString CJX_Node::GetAttribute(XFA_Attribute attr) { pdfium::Optional<WideString> CJX_Node::TryAttribute(XFA_Attribute eAttr, bool bUseDefault) { const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); - if (!pAttr) - return {}; XFA_AttributeType eType = pAttr->eType; if (eType == XFA_AttributeType::NotSure) { @@ -298,9 +294,9 @@ pdfium::Optional<WideString> CJX_Node::TryAttribute(XFA_Attribute eAttr, pdfium::Optional<WideString> CJX_Node::TryAttribute( const WideStringView& wsAttr, bool bUseDefault) { - const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); - if (pAttributeInfo) - return TryAttribute(pAttributeInfo->eName, bUseDefault); + XFA_Attribute attr = CXFA_Node::NameToAttribute(wsAttr); + if (attr != XFA_Attribute::Unknown) + return TryAttribute(attr, bUseDefault); void* pKey = GetMapKey_Custom(wsAttr); WideStringView wsValueC; @@ -687,9 +683,8 @@ void CJX_Node::Script_NodeClass_IsPropertySpecified( WideString wsExpression = WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringView()); - const XFA_ATTRIBUTEINFO* pAttributeInfo = - XFA_GetAttributeByName(wsExpression.AsStringView()); - if (pAttributeInfo && HasAttribute(pAttributeInfo->eName)) { + XFA_Attribute attr = CXFA_Node::NameToAttribute(wsExpression.AsStringView()); + if (attr != XFA_Attribute::Unknown && HasAttribute(attr)) { pValue->SetBoolean(true); return; } @@ -701,7 +696,7 @@ void CJX_Node::Script_NodeClass_IsPropertySpecified( if (!bHas && bParent && GetXFANode()->GetParent()) { // Also check on the parent. auto* jsnode = GetXFANode()->GetParent()->JSNode(); - bHas = jsnode->HasAttribute(pAttributeInfo->eName) || + bHas = jsnode->HasAttribute(attr) || !!jsnode->GetProperty(iIndex, eType, true); } pValue->SetBoolean(bHas); @@ -3125,9 +3120,6 @@ bool CJX_Node::SetCData(XFA_Attribute eAttr, } const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); - if (!pInfo) - return true; - ASSERT(elem->GetType() == FX_XMLNODE_Element); WideString wsAttrName = pInfo->pName; if (pInfo->eName == XFA_Attribute::ContentType) @@ -3223,22 +3215,19 @@ bool CJX_Node::SetValue(XFA_Attribute eAttr, auto* elem = static_cast<CFX_XMLElement*>(GetXFANode()->GetXMLMappingNode()); ASSERT(elem->GetType() == FX_XMLNODE_Element); - const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); - if (!pInfo) - return true; switch (eType) { case XFA_AttributeType::Enum: elem->SetString( - pInfo->pName, + CXFA_Node::AttributeToName(eAttr), GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)->pName); break; case XFA_AttributeType::Boolean: - elem->SetString(pInfo->pName, pValue ? L"1" : L"0"); + elem->SetString(CXFA_Node::AttributeToName(eAttr), pValue ? L"1" : L"0"); break; case XFA_AttributeType::Integer: { elem->SetString( - pInfo->pName, + CXFA_Node::AttributeToName(eAttr), WideString::Format(L"%d", static_cast<int32_t>( reinterpret_cast<uintptr_t>(pValue)))); break; |