Remove some more xfa/fwl circular includes into xfa/fxfa

Both CFWL_App and CFWL_WidgetMgr need to declare a virtual interface
for the higher levels to implement to prevent direct calls.

Change-Id: Ifbf8c8467ce7a5b9716048d64d1539db0a8f817d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55110
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/cfwl_app.cpp b/xfa/fwl/cfwl_app.cpp
index 666a91d..c3a06e3 100644
--- a/xfa/fwl/cfwl_app.cpp
+++ b/xfa/fwl/cfwl_app.cpp
@@ -10,11 +10,11 @@
 #include "xfa/fwl/cfwl_notedriver.h"
 #include "xfa/fwl/cfwl_widget.h"
 #include "xfa/fwl/cfwl_widgetmgr.h"
-#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h"
 
-CFWL_App::CFWL_App(CXFA_FFApp* pAdapter)
+CFWL_App::CFWL_App(AdapterIface* pAdapter)
     : m_pAdapterNative(pAdapter),
-      m_pWidgetMgr(pdfium::MakeUnique<CFWL_WidgetMgr>(pAdapter)),
+      m_pWidgetMgr(
+          pdfium::MakeUnique<CFWL_WidgetMgr>(pAdapter->GetWidgetMgrAdapter())),
       m_pNoteDriver(pdfium::MakeUnique<CFWL_NoteDriver>()) {
   ASSERT(m_pAdapterNative);
 }
diff --git a/xfa/fwl/cfwl_app.h b/xfa/fwl/cfwl_app.h
index ed47149..3bac5bd 100644
--- a/xfa/fwl/cfwl_app.h
+++ b/xfa/fwl/cfwl_app.h
@@ -10,12 +10,12 @@
 #include <memory>
 
 #include "core/fxcrt/fx_string.h"
+#include "xfa/fwl/cfwl_widgetmgr.h"
 
 class CFWL_NoteDriver;
 class CFWL_WidgetMgr;
-class CXFA_FFApp;
-class CXFA_FWLAdapterWidgetMgr;
 class CFWL_Widget;
+class IFWL_AdapterTimerMgr;
 
 enum FWL_KeyFlag {
   FWL_KEYFLAG_Ctrl = 1 << 0,
@@ -29,15 +29,22 @@
 
 class CFWL_App {
  public:
-  explicit CFWL_App(CXFA_FFApp* pAdapter);
+  class AdapterIface {
+   public:
+    virtual ~AdapterIface() {}
+    virtual CFWL_WidgetMgr::AdapterIface* GetWidgetMgrAdapter() = 0;
+    virtual std::unique_ptr<IFWL_AdapterTimerMgr> NewTimerMgr() = 0;
+  };
+
+  explicit CFWL_App(AdapterIface* pAdapter);
   ~CFWL_App();
 
-  CXFA_FFApp* GetAdapterNative() const { return m_pAdapterNative.Get(); }
+  AdapterIface* GetAdapterNative() const { return m_pAdapterNative.Get(); }
   CFWL_WidgetMgr* GetWidgetMgr() const { return m_pWidgetMgr.get(); }
   CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); }
 
  private:
-  UnownedPtr<CXFA_FFApp> const m_pAdapterNative;
+  UnownedPtr<AdapterIface> const m_pAdapterNative;
   std::unique_ptr<CFWL_WidgetMgr> m_pWidgetMgr;
   std::unique_ptr<CFWL_NoteDriver> m_pNoteDriver;
 };
diff --git a/xfa/fwl/cfwl_timer.cpp b/xfa/fwl/cfwl_timer.cpp
index c332555..8e82834 100644
--- a/xfa/fwl/cfwl_timer.cpp
+++ b/xfa/fwl/cfwl_timer.cpp
@@ -10,14 +10,14 @@
 #include "xfa/fwl/cfwl_timerinfo.h"
 #include "xfa/fwl/cfwl_widget.h"
 #include "xfa/fwl/ifwl_adaptertimermgr.h"
