@@ -2158,6 +2158,11 @@ Control::FocusBehaviorRecursive Control::get_focus_behavior_recursive() const {
2158
2158
return data.focus_behavior_recursive ;
2159
2159
}
2160
2160
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
+
2161
2166
bool Control::_is_focus_mode_enabled () const {
2162
2167
if (data.focus_behavior_recursive == FOCUS_BEHAVIOR_INHERITED) {
2163
2168
if (data.parent_control ) {
@@ -2270,7 +2275,7 @@ Control *Control::find_next_valid_focus() const {
2270
2275
ERR_FAIL_NULL_V_MSG (n, nullptr , " Next focus node path is invalid: '" + data.focus_next + " '." );
2271
2276
Control *c = Object::cast_to<Control>(n);
2272
2277
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 () ) {
2274
2279
return c;
2275
2280
}
2276
2281
}
@@ -2374,7 +2379,7 @@ Control *Control::find_prev_valid_focus() const {
2374
2379
ERR_FAIL_NULL_V_MSG (n, nullptr , " Previous focus node path is invalid: '" + data.focus_prev + " '." );
2375
2380
Control *c = Object::cast_to<Control>(n);
2376
2381
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 () ) {
2378
2383
return c;
2379
2384
}
2380
2385
}
@@ -2494,7 +2499,7 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
2494
2499
ERR_FAIL_NULL_V_MSG (n, nullptr , " Neighbor focus node path is invalid: '" + data.focus_neighbor [p_side] + " '." );
2495
2500
Control *c = Object::cast_to<Control>(n);
2496
2501
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 () ) {
2498
2503
return c;
2499
2504
}
2500
2505
0 commit comments