Make XFA_NodeFilter an enum class.
Use fxcrt::Mask<T> template to create masks of these values.
-- re-order some code to avoid making a temporary mask.
Change-Id: If26132186a22dd62d60ab4faf4800dd1fb151707
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/84074
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_resolveprocessor.cpp b/fxjs/xfa/cfxjse_resolveprocessor.cpp
index 58dc7ae..3bcf9f3 100644
--- a/fxjs/xfa/cfxjse_resolveprocessor.cpp
+++ b/fxjs/xfa/cfxjse_resolveprocessor.cpp
@@ -522,7 +522,7 @@
bool CFXJSE_ResolveProcessor::ResolveAsterisk(CFXJSE_ResolveNodeData& rnd) {
CXFA_Node* curNode = ToNode(rnd.m_CurObject.Get());
std::vector<CXFA_Node*> array = curNode->GetNodeListWithFilter(
- XFA_NodeFilter_Children | XFA_NodeFilter_Properties);
+ {XFA_NodeFilter::kChildren, XFA_NodeFilter::kProperties});
rnd.m_Result.objects.insert(rnd.m_Result.objects.end(), array.begin(),
array.end());
return !rnd.m_Result.objects.empty();
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index e53ae3e..788d3ee 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -460,7 +460,7 @@
}
std::vector<CXFA_Node*> properties =
- GetXFANode()->GetNodeListWithFilter(XFA_NodeFilter_OneOfProperty);
+ GetXFANode()->GetNodeListWithFilter(XFA_NodeFilter::kOneOfProperty);
if (!properties.empty()) {
*pValue = GetDocument()->GetScriptContext()->GetOrCreateJSBindingFromMap(
properties.front());
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 740d41d..4d1ae6f 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -676,7 +676,7 @@
case XFA_FFWidgetType::kChoiceList:
if (pFormNode->IsChoiceListMultiSelect()) {
std::vector<CXFA_Node*> items = pDataNode->GetNodeListWithFilter(
- XFA_NodeFilter_Children | XFA_NodeFilter_Properties);
+ {XFA_NodeFilter::kChildren, XFA_NodeFilter::kProperties});
if (!items.empty()) {
bool single = items.size() == 1;
wsNormalizeValue.clear();
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 7aacbbf5..0cb8edf 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -680,24 +680,24 @@
CXFA_Node* FindFirstSiblingNamedInList(CXFA_Node* parent,
uint32_t dwNameHash,
- uint32_t dwFilter);
+ Mask<XFA_NodeFilter> dwFilter);
CXFA_Node* FindFirstSiblingOfClassInList(CXFA_Node* parent,
XFA_Element element,
- uint32_t dwFilter);
+ Mask<XFA_NodeFilter> dwFilter);
CXFA_Node* FindFirstSiblingNamed(CXFA_Node* parent, uint32_t dwNameHash) {
CXFA_Node* result = FindFirstSiblingNamedInList(parent, dwNameHash,
- XFA_NodeFilter_Properties);
+ XFA_NodeFilter::kProperties);
if (result)
return result;
return FindFirstSiblingNamedInList(parent, dwNameHash,
- XFA_NodeFilter_Children);
+ XFA_NodeFilter::kChildren);
}
CXFA_Node* FindFirstSiblingNamedInList(CXFA_Node* parent,
uint32_t dwNameHash,
- uint32_t dwFilter) {
+ Mask<XFA_NodeFilter> dwFilter) {
for (CXFA_Node* child : parent->GetNodeListWithFilter(dwFilter)) {
if (child->GetNameHash() == dwNameHash)
return child;
@@ -710,18 +710,18 @@
}
CXFA_Node* FindFirstSiblingOfClass(CXFA_Node* parent, XFA_Element element) {
- CXFA_Node* result =
- FindFirstSiblingOfClassInList(parent, element, XFA_NodeFilter_Properties);
+ CXFA_Node* result = FindFirstSiblingOfClassInList(
+ parent, element, XFA_NodeFilter::kProperties);
if (result)
return result;
return FindFirstSiblingOfClassInList(parent, element,
- XFA_NodeFilter_Children);
+ XFA_NodeFilter::kChildren);
}
CXFA_Node* FindFirstSiblingOfClassInList(CXFA_Node* parent,
XFA_Element element,
- uint32_t dwFilter) {
+ Mask<XFA_NodeFilter> dwFilter) {
for (CXFA_Node* child : parent->GetNodeListWithFilter(dwFilter)) {
if (child->GetElementType() == element)
return child;
@@ -760,7 +760,7 @@
DCHECK(parent);
DCHECK(pSiblings);
for (CXFA_Node* child :
- parent->GetNodeListWithFilter(XFA_NodeFilter_Children)) {
+ parent->GetNodeListWithFilter(XFA_NodeFilter::kChildren)) {
if (child->GetElementType() == XFA_Element::Variables)
continue;
@@ -785,7 +785,7 @@
DCHECK(parent);
DCHECK(pSiblings);
for (CXFA_Node* child :
- parent->GetNodeListWithFilter(XFA_NodeFilter_Properties)) {
+ parent->GetNodeListWithFilter(XFA_NodeFilter::kProperties)) {
if (bIsClassName) {
if (child->GetClassHashCode() == dwNameHash)
pSiblings->push_back(child);
@@ -1198,21 +1198,24 @@
}
std::vector<CXFA_Node*> CXFA_Node::GetNodeListWithFilter(
- XFA_NodeFilterMask dwFilter) {
+ Mask<XFA_NodeFilter> dwFilter) {
+ if (!dwFilter)
+ return std::vector<CXFA_Node*>();
+
+ const bool bFilterChildren = !!(dwFilter & XFA_NodeFilter::kChildren);
+ const bool bFilterProperties = !!(dwFilter & XFA_NodeFilter::kProperties);
+ const bool bFilterOneOfProperties =
+ !!(dwFilter & XFA_NodeFilter::kOneOfProperty);
+
std::vector<CXFA_Node*> nodes;
- if (dwFilter == (XFA_NodeFilter_Children | XFA_NodeFilter_Properties)) {
+ if (bFilterChildren && bFilterProperties && !bFilterOneOfProperties) {
for (CXFA_Node* pChild = GetFirstChild(); pChild;
- pChild = pChild->GetNextSibling())
+ pChild = pChild->GetNextSibling()) {
nodes.push_back(pChild);
+ }
return nodes;
}
- if (dwFilter == 0)
- return nodes;
-
- bool bFilterChildren = !!(dwFilter & XFA_NodeFilter_Children);
- bool bFilterProperties = !!(dwFilter & XFA_NodeFilter_Properties);
- bool bFilterOneOfProperties = !!(dwFilter & XFA_NodeFilter_OneOfProperty);
for (CXFA_Node* pChild = GetFirstChild(); pChild;
pChild = pChild->GetNextSibling()) {
if (HasProperty(pChild->GetElementType())) {
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index a06fd38..ec2b35f 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -16,6 +16,7 @@
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/mask.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxge/dib/fx_dib.h"
@@ -54,12 +55,11 @@
class CXFA_WidgetLayoutData;
class GCedLocaleIface;
-enum XFA_NodeFilter : uint8_t {
- XFA_NodeFilter_Children = 1 << 0,
- XFA_NodeFilter_Properties = 1 << 1,
- XFA_NodeFilter_OneOfProperty = 1 << 2,
+enum class XFA_NodeFilter : uint8_t {
+ kChildren = 1 << 0,
+ kProperties = 1 << 1,
+ kOneOfProperty = 1 << 2,
};
-using XFA_NodeFilterMask = std::underlying_type<XFA_NodeFilter>::type;
enum class XFA_CheckState : uint8_t {
kOn = 0,
@@ -200,7 +200,7 @@
CXFA_Node* GetContainerParent() const;
std::vector<CXFA_Node*> GetNodeListForType(XFA_Element eTypeFilter);
- std::vector<CXFA_Node*> GetNodeListWithFilter(XFA_NodeFilterMask dwFilter);
+ std::vector<CXFA_Node*> GetNodeListWithFilter(Mask<XFA_NodeFilter> dwFilter);
CXFA_Node* CreateSamePacketNode(XFA_Element eType);
CXFA_Node* CloneTemplateToForm(bool bRecursive);
CXFA_Node* GetTemplateNodeIfExists() const;