summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-27 18:10:47 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-27 18:10:47 +0000
commitf473672fd6305fe97c749bde3b92e3c9c90e88d0 (patch)
treefe1ec0af4f66a801c7a08fd762e61b065b89d4ec /fxjs
parent3636a854af15219fd679ed54207abcdad3283b9b (diff)
downloadpdfium-f473672fd6305fe97c749bde3b92e3c9c90e88d0.tar.xz
Generate XFA node classes
This CL adds concrete classes for each of the XFA Node types. Change-Id: Ieac8e2fcd5d13c61daa27fc63e3d80abb7aa7a29 Reviewed-on: https://pdfium-review.googlesource.com/18271 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cfxjse_engine.cpp2
-rw-r--r--fxjs/cfxjse_resolveprocessor.cpp13
-rw-r--r--fxjs/cjx_node.cpp42
3 files changed, 15 insertions, 42 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index c2dba2f311..9eeb9bda89 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -365,7 +365,7 @@ void CFXJSE_Engine::NormalPropertySetter(CFXJSE_Value* pOriginalValue,
CXFA_Node* pNode = ToNode(pObject);
CXFA_Node* pPropOrChild = nullptr;
- XFA_Element eType = XFA_GetElementTypeForName(wsPropName.AsStringView());
+ XFA_Element eType = CXFA_Node::NameToElement(wsPropName);
if (eType != XFA_Element::Unknown)
pPropOrChild = pNode->JSNode()->GetProperty(0, eType, true);
else
diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp
index 3a6bc91d50..ef0fcbf174 100644
--- a/fxjs/cfxjse_resolveprocessor.cpp
+++ b/fxjs/cfxjse_resolveprocessor.cpp
@@ -242,10 +242,7 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) {
pPageSetNode = pChild;
continue;
}
- const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
- curNode->GetElementType(), pChild->GetElementType(),
- XFA_XDPPACKET_UNKNOWN);
- if (pProperty)
+ if (curNode->HasProperty(pChild->GetElementType()))
properties.push_back(pChild);
else
children.push_back(pChild);
@@ -348,7 +345,7 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) {
true);
}
} else {
- XFA_Element eType = XFA_GetElementTypeForName(wsName.AsStringView());
+ XFA_Element eType = CXFA_Node::NameToElement(wsName);
if (eType != XFA_Element::Unknown) {
pProp = curNode->AsNode()->JSNode()->GetProperty(
0, eType, eType != XFA_Element::PageSet);
@@ -405,11 +402,9 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) {
} else if (child->GetNameHash() == uNameHash) {
rnd.m_Objects.push_back(child);
}
- const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement(
- parentNode->GetElementType(), child->GetElementType(),
- XFA_XDPPACKET_UNKNOWN);
+
bool bInnerSearch = false;
- if (pPropert) {
+ if (parentNode->HasProperty(child->GetElementType())) {
if ((child->GetElementType() == XFA_Element::Variables ||
child->GetElementType() == XFA_Element::PageSet)) {
bInnerSearch = true;
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index 2d96cbb8f3..5e00d525db 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -92,24 +92,6 @@ void* GetMapKey_Element(XFA_Element eType, XFA_Attribute eAttribute) {
XFA_KEYTYPE_Element);
}
-const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
- XFA_Attribute eAttribute,
- uint32_t dwPacket) {
- int32_t iCount = 0;
- const XFA_Attribute* pAttr = XFA_GetElementAttributes(eElement, iCount);
- if (!pAttr || iCount < 1)
- return nullptr;
-
- if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
- return nullptr;
-
- const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
- ASSERT(pInfo);
- if (dwPacket == XFA_XDPPACKET_UNKNOWN)
- return pInfo;
- return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
-}
-
struct XFA_ExecEventParaInfo {
public:
uint32_t m_uHash;
@@ -685,8 +667,8 @@ void CJX_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringView());
int32_t iValue = iLength >= 2 ? pArguments->GetInt32(1) : 0;
- CXFA_Node* pNode = GetProperty(
- iValue, XFA_GetElementTypeForName(wsExpression.AsStringView()), true);
+ CXFA_Node* pNode =
+ GetProperty(iValue, CXFA_Node::NameToElement(wsExpression), true);
pArguments->GetReturnValue()->Assign(
GetDocument()->GetScriptContext()->GetJSValueFromMap(pNode));
}
@@ -714,7 +696,7 @@ void CJX_Node::Script_NodeClass_IsPropertySpecified(
bool bParent = iLength < 2 || pArguments->GetInt32(1);
int32_t iIndex = iLength == 3 ? pArguments->GetInt32(2) : 0;
- XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringView());
+ XFA_Element eType = CXFA_Node::NameToElement(wsExpression);
bool bHas = !!GetProperty(iIndex, eType, true);
if (!bHas && bParent && GetXFANode()->GetParent()) {
// Also check on the parent.
@@ -2382,7 +2364,7 @@ void CJX_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
ByteString bsTagName = pArguments->GetUTF8String(0);
WideString strTagName = WideString::FromUTF8(bsTagName.AsStringView());
- XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringView());
+ XFA_Element eType = CXFA_Node::NameToElement(strTagName);
CXFA_Node* pNewNode = GetXFANode()->CreateSamePacketNode(eType);
if (!pNewNode) {
pArguments->GetReturnValue()->SetNull();
@@ -2395,8 +2377,7 @@ void CJX_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
return;
}
- if (!GetAttributeOfElement(eType, XFA_Attribute::Name,
- XFA_XDPPACKET_UNKNOWN)) {
+ if (!pNewNode->HasAttribute(XFA_Attribute::Name)) {
ThrowMissingPropertyException(strTagName, L"name");
return;
}
@@ -3580,11 +3561,8 @@ pdfium::Optional<WideString> CJX_Node::TryNamespace() {
CXFA_Node* CJX_Node::GetProperty(int32_t index,
XFA_Element eProperty,
bool bCreateProperty) {
- XFA_Element eType = GetXFANode()->GetElementType();
uint32_t dwPacket = GetXFANode()->GetPacketID();
- const XFA_PROPERTY* pProperty =
- XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
- if (!pProperty || index >= pProperty->uOccur)
+ if (index < 0 || index >= GetXFANode()->PropertyOccuranceCount(eProperty))
return nullptr;
CXFA_Node* pNode = GetXFANode()->GetChildNode();
@@ -3599,13 +3577,13 @@ CXFA_Node* CJX_Node::GetProperty(int32_t index,
if (!bCreateProperty)
return nullptr;
- if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
+ if (GetXFANode()->HasPropertyFlags(eProperty, XFA_PROPERTYFLAG_OneOf)) {
pNode = GetXFANode()->GetChildNode();
for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
- const XFA_PROPERTY* pExistProperty =
- XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
- if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
+ if (GetXFANode()->HasPropertyFlags(pNode->GetElementType(),
+ XFA_PROPERTYFLAG_OneOf)) {
return nullptr;
+ }
}
}