Cleanup CPWL_Caret code

Add some early returns where possible.

Change-Id: I9c53435e6e927057b085b1ccaa30a1637c185486
Reviewed-on: https://pdfium-review.googlesource.com/14350
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/pwl/cpwl_caret.cpp b/fpdfsdk/pwl/cpwl_caret.cpp
index 99d2e2e..c58f019 100644
--- a/fpdfsdk/pwl/cpwl_caret.cpp
+++ b/fpdfsdk/pwl/cpwl_caret.cpp
@@ -55,13 +55,14 @@
 
 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 @@
 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.
 }