Merge IFWL_App and FWL_AppImp together

The IFWL_App class just acts as a proxy to the FWL_AppImp code. This Cl removes
FWL_AppImp and merges the code back up to IFWL_App, simplifying the
object hierarchy.

Review-Url: https://codereview.chromium.org/2430563003
diff --git a/BUILD.gn b/BUILD.gn
index 952575e..aa467d5 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1204,8 +1204,6 @@
       "xfa/fwl/core/cfwl_widgetimpproperties.h",
       "xfa/fwl/core/cfwl_widgetmgr.cpp",
       "xfa/fwl/core/cfwl_widgetmgr.h",
-      "xfa/fwl/core/fwl_appimp.cpp",
-      "xfa/fwl/core/fwl_appimp.h",
       "xfa/fwl/core/fwl_error.h",
       "xfa/fwl/core/fwl_formimp.cpp",
       "xfa/fwl/core/fwl_formimp.h",
@@ -1217,6 +1215,7 @@
       "xfa/fwl/core/fwl_widgetimp.cpp",
       "xfa/fwl/core/fwl_widgetimp.h",
       "xfa/fwl/core/ifwl_adaptertimermgr.h",
+      "xfa/fwl/core/ifwl_app.cpp",
       "xfa/fwl/core/ifwl_app.h",
       "xfa/fwl/core/ifwl_dataprovider.h",
       "xfa/fwl/core/ifwl_form.h",
diff --git a/xfa/fwl/basewidget/fwl_comboboximp.cpp b/xfa/fwl/basewidget/fwl_comboboximp.cpp
index 17c5bf8..e586055 100644
--- a/xfa/fwl/basewidget/fwl_comboboximp.cpp
+++ b/xfa/fwl/basewidget/fwl_comboboximp.cpp
@@ -17,7 +17,6 @@
 #include "xfa/fwl/core/cfwl_themepart.h"
 #include "xfa/fwl/core/cfwl_themetext.h"
 #include "xfa/fwl/core/cfwl_widgetmgr.h"
-#include "xfa/fwl/core/fwl_appimp.h"
 #include "xfa/fwl/core/fwl_formimp.h"
 #include "xfa/fwl/core/fwl_noteimp.h"
 #include "xfa/fwl/core/fwl_widgetimp.h"
diff --git a/xfa/fwl/basewidget/fwl_editimp.cpp b/xfa/fwl/basewidget/fwl_editimp.cpp
index 8377daf..0f939f1 100644
--- a/xfa/fwl/basewidget/fwl_editimp.cpp
+++ b/xfa/fwl/basewidget/fwl_editimp.cpp
@@ -24,7 +24,6 @@
 #include "xfa/fwl/core/cfwl_themebackground.h"
 #include "xfa/fwl/core/cfwl_themepart.h"
 #include "xfa/fwl/core/cfwl_widgetmgr.h"
-#include "xfa/fwl/core/fwl_appimp.h"
 #include "xfa/fwl/core/fwl_widgetimp.h"
 #include "xfa/fwl/core/ifwl_app.h"
 #include "xfa/fwl/core/ifwl_themeprovider.h"
diff --git a/xfa/fwl/core/cfwl_widgetmgr.cpp b/xfa/fwl/core/cfwl_widgetmgr.cpp
index db10350..30571c9 100644
--- a/xfa/fwl/core/cfwl_widgetmgr.cpp
+++ b/xfa/fwl/core/cfwl_widgetmgr.cpp
@@ -7,7 +7,6 @@
 #include "xfa/fwl/core/cfwl_widgetmgr.h"
 
 #include "xfa/fwl/core/cfwl_message.h"
-#include "xfa/fwl/core/fwl_appimp.h"
 #include "xfa/fwl/core/fwl_noteimp.h"
 #include "xfa/fwl/core/fwl_widgetimp.h"
 #include "xfa/fwl/core/ifwl_app.h"
