Tidy CFGAS_GEGraphics::StateRestore() usage

Change-Id: I2e5861d34b499085d25fc44ed6b254ccf4f824ba
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96512
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.h b/xfa/fgas/graphics/cfgas_gegraphics.h
index 4a28ffd..9885990 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.h
+++ b/xfa/fgas/graphics/cfgas_gegraphics.h
@@ -39,9 +39,6 @@
   explicit CFGAS_GEGraphics(CFX_RenderDevice* renderDevice);
   ~CFGAS_GEGraphics();
 
-  void SaveGraphState();
-  void RestoreGraphState();
-
   CFX_RectF GetClipRect() const;
   const CFX_Matrix* GetMatrix() const;
   CFX_RenderDevice* GetRenderDevice();
@@ -73,6 +70,9 @@
     CFGAS_GEColor fillColor{nullptr};
   };
 
+  void SaveGraphState();
+  void RestoreGraphState();
+
   void RenderDeviceStrokePath(const CFGAS_GEPath& path,
                               const CFX_Matrix& matrix);
   void RenderDeviceFillPath(const CFGAS_GEPath& path,
diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp
index 4f90aee..c9d3a52 100644
--- a/xfa/fwl/cfwl_combobox.cpp
+++ b/xfa/fwl/cfwl_combobox.cpp
@@ -103,16 +103,14 @@
 
 void CFWL_ComboBox::DrawWidget(CFGAS_GEGraphics* pGraphics,
                                const CFX_Matrix& matrix) {
-  {
+  if (!m_BtnRect.IsEmpty(0.1f)) {
     CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
     pGraphics->ConcatMatrix(matrix);
-    if (!m_BtnRect.IsEmpty(0.1f)) {
-      CFWL_ThemeBackground param(this, pGraphics);
-      param.m_iPart = CFWL_ThemePart::Part::kDropDownButton;
-      param.m_dwStates = m_iBtnState;
-      param.m_PartRect = m_BtnRect;
-      GetThemeProvider()->DrawBackground(param);
-    }
+    CFWL_ThemeBackground param(this, pGraphics);
+    param.m_iPart = CFWL_ThemePart::Part::kDropDownButton;
+    param.m_dwStates = m_iBtnState;
+    param.m_PartRect = m_BtnRect;
+    GetThemeProvider()->DrawBackground(param);
   }
   if (m_pEdit) {
     CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 7c101dc..bdd3e0a 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -311,14 +311,32 @@
 
 void CFWL_Edit::DrawContent(CFGAS_GEGraphics* pGraphics,
                             const CFX_Matrix& mtMatrix) {
-  CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
-  if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_CombText)
-    pGraphics->SaveGraphState();
+  DrawContentNonComb(pGraphics, mtMatrix);
+  if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_CombText) {
+    CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+    CFGAS_GEPath path;
+    const int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1;
+    const float fStep = m_EngineRect.width / iLimit;
+    float fLeft = m_EngineRect.left + 1;
+    for (int32_t i = 1; i < iLimit; i++) {
+      fLeft += fStep;
+      path.AddLine(CFX_PointF(fLeft, m_ClientRect.top),
+                   CFX_PointF(fLeft, m_ClientRect.bottom()));
+    }
+    CFWL_ThemeBackground param(this, pGraphics);
+    param.m_matrix = mtMatrix;
+    param.m_iPart = CFWL_ThemePart::Part::kCombTextLine;
+    param.SetPath(&path);
+    GetThemeProvider()->DrawBackground(param);
+  }
+}
 
+void CFWL_Edit::DrawContentNonComb(CFGAS_GEGraphics* pGraphics,
+                                   const CFX_Matrix& mtMatrix) {
+  CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
   CFX_RectF rtClip = m_EngineRect;
   float fOffSetX = m_EngineRect.left - m_fScrollOffsetX;
   float fOffSetY = m_EngineRect.top - m_fScrollOffsetY + m_fVAlignOffset;
-
   CFX_Matrix mt(1, 0, 0, 1, fOffSetX, fOffSetY);
   rtClip = mtMatrix.TransformRect(rtClip);
   mt.Concat(mtMatrix);
@@ -349,26 +367,6 @@
 
   CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice();
   RenderText(pRenderDev, rtClip, mt);
-
-  if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_CombText) {
-    pGraphics->RestoreGraphState();
-
-    CFGAS_GEPath path;
-    int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1;
-    float fStep = m_EngineRect.width / iLimit;
-    float fLeft = m_EngineRect.left + 1;
-    for (int32_t i = 1; i < iLimit; i++) {
-      fLeft += fStep;
-      path.AddLine(CFX_PointF(fLeft, m_ClientRect.top),
-                   CFX_PointF(fLeft, m_ClientRect.bottom()));
-    }
-
-    CFWL_ThemeBackground param(this, pGraphics);
-    param.m_matrix = mtMatrix;
-    param.m_iPart = CFWL_ThemePart::Part::kCombTextLine;
-    param.SetPath(&path);
-    GetThemeProvider()->DrawBackground(param);
-  }
 }
 
 void CFWL_Edit::RenderText(CFX_RenderDevice* pRenderDev,
diff --git a/xfa/fwl/cfwl_edit.h b/xfa/fwl/cfwl_edit.h
index 66ff7de..fc14a1a 100644
--- a/xfa/fwl/cfwl_edit.h
+++ b/xfa/fwl/cfwl_edit.h
@@ -110,6 +110,8 @@
                   const CFX_RectF& clipRect,
                   const CFX_Matrix& mt);
   void DrawContent(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+  void DrawContentNonComb(CFGAS_GEGraphics* pGraphics,
+                          const CFX_Matrix& mtMatrix);
 
   void UpdateEditEngine();
   void UpdateEditParams();
diff --git a/xfa/fwl/theme/cfwl_edittp.cpp b/xfa/fwl/theme/cfwl_edittp.cpp
index 22b2597..cc52473 100644
--- a/xfa/fwl/theme/cfwl_edittp.cpp
+++ b/xfa/fwl/theme/cfwl_edittp.cpp
@@ -24,10 +24,10 @@
       break;
     }
     case CFWL_ThemePart::Part::kBackground: {
+      CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
+      CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
       const CFGAS_GEPath* pParamsPath = pParams.GetPath();
       if (pParamsPath) {
-        CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
-        CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
         pGraphics->SetFillColor(CFGAS_GEColor(FWLTHEME_COLOR_BKSelected));
         pGraphics->FillPath(*pParamsPath,
                             CFX_FillRenderOptions::FillType::kWinding,
@@ -45,10 +45,9 @@
           else
             cr = CFGAS_GEColor(0xFFFFFFFF);
         }
-        CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
-        pParams.GetGraphics()->SetFillColor(cr);
-        pParams.GetGraphics()->FillPath(
-            path, CFX_FillRenderOptions::FillType::kWinding, pParams.m_matrix);
+        pGraphics->SetFillColor(cr);
+        pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding,
+                            pParams.m_matrix);
       }
       break;
     }