Split CPWL_SBButton off into its own file

Adhere to the "one class in a similarly named file" rule.

Change-Id: Ia1c3c09155b1f3c81d4ccfabd68591eee4f0d98d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79170
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/pwl/BUILD.gn b/fpdfsdk/pwl/BUILD.gn
index 6921b27..7390119 100644
--- a/fpdfsdk/pwl/BUILD.gn
+++ b/fpdfsdk/pwl/BUILD.gn
@@ -29,6 +29,8 @@
     "cpwl_list_box.h",
     "cpwl_list_ctrl.cpp",
     "cpwl_list_ctrl.h",
+    "cpwl_sbbutton.cpp",
+    "cpwl_sbbutton.h",
     "cpwl_scroll_bar.cpp",
     "cpwl_scroll_bar.h",
     "cpwl_special_button.cpp",
diff --git a/fpdfsdk/pwl/cpwl_sbbutton.cpp b/fpdfsdk/pwl/cpwl_sbbutton.cpp
new file mode 100644
index 0000000..4605c33
--- /dev/null
+++ b/fpdfsdk/pwl/cpwl_sbbutton.cpp
@@ -0,0 +1,147 @@
+// Copyright 2021 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 "fpdfsdk/pwl/cpwl_sbbutton.h"
+
+#include <utility>
+#include <vector>
+
+#include "core/fxge/cfx_renderdevice.h"
+#include "third_party/base/stl_util.h"
+
+CPWL_SBButton::CPWL_SBButton(
+    const CreateParams& cp,
+    std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData,
+    PWL_SBBUTTON_TYPE eButtonType)
+    : CPWL_Wnd(cp, std::move(pAttachedData)), m_eSBButtonType(eButtonType) {
+  GetCreationParams()->eCursorType = FXCT_ARROW;
+}
+
+CPWL_SBButton::~CPWL_SBButton() = default;
+
+void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
+                                       const CFX_Matrix& mtUser2Device) {
+  if (!IsVisible())
+    return;
+
+  CFX_FloatRect rectWnd = GetWindowRect();
+  if (rectWnd.IsEmpty())
+    return;
+
+  CFX_PointF ptCenter = GetCenterPoint();
+  int32_t nTransparency = GetTransparency();
+
+  // draw border
+  pDevice->DrawStrokeRect(mtUser2Device, rectWnd,
+                          ArgbEncode(nTransparency, 100, 100, 100), 0.0f);
+  pDevice->DrawStrokeRect(mtUser2Device, rectWnd.GetDeflated(0.5f, 0.5f),
+                          ArgbEncode(nTransparency, 255, 255, 255), 1.0f);
+
+  if (m_eSBButtonType != PSBT_POS) {
+    // draw background
+    pDevice->DrawShadow(mtUser2Device, true, false,
+                        rectWnd.GetDeflated(1.0f, 1.0f), nTransparency, 80,
+                        220);
+    // draw arrow
+    if (rectWnd.top - rectWnd.bottom > 6.0f) {
+      float fX = rectWnd.left + 1.5f;
+      float fY = rectWnd.bottom;
+      std::vector<CFX_PointF> pts;
+      static constexpr float kOffsetsX[] = {2.5f, 2.5f, 4.5f, 6.5f,
+                                            6.5f, 4.5f, 2.5f};
+      static constexpr float kOffsetsY[] = {5.0f, 6.0f, 4.0f, 6.0f,
+                                            5.0f, 3.0f, 5.0f};
+      static constexpr float kOffsetsMinY[] = {4.0f, 3.0f, 5.0f, 3.0f,
+                                               4.0f, 6.0f, 4.0f};
+      static_assert(pdfium::size(kOffsetsX) == pdfium::size(kOffsetsY),
+                    "Wrong offset count");
+      static_assert(pdfium::size(kOffsetsX) == pdfium::size(kOffsetsMinY),
+                    "Wrong offset count");
+      const float* pOffsetsY =
+          m_eSBButtonType == PSBT_MIN ? kOffsetsMinY : kOffsetsY;
+      for (size_t i = 0; i < pdfium::size(kOffsetsX); ++i)
+        pts.push_back(CFX_PointF(fX + kOffsetsX[i], fY + pOffsetsY[i]));
+      pDevice->DrawFillArea(mtUser2Device, pts,
+                            ArgbEncode(nTransparency, 255, 255, 255));
+    }
+    return;
+  }
+
+  // draw shadow effect
+  CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f);
+  CFX_PointF ptBottom = CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f);
+
+  ptTop.x += 1.5f;
+  ptBottom.x += 1.5f;
+
+  const FX_COLORREF refs[] = {ArgbEncode(nTransparency, 210, 210, 210),
+                              ArgbEncode(nTransparency, 220, 220, 220),
+                              ArgbEncode(nTransparency, 240, 240, 240),
+                              ArgbEncode(nTransparency, 240, 240, 240),
+                              ArgbEncode(nTransparency, 210, 210, 210),
+                              ArgbEncode(nTransparency, 180, 180, 180),
+                              ArgbEncode(nTransparency, 150, 150, 150),
+                              ArgbEncode(nTransparency, 150, 150, 150),
+                              ArgbEncode(nTransparency, 180, 180, 180),
+                              ArgbEncode(nTransparency, 210, 210, 210)};
+  for (FX_COLORREF ref : refs) {
+    pDevice->DrawStrokeLine(&mtUser2Device, ptTop, ptBottom, ref, 1.0f);
+
+    ptTop.x += 1.0f;
+    ptBottom.x += 1.0f;
+  }
+
+  // draw friction
+  if (rectWnd.Height() <= 8.0f)
+    return;
+
+  FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120);
+  float nFrictionWidth = 5.0f;
+  float nFrictionHeight = 5.5f;
+  CFX_PointF ptLeft = CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f,
+                                 ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
+  CFX_PointF ptRight = CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f,
+                                  ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
+
+  for (size_t i = 0; i < 3; ++i) {
+    pDevice->DrawStrokeLine(&mtUser2Device, ptLeft, ptRight, crStroke, 1.0f);
+    ptLeft.y += 2.0f;
+    ptRight.y += 2.0f;
+  }
+}
+
+bool CPWL_SBButton::OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) {
+  CPWL_Wnd::OnLButtonDown(nFlag, point);
+
+  if (CPWL_Wnd* pParent = GetParentWindow())
+    pParent->NotifyLButtonDown(this, point);
+
+  m_bMouseDown = true;
+  SetCapture();
+
+  return true;
+}
+
+bool CPWL_SBButton::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
+  CPWL_Wnd::OnLButtonUp(nFlag, point);
+
+  if (CPWL_Wnd* pParent = GetParentWindow())
+    pParent->NotifyLButtonUp(this, point);
+
+  m_bMouseDown = false;
+  ReleaseCapture();
+
+  return true;
+}
+
+bool CPWL_SBButton::OnMouseMove(uint32_t nFlag, const CFX_PointF& point) {
+  CPWL_Wnd::OnMouseMove(nFlag, point);
+
+  if (CPWL_Wnd* pParent = GetParentWindow())
+    pParent->NotifyMouseMove(this, point);
+
+  return true;
+}
diff --git a/fpdfsdk/pwl/cpwl_sbbutton.h b/fpdfsdk/pwl/cpwl_sbbutton.h
new file mode 100644
index 0000000..03e2d23
--- /dev/null
+++ b/fpdfsdk/pwl/cpwl_sbbutton.h
@@ -0,0 +1,37 @@
+// Copyright 2021 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 FPDFSDK_PWL_CPWL_SBBUTTON_H_
+#define FPDFSDK_PWL_CPWL_SBBUTTON_H_
+
+#include <memory>
+
+#include "fpdfsdk/pwl/cpwl_wnd.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
+
+enum PWL_SBBUTTON_TYPE { PSBT_MIN, PSBT_MAX, PSBT_POS };
+
+class CPWL_SBButton final : public CPWL_Wnd {
+ public:
+  CPWL_SBButton(
+      const CreateParams& cp,
+      std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData,
+      PWL_SBBUTTON_TYPE eButtonType);
+  ~CPWL_SBButton() override;
+
+  // CPWL_Wnd
+  void DrawThisAppearance(CFX_RenderDevice* pDevice,
+                          const CFX_Matrix& mtUser2Device) override;
+  bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) override;
+  bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
+  bool OnMouseMove(uint32_t nFlag, const CFX_PointF& point) override;
+
+ private:
+  PWL_SBBUTTON_TYPE m_eSBButtonType;
+  bool m_bMouseDown = false;
+};
+
+#endif  // FPDFSDK_PWL_CPWL_SBBUTTON_H_
diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
index dd11c96..31744ec 100644
--- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp
+++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
@@ -9,14 +9,12 @@
 #include <algorithm>
 #include <sstream>
 #include <utility>
