Consolidate CFLW_PartState to FWLTHEME_STATE conversions

This is currently being done in three different ways in three
different places in xfa/fwl. All of them appear wrong because
either:

-- PartState is a bitmap so switching on it is wrong.
-- &ing it with 0x03 doesn't select the bits we want to test.
-- &ing it against a different type is not meaningful.
-- Not all of the possibilities are covered sometimes.

Add a method GetThemeStates() that tests each bit in order of
some natural "priority".

-- Inline DrawDropDownButton() methods into only callers.

Change-Id: Iaef63405ed061212aff371dca0fe76001aec6a10
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83591
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/cfwl_themepart.cpp b/xfa/fwl/cfwl_themepart.cpp
index f7d5974..69bdb37 100644
--- a/xfa/fwl/cfwl_themepart.cpp
+++ b/xfa/fwl/cfwl_themepart.cpp
@@ -9,3 +9,13 @@
 CFWL_ThemePart::CFWL_ThemePart(CFWL_Widget* pWidget) : m_pWidget(pWidget) {}
 
 CFWL_ThemePart::~CFWL_ThemePart() = default;
+
+FWLTHEME_STATE CFWL_ThemePart::GetThemeState() const {
+  if (m_dwStates & CFWL_PartState_Disabled)
+    return FWLTHEME_STATE::kDisable;
+  if (m_dwStates & CFWL_PartState_Pressed)
+    return FWLTHEME_STATE::kPressed;
+  if (m_dwStates & CFWL_PartState_Hovered)
+    return FWLTHEME_STATE::kHover;
+  return FWLTHEME_STATE::kNormal;
+}
diff --git a/xfa/fwl/cfwl_themepart.h b/xfa/fwl/cfwl_themepart.h
index 77b9bc5..fc1d1a6 100644
--- a/xfa/fwl/cfwl_themepart.h
+++ b/xfa/fwl/cfwl_themepart.h
@@ -13,6 +13,7 @@
 
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/unowned_ptr.h"
+#include "xfa/fwl/theme/cfwl_utils.h"
 
 class CFWL_Widget;
 
@@ -87,6 +88,7 @@
   ~CFWL_ThemePart();
 
   CFWL_Widget* GetWidget() const { return m_pWidget.Get(); }
+  FWLTHEME_STATE GetThemeState() const;
 
   CFX_Matrix m_matrix;
   CFX_RectF m_PartRect;
diff --git a/xfa/fwl/theme/cfwl_comboboxtp.cpp b/xfa/fwl/theme/cfwl_comboboxtp.cpp
index 0d5695f..969ccc3 100644
--- a/xfa/fwl/theme/cfwl_comboboxtp.cpp
+++ b/xfa/fwl/theme/cfwl_comboboxtp.cpp
@@ -46,35 +46,12 @@
       break;
     }
     case CFWL_ThemePart::Part::kDropDownButton: {
-      DrawDropDownButton(pParams, pParams.m_dwStates, pParams.m_matrix);
+      DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
+                   FWLTHEME_DIRECTION::kDown, pParams.GetThemeState(),
+                   pParams.m_matrix);
       break;
     }
     default:
       break;
   }
 }
-
-void CFWL_ComboBoxTP::DrawDropDownButton(const CFWL_ThemeBackground& pParams,
-                                         uint32_t dwStates,
-                                         const CFX_Matrix& matrix) {
-  FWLTHEME_STATE eState;
-  switch (dwStates) {
-    case CFWL_PartState_Normal:
-      eState = FWLTHEME_STATE::kNormal;
-      break;
-    case CFWL_PartState_Hovered:
-      eState = FWLTHEME_STATE::kHover;
-      break;
-    case CFWL_PartState_Pressed:
-      eState = FWLTHEME_STATE::kPressed;
-      break;
-    case CFWL_PartState_Disabled:
-      eState = FWLTHEME_STATE::kDisable;
-      break;
-    default:
-      eState = FWLTHEME_STATE::kNormal;
-      break;
-  }
-  DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
-               FWLTHEME_DIRECTION::kDown, eState, pParams.m_matrix);
-}
diff --git a/xfa/fwl/theme/cfwl_comboboxtp.h b/xfa/fwl/theme/cfwl_comboboxtp.h
index 501f67a..f218064 100644
--- a/xfa/fwl/theme/cfwl_comboboxtp.h
+++ b/xfa/fwl/theme/cfwl_comboboxtp.h
@@ -20,10 +20,6 @@
 
  private:
   CFWL_ComboBoxTP();
