core: Add InteractiveObject.tab_enabled_default

This patch removes two methods:
* `tab_enabled_avm1`, and
* `tab_enabled_avm2_default`,
and replaces them with `tab_enabled_default`.

This refactor makes the code more readable and simple.
This commit is contained in:
Kamil Jarosz 2024-05-13 00:05:29 +02:00 committed by Nathan Adams
parent 819abe8420
commit 4253525f8b
5 changed files with 20 additions and 25 deletions

View File

@ -599,8 +599,8 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {
}
}
fn tab_enabled_avm1(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
self.get_avm1_boolean_property(context, "tabEnabled", |_| true)
fn tab_enabled_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
true
}
fn highlight_bounds(self) -> Rectangle<Twips> {

View File

@ -821,7 +821,7 @@ impl<'gc> TInteractiveObject<'gc> for Avm2Button<'gc> {
}
}
fn tab_enabled_avm2_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
fn tab_enabled_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
true
}
}

View File

@ -2459,11 +2459,7 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
self.tab_enabled(context)
}
fn tab_enabled_avm1(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
self.get_avm1_boolean_property(context, "tabEnabled", |_| true)
}
fn tab_enabled_avm2_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
fn tab_enabled_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
self.is_editable()
}
}

View File

@ -641,20 +641,16 @@ pub trait TInteractiveObject<'gc>:
if context.swf.is_action_script_3() {
self.raw_interactive()
.tab_enabled
.unwrap_or_else(|| self.tab_enabled_avm2_default(context))
.unwrap_or_else(|| self.tab_enabled_default(context))
} else {
self.tab_enabled_avm1(context)
self.as_displayobject()
.get_avm1_boolean_property(context, "tabEnabled", |context| {
self.tab_enabled_default(context)
})
}
}
/// Look up the `tabEnabled` property from AVM1.
///
/// Do not use this directly, use [`Self::is_tabbable()`] or [`Self::tab_enabled()`].
fn tab_enabled_avm1(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
false
}
fn tab_enabled_avm2_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
fn tab_enabled_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
false
}

View File

@ -3369,14 +3369,17 @@ impl<'gc> TInteractiveObject<'gc> for MovieClip<'gc> {
}
}
fn tab_enabled_avm1(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
self.get_avm1_boolean_property(context, "tabEnabled", |context| {
self.tab_index().is_some() || self.is_button_mode(context)
})
fn tab_enabled_default(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
if self.is_button_mode(context) {
return true;
}
fn tab_enabled_avm2_default(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
self.is_button_mode(context)
let is_avm1 = !context.swf.is_action_script_3();
if is_avm1 && self.tab_index().is_some() {
return true;
}
false
}
}