Create CXFA_Node::PresenceRequiresSpace

This CL replaces XFA_ItemLayoutProcessor_IsTakingSpace with a
PresenceRequiresSpace call on CXFA_Node.

Change-Id: Ibf570f25eeb3404d72e87cb62e06a7ad70f0916f
Reviewed-on: https://pdfium-review.googlesource.com/24850
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
index 98e3234..f5392a5 100644
--- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
+++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
@@ -239,7 +239,7 @@
 
     pLayoutChild->m_sPos = CFX_PointF(fCurrentColX, 0);
     pLayoutChild->m_sSize.width = fColSpanWidth;
-    if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutChild->m_pFormNode))
+    if (!pLayoutChild->m_pFormNode->PresenceRequiresSpace())
       continue;
 
     fCurrentColX += fColSpanWidth;
@@ -520,7 +520,7 @@
 }
 
 bool ExistContainerKeep(CXFA_Node* pCurNode, bool bPreFind) {
-  if (!pCurNode || !XFA_ItemLayoutProcessor_IsTakingSpace(pCurNode))
+  if (!pCurNode || !pCurNode->PresenceRequiresSpace())
     return false;
 
   CXFA_Node* pPreContainer = bPreFind ? pCurNode->GetPrevContainerSibling()
@@ -666,8 +666,7 @@
     bool* bForceEndPage,
     CXFA_LayoutContext* pLayoutContext,
     bool bNewRow) {
-  bool bTakeSpace =
-      XFA_ItemLayoutProcessor_IsTakingSpace(pProcessor->m_pFormNode);
+  bool bTakeSpace = pProcessor->m_pFormNode->PresenceRequiresSpace();
   uint8_t uHAlign = HAlignEnumToInt(
       pThis->m_pCurChildNode->JSObject()->GetEnum(XFA_Attribute::HAlign));
   if (bContainerWidthAutoSize)
@@ -1580,14 +1579,6 @@
   return FindBreakNode(pBreakAfterNode, pCurActionNode, &nCurStage, false);
 }
 
-bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode) {
-  XFA_AttributeEnum ePresence = pNode->JSObject()
-                                    ->TryEnum(XFA_Attribute::Presence, true)
-                                    .value_or(XFA_AttributeEnum::Visible);
-  return ePresence == XFA_AttributeEnum::Visible ||
-         ePresence == XFA_AttributeEnum::Invisible;
-}
-
 bool CXFA_ItemLayoutProcessor::IncrementRelayoutNode(
     CXFA_LayoutProcessor* pLayoutProcessor,
     CXFA_Node* pNode,
@@ -1714,7 +1705,7 @@
 
     CFX_SizeF size = pProcessor->GetCurrentComponentSize();
     bool bChangeParentSize = false;
-    if (XFA_ItemLayoutProcessor_IsTakingSpace(m_pCurChildNode))
+    if (m_pCurChildNode->PresenceRequiresSpace())
       bChangeParentSize = true;
 
     CFX_PointF absolutePos;
@@ -1847,7 +1838,7 @@
                            pLayoutChild->m_pNextSibling)) {
       if (pLayoutChild->m_pFormNode->GetElementType() != XFA_Element::Subform)
         continue;
-      if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutChild->m_pFormNode))
+      if (!pLayoutChild->m_pFormNode->PresenceRequiresSpace())
         continue;
 
       XFA_AttributeEnum eLayout =
