avm2: Ensure the focus is dropped when it's removed

The logic of dropping the focus when it's removed
applies not only to TextFields but for every InteractiveObject.
This patch ensures that any focus is dropped when its parent is removed.
This commit is contained in:
Kamil Jarosz 2024-05-06 13:03:49 +02:00 committed by Nathan Adams
parent 428688e7e7
commit b551d14a59
2 changed files with 4 additions and 10 deletions

View File

@ -1594,6 +1594,10 @@ pub trait TDisplayObject<'gc>:
let parent_removed = had_parent && !has_parent;
if parent_removed {
if let Some(int) = self.as_interactive() {
int.drop_focus(context);
}
self.on_parent_removed(context);
}
}

View File

@ -2114,16 +2114,6 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
self.0.write(context.gc_context).object = Some(to.into());
}
fn on_parent_removed(&self, context: &mut UpdateContext<'_, 'gc>) {
if self.movie().is_action_script_3() {
let had_focus = self.has_focus();
if had_focus {
let tracker = context.focus_tracker;
tracker.set(None, context);
}
}
}
fn self_bounds(&self) -> Rectangle<Twips> {
self.0.read().bounds.clone()
}