Skip to content

Commit

Permalink
LibGUI: Remove unnecessary is_enabled() checks in mouse event handlers
Browse files Browse the repository at this point in the history
We never deliver mouse events to disabled widgets, so there's no need
to check is_enabled() in these event handlers.
  • Loading branch information
awesomekling committed Apr 29, 2020
1 parent cdbc252 commit 57fe4d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
44 changes: 19 additions & 25 deletions Libraries/LibGUI/AbstractButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,16 @@ void AbstractButton::mousemove_event(MouseEvent& event)
bool is_over = rect().contains(event.position());
m_hovered = is_over;
if (event.buttons() & MouseButton::Left) {
if (is_enabled()) {
bool being_pressed = is_over;
if (being_pressed != m_being_pressed) {
m_being_pressed = being_pressed;
if (m_auto_repeat_interval) {
if (!m_being_pressed)
m_auto_repeat_timer->stop();
else
m_auto_repeat_timer->start(m_auto_repeat_interval);
}
update();
bool being_pressed = is_over;
if (being_pressed != m_being_pressed) {
m_being_pressed = being_pressed;
if (m_auto_repeat_interval) {
if (!m_being_pressed)
m_auto_repeat_timer->stop();
else
m_auto_repeat_timer->start(m_auto_repeat_interval);
}
update();
}
}
Widget::mousemove_event(event);
Expand All @@ -113,14 +111,12 @@ void AbstractButton::mousedown_event(MouseEvent& event)
dbgprintf("AbstractButton::mouse_down_event: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
#endif
if (event.button() == MouseButton::Left) {
if (is_enabled()) {
m_being_pressed = true;
update();
m_being_pressed = true;
update();

if (m_auto_repeat_interval) {
click();
m_auto_repeat_timer->start(m_auto_repeat_interval);
}
if (m_auto_repeat_interval) {
click();
m_auto_repeat_timer->start(m_auto_repeat_interval);
}
}
Widget::mousedown_event(event);
Expand All @@ -134,13 +130,11 @@ void AbstractButton::mouseup_event(MouseEvent& event)
if (event.button() == MouseButton::Left) {
bool was_auto_repeating = m_auto_repeat_timer->is_active();
m_auto_repeat_timer->stop();
if (is_enabled()) {
bool was_being_pressed = m_being_pressed;
m_being_pressed = false;
update();
if (was_being_pressed && !was_auto_repeating)
click();
}
bool was_being_pressed = m_being_pressed;
m_being_pressed = false;
update();
if (was_being_pressed && !was_auto_repeating)
click();
}
Widget::mouseup_event(event);
}
Expand Down
9 changes: 0 additions & 9 deletions Libraries/LibGUI/Slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ Gfx::Rect Slider::knob_rect() const

void Slider::mousedown_event(MouseEvent& event)
{
if (!is_enabled())
return;
if (event.button() == MouseButton::Left) {
if (knob_rect().contains(event.position())) {
m_dragging = true;
Expand All @@ -135,8 +133,6 @@ void Slider::mousedown_event(MouseEvent& event)

void Slider::mousemove_event(MouseEvent& event)
{
if (!is_enabled())
return;
set_knob_hovered(knob_rect().contains(event.position()));
if (m_dragging) {
float delta = event.position().primary_offset_for_orientation(orientation()) - m_drag_origin.primary_offset_for_orientation(orientation());
Expand All @@ -151,8 +147,6 @@ void Slider::mousemove_event(MouseEvent& event)

void Slider::mouseup_event(MouseEvent& event)
{
if (!is_enabled())
return;
if (event.button() == MouseButton::Left) {
m_dragging = false;
return;
Expand All @@ -163,9 +157,6 @@ void Slider::mouseup_event(MouseEvent& event)

void Slider::mousewheel_event(MouseEvent& event)
{
if (!is_enabled())
return;

if (orientation() == Orientation::Horizontal)
set_value(value() - event.wheel_delta() * m_step);
else
Expand Down

0 comments on commit 57fe4d1

Please sign in to comment.