-#include <vector>
 
 #include "core/fxge/cfx_fillrenderoptions.h"
 #include "core/fxge/cfx_pathdata.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "fpdfsdk/pwl/cpwl_wnd.h"
 #include "third_party/base/check.h"
-#include "third_party/base/stl_util.h"
 
 namespace {
 
@@ -105,140 +103,6 @@
     SetPos(ScrollRange.fMin);
 }
 
-CPWL_SBButton::CPWL_SBButton(
-    const CreateParams& cp,
-    std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData,
-    PWL_SBBUTTON_TYPE eButtonType)
-    : CPWL_Wnd(cp, std::move(pAttachedData)), m_eSBButtonType(eButtonType) {
-  GetCreationParams()->eCursorType = FXCT_ARROW;
-}
-
-CPWL_SBButton::~CPWL_SBButton() = default;
-
-void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
-                                       const CFX_Matrix& mtUser2Device) {
-  if (!IsVisible())
-    return;
-
-  CFX_FloatRect rectWnd = GetWindowRect();
-  if (rectWnd.IsEmpty())
-    return;
-
-  CFX_PointF ptCenter = GetCenterPoint();
-  int32_t nTransparency = GetTransparency();
-
-  // draw border
-  pDevice->DrawStrokeRect(mtUser2Device, rectWnd,
-                          ArgbEncode(nTransparency, 100, 100, 100), 0.0f);
-  pDevice->DrawStrokeRect(mtUser2Device, rectWnd.GetDeflated(0.5f, 0.5f),
-                          ArgbEncode(nTransparency, 255, 255, 255), 1.0f);
-
-  if (m_eSBButtonType != PSBT_POS) {
-    // draw background
-    pDevice->DrawShadow(mtUser2Device, true, false,
-                        rectWnd.GetDeflated(1.0f, 1.0f), nTransparency, 80,
-                        220);
-    // draw arrow
-    if (rectWnd.top - rectWnd.bottom > 6.0f) {
-      float fX = rectWnd.left + 1.5f;
-      float fY = rectWnd.bottom;
-      std::vector<CFX_PointF> pts;
-      static constexpr float kOffsetsX[] = {2.5f, 2.5f, 4.5f, 6.5f,
-                                            6.5f, 4.5f, 2.5f};
-      static constexpr float kOffsetsY[] = {5.0f, 6.0f, 4.0f, 6.0f,
-                                            5.0f, 3.0f, 5.0f};
-      static constexpr float kOffsetsMinY[] = {4.0f, 3.0f, 5.0f, 3.0f,
-                                               4.0f, 6.0f, 4.0f};
-      static_assert(pdfium::size(kOffsetsX) == pdfium::size(kOffsetsY),
-                    "Wrong offset count");
-      static_assert(pdfium::size(kOffsetsX) == pdfium::size(kOffsetsMinY),
-                    "Wrong offset count");
-      const float* pOffsetsY =
-          m_eSBButtonType == PSBT_MIN ? kOffsetsMinY : kOffsetsY;
-      for (size_t i = 0; i < pdfium::size(kOffsetsX); ++i)
-        pts.push_back(CFX_PointF(fX + kOffsetsX[i], fY + pOffsetsY[i]));
-      pDevice->DrawFillArea(mtUser2Device, pts,
-                            ArgbEncode(nTransparency, 255, 255, 255));
-    }
-    return;
-  }
-
-  // draw shadow effect
-  CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f);
-  CFX_PointF ptBottom = CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f);
-
-  ptTop.x += 1.5f;
-  ptBottom.x += 1.5f;
-
-  const FX_COLORREF refs[] = {ArgbEncode(nTransparency, 210, 210, 210),
-                              ArgbEncode(nTransparency, 220, 220, 220),
-                              ArgbEncode(nTransparency, 240, 240, 240),
-                              ArgbEncode(nTransparency, 240, 240, 240),
-                              ArgbEncode(nTransparency, 210, 210, 210),
-                              ArgbEncode(nTransparency, 180, 180, 180),
-                              ArgbEncode(nTransparency, 150, 150, 150),
-                              ArgbEncode(nTransparency, 150, 150, 150),
-                              ArgbEncode(nTransparency, 180, 180, 180),
-                              ArgbEncode(nTransparency, 210, 210, 210)};
-  for (FX_COLORREF ref : refs) {
-    pDevice->DrawStrokeLine(&mtUser2Device, ptTop, ptBottom, ref, 1.0f);
-
-    ptTop.x += 1.0f;
-    ptBottom.x += 1.0f;
-  }
-
-  // draw friction
-  if (rectWnd.Height() <= 8.0f)
-    return;
-
-  FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120);
-  float nFrictionWidth = 5.0f;
-  float nFrictionHeight = 5.5f;
-  CFX_PointF ptLeft = CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f,
-                                 ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
-  CFX_PointF ptRight = CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f,
-                                  ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
-
-  for (size_t i = 0; i < 3; ++i) {
-    pDevice->DrawStrokeLine(&mtUser2Device, ptLeft, ptRight, crStroke, 1.0f);
-    ptLeft.y += 2.0f;
-    ptRight.y += 2.0f;
-  }
-}
-
-bool CPWL_SBButton::OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) {
-  CPWL_Wnd::OnLButtonDown(nFlag, point);
-
-  if (CPWL_Wnd* pParent = GetParentWindow())
-    pParent->NotifyLButtonDown(this, point);
-
-  m_bMouseDown = true;
-  SetCapture();
-
-  return true;
-}
-
-bool CPWL_SBButton::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
-  CPWL_Wnd::OnLButtonUp(nFlag, point);
-
-  if (CPWL_Wnd* pParent = GetParentWindow())
-    pParent->NotifyLButtonUp(this, point);
-
-  m_bMouseDown = false;
-  ReleaseCapture();
-
-  return true;
-}
-
-bool CPWL_SBButton::OnMouseMove(uint32_t nFlag, const CFX_PointF& point) {
-  CPWL_Wnd::OnMouseMove(nFlag, point);
-
-  if (CPWL_Wnd* pParent = GetParentWindow())
-    pParent->NotifyMouseMove(this, point);
-
-  return true;
-}
-
 CPWL_ScrollBar::CPWL_ScrollBar(
     const CreateParams& cp,
     std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.h b/fpdfsdk/pwl/cpwl_scroll_bar.h
index a9595af..805df52 100644
--- a/fpdfsdk/pwl/cpwl_scroll_bar.h
+++ b/fpdfsdk/pwl/cpwl_scroll_bar.h
@@ -11,6 +11,7 @@
 
 #include "core/fxcrt/cfx_timer.h"
 #include "core/fxcrt/unowned_ptr.h"
+#include "fpdfsdk/pwl/cpwl_sbbutton.h"
 #include "fpdfsdk/pwl/cpwl_wnd.h"
 
 struct PWL_SCROLL_INFO {
@@ -38,28 +39,6 @@
   float fSmallStep;
 };
 
-enum PWL_SBBUTTON_TYPE { PSBT_MIN, PSBT_MAX, PSBT_POS };
-
-class CPWL_SBButton final : public CPWL_Wnd {
- public:
-  CPWL_SBButton(
-      const CreateParams& cp,
-      std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData,
-      PWL_SBBUTTON_TYPE eButtonType);
-  ~CPWL_SBButton() override;
-
-  // CPWL_Wnd
-  void DrawThisAppearance(CFX_RenderDevice* pDevice,
-                          const CFX_Matrix& mtUser2Device) override;
-  bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) override;
-  bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
-  bool OnMouseMove(uint32_t nFlag, const CFX_PointF& point) override;
-
- private:
-  PWL_SBBUTTON_TYPE m_eSBButtonType;
-  bool m_bMouseDown = false;
-};
-
 struct PWL_FLOATRANGE {
  public:
   PWL_FLOATRANGE() = default;