diff --git a/xfa/fwl/core/fwl_appimp.cpp b/xfa/fwl/core/fwl_appimp.cpp
deleted file mode 100644
index 2df579c..0000000
--- a/xfa/fwl/core/fwl_appimp.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fwl/core/fwl_appimp.h"
-
-#include "xfa/fwl/core/cfwl_widgetmgr.h"
-#include "xfa/fwl/core/fwl_noteimp.h"
-#include "xfa/fwl/core/ifwl_app.h"
-#include "xfa/fwl/core/ifwl_widget.h"
-#include "xfa/fxfa/app/xfa_fwladapter.h"
-
-IFWL_App* IFWL_App::Create(CXFA_FFApp* pAdapter) {
-  IFWL_App* pApp = new IFWL_App;
-  pApp->SetImpl(new CFWL_AppImp(pApp, pAdapter));
-  return pApp;
-}
-
-IFWL_App::IFWL_App() {}
-
-IFWL_App::~IFWL_App() {}
-
-void IFWL_App::Release() {}
-
-FWL_Error IFWL_App::Initialize() {
-  return static_cast<CFWL_AppImp*>(GetImpl())->Initialize();
-}
-
-FWL_Error IFWL_App::Finalize() {
-  return static_cast<CFWL_AppImp*>(GetImpl())->Finalize();
-}
-
-CXFA_FFApp* IFWL_App::GetAdapterNative() {
-  return static_cast<CFWL_AppImp*>(GetImpl())->GetAdapterNative();
-}
-
-CFWL_WidgetMgr* IFWL_App::GetWidgetMgr() {
-  return static_cast<CFWL_AppImp*>(GetImpl())->GetWidgetMgr();
-}
-
-IFWL_ThemeProvider* IFWL_App::GetThemeProvider() {
-  return static_cast<CFWL_AppImp*>(GetImpl())->GetThemeProvider();
-}
-
-void IFWL_App::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
-  static_cast<CFWL_AppImp*>(GetImpl())->SetThemeProvider(pThemeProvider);
-}
-
-void IFWL_App::Exit(int32_t iExitCode) {
-  static_cast<CFWL_AppImp*>(GetImpl())->Exit(iExitCode);
-}
-
-CFWL_NoteDriver* IFWL_App::GetNoteDriver() const {
-  return static_cast<CFWL_AppImp*>(GetImpl())->GetNoteDriver();
-}
-
-CFWL_AppImp::CFWL_AppImp(IFWL_App* pIface, CXFA_FFApp* pAdapter)
-    : m_pAdapterNative(pAdapter),
-      m_pThemeProvider(nullptr),
-      m_pNoteDriver(new CFWL_NoteDriver),
-      m_pIface(pIface) {}
-
-CFWL_AppImp::~CFWL_AppImp() {
-  CFWL_ToolTipContainer::DeleteInstance();
-}
-
-FWL_Error CFWL_AppImp::Initialize() {
-  if (!m_pWidgetMgr) {
-    m_pWidgetMgr.reset(new CFWL_WidgetMgr(m_pAdapterNative));
-  }
-  return FWL_Error::Succeeded;
-}
-FWL_Error CFWL_AppImp::Finalize() {
-  m_pWidgetMgr.reset();
-  return FWL_Error::Succeeded;
-}
-CXFA_FFApp* CFWL_AppImp::GetAdapterNative() const {
-  return m_pAdapterNative;
-}
-CXFA_FWLAdapterWidgetMgr* FWL_GetAdapterWidgetMgr() {
-  return CFWL_WidgetMgr::GetInstance()->GetAdapterWidgetMgr();
-}
-CFWL_WidgetMgr* CFWL_AppImp::GetWidgetMgr() const {
-  return m_pWidgetMgr.get();
-}
-
-void CFWL_AppImp::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
-  m_pThemeProvider = pThemeProvider;
-}
-
-void CFWL_AppImp::Exit(int32_t iExitCode) {
-  while (m_pNoteDriver->PopNoteLoop()) {
-    continue;
-  }
-}
-
-IFWL_ThemeProvider* CFWL_AppImp::GetThemeProvider() const {
-  return m_pThemeProvider;
-}
-
-CXFA_FFApp* FWL_GetAdapterNative() {
-  IFWL_App* pApp = FWL_GetApp();
-  if (!pApp)
-    return nullptr;
-  return pApp->GetAdapterNative();
-}
-
-static IFWL_App* g_theApp = nullptr;
-IFWL_App* FWL_GetApp() {
-  return g_theApp;
-}
-
-void FWL_SetApp(IFWL_App* pApp) {
-  g_theApp = pApp;
-}
diff --git a/xfa/fwl/core/fwl_appimp.h b/xfa/fwl/core/fwl_appimp.h
deleted file mode 100644
index f337704..0000000
--- a/xfa/fwl/core/fwl_appimp.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FWL_CORE_FWL_APPIMP_H_
-#define XFA_FWL_CORE_FWL_APPIMP_H_
-
-#include <memory>
-
-#include "xfa/fwl/core/fwl_noteimp.h"
-
-class CFWL_WidgetMgr;
-class CXFA_FFApp;
-class IFWL_App;
-class IFWL_NoteThread;
-class IFWL_ThemeProvider;
-
-class CFWL_AppImp {
- public:
-  CFWL_AppImp(IFWL_App* pIface, CXFA_FFApp* pAdapter);
-  ~CFWL_AppImp();
-
-  IFWL_App* GetInterface() const { return m_pIface; }
-  CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); }
-
-  FWL_Error Initialize();
-  FWL_Error Finalize();
-  CXFA_FFApp* GetAdapterNative() const;
-  CFWL_WidgetMgr* GetWidgetMgr() const;
-  IFWL_ThemeProvider* GetThemeProvider() const;
-  void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider);
-  void Exit(int32_t iExitCode);
-
- private:
-  CXFA_FFApp* const m_pAdapterNative;
-  std::unique_ptr<CFWL_WidgetMgr> m_pWidgetMgr;
-  IFWL_ThemeProvider* m_pThemeProvider;
-  std::unique_ptr<CFWL_NoteDriver> m_pNoteDriver;
-  IFWL_App* const m_pIface;
-};
-
-#endif  // XFA_FWL_CORE_FWL_APPIMP_H_
diff --git a/xfa/fwl/core/fwl_formimp.cpp b/xfa/fwl/core/fwl_formimp.cpp
index 4dcedf6..747e5e8 100644
--- a/xfa/fwl/core/fwl_formimp.cpp
+++ b/xfa/fwl/core/fwl_formimp.cpp
@@ -13,7 +13,6 @@
 #include "xfa/fwl/core/cfwl_themepart.h"
 #include "xfa/fwl/core/cfwl_themetext.h"
 #include "xfa/fwl/core/cfwl_widgetmgr.h"
