| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
| dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 7 | #include "xfa/fwl/cfwl_caret.h" |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
| Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
| Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 11 | #include "xfa/fwl/cfwl_app.h" |
| dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 12 | #include "xfa/fwl/cfwl_notedriver.h" |
| 13 | #include "xfa/fwl/cfwl_themebackground.h" |
| dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 14 | #include "xfa/fwl/ifwl_themeprovider.h" |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 15 | |
| dsinclair | c64b76c | 2016-11-14 09:01:37 -0800 | [diff] [blame] | 16 | namespace { |
| 17 | |
| Henrique Nakashima | 3294220 | 2018-04-04 20:48:50 +0000 | [diff] [blame] | 18 | const uint32_t kBlinkPeriodMs = 600; |
| dsinclair | c64b76c | 2016-11-14 09:01:37 -0800 | [diff] [blame] | 19 | |
| Dan Sinclair | 951b111 | 2017-10-02 10:38:55 -0400 | [diff] [blame] | 20 | constexpr int kStateHighlight = (1 << 0); |
| 21 | |
| dsinclair | c64b76c | 2016-11-14 09:01:37 -0800 | [diff] [blame] | 22 | } // namespace |
| 23 | |
| Tom Sepez | 0a9d974 | 2020-09-01 21:40:52 +0000 | [diff] [blame] | 24 | CFWL_Caret::CFWL_Caret(CFWL_App* app, |
| Tom Sepez | 5f4456e | 2020-08-14 20:22:02 +0000 | [diff] [blame] | 25 | const Properties& properties, |
| dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 26 | CFWL_Widget* pOuter) |
| Tom Sepez | 5f4456e | 2020-08-14 20:22:02 +0000 | [diff] [blame] | 27 | : CFWL_Widget(app, properties, pOuter) { |
| Dan Sinclair | 951b111 | 2017-10-02 10:38:55 -0400 | [diff] [blame] | 28 | SetStates(kStateHighlight); |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 29 | } |
| thestig | 495bda1 | 2016-04-28 17:29:19 -0700 | [diff] [blame] | 30 | |
| Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 31 | CFWL_Caret::~CFWL_Caret() = default; |
| dsinclair | 6fe8795 | 2016-11-01 18:48:19 -0700 | [diff] [blame] | 32 | |
| dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 33 | FWL_Type CFWL_Caret::GetClassID() const { |
| dsinclair | 6fe8795 | 2016-11-01 18:48:19 -0700 | [diff] [blame] | 34 | return FWL_Type::Caret; |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 35 | } |
| dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 36 | |
| dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 37 | void CFWL_Caret::Update() {} |
| dsinclair | e36430e | 2016-11-23 07:36:00 -0800 | [diff] [blame] | 38 | |
| Tom Sepez | 45eae7b | 2020-10-13 22:50:53 +0000 | [diff] [blame] | 39 | void CFWL_Caret::DrawWidget(CFGAS_GEGraphics* pGraphics, |
| Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 40 | const CFX_Matrix& matrix) { |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 41 | if (!pGraphics) |
| dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 42 | return; |
| dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 43 | |
| Tom Sepez | 235683e | 2021-04-14 00:19:48 +0000 | [diff] [blame] | 44 | DrawCaretBK(pGraphics, matrix); |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 45 | } |
| dsinclair | 55fa356 | 2016-05-04 14:24:53 -0700 | [diff] [blame] | 46 | |
| dsinclair | 919c084 | 2016-12-07 17:12:59 -0800 | [diff] [blame] | 47 | void CFWL_Caret::ShowCaret() { |
| Tom Sepez | c03a0ea | 2020-08-18 16:24:34 +0000 | [diff] [blame] | 48 | m_pTimer = std::make_unique<CFX_Timer>(GetFWLApp()->GetTimerHandler(), this, |
| 49 | kBlinkPeriodMs); |
| Tom Sepez | ca44098 | 2021-07-21 01:13:13 +0000 | [diff] [blame] | 50 | RemoveStates(FWL_STATE_WGT_Invisible); |
| Henrique Nakashima | ecc1b27 | 2018-04-25 22:01:14 +0000 | [diff] [blame] | 51 | SetStates(kStateHighlight); |
| dsinclair | 919c084 | 2016-12-07 17:12:59 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void CFWL_Caret::HideCaret() { |
| Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 55 | m_pTimer.reset(); |
| Tom Sepez | ca44098 | 2021-07-21 01:13:13 +0000 | [diff] [blame] | 56 | SetStates(FWL_STATE_WGT_Invisible); |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 57 | } |
| dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 58 | |
| Tom Sepez | 45eae7b | 2020-10-13 22:50:53 +0000 | [diff] [blame] | 59 | void CFWL_Caret::DrawCaretBK(CFGAS_GEGraphics* pGraphics, |
| Tom Sepez | 235683e | 2021-04-14 00:19:48 +0000 | [diff] [blame] | 60 | const CFX_Matrix& mtMatrix) { |
| Tom Sepez | 5f4456e | 2020-08-14 20:22:02 +0000 | [diff] [blame] | 61 | if (!(m_Properties.m_dwStates & kStateHighlight)) |
| dsinclair | d4f24c7 | 2016-11-16 08:44:31 -0800 | [diff] [blame] | 62 | return; |
| 63 | |
| Tom Sepez | 693d552 | 2021-05-10 19:59:26 +0000 | [diff] [blame] | 64 | CFWL_ThemeBackground param(this, pGraphics); |
| Tom Sepez | 8e8c2ce | 2020-05-06 20:01:34 +0000 | [diff] [blame] | 65 | param.m_PartRect = CFX_RectF(0, 0, GetWidgetRect().Size()); |
| Lei Zhang | 58842d1 | 2021-06-05 01:38:48 +0000 | [diff] [blame] | 66 | param.m_iPart = CFWL_ThemePart::Part::kBackground; |
| dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 67 | param.m_dwStates = CFWL_PartState_HightLight; |
| Tom Sepez | 693d552 | 2021-05-10 19:59:26 +0000 | [diff] [blame] | 68 | param.m_matrix = mtMatrix; |
| Tom Sepez | a911672 | 2020-08-13 22:18:18 +0000 | [diff] [blame] | 69 | GetThemeProvider()->DrawBackground(param); |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 72 | void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} |
| dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 73 | |
| Tom Sepez | 45eae7b | 2020-10-13 22:50:53 +0000 | [diff] [blame] | 74 | void CFWL_Caret::OnDrawWidget(CFGAS_GEGraphics* pGraphics, |
| Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 75 | const CFX_Matrix& matrix) { |
| 76 | DrawWidget(pGraphics, matrix); |
| dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 79 | void CFWL_Caret::OnTimerFired() { |
| 80 | if (!(GetStates() & kStateHighlight)) |
| 81 | SetStates(kStateHighlight); |
| dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 82 | else |
| Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 83 | RemoveStates(kStateHighlight); |
| tsepez | 6f4f233 | 2016-06-06 13:23:55 -0700 | [diff] [blame] | 84 | |
| Tom Sepez | 3e5e563e | 2019-08-12 17:54:25 +0000 | [diff] [blame] | 85 | CFX_RectF rt = GetWidgetRect(); |
| 86 | RepaintRect(CFX_RectF(0, 0, rt.width + 1, rt.height)); |
| Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 87 | } |