Replace duplicate FXCT_* definitions with enum class CursorStyle. Bug: pdfium:1085 Change-Id: I64ea1b6719fbec02218d8a6adb14fdce01d9faeb Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80571 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index c284f86..15d80f1 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -28,6 +28,25 @@ #include "third_party/base/check.h" #include "third_party/base/stl_util.h" +static_assert(FXCT_ARROW == + static_cast<int>(IPWL_SystemHandler::CursorStyle::kArrow), + "kArrow value mismatch"); +static_assert(FXCT_NESW == + static_cast<int>(IPWL_SystemHandler::CursorStyle::kNESW), + "kNEWS value mismatch"); +static_assert(FXCT_NWSE == + static_cast<int>(IPWL_SystemHandler::CursorStyle::kNWSE), + "kNWSE value mismatch"); +static_assert(FXCT_VBEAM == + static_cast<int>(IPWL_SystemHandler::CursorStyle::kVBeam), + "kVBeam value mismatch"); +static_assert(FXCT_HBEAM == + static_cast<int>(IPWL_SystemHandler::CursorStyle::kHBeam), + "HBeam value mismatch"); +static_assert(FXCT_HAND == + static_cast<int>(IPWL_SystemHandler::CursorStyle::kHand), + "kHand value mismatch"); + FPDF_WIDESTRING AsFPDFWideString(ByteString* bsUTF16LE) { // Force a private version of the string, since we're about to hand it off // to the embedder. Should the embedder modify it by accident, it won't @@ -345,9 +364,9 @@ } } -void CPDFSDK_FormFillEnvironment::SetCursor(int nCursorType) { +void CPDFSDK_FormFillEnvironment::SetCursor(CursorStyle nCursorType) { if (m_pInfo && m_pInfo->FFI_SetCursor) - m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); + m_pInfo->FFI_SetCursor(m_pInfo, static_cast<int>(nCursorType)); } int CPDFSDK_FormFillEnvironment::SetTimer(int uElapse,
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index cc1cdba..7cee3ed 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -64,7 +64,7 @@ void OutputSelectedRect(CFFL_FormFiller* pFormFiller, const CFX_FloatRect& rect) override; bool IsSelectionImplemented() const override; - void SetCursor(int32_t nCursorType) override; + void SetCursor(CursorStyle nCursorType) override; CPDFSDK_PageView* GetPageView(IPDF_Page* pUnderlyingPage, bool renew); CPDFSDK_PageView* GetPageViewAtIndex(int nIndex);
diff --git a/fpdfsdk/pwl/cpwl_button.cpp b/fpdfsdk/pwl/cpwl_button.cpp index 39ea618..7b978bb 100644 --- a/fpdfsdk/pwl/cpwl_button.cpp +++ b/fpdfsdk/pwl/cpwl_button.cpp
@@ -12,7 +12,7 @@ const CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) : CPWL_Wnd(cp, std::move(pAttachedData)) { - GetCreationParams()->eCursorType = FXCT_HAND; + GetCreationParams()->eCursorType = IPWL_SystemHandler::CursorStyle::kHand; } CPWL_Button::~CPWL_Button() = default;
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp index 1ddb1ef..2082792 100644 --- a/fpdfsdk/pwl/cpwl_combo_box.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -170,7 +170,7 @@ bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; bcp.dwBorderWidth = 2; bcp.nBorderStyle = BorderStyle::kBeveled; - bcp.eCursorType = FXCT_ARROW; + bcp.eCursorType = IPWL_SystemHandler::CursorStyle::kArrow; auto pButton = std::make_unique<CPWL_CBButton>(bcp, CloneAttachedData()); m_pButton = pButton.get(); @@ -186,7 +186,7 @@ lcp.dwFlags = PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; lcp.nBorderStyle = BorderStyle::kSolid; lcp.dwBorderWidth = 1; - lcp.eCursorType = FXCT_ARROW; + lcp.eCursorType = IPWL_SystemHandler::CursorStyle::kArrow; lcp.rcRectWnd = CFX_FloatRect(); lcp.fFontSize =
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp index b359c99..2b64312 100644 --- a/fpdfsdk/pwl/cpwl_edit.cpp +++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -33,7 +33,7 @@ std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) : CPWL_Wnd(cp, std::move(pAttachedData)), m_pEditImpl(std::make_unique<CPWL_EditImpl>()) { - GetCreationParams()->eCursorType = FXCT_VBEAM; + GetCreationParams()->eCursorType = IPWL_SystemHandler::CursorStyle::kVBeam; } CPWL_Edit::~CPWL_Edit() { @@ -482,8 +482,11 @@ } void CPWL_Edit::SetCursor() { - if (IsValid()) - GetSystemHandler()->SetCursor(IsWndHorV() ? FXCT_VBEAM : FXCT_HBEAM); + if (IsValid()) { + GetSystemHandler()->SetCursor( + IsWndHorV() ? IPWL_SystemHandler::CursorStyle::kVBeam + : IPWL_SystemHandler::CursorStyle::kHBeam); + } } WideString CPWL_Edit::GetSelectedText() {
diff --git a/fpdfsdk/pwl/cpwl_sbbutton.cpp b/fpdfsdk/pwl/cpwl_sbbutton.cpp index 7b96fcf..f2fbd52 100644 --- a/fpdfsdk/pwl/cpwl_sbbutton.cpp +++ b/fpdfsdk/pwl/cpwl_sbbutton.cpp
@@ -17,7 +17,7 @@ std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData, Type eButtonType) : CPWL_Wnd(cp, std::move(pAttachedData)), m_eSBButtonType(eButtonType) { - GetCreationParams()->eCursorType = FXCT_ARROW; + GetCreationParams()->eCursorType = IPWL_SystemHandler::CursorStyle::kArrow; } CPWL_SBButton::~CPWL_SBButton() = default;
diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp index 2e47f1b..fe78fcd 100644 --- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp +++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
@@ -107,7 +107,7 @@ const CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) : CPWL_Wnd(cp, std::move(pAttachedData)) { - GetCreationParams()->eCursorType = FXCT_ARROW; + GetCreationParams()->eCursorType = IPWL_SystemHandler::CursorStyle::kArrow; } CPWL_ScrollBar::~CPWL_ScrollBar() = default;
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp index f2628f2..ed0b4af 100644 --- a/fpdfsdk/pwl/cpwl_wnd.cpp +++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -491,7 +491,7 @@ CreateParams scp = cp; scp.dwFlags = PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; - scp.eCursorType = FXCT_ARROW; + scp.eCursorType = IPWL_SystemHandler::CursorStyle::kArrow; scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; auto pBar = std::make_unique<CPWL_ScrollBar>(scp, CloneAttachedData());
diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h index c51fd12..e293a2b 100644 --- a/fpdfsdk/pwl/cpwl_wnd.h +++ b/fpdfsdk/pwl/cpwl_wnd.h
@@ -56,14 +56,6 @@ // combobox styles #define PCBS_ALLOWCUSTOMTEXT 0x0001L -// Cursor style. These must match the values in public/fpdf_formfill.h -#define FXCT_ARROW 0 -#define FXCT_NESW 1 -#define FXCT_NWSE 2 -#define FXCT_VBEAM 3 -#define FXCT_HBEAM 4 -#define FXCT_HAND 5 - struct CPWL_Dash { CPWL_Dash() : nDash(0), nGap(0), nPhase(0) {} CPWL_Dash(int32_t dash, int32_t gap, int32_t phase) @@ -102,6 +94,7 @@ virtual void OnSetFocus(CPWL_Edit* pEdit) = 0; }; + // Caller-provided options for window creation. class CreateParams { public: CreateParams(); @@ -114,6 +107,7 @@ UnownedPtr<IPWL_SystemHandler> pSystemHandler; UnownedPtr<IPVT_FontMap> pFontMap; ObservedPtr<ProviderIface> pProvider; + // Optional: UnownedPtr<FocusHandlerIface> pFocusHandler; uint32_t dwFlags = 0; @@ -125,9 +119,11 @@ int32_t nTransparency = 255; float fFontSize; CPWL_Dash sDash; - // Ignore: + + // Ignore, used internally only: CPWL_MsgControl* pMsgControl = nullptr; - int32_t eCursorType = FXCT_ARROW; + IPWL_SystemHandler::CursorStyle eCursorType = + IPWL_SystemHandler::CursorStyle::kArrow; }; static bool IsSHIFTKeyDown(uint32_t nFlag);
diff --git a/fpdfsdk/pwl/ipwl_systemhandler.h b/fpdfsdk/pwl/ipwl_systemhandler.h index 8a14d8e..61ed7f6 100644 --- a/fpdfsdk/pwl/ipwl_systemhandler.h +++ b/fpdfsdk/pwl/ipwl_systemhandler.h
@@ -16,6 +16,16 @@ class IPWL_SystemHandler { public: + // These must match the values in public/fpdf_formfill.h + enum CursorStyle { + kArrow = 0, + kNESW = 1, + kNWSE = 2, + kVBeam = 3, + kHBeam = 4, + kHand = 5, + }; + class PerWindowData { public: virtual ~PerWindowData() = default; @@ -29,7 +39,7 @@ virtual void OutputSelectedRect(CFFL_FormFiller* pFormFiller, const CFX_FloatRect& rect) = 0; virtual bool IsSelectionImplemented() const = 0; - virtual void SetCursor(int32_t nCursorType) = 0; + virtual void SetCursor(CursorStyle nCursorStyle) = 0; }; #endif // FPDFSDK_PWL_IPWL_SYSTEMHANDLER_H_