-#include "xfa/fwl/core/fwl_appimp.h"
 #include "xfa/fwl/core/fwl_noteimp.h"
 #include "xfa/fwl/core/fwl_widgetimp.h"
 #include "xfa/fwl/core/ifwl_app.h"
diff --git a/xfa/fwl/core/fwl_noteimp.cpp b/xfa/fwl/core/fwl_noteimp.cpp
index 3173f3e..848cb77 100644
--- a/xfa/fwl/core/fwl_noteimp.cpp
+++ b/xfa/fwl/core/fwl_noteimp.cpp
@@ -12,7 +12,6 @@
 #include "xfa/fwl/basewidget/ifwl_tooltip.h"
 #include "xfa/fwl/core/cfwl_message.h"
 #include "xfa/fwl/core/cfwl_widgetmgr.h"
-#include "xfa/fwl/core/fwl_appimp.h"
 #include "xfa/fwl/core/fwl_formimp.h"
 #include "xfa/fwl/core/fwl_widgetimp.h"
 #include "xfa/fwl/core/ifwl_app.h"
diff --git a/xfa/fwl/core/fwl_timerimp.cpp b/xfa/fwl/core/fwl_timerimp.cpp
index a464693..941113e 100644
--- a/xfa/fwl/core/fwl_timerimp.cpp
+++ b/xfa/fwl/core/fwl_timerimp.cpp
@@ -4,7 +4,6 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "xfa/fwl/core/fwl_appimp.h"
 #include "xfa/fwl/core/ifwl_adaptertimermgr.h"
 #include "xfa/fwl/core/ifwl_app.h"
 #include "xfa/fwl/core/ifwl_timer.h"
diff --git a/xfa/fwl/core/fwl_widgetimp.cpp b/xfa/fwl/core/fwl_widgetimp.cpp
index 6e8ec09..b59fd27 100644
--- a/xfa/fwl/core/fwl_widgetimp.cpp
+++ b/xfa/fwl/core/fwl_widgetimp.cpp
@@ -15,7 +15,6 @@
 #include "xfa/fwl/core/cfwl_themepart.h"
 #include "xfa/fwl/core/cfwl_themetext.h"
 #include "xfa/fwl/core/cfwl_widgetmgr.h"
-#include "xfa/fwl/core/fwl_appimp.h"
 #include "xfa/fwl/core/fwl_noteimp.h"
 #include "xfa/fwl/core/ifwl_app.h"
 #include "xfa/fwl/core/ifwl_form.h"
@@ -179,7 +178,7 @@
   if (!pAdapter)
     return FWL_Error::Indefinite;
 
-  SetOwnerApp(static_cast<CFWL_AppImp*>(FWL_GetApp()->GetImpl()));
+  SetOwnerApp(FWL_GetApp());
 
   IFWL_Widget* pParent = m_pProperties->m_pParent;
   m_pWidgetMgr->InsertWidget(pParent, m_pInterface);
@@ -492,9 +491,9 @@
   return pOldDelegate;
 }
 IFWL_App* CFWL_WidgetImp::GetOwnerApp() const {
-  return static_cast<IFWL_App*>(m_pOwnerApp->GetInterface());
+  return m_pOwnerApp;
 }