-
-  void DrawDropDownButton(const CFWL_ThemeBackground& pParams,
-                          uint32_t dwStates,
-                          const CFX_Matrix& matrix);
 };
 
 #endif  // XFA_FWL_THEME_CFWL_COMBOBOXTP_H_
diff --git a/xfa/fwl/theme/cfwl_datetimepickertp.cpp b/xfa/fwl/theme/cfwl_datetimepickertp.cpp
index c332b1b..24df85b 100644
--- a/xfa/fwl/theme/cfwl_datetimepickertp.cpp
+++ b/xfa/fwl/theme/cfwl_datetimepickertp.cpp
@@ -20,37 +20,11 @@
       DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
       break;
     case CFWL_ThemePart::Part::kDropDownButton:
-      DrawDropDownButton(pParams, pParams.m_matrix);
+      DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
+                   FWLTHEME_DIRECTION::kDown, pParams.GetThemeState(),
+                   pParams.m_matrix);
       break;
     default:
       break;
   }
 }
-
-void CFWL_DateTimePickerTP::DrawDropDownButton(
-    const CFWL_ThemeBackground& pParams,
-    const CFX_Matrix& matrix) {
-  uint32_t dwStates = pParams.m_dwStates;
-  dwStates &= 0x03;
-  FWLTHEME_STATE eState = FWLTHEME_STATE::kNormal;
-
-  // TODO(tsepez): enum mismatch, &ing with 1 makes no sense here.
-  switch (static_cast<uint32_t>(eState) & dwStates) {
-    case CFWL_PartState_Normal:
-      eState = FWLTHEME_STATE::kNormal;
-      break;
-    case CFWL_PartState_Hovered:
-      eState = FWLTHEME_STATE::kHover;
-      break;
-    case CFWL_PartState_Pressed:
-      eState = FWLTHEME_STATE::kPressed;
-      break;
-    case CFWL_PartState_Disabled:
-      eState = FWLTHEME_STATE::kDisable;
-      break;
-    default:
-      break;
-  }
-  DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
-               FWLTHEME_DIRECTION::kDown, eState, matrix);
-}
diff --git a/xfa/fwl/theme/cfwl_datetimepickertp.h b/xfa/fwl/theme/cfwl_datetimepickertp.h
index 951f784..c02c422 100644
--- a/xfa/fwl/theme/cfwl_datetimepickertp.h
+++ b/xfa/fwl/theme/cfwl_datetimepickertp.h
@@ -20,9 +20,6 @@
 
  private:
   CFWL_DateTimePickerTP();
-
-  void DrawDropDownButton(const CFWL_ThemeBackground& pParams,
-                          const CFX_Matrix& matrix);
 };
 
 #endif  // XFA_FWL_THEME_CFWL_DATETIMEPICKERTP_H_
diff --git a/xfa/fwl/theme/cfwl_monthcalendartp.cpp b/xfa/fwl/theme/cfwl_monthcalendartp.cpp
index 125119e..2f28c67 100644
--- a/xfa/fwl/theme/cfwl_monthcalendartp.cpp
+++ b/xfa/fwl/theme/cfwl_monthcalendartp.cpp
@@ -47,15 +47,15 @@
       break;
     }
     case CFWL_ThemePart::Part::kLBtn: {
-      FWLTHEME_STATE eState = GetState(pParams.m_dwStates);
       DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
-                   FWLTHEME_DIRECTION::kLeft, eState, pParams.m_matrix);
+                   FWLTHEME_DIRECTION::kLeft, pParams.GetThemeState(),
+                   pParams.m_matrix);
       break;
     }
     case CFWL_ThemePart::Part::kRBtn: {
-      FWLTHEME_STATE eState = GetState(pParams.m_dwStates);
       DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
-                   FWLTHEME_DIRECTION::kRight, eState, pParams.m_matrix);
+                   FWLTHEME_DIRECTION::kRight, pParams.GetThemeState(),
+                   pParams.m_matrix);
       break;
     }
     case CFWL_ThemePart::Part::kHSeparator: {
@@ -265,11 +265,3 @@
   pParams.GetGraphics()->StrokePath(path, matrix);
   pParams.GetGraphics()->RestoreGraphState();
 }
