Avoid running ui::Entry timer when it's not needed

This commit is contained in:
David Capello 2018-12-12 13:27:11 -03:00
parent 3b810701ce
commit ab9883e260
2 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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;