Provide better layering for FWL theme providers.

Move knowledge of specific CFWL_*TP theme providers out of the
xfa/ layer and back down into the pwl/ layer. This unfortunately
makes a pure virtual interface impure, but the resulting object
is still reasonable.

-- Use only pointers to common superclass in the header.

Change-Id: I393265f4cac7e0171a0d48edb8aafc706e89b914
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72491
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/BUILD.gn b/xfa/fwl/BUILD.gn
index 4ff251f..a3778b2 100644
--- a/xfa/fwl/BUILD.gn
+++ b/xfa/fwl/BUILD.gn
@@ -81,6 +81,7 @@
     "cfwl_widgetproperties.h",
     "fwl_widgetdef.h",
     "fwl_widgethit.h",
+    "ifwl_themeprovider.cpp",
     "ifwl_themeprovider.h",
     "ifwl_widgetdelegate.h",
     "theme/cfwl_barcodetp.cpp",
diff --git a/xfa/fwl/ifwl_themeprovider.cpp b/xfa/fwl/ifwl_themeprovider.cpp
new file mode 100644
index 0000000..3f46227
--- /dev/null
+++ b/xfa/fwl/ifwl_themeprovider.cpp
@@ -0,0 +1,64 @@
+// Copyright 2020 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/ifwl_themeprovider.h"
+
+#include "xfa/fwl/cfwl_widget.h"
+#include "xfa/fwl/theme/cfwl_barcodetp.h"
+#include "xfa/fwl/theme/cfwl_carettp.h"
+#include "xfa/fwl/theme/cfwl_checkboxtp.h"
+#include "xfa/fwl/theme/cfwl_comboboxtp.h"
+#include "xfa/fwl/theme/cfwl_datetimepickertp.h"
+#include "xfa/fwl/theme/cfwl_edittp.h"
+#include "xfa/fwl/theme/cfwl_listboxtp.h"
+#include "xfa/fwl/theme/cfwl_monthcalendartp.h"
+#include "xfa/fwl/theme/cfwl_pictureboxtp.h"
+#include "xfa/fwl/theme/cfwl_pushbuttontp.h"
+#include "xfa/fwl/theme/cfwl_scrollbartp.h"
+
+IFWL_ThemeProvider::IFWL_ThemeProvider()
+    : m_pCheckBoxTP(std::make_unique<CFWL_CheckBoxTP>()),
+      m_pListBoxTP(std::make_unique<CFWL_ListBoxTP>()),
+      m_pPictureBoxTP(std::make_unique<CFWL_PictureBoxTP>()),
+      m_pSrollBarTP(std::make_unique<CFWL_ScrollBarTP>()),
+      m_pEditTP(std::make_unique<CFWL_EditTP>()),
+      m_pComboBoxTP(std::make_unique<CFWL_ComboBoxTP>()),
+      m_pMonthCalendarTP(std::make_unique<CFWL_MonthCalendarTP>()),
+      m_pDateTimePickerTP(std::make_unique<CFWL_DateTimePickerTP>()),
+      m_pPushButtonTP(std::make_unique<CFWL_PushButtonTP>()),
+      m_pCaretTP(std::make_unique<CFWL_CaretTP>()),
+      m_pBarcodeTP(std::make_unique<CFWL_BarcodeTP>()) {}
+
+IFWL_ThemeProvider::~IFWL_ThemeProvider() = default;
+
+CFWL_WidgetTP* IFWL_ThemeProvider::GetTheme(const CFWL_Widget* pWidget) const {
+  switch (pWidget->GetClassID()) {
+    case FWL_Type::CheckBox:
+      return m_pCheckBoxTP.get();
+    case FWL_Type::ListBox:
+      return m_pListBoxTP.get();
+    case FWL_Type::PictureBox:
+      return m_pPictureBoxTP.get();
+    case FWL_Type::ScrollBar:
+      return m_pSrollBarTP.get();
+    case FWL_Type::Edit:
+      return m_pEditTP.get();
+    case FWL_Type::ComboBox:
+      return m_pComboBoxTP.get();
+    case FWL_Type::MonthCalendar:
+      return m_pMonthCalendarTP.get();
+    case FWL_Type::DateTimePicker:
+      return m_pDateTimePickerTP.get();
+    case FWL_Type::PushButton:
+      return m_pPushButtonTP.get();
+    case FWL_Type::Caret:
+      return m_pCaretTP.get();
+    case FWL_Type::Barcode:
+      return m_pBarcodeTP.get();
+    default:
+      return nullptr;
+  }
+}
diff --git a/xfa/fwl/ifwl_themeprovider.h b/xfa/fwl/ifwl_themeprovider.h
index 5700d34..f23acff 100644
--- a/xfa/fwl/ifwl_themeprovider.h
+++ b/xfa/fwl/ifwl_themeprovider.h
@@ -7,6 +7,8 @@
 #ifndef XFA_FWL_IFWL_THEMEPROVIDER_H_
 #define XFA_FWL_IFWL_THEMEPROVIDER_H_
 