-FWL_Error CFWL_WidgetImp::SetOwnerApp(CFWL_AppImp* pOwnerApp) {
+FWL_Error CFWL_WidgetImp::SetOwnerApp(IFWL_App* pOwnerApp) {
   m_pOwnerApp = pOwnerApp;
   return FWL_Error::Succeeded;
 }
@@ -642,7 +641,7 @@
         return pRet;
     }
   } while (pUp);
-  return FWL_GetApp()->GetThemeProvider();
+  return nullptr;
 }
 CFWL_WidgetImp* CFWL_WidgetImp::GetRootOuter() {
   IFWL_Widget* pRet = m_pOuter;
diff --git a/xfa/fwl/core/fwl_widgetimp.h b/xfa/fwl/core/fwl_widgetimp.h
index 57970a8..dfbfc5b 100644
--- a/xfa/fwl/core/fwl_widgetimp.h
+++ b/xfa/fwl/core/fwl_widgetimp.h
@@ -72,7 +72,7 @@
   virtual IFWL_WidgetDelegate* SetDelegate(IFWL_WidgetDelegate* pDelegate);
   virtual IFWL_App* GetOwnerApp() const;
 
-  FWL_Error SetOwnerApp(CFWL_AppImp* pOwnerApp);
+  FWL_Error SetOwnerApp(IFWL_App* pOwnerApp);
   IFWL_Widget* GetInterface() const;
   void SetInterface(IFWL_Widget* pInterface);
   CFX_SizeF GetOffsetFromParent(IFWL_Widget* pParent);
@@ -157,7 +157,7 @@
   FX_BOOL IsParent(IFWL_Widget* pParent);
 
   CFWL_WidgetMgr* const m_pWidgetMgr;
-  CFWL_AppImp* m_pOwnerApp;
+  IFWL_App* m_pOwnerApp;
   std::unique_ptr<CFWL_WidgetImpProperties> m_pProperties;
   IFWL_WidgetDelegate* m_pDelegate;
   IFWL_WidgetDelegate* m_pCurDelegate;
diff --git a/xfa/fwl/core/ifwl_app.cpp b/xfa/fwl/core/ifwl_app.cpp
new file mode 100644
index 0000000..a47a76e
--- /dev/null
+++ b/xfa/fwl/core/ifwl_app.cpp
@@ -0,0 +1,50 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fwl/core/ifwl_app.h"
+
+#include "third_party/base/ptr_util.h"
+#include "xfa/fwl/core/cfwl_widgetmgr.h"
+#include "xfa/fwl/core/fwl_noteimp.h"
+#include "xfa/fwl/core/ifwl_widget.h"
+#include "xfa/fxfa/app/xfa_fwladapter.h"
+
+CXFA_FWLAdapterWidgetMgr* FWL_GetAdapterWidgetMgr() {
+  return CFWL_WidgetMgr::GetInstance()->GetAdapterWidgetMgr();
+}
+
+CXFA_FFApp* FWL_GetAdapterNative() {
+  IFWL_App* pApp = FWL_GetApp();
+  if (!pApp)
+    return nullptr;
+  return pApp->GetAdapterNative();
+}
+
+static IFWL_App* g_theApp = nullptr;
+IFWL_App* FWL_GetApp() {
+  return g_theApp;
+}
+
+void FWL_SetApp(IFWL_App* pApp) {
+  g_theApp = pApp;
+}
+
+IFWL_App::IFWL_App(CXFA_FFApp* pAdapter)
+    : m_pAdapterNative(pAdapter),
+      m_pWidgetMgr(pdfium::MakeUnique<CFWL_WidgetMgr>(pAdapter)),
+      m_pNoteDriver(pdfium::MakeUnique<CFWL_NoteDriver>()) {}
+
+IFWL_App::~IFWL_App() {
+  CFWL_ToolTipContainer::DeleteInstance();
+}
+
+CXFA_FFApp* IFWL_App::GetAdapterNative() {
+  return m_pAdapterNative;
+}
+
+CFWL_WidgetMgr* IFWL_App::GetWidgetMgr() {
+  return m_pWidgetMgr.get();
+}
diff --git a/xfa/fwl/core/ifwl_app.h b/xfa/fwl/core/ifwl_app.h
index c030e26..35cbbe2 100644
--- a/xfa/fwl/core/ifwl_app.h
+++ b/xfa/fwl/core/ifwl_app.h
@@ -7,25 +7,14 @@
 #ifndef XFA_FWL_CORE_IFWL_APP_H_
 #define XFA_FWL_CORE_IFWL_APP_H_
 
-// The FWL app code contains three parallel classes, which reference each
-// other via pointers as follows:
-//
-//                    m_pIface               m_pImpl
-//      CXFA_FFApp ------------> IFWL_App -----------> CFWL_AppImp
-//                                        <-----------
-//                                           m_pIface
-
 #include <memory>
 
 #include "core/fxcrt/fx_string.h"
-#include "xfa/fwl/core/fwl_appimp.h"
-#include "xfa/fwl/core/fwl_error.h"
 
 class CFWL_NoteDriver;
 class CFWL_WidgetMgr;
 class CXFA_FFApp;
 class CXFA_FWLAdapterWidgetMgr;
-class IFWL_ThemeProvider;
 class IFWL_Widget;
 
 enum FWL_KeyFlag {
@@ -40,32 +29,17 @@
 
 class IFWL_App {
  public:
-  static IFWL_App* Create(CXFA_FFApp* pAdapter);
+  explicit IFWL_App(CXFA_FFApp* pAdapter);
+  ~IFWL_App();
 
-  virtual ~IFWL_App();
-
-  FWL_Error Initialize();
-  FWL_Error Finalize();
   CXFA_FFApp* GetAdapterNative();
   CFWL_WidgetMgr* GetWidgetMgr();
-  IFWL_ThemeProvider* GetThemeProvider();
-  void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider);
-  void Exit(int32_t iExitCode);
-
-  // These call into polymorphic methods in the impl; no need to override.
-  void Release();
-
-  CFWL_AppImp* GetImpl() const { return m_pImpl.get(); }
-
-  // Takes ownership of |pImpl|.
-  void SetImpl(CFWL_AppImp* pImpl) { m_pImpl.reset(pImpl); }
-
-  CFWL_NoteDriver* GetNoteDriver() const;
+  CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); }
 
  private:
