blob: 417901d0df3d081c735fc34591c1d98ee5fae158 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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
dsinclair447b1f32016-12-08 10:06:32 -08007#include "xfa/fwl/cfwl_caret.h"
Dan Sinclair1770c022016-03-14 14:14:16 -04008
Dan Sinclair85c8e7f2016-11-21 13:50:32 -05009#include <utility>
10
Tom Sepez3e5e563e2019-08-12 17:54:25 +000011#include "xfa/fwl/cfwl_app.h"
dsinclair447b1f32016-12-08 10:06:32 -080012#include "xfa/fwl/cfwl_notedriver.h"
13#include "xfa/fwl/cfwl_themebackground.h"
dsinclair447b1f32016-12-08 10:06:32 -080014#include "xfa/fwl/ifwl_themeprovider.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040015
dsinclairc64b76c2016-11-14 09:01:37 -080016namespace {
17
Henrique Nakashima32942202018-04-04 20:48:50 +000018const uint32_t kBlinkPeriodMs = 600;
dsinclairc64b76c2016-11-14 09:01:37 -080019
Dan Sinclair951b1112017-10-02 10:38:55 -040020constexpr int kStateHighlight = (1 << 0);
21
dsinclairc64b76c2016-11-14 09:01:37 -080022} // namespace
23
Tom Sepez0a9d9742020-09-01 21:40:52 +000024CFWL_Caret::CFWL_Caret(CFWL_App* app,
Tom Sepez5f4456e2020-08-14 20:22:02 +000025 const Properties& properties,
dsinclair2c489cc2016-11-23 16:17:20 -080026 CFWL_Widget* pOuter)
Tom Sepez5f4456e2020-08-14 20:22:02 +000027 : CFWL_Widget(app, properties, pOuter) {
Dan Sinclair951b1112017-10-02 10:38:55 -040028 SetStates(kStateHighlight);
Dan Sinclair1770c022016-03-14 14:14:16 -040029}
thestig495bda12016-04-28 17:29:19 -070030
Tom Sepez3e5e563e2019-08-12 17:54:25 +000031CFWL_Caret::~CFWL_Caret() = default;
dsinclair6fe87952016-11-01 18:48:19 -070032
dsinclair0ce11ee2016-11-23 16:03:10 -080033FWL_Type CFWL_Caret::GetClassID() const {
dsinclair6fe87952016-11-01 18:48:19 -070034 return FWL_Type::Caret;
Dan Sinclair1770c022016-03-14 14:14:16 -040035}
dsinclairfb505592016-10-20 06:44:03 -070036
dsinclair0ce11ee2016-11-23 16:03:10 -080037void CFWL_Caret::Update() {}
dsinclaire36430e2016-11-23 07:36:00 -080038
Tom Sepez45eae7b2020-10-13 22:50:53 +000039void CFWL_Caret::DrawWidget(CFGAS_GEGraphics* pGraphics,
Lei Zhang4b472142017-08-17 14:30:08 -070040 const CFX_Matrix& matrix) {
Dan Sinclair1770c022016-03-14 14:14:16 -040041 if (!pGraphics)
dsinclair98329fe2016-11-10 09:40:14 -080042 return;
dsinclairc777f482016-05-04 17:57:03 -070043
Tom Sepez235683e2021-04-14 00:19:48 +000044 DrawCaretBK(pGraphics, matrix);
Dan Sinclair1770c022016-03-14 14:14:16 -040045}
dsinclair55fa3562016-05-04 14:24:53 -070046
dsinclair919c0842016-12-07 17:12:59 -080047void CFWL_Caret::ShowCaret() {
Tom Sepezc03a0ea2020-08-18 16:24:34 +000048 m_pTimer = std::make_unique<CFX_Timer>(GetFWLApp()->GetTimerHandler(), this,
49 kBlinkPeriodMs);
Tom Sepezca440982021-07-21 01:13:13 +000050 RemoveStates(FWL_STATE_WGT_Invisible);
Henrique Nakashimaecc1b272018-04-25 22:01:14 +000051 SetStates(kStateHighlight);
dsinclair919c0842016-12-07 17:12:59 -080052}
53
54void CFWL_Caret::HideCaret() {
Tom Sepez3e5e563e2019-08-12 17:54:25 +000055 m_pTimer.reset();
Tom Sepezca440982021-07-21 01:13:13 +000056 SetStates(FWL_STATE_WGT_Invisible);
Dan Sinclair1770c022016-03-14 14:14:16 -040057}
dsinclairfb505592016-10-20 06:44:03 -070058
Tom Sepez45eae7b2020-10-13 22:50:53 +000059void CFWL_Caret::DrawCaretBK(CFGAS_GEGraphics* pGraphics,
Tom Sepez235683e2021-04-14 00:19:48 +000060 const CFX_Matrix& mtMatrix) {
Tom Sepez5f4456e2020-08-14 20:22:02 +000061 if (!(m_Properties.m_dwStates & kStateHighlight))
dsinclaird4f24c72016-11-16 08:44:31 -080062 return;
63
Tom Sepez693d5522021-05-10 19:59:26 +000064 CFWL_ThemeBackground param(this, pGraphics);
Tom Sepez8e8c2ce2020-05-06 20:01:34 +000065 param.m_PartRect = CFX_RectF(0, 0, GetWidgetRect().Size());
Lei Zhang58842d12021-06-05 01:38:48 +000066 param.m_iPart = CFWL_ThemePart::Part::kBackground;
dsinclairf87058d2016-04-21 06:22:11 -070067 param.m_dwStates = CFWL_PartState_HightLight;
Tom Sepez693d5522021-05-10 19:59:26 +000068 param.m_matrix = mtMatrix;
Tom Sepeza9116722020-08-13 22:18:18 +000069 GetThemeProvider()->DrawBackground(param);
Dan Sinclair1770c022016-03-14 14:14:16 -040070}
71
dsinclair0ce11ee2016-11-23 16:03:10 -080072void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {}
dsinclair3b3ce1a2016-11-02 14:51:25 -070073
Tom Sepez45eae7b2020-10-13 22:50:53 +000074void CFWL_Caret::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
Lei Zhang4b472142017-08-17 14:30:08 -070075 const CFX_Matrix& matrix) {
76 DrawWidget(pGraphics, matrix);
dsinclair3b3ce1a2016-11-02 14:51:25 -070077}
78
Tom Sepez3e5e563e2019-08-12 17:54:25 +000079void CFWL_Caret::OnTimerFired() {
80 if (!(GetStates() & kStateHighlight))
81 SetStates(kStateHighlight);
dsinclair7fa190d2016-12-07 17:23:28 -080082 else
Tom Sepez3e5e563e2019-08-12 17:54:25 +000083 RemoveStates(kStateHighlight);
tsepez6f4f2332016-06-06 13:23:55 -070084
Tom Sepez3e5e563e2019-08-12 17:54:25 +000085 CFX_RectF rt = GetWidgetRect();
86 RepaintRect(CFX_RectF(0, 0, rt.width + 1, rt.height));
Dan Sinclair1770c022016-03-14 14:14:16 -040087}