diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-30 20:21:00 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-30 20:21:00 +0000 |
commit | 5fda35f2b0a658e310f778c2dc40ef24e6d05975 (patch) | |
tree | 3daddbde21cef2a9aa3aa2827a1c34ef06ad6a85 /xfa/fxfa/parser/cxfa_node.cpp | |
parent | 0be087619a60b8bc6e2ed2e14c54f67aa8e963e4 (diff) | |
download | pdfium-5fda35f2b0a658e310f778c2dc40ef24e6d05975.tar.xz |
Generate XFA node attribute information
This CL moves the attribute information out of the xfa basic data array
and stores in the generated nodes.
Change-Id: Id8e280324bf0f75a1da9c937c2734d161324242d
Reviewed-on: https://pdfium-review.googlesource.com/19271
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_node.cpp')
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 92 |
1 files changed, 29 insertions, 63 deletions
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 05228734f3..4eff4b0748 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -138,34 +138,13 @@ const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { return g_XFAEnumData + eName; } -// static -WideString CXFA_Node::AttributeToName(XFA_Attribute attr) { - return XFA_GetAttributeByID(attr)->pName; -} - -// static -XFA_Attribute CXFA_Node::NameToAttribute(const WideStringView& name) { - if (name.IsEmpty()) - return XFA_Attribute::Unknown; - - auto* it = std::lower_bound(g_XFAAttributeData, - g_XFAAttributeData + g_iXFAAttributeCount, - FX_HashCode_GetW(name, false), - [](const XFA_ATTRIBUTEINFO& arg, uint32_t hash) { - return arg.uHash < hash; - }); - if (it != g_XFAAttributeData + g_iXFAAttributeCount && name == it->pName) - return it->eName; - return XFA_Attribute::Unknown; -} - CXFA_Node::CXFA_Node(CXFA_Document* pDoc, uint16_t ePacket, uint32_t validPackets, XFA_ObjectType oType, XFA_Element eType, const PropertyData* properties, - const XFA_Attribute* attributes, + const AttributeData* attributes, const WideStringView& elementName) : CXFA_Object(pDoc, oType, @@ -312,36 +291,35 @@ pdfium::Optional<XFA_Element> CXFA_Node::GetFirstPropertyWithFlag( return {}; } -bool CXFA_Node::HasAttribute(XFA_Attribute attr) const { +const CXFA_Node::AttributeData* CXFA_Node::GetAttributeData( + XFA_Attribute attr) const { if (m_Attributes == nullptr) - return false; + return nullptr; for (size_t i = 0;; ++i) { - XFA_Attribute cur_attr = *(m_Attributes + i); - if (cur_attr == XFA_Attribute::Unknown) + const AttributeData* cur_attr = &m_Attributes[i]; + if (cur_attr->attribute == XFA_Attribute::Unknown) break; - if (cur_attr == attr) - return true; + if (cur_attr->attribute == attr) + return cur_attr; } - return false; + return nullptr; +} + +bool CXFA_Node::HasAttribute(XFA_Attribute attr) const { + return !!GetAttributeData(attr); } // Note: This Method assumes that i is a valid index .... XFA_Attribute CXFA_Node::GetAttribute(size_t i) const { if (m_Attributes == nullptr) return XFA_Attribute::Unknown; - return *(m_Attributes + i); + return m_Attributes[i].attribute; } XFA_AttributeType CXFA_Node::GetAttributeType(XFA_Attribute type) const { - const XFA_ATTRIBUTEINFO* attr = XFA_GetAttributeByID(type); - XFA_AttributeType eType = attr->eType; - if (eType != XFA_AttributeType::NotSure) - return eType; - - const XFA_NOTSUREATTRIBUTE* pNotsure = - XFA_GetNotsureAttribute(GetElementType(), attr->eName); - return pNotsure ? pNotsure->eType : XFA_AttributeType::CData; + const AttributeData* data = GetAttributeData(type); + return data ? data->type : XFA_AttributeType::CData; } CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, @@ -654,7 +632,9 @@ bool CXFA_Node::GetLocaleName(WideString& wsLocaleName) { XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep); - XFA_ATTRIBUTEENUM eLayoutType = JSNode()->GetEnum(XFA_Attribute::Layout); + XFA_ATTRIBUTEENUM eLayoutType = JSNode() + ->TryEnum(XFA_Attribute::Layout, true) + .value_or(XFA_ATTRIBUTEENUM_Position); if (pKeep) { pdfium::Optional<XFA_ATTRIBUTEENUM> intact = pKeep->JSNode()->TryEnum(XFA_Attribute::Intact, false); @@ -710,7 +690,9 @@ XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { return XFA_ATTRIBUTEENUM_ContentArea; if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { XFA_ATTRIBUTEENUM eParLayout = - pParentNode->JSNode()->GetEnum(XFA_Attribute::Layout); + pParentNode->JSNode() + ->TryEnum(XFA_Attribute::Layout, true) + .value_or(XFA_ATTRIBUTEENUM_Position); if (eParLayout == XFA_ATTRIBUTEENUM_Position || eParLayout == XFA_ATTRIBUTEENUM_Row || eParLayout == XFA_ATTRIBUTEENUM_Table) { @@ -1118,17 +1100,8 @@ void CXFA_Node::OnRemoved(bool bNotify) { } void CXFA_Node::UpdateNameHash() { - const XFA_NOTSUREATTRIBUTE* pNotsure = - XFA_GetNotsureAttribute(GetElementType(), XFA_Attribute::Name); - WideString wsName; - if (!pNotsure || pNotsure->eType == XFA_AttributeType::CData) { - wsName = JSNode()->GetCData(XFA_Attribute::Name); - 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.AsStringView(), false); - } + WideString wsName = JSNode()->GetCData(XFA_Attribute::Name); + m_dwNameHash = FX_HashCode_GetW(wsName.AsStringView(), false); } CFX_XMLNode* CXFA_Node::CreateXMLMappingNode() { @@ -1378,19 +1351,12 @@ pdfium::Optional<XFA_ATTRIBUTEENUM> CXFA_Node::GetDefaultEnum( pdfium::Optional<void*> CXFA_Node::GetDefaultValue( XFA_Attribute attr, XFA_AttributeType eType) const { - const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(attr); - if (!pInfo) + const AttributeData* data = GetAttributeData(attr); + if (!data) return {}; - if (GetPacketID() && (GetPacketID() & pInfo->dwPackets) == 0) + if (GetPacketID() && (GetPacketID() & data->packets) == 0) return {}; - if (pInfo->eType == eType) - return {pInfo->pDefValue}; - if (pInfo->eType != XFA_AttributeType::NotSure) - return {}; - - const XFA_NOTSUREATTRIBUTE* pAttr = - XFA_GetNotsureAttribute(GetElementType(), attr, eType); - if (pAttr) - return {pAttr->pValue}; + if (data->type == eType) + return {data->default_value}; return {}; } |