• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef XFA_FWL_CFWL_SCROLLBAR_H_
8 #define XFA_FWL_CFWL_SCROLLBAR_H_
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 
14 #include "core/fxcrt/cfx_timer.h"
15 #include "core/fxcrt/check.h"
16 #include "xfa/fwl/cfwl_eventscroll.h"
17 #include "xfa/fwl/cfwl_themepart.h"
18 #include "xfa/fwl/cfwl_widget.h"
19 
20 namespace pdfium {
21 
22 #define FWL_STYLEEXT_SCB_Horz (0L << 0)
23 #define FWL_STYLEEXT_SCB_Vert (1L << 0)
24 
25 class CFWL_ScrollBar final : public CFWL_Widget,
26                              public CFX_Timer::CallbackIface {
27  public:
28   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
29   ~CFWL_ScrollBar() override;
30 
31   // CFWL_Widget:
32   FWL_Type GetClassID() const override;
33   void Update() override;
34   void DrawWidget(CFGAS_GEGraphics* pGraphics,
35                   const CFX_Matrix& matrix) override;
36   void OnProcessMessage(CFWL_Message* pMessage) override;
37   void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
38                     const CFX_Matrix& matrix) override;
39 
40   // CFX_Timer::CallbackIface:
41   void OnTimerFired() override;
42 
GetRange(float * fMin,float * fMax)43   void GetRange(float* fMin, float* fMax) const {
44     *fMin = m_fRangeMin;
45     *fMax = m_fRangeMax;
46   }
SetRange(float fMin,float fMax)47   void SetRange(float fMin, float fMax) {
48     m_fRangeMin = fMin;
49     m_fRangeMax = fMax;
50   }
GetPageSize()51   float GetPageSize() const { return m_fPageSize; }
SetPageSize(float fPageSize)52   void SetPageSize(float fPageSize) { m_fPageSize = fPageSize; }
GetStepSize()53   float GetStepSize() const { return m_fStepSize; }
SetStepSize(float fStepSize)54   void SetStepSize(float fStepSize) { m_fStepSize = fStepSize; }
GetPos()55   float GetPos() const { return m_fPos; }
SetPos(float fPos)56   void SetPos(float fPos) { m_fPos = fPos; }
57   void SetTrackPos(float fTrackPos);
58 
59  private:
60   CFWL_ScrollBar(CFWL_App* app,
61                  const Properties& properties,
62                  CFWL_Widget* pOuter);
63 
IsVertical()64   bool IsVertical() const { return !!(GetStyleExts() & FWL_STYLEEXT_SCB_Vert); }
65   void DrawUpperTrack(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
66   void DrawLowerTrack(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
67   void DrawMaxArrowBtn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
68   void DrawMinArrowBtn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
69   void DrawThumb(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
70   void Layout();
71   void CalcButtonLen();
72   CFX_RectF CalcMinButtonRect();
73   CFX_RectF CalcMaxButtonRect();
74   CFX_RectF CalcThumbButtonRect(const CFX_RectF& rtThumbRect);
75   CFX_RectF CalcMinTrackRect(const CFX_RectF& rtMinRect);
76   CFX_RectF CalcMaxTrackRect(const CFX_RectF& rtMaxRect);
77   float GetTrackPointPos(const CFX_PointF& point);
78 
79   bool SendEvent();
80   bool OnScroll(CFWL_EventScroll::Code dwCode, float fPos);
81   void OnLButtonDown(const CFX_PointF& point);
82   void OnLButtonUp(const CFX_PointF& point);
83   void OnMouseMove(const CFX_PointF& point);
84   void OnMouseLeave();
85   void OnMouseWheel(const CFX_Vector& delta);
86   bool DoScroll(CFWL_EventScroll::Code dwCode, float fPos);
87   void DoMouseDown(int32_t iItem,
88                    const CFX_RectF& rtItem,
89                    CFWL_PartState* pState,
90                    const CFX_PointF& point);
91   void DoMouseUp(int32_t iItem,
92                  const CFX_RectF& rtItem,
93                  CFWL_PartState* pState,
94                  const CFX_PointF& point);
95   void DoMouseMove(int32_t iItem,
96                    const CFX_RectF& rtItem,
97                    CFWL_PartState* pState,
98                    const CFX_PointF& point);
99   void DoMouseLeave(int32_t iItem,
100                     const CFX_RectF& rtItem,
101                     CFWL_PartState* pState);
102   void DoMouseHover(int32_t iItem,
103                     const CFX_RectF& rtItem,
104                     CFWL_PartState* pState);
105 
106   float m_fRangeMin = 0.0f;
107   float m_fRangeMax = -1.0f;
108   float m_fPageSize = 0.0f;
109   float m_fStepSize = 0.0f;
110   float m_fPos = 0.0f;
111   float m_fTrackPos = 0.0f;
112   CFWL_PartState m_iMinButtonState = CFWL_PartState::kNormal;
113   CFWL_PartState m_iMaxButtonState = CFWL_PartState::kNormal;
114   CFWL_PartState m_iThumbButtonState = CFWL_PartState::kNormal;
115   CFWL_PartState m_iMinTrackState = CFWL_PartState::kNormal;
116   CFWL_PartState m_iMaxTrackState = CFWL_PartState::kNormal;
117   float m_fLastTrackPos = 0.0f;
118   CFX_PointF m_cpTrackPoint;
119   int32_t m_iMouseWheel = 0;
120   float m_fButtonLen = 0.0f;
121   bool m_bMouseDown = false;
122   bool m_bMinSize = false;
123   CFX_RectF m_ClientRect;
124   CFX_RectF m_ThumbRect;
125   CFX_RectF m_MinBtnRect;
126   CFX_RectF m_MaxBtnRect;
127   CFX_RectF m_MinTrackRect;
128   CFX_RectF m_MaxTrackRect;
129   std::unique_ptr<CFX_Timer> m_pTimer;
130 };
131 
132 }  // namespace pdfium
133 
134 // TODO(crbug.com/42271761): Remove.
135 using pdfium::CFWL_ScrollBar;
136 
137 #endif  // XFA_FWL_CFWL_SCROLLBAR_H_
138