Separate CXFA_ViewLayoutItem from CXFA_FFPageView.

Similar to https://pdfium-review.googlesource.com/c/pdfium/+/52970,
but applies to the other subclass of CXFA_LayoutItem.

- Fix some CamelCase in a member name.

Change-Id: I6ecbfb9f2cff420afe41108856ba86717752c535
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53170
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index cd51fe4..4b0ab34 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -555,7 +555,7 @@
   switch (pContext->GetFormType()) {
     case FormType::kXFAFull: {
       CXFA_FFPageView* pPageView = m_page->AsXFAPage()->GetXFAPageView();
-      return pPageView ? pPageView->GetPageIndex() : -1;
+      return pPageView ? pPageView->GetLayoutItem()->GetPageIndex() : -1;
     }
     case FormType::kNone:
     case FormType::kAcroForm:
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index bb7bb65..36b9633 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -200,7 +200,8 @@
 CXFA_FFPageView* CXFA_FFDocView::GetPageView(int32_t nIndex) const {
   if (!m_pXFADocLayout)
     return nullptr;
-  return static_cast<CXFA_FFPageView*>(m_pXFADocLayout->GetPage(nIndex));
+  auto* pPage = m_pXFADocLayout->GetPage(nIndex);
+  return pPage ? pPage->GetPageView() : nullptr;
 }
 
 CXFA_LayoutProcessor* CXFA_FFDocView::GetXFALayout() const {
@@ -431,7 +432,7 @@
 
 void CXFA_FFDocView::OnPageEvent(CXFA_ViewLayoutItem* pSender,
                                  uint32_t dwEvent) {
-  CXFA_FFPageView* pFFPageView = static_cast<CXFA_FFPageView*>(pSender);
+  CXFA_FFPageView* pFFPageView = pSender ? pSender->GetPageView() : nullptr;
   m_pDoc->GetDocEnvironment()->PageViewEvent(pFFPageView, dwEvent);
 }
 
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp
index 6c5f444..a58e4f1 100644
--- a/xfa/fxfa/cxfa_ffnotify.cpp
+++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -92,19 +92,14 @@
   }
 }
 