-  IFWL_App();
-
-  std::unique_ptr<CFWL_AppImp> m_pImpl;
+  CXFA_FFApp* const m_pAdapterNative;
+  std::unique_ptr<CFWL_WidgetMgr> m_pWidgetMgr;
+  std::unique_ptr<CFWL_NoteDriver> m_pNoteDriver;
 };
 
 IFWL_App* FWL_GetApp();
diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp
index 6bedcd4..642ee56 100644
--- a/xfa/fxfa/app/xfa_ffapp.cpp
+++ b/xfa/fxfa/app/xfa_ffapp.cpp
@@ -74,18 +74,12 @@
 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider)
     : m_pProvider(pProvider),
       m_pWidgetMgrDelegate(nullptr),
-      m_pFWLApp(IFWL_App::Create(this)) {
+      m_pFWLApp(pdfium::MakeUnique<IFWL_App>(this)) {
   FWL_SetApp(m_pFWLApp.get());
-  m_pFWLApp->Initialize();
   CXFA_TimeZoneProvider::Create();
 }
 
 CXFA_FFApp::~CXFA_FFApp() {
-  if (m_pFWLApp) {
-    m_pFWLApp->Finalize();
-    m_pFWLApp->Release();
-  }
-
   CXFA_TimeZoneProvider::Destroy();
 }
 
diff --git a/xfa/fxfa/app/xfa_fftext.cpp b/xfa/fxfa/app/xfa_fftext.cpp
index 9fa6baf..b8ad671 100644
--- a/xfa/fxfa/app/xfa_fftext.cpp
+++ b/xfa/fxfa/app/xfa_fftext.cpp
@@ -7,6 +7,7 @@
 #include "xfa/fxfa/app/xfa_fftext.h"
 
 #include "xfa/fwl/core/fwl_widgetdef.h"
+#include "xfa/fwl/core/fwl_widgethit.h"
 #include "xfa/fxfa/app/xfa_ffdraw.h"
 #include "xfa/fxfa/app/xfa_textlayout.h"
 #include "xfa/fxfa/xfa_ffapp.h"
diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp
index cac9ccf..0e84ad6 100644
--- a/xfa/fxfa/app/xfa_ffwidget.cpp
+++ b/xfa/fxfa/app/xfa_ffwidget.cpp
@@ -15,6 +15,7 @@
 #include "core/fxge/cfx_gemodule.h"
 #include "core/fxge/cfx_pathdata.h"
 #include "core/fxge/cfx_renderdevice.h"
+#include "xfa/fwl/core/fwl_widgethit.h"
 #include "xfa/fxfa/app/xfa_textlayout.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
 #include "xfa/fxfa/fxfa_widget.h"