Be more careful about enum CFWL_PartState. Initial cleanup before worrying about whether we are ORing things into this mask that aren't CFWL_PartStates. -- Remove some non-const refs while at it. Change-Id: I03536d07686760b434c1a6d3cde5b62b243df1e5 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83192 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fwl/cfwl_scrollbar.cpp b/xfa/fwl/cfwl_scrollbar.cpp index e5b0bf9..b967911 100644 --- a/xfa/fwl/cfwl_scrollbar.cpp +++ b/xfa/fwl/cfwl_scrollbar.cpp
@@ -327,15 +327,15 @@ m_cpTrackPoint = point; m_fLastTrackPos = m_fTrackPos; if (m_MinBtnRect.Contains(point)) - DoMouseDown(0, m_MinBtnRect, m_iMinButtonState, point); + DoMouseDown(0, m_MinBtnRect, &m_iMinButtonState, point); else if (m_ThumbRect.Contains(point)) - DoMouseDown(1, m_ThumbRect, m_iThumbButtonState, point); + DoMouseDown(1, m_ThumbRect, &m_iThumbButtonState, point); else if (m_MaxBtnRect.Contains(point)) - DoMouseDown(2, m_MaxBtnRect, m_iMaxButtonState, point); + DoMouseDown(2, m_MaxBtnRect, &m_iMaxButtonState, point); else if (m_MinTrackRect.Contains(point)) - DoMouseDown(3, m_MinTrackRect, m_iMinTrackState, point); + DoMouseDown(3, m_MinTrackRect, &m_iMinTrackState, point); else - DoMouseDown(4, m_MaxTrackRect, m_iMaxTrackState, point); + DoMouseDown(4, m_MaxTrackRect, &m_iMaxTrackState, point); if (!SendEvent()) { m_pTimer = std::make_unique<CFX_Timer>(GetFWLApp()->GetTimerHandler(), this, @@ -346,28 +346,28 @@ void CFWL_ScrollBar::OnLButtonUp(const CFX_PointF& point) { m_pTimer.reset(); m_bMouseDown = false; - DoMouseUp(0, m_MinBtnRect, m_iMinButtonState, point); - DoMouseUp(1, m_ThumbRect, m_iThumbButtonState, point); - DoMouseUp(2, m_MaxBtnRect, m_iMaxButtonState, point); - DoMouseUp(3, m_MinTrackRect, m_iMinTrackState, point); - DoMouseUp(4, m_MaxTrackRect, m_iMaxTrackState, point); + DoMouseUp(0, m_MinBtnRect, &m_iMinButtonState, point); + DoMouseUp(1, m_ThumbRect, &m_iThumbButtonState, point); + DoMouseUp(2, m_MaxBtnRect, &m_iMaxButtonState, point); + DoMouseUp(3, m_MinTrackRect, &m_iMinTrackState, point); + DoMouseUp(4, m_MaxTrackRect, &m_iMaxTrackState, point); SetGrab(false); } void CFWL_ScrollBar::OnMouseMove(const CFX_PointF& point) { - DoMouseMove(0, m_MinBtnRect, m_iMinButtonState, point); - DoMouseMove(1, m_ThumbRect, m_iThumbButtonState, point); - DoMouseMove(2, m_MaxBtnRect, m_iMaxButtonState, point); - DoMouseMove(3, m_MinTrackRect, m_iMinTrackState, point); - DoMouseMove(4, m_MaxTrackRect, m_iMaxTrackState, point); + DoMouseMove(0, m_MinBtnRect, &m_iMinButtonState, point); + DoMouseMove(1, m_ThumbRect, &m_iThumbButtonState, point); + DoMouseMove(2, m_MaxBtnRect, &m_iMaxButtonState, point); + DoMouseMove(3, m_MinTrackRect, &m_iMinTrackState, point); + DoMouseMove(4, m_MaxTrackRect, &m_iMaxTrackState, point); } void CFWL_ScrollBar::OnMouseLeave() { - DoMouseLeave(0, m_MinBtnRect, m_iMinButtonState); - DoMouseLeave(1, m_ThumbRect, m_iThumbButtonState); - DoMouseLeave(2, m_MaxBtnRect, m_iMaxButtonState); - DoMouseLeave(3, m_MinTrackRect, m_iMinTrackState); - DoMouseLeave(4, m_MaxTrackRect, m_iMaxTrackState); + DoMouseLeave(0, m_MinBtnRect, &m_iMinButtonState); + DoMouseLeave(1, m_ThumbRect, &m_iThumbButtonState); + DoMouseLeave(2, m_MaxBtnRect, &m_iMaxButtonState); + DoMouseLeave(3, m_MinTrackRect, &m_iMinTrackState); + DoMouseLeave(4, m_MaxTrackRect, &m_iMaxTrackState); } void CFWL_ScrollBar::OnMouseWheel(const CFX_Vector& delta) { @@ -378,42 +378,42 @@ void CFWL_ScrollBar::DoMouseDown(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState, + CFWL_PartState* pState, const CFX_PointF& point) { if (!rtItem.Contains(point)) return; - if (iState == CFWL_PartState_Pressed) + if (*pState == CFWL_PartState_Pressed) return; - iState = CFWL_PartState_Pressed; + *pState = CFWL_PartState_Pressed; RepaintRect(rtItem); } void CFWL_ScrollBar::DoMouseUp(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState, + CFWL_PartState* pState, const CFX_PointF& point) { - int32_t iNewState = + CFWL_PartState iNewState = rtItem.Contains(point) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; - if (iState == iNewState) + if (*pState == iNewState) return; - iState = iNewState; + *pState = iNewState; RepaintRect(rtItem); OnScroll(CFWL_EventScroll::Code::EndScroll, m_fTrackPos); } void CFWL_ScrollBar::DoMouseMove(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState, + CFWL_PartState* pState, const CFX_PointF& point) { if (!m_bMouseDown) { - int32_t iNewState = + CFWL_PartState iNewState = rtItem.Contains(point) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; - if (iState == iNewState) + if (*pState == iNewState) return; - iState = iNewState; + *pState = iNewState; RepaintRect(rtItem); } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { m_fTrackPos = GetTrackPointPos(point); @@ -423,21 +423,21 @@ void CFWL_ScrollBar::DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState) { - if (iState == CFWL_PartState_Normal) + CFWL_PartState* pState) { + if (*pState == CFWL_PartState_Normal) return; - iState = CFWL_PartState_Normal; + *pState = CFWL_PartState_Normal; RepaintRect(rtItem); } void CFWL_ScrollBar::DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState) { - if (iState == CFWL_PartState_Hovered) + CFWL_PartState* pState) { + if (*pState == CFWL_PartState_Hovered) return; - iState = CFWL_PartState_Hovered; + *pState = CFWL_PartState_Hovered; RepaintRect(rtItem); }
diff --git a/xfa/fwl/cfwl_scrollbar.h b/xfa/fwl/cfwl_scrollbar.h index 0923a02..dd8921d 100644 --- a/xfa/fwl/cfwl_scrollbar.h +++ b/xfa/fwl/cfwl_scrollbar.h
@@ -13,6 +13,7 @@ #include "core/fxcrt/fx_system.h" #include "third_party/base/check.h" #include "xfa/fwl/cfwl_eventscroll.h" +#include "xfa/fwl/cfwl_themepart.h" #include "xfa/fwl/cfwl_widget.h" #define FWL_STYLEEXT_SCB_Horz (0L << 0) @@ -86,18 +87,22 @@ bool DoScroll(CFWL_EventScroll::Code dwCode, float fPos); void DoMouseDown(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState, + CFWL_PartState* pState, const CFX_PointF& point); void DoMouseUp(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState, + CFWL_PartState* pState, const CFX_PointF& point); void DoMouseMove(int32_t iItem, const CFX_RectF& rtItem, - int32_t& iState, + CFWL_PartState* pState, const CFX_PointF& point); - void DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); - void DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); + void DoMouseLeave(int32_t iItem, + const CFX_RectF& rtItem, + CFWL_PartState* pState); + void DoMouseHover(int32_t iItem, + const CFX_RectF& rtItem, + CFWL_PartState* pState); float m_fRangeMin = 0.0f; float m_fRangeMax = -1.0f; @@ -105,11 +110,11 @@ float m_fStepSize = 0.0f; float m_fPos = 0.0f; float m_fTrackPos = 0.0f; - int32_t m_iMinButtonState = CFWL_PartState_Normal; - int32_t m_iMaxButtonState = CFWL_PartState_Normal; - int32_t m_iThumbButtonState = CFWL_PartState_Normal; - int32_t m_iMinTrackState = CFWL_PartState_Normal; - int32_t m_iMaxTrackState = CFWL_PartState_Normal; + CFWL_PartState m_iMinButtonState = CFWL_PartState_Normal; + CFWL_PartState m_iMaxButtonState = CFWL_PartState_Normal; + CFWL_PartState m_iThumbButtonState = CFWL_PartState_Normal; + CFWL_PartState m_iMinTrackState = CFWL_PartState_Normal; + CFWL_PartState m_iMaxTrackState = CFWL_PartState_Normal; float m_fLastTrackPos = 0.0f; CFX_PointF m_cpTrackPoint; int32_t m_iMouseWheel = 0;
diff --git a/xfa/fwl/cfwl_themepart.h b/xfa/fwl/cfwl_themepart.h index c162772..a3a1a34 100644 --- a/xfa/fwl/cfwl_themepart.h +++ b/xfa/fwl/cfwl_themepart.h
@@ -7,11 +7,15 @@ #ifndef XFA_FWL_CFWL_THEMEPART_H_ #define XFA_FWL_CFWL_THEMEPART_H_ +#include <type_traits> + #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" #include "core/fxcrt/unowned_ptr.h" -enum CFWL_PartState { +class CFWL_Widget; + +enum CFWL_PartState : uint32_t { CFWL_PartState_Normal = 0, CFWL_PartState_Checked = 1 << 1, @@ -28,8 +32,7 @@ CFWL_PartState_RSelected = 1 << 13, CFWL_PartState_Selected = 1 << 14 }; - -class CFWL_Widget; +using CFWL_PartStateMask = std::underlying_type<CFWL_PartState>::type; class CFWL_ThemePart { public: @@ -87,7 +90,7 @@ CFX_Matrix m_matrix; CFX_RectF m_PartRect; UnownedPtr<const CFX_RectF> m_pRtData; - uint32_t m_dwStates = CFWL_PartState_Normal; + CFWL_PartStateMask m_dwStates = CFWL_PartState_Normal; Part m_iPart = Part::kNone; bool m_bMaximize = false; bool m_bStaticBackground = false;