-std::unique_ptr<CXFA_ViewLayoutItem> CXFA_FFNotify::OnCreateViewLayoutItem(
+std::unique_ptr<CXFA_FFPageView> CXFA_FFNotify::OnCreateViewLayoutItem(
     CXFA_Node* pNode) {
-  XFA_Element type = pNode->GetElementType();
-  if (type == XFA_Element::PageArea) {
-    CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetLayoutProcessor();
-    return pdfium::MakeUnique<CXFA_FFPageView>(m_pDoc->GetDocView(pLayout),
-                                               pNode);
-  }
-  if (type == XFA_Element::ContentArea)
-    return pdfium::MakeUnique<CXFA_ViewLayoutItem>(pNode);
+  if (pNode->GetElementType() != XFA_Element::PageArea)
+    return nullptr;
 
-  NOTREACHED();
-  return nullptr;
+  CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetLayoutProcessor();
+  return pdfium::MakeUnique<CXFA_FFPageView>(m_pDoc->GetDocView(pLayout),
+                                             pNode);
 }
 
 std::unique_ptr<CXFA_FFWidget> CXFA_FFNotify::OnCreateContentLayoutItem(
diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h
index 23a50dc..7642308 100644
--- a/xfa/fxfa/cxfa_ffnotify.h
+++ b/xfa/fxfa/cxfa_ffnotify.h
@@ -42,7 +42,7 @@
   void OnChildAdded(CXFA_Node* pSender);
   void OnChildRemoved();
 
-  std::unique_ptr<CXFA_ViewLayoutItem> OnCreateViewLayoutItem(CXFA_Node* pNode);
+  std::unique_ptr<CXFA_FFPageView> OnCreateViewLayoutItem(CXFA_Node* pNode);
   std::unique_ptr<CXFA_FFWidget> OnCreateContentLayoutItem(CXFA_Node* pNode);
 
   void OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout,
diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp
index b5c5628..d517969 100644
--- a/xfa/fxfa/cxfa_ffpageview.cpp
+++ b/xfa/fxfa/cxfa_ffpageview.cpp
@@ -71,7 +71,7 @@
 bool PageWidgetFilter(CXFA_FFWidget* pWidget,
                       uint32_t dwFilter,
                       bool bTraversal,
-                      bool bIgnorerelevant) {
+                      bool bIgnoreRelevant) {
   CXFA_Node* pNode = pWidget->GetNode();
 
   if ((dwFilter & XFA_WidgetStatus_Focused) &&
@@ -82,8 +82,7 @@
   CXFA_ContentLayoutItem* pItem = pWidget->GetLayoutItem();
   if (bTraversal && pItem->TestStatusBits(XFA_WidgetStatus_Disabled))
     return false;
-
-  if (bIgnorerelevant)
+  if (bIgnoreRelevant)
     return pItem->TestStatusBits(XFA_WidgetStatus_Visible);
 
   dwFilter &= (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable |
@@ -112,7 +111,7 @@
 }  // namespace
 
 CXFA_FFPageView::CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea)
-    : CXFA_ViewLayoutItem(pPageArea), m_pDocView(pDocView) {}
+    : m_pPageArea(pPageArea), m_pDocView(pDocView) {}
 
 CXFA_FFPageView::~CXFA_FFPageView() {}
 
@@ -121,12 +120,13 @@
 }
 
 CFX_RectF CXFA_FFPageView::GetPageViewRect() const {
-  return CFX_RectF(0, 0, GetPageSize());
+  return CFX_RectF(0, 0, GetLayoutItem()->GetPageSize());
 }
 
 CFX_Matrix CXFA_FFPageView::GetDisplayMatrix(const FX_RECT& rtDisp,
                                              int32_t iRotate) const {
-  return GetPageMatrix(CFX_RectF(0, 0, GetPageSize()), rtDisp, iRotate, 0);
+  return GetPageMatrix(CFX_RectF(0, 0, GetLayoutItem()->GetPageSize()), rtDisp,
+                       iRotate, 0);
 }
 
 std::unique_ptr<IXFA_WidgetIterator> CXFA_FFPageView::CreateWidgetIterator(
@@ -145,8 +145,10 @@
 
 CXFA_FFPageWidgetIterator::CXFA_FFPageWidgetIterator(CXFA_FFPageView* pPageView,
                                                      uint32_t dwFilter)
-    : m_pPageView(pPageView), m_dwFilter(dwFilter), m_sIterator(pPageView) {
-  m_bIgnorerelevant =
+    : m_pPageView(pPageView),
+      m_dwFilter(dwFilter),
+      m_sIterator(pPageView->GetLayoutItem()) {
+  m_bIgnoreRelevant =
       m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() <
       XFA_VERSION_205;
 }
@@ -208,7 +210,7 @@
   if (!pWidget)
     return nullptr;
 
-  if (!PageWidgetFilter(pWidget, m_dwFilter, false, m_bIgnorerelevant))
+  if (!PageWidgetFilter(pWidget, m_dwFilter, false, m_bIgnoreRelevant))
     return nullptr;
 
   if (!pWidget->IsLoaded() &&
@@ -233,7 +235,7 @@
     CXFA_FFPageView* pPageView,
     uint32_t dwFilter)
     : m_pPageView(pPageView), m_dwFilter(dwFilter), m_iCurWidget(-1) {
-  m_bIgnorerelevant =
+  m_bIgnoreRelevant =
       m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() <
       XFA_VERSION_205;
   Reset();
@@ -250,7 +252,7 @@
   for (int32_t i = 0;
        i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
     if (PageWidgetFilter(m_TabOrderWidgetArray[i].Get(), m_dwFilter, true,
-                         m_bIgnorerelevant)) {
+                         m_bIgnoreRelevant)) {
       m_iCurWidget = i;
       return m_TabOrderWidgetArray[m_iCurWidget].Get();
     }
@@ -262,7 +264,7 @@
   for (int32_t i = pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) - 1;
        i >= 0; i--) {
     if (PageWidgetFilter(m_TabOrderWidgetArray[i].Get(), m_dwFilter, true,
-                         m_bIgnorerelevant)) {
+                         m_bIgnoreRelevant)) {
       m_iCurWidget = i;
       return m_TabOrderWidgetArray[m_iCurWidget].Get();
     }
@@ -274,7 +276,7 @@
   for (int32_t i = m_iCurWidget + 1;
        i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
     if (PageWidgetFilter(m_TabOrderWidgetArray[i].Get(), m_dwFilter, true,
-                         m_bIgnorerelevant)) {
+                         m_bIgnoreRelevant)) {
       m_iCurWidget = i;
       return m_TabOrderWidgetArray[m_iCurWidget].Get();
     }
@@ -286,7 +288,7 @@
 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() {
   for (int32_t i = m_iCurWidget - 1; i >= 0; i--) {
     if (PageWidgetFilter(m_TabOrderWidgetArray[i].Get(), m_dwFilter, true,
-                         m_bIgnorerelevant)) {
+                         m_bIgnoreRelevant)) {
       m_iCurWidget = i;
       return m_TabOrderWidgetArray[m_iCurWidget].Get();
     }
@@ -435,7 +437,7 @@
 
 void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray(
     std::vector<CXFA_FFWidget*>* WidgetArray) {
-  CXFA_LayoutItemIterator sIterator(m_pPageView.Get());
+  CXFA_LayoutItemIterator sIterator(m_pPageView->GetLayoutItem());
   auto pParam = pdfium::MakeUnique<CXFA_TabParam>(nullptr);
   bool bCurrentItem = false;
   bool bContentArea = false;
diff --git a/xfa/fxfa/cxfa_ffpageview.h b/xfa/fxfa/cxfa_ffpageview.h
index f6fda19..804c93d 100644
--- a/xfa/fxfa/cxfa_ffpageview.h
+++ b/xfa/fxfa/cxfa_ffpageview.h
@@ -17,10 +17,13 @@
 class CXFA_FFWidget;
 class CXFA_FFDocView;
 
-class CXFA_FFPageView final : public CXFA_ViewLayoutItem {
+class CXFA_FFPageView {
  public:
   CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea);
-  ~CXFA_FFPageView() override;
+  ~CXFA_FFPageView();
+
+  CXFA_ViewLayoutItem* GetLayoutItem() const { return m_pLayoutItem.Get(); }
+  void SetLayoutItem(CXFA_ViewLayoutItem* pItem) { m_pLayoutItem = pItem; }
 
   CXFA_FFDocView* GetDocView() const;
   CFX_RectF GetPageViewRect() const;
@@ -30,7 +33,9 @@
       uint32_t dwWidgetFilter);
 
  private:
+  UnownedPtr<CXFA_Node> const m_pPageArea;
   UnownedPtr<CXFA_FFDocView> const m_pDocView;
+  UnownedPtr<CXFA_ViewLayoutItem> m_pLayoutItem;
 };
 
 class CXFA_FFPageWidgetIterator final : public IXFA_WidgetIterator {
@@ -52,7 +57,7 @@
   UnownedPtr<CXFA_FFPageView> m_pPageView;
   UnownedPtr<CXFA_FFWidget> m_hCurWidget;
   uint32_t m_dwFilter;
-  bool m_bIgnorerelevant;
+  bool m_bIgnoreRelevant;
   CXFA_LayoutItemIterator m_sIterator;
 };
 
@@ -103,7 +108,7 @@
   UnownedPtr<CXFA_FFPageView> m_pPageView;
   uint32_t m_dwFilter;
   int32_t m_iCurWidget;
-  bool m_bIgnorerelevant;
+  bool m_bIgnoreRelevant;
 };
 
 #endif  // XFA_FXFA_CXFA_FFPAGEVIEW_H_
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
index 81f9db0..917e748 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
@@ -13,6 +13,7 @@
 #include "third_party/base/ptr_util.h"
 #include "third_party/base/stl_util.h"
 #include "xfa/fxfa/cxfa_ffnotify.h"
+#include "xfa/fxfa/cxfa_ffpageview.h"
 #include "xfa/fxfa/layout/cxfa_contentlayoutitem.h"
 #include "xfa/fxfa/layout/cxfa_itemlayoutprocessor.h"
 #include "xfa/fxfa/layout/cxfa_layoutprocessor.h"
@@ -393,7 +394,8 @@
     m_pPageSetLayoutItemRoot->SetNextSibling(nullptr);
     m_pPageSetLayoutItemRoot->SetFormNode(m_pTemplatePageSetRoot);
   } else {
-    m_pPageSetLayoutItemRoot = new CXFA_ViewLayoutItem(m_pTemplatePageSetRoot);
+    m_pPageSetLayoutItemRoot =
+        new CXFA_ViewLayoutItem(m_pTemplatePageSetRoot, nullptr);
   }
   m_pPageSetCurRoot = m_pPageSetLayoutItemRoot;
   m_pTemplatePageSetRoot->JSObject()->SetLayoutItem(m_pPageSetLayoutItemRoot);
@@ -604,7 +606,7 @@
       pNewRecord->pCurPageSet = m_pPageSetLayoutItemRoot;
     } else {
       CXFA_ViewLayoutItem* pPageSetLayoutItem =
-          new CXFA_ViewLayoutItem(pPageSet);
+          new CXFA_ViewLayoutItem(pPageSet, nullptr);
       pPageSet->JSObject()->SetLayoutItem(pPageSetLayoutItem);
       m_pPageSetLayoutItemRoot->AddChild(pPageSetLayoutItem);
       pNewRecord->pCurPageSet = pPageSetLayoutItem;
@@ -640,7 +642,7 @@
     pParentPageSetLayout =
         ToViewLayoutItem(pPageSet->GetParent()->JSObject()->GetLayoutItem());
   }
-  auto* pPageSetLayoutItem = new CXFA_ViewLayoutItem(pPageSet);
+  auto* pPageSetLayoutItem = new CXFA_ViewLayoutItem(pPageSet, nullptr);
   pPageSet->JSObject()->SetLayoutItem(pPageSetLayoutItem);
   if (!pParentPageSetLayout) {
     CXFA_ViewLayoutItem* pPrePageSet = m_pPageSetLayoutItemRoot;
@@ -675,7 +677,10 @@
     pNewPageAreaLayoutItem = pViewItem;
   } else {
     CXFA_FFNotify* pNotify = pNewPageArea->GetDocument()->GetNotify();
-    auto* pViewItem = pNotify->OnCreateViewLayoutItem(pNewPageArea).release();
+    auto* pViewItem =
+        pdfium::MakeUnique<CXFA_ViewLayoutItem>(
+            pNewPageArea, pNotify->OnCreateViewLayoutItem(pNewPageArea))
+            .release();
     m_PageArray.push_back(pViewItem);
     m_nAvailPages++;
     pNotify->OnPageEvent(pViewItem, XFA_PAGEVIEWEVENT_PostRemoved);
@@ -692,11 +697,11 @@
     pNewRecord->pCurContentArea = nullptr;
     return;
   }
-  CXFA_ViewLayoutItem* pNewContentAreaLayoutItem =
-      new CXFA_ViewLayoutItem(pContentArea);
+  CXFA_ViewLayoutItem* pNewViewLayoutItem =
+      new CXFA_ViewLayoutItem(pContentArea, nullptr);
   ASSERT(pNewRecord->pCurPageArea);
-  pNewRecord->pCurPageArea->AddChild(pNewContentAreaLayoutItem);
-  pNewRecord->pCurContentArea = pNewContentAreaLayoutItem;
+  pNewRecord->pCurPageArea->AddChild(pNewViewLayoutItem);
+  pNewRecord->pCurContentArea = pNewViewLayoutItem;
 }
 
 void CXFA_LayoutPageMgr::FinishPaginatedPageSets() {
diff --git a/xfa/fxfa/layout/cxfa_viewlayoutitem.cpp b/xfa/fxfa/layout/cxfa_viewlayoutitem.cpp
index 36650fd..5513b19 100644
--- a/xfa/fxfa/layout/cxfa_viewlayoutitem.cpp
+++ b/xfa/fxfa/layout/cxfa_viewlayoutitem.cpp
@@ -6,15 +6,23 @@
 
 #include "xfa/fxfa/layout/cxfa_viewlayoutitem.h"
 
+#include <utility>
+
 #include "fxjs/xfa/cjx_object.h"
+#include "xfa/fxfa/cxfa_ffpageview.h"
 #include "xfa/fxfa/layout/cxfa_layoutpagemgr.h"
 #include "xfa/fxfa/layout/cxfa_layoutprocessor.h"
 #include "xfa/fxfa/parser/cxfa_measurement.h"
 #include "xfa/fxfa/parser/cxfa_medium.h"
 #include "xfa/fxfa/parser/cxfa_node.h"
 
-CXFA_ViewLayoutItem::CXFA_ViewLayoutItem(CXFA_Node* pNode)
-    : CXFA_LayoutItem(pNode, kViewItem) {}
+CXFA_ViewLayoutItem::CXFA_ViewLayoutItem(
+    CXFA_Node* pNode,
+    std::unique_ptr<CXFA_FFPageView> pPageView)
+    : CXFA_LayoutItem(pNode, kViewItem), m_pFFPageView(std::move(pPageView)) {
+  if (m_pFFPageView)
+    m_pFFPageView->SetLayoutItem(this);
+}
 
 CXFA_ViewLayoutItem::~CXFA_ViewLayoutItem() = default;
 
diff --git a/xfa/fxfa/layout/cxfa_viewlayoutitem.h b/xfa/fxfa/layout/cxfa_viewlayoutitem.h
index 6658946..1ced481 100644
--- a/xfa/fxfa/layout/cxfa_viewlayoutitem.h
+++ b/xfa/fxfa/layout/cxfa_viewlayoutitem.h
@@ -7,19 +7,28 @@
 #ifndef XFA_FXFA_LAYOUT_CXFA_VIEWLAYOUTITEM_H_
 #define XFA_FXFA_LAYOUT_CXFA_VIEWLAYOUTITEM_H_
 
+#include <memory>
+
 #include "xfa/fxfa/layout/cxfa_layoutitem.h"
 
+class CXFA_FFPageView;
+
 class CXFA_ViewLayoutItem : public CXFA_LayoutItem {
  public:
-  explicit CXFA_ViewLayoutItem(CXFA_Node* pNode);
+  CXFA_ViewLayoutItem(CXFA_Node* pNode,
+                      std::unique_ptr<CXFA_FFPageView> pPageView);
   ~CXFA_ViewLayoutItem() override;
 
+  CXFA_FFPageView* GetPageView() const { return m_pFFPageView.get(); }
   CXFA_LayoutProcessor* GetLayout() const;
   int32_t GetPageIndex() const;
   CFX_SizeF GetPageSize() const;
   CXFA_Node* GetMasterPage() const;
 
   UnownedPtr<CXFA_Node> m_pOldSubform;
+
+ private:
+  std::unique_ptr<CXFA_FFPageView> const m_pFFPageView;
 };
 
 #endif  // XFA_FXFA_LAYOUT_CXFA_VIEWLAYOUTITEM_H_