@@ -1873,13 +1864,13 @@
       bMoreColumns = false;
       bool bAutoCol = false;
       for (int32_t i = 0; i < iRowCount; i++) {
-        while (rgRowItems[i] && (rgRowItemsSpan[i] <= 0 ||
-                                 !XFA_ItemLayoutProcessor_IsTakingSpace(
-                                     rgRowItems[i]->m_pFormNode))) {
+        while (rgRowItems[i] &&
+               (rgRowItemsSpan[i] <= 0 ||
+                !rgRowItems[i]->m_pFormNode->PresenceRequiresSpace())) {
           CXFA_ContentLayoutItem* pNewCell =
               (CXFA_ContentLayoutItem*)rgRowItems[i]->m_pNextSibling;
-          if (rgRowItemsSpan[i] < 0 && XFA_ItemLayoutProcessor_IsTakingSpace(
-                                           rgRowItems[i]->m_pFormNode)) {
+          if (rgRowItemsSpan[i] < 0 &&
+              rgRowItems[i]->m_pFormNode->PresenceRequiresSpace()) {
             pNewCell = nullptr;
           }
           rgRowItems[i] = pNewCell;
@@ -1933,7 +1924,7 @@
            (CXFA_ContentLayoutItem*)m_pLayoutItem->m_pFirstChild;
        pLayoutChild;
        pLayoutChild = (CXFA_ContentLayoutItem*)pLayoutChild->m_pNextSibling) {
-    if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutChild->m_pFormNode))
+    if (!pLayoutChild->m_pFormNode->PresenceRequiresSpace())
       continue;
 
     if (pLayoutChild->m_pFormNode->GetElementType() == XFA_Element::Subform) {
@@ -2222,7 +2213,7 @@
          pLayoutTempChild != pLayoutChild;
          pLayoutTempChild =
              (CXFA_ContentLayoutItem*)pLayoutTempChild->m_pNextSibling) {
-      if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutTempChild->m_pFormNode))
+      if (!pLayoutTempChild->m_pFormNode->PresenceRequiresSpace())
         continue;
 
       fContentCalculatedWidth = std::max(
@@ -2281,7 +2272,7 @@
         } else if (uHAlign < uCurHAlignState) {
           uCurHAlignState = uHAlign;
         }
-        if (XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutNext->m_pFormNode)) {
+        if (pLayoutNext->m_pFormNode->PresenceRequiresSpace()) {
           if (pLayoutNext->m_sSize.height > fContentCurRowHeight)
             fContentCurRowHeight = pLayoutNext->m_sSize.height;
           fContentCurRowAvailWidth -= pLayoutNext->m_sSize.width;
@@ -2489,7 +2480,7 @@
           if (m_pCurChildNode->GetElementType() == XFA_Element::Variables)
             break;
           if (fContentCurRowY >= fHeightLimit + XFA_LAYOUT_FLOAT_PERCISION &&
-              XFA_ItemLayoutProcessor_IsTakingSpace(m_pCurChildNode)) {
+              m_pCurChildNode->PresenceRequiresSpace()) {
             bForceEndPage = true;
             goto SuspendAndCreateNewRow;
           }
@@ -2602,10 +2593,8 @@
     nGroupLengths[i] = pdfium::CollectionSize<int32_t>(rgCurLineLayoutItems[i]);
     for (int32_t c = nGroupLengths[i], j = 0; j < c; j++) {
       nTotalLength++;
-      if (XFA_ItemLayoutProcessor_IsTakingSpace(
-              rgCurLineLayoutItems[i][j]->m_pFormNode)) {
+      if (rgCurLineLayoutItems[i][j]->m_pFormNode->PresenceRequiresSpace())
         fGroupWidths[i] += rgCurLineLayoutItems[i][j]->m_sSize.width;
-      }
     }
   }
   if (!nTotalLength) {
@@ -2629,10 +2618,8 @@
       } else {
         rgCurLineLayoutItems[0][j]->m_sPos =
             CFX_PointF(fCurPos, *fContentCurRowY);
-        if (XFA_ItemLayoutProcessor_IsTakingSpace(
-                rgCurLineLayoutItems[0][j]->m_pFormNode)) {
+        if (rgCurLineLayoutItems[0][j]->m_pFormNode->PresenceRequiresSpace())
           fCurPos += rgCurLineLayoutItems[0][j]->m_sSize.width;
-        }
       }
       m_pLayoutItem->AddChild(rgCurLineLayoutItems[0][j]);
       m_fLastRowWidth = fCurPos;
@@ -2648,10 +2635,8 @@
       } else {
         rgCurLineLayoutItems[1][j]->m_sPos =
             CFX_PointF(fCurPos, *fContentCurRowY);
-        if (XFA_ItemLayoutProcessor_IsTakingSpace(
-                rgCurLineLayoutItems[1][j]->m_pFormNode)) {
+        if (rgCurLineLayoutItems[1][j]->m_pFormNode->PresenceRequiresSpace())
           fCurPos += rgCurLineLayoutItems[1][j]->m_sSize.width;
-        }
       }
       m_pLayoutItem->AddChild(rgCurLineLayoutItems[1][j]);
       m_fLastRowWidth = fCurPos;
@@ -2665,10 +2650,8 @@
       } else {
         rgCurLineLayoutItems[2][j]->m_sPos =
             CFX_PointF(fCurPos, *fContentCurRowY);
-        if (XFA_ItemLayoutProcessor_IsTakingSpace(
-                rgCurLineLayoutItems[2][j]->m_pFormNode)) {
+        if (rgCurLineLayoutItems[2][j]->m_pFormNode->PresenceRequiresSpace())
           fCurPos += rgCurLineLayoutItems[2][j]->m_sSize.width;
-        }
       }
       m_pLayoutItem->AddChild(rgCurLineLayoutItems[2][j]);
       m_fLastRowWidth = fCurPos;
