@@ -2158,6 +2158,11 @@ Control::FocusBehaviorRecursive Control::get_focus_behavior_recursive() const {
21582158 return data.focus_behavior_recursive ;
21592159}
21602160
2161+ bool Control::_is_focusable () const {
2162+ bool ac_enabled = is_inside_tree () && get_tree ()->is_accessibility_enabled ();
2163+ return (is_visible_in_tree () && ((get_focus_mode_with_override () == FOCUS_ALL) || (get_focus_mode_with_override () == FOCUS_CLICK) || (ac_enabled && get_focus_mode_with_override () == FOCUS_ACCESSIBILITY)));
2164+ }
2165+
21612166bool Control::_is_focus_mode_enabled () const {
21622167 if (data.focus_behavior_recursive == FOCUS_BEHAVIOR_INHERITED) {
21632168 if (data.parent_control ) {
@@ -2270,7 +2275,7 @@ Control *Control::find_next_valid_focus() const {
22702275 ERR_FAIL_NULL_V_MSG (n, nullptr , " Next focus node path is invalid: '" + data.focus_next + " '." );
22712276 Control *c = Object::cast_to<Control>(n);
22722277 ERR_FAIL_NULL_V_MSG (c, nullptr , " Next focus node is not a control: '" + n->get_name () + " '." );
2273- if (c->is_visible_in_tree () && c-> get_focus_mode_with_override () != FOCUS_NONE ) {
2278+ if (c->_is_focusable () ) {
22742279 return c;
22752280 }
22762281 }
@@ -2374,7 +2379,7 @@ Control *Control::find_prev_valid_focus() const {
23742379 ERR_FAIL_NULL_V_MSG (n, nullptr , " Previous focus node path is invalid: '" + data.focus_prev + " '." );
23752380 Control *c = Object::cast_to<Control>(n);
23762381 ERR_FAIL_NULL_V_MSG (c, nullptr , " Previous focus node is not a control: '" + n->get_name () + " '." );
2377- if (c->is_visible_in_tree () && c-> get_focus_mode_with_override () != FOCUS_NONE ) {
2382+ if (c->_is_focusable () ) {
23782383 return c;
23792384 }
23802385 }
@@ -2494,7 +2499,7 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
24942499 ERR_FAIL_NULL_V_MSG (n, nullptr , " Neighbor focus node path is invalid: '" + data.focus_neighbor [p_side] + " '." );
24952500 Control *c = Object::cast_to<Control>(n);
24962501 ERR_FAIL_NULL_V_MSG (c, nullptr , " Neighbor focus node is not a control: '" + n->get_name () + " '." );
2497- if (c->is_visible_in_tree () && c-> get_focus_mode_with_override () != FOCUS_NONE ) {
2502+ if (c->_is_focusable () ) {
24982503 return c;
24992504 }
25002505
0 commit comments