Remove CFWL_WidgetProperties::m_pFWLThemeProvider.

The IFWL_ThemeProvider, as implemented by CXFA_FWLThemeProvider is
essentially a singleton living in the CXFA_FFApp. Instead of storing
a theoretically changing pointer to it inside each of the FWL widget's
properties, retrieve the one and only instance as needed. Then remove
code to set it into widgets, which mainly involved propagating the
values to sub-widgets to keep them in sync.

Change-Id: Ia645a338bdc600cb9199d439c09aabdbe959bfe8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72750
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index 1839fe7..a431e38 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -111,6 +111,12 @@
   m_nLoadStatus = FXFA_LOADSTATUS_LOADING;
   m_XFAPageList.clear();
 
+  CJS_Runtime* actual_runtime = GetCJSRuntime();  // Null if a stub.
+  if (!actual_runtime) {
+    FXSYS_SetLastError(FPDF_ERR_XFALOAD);
+    return false;
+  }
+
   auto stream = CreateXFAMultiStream(m_pPDFDoc.Get());
   if (!stream) {
     FXSYS_SetLastError(FPDF_ERR_XFALOAD);
@@ -127,15 +133,14 @@
   m_pXFADoc =
       CXFA_FFDoc::CreateAndOpen(m_pXFAApp.get(), m_pDocEnv.get(),
                                 m_pPDFDoc.Get(), m_pGCHeap.get(), m_pXML.get());
-
   if (!m_pXFADoc) {
     FXSYS_SetLastError(FPDF_ERR_XFALOAD);
     return false;
   }
 
-  CJS_Runtime* actual_runtime = GetCJSRuntime();  // Null if a stub.
-  if (!actual_runtime) {
-    FXSYS_SetLastError(FPDF_ERR_XFALOAD);
+  if (!m_pXFAApp->LoadFWLTheme(m_pXFADoc.get())) {
+    m_pXFADoc.reset();
+    FXSYS_SetLastError(FPDF_ERR_XFALAYOUT);
     return false;
   }
 
diff --git a/xfa/fwl/cfwl_app.h b/xfa/fwl/cfwl_app.h
index 09ace2b..8dfc2ae 100644
--- a/xfa/fwl/cfwl_app.h
+++ b/xfa/fwl/cfwl_app.h
@@ -14,6 +14,7 @@
 
 class CFWL_NoteDriver;
 class CFWL_WidgetMgr;
+class IFWL_ThemeProvider;
 
 enum FWL_KeyFlag {
   FWL_KEYFLAG_Ctrl = 1 << 0,
@@ -32,6 +33,7 @@
     virtual ~AdapterIface() = default;
     virtual CFWL_WidgetMgr::AdapterIface* GetWidgetMgrAdapter() = 0;
     virtual TimerHandlerIface* GetTimerHandler() = 0;
+    virtual IFWL_ThemeProvider* GetThemeProvider() = 0;
   };
 
   explicit CFWL_App(AdapterIface* pAdapter);
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index 31a3051..d77c18a 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -36,8 +36,7 @@
                               const CFX_Matrix& matrix) {
   if (!pGraphics)
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    return;
+
   if ((GetProperties()->m_dwStates & FWL_WGTSTATE_Focused) == 0) {
     GenerateBarcodeImageCache();
     if (!m_pBarcodeEngine || m_eStatus != Status::kEncodeSuccess)
@@ -157,20 +156,15 @@
   if (!m_pBarcodeEngine)
     return;
 
-  IFWL_ThemeProvider* pTheme = GetAvailableTheme();
-  if (pTheme) {
-    CFWL_ThemePart part;
-    part.m_pWidget = this;
-    if (RetainPtr<CFGAS_GEFont> pFont = pTheme->GetFont(part)) {
-      if (CFX_Font* pCXFont = pFont->GetDevFont())
-        m_pBarcodeEngine->SetFont(pCXFont);
-    }
-    m_pBarcodeEngine->SetFontSize(pTheme->GetFontSize(part));
-    m_pBarcodeEngine->SetFontColor(pTheme->GetTextColor(part));
-  } else {
-    m_pBarcodeEngine->SetFontSize(FWLTHEME_CAPACITY_FontSize);
+  IFWL_ThemeProvider* pTheme = GetThemeProvider();
+  CFWL_ThemePart part;
+  part.m_pWidget = this;
+  if (RetainPtr<CFGAS_GEFont> pFont = pTheme->GetFont(part)) {
+    if (CFX_Font* pCXFont = pFont->GetDevFont())
+      m_pBarcodeEngine->SetFont(pCXFont);
   }
-
+  m_pBarcodeEngine->SetFontSize(pTheme->GetFontSize(part));
+  m_pBarcodeEngine->SetFontColor(pTheme->GetTextColor(part));
   m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height));
   m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width));
   if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING)
diff --git a/xfa/fwl/cfwl_caret.cpp b/xfa/fwl/cfwl_caret.cpp
index fabe4bb..a612cc3 100644
--- a/xfa/fwl/cfwl_caret.cpp
+++ b/xfa/fwl/cfwl_caret.cpp
@@ -41,12 +41,8 @@
                             const CFX_Matrix& matrix) {
   if (!pGraphics)
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
-  if (!GetProperties()->m_pThemeProvider)
-    return;
 
-  DrawCaretBK(pGraphics, GetProperties()->m_pThemeProvider.Get(), &matrix);
+  DrawCaretBK(pGraphics, &matrix);
 }
 
 void CFWL_Caret::ShowCaret() {
@@ -63,7 +59,6 @@
 }
 
 void CFWL_Caret::DrawCaretBK(CXFA_Graphics* pGraphics,
-                             IFWL_ThemeProvider* pTheme,
                              const CFX_Matrix* pMatrix) {
   if (!(GetProperties()->m_dwStates & kStateHighlight))
     return;
@@ -76,7 +71,8 @@
   param.m_dwStates = CFWL_PartState_HightLight;
   if (pMatrix)
     param.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(param);
+
+  GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {}
diff --git a/xfa/fwl/cfwl_caret.h b/xfa/fwl/cfwl_caret.h
index 7f5dfdf..834ea1b 100644
--- a/xfa/fwl/cfwl_caret.h
+++ b/xfa/fwl/cfwl_caret.h
@@ -38,9 +38,7 @@
   void HideCaret();
 
  private:
-  void DrawCaretBK(CXFA_Graphics* pGraphics,
-                   IFWL_ThemeProvider* pTheme,
-                   const CFX_Matrix* pMatrix);
+  void DrawCaretBK(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix);
 
   std::unique_ptr<CFX_Timer> m_pTimer;
 };
diff --git a/xfa/fwl/cfwl_checkbox.cpp b/xfa/fwl/cfwl_checkbox.cpp
index baf7133..912130b 100644
--- a/xfa/fwl/cfwl_checkbox.cpp
+++ b/xfa/fwl/cfwl_checkbox.cpp
@@ -46,8 +46,6 @@
 void CFWL_CheckBox::Update() {
   if (IsLocked())
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
 
   UpdateTextOutStyles();
   Layout();
@@ -58,15 +56,10 @@
   if (!pGraphics)
     return;
 
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
-  if (!pTheme)
-    return;
-
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
 
   int32_t dwStates = GetPartStates();
-
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
   param.m_iPart = CFWL_Part::Background;
@@ -75,8 +68,9 @@
   param.m_matrix.Concat(matrix);
   param.m_PartRect = m_ClientRect;
   if (GetProperties()->m_dwStates & FWL_WGTSTATE_Focused)
-
     param.m_pRtData = &m_FocusRect;
+
+  IFWL_ThemeProvider* pTheme = GetThemeProvider();
   pTheme->DrawBackground(param);
 
   param.m_iPart = CFWL_Part::CheckBox;
@@ -127,9 +121,7 @@
   m_CaptionRect.Inflate(-kCaptionMargin, -kCaptionMargin);
 
   CFX_RectF rtFocus = m_CaptionRect;
-  CalcTextRect(L"Check box", GetProperties()->m_pThemeProvider.Get(),
-               m_TTOStyles, m_iTTOAlign, &rtFocus);
-
+  CalcTextRect(L"Check box", m_TTOStyles, m_iTTOAlign, &rtFocus);
   m_FocusRect = CFX_RectF(m_CaptionRect.TopLeft(),
                           std::max(m_CaptionRect.width, rtFocus.width),
                           std::min(m_CaptionRect.height, rtFocus.height));
diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp
index 6d50262..f1b52f0 100644
--- a/xfa/fwl/cfwl_combobox.cpp
+++ b/xfa/fwl/cfwl_combobox.cpp
@@ -76,7 +76,6 @@
 
   if (m_pEdit)
     ResetEditAlignment();
-  ResetTheme();
   Layout();
 }
 
