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

LibGUI: Add Widget focus proxies

A Widget can now have a focus proxy widget. Questions about focus are
redirected to the proxy if present. This is useful if a widget could
logically get focus, but wants one of its child widgets to actually
handle it.
This commit is contained in:
Andreas Kling 2020-08-25 11:21:49 +02:00
parent 9ba3862ee9
commit af16552624
2 changed files with 23 additions and 0 deletions

View file

@ -499,8 +499,22 @@ void Widget::set_window(Window* window)
m_window = window;
}
void Widget::set_focus_proxy(Widget* proxy)
{
if (m_focus_proxy == proxy)
return;
if (proxy)
m_focus_proxy = proxy->make_weak_ptr();
else
m_focus_proxy = nullptr;
}
bool Widget::is_focused() const
{
if (m_focus_proxy)
return m_focus_proxy->is_focused();
auto* win = window();
if (!win)
return false;
@ -514,6 +528,9 @@ bool Widget::is_focused() const
void Widget::set_focus(bool focus, FocusSource source)
{
if (m_focus_proxy)
return m_focus_proxy->set_focus(focus, source);
auto* win = window();
if (!win)
return;