1 // Copyright 2017 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 #include "fpdfsdk/formfiller/cffl_button.h"
8
9 #include "fpdfsdk/cpdfsdk_widget.h"
10 #include "third_party/base/check.h"
11
CFFL_Button(CFFL_InteractiveFormFiller * pFormFiller,CPDFSDK_Widget * pWidget)12 CFFL_Button::CFFL_Button(CFFL_InteractiveFormFiller* pFormFiller,
13 CPDFSDK_Widget* pWidget)
14 : CFFL_FormField(pFormFiller, pWidget) {}
15
16 CFFL_Button::~CFFL_Button() = default;
17
OnMouseEnter(CPDFSDK_PageView * pPageView)18 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView) {
19 m_bMouseIn = true;
20 InvalidateRect(GetViewBBox(pPageView));
21 }
22
OnMouseExit(CPDFSDK_PageView * pPageView)23 void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView) {
24 m_bMouseIn = false;
25 InvalidateRect(GetViewBBox(pPageView));
26 m_pTimer.reset();
27 DCHECK(m_pWidget);
28 }
29
OnLButtonDown(CPDFSDK_PageView * pPageView,CPDFSDK_Widget * pWidget,Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)30 bool CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView,
31 CPDFSDK_Widget* pWidget,
32 Mask<FWL_EVENTFLAG> nFlags,
33 const CFX_PointF& point) {
34 if (!pWidget->GetRect().Contains(point))
35 return false;
36
37 m_bMouseDown = true;
38 m_bValid = true;
39 InvalidateRect(GetViewBBox(pPageView));
40 return true;
41 }
42
OnLButtonUp(CPDFSDK_PageView * pPageView,CPDFSDK_Widget * pWidget,Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)43 bool CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView,
44 CPDFSDK_Widget* pWidget,
45 Mask<FWL_EVENTFLAG> nFlags,
46 const CFX_PointF& point) {
47 if (!pWidget->GetRect().Contains(point))
48 return false;
49
50 m_bMouseDown = false;
51 InvalidateRect(GetViewBBox(pPageView));
52 return true;
53 }
54
OnMouseMove(CPDFSDK_PageView * pPageView,Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)55 bool CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView,
56 Mask<FWL_EVENTFLAG> nFlags,
57 const CFX_PointF& point) {
58 return true;
59 }
60
OnDraw(CPDFSDK_PageView * pPageView,CPDFSDK_Widget * pWidget,CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device)61 void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView,
62 CPDFSDK_Widget* pWidget,
63 CFX_RenderDevice* pDevice,
64 const CFX_Matrix& mtUser2Device) {
65 DCHECK(pPageView);
66 if (!pWidget->IsPushHighlighted()) {
67 pWidget->DrawAppearance(pDevice, mtUser2Device,
68 CPDF_Annot::AppearanceMode::kNormal);
69 return;
70 }
71 if (m_bMouseDown) {
72 if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode::kDown)) {
73 pWidget->DrawAppearance(pDevice, mtUser2Device,
74 CPDF_Annot::AppearanceMode::kDown);
75 } else {
76 pWidget->DrawAppearance(pDevice, mtUser2Device,
77 CPDF_Annot::AppearanceMode::kNormal);
78 }
79 return;
80 }
81 if (m_bMouseIn) {
82 if (pWidget->IsWidgetAppearanceValid(
83 CPDF_Annot::AppearanceMode::kRollover)) {
84 pWidget->DrawAppearance(pDevice, mtUser2Device,
85 CPDF_Annot::AppearanceMode::kRollover);
86 } else {
87 pWidget->DrawAppearance(pDevice, mtUser2Device,
88 CPDF_Annot::AppearanceMode::kNormal);
89 }
90 return;
91 }
92
93 pWidget->DrawAppearance(pDevice, mtUser2Device,
94 CPDF_Annot::AppearanceMode::kNormal);
95 }
96
OnDrawDeactive(CPDFSDK_PageView * pPageView,CPDFSDK_Widget * pWidget,CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device)97 void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView,
98 CPDFSDK_Widget* pWidget,
99 CFX_RenderDevice* pDevice,
100 const CFX_Matrix& mtUser2Device) {
101 OnDraw(pPageView, pWidget, pDevice, mtUser2Device);
102 }
103