@@ -2677,10 +2660,9 @@
     float fCurPos;
     fCurPos = fGroupWidths[0];
     for (int32_t c = nGroupLengths[0], j = 0; j < c; j++) {
-      if (XFA_ItemLayoutProcessor_IsTakingSpace(
-              rgCurLineLayoutItems[0][j]->m_pFormNode)) {
+      if (rgCurLineLayoutItems[0][j]->m_pFormNode->PresenceRequiresSpace())
         fCurPos -= rgCurLineLayoutItems[0][j]->m_sSize.width;
-      }
+
       rgCurLineLayoutItems[0][j]->m_sPos =
           CFX_PointF(fCurPos, *fContentCurRowY);
       m_pLayoutItem->AddChild(rgCurLineLayoutItems[0][j]);
@@ -2690,10 +2672,9 @@
                fGroupWidths[2]) /
               2;
     for (int32_t c = nGroupLengths[1], j = 0; j < c; j++) {
-      if (XFA_ItemLayoutProcessor_IsTakingSpace(
-              rgCurLineLayoutItems[1][j]->m_pFormNode)) {
+      if (rgCurLineLayoutItems[1][j]->m_pFormNode->PresenceRequiresSpace())
         fCurPos -= rgCurLineLayoutItems[1][j]->m_sSize.width;
-      }
+
       rgCurLineLayoutItems[1][j]->m_sPos =
           CFX_PointF(fCurPos, *fContentCurRowY);
       m_pLayoutItem->AddChild(rgCurLineLayoutItems[1][j]);
@@ -2701,10 +2682,9 @@
     }
     fCurPos = fContentWidthLimit;
     for (int32_t c = nGroupLengths[2], j = 0; j < c; j++) {
-      if (XFA_ItemLayoutProcessor_IsTakingSpace(
-              rgCurLineLayoutItems[2][j]->m_pFormNode)) {
+      if (rgCurLineLayoutItems[2][j]->m_pFormNode->PresenceRequiresSpace())
         fCurPos -= rgCurLineLayoutItems[2][j]->m_sSize.width;
-      }
+
       rgCurLineLayoutItems[2][j]->m_sPos =
           CFX_PointF(fCurPos, *fContentCurRowY);
       m_pLayoutItem->AddChild(rgCurLineLayoutItems[2][j]);
diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h
index e178095..7dbc754 100644
--- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h
+++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h
@@ -46,8 +46,6 @@
   Done,
 };
 
-bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode);
-
 class CXFA_ItemLayoutProcessor {
  public:
   static bool IncrementRelayoutNode(CXFA_LayoutProcessor* pLayoutProcessor,
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index 123cafb..f921d80 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -398,8 +398,7 @@
     bProBreakBefore = true;
     pRootSubform =
         pRootSubform->GetFirstChildByClass<CXFA_Subform>(XFA_Element::Subform);
-    while (pRootSubform &&
-           !XFA_ItemLayoutProcessor_IsTakingSpace(pRootSubform)) {
+    while (pRootSubform && !pRootSubform->PresenceRequiresSpace()) {
       pRootSubform = pRootSubform->GetNextSameClassSibling<CXFA_Subform>(
           XFA_Element::Subform);
     }
@@ -885,7 +884,7 @@
   CXFA_Node* pLeaderTemplate = nullptr;
   CXFA_Node* pTrailerTemplate = nullptr;
   CXFA_Node* pFormNode = pBreakNode->GetContainerParent();
-  if (XFA_ItemLayoutProcessor_IsTakingSpace(pFormNode)) {
+  if (pFormNode->PresenceRequiresSpace()) {
     bCreatePage = ExecuteBreakBeforeOrAfter(pBreakNode, bBefore,
                                             pLeaderTemplate, pTrailerTemplate);
     CXFA_Document* pDocument = pBreakNode->GetDocument();
@@ -1760,8 +1759,7 @@
             pFormLayout = pFormLayout->m_pFirstChild;
             if (iLevel == 2) {
               while (pFormLayout &&
-                     !XFA_ItemLayoutProcessor_IsTakingSpace(
-                         pFormLayout->m_pFormNode)) {
+                     !pFormLayout->m_pFormNode->PresenceRequiresSpace()) {
                 pFormLayout = pFormLayout->m_pNextSibling;
               }
             }
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index ec9be78..7cda5ca 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -4673,3 +4673,11 @@
   }
   return wsRet;
 }
+
+bool CXFA_Node::PresenceRequiresSpace() const {
+  XFA_AttributeEnum ePresence = JSObject()
+                                    ->TryEnum(XFA_Attribute::Presence, true)
+                                    .value_or(XFA_AttributeEnum::Visible);
+  return ePresence == XFA_AttributeEnum::Visible ||
+         ePresence == XFA_AttributeEnum::Invisible;
+}
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 415ad94..22b5192 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -136,6 +136,8 @@
     return HasFlag(XFA_NodeFlag_LayoutGeneratedNode);
   }
 
+  bool PresenceRequiresSpace() const;
+
   void SetBindingNode(CXFA_Node* node) {
     binding_nodes_.clear();
     if (node)