+#include <memory>
+
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxge/fx_dib.h"
@@ -16,10 +18,12 @@
 class CFWL_ThemePart;
 class CFWL_ThemeText;
 class CFWL_Widget;
+class CFWL_WidgetTP;
 
 class IFWL_ThemeProvider {
  public:
-  virtual ~IFWL_ThemeProvider() = default;
+  IFWL_ThemeProvider();
+  virtual ~IFWL_ThemeProvider();
 
   virtual void DrawBackground(const CFWL_ThemeBackground& pParams) = 0;
   virtual void DrawText(const CFWL_ThemeText& pParams) = 0;
@@ -36,6 +40,22 @@
   virtual FX_COLORREF GetTextColor(const CFWL_ThemePart& pThemePart) const = 0;
   virtual CFX_SizeF GetSpaceAboveBelow(
       const CFWL_ThemePart& pThemePart) const = 0;
+
+ protected:
+  CFWL_WidgetTP* GetTheme(const CFWL_Widget* pWidget) const;
+
+ private:
+  std::unique_ptr<CFWL_WidgetTP> m_pCheckBoxTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pListBoxTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pPictureBoxTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pSrollBarTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pEditTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pComboBoxTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pMonthCalendarTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pDateTimePickerTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pPushButtonTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pCaretTP;
+  std::unique_ptr<CFWL_WidgetTP> m_pBarcodeTP;
 };
 
 #endif  // XFA_FWL_IFWL_THEMEPROVIDER_H_
diff --git a/xfa/fxfa/cxfa_fwltheme.cpp b/xfa/fxfa/cxfa_fwltheme.cpp
index 0cba241..bf5ee49 100644
--- a/xfa/fxfa/cxfa_fwltheme.cpp
+++ b/xfa/fxfa/cxfa_fwltheme.cpp
@@ -48,19 +48,7 @@
 }  // namespace
 
 CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp)
