OLD | NEW |
| (Empty) |
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 | |
7 #include "xfa/fwl/core/ifwl_caret.h" | |
8 | |
9 #include <utility> | |
10 | |
11 #include "third_party/base/ptr_util.h" | |
12 #include "xfa/fwl/core/cfwl_notedriver.h" | |
13 #include "xfa/fwl/core/cfwl_themebackground.h" | |
14 #include "xfa/fwl/core/cfwl_timerinfo.h" | |
15 #include "xfa/fwl/core/cfwl_widgetproperties.h" | |
16 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
17 | |
18 namespace { | |
19 | |
20 const uint32_t kFrequency = 400; | |
21 | |
22 } // namespace | |
23 | |
24 IFWL_Caret::IFWL_Caret(const CFWL_App* app, | |
25 std::unique_ptr<CFWL_WidgetProperties> properties, | |
26 IFWL_Widget* pOuter) | |
27 : IFWL_Widget(app, std::move(properties), pOuter), | |
28 m_pTimer(new IFWL_Caret::Timer(this)), | |
29 m_pTimerInfo(nullptr) { | |
30 SetStates(FWL_STATE_CAT_HightLight); | |
31 } | |
32 | |
33 IFWL_Caret::~IFWL_Caret() { | |
34 if (m_pTimerInfo) { | |
35 m_pTimerInfo->StopTimer(); | |
36 m_pTimerInfo = nullptr; | |
37 } | |
38 } | |
39 | |
40 FWL_Type IFWL_Caret::GetClassID() const { | |
41 return FWL_Type::Caret; | |
42 } | |
43 | |
44 void IFWL_Caret::Update() {} | |
45 | |
46 void IFWL_Caret::DrawWidget(CFX_Graphics* pGraphics, | |
47 const CFX_Matrix* pMatrix) { | |
48 if (!pGraphics) | |
49 return; | |
50 if (!m_pProperties->m_pThemeProvider) | |
51 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
52 if (!m_pProperties->m_pThemeProvider) | |
53 return; | |
54 | |
55 DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); | |
56 } | |
57 | |
58 void IFWL_Caret::ShowCaret(bool bFlag) { | |
59 if (m_pTimerInfo) { | |
60 m_pTimerInfo->StopTimer(); | |
61 m_pTimerInfo = nullptr; | |
62 } | |
63 if (bFlag) | |
64 m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); | |
65 | |
66 SetStates(FWL_WGTSTATE_Invisible, !bFlag); | |
67 } | |
68 | |
69 void IFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, | |
70 IFWL_ThemeProvider* pTheme, | |
71 const CFX_Matrix* pMatrix) { | |
72 if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) | |
73 return; | |
74 | |
75 CFX_RectF rect; | |
76 GetWidgetRect(rect); | |
77 rect.Set(0, 0, rect.width, rect.height); | |
78 | |
79 CFWL_ThemeBackground param; | |
80 param.m_pWidget = this; | |
81 param.m_pGraphics = pGraphics; | |
82 param.m_rtPart = rect; | |
83 param.m_iPart = CFWL_Part::Background; | |
84 param.m_dwStates = CFWL_PartState_HightLight; | |
85 if (pMatrix) | |
86 param.m_matrix.Concat(*pMatrix); | |
87 pTheme->DrawBackground(¶m); | |
88 } | |
89 | |
90 void IFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} | |
91 | |
92 void IFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics, | |
93 const CFX_Matrix* pMatrix) { | |
94 DrawWidget(pGraphics, pMatrix); | |
95 } | |
96 | |
97 IFWL_Caret::Timer::Timer(IFWL_Caret* pCaret) : CFWL_Timer(pCaret) {} | |
98 | |
99 void IFWL_Caret::Timer::Run(CFWL_TimerInfo* pTimerInfo) { | |
100 IFWL_Caret* pCaret = static_cast<IFWL_Caret*>(m_pWidget); | |
101 pCaret->SetStates(FWL_STATE_CAT_HightLight, | |
102 !(pCaret->GetStates() & FWL_STATE_CAT_HightLight)); | |
103 | |
104 CFX_RectF rt; | |
105 pCaret->GetWidgetRect(rt); | |
106 rt.Set(0, 0, rt.width + 1, rt.height); | |
107 pCaret->Repaint(&rt); | |
108 } | |
OLD | NEW |