-
-FWLTHEME_STATE CFWL_MonthCalendarTP::GetState(uint32_t dwFWLStates) {
-  if (dwFWLStates & CFWL_PartState_Hovered)
-    return FWLTHEME_STATE::kHover;
-  if (dwFWLStates & CFWL_PartState_Pressed)
-    return FWLTHEME_STATE::kPressed;
-  return FWLTHEME_STATE::kNormal;
-}
diff --git a/xfa/fwl/theme/cfwl_monthcalendartp.h b/xfa/fwl/theme/cfwl_monthcalendartp.h
index 3cf68ba..15b3f6b 100644
--- a/xfa/fwl/theme/cfwl_monthcalendartp.h
+++ b/xfa/fwl/theme/cfwl_monthcalendartp.h
@@ -40,7 +40,6 @@
                       const CFX_Matrix& matrix);
   void DrawWeekNumSep(const CFWL_ThemeBackground& pParams,
                       const CFX_Matrix& matrix);
-  FWLTHEME_STATE GetState(uint32_t dwFWLStates);
 };
 
 #endif  // XFA_FWL_THEME_CFWL_MONTHCALENDARTP_H_
diff --git a/xfa/fwl/theme/cfwl_scrollbartp.cpp b/xfa/fwl/theme/cfwl_scrollbartp.cpp
index 7e4cfcd..562d1a0 100644
--- a/xfa/fwl/theme/cfwl_scrollbartp.cpp
+++ b/xfa/fwl/theme/cfwl_scrollbartp.cpp
@@ -22,43 +22,35 @@
 
 void CFWL_ScrollBarTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
   CFWL_Widget* pWidget = pParams.GetWidget();
-  FWLTHEME_STATE eState = FWLTHEME_STATE::kNormal;
-  if (pParams.m_dwStates & CFWL_PartState_Hovered)
-    eState = FWLTHEME_STATE::kHover;
-  else if (pParams.m_dwStates & CFWL_PartState_Pressed)
-    eState = FWLTHEME_STATE::kPressed;
-  else if (pParams.m_dwStates & CFWL_PartState_Disabled)
-    eState = FWLTHEME_STATE::kDisable;
-
   CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
   bool bVert = !!pWidget->GetStyleExts();
   switch (pParams.m_iPart) {
     case CFWL_ThemePart::Part::kForeArrow: {
       DrawMaxMinBtn(pGraphics, pParams.m_PartRect,
                     bVert ? FWLTHEME_DIRECTION::kUp : FWLTHEME_DIRECTION::kLeft,
-                    eState, pParams.m_matrix);
+                    pParams.GetThemeState(), pParams.m_matrix);
       break;
     }
     case CFWL_ThemePart::Part::kBackArrow: {
       DrawMaxMinBtn(
           pGraphics, pParams.m_PartRect,
           bVert ? FWLTHEME_DIRECTION::kDown : FWLTHEME_DIRECTION::kRight,
-          eState, pParams.m_matrix);
+          pParams.GetThemeState(), pParams.m_matrix);
       break;
     }
     case CFWL_ThemePart::Part::kThumb: {
-      DrawThumbBtn(pGraphics, pParams.m_PartRect, bVert, eState,
-                   pParams.m_matrix);
+      DrawThumbBtn(pGraphics, pParams.m_PartRect, bVert,
+                   pParams.GetThemeState(), pParams.m_matrix);
       break;
     }
     case CFWL_ThemePart::Part::kLowerTrack: {
-      DrawTrack(pGraphics, pParams.m_PartRect, bVert, eState, true,
-                pParams.m_matrix);
+      DrawTrack(pGraphics, pParams.m_PartRect, bVert, pParams.GetThemeState(),
+                true, pParams.m_matrix);
       break;
     }
     case CFWL_ThemePart::Part::kUpperTrack: {
-      DrawTrack(pGraphics, pParams.m_PartRect, bVert, eState, false,
-                pParams.m_matrix);
+      DrawTrack(pGraphics, pParams.m_PartRect, bVert, pParams.GetThemeState(),
+                false, pParams.m_matrix);
       break;
     }
     default: