mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibGUI: Forget some of Window's widgets eagerly on widget unparenting
Previously the focused widget would only get cleared on replacement or on destruction (being a WeakPtr and all.) This could lead to window dispatching events to a focused widget after it had been removed from the window's widget tree. The same issue existed for the hovered widget, etc. So this patch makes sure that we eagerly clear the various widget pointers in Window immediately when they are removed from the window's widget tree.
This commit is contained in:
parent
e23c5b7e83
commit
4d5e144a6b
Notes:
sideshowbarker
2024-07-19 08:53:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4d5e144a6ba
3 changed files with 16 additions and 0 deletions
|
@ -123,6 +123,8 @@ void Widget::child_event(Core::ChildEvent& event)
|
|||
else
|
||||
invalidate_layout();
|
||||
}
|
||||
if (event.child() && Core::is<Widget>(*event.child()))
|
||||
window()->did_remove_widget({}, Core::to<Widget>(*event.child()));
|
||||
update();
|
||||
}
|
||||
return Core::Object::child_event(event);
|
||||
|
|
|
@ -689,4 +689,16 @@ void Window::set_size_increment(const Gfx::Size& size_increment)
|
|||
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement>(m_window_id, m_base_size, m_size_increment);
|
||||
}
|
||||
|
||||
void Window::did_remove_widget(Badge<Widget>, const Widget& widget)
|
||||
{
|
||||
if (m_focused_widget == &widget)
|
||||
m_focused_widget = nullptr;
|
||||
if (m_hovered_widget == &widget)
|
||||
m_hovered_widget = nullptr;
|
||||
if (m_global_cursor_tracking_widget)
|
||||
m_global_cursor_tracking_widget = nullptr;
|
||||
if (m_automatic_cursor_tracking_widget)
|
||||
m_automatic_cursor_tracking_widget = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -179,6 +179,8 @@ public:
|
|||
|
||||
Action* action_for_key_event(const KeyEvent&);
|
||||
|
||||
void did_remove_widget(Badge<Widget>, const Widget&);
|
||||
|
||||
protected:
|
||||
Window(Core::Object* parent = nullptr);
|
||||
virtual void wm_event(WMEvent&);
|
||||
|
|
Loading…
Reference in a new issue