Moving drawing focus rect to class CFX_DrawUtils

This CL moves drawing focus rect from cffl_interactiveformfiller.cc to
separate file. After this refactoring, other classes can reuse this
utility function. Eg. Tabbing is supported for links/highlights
(60011: Add keyboard tabbing for links & highlights)
focus rect needs to be drawn for links/highlights as well.

So moving drawing focus rect part to a separate file helps to reuse the
method for other features as well.

Bug: chromium:994500
Change-Id: I2a2d81aa285f6b02022df47cef3f95ddc3c22723
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/67250
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn
index f8b7d4e..98ec1b5 100644
--- a/core/fxge/BUILD.gn
+++ b/core/fxge/BUILD.gn
@@ -23,6 +23,8 @@
     "cfx_color.cpp",
     "cfx_color.h",
     "cfx_defaultrenderdevice.h",
+    "cfx_drawutils.cpp",
+    "cfx_drawutils.h",
     "cfx_face.cpp",
     "cfx_face.h",
     "cfx_folderfontinfo.cpp",
diff --git a/core/fxge/cfx_drawutils.cpp b/core/fxge/cfx_drawutils.cpp
new file mode 100644
index 0000000..b144153
--- /dev/null
+++ b/core/fxge/cfx_drawutils.cpp
@@ -0,0 +1,38 @@
+// 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 "core/fxge/cfx_drawutils.h"
+
+#include "core/fxge/cfx_graphstatedata.h"
+#include "core/fxge/cfx_pathdata.h"
+#include "core/fxge/cfx_renderdevice.h"
+
+// static
+void CFX_DrawUtils::DrawFocusRect(CFX_RenderDevice* render_device,
+                                  const CFX_Matrix& user_to_device,
+                                  const CFX_FloatRect& view_bounding_box) {
+  ASSERT(render_device);
+  CFX_PathData path;
+  path.AppendPoint(CFX_PointF(view_bounding_box.left, view_bounding_box.top),
+                   FXPT_TYPE::MoveTo, /*closeFigure=*/false);
+  path.AppendPoint(CFX_PointF(view_bounding_box.left, view_bounding_box.bottom),
+                   FXPT_TYPE::LineTo, /*closeFigure=*/false);
+  path.AppendPoint(
+      CFX_PointF(view_bounding_box.right, view_bounding_box.bottom),
+      FXPT_TYPE::LineTo, /*closeFigure=*/false);
+  path.AppendPoint(CFX_PointF(view_bounding_box.right, view_bounding_box.top),
+                   FXPT_TYPE::LineTo, /*closeFigure=*/false);
+  path.AppendPoint(CFX_PointF(view_bounding_box.left, view_bounding_box.top),
+                   FXPT_TYPE::LineTo, /*closeFigure=*/false);
+
+  CFX_GraphStateData graph_state_data;
+  graph_state_data.m_DashArray = {1.0f};
+  graph_state_data.m_DashPhase = 0;
+  graph_state_data.m_LineWidth = 1.0f;
+
+  render_device->DrawPath(&path, &user_to_device, &graph_state_data, 0,
+                          ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE);
+}
diff --git a/core/fxge/cfx_drawutils.h b/core/fxge/cfx_drawutils.h
new file mode 100644
index 0000000..4c8b2fe
--- /dev/null
+++ b/core/fxge/cfx_drawutils.h
@@ -0,0 +1,24 @@
+// 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
+
+#ifndef CORE_FXGE_CFX_DRAWUTILS_H_
+#define CORE_FXGE_CFX_DRAWUTILS_H_
+
+class CFX_FloatRect;
+class CFX_Matrix;
+class CFX_RenderDevice;
+
+class CFX_DrawUtils {
+ public:
+  CFX_DrawUtils() = delete;
+  CFX_DrawUtils(const CFX_DrawUtils&) = delete;
+  CFX_DrawUtils& operator=(const CFX_DrawUtils&) = delete;
+
+  static void DrawFocusRect(CFX_RenderDevice* render_device,
+                            const CFX_Matrix& user_to_device,
+                            const CFX_FloatRect& view_bounding_box);
+};
+#endif  // CORE_FXGE_CFX_DRAWUTILS_H_
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
index 1e6d4a8..b6dc475 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -10,9 +10,7 @@
 #include "constants/form_flags.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fxcrt/autorestorer.h"
-#include "core/fxge/cfx_graphstatedata.h"
-#include "core/fxge/cfx_pathdata.h"
-#include "core/fxge/cfx_renderdevice.h"
+#include "core/fxge/cfx_drawutils.h"
 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
 #include "fpdfsdk/cpdfsdk_interactiveform.h"
 #include "fpdfsdk/cpdfsdk_pageview.h"
@@ -75,24 +73,8 @@
     if (rcFocus.IsEmpty())
       return;
 
-    CFX_PathData path;
-    path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::MoveTo,
-                     false);
-    path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.bottom),
-                     FXPT_TYPE::LineTo, false);
-    path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.bottom),
-                     FXPT_TYPE::LineTo, false);
-    path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.top), FXPT_TYPE::LineTo,
-                     false);
-    path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::LineTo,
-                     false);
+    CFX_DrawUtils::DrawFocusRect(pDevice, mtUser2Device, rcFocus);
 
-    CFX_GraphStateData gsd;
-    gsd.m_DashArray = {1.0f};
-    gsd.m_DashPhase = 0;
-    gsd.m_LineWidth = 1.0f;
-    pDevice->DrawPath(&path, &mtUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0),
-                      FXFILL_ALTERNATE);
     return;
   }