-    : m_pCheckBoxTP(std::make_unique<CFWL_CheckBoxTP>()),
-      m_pListBoxTP(std::make_unique<CFWL_ListBoxTP>()),
-      m_pPictureBoxTP(std::make_unique<CFWL_PictureBoxTP>()),
-      m_pSrollBarTP(std::make_unique<CFWL_ScrollBarTP>()),
-      m_pEditTP(std::make_unique<CFWL_EditTP>()),
-      m_pComboBoxTP(std::make_unique<CFWL_ComboBoxTP>()),
-      m_pMonthCalendarTP(std::make_unique<CFWL_MonthCalendarTP>()),
-      m_pDateTimePickerTP(std::make_unique<CFWL_DateTimePickerTP>()),
-      m_pPushButtonTP(std::make_unique<CFWL_PushButtonTP>()),
-      m_pCaretTP(std::make_unique<CFWL_CaretTP>()),
-      m_pBarcodeTP(std::make_unique<CFWL_BarcodeTP>()),
-      m_pTextOut(std::make_unique<CFDE_TextOut>()),
-      m_pApp(pApp) {}
+    : m_pTextOut(std::make_unique<CFDE_TextOut>()), m_pApp(pApp) {}
 
 bool CXFA_FWLTheme::LoadCalendarFont(CXFA_FFDoc* doc) {
   for (size_t i = 0; !m_pCalendarFont && i < pdfium::size(g_FWLTheme_CalFonts);
@@ -250,32 +238,3 @@
   m_pTextOut->SetStyles(pParams.m_dwTTOStyles);
   m_pTextOut->CalcLogicSize(pParams.m_wsText.AsStringView(), pRect);
 }
-
-CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(CFWL_Widget* pWidget) const {
-  switch (pWidget->GetClassID()) {
-    case FWL_Type::CheckBox:
-      return m_pCheckBoxTP.get();
-    case FWL_Type::ListBox:
-      return m_pListBoxTP.get();
-    case FWL_Type::PictureBox:
-      return m_pPictureBoxTP.get();
-    case FWL_Type::ScrollBar:
-      return m_pSrollBarTP.get();
-    case FWL_Type::Edit:
-      return m_pEditTP.get();
-    case FWL_Type::ComboBox:
-      return m_pComboBoxTP.get();
-    case FWL_Type::MonthCalendar:
-      return m_pMonthCalendarTP.get();
-    case FWL_Type::DateTimePicker:
-      return m_pDateTimePickerTP.get();
-    case FWL_Type::PushButton:
-      return m_pPushButtonTP.get();
-    case FWL_Type::Caret:
-      return m_pCaretTP.get();
-    case FWL_Type::Barcode:
-      return m_pBarcodeTP.get();
-    default:
-      return nullptr;
-  }
-}
diff --git a/xfa/fxfa/cxfa_fwltheme.h b/xfa/fxfa/cxfa_fwltheme.h
index 11f2584..a84122a 100644
--- a/xfa/fxfa/cxfa_fwltheme.h
+++ b/xfa/fxfa/cxfa_fwltheme.h
@@ -10,19 +10,10 @@
 #include <memory>
 
 #include "xfa/fwl/ifwl_themeprovider.h"
-#include "xfa/fwl/theme/cfwl_barcodetp.h"
-#include "xfa/fwl/theme/cfwl_carettp.h"
-#include "xfa/fwl/theme/cfwl_checkboxtp.h"
-#include "xfa/fwl/theme/cfwl_comboboxtp.h"
-#include "xfa/fwl/theme/cfwl_datetimepickertp.h"
-#include "xfa/fwl/theme/cfwl_edittp.h"
-#include "xfa/fwl/theme/cfwl_listboxtp.h"
-#include "xfa/fwl/theme/cfwl_monthcalendartp.h"
-#include "xfa/fwl/theme/cfwl_pictureboxtp.h"
-#include "xfa/fwl/theme/cfwl_pushbuttontp.h"
-#include "xfa/fwl/theme/cfwl_scrollbartp.h"
-#include "xfa/fwl/theme/cfwl_widgettp.h"
-#include "xfa/fxfa/cxfa_ffapp.h"
+
+class CFDE_TextOut;
+class CXFA_FFApp;
+class CXFA_FFDoc;
 
 class CXFA_FWLTheme final : public IFWL_ThemeProvider {
  public:
@@ -47,19 +38,6 @@
   CFX_SizeF GetSpaceAboveBelow(const CFWL_ThemePart& pThemePart) const override;
 
  private:
-  CFWL_WidgetTP* GetTheme(CFWL_Widget* pWidget) const;
-
-  std::unique_ptr<CFWL_CheckBoxTP> m_pCheckBoxTP;
-  std::unique_ptr<CFWL_ListBoxTP> m_pListBoxTP;
-  std::unique_ptr<CFWL_PictureBoxTP> m_pPictureBoxTP;
-  std::unique_ptr<CFWL_ScrollBarTP> m_pSrollBarTP;
-  std::unique_ptr<CFWL_EditTP> m_pEditTP;
-  std::unique_ptr<CFWL_ComboBoxTP> m_pComboBoxTP;
-  std::unique_ptr<CFWL_MonthCalendarTP> m_pMonthCalendarTP;
-  std::unique_ptr<CFWL_DateTimePickerTP> m_pDateTimePickerTP;
-  std::unique_ptr<CFWL_PushButtonTP> m_pPushButtonTP;
-  std::unique_ptr<CFWL_CaretTP> m_pCaretTP;
-  std::unique_ptr<CFWL_BarcodeTP> m_pBarcodeTP;
   std::unique_ptr<CFDE_TextOut> m_pTextOut;
   RetainPtr<CFGAS_GEFont> m_pCalendarFont;
   WideString m_wsResource;