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