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/cfwl_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 CFWL_Caret::CFWL_Caret(const CFWL_App* app, | |
25 std::unique_ptr<CFWL_WidgetProperties> properties, | |
26 CFWL_Widget* pOuter) | |
27 : CFWL_Widget(app, std::move(properties), pOuter), | |
28 m_pTimer(new CFWL_Caret::Timer(this)), | |
29 m_pTimerInfo(nullptr) { | |
30 SetStates(FWL_STATE_CAT_HightLight); | |
31 } | |
32 | |
33 CFWL_Caret::~CFWL_Caret() { | |
34 if (m_pTimerInfo) { | |
35 m_pTimerInfo->StopTimer(); | |
36 m_pTimerInfo = nullptr; | |
37 } | |
38 } | |
39 | |
40 FWL_Type CFWL_Caret::GetClassID() const { | |
41 return FWL_Type::Caret; | |
42 } | |
43 | |
44 void CFWL_Caret::Update() {} | |
45 | |
46 void CFWL_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 CFWL_Caret::ShowCaret() { | |
59 if (m_pTimerInfo) | |
60 m_pTimerInfo->StopTimer(); | |
61 m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); | |
62 RemoveStates(FWL_WGTSTATE_Invisible); | |
63 } | |
64 | |
65 void CFWL_Caret::HideCaret() { | |
66 if (m_pTimerInfo) { | |
67 m_pTimerInfo->StopTimer(); | |
68 m_pTimerInfo = nullptr; | |
69 } | |
70 SetStates(FWL_WGTSTATE_Invisible); | |
71 } | |
72 | |
73 void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, | |
74 IFWL_ThemeProvider* pTheme, | |
75 const CFX_Matrix* pMatrix) { | |
76 if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) | |
77 return; | |
78 | |
79 CFX_RectF rect = GetWidgetRect(); | |
80 rect.Set(0, 0, rect.width, rect.height); | |
81 | |
82 CFWL_ThemeBackground param; | |
83 param.m_pWidget = this; | |
84 param.m_pGraphics = pGraphics; | |
85 param.m_rtPart = rect; | |
86 param.m_iPart = CFWL_Part::Background; | |
87 param.m_dwStates = CFWL_PartState_HightLight; | |
88 if (pMatrix) | |
89 param.m_matrix.Concat(*pMatrix); | |
90 pTheme->DrawBackground(¶m); | |
91 } | |
92 | |
93 void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} | |
94 | |
95 void CFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics, | |
96 const CFX_Matrix* pMatrix) { | |
97 DrawWidget(pGraphics, pMatrix); | |
98 } | |
99 | |
100 CFWL_Caret::Timer::Timer(CFWL_Caret* pCaret) : CFWL_Timer(pCaret) {} | |
101 | |
102 void CFWL_Caret::Timer::Run(CFWL_TimerInfo* pTimerInfo) { | |
103 CFWL_Caret* pCaret = static_cast<CFWL_Caret*>(m_pWidget); | |
104 if (!(pCaret->GetStates() & FWL_STATE_CAT_HightLight)) | |
105 pCaret->SetStates(FWL_STATE_CAT_HightLight); | |
106 else | |
107 pCaret->RemoveStates(FWL_STATE_CAT_HightLight); | |
108 | |
109 CFX_RectF rt = pCaret->GetWidgetRect(); | |
110 rt.Set(0, 0, rt.width + 1, rt.height); | |
111 pCaret->Repaint(&rt); | |
112 } | |
OLD | NEW |