Introduce IPWL_SystemHandler and fxcrt::TimerHandlerIface for layering.
One of a growing number of callback interfaces for the pwl
windowing layer which is unsurprising given how much functionality
from above this layer wants. Consolidation may be possible down
the road.
fxcrt::TimerHandlerIface is split off from the systemhander so
that fxjs/ can used the timer functions without gaining knowledge
of the pwl/ layer.
Change-Id: I1c075aac40a0c2842519f9c6f61e031042d7208c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58710
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index d4a986d..b582acc 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -62,6 +62,7 @@
"string_data_template.h",
"string_pool_template.h",
"string_view_template.h",
+ "timerhandler_iface.h",
"tree_node.h",
"unowned_ptr.h",
"weak_ptr.h",
diff --git a/core/fxcrt/timerhandler_iface.h b/core/fxcrt/timerhandler_iface.h
new file mode 100644
index 0000000..05f241e
--- /dev/null
+++ b/core/fxcrt/timerhandler_iface.h
@@ -0,0 +1,29 @@
+// Copyright 2019 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_FXCRT_TIMERHANDLER_IFACE_H_
+#define CORE_FXCRT_TIMERHANDLER_IFACE_H_
+
+#include "core/fxcrt/fx_system.h"
+
+namespace fxcrt {
+
+class TimerHandlerIface {
+ public:
+ static constexpr int32_t kInvalidTimerID = 0;
+ using TimerCallback = void (*)(int32_t idEvent);
+
+ virtual ~TimerHandlerIface() = default;
+
+ virtual int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) = 0;
+ virtual void KillTimer(int32_t nID) = 0;
+};
+
+} // namespace fxcrt
+
+using fxcrt::TimerHandlerIface;
+
+#endif // CORE_FXCRT_TIMERHANDLER_IFACE_H_
diff --git a/fpdfsdk/cfx_systemhandler.h b/fpdfsdk/cfx_systemhandler.h
index 49297cd..733cce9 100644
--- a/fpdfsdk/cfx_systemhandler.h
+++ b/fpdfsdk/cfx_systemhandler.h
@@ -8,30 +8,27 @@
#define FPDFSDK_CFX_SYSTEMHANDLER_H_
#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
class CFFL_FormFiller;
-class CPDF_Document;
class CPDFSDK_FormFillEnvironment;
class CPDFSDK_Widget;
-class CFX_SystemHandler {
+class CFX_SystemHandler final : public IPWL_SystemHandler {
public:
- static constexpr int32_t kInvalidTimerID = 0;
- using TimerCallback = void (*)(int32_t idEvent);
-
explicit CFX_SystemHandler(CPDFSDK_FormFillEnvironment* pFormFillEnv);
- ~CFX_SystemHandler();
+ ~CFX_SystemHandler() override;
- void InvalidateRect(CPDFSDK_Widget* widget, const CFX_FloatRect& rect);
+ void InvalidateRect(CPDFSDK_Widget* widget,
+ const CFX_FloatRect& rect) override;
void OutputSelectedRect(CFFL_FormFiller* pFormFiller,
- const CFX_FloatRect& rect);
- bool IsSelectionImplemented() const;
- void SetCursor(int32_t nCursorType);
- int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc);
- void KillTimer(int32_t nID);
+ const CFX_FloatRect& rect) override;
+ bool IsSelectionImplemented() const override;
+ void SetCursor(int32_t nCursorType) override;
+ int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) override;
+ void KillTimer(int32_t nID) override;
private:
UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp
index 11074f9..1040172 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_formfiller.cpp
@@ -580,7 +580,7 @@
void CFFL_FormFiller::TimerProc() {}
-CFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const {
+IPWL_SystemHandler* CFFL_FormFiller::GetSystemHandler() const {
return m_pFormFillEnv->GetSysHandler();
}
diff --git a/fpdfsdk/formfiller/cffl_formfiller.h b/fpdfsdk/formfiller/cffl_formfiller.h
index 0f098e2..0397c1f 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.h
+++ b/fpdfsdk/formfiller/cffl_formfiller.h
@@ -83,9 +83,9 @@
void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag);
void KillFocusForAnnot(uint32_t nFlag);
- // CPWL_TimerHandler
+ // CPWL_TimerHandler:
void TimerProc() override;
- CFX_SystemHandler* GetSystemHandler() const override;
+ IPWL_SystemHandler* GetSystemHandler() const override;
// CPWL_Wnd::ProviderIface:
CFX_Matrix GetWindowMatrix(const CPWL_Wnd::PrivateData* pAttached) override;
diff --git a/fpdfsdk/pwl/BUILD.gn b/fpdfsdk/pwl/BUILD.gn
index a771aa5..b018d53 100644
--- a/fpdfsdk/pwl/BUILD.gn
+++ b/fpdfsdk/pwl/BUILD.gn
@@ -36,6 +36,7 @@
"cpwl_timer_handler.h",
"cpwl_wnd.cpp",
"cpwl_wnd.h",
+ "ipwl_systemhandler.h",
]
configs += [ "../../:pdfium_core_config" ]
deps = [
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index 1aab8ef..6ce6a0f 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -237,7 +237,7 @@
pRange = &wrRange;
}
- CFX_SystemHandler* pSysHandler = GetSystemHandler();
+ IPWL_SystemHandler* pSysHandler = GetSystemHandler();
CPWL_EditImpl::DrawEdit(pDevice, mtUser2Device, m_pEdit.get(),
GetTextColor().ToFXColor(GetTransparency()), rcClip,
CFX_PointF(), pRange, pSysHandler,
@@ -279,7 +279,7 @@
if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
return true;
- CFX_SystemHandler* pSH = GetSystemHandler();
+ IPWL_SystemHandler* pSH = GetSystemHandler();
if (!pSH)
return false;
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
index 7e03e55..9b874c1 100644
--- a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
@@ -41,7 +41,7 @@
void CPWL_EditCtrl::SetCursor() {
if (IsValid()) {
- if (CFX_SystemHandler* pSH = GetSystemHandler()) {
+ if (IPWL_SystemHandler* pSH = GetSystemHandler()) {
if (IsWndHorV())
pSH->SetCursor(FXCT_VBEAM);
else
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp
index 80e1367..6197dd7 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp
@@ -21,10 +21,10 @@
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
-#include "fpdfsdk/cfx_systemhandler.h"
#include "fpdfsdk/pwl/cpwl_edit.h"
#include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
#include "third_party/base/compiler_specific.h"
#include "third_party/base/ptr_util.h"
@@ -458,7 +458,7 @@
const CFX_FloatRect& rcClip,
const CFX_PointF& ptOffset,
const CPVT_WordRange* pRange,
- CFX_SystemHandler* pSystemHandler,
+ IPWL_SystemHandler* pSystemHandler,
CFFL_FormFiller* pFFLData) {
const bool bContinuous =
pEdit->GetCharArray() == 0 && pEdit->GetCharSpace() <= 0.0f;
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.h b/fpdfsdk/pwl/cpwl_edit_impl.h
index 889ed78..1e36b2e 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.h
+++ b/fpdfsdk/pwl/cpwl_edit_impl.h
@@ -25,9 +25,9 @@
class CPWL_EditImpl_Iterator;
class CPWL_EditImpl_Provider;
class CFX_RenderDevice;
-class CFX_SystemHandler;
class CPWL_Edit;
class CPWL_EditCtrl;
+class IPWL_SystemHandler;
class IFX_Edit_UndoItem;
struct CPWL_EditImpl_LineRect {
@@ -261,7 +261,7 @@
const CFX_FloatRect& rcClip,
const CFX_PointF& ptOffset,
const CPVT_WordRange* pRange,
- CFX_SystemHandler* pSystemHandler,
+ IPWL_SystemHandler* pSystemHandler,
CFFL_FormFiller* pFFLData);
CPWL_EditImpl();
diff --git a/fpdfsdk/pwl/cpwl_list_box.cpp b/fpdfsdk/pwl/cpwl_list_box.cpp
index 6b9f837..b64b4a0 100644
--- a/fpdfsdk/pwl/cpwl_list_box.cpp
+++ b/fpdfsdk/pwl/cpwl_list_box.cpp
@@ -113,8 +113,8 @@
rcItem.Intersect(rcClient);
}
+ IPWL_SystemHandler* pSysHandler = GetSystemHandler();
if (m_pList->IsItemSelected(i)) {
- CFX_SystemHandler* pSysHandler = GetSystemHandler();
if (pSysHandler && pSysHandler->IsSelectionImplemented()) {
CPWL_EditImpl::DrawEdit(pDevice, mtUser2Device, m_pList->GetItemEdit(i),
GetTextColor().ToFXColor(255), rcList, ptOffset,
@@ -129,7 +129,6 @@
m_pFormFiller.Get());
}
} else {
- CFX_SystemHandler* pSysHandler = GetSystemHandler();
CPWL_EditImpl::DrawEdit(pDevice, mtUser2Device, m_pList->GetItemEdit(i),
GetTextColor().ToFXColor(255), rcList, ptOffset,
nullptr, pSysHandler, nullptr);
diff --git a/fpdfsdk/pwl/cpwl_timer.cpp b/fpdfsdk/pwl/cpwl_timer.cpp
index b5436d4..cb02b43 100644
--- a/fpdfsdk/pwl/cpwl_timer.cpp
+++ b/fpdfsdk/pwl/cpwl_timer.cpp
@@ -21,7 +21,7 @@
} // namespace
CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached,
- CFX_SystemHandler* pSystemHandler)
+ IPWL_SystemHandler* pSystemHandler)
: m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) {
ASSERT(m_pAttached);
ASSERT(m_pSystemHandler);
@@ -46,7 +46,7 @@
m_pSystemHandler->KillTimer(m_nTimerID);
GetPWLTimeMap().erase(m_nTimerID);
- m_nTimerID = CFX_SystemHandler::kInvalidTimerID;
+ m_nTimerID = IPWL_SystemHandler::kInvalidTimerID;
}
// static
diff --git a/fpdfsdk/pwl/cpwl_timer.h b/fpdfsdk/pwl/cpwl_timer.h
index 79259fe..a77cacb 100644
--- a/fpdfsdk/pwl/cpwl_timer.h
+++ b/fpdfsdk/pwl/cpwl_timer.h
@@ -8,13 +8,13 @@
#define FPDFSDK_PWL_CPWL_TIMER_H_
#include "core/fxcrt/unowned_ptr.h"
-#include "fpdfsdk/cfx_systemhandler.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
class CPWL_TimerHandler;
class CPWL_Timer {
public:
- CPWL_Timer(CPWL_TimerHandler* pAttached, CFX_SystemHandler* pSystemHandler);
+ CPWL_Timer(CPWL_TimerHandler* pAttached, IPWL_SystemHandler* pSystemHandler);
~CPWL_Timer();
static void TimerProc(int32_t idEvent);
@@ -24,12 +24,12 @@
private:
bool HasValidID() const {
- return m_nTimerID != CFX_SystemHandler::kInvalidTimerID;
+ return m_nTimerID != IPWL_SystemHandler::kInvalidTimerID;
}
- int32_t m_nTimerID = CFX_SystemHandler::kInvalidTimerID;
+ int32_t m_nTimerID = IPWL_SystemHandler::kInvalidTimerID;
UnownedPtr<CPWL_TimerHandler> const m_pAttached;
- UnownedPtr<CFX_SystemHandler> const m_pSystemHandler;
+ UnownedPtr<IPWL_SystemHandler> const m_pSystemHandler;
};
#endif // FPDFSDK_PWL_CPWL_TIMER_H_
diff --git a/fpdfsdk/pwl/cpwl_timer_handler.h b/fpdfsdk/pwl/cpwl_timer_handler.h
index f208e1c..67c117e 100644
--- a/fpdfsdk/pwl/cpwl_timer_handler.h
+++ b/fpdfsdk/pwl/cpwl_timer_handler.h
@@ -9,8 +9,8 @@
#include <memory>
-class CFX_SystemHandler;
class CPWL_Timer;
+class IPWL_SystemHandler;
class CPWL_TimerHandler {
public:
@@ -18,7 +18,7 @@
virtual ~CPWL_TimerHandler();
virtual void TimerProc();
- virtual CFX_SystemHandler* GetSystemHandler() const = 0;
+ virtual IPWL_SystemHandler* GetSystemHandler() const = 0;
void BeginTimer(int32_t nElapse);
void EndTimer();
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index 3d8e84d..6316ced 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -268,7 +268,7 @@
rcWin.Inflate(1, 1);
rcWin.Normalize();
- CFX_SystemHandler* pSH = GetSystemHandler();
+ IPWL_SystemHandler* pSH = GetSystemHandler();
if (!pSH)
return true;
@@ -606,7 +606,7 @@
void CPWL_Wnd::SetCursor() {
if (IsValid()) {
- if (CFX_SystemHandler* pSH = GetSystemHandler())
+ if (IPWL_SystemHandler* pSH = GetSystemHandler())
pSH->SetCursor(GetCreationParams()->eCursorType);
}
}
@@ -662,7 +662,7 @@
m_CreationParams.fFontSize = fFontSize;
}
-CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
+IPWL_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
return m_CreationParams.pSystemHandler.Get();
}
diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h
index b0adc89..2349783 100644
--- a/fpdfsdk/pwl/cpwl_wnd.h
+++ b/fpdfsdk/pwl/cpwl_wnd.h
@@ -22,8 +22,8 @@
class CPWL_Edit;
class CPWL_MsgControl;
class CPWL_ScrollBar;
-class CFX_SystemHandler;
class IPVT_FontMap;
+class IPWL_SystemHandler;
struct PWL_SCROLL_INFO;
// window styles
@@ -121,7 +121,7 @@
~CreateParams();
CFX_FloatRect rcRectWnd; // required
- UnownedPtr<CFX_SystemHandler> pSystemHandler; // required
+ UnownedPtr<IPWL_SystemHandler> pSystemHandler; // required
UnownedPtr<IPVT_FontMap> pFontMap; // required
ObservedPtr<ProviderIface> pProvider; // required
UnownedPtr<FocusHandlerIface> pFocusHandler; // optional
@@ -262,7 +262,7 @@
protected:
// CPWL_TimerHandler:
- CFX_SystemHandler* GetSystemHandler() const override;
+ IPWL_SystemHandler* GetSystemHandler() const override;
virtual void CreateChildWnd(const CreateParams& cp);
diff --git a/fpdfsdk/pwl/ipwl_systemhandler.h b/fpdfsdk/pwl/ipwl_systemhandler.h
new file mode 100644
index 0000000..3607e73
--- /dev/null
+++ b/fpdfsdk/pwl/ipwl_systemhandler.h
@@ -0,0 +1,29 @@
+// Copyright 2019 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_IPWL_SYSTEMHANDLER_H_
+#define FPDFSDK_PWL_IPWL_SYSTEMHANDLER_H_
+
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/timerhandler_iface.h"
+
+class CPDFSDK_Widget;
+class CFFL_FormFiller;
+
+class IPWL_SystemHandler : public TimerHandlerIface {
+ public:
+ ~IPWL_SystemHandler() override = default;
+
+ virtual void InvalidateRect(CPDFSDK_Widget* widget,
+ const CFX_FloatRect& rect) = 0;
+ virtual void OutputSelectedRect(CFFL_FormFiller* pFormFiller,
+ const CFX_FloatRect& rect) = 0;
+ virtual bool IsSelectionImplemented() const = 0;
+ virtual void SetCursor(int32_t nCursorType) = 0;
+};
+
+#endif // FPDFSDK_PWL_IPWL_SYSTEMHANDLER_H_
diff --git a/fxjs/global_timer.cpp b/fxjs/global_timer.cpp
index a4d3c04..88ea27b 100644
--- a/fxjs/global_timer.cpp
+++ b/fxjs/global_timer.cpp
@@ -8,7 +8,7 @@
#include <map>
-#include "fpdfsdk/cfx_systemhandler.h"
+#include "core/fxcrt/timerhandler_iface.h"
#include "fxjs/cjs_app.h"
namespace {