7#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
15#include "core/fxge/cfx_fillrenderoptions.h"
16#include "core/fxge/cfx_path.h"
17#include "core/fxge/cfx_renderdevice.h"
18#include "fpdfsdk/pwl/cpwl_wnd.h"
19#include "third_party/base/check.h"
23constexpr float kButtonWidth = 9.0f;
24constexpr float kPosButtonMinWidth = 2.0f;
110 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
122 m_pMinButton.ExtractAsDangling();
123 m_pMaxButton.ExtractAsDangling();
124 m_pPosButton.ExtractAsDangling();
133 kButtonWidth * 2 + kPosButtonMinWidth + 2)) {
140 (rcClient
.top - rcClient
.bottom - kPosButtonMinWidth - 2) / 2;
152 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
154 m_pMinButton->Move(rcMinButton,
true,
false);
155 if (!this_observed) {
160 m_pMaxButton->Move(rcMaxButton,
true,
false);
161 if (!this_observed) {
166 return MovePosButton(
false);
178 &mtUser2Device
, CFX_PointF(rectWnd
.left + 2.0f, rectWnd
.top - 2.0f)
,
183 &mtUser2Device
, CFX_PointF(rectWnd
.right - 2.0f, rectWnd
.top - 2.0f)
,
190 const CFX_PointF& point) {
201 if (m_pPosButton && m_pPosButton->IsVisible()) {
206 rcClient
.top - kButtonWidth
);
216 if (!MovePosButton(
true))
218 NotifyScrollWindow();
223 if (!MovePosButton(
true))
225 NotifyScrollWindow();
233 const CFX_PointF& point) {
245 m_bMouseDown =
false;
250 if (info
== m_OriginInfo)
266 if (child == m_pMinButton)
267 OnMinButtonLBDown(pos);
268 else if (child == m_pMaxButton)
269 OnMaxButtonLBDown(pos);
270 else if (child == m_pPosButton)
271 OnPosButtonLBDown(pos);
275 if (child == m_pMinButton)
276 OnMinButtonLBUp(pos);
277 else if (child == m_pMaxButton)
278 OnMaxButtonLBUp(pos);
279 else if (child == m_pPosButton)
280 OnPosButtonLBUp(pos);
284 if (child == m_pMinButton)
285 OnMinButtonMouseMove(pos);
286 else if (child == m_pMaxButton)
287 OnMaxButtonMouseMove(pos);
288 else if (child == m_pPosButton)
289 OnPosButtonMouseMove(pos);
292void CPWL_ScrollBar::CreateButtons(
const CreateParams& cp) {
299 auto pButton = std::make_unique<CPWL_SBButton>(
300 scp, CloneAttachedData(), CPWL_SBButton::Type::kMinButton);
301 m_pMinButton = pButton.get();
302 AddChild(std::move(pButton));
303 m_pMinButton->Realize();
307 auto pButton = std::make_unique<CPWL_SBButton>(
308 scp, CloneAttachedData(), CPWL_SBButton::Type::kMaxButton);
309 m_pMaxButton = pButton.get();
310 AddChild(std::move(pButton));
311 m_pMaxButton->Realize();
315 auto pButton = std::make_unique<CPWL_SBButton>(
316 scp, CloneAttachedData(), CPWL_SBButton::Type::kPosButton);
317 m_pPosButton = pButton.get();
318 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
319 if (m_pPosButton->SetVisible(
false) && this_observed) {
320 AddChild(std::move(pButton));
321 m_pPosButton->Realize();
330void CPWL_ScrollBar::SetScrollRange(
float fMin,
332 float fClientWidth) {
336 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
341 (
void)m_pPosButton->SetVisible(
false);
347 if (!m_pPosButton->SetVisible(
true) || !this_observed) {
351 (
void)MovePosButton(
true);
356void CPWL_ScrollBar::SetScrollPos(
float fPos) {
360 (
void)MovePosButton(
true);
366void CPWL_ScrollBar::SetScrollStep(
float fBigStep,
float fSmallStep) {
371bool CPWL_ScrollBar::MovePosButton(
bool bRefresh) {
372 DCHECK(m_pMinButton);
373 DCHECK(m_pMaxButton);
375 if (m_pPosButton->IsVisible()) {
381 fBottom = fTop - kPosButtonMinWidth;
385 fTop = fBottom + kPosButtonMinWidth;
391 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
392 m_pPosButton->Move(rcPosButton,
true, bRefresh);
393 if (!this_observed) {
401void CPWL_ScrollBar::OnMinButtonLBDown(
const CFX_PointF& point) {
403 if (!MovePosButton(
true))
406 NotifyScrollWindow();
408 m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(),
this, 100);
411void CPWL_ScrollBar::OnMinButtonLBUp(
const CFX_PointF& point) {}
413void CPWL_ScrollBar::OnMinButtonMouseMove(
const CFX_PointF& point) {}
415void CPWL_ScrollBar::OnMaxButtonLBDown(
const CFX_PointF& point) {
417 if (!MovePosButton(
true))
420 NotifyScrollWindow();
422 m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(),
this, 100);
425void CPWL_ScrollBar::OnMaxButtonLBUp(
const CFX_PointF& point) {}
427void CPWL_ScrollBar::OnMaxButtonMouseMove(
const CFX_PointF& point) {}
429void CPWL_ScrollBar::OnPosButtonLBDown(
const CFX_PointF& point) {
435 m_fOldPosButton = rcPosButton
.top;
439void CPWL_ScrollBar::OnPosButtonLBUp(
const CFX_PointF& point) {
440 m_bMouseDown =
false;
443void CPWL_ScrollBar::OnPosButtonMouseMove(
const CFX_PointF& point) {
444 if (fabs(point.y - m_nOldPos) < 1)
448 float fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos);
461 if (!MovePosButton(
true))
464 NotifyScrollWindow();
469void CPWL_ScrollBar::NotifyScrollWindow() {
480 if (!m_pMinButton || !m_pMaxButton)
489 if (rcClient
.top - rcClient
.bottom > fMinHeight + fMaxHeight + 2) {
501float CPWL_ScrollBar::TrueToFace(
float fTrue) {
504 fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
505 return rcPosArea
.top -
506 fTrue * (rcPosArea
.top - rcPosArea
.bottom) / fFactWidth;
509float CPWL_ScrollBar::FaceToTrue(
float fFace) {
512 fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
513 return (rcPosArea
.top - fFace) * fFactWidth /
528 if (sTemp
== m_sData)
531 if (!MovePosButton(
true))
534 NotifyScrollWindow();
bool Contains(const CFX_PointF &point) const
constexpr CFX_FloatRect(float l, float b, float r, float t)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
void DrawStrokeLine(const CFX_Matrix *pUser2Device, const CFX_PointF &ptMoveTo, const CFX_PointF &ptLineTo, const FX_COLORREF &color, float fWidth)
virtual void ScrollWindowVertically(float pos)
CFX_Color GetBackgroundColor() const
bool HasFlag(uint32_t dwFlags) const
virtual CFX_FloatRect GetClientRect() const
CFX_FloatRect GetWindowRect() const
CPWL_Wnd * GetParentWindow() const
void SetTransparency(int32_t nTransparency)
virtual bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
CreateParams * GetCreationParams()
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
virtual bool SetVisible(bool bVisible)
int32_t GetTransparency()
virtual bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
#define PWS_AUTOTRANSPARENT
#define PWS_NOREFRESHCLIP
#define FXSYS_IsFloatBigger(fa, fb)
#define FXSYS_IsFloatEqual(fa, fb)
#define FXSYS_IsFloatSmaller(fa, fb)
void Set(float min, float max)