| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fwl/core/ifwl_scrollbar.h" | 7 #include "xfa/fwl/core/ifwl_scrollbar.h" |
| 8 | 8 |
| 9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
| 10 #include "xfa/fwl/core/cfwl_message.h" | 10 #include "xfa/fwl/core/cfwl_message.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 m_bMinSize(FALSE), | 45 m_bMinSize(FALSE), |
| 46 m_bCustomLayout(false), | 46 m_bCustomLayout(false), |
| 47 m_fMinThumb(FWL_SCROLLBAR_MinThumb), | 47 m_fMinThumb(FWL_SCROLLBAR_MinThumb), |
| 48 m_Timer(this) { | 48 m_Timer(this) { |
| 49 m_rtClient.Reset(); | 49 m_rtClient.Reset(); |
| 50 m_rtThumb.Reset(); | 50 m_rtThumb.Reset(); |
| 51 m_rtMinBtn.Reset(); | 51 m_rtMinBtn.Reset(); |
| 52 m_rtMaxBtn.Reset(); | 52 m_rtMaxBtn.Reset(); |
| 53 m_rtMinTrack.Reset(); | 53 m_rtMinTrack.Reset(); |
| 54 m_rtMaxTrack.Reset(); | 54 m_rtMaxTrack.Reset(); |
| 55 | |
| 56 SetDelegate(pdfium::MakeUnique<CFWL_ScrollBarImpDelegate>(this)); | |
| 57 } | 55 } |
| 58 | 56 |
| 59 IFWL_ScrollBar::~IFWL_ScrollBar() {} | 57 IFWL_ScrollBar::~IFWL_ScrollBar() {} |
| 60 | 58 |
| 61 FWL_Type IFWL_ScrollBar::GetClassID() const { | 59 FWL_Type IFWL_ScrollBar::GetClassID() const { |
| 62 return FWL_Type::ScrollBar; | 60 return FWL_Type::ScrollBar; |
| 63 } | 61 } |
| 64 | 62 |
| 65 FWL_Error IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 63 FWL_Error IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { |
| 66 if (bAutoSize) { | 64 if (bAutoSize) { |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 FX_BOOL bRet = TRUE; | 560 FX_BOOL bRet = TRUE; |
| 563 CFWL_EvtScroll ev; | 561 CFWL_EvtScroll ev; |
| 564 ev.m_iScrollCode = dwCode; | 562 ev.m_iScrollCode = dwCode; |
| 565 ev.m_pSrcTarget = this; | 563 ev.m_pSrcTarget = this; |
| 566 ev.m_fPos = fPos; | 564 ev.m_fPos = fPos; |
| 567 ev.m_pRet = &bRet; | 565 ev.m_pRet = &bRet; |
| 568 DispatchEvent(&ev); | 566 DispatchEvent(&ev); |
| 569 return bRet; | 567 return bRet; |
| 570 } | 568 } |
| 571 | 569 |
| 572 CFWL_ScrollBarImpDelegate::CFWL_ScrollBarImpDelegate(IFWL_ScrollBar* pOwner) | 570 void IFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { |
| 573 : m_pOwner(pOwner) {} | |
| 574 | |
| 575 void CFWL_ScrollBarImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 576 if (!pMessage) | 571 if (!pMessage) |
| 577 return; | 572 return; |
| 578 | 573 |
| 579 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 574 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
| 580 if (dwMsgCode == CFWL_MessageType::Mouse) { | 575 if (dwMsgCode == CFWL_MessageType::Mouse) { |
| 581 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 576 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
| 582 switch (pMsg->m_dwCmd) { | 577 switch (pMsg->m_dwCmd) { |
| 583 case FWL_MouseCommand::LeftButtonDown: { | 578 case FWL_MouseCommand::LeftButtonDown: |
| 584 OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); | 579 OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); |
| 585 break; | 580 break; |
| 586 } | 581 case FWL_MouseCommand::LeftButtonUp: |
| 587 case FWL_MouseCommand::LeftButtonUp: { | |
| 588 OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); | 582 OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); |
| 589 break; | 583 break; |
| 590 } | 584 case FWL_MouseCommand::Move: |
| 591 case FWL_MouseCommand::Move: { | |
| 592 OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); | 585 OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); |
| 593 break; | 586 break; |
| 594 } | 587 case FWL_MouseCommand::Leave: |
| 595 case FWL_MouseCommand::Leave: { | |
| 596 OnMouseLeave(); | 588 OnMouseLeave(); |
| 597 break; | 589 break; |
| 598 } | 590 default: |
| 599 default: { break; } | 591 break; |
| 600 } | 592 } |
| 601 } else if (dwMsgCode == CFWL_MessageType::MouseWheel) { | 593 } else if (dwMsgCode == CFWL_MessageType::MouseWheel) { |
| 602 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage); | 594 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage); |
| 603 OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, | 595 OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, |
| 604 pMsg->m_fDeltaY); | 596 pMsg->m_fDeltaY); |
| 605 } | 597 } |
| 606 } | 598 } |
| 607 | 599 |
| 608 void CFWL_ScrollBarImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 600 void IFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, |
| 609 const CFX_Matrix* pMatrix) { | 601 const CFX_Matrix* pMatrix) { |
| 610 m_pOwner->DrawWidget(pGraphics, pMatrix); | 602 DrawWidget(pGraphics, pMatrix); |
| 611 } | 603 } |
| 612 | 604 |
| 613 void CFWL_ScrollBarImpDelegate::OnLButtonDown(uint32_t dwFlags, | 605 void IFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { |
| 614 FX_FLOAT fx, | 606 if (!IsEnabled()) |
| 615 FX_FLOAT fy) { | |
| 616 if (!m_pOwner->IsEnabled()) { | |
| 617 return; | 607 return; |
| 618 } | 608 |
| 619 m_pOwner->m_bMouseDown = TRUE; | 609 m_bMouseDown = TRUE; |
| 620 m_pOwner->SetGrab(TRUE); | 610 SetGrab(TRUE); |
| 621 m_pOwner->m_cpTrackPointX = fx; | 611 m_cpTrackPointX = fx; |
| 622 m_pOwner->m_cpTrackPointY = fy; | 612 m_cpTrackPointY = fy; |
| 623 m_pOwner->m_fLastTrackPos = m_pOwner->m_fTrackPos; | 613 m_fLastTrackPos = m_fTrackPos; |
| 624 if (m_pOwner->m_rtMinBtn.Contains(fx, fy)) { | 614 if (m_rtMinBtn.Contains(fx, fy)) |
| 625 DoMouseDown(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); | 615 DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy); |
| 626 } else { | 616 else if (m_rtThumb.Contains(fx, fy)) |
| 627 if (m_pOwner->m_rtThumb.Contains(fx, fy)) { | 617 DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy); |
| 628 DoMouseDown(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, | 618 else if (m_rtMaxBtn.Contains(fx, fy)) |
| 629 fy); | 619 DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); |
| 630 } else { | 620 else if (m_rtMinTrack.Contains(fx, fy)) |
| 631 if (m_pOwner->m_rtMaxBtn.Contains(fx, fy)) { | 621 DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy); |
| 632 DoMouseDown(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, | 622 else |
| 633 fy); | 623 DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); |
| 634 } else { | 624 |
| 635 if (m_pOwner->m_rtMinTrack.Contains(fx, fy)) { | 625 if (!SendEvent()) |
| 636 DoMouseDown(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, | 626 m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); |
| 637 fy); | |
| 638 } else { | |
| 639 DoMouseDown(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, | |
| 640 fy); | |
| 641 } | |
| 642 } | |
| 643 } | |
| 644 } | |
| 645 if (!m_pOwner->SendEvent()) | |
| 646 m_pOwner->m_pTimerInfo = | |
| 647 m_pOwner->m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); | |
| 648 } | 627 } |
| 649 | 628 |
| 650 void CFWL_ScrollBarImpDelegate::OnLButtonUp(uint32_t dwFlags, | 629 void IFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { |
| 651 FX_FLOAT fx, | 630 m_pTimerInfo->StopTimer(); |
| 652 FX_FLOAT fy) { | 631 m_bMouseDown = FALSE; |
| 653 m_pOwner->m_pTimerInfo->StopTimer(); | 632 DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy); |
| 654 m_pOwner->m_bMouseDown = FALSE; | 633 DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy); |
| 655 DoMouseUp(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); | 634 DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); |
| 656 DoMouseUp(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy); | 635 DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy); |
| 657 DoMouseUp(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy); | 636 DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); |
| 658 DoMouseUp(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, fy); | 637 SetGrab(FALSE); |
| 659 DoMouseUp(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, fy); | |
| 660 m_pOwner->SetGrab(FALSE); | |
| 661 } | 638 } |
| 662 | 639 |
| 663 void CFWL_ScrollBarImpDelegate::OnMouseMove(uint32_t dwFlags, | 640 void IFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { |
| 664 FX_FLOAT fx, | 641 DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy); |
| 665 FX_FLOAT fy) { | 642 DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy); |
| 666 DoMouseMove(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); | 643 DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); |
| 667 DoMouseMove(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy); | 644 DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy); |
| 668 DoMouseMove(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy); | 645 DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); |
| 669 DoMouseMove(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, fy); | |
| 670 DoMouseMove(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, fy); | |
| 671 } | 646 } |
| 672 | 647 |
| 673 void CFWL_ScrollBarImpDelegate::OnMouseLeave() { | 648 void IFWL_ScrollBar::OnMouseLeave() { |
| 674 DoMouseLeave(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState); | 649 DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); |
| 675 DoMouseLeave(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState); | 650 DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); |
| 676 DoMouseLeave(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState); | 651 DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); |
| 677 DoMouseLeave(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState); | 652 DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); |
| 678 DoMouseLeave(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState); | 653 DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); |
| 679 } | 654 } |
| 680 | 655 |
| 681 void CFWL_ScrollBarImpDelegate::OnMouseWheel(FX_FLOAT fx, | 656 void IFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx, |
| 682 FX_FLOAT fy, | 657 FX_FLOAT fy, |
| 683 uint32_t dwFlags, | 658 uint32_t dwFlags, |
| 684 FX_FLOAT fDeltaX, | 659 FX_FLOAT fDeltaX, |
| 685 FX_FLOAT fDeltaY) { | 660 FX_FLOAT fDeltaY) { |
| 686 m_pOwner->m_iMouseWheel = (int32_t)fDeltaX; | 661 m_iMouseWheel = (int32_t)fDeltaX; |
| 687 m_pOwner->SendEvent(); | 662 SendEvent(); |
| 688 m_pOwner->m_iMouseWheel = 0; | 663 m_iMouseWheel = 0; |
| 689 } | 664 } |
| 690 | 665 |
| 691 void CFWL_ScrollBarImpDelegate::DoMouseDown(int32_t iItem, | 666 void IFWL_ScrollBar::DoMouseDown(int32_t iItem, |
| 692 const CFX_RectF& rtItem, | 667 const CFX_RectF& rtItem, |
| 693 int32_t& iState, | 668 int32_t& iState, |
| 694 FX_FLOAT fx, | 669 FX_FLOAT fx, |
| 695 FX_FLOAT fy) { | 670 FX_FLOAT fy) { |
| 696 if (!rtItem.Contains(fx, fy)) { | 671 if (!rtItem.Contains(fx, fy)) |
| 697 return; | 672 return; |
| 698 } | 673 if (iState == CFWL_PartState_Pressed) |
| 699 if (iState == CFWL_PartState_Pressed) { | |
| 700 return; | 674 return; |
| 701 } | |
| 702 iState = CFWL_PartState_Pressed; | 675 iState = CFWL_PartState_Pressed; |
| 703 m_pOwner->Repaint(&rtItem); | 676 Repaint(&rtItem); |
| 704 } | 677 } |
| 705 | 678 |
| 706 void CFWL_ScrollBarImpDelegate::DoMouseUp(int32_t iItem, | 679 void IFWL_ScrollBar::DoMouseUp(int32_t iItem, |
| 707 const CFX_RectF& rtItem, | 680 const CFX_RectF& rtItem, |
| 708 int32_t& iState, | 681 int32_t& iState, |
| 709 FX_FLOAT fx, | 682 FX_FLOAT fx, |
| 710 FX_FLOAT fy) { | 683 FX_FLOAT fy) { |
| 711 int32_t iNewState = | 684 int32_t iNewState = |
| 712 rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; | 685 rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; |
| 713 if (iState == iNewState) { | 686 if (iState == iNewState) |
| 714 return; | 687 return; |
| 715 } | 688 |
| 716 iState = iNewState; | 689 iState = iNewState; |
| 717 m_pOwner->Repaint(&rtItem); | 690 Repaint(&rtItem); |
| 718 m_pOwner->OnScroll(FWL_SCBCODE_EndScroll, m_pOwner->m_fTrackPos); | 691 OnScroll(FWL_SCBCODE_EndScroll, m_fTrackPos); |
| 719 } | 692 } |
| 720 | 693 |
| 721 void CFWL_ScrollBarImpDelegate::DoMouseMove(int32_t iItem, | 694 void IFWL_ScrollBar::DoMouseMove(int32_t iItem, |
| 722 const CFX_RectF& rtItem, | 695 const CFX_RectF& rtItem, |
| 723 int32_t& iState, | 696 int32_t& iState, |
| 724 FX_FLOAT fx, | 697 FX_FLOAT fx, |
| 725 FX_FLOAT fy) { | 698 FX_FLOAT fy) { |
| 726 if (!m_pOwner->m_bMouseDown) { | 699 if (!m_bMouseDown) { |
| 727 int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered | 700 int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered |
| 728 : CFWL_PartState_Normal; | 701 : CFWL_PartState_Normal; |
| 729 if (iState == iNewState) { | 702 if (iState == iNewState) |
| 730 return; | 703 return; |
| 731 } | 704 |
| 732 iState = iNewState; | 705 iState = iNewState; |
| 733 m_pOwner->Repaint(&rtItem); | 706 Repaint(&rtItem); |
| 734 } else if ((2 == iItem) && | 707 } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { |
| 735 (m_pOwner->m_iThumbButtonState == CFWL_PartState_Pressed)) { | 708 FX_FLOAT fPos = GetTrackPointPos(fx, fy); |
| 736 FX_FLOAT fPos = m_pOwner->GetTrackPointPos(fx, fy); | 709 m_fTrackPos = fPos; |
| 737 m_pOwner->m_fTrackPos = fPos; | 710 OnScroll(FWL_SCBCODE_TrackPos, fPos); |
| 738 m_pOwner->OnScroll(FWL_SCBCODE_TrackPos, fPos); | |
| 739 } | 711 } |
| 740 } | 712 } |
| 741 | 713 |
| 742 void CFWL_ScrollBarImpDelegate::DoMouseLeave(int32_t iItem, | 714 void IFWL_ScrollBar::DoMouseLeave(int32_t iItem, |
| 743 const CFX_RectF& rtItem, | 715 const CFX_RectF& rtItem, |
| 744 int32_t& iState) { | 716 int32_t& iState) { |
| 745 if (iState == CFWL_PartState_Normal) { | 717 if (iState == CFWL_PartState_Normal) |
| 746 return; | 718 return; |
| 747 } | 719 |
| 748 iState = CFWL_PartState_Normal; | 720 iState = CFWL_PartState_Normal; |
| 749 m_pOwner->Repaint(&rtItem); | 721 Repaint(&rtItem); |
| 750 } | 722 } |
| 751 | 723 |
| 752 void CFWL_ScrollBarImpDelegate::DoMouseHover(int32_t iItem, | 724 void IFWL_ScrollBar::DoMouseHover(int32_t iItem, |
| 753 const CFX_RectF& rtItem, | 725 const CFX_RectF& rtItem, |
| 754 int32_t& iState) { | 726 int32_t& iState) { |
| 755 if (iState == CFWL_PartState_Hovered) { | 727 if (iState == CFWL_PartState_Hovered) |
| 756 return; | 728 return; |
| 757 } | 729 |
| 758 iState = CFWL_PartState_Hovered; | 730 iState = CFWL_PartState_Hovered; |
| 759 m_pOwner->Repaint(&rtItem); | 731 Repaint(&rtItem); |
| 760 } | 732 } |
| 761 | 733 |
| 762 IFWL_ScrollBar::Timer::Timer(IFWL_ScrollBar* pToolTip) : IFWL_Timer(pToolTip) {} | 734 IFWL_ScrollBar::Timer::Timer(IFWL_ScrollBar* pToolTip) : IFWL_Timer(pToolTip) {} |
| 763 | 735 |
| 764 void IFWL_ScrollBar::Timer::Run(IFWL_TimerInfo* pTimerInfo) { | 736 void IFWL_ScrollBar::Timer::Run(IFWL_TimerInfo* pTimerInfo) { |
| 765 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); | 737 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); |
| 766 | 738 |
| 767 if (pButton->m_pTimerInfo) | 739 if (pButton->m_pTimerInfo) |
| 768 pButton->m_pTimerInfo->StopTimer(); | 740 pButton->m_pTimerInfo->StopTimer(); |
| 769 | 741 |
| 770 if (!pButton->SendEvent()) | 742 if (!pButton->SendEvent()) |
| 771 pButton->m_pTimerInfo = StartTimer(0, true); | 743 pButton->m_pTimerInfo = StartTimer(0, true); |
| 772 } | 744 } |
| OLD | NEW |