1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

LibGUI: Mimic a user click when calling Button::click()

The `mimic_pressed` function was primarily used in one place, the
Calculator. This patch removes quite a lot of logic duplication there.
It is also profitable to a lot of other places where `click()` was
called without mimicking a click.
This commit is contained in:
Lucas CHOLLET 2023-01-17 17:31:45 -05:00 committed by Andreas Kling
parent 96b3063121
commit d4ef2e226c
5 changed files with 37 additions and 54 deletions

View file

@ -131,12 +131,13 @@ void AbstractButton::mouseup_event(MouseEvent& event)
if (event.button() == m_pressed_mouse_button && m_being_pressed) {
bool was_auto_repeating = m_auto_repeat_timer->is_active();
m_auto_repeat_timer->stop();
bool was_being_pressed = m_being_pressed;
m_was_being_pressed = m_being_pressed;
ScopeGuard update_was_being_pressed { [this] { m_was_being_pressed = m_being_pressed; } };
m_being_pressed = false;
m_pressed_mouse_button = MouseButton::None;
if (!is_checkable() || is_checked())
repaint();
if (was_being_pressed && !was_auto_repeating) {
if (m_was_being_pressed && !was_auto_repeating) {
switch (event.button()) {
case MouseButton::Primary:
click(event.modifiers());