-#include "xfa/fxfa/cxfa_ffapp.h"
 
 CFWL_Timer::CFWL_Timer(CFWL_Widget* parent) : m_pWidget(parent) {}
 
 CFWL_Timer::~CFWL_Timer() {}
 
 CFWL_TimerInfo* CFWL_Timer::StartTimer(uint32_t dwElapse, bool bImmediately) {
-  CXFA_FFApp* pAdapterNative = m_pWidget->GetOwnerApp()->GetAdapterNative();
+  CFWL_App::AdapterIface* pAdapterNative =
+      m_pWidget->GetOwnerApp()->GetAdapterNative();
   if (!pAdapterNative)
     return nullptr;
 
diff --git a/xfa/fwl/cfwl_widget.cpp b/xfa/fwl/cfwl_widget.cpp
index 0150bbb..a6ab965 100644
--- a/xfa/fwl/cfwl_widget.cpp
+++ b/xfa/fwl/cfwl_widget.cpp
@@ -27,7 +27,6 @@
 #include "xfa/fwl/cfwl_themetext.h"
 #include "xfa/fwl/cfwl_widgetmgr.h"
 #include "xfa/fwl/ifwl_themeprovider.h"
-#include "xfa/fxfa/cxfa_ffapp.h"
 
 #define FWL_WGT_CalcHeight 2048
 #define FWL_WGT_CalcWidth 2048
diff --git a/xfa/fwl/cfwl_widgetmgr.cpp b/xfa/fwl/cfwl_widgetmgr.cpp
index 3531bf2..a95386f 100644
--- a/xfa/fwl/cfwl_widgetmgr.cpp
+++ b/xfa/fwl/cfwl_widgetmgr.cpp
@@ -12,11 +12,9 @@
 #include "third_party/base/ptr_util.h"
 #include "xfa/fwl/cfwl_app.h"
 #include "xfa/fwl/cfwl_notedriver.h"
-#include "xfa/fxfa/cxfa_ffapp.h"
-#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h"
 
-CFWL_WidgetMgr::CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative)
-    : m_pAdapter(pAdapterNative->GetFWLAdapterWidgetMgr()) {
+CFWL_WidgetMgr::CFWL_WidgetMgr(AdapterIface* pAdapterNative)
+    : m_pAdapter(pAdapterNative) {
   m_mapWidgetItem[nullptr] = pdfium::MakeUnique<Item>();
 }
 
diff --git a/xfa/fwl/cfwl_widgetmgr.h b/xfa/fwl/cfwl_widgetmgr.h
index 796b37e..cb2b1ca 100644
--- a/xfa/fwl/cfwl_widgetmgr.h
+++ b/xfa/fwl/cfwl_widgetmgr.h
@@ -15,15 +15,24 @@
 #include "xfa/fxgraphics/cxfa_graphics.h"
 
 class CFWL_Message;
-class CXFA_FFApp;
-class CXFA_FWLAdapterWidgetMgr;
 class CXFA_Graphics;
 class CFX_Matrix;
 class CFWL_Widget;
 
 class CFWL_WidgetMgr {
  public:
-  explicit CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative);
+  class AdapterIface {
+   public:
+    virtual ~AdapterIface() {}
+    virtual void RepaintWidget(CFWL_Widget* pWidget) = 0;
+    virtual bool GetPopupPos(CFWL_Widget* pWidget,
+                             float fMinHeight,
+                             float fMaxHeight,
+                             const CFX_RectF& rtAnchor,
+                             CFX_RectF* pPopupRect) = 0;
+  };
+
+  explicit CFWL_WidgetMgr(AdapterIface* pAdapterNative);
   ~CFWL_WidgetMgr();
 
   void OnProcessMessageToForm(CFWL_Message* pMessage);
@@ -89,7 +98,7 @@
   bool IsAbleNative(CFWL_Widget* pWidget) const;
 
   std::map<const CFWL_Widget*, std::unique_ptr<Item>> m_mapWidgetItem;
-  UnownedPtr<CXFA_FWLAdapterWidgetMgr> const m_pAdapter;
+  UnownedPtr<AdapterIface> const m_pAdapter;
 };
 
 #endif  // XFA_FWL_CFWL_WIDGETMGR_H_
diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp
index 7b849f3..a70de91 100644
--- a/xfa/fxfa/cxfa_ffapp.cpp
+++ b/xfa/fxfa/cxfa_ffapp.cpp
@@ -60,13 +60,13 @@
   return m_pFWLTheme.get();
 }
 
-CXFA_FWLAdapterWidgetMgr* CXFA_FFApp::GetFWLAdapterWidgetMgr() {
+CFWL_WidgetMgr::AdapterIface* CXFA_FFApp::GetWidgetMgrAdapter() {
   if (!m_pAdapterWidgetMgr)
     m_pAdapterWidgetMgr = pdfium::MakeUnique<CXFA_FWLAdapterWidgetMgr>();
   return m_pAdapterWidgetMgr.get();
 }
 
-std::unique_ptr<IFWL_AdapterTimerMgr> CXFA_FFApp::NewTimerMgr() const {
+std::unique_ptr<IFWL_AdapterTimerMgr> CXFA_FFApp::NewTimerMgr() {
   return m_pProvider->NewTimerMgr();
 }
 
diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h
index 724c571..3bf0a93 100644
--- a/xfa/fxfa/cxfa_ffapp.h
+++ b/xfa/fxfa/cxfa_ffapp.h
@@ -20,23 +20,24 @@
 class CXFA_FWLTheme;
 class IFWL_AdapterTimerMgr;
 
-class CXFA_FFApp {
+class CXFA_FFApp : public CFWL_App::AdapterIface {
  public:
   static void SkipFontLoadForTesting(bool skip);
 
   explicit CXFA_FFApp(IXFA_AppProvider* pProvider);
-  ~CXFA_FFApp();
+  ~CXFA_FFApp() override;
 
-  CXFA_FWLAdapterWidgetMgr* GetFWLAdapterWidgetMgr();
+  // CFWL_App::AdapterIface:
+  CFWL_WidgetMgr::AdapterIface* GetWidgetMgrAdapter() override;
+  std::unique_ptr<IFWL_AdapterTimerMgr> NewTimerMgr() override;
+
   CFWL_WidgetMgr* GetFWLWidgetMgr() const { return m_pFWLApp->GetWidgetMgr(); }
-
   CFGAS_FontMgr* GetFDEFontMgr();
   CXFA_FWLTheme* GetFWLTheme(CXFA_FFDoc* doc);
 
   IXFA_AppProvider* GetAppProvider() const { return m_pProvider.Get(); }
   const CFWL_App* GetFWLApp() const { return m_pFWLApp.get(); }
   CXFA_FontMgr* GetXFAFontMgr() { return &m_pFontMgr; }
-  std::unique_ptr<IFWL_AdapterTimerMgr> NewTimerMgr() const;
 
   void ClearEventTargets();
 
diff --git a/xfa/fxfa/cxfa_fwladapterwidgetmgr.h b/xfa/fxfa/cxfa_fwladapterwidgetmgr.h
index f0cc373..4a50c28 100644
--- a/xfa/fxfa/cxfa_fwladapterwidgetmgr.h
+++ b/xfa/fxfa/cxfa_fwladapterwidgetmgr.h
@@ -9,20 +9,21 @@
 
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_system.h"
+#include "xfa/fwl/cfwl_widgetmgr.h"
 
 class CFWL_Widget;
 
-class CXFA_FWLAdapterWidgetMgr {
+class CXFA_FWLAdapterWidgetMgr : public CFWL_WidgetMgr::AdapterIface {
  public:
   CXFA_FWLAdapterWidgetMgr();
-  ~CXFA_FWLAdapterWidgetMgr();
+  ~CXFA_FWLAdapterWidgetMgr() override;
 
-  void RepaintWidget(CFWL_Widget* pWidget);
+  void RepaintWidget(CFWL_Widget* pWidget) override;
   bool GetPopupPos(CFWL_Widget* pWidget,
                    float fMinHeight,
                    float fMaxHeight,
                    const CFX_RectF& rtAnchor,
-                   CFX_RectF* pPopupRect);
+                   CFX_RectF* pPopupRect) override;
 };
 
 #endif  // XFA_FXFA_CXFA_FWLADAPTERWIDGETMGR_H_