summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/pwl/cpwl_caret.cpp108
1 files 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.
}