@@ -97,7 +96,6 @@
 
 void CFWL_ComboBox::DrawWidget(CXFA_Graphics* pGraphics,
                                const CFX_Matrix& matrix) {
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
   pGraphics->SaveGraphState();
   pGraphics->ConcatMatrix(&matrix);
   if (!m_BtnRect.IsEmpty(0.1f)) {
@@ -107,7 +105,7 @@
     param.m_dwStates = m_iBtnState;
     param.m_pGraphics = pGraphics;
     param.m_PartRect = m_BtnRect;
-    pTheme->DrawBackground(param);
+    GetThemeProvider()->DrawBackground(param);
   }
   pGraphics->RestoreGraphState();
 
@@ -125,17 +123,6 @@
   }
 }
 
-void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
-  if (!pThemeProvider)
-    return;
-
-  GetProperties()->m_pThemeProvider = pThemeProvider;
-  if (m_pListBox)
-    m_pListBox->SetThemeProvider(pThemeProvider);
-  if (m_pEdit)
-    m_pEdit->SetThemeProvider(pThemeProvider);
-}
-
 WideString CFWL_ComboBox::GetTextByIndex(int32_t iIndex) const {
   CFWL_ListItem* pItem = static_cast<CFWL_ListItem*>(
       m_pListBox->GetItem(m_pListBox.get(), iIndex));
@@ -281,10 +268,8 @@
 void CFWL_ComboBox::Layout() {
   m_ClientRect = GetClientRect();
   m_ContentRect = m_ClientRect;
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  if (!theme)
-    return;
 
+  IFWL_ThemeProvider* theme = GetThemeProvider();
   float borderWidth = 1;
   float fBtn = theme->GetScrollBarWidth();
   if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) {
@@ -314,17 +299,6 @@
   m_pEdit->Update();
 }
 
-void CFWL_ComboBox::ResetTheme() {
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
-
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
-  if (m_pListBox && !m_pListBox->GetThemeProvider())
-    m_pListBox->SetThemeProvider(pTheme);
-  if (m_pEdit && !m_pEdit->GetThemeProvider())
-    m_pEdit->SetThemeProvider(pTheme);
-}
-
 void CFWL_ComboBox::ResetEditAlignment() {
   if (!m_pEdit)
     return;
@@ -408,7 +382,6 @@
   auto prop = std::make_unique<CFWL_WidgetProperties>();
   prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll;
   prop->m_dwStates = FWL_WGTSTATE_Invisible;
-  prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
   m_pListBox =
       std::make_unique<CFWL_ComboList>(GetOwnerApp(), std::move(prop), this);
 }
@@ -417,11 +390,8 @@
   if (m_pEdit)
     return;
 
-  auto prop = std::make_unique<CFWL_WidgetProperties>();
-  prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
-
-  m_pEdit =
-      std::make_unique<CFWL_ComboEdit>(GetOwnerApp(), std::move(prop), this);
+  m_pEdit = std::make_unique<CFWL_ComboEdit>(
+      GetOwnerApp(), std::make_unique<CFWL_WidgetProperties>(), this);
 }
 
 void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) {
diff --git a/xfa/fwl/cfwl_combobox.h b/xfa/fwl/cfwl_combobox.h
index 50908cf..719c825 100644
--- a/xfa/fwl/cfwl_combobox.h
+++ b/xfa/fwl/cfwl_combobox.h
@@ -49,7 +49,6 @@
   void Update() override;
   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
-  void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
   void OnProcessMessage(CFWL_Message* pMessage) override;
   void OnProcessEvent(CFWL_Event* pEvent) override;
   void OnDrawWidget(CXFA_Graphics* pGraphics,
@@ -102,7 +101,6 @@
   void MatchEditText();
   void SyncEditText(int32_t iListItem);
   void Layout();
-  void ResetTheme();
   void ResetEditAlignment();
   void ResetListItemAlignment();
   void GetPopupPos(float fMinHeight,
diff --git a/xfa/fwl/cfwl_datetimepicker.cpp b/xfa/fwl/cfwl_datetimepicker.cpp
index 04efcdb..60fb199 100644
--- a/xfa/fwl/cfwl_datetimepicker.cpp
+++ b/xfa/fwl/cfwl_datetimepicker.cpp
@@ -30,18 +30,15 @@
   auto monthProp = std::make_unique<CFWL_WidgetProperties>();
   monthProp->m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border;
   monthProp->m_dwStates = FWL_WGTSTATE_Invisible;
-  monthProp->m_pThemeProvider = GetProperties()->m_pThemeProvider;
   m_pMonthCal = std::make_unique<CFWL_MonthCalendar>(
       GetOwnerApp(), std::move(monthProp), this);
 
   m_pMonthCal->SetWidgetRect(
       CFX_RectF(0, 0, m_pMonthCal->GetAutosizedWidgetRect().Size()));
 
-  auto editProp = std::make_unique<CFWL_WidgetProperties>();
-  editProp->m_pThemeProvider = GetProperties()->m_pThemeProvider;
+  m_pEdit = std::make_unique<CFWL_DateTimeEdit>(
+      GetOwnerApp(), std::make_unique<CFWL_WidgetProperties>(), this);
 
-  m_pEdit = std::make_unique<CFWL_DateTimeEdit>(GetOwnerApp(),
-                                                std::move(editProp), this);
   RegisterEventTarget(m_pMonthCal.get());
   RegisterEventTarget(m_pEdit.get());
 }
@@ -58,21 +55,12 @@
   if (IsLocked())
     return;
 
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
-  m_pEdit->SetThemeProvider(GetProperties()->m_pThemeProvider.Get());
   m_ClientRect = GetClientRect();
   m_pEdit->SetWidgetRect(m_ClientRect);
   ResetEditAlignment();
   m_pEdit->Update();
-  if (!m_pMonthCal->GetThemeProvider())
-    m_pMonthCal->SetThemeProvider(GetProperties()->m_pThemeProvider.Get());
 
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  if (!theme)
-    return;
-
-  m_fBtn = theme->GetScrollBarWidth();
+  m_fBtn = GetThemeProvider()->GetScrollBarWidth();
   CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
   CFX_RectF rtPopUp(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight,
                     rtMonthCal.width, rtMonthCal.height);
@@ -101,18 +89,14 @@
   if (!pGraphics)
     return;
 
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
-  if (!pTheme)
-    return;
-
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
+
   if (!m_BtnRect.IsEmpty())
-    DrawDropDownButton(pGraphics, pTheme, &matrix);
+    DrawDropDownButton(pGraphics, &matrix);
 
   if (m_pEdit) {
     CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
-
     CFX_Matrix mt(1, 0, 0, 1, rtEdit.left, rtEdit.top);
     mt.Concat(matrix);
     m_pEdit->DrawWidget(pGraphics, mt);
@@ -126,11 +110,6 @@
   m_pMonthCal->DrawWidget(pGraphics, mt);
 }
 
-void CFWL_DateTimePicker::SetThemeProvider(IFWL_ThemeProvider* pTP) {
-  GetProperties()->m_pThemeProvider = pTP;
-  m_pMonthCal->SetThemeProvider(pTP);
-}
-
 void CFWL_DateTimePicker::GetCurSel(int32_t& iYear,
                                     int32_t& iMonth,
                                     int32_t& iDay) {
@@ -198,7 +177,6 @@
 }
 
 void CFWL_DateTimePicker::DrawDropDownButton(CXFA_Graphics* pGraphics,
-                                             IFWL_ThemeProvider* pTheme,
                                              const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
@@ -208,7 +186,7 @@
   param.m_PartRect = m_BtnRect;
   if (pMatrix)
     param.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 WideString CFWL_DateTimePicker::FormatDateString(int32_t iYear,
diff --git a/xfa/fwl/cfwl_datetimepicker.h b/xfa/fwl/cfwl_datetimepicker.h
index 734dd07..4b84d83 100644
--- a/xfa/fwl/cfwl_datetimepicker.h
+++ b/xfa/fwl/cfwl_datetimepicker.h
@@ -39,7 +39,6 @@
   void Update() override;
   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
-  void SetThemeProvider(IFWL_ThemeProvider* pTP) override;
   void OnProcessMessage(CFWL_Message* pMessage) override;
   void OnDrawWidget(CXFA_Graphics* pGraphics,
                     const CFX_Matrix& matrix) override;
@@ -76,9 +75,7 @@
   void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay);
 
  private:
-  void DrawDropDownButton(CXFA_Graphics* pGraphics,
-                          IFWL_ThemeProvider* pTheme,
-                          const CFX_Matrix* pMatrix);
+  void DrawDropDownButton(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix);
   WideString FormatDateString(int32_t iYear, int32_t iMonth, int32_t iDay);
   void ResetEditAlignment();
   void GetPopupPos(float fMinHeight,
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 553f74e..c39727c 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -65,8 +65,7 @@
 CFX_RectF CFWL_Edit::GetWidgetRect() {
   CFX_RectF rect = GetProperties()->m_WidgetRect;
   if (GetProperties()->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
-    IFWL_ThemeProvider* theme = GetAvailableTheme();
-    float scrollbarWidth = theme ? theme->GetScrollBarWidth() : 0.0f;
+    float scrollbarWidth = GetThemeProvider()->GetScrollBarWidth();
     if (IsShowScrollBar(true)) {
       rect.width += scrollbarWidth;
       rect.width += kEditMargin;
@@ -81,14 +80,12 @@
 
 CFX_RectF CFWL_Edit::GetAutosizedWidgetRect() {
   CFX_RectF rect;
-
   if (m_pEditEngine->GetLength() > 0) {
     CFX_SizeF size = CalcTextSize(
-        m_pEditEngine->GetText(), GetProperties()->m_pThemeProvider.Get(),
+        m_pEditEngine->GetText(),
         !!(GetProperties()->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine));
     rect = CFX_RectF(0, 0, size);
   }
-
   InflateWidgetRect(rect);
   return rect;
 }
@@ -104,8 +101,6 @@
 void CFWL_Edit::Update() {
   if (IsLocked())
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
 
   Layout();
   if (m_ClientRect.IsEmpty())
@@ -140,25 +135,9 @@
   if (m_ClientRect.IsEmpty())
     return;
 
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
-  if (!pTheme)
-    return;
-
-  DrawContent(pGraphics, pTheme, &matrix);
+  DrawContent(pGraphics, &matrix);
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
-}
-
-void CFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
-  if (!pThemeProvider)
-    return;
-  if (m_pHorzScrollBar)
-    m_pHorzScrollBar->SetThemeProvider(pThemeProvider);
-  if (m_pVertScrollBar)
-    m_pVertScrollBar->SetThemeProvider(pThemeProvider);
-  if (m_pCaret)
-    m_pCaret->SetThemeProvider(pThemeProvider);
-  GetProperties()->m_pThemeProvider = pThemeProvider;
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
 }
 
 void CFWL_Edit::SetText(const WideString& wsText) {
@@ -331,7 +310,6 @@
 }
 
 void CFWL_Edit::DrawTextBk(CXFA_Graphics* pGraphics,
-                           IFWL_ThemeProvider* pTheme,
                            const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
@@ -346,7 +324,7 @@
   param.m_pGraphics = pGraphics;
   param.m_matrix = *pMatrix;
   param.m_PartRect = m_ClientRect;
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 
   if (!IsShowScrollBar(true) || !IsShowScrollBar(false))
     return;
@@ -359,14 +337,12 @@
   param.m_bStaticBackground = true;
   param.m_bMaximize = true;
   param.m_PartRect = rtStatic;
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_Edit::DrawContent(CXFA_Graphics* pGraphics,
-                            IFWL_ThemeProvider* pTheme,
                             const CFX_Matrix* pMatrix) {
   pGraphics->SaveGraphState();
-
   if (GetProperties()->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText)
     pGraphics->SaveGraphState();
 
@@ -402,7 +378,7 @@
     param.m_pWidget = this;
     param.m_iPart = CFWL_Part::Background;
     param.m_pPath = &path;
-    pTheme->DrawBackground(param);
+    GetThemeProvider()->DrawBackground(param);
   }
 
   CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice();
@@ -427,7 +403,7 @@
     param.m_pWidget = this;
     param.m_iPart = CFWL_Part::CombTextLine;
     param.m_pPath = &path;
-    pTheme->DrawBackground(param);
+    GetThemeProvider()->DrawBackground(param);
   }
   pGraphics->RestoreGraphState();
 }
@@ -523,14 +499,9 @@
   }
   m_pEditEngine->LimitHorizontalScroll(!auto_hscroll);
 
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
+  IFWL_ThemeProvider* theme = GetThemeProvider();
   CFWL_ThemePart part;
   part.m_pWidget = this;
-
-  if (!theme) {
-    m_fFontSize = FWLTHEME_CAPACITY_FontSize;
-    return;
-  }
   m_fFontSize = theme->GetFontSize(part);
 
   RetainPtr<CFGAS_GEFont> pFont = theme->GetFont(part);
@@ -603,15 +574,13 @@
 void CFWL_Edit::UpdateVAlignment() {
   float fSpaceAbove = 0.0f;
   float fSpaceBelow = 0.0f;
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  if (theme) {
-    CFWL_ThemePart part;
-    part.m_pWidget = this;
+  IFWL_ThemeProvider* theme = GetThemeProvider();
+  CFWL_ThemePart part;
+  part.m_pWidget = this;
 
-    CFX_SizeF pSpace = theme->GetSpaceAboveBelow(part);
-    fSpaceAbove = pSpace.width >= 0.1f ? pSpace.width : 0.0f;
-    fSpaceBelow = pSpace.height >= 0.1f ? pSpace.height : 0.0f;
-  }
+  CFX_SizeF pSpace = theme->GetSpaceAboveBelow(part);
+  fSpaceAbove = pSpace.width >= 0.1f ? pSpace.width : 0.0f;
+  fSpaceBelow = pSpace.height >= 0.1f ? pSpace.height : 0.0f;
 
   float fOffsetY = 0.0f;
   CFX_RectF contents_bounds = m_pEditEngine->GetContentsBoundingBox();
@@ -739,10 +708,8 @@
 void CFWL_Edit::Layout() {
   m_ClientRect = GetClientRect();
   m_EngineRect = m_ClientRect;
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  if (!theme)
-    return;
 
+  IFWL_ThemeProvider* theme = GetThemeProvider();
   float fWidth = theme->GetScrollBarWidth();
   CFWL_ThemePart part;
   if (!GetOuter()) {
@@ -812,9 +779,8 @@
 
   bool bShowVertScrollbar = IsShowScrollBar(true);
   bool bShowHorzScrollbar = IsShowScrollBar(false);
-
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  float fWidth = theme ? theme->GetScrollBarWidth() : 0;
+  IFWL_ThemeProvider* theme = GetThemeProvider();
+  float fWidth = theme->GetScrollBarWidth();
   if (bShowVertScrollbar) {
     if (!m_pVertScrollBar) {
       InitVerticalScrollBar();
@@ -873,7 +839,6 @@
   auto prop = std::make_unique<CFWL_WidgetProperties>();
   prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert;
   prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
-  prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
   m_pVertScrollBar =
       std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
 }
@@ -885,7 +850,6 @@
   auto prop = std::make_unique<CFWL_WidgetProperties>();
   prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz;
   prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
-  prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
   m_pHorzScrollBar =
       std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
 }
diff --git a/xfa/fwl/cfwl_edit.h b/xfa/fwl/cfwl_edit.h
index 8151946..d77413b 100644
--- a/xfa/fwl/cfwl_edit.h
+++ b/xfa/fwl/cfwl_edit.h
@@ -58,7 +58,6 @@
   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
   void SetStates(uint32_t dwStates) override;
   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
-  void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
   void OnProcessMessage(CFWL_Message* pMessage) override;
   void OnProcessEvent(CFWL_Event* pEvent) override;
   void OnDrawWidget(CXFA_Graphics* pGraphics,
@@ -108,10 +107,8 @@
                   const CFX_RectF& clipRect,
                   const CFX_Matrix& mt);
   void DrawTextBk(CXFA_Graphics* pGraphics,
-                  IFWL_ThemeProvider* pTheme,
                   const CFX_Matrix* pMatrix);
   void DrawContent(CXFA_Graphics* pGraphics,
-                   IFWL_ThemeProvider* pTheme,
                    const CFX_Matrix* pMatrix);
 
   void UpdateEditEngine();
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp
index bf38e5f..08e9f0c 100644
--- a/xfa/fwl/cfwl_listbox.cpp
+++ b/xfa/fwl/cfwl_listbox.cpp
@@ -42,23 +42,18 @@
 void CFWL_ListBox::Update() {
   if (IsLocked())
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
 
   switch (GetProperties()->m_dwStyleExes & FWL_STYLEEXT_LTB_AlignMask) {
-    case FWL_STYLEEXT_LTB_LeftAlign: {
+    case FWL_STYLEEXT_LTB_LeftAlign:
       m_iTTOAligns = FDE_TextAlignment::kCenterLeft;
       break;
-    }
-    case FWL_STYLEEXT_LTB_RightAlign: {
+    case FWL_STYLEEXT_LTB_RightAlign:
       m_iTTOAligns = FDE_TextAlignment::kCenterRight;
       break;
-    }
     case FWL_STYLEEXT_LTB_CenterAlign:
-    default: {
+    default:
       m_iTTOAligns = FDE_TextAlignment::kCenter;
       break;
-    }
   }
   m_TTOStyles.single_line_ = true;
   m_fScorllBarWidth = GetScrollWidth();
@@ -86,13 +81,9 @@
   if (!pGraphics)
     return;
 
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
-  if (!pTheme)
-    return;
-
   pGraphics->SaveGraphState();
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
 
   CFX_RectF rtClip(m_ContentRect);
   if (IsShowScrollBar(false))
@@ -102,17 +93,12 @@
 
   pGraphics->SetClipRect(matrix.TransformRect(rtClip));
   if ((GetProperties()->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0)
-    DrawBkground(pGraphics, pTheme, &matrix);
+    DrawBkground(pGraphics, &matrix);
 
-  DrawItems(pGraphics, pTheme, &matrix);
+  DrawItems(pGraphics, &matrix);
   pGraphics->RestoreGraphState();
 }
 
-void CFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
-  if (pThemeProvider)
-    GetProperties()->m_pThemeProvider = pThemeProvider;
-}
-
 int32_t CFWL_ListBox::CountSelItems() {
   int32_t iRet = 0;
   int32_t iCount = CountItems(this);
@@ -342,12 +328,9 @@
 }
 
 void CFWL_ListBox::DrawBkground(CXFA_Graphics* pGraphics,
-                                IFWL_ThemeProvider* pTheme,
                                 const CFX_Matrix* pMatrix) {
   if (!pGraphics)
     return;
-  if (!pTheme)
-    return;
 
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
@@ -360,12 +343,10 @@
     param.m_pRtData = &m_StaticRect;
   if (!IsEnabled())
     param.m_dwStates = CFWL_PartState_Disabled;
-
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_ListBox::DrawItems(CXFA_Graphics* pGraphics,
-                             IFWL_ThemeProvider* pTheme,
                              const CFX_Matrix* pMatrix) {
   float fPosX = 0.0f;
   if (m_pHorzScrollBar)
@@ -393,12 +374,11 @@
       continue;
     if (rtItem.top >= m_ContentRect.bottom())
       break;
-    DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix);
+    DrawItem(pGraphics, pItem, i, rtItem, pMatrix);
   }
 }
 
 void CFWL_ListBox::DrawItem(CXFA_Graphics* pGraphics,
-                            IFWL_ThemeProvider* pTheme,
                             CFWL_ListItem* pItem,
                             int32_t Index,
                             const CFX_RectF& rtItem,
@@ -431,8 +411,9 @@
     bg_param.m_PartRect.width -= (m_fScorllBarWidth + 1);
     rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1);
   }
-  pTheme->DrawBackground(bg_param);
 
+  IFWL_ThemeProvider* pTheme = GetThemeProvider();
+  pTheme->DrawBackground(bg_param);
   if (!pItem)
     return;
 
@@ -458,17 +439,13 @@
 }
 
 CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) {
-  if (!GetProperties()->m_pThemeProvider)
-    return CFX_SizeF();
-
   m_ClientRect = GetClientRect();
   m_ContentRect = m_ClientRect;
   CFX_RectF rtUIMargin;
   if (!GetOuter()) {
     CFWL_ThemePart part;
     part.m_pWidget = this;
-    IFWL_ThemeProvider* theme = GetAvailableTheme();
-    CFX_RectF pUIMargin = theme ? theme->GetUIMargin(part) : CFX_RectF();
+    CFX_RectF pUIMargin = GetThemeProvider()->GetUIMargin(part);
     m_ContentRect.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
                           pUIMargin.height);
   }
@@ -592,23 +569,20 @@
     if (!pItem)
       continue;
 
-    CFX_SizeF sz = CalcTextSize(pItem->GetText(),
-                                GetProperties()->m_pThemeProvider.Get(), false);
+    CFX_SizeF sz = CalcTextSize(pItem->GetText(), false);
     fRet = std::max(fRet, sz.width);
   }
   return fRet;
 }
 
 float CFWL_ListBox::GetScrollWidth() {
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  return theme ? theme->GetScrollBarWidth() : 0.0f;
+  return GetThemeProvider()->GetScrollBarWidth();
 }
 
 float CFWL_ListBox::CalcItemHeight() {
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
   CFWL_ThemePart part;
   part.m_pWidget = this;
-  return (theme ? theme->GetFontSize(part) : 20.0f) + 2 * kItemTextMargin;
+  return GetThemeProvider()->GetFontSize(part) + 2 * kItemTextMargin;
 }
 
 void CFWL_ListBox::InitVerticalScrollBar() {
@@ -618,7 +592,6 @@
   auto prop = std::make_unique<CFWL_WidgetProperties>();
   prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert;
   prop->m_dwStates = FWL_WGTSTATE_Invisible;
-  prop->m_pThemeProvider = m_pScrollBarTP;
   m_pVertScrollBar =
       std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
 }
@@ -630,7 +603,6 @@
   auto prop = std::make_unique<CFWL_WidgetProperties>();
   prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz;
   prop->m_dwStates = FWL_WGTSTATE_Invisible;
-  prop->m_pThemeProvider = m_pScrollBarTP;
   m_pHorzScrollBar =
       std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
 }
