From ab9883e260df5fab8f6fc5602cd9691f4b95af10 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 12 Dec 2018 13:27:11 -0300 Subject: [PATCH] Avoid running ui::Entry timer when it's not needed --- src/ui/entry.cpp | 17 ++++++++++++++--- src/ui/entry.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ui/entry.cpp b/src/ui/entry.cpp index 8b7e72a11..d77e53ad6 100644 --- a/src/ui/entry.cpp +++ b/src/ui/entry.cpp @@ -91,12 +91,15 @@ void Entry::setReadOnly(bool state) void Entry::showCaret() { m_hidden = false; + if (shouldStartTimer(hasFocus())) + m_timer.start(); invalidate(); } void Entry::hideCaret() { m_hidden = true; + m_timer.stop(); invalidate(); } @@ -131,7 +134,8 @@ void Entry::setCaretPos(int pos) } } - m_timer.start(); + if (shouldStartTimer(hasFocus())) + m_timer.start(); m_state = true; invalidate(); @@ -227,7 +231,8 @@ bool Entry::onProcessMessage(Message* msg) break; case kFocusEnterMessage: - m_timer.start(); + if (shouldStartTimer(true)) + m_timer.start(); m_state = true; invalidate(); @@ -392,7 +397,8 @@ bool Entry::onProcessMessage(Message* msg) // Show the caret if (is_dirty) { - m_timer.start(); + if (shouldStartTimer(true)) + m_timer.start(); m_state = true; } @@ -885,4 +891,9 @@ void Entry::recalcCharBoxes(const std::string& text) m_boxes.push_back(box); } +bool Entry::shouldStartTimer(bool hasFocus) +{ + return (!m_hidden && hasFocus && isEnabled()); +} + } // namespace ui diff --git a/src/ui/entry.h b/src/ui/entry.h index 062f6e7d4..1a8a3a4e3 100644 --- a/src/ui/entry.h +++ b/src/ui/entry.h @@ -94,6 +94,7 @@ namespace ui { bool isPosInSelection(int pos); void showEditPopupMenu(const gfx::Point& pt); void recalcCharBoxes(const std::string& text); + bool shouldStartTimer(const bool hasFocus); class CalcBoxesTextDelegate;