Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 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 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 7 | #include "xfa/fwl/cfwl_scrollbar.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
| 11 | #include <utility> |
| 12 | |
Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 13 | #include "third_party/base/ptr_util.h" |
Lei Zhang | 85f019a | 2017-03-17 15:14:19 -0700 | [diff] [blame] | 14 | #include "third_party/base/stl_util.h" |
Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 15 | #include "xfa/fwl/cfwl_app.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 16 | #include "xfa/fwl/cfwl_messagemouse.h" |
| 17 | #include "xfa/fwl/cfwl_messagemousewheel.h" |
| 18 | #include "xfa/fwl/cfwl_notedriver.h" |
| 19 | #include "xfa/fwl/cfwl_themebackground.h" |
| 20 | #include "xfa/fwl/cfwl_themepart.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 21 | #include "xfa/fwl/ifwl_themeprovider.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 22 | |
| 23 | #define FWL_SCROLLBAR_Elapse 500 |
Dan Sinclair | c635c93 | 2017-01-03 15:46:55 -0500 | [diff] [blame] | 24 | |
| 25 | namespace { |
| 26 | |
| 27 | const float kMinThumbSize = 5.0f; |
| 28 | |
| 29 | } // namespace |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 30 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 31 | CFWL_ScrollBar::CFWL_ScrollBar( |
dsinclair | 1a7534a | 2016-11-22 15:56:11 -0800 | [diff] [blame] | 32 | const CFWL_App* app, |
dsinclair | a5811f0 | 2016-11-03 12:27:25 -0700 | [diff] [blame] | 33 | std::unique_ptr<CFWL_WidgetProperties> properties, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 34 | CFWL_Widget* pOuter) |
Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 35 | : CFWL_Widget(app, std::move(properties), pOuter) {} |
dsinclair | b4d40ff | 2016-05-05 10:28:02 -0700 | [diff] [blame] | 36 | |
Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 37 | CFWL_ScrollBar::~CFWL_ScrollBar() = default; |
dsinclair | b4d40ff | 2016-05-05 10:28:02 -0700 | [diff] [blame] | 38 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 39 | FWL_Type CFWL_ScrollBar::GetClassID() const { |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 40 | return FWL_Type::ScrollBar; |
| 41 | } |
| 42 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 43 | void CFWL_ScrollBar::Update() { |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 44 | if (IsLocked()) |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 45 | return; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 46 | if (!m_pProperties->m_pThemeProvider) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 47 | m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 48 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 49 | Layout(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 50 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 51 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 52 | void CFWL_ScrollBar::DrawWidget(CXFA_Graphics* pGraphics, |
Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 53 | const CFX_Matrix& matrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 54 | if (!pGraphics) |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 55 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 56 | if (!m_pProperties->m_pThemeProvider) |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 57 | return; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 58 | |
Tom Sepez | bcdbeae | 2018-08-21 23:07:21 +0000 | [diff] [blame] | 59 | IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get(); |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 60 | if (HasBorder()) |
Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 61 | DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix); |
| 62 | DrawTrack(pGraphics, pTheme, true, &matrix); |
| 63 | DrawTrack(pGraphics, pTheme, false, &matrix); |
| 64 | DrawArrowBtn(pGraphics, pTheme, true, &matrix); |
| 65 | DrawArrowBtn(pGraphics, pTheme, false, &matrix); |
| 66 | DrawThumb(pGraphics, pTheme, &matrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 67 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 68 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 69 | void CFWL_ScrollBar::SetTrackPos(float fTrackPos) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | m_fTrackPos = fTrackPos; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 71 | m_rtThumb = CalcThumbButtonRect(m_rtThumb); |
| 72 | m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack); |
| 73 | m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 74 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 75 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 76 | bool CFWL_ScrollBar::DoScroll(CFWL_EventScroll::Code dwCode, float fPos) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 77 | if (dwCode == CFWL_EventScroll::Code::None) |
dsinclair | 3e577c2 | 2016-11-10 11:01:16 -0800 | [diff] [blame] | 78 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 79 | return OnScroll(dwCode, fPos); |
| 80 | } |
tsepez | 6f4f233 | 2016-06-06 13:23:55 -0700 | [diff] [blame] | 81 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 82 | void CFWL_ScrollBar::DrawTrack(CXFA_Graphics* pGraphics, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 83 | IFWL_ThemeProvider* pTheme, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 84 | bool bLower, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 85 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 86 | CFWL_ThemeBackground param; |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 87 | param.m_pWidget = this; |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 88 | param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 89 | param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 90 | ? CFWL_PartState_Disabled |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 91 | : (bLower ? m_iMinTrackState : m_iMaxTrackState); |
| 92 | param.m_pGraphics = pGraphics; |
| 93 | param.m_matrix.Concat(*pMatrix); |
| 94 | param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; |
Tom Sepez | f801451 | 2019-01-17 21:59:24 +0000 | [diff] [blame] | 95 | pTheme->DrawBackground(param); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 96 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 97 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 98 | void CFWL_ScrollBar::DrawArrowBtn(CXFA_Graphics* pGraphics, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 99 | IFWL_ThemeProvider* pTheme, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 100 | bool bMinBtn, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 101 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 102 | CFWL_ThemeBackground param; |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 103 | param.m_pWidget = this; |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 104 | param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 105 | param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 106 | ? CFWL_PartState_Disabled |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 107 | : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); |
| 108 | param.m_pGraphics = pGraphics; |
| 109 | param.m_matrix.Concat(*pMatrix); |
| 110 | param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 111 | if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) |
Tom Sepez | f801451 | 2019-01-17 21:59:24 +0000 | [diff] [blame] | 112 | pTheme->DrawBackground(param); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 113 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 114 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 115 | void CFWL_ScrollBar::DrawThumb(CXFA_Graphics* pGraphics, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 116 | IFWL_ThemeProvider* pTheme, |
| 117 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 118 | CFWL_ThemeBackground param; |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 119 | param.m_pWidget = this; |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 120 | param.m_iPart = CFWL_Part::Thumb; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 121 | param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 122 | ? CFWL_PartState_Disabled |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 123 | : m_iThumbButtonState; |
| 124 | param.m_pGraphics = pGraphics; |
| 125 | param.m_matrix.Concat(*pMatrix); |
| 126 | param.m_rtPart = m_rtThumb; |
Tom Sepez | f801451 | 2019-01-17 21:59:24 +0000 | [diff] [blame] | 127 | pTheme->DrawBackground(param); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 128 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 129 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 130 | void CFWL_ScrollBar::Layout() { |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 131 | m_rtClient = GetClientRect(); |
Dan Sinclair | c635c93 | 2017-01-03 15:46:55 -0500 | [diff] [blame] | 132 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 133 | CalcButtonLen(); |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 134 | m_rtMinBtn = CalcMinButtonRect(); |
| 135 | m_rtMaxBtn = CalcMaxButtonRect(); |
| 136 | m_rtThumb = CalcThumbButtonRect(m_rtThumb); |
| 137 | m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack); |
| 138 | m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 139 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 140 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 141 | void CFWL_ScrollBar::CalcButtonLen() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 142 | m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 143 | float fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 144 | if (fLength < m_fButtonLen * 2) { |
| 145 | m_fButtonLen = fLength / 2; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 146 | m_bMinSize = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 147 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 148 | m_bMinSize = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 149 | } |
| 150 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 151 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 152 | CFX_RectF CFWL_ScrollBar::CalcMinButtonRect() { |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 153 | if (IsVertical()) |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 154 | return CFX_RectF(m_rtClient.TopLeft(), m_rtClient.width, m_fButtonLen); |
| 155 | return CFX_RectF(m_rtClient.TopLeft(), m_fButtonLen, m_rtClient.height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 156 | } |
dsinclair | 878dd5b | 2016-10-17 18:14:25 -0700 | [diff] [blame] | 157 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 158 | CFX_RectF CFWL_ScrollBar::CalcMaxButtonRect() { |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 159 | if (IsVertical()) { |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 160 | return CFX_RectF(m_rtClient.left, m_rtClient.bottom() - m_fButtonLen, |
| 161 | m_rtClient.width, m_fButtonLen); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 162 | } |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 163 | return CFX_RectF(m_rtClient.right() - m_fButtonLen, m_rtClient.top, |
| 164 | m_fButtonLen, m_rtClient.height); |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | CFX_RectF CFWL_ScrollBar::CalcThumbButtonRect(const CFX_RectF& rtThumb) { |
| 168 | CFX_RectF rect; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 169 | if (!IsEnabled()) |
| 170 | return rect; |
| 171 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 172 | if (m_bMinSize) { |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 173 | rect.left = rtThumb.left; |
| 174 | rect.top = rtThumb.top; |
| 175 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 176 | } |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 177 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 178 | float fRange = m_fRangeMax - m_fRangeMin; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 179 | if (fRange < 0) { |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 180 | if (IsVertical()) { |
| 181 | return CFX_RectF(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, |
| 182 | 0); |
| 183 | } |
| 184 | return CFX_RectF(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 185 | } |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 186 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 187 | CFX_RectF rtClient = m_rtClient; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 188 | float fLength = IsVertical() ? rtClient.height : rtClient.width; |
| 189 | float fSize = m_fButtonLen; |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 190 | fLength -= fSize * 2.0f; |
| 191 | if (fLength < fSize) |
| 192 | fLength = 0.0f; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 193 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 194 | float fThumbSize = fLength * fLength / (fRange + fLength); |
Dan Sinclair | c635c93 | 2017-01-03 15:46:55 -0500 | [diff] [blame] | 195 | fThumbSize = std::max(fThumbSize, kMinThumbSize); |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 196 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 197 | float fDiff = std::max(fLength - fThumbSize, 0.0f); |
Lei Zhang | 85f019a | 2017-03-17 15:14:19 -0700 | [diff] [blame] | 198 | float fTrackPos = pdfium::clamp(m_fTrackPos, m_fRangeMin, m_fRangeMax); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 199 | if (!fRange) |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 200 | return rect; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 201 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 202 | float iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 203 | rect.left = rtClient.left; |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 204 | rect.top = rtClient.top; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 205 | if (IsVertical()) { |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 206 | rect.top += iPos; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 207 | rect.width = rtClient.width; |
| 208 | rect.height = fThumbSize; |
| 209 | } else { |
| 210 | rect.left += iPos; |
| 211 | rect.width = fThumbSize; |
| 212 | rect.height = rtClient.height; |
| 213 | } |
| 214 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 215 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 216 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 217 | CFX_RectF CFWL_ScrollBar::CalcMinTrackRect(const CFX_RectF& rtMinRect) { |
| 218 | CFX_RectF rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 219 | if (m_bMinSize) { |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 220 | rect.left = rtMinRect.left; |
| 221 | rect.top = rtMinRect.top; |
| 222 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 223 | } |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 224 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 225 | rect.left = m_rtClient.left; |
| 226 | rect.top = m_rtClient.top; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 227 | if (IsVertical()) { |
| 228 | rect.width = m_rtClient.width; |
| 229 | rect.height = (m_rtThumb.top + m_rtThumb.bottom()) / 2; |
| 230 | } else { |
| 231 | rect.width = (m_rtThumb.left + m_rtThumb.right()) / 2; |
| 232 | rect.height = m_rtClient.height; |
| 233 | } |
| 234 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 235 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 236 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 237 | CFX_RectF CFWL_ScrollBar::CalcMaxTrackRect(const CFX_RectF& rtMaxRect) { |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 238 | if (m_bMinSize) |
| 239 | return CFX_RectF(rtMaxRect.TopLeft(), 0, 0); |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 240 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 241 | if (IsVertical()) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 242 | float iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 243 | return CFX_RectF(m_rtClient.left, iy, m_rtClient.width, |
| 244 | m_rtClient.bottom() - iy); |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame] | 245 | } |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 246 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 247 | float ix = (m_rtThumb.left + m_rtThumb.right()) / 2; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 248 | return CFX_RectF(ix, m_rtClient.top, m_rtClient.height - ix, |
| 249 | m_rtClient.height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 250 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 251 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 252 | float CFWL_ScrollBar::GetTrackPointPos(const CFX_PointF& point) { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 253 | CFX_PointF diff = point - m_cpTrackPoint; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 254 | float fRange = m_fRangeMax - m_fRangeMin; |
| 255 | float fPos; |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 256 | |
| 257 | if (IsVertical()) { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 258 | fPos = fRange * diff.y / |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 259 | (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 260 | } else { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 261 | fPos = fRange * diff.x / |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 262 | (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 263 | } |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 264 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 265 | fPos += m_fLastTrackPos; |
Lei Zhang | 85f019a | 2017-03-17 15:14:19 -0700 | [diff] [blame] | 266 | return pdfium::clamp(fPos, m_fRangeMin, m_fRangeMax); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 267 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 268 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 269 | bool CFWL_ScrollBar::SendEvent() { |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 270 | if (m_iMinButtonState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 271 | DoScroll(CFWL_EventScroll::Code::StepBackward, m_fTrackPos); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 272 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 273 | } |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 274 | if (m_iMaxButtonState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 275 | DoScroll(CFWL_EventScroll::Code::StepForward, m_fTrackPos); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 276 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 277 | } |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 278 | if (m_iMinTrackState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 279 | DoScroll(CFWL_EventScroll::Code::PageBackward, m_fTrackPos); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 280 | return m_rtThumb.Contains(m_cpTrackPoint); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 281 | } |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 282 | if (m_iMaxTrackState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 283 | DoScroll(CFWL_EventScroll::Code::PageForward, m_fTrackPos); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 284 | return m_rtThumb.Contains(m_cpTrackPoint); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 285 | } |
| 286 | if (m_iMouseWheel) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 287 | CFWL_EventScroll::Code dwCode = m_iMouseWheel < 0 |
| 288 | ? CFWL_EventScroll::Code::StepForward |
| 289 | : CFWL_EventScroll::Code::StepBackward; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 290 | DoScroll(dwCode, m_fTrackPos); |
| 291 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 292 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 293 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 294 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 295 | bool CFWL_ScrollBar::OnScroll(CFWL_EventScroll::Code dwCode, float fPos) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 296 | CFWL_EventScroll ev(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 297 | ev.m_iScrollCode = dwCode; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 298 | ev.m_fPos = fPos; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 299 | DispatchEvent(&ev); |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 300 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 301 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 302 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 303 | void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 304 | if (!pMessage) |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 305 | return; |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 306 | |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 307 | CFWL_Message::Type type = pMessage->GetType(); |
| 308 | if (type == CFWL_Message::Type::Mouse) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 309 | CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 310 | switch (pMsg->m_dwCmd) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 311 | case FWL_MouseCommand::LeftButtonDown: |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 312 | OnLButtonDown(pMsg->m_pos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 313 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 314 | case FWL_MouseCommand::LeftButtonUp: |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 315 | OnLButtonUp(pMsg->m_pos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 316 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 317 | case FWL_MouseCommand::Move: |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 318 | OnMouseMove(pMsg->m_pos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 319 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 320 | case FWL_MouseCommand::Leave: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 321 | OnMouseLeave(); |
| 322 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 323 | default: |
| 324 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 325 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 326 | } else if (type == CFWL_Message::Type::MouseWheel) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 327 | CFWL_MessageMouseWheel* pMsg = |
| 328 | static_cast<CFWL_MessageMouseWheel*>(pMessage); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 329 | OnMouseWheel(pMsg->m_delta); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 330 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 331 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 332 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 333 | void CFWL_ScrollBar::OnDrawWidget(CXFA_Graphics* pGraphics, |
Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 334 | const CFX_Matrix& matrix) { |
| 335 | DrawWidget(pGraphics, matrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 336 | } |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 337 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 338 | void CFWL_ScrollBar::OnLButtonDown(const CFX_PointF& point) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 339 | if (!IsEnabled()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 340 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 341 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 342 | m_bMouseDown = true; |
| 343 | SetGrab(true); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 344 | |
| 345 | m_cpTrackPoint = point; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 346 | m_fLastTrackPos = m_fTrackPos; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 347 | if (m_rtMinBtn.Contains(point)) |
| 348 | DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, point); |
| 349 | else if (m_rtThumb.Contains(point)) |
| 350 | DoMouseDown(1, m_rtThumb, m_iThumbButtonState, point); |
| 351 | else if (m_rtMaxBtn.Contains(point)) |
| 352 | DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, point); |
| 353 | else if (m_rtMinTrack.Contains(point)) |
| 354 | DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, point); |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 355 | else |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 356 | DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, point); |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 357 | |
Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 358 | if (!SendEvent()) { |
| 359 | m_pTimer = pdfium::MakeUnique<CFX_Timer>( |
| 360 | GetOwnerApp()->GetAdapterNative()->GetTimerHandler(), this, |
| 361 | FWL_SCROLLBAR_Elapse); |
| 362 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 363 | } |
tsepez | 6f4f233 | 2016-06-06 13:23:55 -0700 | [diff] [blame] | 364 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 365 | void CFWL_ScrollBar::OnLButtonUp(const CFX_PointF& point) { |
Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 366 | m_pTimer.reset(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 367 | m_bMouseDown = false; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 368 | DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, point); |
| 369 | DoMouseUp(1, m_rtThumb, m_iThumbButtonState, point); |
| 370 | DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, point); |
| 371 | DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, point); |
| 372 | DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, point); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 373 | SetGrab(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 374 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 375 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 376 | void CFWL_ScrollBar::OnMouseMove(const CFX_PointF& point) { |
| 377 | DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, point); |
| 378 | DoMouseMove(1, m_rtThumb, m_iThumbButtonState, point); |
| 379 | DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, point); |
| 380 | DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, point); |
| 381 | DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, point); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 382 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 383 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 384 | void CFWL_ScrollBar::OnMouseLeave() { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 385 | DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); |
| 386 | DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); |
| 387 | DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); |
| 388 | DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); |
| 389 | DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 390 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 391 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 392 | void CFWL_ScrollBar::OnMouseWheel(const CFX_PointF& delta) { |
| 393 | m_iMouseWheel = static_cast<int32_t>(delta.x); |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 394 | SendEvent(); |
| 395 | m_iMouseWheel = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 396 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 397 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 398 | void CFWL_ScrollBar::DoMouseDown(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 399 | const CFX_RectF& rtItem, |
| 400 | int32_t& iState, |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 401 | const CFX_PointF& point) { |
| 402 | if (!rtItem.Contains(point)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 403 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 404 | if (iState == CFWL_PartState_Pressed) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 405 | return; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 406 | |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 407 | iState = CFWL_PartState_Pressed; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 408 | RepaintRect(rtItem); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 409 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 410 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 411 | void CFWL_ScrollBar::DoMouseUp(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 412 | const CFX_RectF& rtItem, |
| 413 | int32_t& iState, |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 414 | const CFX_PointF& point) { |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 415 | int32_t iNewState = |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 416 | rtItem.Contains(point) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 417 | if (iState == iNewState) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 418 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 419 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 420 | iState = iNewState; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 421 | RepaintRect(rtItem); |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 422 | OnScroll(CFWL_EventScroll::Code::EndScroll, m_fTrackPos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 423 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 424 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 425 | void CFWL_ScrollBar::DoMouseMove(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 426 | const CFX_RectF& rtItem, |
| 427 | int32_t& iState, |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 428 | const CFX_PointF& point) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 429 | if (!m_bMouseDown) { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 430 | int32_t iNewState = |
| 431 | rtItem.Contains(point) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 432 | if (iState == iNewState) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 433 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 434 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 435 | iState = iNewState; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 436 | RepaintRect(rtItem); |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 437 | } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 438 | m_fTrackPos = GetTrackPointPos(point); |
| 439 | OnScroll(CFWL_EventScroll::Code::TrackPos, m_fTrackPos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 440 | } |
| 441 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 442 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 443 | void CFWL_ScrollBar::DoMouseLeave(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 444 | const CFX_RectF& rtItem, |
| 445 | int32_t& iState) { |
| 446 | if (iState == CFWL_PartState_Normal) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 447 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 448 | |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 449 | iState = CFWL_PartState_Normal; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 450 | RepaintRect(rtItem); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 451 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 452 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 453 | void CFWL_ScrollBar::DoMouseHover(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 454 | const CFX_RectF& rtItem, |
| 455 | int32_t& iState) { |
| 456 | if (iState == CFWL_PartState_Hovered) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 457 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 458 | |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 459 | iState = CFWL_PartState_Hovered; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 460 | RepaintRect(rtItem); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 461 | } |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 462 | |
Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 463 | void CFWL_ScrollBar::OnTimerFired() { |
| 464 | m_pTimer.reset(); |
| 465 | if (!SendEvent()) { |
| 466 | m_pTimer = pdfium::MakeUnique<CFX_Timer>( |
| 467 | GetOwnerApp()->GetAdapterNative()->GetTimerHandler(), this, 0); |
Henrique Nakashima | 5a7e330 | 2018-03-08 20:41:59 +0000 | [diff] [blame] | 468 | } |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 469 | } |