Parcourir la source

LibGUI: Allow widgets to make themselves non-auto-focusable

This patchs adds a way for widgets exclude themselves from being a focus
candidate in Window::focus_a_widget_if_possible().

This is to allow the URL box to not get auto-focused when the browser
is loaded.
Rob Ryan il y a 3 ans
Parent
commit
fbf824a50f
2 fichiers modifiés avec 6 ajouts et 0 suppressions
  1. 4 0
      Userland/Libraries/LibGUI/Widget.h
  2. 2 0
      Userland/Libraries/LibGUI/Window.cpp

+ 4 - 0
Userland/Libraries/LibGUI/Widget.h

@@ -114,6 +114,9 @@ public:
     String tooltip() const { return m_tooltip; }
     void set_tooltip(String);
 
+    bool is_auto_focusable() const { return m_auto_focusable; }
+    void set_auto_focusable(bool auto_focusable) { m_auto_focusable = auto_focusable; }
+
     bool is_enabled() const { return m_enabled; }
     void set_enabled(bool);
 
@@ -357,6 +360,7 @@ private:
     bool m_fill_with_background_color { false };
     bool m_visible { true };
     bool m_greedy_for_hits { false };
+    bool m_auto_focusable { true };
     bool m_enabled { true };
     bool m_updates_enabled { true };
     bool m_accepts_emoji_input { false };

+ 2 - 0
Userland/Libraries/LibGUI/Window.cpp

@@ -947,6 +947,8 @@ Vector<Widget&> Window::focusable_widgets(FocusSource source) const
                 return IterationDecision::Continue;
             if (!child.is_enabled())
                 return IterationDecision::Continue;
+            if (!child.is_auto_focusable())
+                return IterationDecision::Continue;
             collect_focusable_widgets(child);
             return IterationDecision::Continue;
         });