From eea631943cb9535db8be2885a7c81bda956758e5 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 20 Sep 2017 08:34:24 -0400 Subject: Cleanup CPWL_Caret code Add some early returns where possible. Change-Id: I9c53435e6e927057b085b1ccaa30a1637c185486 Reviewed-on: https://pdfium-review.googlesource.com/14350 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fpdfsdk/pwl/cpwl_caret.cpp | 108 ++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 50 deletions(-) diff --git a/fpdfsdk/pwl/cpwl_caret.cpp b/fpdfsdk/pwl/cpwl_caret.cpp index 99d2e2ece7..c58f019c4c 100644 --- a/fpdfsdk/pwl/cpwl_caret.cpp +++ b/fpdfsdk/pwl/cpwl_caret.cpp @@ -55,13 +55,14 @@ void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, void CPWL_Caret::TimerProc() { if (m_nDelay > 0) { - m_nDelay--; - } else { - m_bFlash = !m_bFlash; - InvalidateRect(nullptr); - // Note, |this| may no longer be viable at this point. If more work needs - // to be done, add an observer. + --m_nDelay; + return; } + + m_bFlash = !m_bFlash; + InvalidateRect(nullptr); + // Note, |this| may no longer be viable at this point. If more work needs + // to be done, add an observer. } CFX_FloatRect CPWL_Caret::GetCaretRect() const { @@ -72,58 +73,65 @@ CFX_FloatRect CPWL_Caret::GetCaretRect() const { void CPWL_Caret::SetCaret(bool bVisible, const CFX_PointF& ptHead, const CFX_PointF& ptFoot) { - if (bVisible) { - if (IsVisible()) { - if (m_ptHead != ptHead || m_ptFoot != ptFoot) { - m_ptHead = ptHead; - m_ptFoot = ptFoot; - m_bFlash = true; - Move(m_rcInvalid, false, true); - // Note, |this| may no longer be viable at this point. If more work - // needs to be done, add an observer. - } - } else { - m_ptHead = ptHead; - m_ptFoot = ptFoot; - EndTimer(); - BeginTimer(PWL_CARET_FLASHINTERVAL); - - ObservedPtr observer(this); - CPWL_Wnd::SetVisible(true); - if (!observer) - return; - - m_bFlash = true; - Move(m_rcInvalid, false, true); - // Note, |this| may no longer be viable at this point. If more work needs - // to be done, add an observer. - } - } else { + if (!bVisible) { m_ptHead = CFX_PointF(); m_ptFoot = CFX_PointF(); m_bFlash = false; - if (IsVisible()) { - EndTimer(); - CPWL_Wnd::SetVisible(false); - // Note, |this| may no longer be viable at this point. If more work needs - // to be done, add an observer. - } + if (!IsVisible()) + return; + + EndTimer(); + CPWL_Wnd::SetVisible(false); + // Note, |this| may no longer be viable at this point. If more work needs + // to be done, add an observer. + return; } + + if (!IsVisible()) { + m_ptHead = ptHead; + m_ptFoot = ptFoot; + EndTimer(); + BeginTimer(PWL_CARET_FLASHINTERVAL); + + ObservedPtr observer(this); + CPWL_Wnd::SetVisible(true); + if (!observer) + return; + + m_bFlash = true; + Move(m_rcInvalid, false, true); + // Note, |this| may no longer be viable at this point. If more work needs + // to be done, add an observer. + return; + } + + if (m_ptHead == ptHead && m_ptFoot == ptFoot) + return; + + m_ptHead = ptHead; + m_ptFoot = ptFoot; + m_bFlash = true; + Move(m_rcInvalid, false, true); + // Note, |this| may no longer be viable at this point. If more work + // needs to be done, add an observer. } void CPWL_Caret::InvalidateRect(CFX_FloatRect* pRect) { - if (pRect) { - CFX_FloatRect rcRefresh = *pRect; - if (!rcRefresh.IsEmpty()) { - rcRefresh.Inflate(0.5f, 0.5f); - rcRefresh.Normalize(); - } - rcRefresh.top += 1; - rcRefresh.bottom -= 1; - CPWL_Wnd::InvalidateRect(&rcRefresh); - } else { - CPWL_Wnd::InvalidateRect(pRect); + if (!pRect) { + CPWL_Wnd::InvalidateRect(nullptr); + // Note, |this| may no longer be viable at this point. If more work needs + // to be done, add an observer. + return; + } + + CFX_FloatRect rcRefresh = *pRect; + if (!rcRefresh.IsEmpty()) { + rcRefresh.Inflate(0.5f, 0.5f); + rcRefresh.Normalize(); } + rcRefresh.top += 1; + rcRefresh.bottom -= 1; + CPWL_Wnd::InvalidateRect(&rcRefresh); // Note, |this| may no longer be viable at this point. If more work needs // to be done, add an observer. } -- cgit v1.2.3