Skip to content

Commit

Permalink
core: Ignore non-tabbable objects from tab ordering
Browse files Browse the repository at this point in the history
These objects include:
* invisible objects along with their children,
* non-editable text fields.

The method `is_tab_enabled` is renamed to `is_tabbable`, as it no
longer represents the `tabEnabled` property value, but also
incorporates other logic.
  • Loading branch information
kjarosh committed Apr 4, 2024
1 parent 53f49eb commit a454b23
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ pub trait TDisplayObject<'gc>:
}

/// Whether this object is included in tab ordering.
fn is_tab_enabled(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
fn is_tabbable(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
false
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/display_object/avm1_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl<'gc> TDisplayObject<'gc> for Avm1Button<'gc> {
self.call_focus_handler(context, focused, other);
}

fn is_tab_enabled(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
fn is_tabbable(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
self.get_avm1_boolean_property(context, "tabEnabled", |_| true)
}

Expand Down
6 changes: 5 additions & 1 deletion core/src/display_object/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@ pub trait TDisplayObjectContainer<'gc>:
}

for child in self.iter_render_list() {
if child.is_tab_enabled(context) {
if !child.visible() {
// Non-visible objects and their children are excluded from tab ordering.
continue;
}
if child.is_tabbable(context) {
tab_order.push(child);
}
if let Some(container) = child.as_container() {
Expand Down
7 changes: 6 additions & 1 deletion core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,12 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
true
}

fn is_tab_enabled(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
fn is_tabbable(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
if !self.is_editable() {
// Non-editable text fields are never tabbable.
return false;
}

self.get_avm1_boolean_property(context, "tabEnabled", |_| true)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/display_object/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3031,7 +3031,7 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
self.call_focus_handler(context, focused, other);
}

fn is_tab_enabled(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
fn is_tabbable(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
self.get_avm1_boolean_property(context, "tabEnabled", |context| {
self.tab_index().is_some() || self.is_button_mode(context)
})
Expand Down

0 comments on commit a454b23

Please sign in to comment.