summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-20 08:34:24 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-20 12:45:42 +0000
commiteea631943cb9535db8be2885a7c81bda956758e5 (patch)
tree92baf242693a4e40e99d26f97a86f41e152fb067
parent61674c854cdd8cfdb88a1a4baef379f24ba0cf3a (diff)
downloadpdfium-eea631943cb9535db8be2885a7c81bda956758e5.tar.xz
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>
-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.
}