diff --git a/xfa/fwl/cfwl_listbox.h b/xfa/fwl/cfwl_listbox.h
index df99c0b..c45e0a5 100644
--- a/xfa/fwl/cfwl_listbox.h
+++ b/xfa/fwl/cfwl_listbox.h
@@ -43,7 +43,6 @@
   void Update() override;
   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
-  void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
   void OnProcessMessage(CFWL_Message* pMessage) override;
   void OnProcessEvent(CFWL_Event* pEvent) override;
   void OnDrawWidget(CXFA_Graphics* pGraphics,
@@ -86,18 +85,15 @@
   CFWL_ListItem* GetFocusedItem();
   void SetFocusItem(CFWL_ListItem* hItem);
   void DrawBkground(CXFA_Graphics* pGraphics,
-                    IFWL_ThemeProvider* pTheme,
                     const CFX_Matrix* pMatrix);
   void DrawItems(CXFA_Graphics* pGraphics,
-                 IFWL_ThemeProvider* pTheme,
                  const CFX_Matrix* pMatrix);
   void DrawItem(CXFA_Graphics* pGraphics,
-                IFWL_ThemeProvider* pTheme,
                 CFWL_ListItem* hItem,
                 int32_t Index,
                 const CFX_RectF& rtItem,
                 const CFX_Matrix* pMatrix);
-  void DrawStatic(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme);
+  void DrawStatic(CXFA_Graphics* pGraphics);
   CFX_SizeF CalcSize(bool bAutoSize);
   void UpdateItemSize(CFWL_ListItem* hItem,
                       CFX_SizeF& size,
@@ -128,7 +124,6 @@
   float m_fItemHeight = 0.0f;
   float m_fScorllBarWidth = 0.0f;
   CFWL_ListItem* m_hAnchor = nullptr;
-  IFWL_ThemeProvider* m_pScrollBarTP = nullptr;
   std::vector<std::unique_ptr<CFWL_ListItem>> m_ItemArray;
 };
 
diff --git a/xfa/fwl/cfwl_monthcalendar.cpp b/xfa/fwl/cfwl_monthcalendar.cpp
index a122f86..8dc6b51 100644
--- a/xfa/fwl/cfwl_monthcalendar.cpp
+++ b/xfa/fwl/cfwl_monthcalendar.cpp
@@ -107,15 +107,11 @@
 void CFWL_MonthCalendar::Update() {
   if (IsLocked())
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
 
-  GetCapValue();
   if (!m_bInitialized) {
     InitDate();
     m_bInitialized = true;
   }
-
   ClearDateItem();
   ResetDateItem();
   Layout();
@@ -126,25 +122,21 @@
   if (!pGraphics)
     return;
 
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
-
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
 
-  DrawBackground(pGraphics, pTheme, &matrix);
-  DrawHeadBK(pGraphics, pTheme, &matrix);
-  DrawLButton(pGraphics, pTheme, &matrix);
-  DrawRButton(pGraphics, pTheme, &matrix);
-  DrawSeparator(pGraphics, pTheme, &matrix);
-  DrawDatesInBK(pGraphics, pTheme, &matrix);
-  DrawDatesInCircle(pGraphics, pTheme, &matrix);
-  DrawCaption(pGraphics, pTheme, &matrix);
-  DrawWeek(pGraphics, pTheme, &matrix);
-  DrawDatesIn(pGraphics, pTheme, &matrix);
-  DrawDatesOut(pGraphics, pTheme, &matrix);
-  DrawToday(pGraphics, pTheme, &matrix);
+  DrawBackground(pGraphics, &matrix);
+  DrawHeadBK(pGraphics, &matrix);
+  DrawLButton(pGraphics, &matrix);
+  DrawRButton(pGraphics, &matrix);
+  DrawSeparator(pGraphics, &matrix);
+  DrawDatesInBK(pGraphics, &matrix);
+  DrawDatesInCircle(pGraphics, &matrix);
+  DrawCaption(pGraphics, &matrix);
+  DrawWeek(pGraphics, &matrix);
+  DrawDatesIn(pGraphics, &matrix);
+  DrawDatesOut(pGraphics, &matrix);
+  DrawToday(pGraphics, &matrix);
 }
 
 void CFWL_MonthCalendar::SetSelect(int32_t iYear,
@@ -155,7 +147,6 @@
 }
 
 void CFWL_MonthCalendar::DrawBackground(CXFA_Graphics* pGraphics,
-                                        IFWL_ThemeProvider* pTheme,
                                         const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground params;
   params.m_pWidget = this;
@@ -165,11 +156,10 @@
   params.m_PartRect = m_ClientRect;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(params);
+  GetThemeProvider()->DrawBackground(params);
 }
 
 void CFWL_MonthCalendar::DrawHeadBK(CXFA_Graphics* pGraphics,
-                                    IFWL_ThemeProvider* pTheme,
                                     const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground params;
   params.m_pWidget = this;
@@ -179,11 +169,10 @@
   params.m_PartRect = m_HeadRect;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(params);
+  GetThemeProvider()->DrawBackground(params);
 }
 
 void CFWL_MonthCalendar::DrawLButton(CXFA_Graphics* pGraphics,
-                                     IFWL_ThemeProvider* pTheme,
                                      const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground params;
   params.m_pWidget = this;
@@ -193,11 +182,10 @@
   params.m_PartRect = m_LBtnRect;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(params);
+  GetThemeProvider()->DrawBackground(params);
 }
 
 void CFWL_MonthCalendar::DrawRButton(CXFA_Graphics* pGraphics,
-                                     IFWL_ThemeProvider* pTheme,
                                      const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground params;
   params.m_pWidget = this;
@@ -207,11 +195,10 @@
   params.m_PartRect = m_RBtnRect;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(params);
+  GetThemeProvider()->DrawBackground(params);
 }
 
 void CFWL_MonthCalendar::DrawCaption(CXFA_Graphics* pGraphics,
-                                     IFWL_ThemeProvider* pTheme,
                                      const CFX_Matrix* pMatrix) {
   CFWL_ThemeText textParam;
   textParam.m_pWidget = this;
@@ -219,19 +206,17 @@
   textParam.m_dwStates = CFWL_PartState_Normal;
   textParam.m_pGraphics = pGraphics;
   textParam.m_wsText = GetHeadText(m_iCurYear, m_iCurMonth);
-  m_HeadSize = CalcTextSize(textParam.m_wsText,
-                            GetProperties()->m_pThemeProvider.Get(), false);
+  m_HeadSize = CalcTextSize(textParam.m_wsText, false);
   CalcHeadSize();
   textParam.m_PartRect = m_HeadTextRect;
   textParam.m_dwTTOStyles.single_line_ = true;
   textParam.m_iTTOAlign = FDE_TextAlignment::kCenter;
   if (pMatrix)
     textParam.m_matrix.Concat(*pMatrix);
-  pTheme->DrawText(textParam);
+  GetThemeProvider()->DrawText(textParam);
 }
 
 void CFWL_MonthCalendar::DrawSeparator(CXFA_Graphics* pGraphics,
-                                       IFWL_ThemeProvider* pTheme,
                                        const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground params;
   params.m_pWidget = this;
@@ -241,11 +226,10 @@
   params.m_PartRect = m_HSepRect;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(params);
+  GetThemeProvider()->DrawBackground(params);
 }
 
 void CFWL_MonthCalendar::DrawDatesInBK(CXFA_Graphics* pGraphics,
-                                       IFWL_ThemeProvider* pTheme,
                                        const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground params;
   params.m_pWidget = this;
@@ -254,6 +238,7 @@
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
 
+  IFWL_ThemeProvider* pTheme = GetThemeProvider();
   int32_t iCount = pdfium::CollectionSize<int32_t>(m_DateArray);
   for (int32_t j = 0; j < iCount; j++) {
     DATEINFO* pDataInfo = m_DateArray[j].get();
@@ -275,7 +260,6 @@
 }
 
 void CFWL_MonthCalendar::DrawWeek(CXFA_Graphics* pGraphics,
-                                  IFWL_ThemeProvider* pTheme,
                                   const CFX_Matrix* pMatrix) {
   CFWL_ThemeText params;
   params.m_pWidget = this;
@@ -285,10 +269,11 @@
   params.m_iTTOAlign = FDE_TextAlignment::kCenter;
   params.m_dwTTOStyles.single_line_ = true;
 
-  CFX_RectF rtDayOfWeek;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
 
+  IFWL_ThemeProvider* pTheme = GetThemeProvider();
+  CFX_RectF rtDayOfWeek;
   for (int32_t i = 0; i < 7; ++i) {
     rtDayOfWeek = CFX_RectF(
         m_WeekRect.left + i * (m_CellSize.width + MONTHCAL_HMARGIN * 2),
@@ -301,7 +286,6 @@
 }
 
 void CFWL_MonthCalendar::DrawToday(CXFA_Graphics* pGraphics,
-                                   IFWL_ThemeProvider* pTheme,
                                    const CFX_Matrix* pMatrix) {
   CFWL_ThemeText params;
   params.m_pWidget = this;
@@ -310,20 +294,16 @@
   params.m_dwStates = CFWL_PartState_Normal;
   params.m_iTTOAlign = FDE_TextAlignment::kCenterLeft;
   params.m_wsText = GetTodayText(m_iYear, m_iMonth, m_iDay);
-
-  m_TodaySize = CalcTextSize(params.m_wsText,
-                             GetProperties()->m_pThemeProvider.Get(), false);
+  m_TodaySize = CalcTextSize(params.m_wsText, false);
   CalcTodaySize();
   params.m_PartRect = m_TodayRect;
   params.m_dwTTOStyles.single_line_ = true;
-
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawText(params);
+  GetThemeProvider()->DrawText(params);
 }
 
 void CFWL_MonthCalendar::DrawDatesIn(CXFA_Graphics* pGraphics,
-                                     IFWL_ThemeProvider* pTheme,
                                      const CFX_Matrix* pMatrix) {
   CFWL_ThemeText params;
   params.m_pWidget = this;
@@ -334,6 +314,7 @@
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
 
+  IFWL_ThemeProvider* pTheme = GetThemeProvider();
   int32_t iCount = pdfium::CollectionSize<int32_t>(m_DateArray);
   for (int32_t j = 0; j < iCount; j++) {
     DATEINFO* pDataInfo = m_DateArray[j].get();
@@ -349,7 +330,6 @@
 }
 
 void CFWL_MonthCalendar::DrawDatesOut(CXFA_Graphics* pGraphics,
-                                      IFWL_ThemeProvider* pTheme,
                                       const CFX_Matrix* pMatrix) {
   CFWL_ThemeText params;
   params.m_pWidget = this;
@@ -359,11 +339,10 @@
   params.m_iTTOAlign = FDE_TextAlignment::kCenter;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawText(params);
+  GetThemeProvider()->DrawText(params);
 }
 
 void CFWL_MonthCalendar::DrawDatesInCircle(CXFA_Graphics* pGraphics,
-                                           IFWL_ThemeProvider* pTheme,
                                            const CFX_Matrix* pMatrix) {
   if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear)
     return;
@@ -383,26 +362,21 @@
   params.m_dwStates = CFWL_PartState_Normal;
   if (pMatrix)
     params.m_matrix.Concat(*pMatrix);
-  pTheme->DrawBackground(params);
+  GetThemeProvider()->DrawBackground(params);
 }
 
 CFX_SizeF CFWL_MonthCalendar::CalcSize() {
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
-  if (!pTheme)
-    return CFX_SizeF();
-
   float fMaxWeekW = 0.0f;
   float fMaxWeekH = 0.0f;
   for (int i = 0; i < 7; ++i) {
-    CFX_SizeF sz = CalcTextSize(GetAbbreviatedDayOfWeek(i), pTheme, false);
+    CFX_SizeF sz = CalcTextSize(GetAbbreviatedDayOfWeek(i), false);
     fMaxWeekW = (fMaxWeekW >= sz.width) ? fMaxWeekW : sz.width;
     fMaxWeekH = (fMaxWeekH >= sz.height) ? fMaxWeekH : sz.height;
   }
-
   float fDayMaxW = 0.0f;
   float fDayMaxH = 0.0f;
   for (int day = 10; day <= 31; day++) {
-    CFX_SizeF sz = CalcTextSize(WideString::Format(L"%d", day), pTheme, false);
+    CFX_SizeF sz = CalcTextSize(WideString::Format(L"%d", day), false);
     fDayMaxW = (fDayMaxW >= sz.width) ? fDayMaxW : sz.width;
     fDayMaxH = (fDayMaxH >= sz.height) ? fDayMaxH : sz.height;
   }
@@ -418,13 +392,12 @@
   float fMonthMaxW = 0.0f;
   float fMonthMaxH = 0.0f;
   for (int i = 0; i < 12; ++i) {
-    CFX_SizeF sz = CalcTextSize(GetMonth(i), pTheme, false);
+    CFX_SizeF sz = CalcTextSize(GetMonth(i), false);
     fMonthMaxW = (fMonthMaxW >= sz.width) ? fMonthMaxW : sz.width;
     fMonthMaxH = (fMonthMaxH >= sz.height) ? fMonthMaxH : sz.height;
   }
 
-  CFX_SizeF szYear =
-      CalcTextSize(GetHeadText(m_iYear, m_iMonth), pTheme, false);
+  CFX_SizeF szYear = CalcTextSize(GetHeadText(m_iYear, m_iMonth), false);
   fMonthMaxH = std::max(fMonthMaxH, szYear.height);
   m_HeadSize = CFX_SizeF(fMonthMaxW + szYear.width, fMonthMaxH);
   fMonthMaxW =
@@ -432,7 +405,7 @@
   fs.width = std::max(fs.width, fMonthMaxW);
 
   m_wsToday = GetTodayText(m_iYear, m_iMonth, m_iDay);
-  m_TodaySize = CalcTextSize(m_wsToday, pTheme, false);
+  m_TodaySize = CalcTextSize(m_wsToday, false);
   m_TodaySize.height = (m_TodaySize.height >= m_CellSize.height)
                            ? m_TodaySize.height
                            : m_CellSize.height;
@@ -516,11 +489,6 @@
   }
 }
 
-void CFWL_MonthCalendar::GetCapValue() {
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
-}
-
 void CFWL_MonthCalendar::InitDate() {
   CFX_DateTime now = CFX_DateTime::Now();
 
diff --git a/xfa/fwl/cfwl_monthcalendar.h b/xfa/fwl/cfwl_monthcalendar.h
index 2972cf7..f57b443 100644
--- a/xfa/fwl/cfwl_monthcalendar.h
+++ b/xfa/fwl/cfwl_monthcalendar.h
@@ -89,47 +89,34 @@
   };
 
   void DrawBackground(CXFA_Graphics* pGraphics,
-                      IFWL_ThemeProvider* pTheme,
                       const CFX_Matrix* pMatrix);
   void DrawHeadBK(CXFA_Graphics* pGraphics,
-                  IFWL_ThemeProvider* pTheme,
                   const CFX_Matrix* pMatrix);
   void DrawLButton(CXFA_Graphics* pGraphics,
-                   IFWL_ThemeProvider* pTheme,
                    const CFX_Matrix* pMatrix);
   void DrawRButton(CXFA_Graphics* pGraphics,
-                   IFWL_ThemeProvider* pTheme,
                    const CFX_Matrix* pMatrix);
   void DrawCaption(CXFA_Graphics* pGraphics,
-                   IFWL_ThemeProvider* pTheme,
                    const CFX_Matrix* pMatrix);
   void DrawSeparator(CXFA_Graphics* pGraphics,
-                     IFWL_ThemeProvider* pTheme,
                      const CFX_Matrix* pMatrix);
   void DrawDatesInBK(CXFA_Graphics* pGraphics,
-                     IFWL_ThemeProvider* pTheme,
                      const CFX_Matrix* pMatrix);
   void DrawWeek(CXFA_Graphics* pGraphics,
-                IFWL_ThemeProvider* pTheme,
                 const CFX_Matrix* pMatrix);
   void DrawToday(CXFA_Graphics* pGraphics,
-                 IFWL_ThemeProvider* pTheme,
                  const CFX_Matrix* pMatrix);
   void DrawDatesIn(CXFA_Graphics* pGraphics,
-                   IFWL_ThemeProvider* pTheme,
                    const CFX_Matrix* pMatrix);
   void DrawDatesOut(CXFA_Graphics* pGraphics,
-                    IFWL_ThemeProvider* pTheme,
                     const CFX_Matrix* pMatrix);
   void DrawDatesInCircle(CXFA_Graphics* pGraphics,
-                         IFWL_ThemeProvider* pTheme,
                          const CFX_Matrix* pMatrix);
   CFX_SizeF CalcSize();
   void Layout();
   void CalcHeadSize();
   void CalcTodaySize();
   void CalDateItem();
-  void GetCapValue();
   void InitDate();
   void ClearDateItem();
   void ResetDateItem();
diff --git a/xfa/fwl/cfwl_picturebox.cpp b/xfa/fwl/cfwl_picturebox.cpp
index 6746042..c1254a1 100644
--- a/xfa/fwl/cfwl_picturebox.cpp
+++ b/xfa/fwl/cfwl_picturebox.cpp
@@ -20,8 +20,6 @@
 void CFWL_PictureBox::Update() {
   if (IsLocked())
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
 
   m_ClientRect = GetClientRect();
 }
@@ -30,12 +28,9 @@
                                  const CFX_Matrix& matrix) {
   if (!pGraphics)
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    return;
 
-  IFWL_ThemeProvider* pTheme = GetAvailableTheme();
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
 }
 
 void CFWL_PictureBox::OnDrawWidget(CXFA_Graphics* pGraphics,
diff --git a/xfa/fwl/cfwl_pushbutton.cpp b/xfa/fwl/cfwl_pushbutton.cpp
index 2e5c962..e78e6d8 100644
--- a/xfa/fwl/cfwl_pushbutton.cpp
+++ b/xfa/fwl/cfwl_pushbutton.cpp
@@ -40,8 +40,6 @@
 void CFWL_PushButton::Update() {
   if (IsLocked())
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
 
   m_ClientRect = GetClientRect();
   m_CaptionRect = m_ClientRect;
@@ -52,17 +50,13 @@
   if (!pGraphics)
     return;
 
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
-  if (!pTheme)
-    return;
-
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
-  DrawBkground(pGraphics, pTheme, &matrix);
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
+
+  DrawBkground(pGraphics, &matrix);
 }
 
 void CFWL_PushButton::DrawBkground(CXFA_Graphics* pGraphics,
-                                   IFWL_ThemeProvider* pTheme,
                                    const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
@@ -74,7 +68,7 @@
   param.m_PartRect = m_ClientRect;
   if (GetProperties()->m_dwStates & FWL_WGTSTATE_Focused)
     param.m_pRtData = &m_CaptionRect;
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 uint32_t CFWL_PushButton::GetPartStates() {
diff --git a/xfa/fwl/cfwl_pushbutton.h b/xfa/fwl/cfwl_pushbutton.h
index 659217a..67403a6 100644
--- a/xfa/fwl/cfwl_pushbutton.h
+++ b/xfa/fwl/cfwl_pushbutton.h
@@ -33,7 +33,6 @@
 
  private:
   void DrawBkground(CXFA_Graphics* pGraphics,
-                    IFWL_ThemeProvider* pTheme,
                     const CFX_Matrix* pMatrix);
   uint32_t GetPartStates();
   void UpdateTextOutStyles();
diff --git a/xfa/fwl/cfwl_scrollbar.cpp b/xfa/fwl/cfwl_scrollbar.cpp
index b550596..9b6aade 100644
--- a/xfa/fwl/cfwl_scrollbar.cpp
+++ b/xfa/fwl/cfwl_scrollbar.cpp
@@ -42,8 +42,6 @@
 void CFWL_ScrollBar::Update() {
   if (IsLocked())
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    GetProperties()->m_pThemeProvider = GetAvailableTheme();
 
   Layout();
 }
@@ -52,17 +50,15 @@
                                 const CFX_Matrix& matrix) {
   if (!pGraphics)
     return;
-  if (!GetProperties()->m_pThemeProvider)
-    return;
 
-  IFWL_ThemeProvider* pTheme = GetProperties()->m_pThemeProvider.Get();
   if (HasBorder())
-    DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
-  DrawTrack(pGraphics, pTheme, true, &matrix);
-  DrawTrack(pGraphics, pTheme, false, &matrix);
-  DrawArrowBtn(pGraphics, pTheme, true, &matrix);
-  DrawArrowBtn(pGraphics, pTheme, false, &matrix);
-  DrawThumb(pGraphics, pTheme, &matrix);
+    DrawBorder(pGraphics, CFWL_Part::Border, matrix);
+
+  DrawTrack(pGraphics, true, &matrix);
+  DrawTrack(pGraphics, false, &matrix);
+  DrawArrowBtn(pGraphics, true, &matrix);
+  DrawArrowBtn(pGraphics, false, &matrix);
+  DrawThumb(pGraphics, &matrix);
 }
 
 void CFWL_ScrollBar::SetTrackPos(float fTrackPos) {
@@ -79,7 +75,6 @@
 }
 
 void CFWL_ScrollBar::DrawTrack(CXFA_Graphics* pGraphics,
-                               IFWL_ThemeProvider* pTheme,
                                bool bLower,
                                const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground param;
@@ -91,11 +86,10 @@
   param.m_pGraphics = pGraphics;
   param.m_matrix.Concat(*pMatrix);
   param.m_PartRect = bLower ? m_MinTrackRect : m_MaxTrackRect;
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_ScrollBar::DrawArrowBtn(CXFA_Graphics* pGraphics,
-                                  IFWL_ThemeProvider* pTheme,
                                   bool bMinBtn,
                                   const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground param;
@@ -108,11 +102,10 @@
   param.m_matrix.Concat(*pMatrix);
   param.m_PartRect = bMinBtn ? m_MinBtnRect : m_MaxBtnRect;
   if (param.m_PartRect.height > 0 && param.m_PartRect.width > 0)
-    pTheme->DrawBackground(param);
+    GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_ScrollBar::DrawThumb(CXFA_Graphics* pGraphics,
-                               IFWL_ThemeProvider* pTheme,
                                const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
@@ -123,7 +116,7 @@
   param.m_pGraphics = pGraphics;
   param.m_matrix.Concat(*pMatrix);
   param.m_PartRect = m_ThumbRect;
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_ScrollBar::Layout() {
diff --git a/xfa/fwl/cfwl_scrollbar.h b/xfa/fwl/cfwl_scrollbar.h
index 72368cd..83899b0 100644
--- a/xfa/fwl/cfwl_scrollbar.h
+++ b/xfa/fwl/cfwl_scrollbar.h
@@ -63,16 +63,12 @@
     return !!(GetProperties()->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert);
   }
   void DrawTrack(CXFA_Graphics* pGraphics,
-                 IFWL_ThemeProvider* pTheme,
                  bool bLower,
                  const CFX_Matrix* pMatrix);
   void DrawArrowBtn(CXFA_Graphics* pGraphics,
-                    IFWL_ThemeProvider* pTheme,
                     bool bMinBtn,
                     const CFX_Matrix* pMatrix);
-  void DrawThumb(CXFA_Graphics* pGraphics,
-                 IFWL_ThemeProvider* pTheme,
-                 const CFX_Matrix* pMatrix);
+  void DrawThumb(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix);
   void Layout();
   void CalcButtonLen();
   CFX_RectF CalcMinButtonRect();
diff --git a/xfa/fwl/cfwl_widget.cpp b/xfa/fwl/cfwl_widget.cpp
index 6733f19..9a634eb 100644
--- a/xfa/fwl/cfwl_widget.cpp
+++ b/xfa/fwl/cfwl_widget.cpp
@@ -167,8 +167,8 @@
   return matrix;
 }
 
-void CFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
-  m_pProperties->m_pThemeProvider = pThemeProvider;
+IFWL_ThemeProvider* CFWL_Widget::GetThemeProvider() const {
+  return m_pOwnerApp->GetAdapterNative()->GetThemeProvider();
 }
 
 bool CFWL_Widget::IsEnabled() const {
@@ -212,13 +212,11 @@
 }
 
 float CFWL_Widget::GetCXBorderSize() const {
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  return theme ? theme->GetCXBorderSize() : 0.0f;
+  return GetThemeProvider()->GetCXBorderSize();
 }
 
 float CFWL_Widget::GetCYBorderSize() const {
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  return theme ? theme->GetCYBorderSize() : 0.0f;
+  return GetThemeProvider()->GetCYBorderSize();
 }
 
 CFX_RectF CFWL_Widget::GetRelativeRect() const {
@@ -226,29 +224,8 @@
                    m_pProperties->m_WidgetRect.height);
 }
 
-IFWL_ThemeProvider* CFWL_Widget::GetAvailableTheme() const {
-  if (m_pProperties->m_pThemeProvider)
-    return m_pProperties->m_pThemeProvider.Get();
-
-  const CFWL_Widget* pUp = this;
-  do {
-    pUp = pUp->IsPopup() ? m_pWidgetMgr->GetOwnerWidget(pUp)
-                         : m_pWidgetMgr->GetParentWidget(pUp);
-    if (pUp) {
-      IFWL_ThemeProvider* pRet = pUp->GetThemeProvider();
-      if (pRet)
-        return pRet;
-    }
-  } while (pUp);
-  return nullptr;
-}
-
 CFX_SizeF CFWL_Widget::CalcTextSize(const WideString& wsText,
-                                    IFWL_ThemeProvider* pTheme,
                                     bool bMultiLine) {
-  if (!pTheme)
-    return CFX_SizeF();
-
   CFWL_ThemeText calPart;
   calPart.m_pWidget = this;
   calPart.m_wsText = wsText;
@@ -260,12 +237,11 @@
   calPart.m_iTTOAlign = FDE_TextAlignment::kTopLeft;
   float fWidth = bMultiLine ? FWL_WGT_CalcMultiLineDefWidth : FWL_WGT_CalcWidth;
   CFX_RectF rect(0, 0, fWidth, FWL_WGT_CalcHeight);
-  pTheme->CalcTextRect(calPart, &rect);
+  GetThemeProvider()->CalcTextRect(calPart, &rect);
   return CFX_SizeF(rect.width, rect.height);
 }
 
 void CFWL_Widget::CalcTextRect(const WideString& wsText,
-                               IFWL_ThemeProvider* pTheme,
                                const FDE_TextStyle& dwTTOStyles,
                                FDE_TextAlignment iTTOAlign,
                                CFX_RectF* pRect) {
@@ -274,7 +250,7 @@
   calPart.m_wsText = wsText;
   calPart.m_dwTTOStyles = dwTTOStyles;
   calPart.m_iTTOAlign = iTTOAlign;
-  pTheme->CalcTextRect(calPart, pRect);
+  GetThemeProvider()->CalcTextRect(calPart, pRect);
 }
 
 void CFWL_Widget::SetGrab(bool bSet) {
@@ -307,7 +283,6 @@
 
 void CFWL_Widget::DrawBackground(CXFA_Graphics* pGraphics,
                                  CFWL_Part iPartBk,
-                                 IFWL_ThemeProvider* pTheme,
                                  const CFX_Matrix* pMatrix) {
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
@@ -316,12 +291,11 @@
   if (pMatrix)
     param.m_matrix = *pMatrix;
   param.m_PartRect = GetRelativeRect();
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_Widget::DrawBorder(CXFA_Graphics* pGraphics,
                              CFWL_Part iPartBorder,
-                             IFWL_ThemeProvider* pTheme,
                              const CFX_Matrix& matrix) {
   CFWL_ThemeBackground param;
   param.m_pWidget = this;
@@ -329,7 +303,7 @@
   param.m_pGraphics = pGraphics;
   param.m_matrix = matrix;
   param.m_PartRect = GetRelativeRect();
-  pTheme->DrawBackground(param);
+  GetThemeProvider()->DrawBackground(param);
 }
 
 void CFWL_Widget::NotifyDriver() {
diff --git a/xfa/fwl/cfwl_widget.h b/xfa/fwl/cfwl_widget.h
index 2a790de..054c7b1 100644
--- a/xfa/fwl/cfwl_widget.h
+++ b/xfa/fwl/cfwl_widget.h
@@ -83,9 +83,8 @@
   virtual FWL_WidgetHit HitTest(const CFX_PointF& point);
   virtual void DrawWidget(CXFA_Graphics* pGraphics,
                           const CFX_Matrix& matrix) = 0;
-  virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider);
 
-  // IFWL_WidgetDelegate.
+  // IFWL_WidgetDelegate:
   void OnProcessMessage(CFWL_Message* pMessage) override;
   void OnProcessEvent(CFWL_Event* pEvent) override;
   void OnDrawWidget(CXFA_Graphics* pGraphics,
@@ -110,10 +109,7 @@
 
   CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point);
   CFX_Matrix GetMatrix() const;
-  IFWL_ThemeProvider* GetThemeProvider() const {
-    return m_pProperties->m_pThemeProvider.Get();
-  }
-
+  IFWL_ThemeProvider* GetThemeProvider() const;
   void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; }
   IFWL_WidgetDelegate* GetDelegate() {
     return m_pDelegate ? m_pDelegate.Get() : this;
@@ -142,16 +138,13 @@
   float GetCXBorderSize() const;
   float GetCYBorderSize() const;
   CFX_RectF GetRelativeRect() const;
-  IFWL_ThemeProvider* GetAvailableTheme() const;
   CFWL_WidgetProperties* GetProperties() { return m_pProperties.get(); }
   const CFWL_WidgetProperties* GetProperties() const {
     return m_pProperties.get();
   }
   CFX_SizeF CalcTextSize(const WideString& wsText,
-                         IFWL_ThemeProvider* pTheme,
                          bool bMultiLine);
   void CalcTextRect(const WideString& wsText,
-                    IFWL_ThemeProvider* pTheme,
                     const FDE_TextStyle& dwTTOStyles,
                     FDE_TextAlignment iTTOAlign,
                     CFX_RectF* pRect);
@@ -161,7 +154,6 @@
   void DispatchEvent(CFWL_Event* pEvent);
   void DrawBorder(CXFA_Graphics* pGraphics,
                   CFWL_Part iPartBorder,
-                  IFWL_ThemeProvider* pTheme,
                   const CFX_Matrix& pMatrix);
 
  private:
@@ -175,7 +167,6 @@
   CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent);
   void DrawBackground(CXFA_Graphics* pGraphics,
                       CFWL_Part iPartBk,
-                      IFWL_ThemeProvider* pTheme,
                       const CFX_Matrix* pMatrix);
   void NotifyDriver();
   bool IsParent(CFWL_Widget* pParent);
diff --git a/xfa/fwl/cfwl_widgetproperties.h b/xfa/fwl/cfwl_widgetproperties.h
index b9432cd..6733306 100644
--- a/xfa/fwl/cfwl_widgetproperties.h
+++ b/xfa/fwl/cfwl_widgetproperties.h
@@ -9,11 +9,8 @@
 
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/unowned_ptr.h"
 #include "xfa/fwl/fwl_widgetdef.h"
 
-class IFWL_ThemeProvider;
-
 class CFWL_WidgetProperties {
  public:
   CFWL_WidgetProperties();
@@ -23,7 +20,6 @@
   uint32_t m_dwStyleExes = 0;
   uint32_t m_dwStates = 0;
   CFX_RectF m_WidgetRect;
-  UnownedPtr<IFWL_ThemeProvider> m_pThemeProvider;
 };
 
 #endif  // XFA_FWL_CFWL_WIDGETPROPERTIES_H_
diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp
index d6f06a4..3686402 100644
--- a/xfa/fxfa/cxfa_ffapp.cpp
+++ b/xfa/fxfa/cxfa_ffapp.cpp
@@ -48,13 +48,13 @@
   return m_pFDEFontMgr.get();
 }
 
-CXFA_FWLTheme* CXFA_FFApp::GetFWLTheme(CXFA_FFDoc* doc) {
-  if (!m_pFWLTheme) {
-    auto fwl_theme = std::make_unique<CXFA_FWLTheme>(this);
-    if (fwl_theme->LoadCalendarFont(doc))
-      m_pFWLTheme = std::move(fwl_theme);
-  }
-  return m_pFWLTheme.get();
+bool CXFA_FFApp::LoadFWLTheme(CXFA_FFDoc* doc) {
+  auto fwl_theme = std::make_unique<CXFA_FWLTheme>(this);
+  if (!fwl_theme->LoadCalendarFont(doc))
+    return false;
+
+  m_pFWLTheme = std::move(fwl_theme);
+  return true;
 }
 
 CFWL_WidgetMgr::AdapterIface* CXFA_FFApp::GetWidgetMgrAdapter() {
@@ -66,3 +66,7 @@
 TimerHandlerIface* CXFA_FFApp::GetTimerHandler() {
   return m_pProvider->GetTimerHandler();
 }
+
+IFWL_ThemeProvider* CXFA_FFApp::GetThemeProvider() {
+  return m_pFWLTheme.get();
+}
diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h
index e3bac30..2c513fd 100644
--- a/xfa/fxfa/cxfa_ffapp.h
+++ b/xfa/fxfa/cxfa_ffapp.h
@@ -29,10 +29,11 @@
   // CFWL_App::AdapterIface:
   CFWL_WidgetMgr::AdapterIface* GetWidgetMgrAdapter() override;
   TimerHandlerIface* GetTimerHandler() override;
+  IFWL_ThemeProvider* GetThemeProvider() override;
 
+  bool LoadFWLTheme(CXFA_FFDoc* doc);
   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(); }
diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp
index f4cd6dc..046f401 100644
--- a/xfa/fxfa/cxfa_fffield.cpp
+++ b/xfa/fxfa/cxfa_fffield.cpp
@@ -124,11 +124,6 @@
   pGS->StrokePath(&path, pMatrix);
 }
 
-void CXFA_FFField::SetFWLThemeProvider() {
-  if (GetNormalWidget())
-    GetNormalWidget()->SetThemeProvider(GetApp()->GetFWLTheme(GetDoc()));
-}
-
 CFWL_Widget* CXFA_FFField::GetNormalWidget() {
   return m_pNormalWidget.get();
 }
@@ -148,8 +143,6 @@
 bool CXFA_FFField::LoadWidget() {
   // Prevents destruction of the CXFA_ContentLayoutItem that owns |this|.
   RetainPtr<CXFA_ContentLayoutItem> retain_layout(m_pLayoutItem.Get());
-
-  SetFWLThemeProvider();
   m_pNode->LoadCaption(GetDoc());
   PerformLayout();
   return true;
diff --git a/xfa/fxfa/cxfa_fffield.h b/xfa/fxfa/cxfa_fffield.h
index dbfd2ac..565df66 100644
--- a/xfa/fxfa/cxfa_fffield.h
+++ b/xfa/fxfa/cxfa_fffield.h
@@ -73,7 +73,6 @@
   bool PtInActiveRect(const CFX_PointF& point) override;
 
   virtual void SetFWLRect();
-  void SetFWLThemeProvider();
   CFWL_Widget* GetNormalWidget();
   const CFWL_Widget* GetNormalWidget() const;
   void SetNormalWidget(std::unique_ptr<CFWL_Widget> widget);