From bfeab62b37a701dc82f180e49d26c602f96f96f9 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Tue, 6 Feb 2018 21:36:45 +0000 Subject: Fix caret not appearing in XFA Edits. This makes the caret appear (again?), blink, and fixes its positioning to be a little spaced from the last character. Known issue: when the edit is empty, the caret is not necessarily aligned with where the text will be. Bug: chromium:592750 Change-Id: I950b0ea236db8855c6ed50f48ec1935d97e6ccf8 Reviewed-on: https://pdfium-review.googlesource.com/25451 Reviewed-by: dsinclair Commit-Queue: Henrique Nakashima --- xfa/fwl/cfwl_caret.cpp | 12 ++++++++---- xfa/fwl/cfwl_edit.cpp | 19 +++++++++++++------ xfa/fwl/cfwl_timer.cpp | 8 +++++--- xfa/fwl/cfwl_timer.h | 4 ++++ xfa/fwl/ifwl_adaptertimermgr.h | 1 + 5 files changed, 31 insertions(+), 13 deletions(-) (limited to 'xfa/fwl') diff --git a/xfa/fwl/cfwl_caret.cpp b/xfa/fwl/cfwl_caret.cpp index cd85041d92..03c8ffde68 100644 --- a/xfa/fwl/cfwl_caret.cpp +++ b/xfa/fwl/cfwl_caret.cpp @@ -58,17 +58,21 @@ void CFWL_Caret::DrawWidget(CXFA_Graphics* pGraphics, } void CFWL_Caret::ShowCaret() { - if (m_pTimerInfo) - m_pTimerInfo->StopTimer(); + if (m_pTimerInfo) { + CFWL_TimerInfo* pOldTimerInfo = m_pTimerInfo.Release(); + pOldTimerInfo->StopTimer(); + } + m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); RemoveStates(FWL_WGTSTATE_Invisible); } void CFWL_Caret::HideCaret() { if (m_pTimerInfo) { - m_pTimerInfo->StopTimer(); - m_pTimerInfo = nullptr; + CFWL_TimerInfo* pOldTimerInfo = m_pTimerInfo.Release(); + pOldTimerInfo->StopTimer(); } + SetStates(FWL_WGTSTATE_Invisible); } diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp index 960ec9967a..051c39f74e 100644 --- a/xfa/fwl/cfwl_edit.cpp +++ b/xfa/fwl/cfwl_edit.cpp @@ -79,7 +79,6 @@ CFWL_Edit::CFWL_Edit(const CFWL_App* app, m_rtEngine.Reset(); m_rtStatic.Reset(); - InitCaret(); m_EdtEngine.SetDelegate(this); } @@ -1065,8 +1064,14 @@ bool CFWL_Edit::ValidateNumberChar(wchar_t cNum) { } void CFWL_Edit::InitCaret() { - m_pCaret.reset(); - m_rtCaret = CFX_RectF(); + if (m_pCaret) + return; + + m_pCaret = pdfium::MakeUnique( + m_pOwnerApp.Get(), pdfium::MakeUnique(), this); + m_pCaret->SetParent(this); + m_pCaret->SetStates(m_pProperties->m_dwStates); + UpdateCursorRect(); } void CFWL_Edit::UpdateCursorRect() { @@ -1076,10 +1081,12 @@ void CFWL_Edit::UpdateCursorRect() { m_EdtEngine.GetCharacterInfo(m_CursorPosition); // TODO(dsinclair): This should handle bidi level ... - if (m_rtCaret.width == 0 && m_rtCaret.left > 1.0f) - m_rtCaret.left -= 1.0f; - m_rtCaret.width = 1.0f; + + // TODO(hnakashima): Handle correctly edits with empty text instead of using + // these defaults. + if (m_rtCaret.height == 0) + m_rtCaret.height = 8.0f; } void CFWL_Edit::SetCursorPosition(size_t position) { diff --git a/xfa/fwl/cfwl_timer.cpp b/xfa/fwl/cfwl_timer.cpp index 2734e49d78..597f928ba0 100644 --- a/xfa/fwl/cfwl_timer.cpp +++ b/xfa/fwl/cfwl_timer.cpp @@ -25,11 +25,13 @@ CFWL_TimerInfo* CFWL_Timer::StartTimer(uint32_t dwElapse, bool bImmediately) { if (!pAdapterNative) return nullptr; - IFWL_AdapterTimerMgr* pAdapterTimerMgr = pAdapterNative->GetTimerMgr(); - if (!pAdapterTimerMgr) + if (!m_pTimeMgrAdapter) + m_pTimeMgrAdapter.reset(pAdapterNative->GetTimerMgr()); + + if (!m_pTimeMgrAdapter) return nullptr; CFWL_TimerInfo* pTimerInfo = nullptr; - pAdapterTimerMgr->Start(this, dwElapse, bImmediately, &pTimerInfo); + m_pTimeMgrAdapter->Start(this, dwElapse, bImmediately, &pTimerInfo); return pTimerInfo; } diff --git a/xfa/fwl/cfwl_timer.h b/xfa/fwl/cfwl_timer.h index da1b4437e2..355ea69d67 100644 --- a/xfa/fwl/cfwl_timer.h +++ b/xfa/fwl/cfwl_timer.h @@ -7,11 +7,14 @@ #ifndef XFA_FWL_CFWL_TIMER_H_ #define XFA_FWL_CFWL_TIMER_H_ +#include + #include "core/fxcrt/fx_system.h" #include "core/fxcrt/unowned_ptr.h" class CFWL_TimerInfo; class CFWL_Widget; +class IFWL_AdapterTimerMgr; class CFWL_Timer { public: @@ -23,6 +26,7 @@ class CFWL_Timer { protected: UnownedPtr m_pWidget; + std::unique_ptr m_pTimeMgrAdapter; }; #endif // XFA_FWL_CFWL_TIMER_H_ diff --git a/xfa/fwl/ifwl_adaptertimermgr.h b/xfa/fwl/ifwl_adaptertimermgr.h index 1f655892ea..23627d9191 100644 --- a/xfa/fwl/ifwl_adaptertimermgr.h +++ b/xfa/fwl/ifwl_adaptertimermgr.h @@ -11,6 +11,7 @@ class IFWL_AdapterTimerMgr { public: + virtual ~IFWL_AdapterTimerMgr() {} virtual void Start(CFWL_Timer* pTimer, uint32_t dwElapse, bool bImmediately, -- cgit v1.2.3