Skip to content

Commit

Permalink
core: Drop the focus when it's made invisible
Browse files Browse the repository at this point in the history
When an object has focus and is made invisible,
the focus should be dropped.
  • Loading branch information
kjarosh committed May 22, 2024
1 parent f67cb24 commit 10150f2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/src/avm1/object/stage_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ fn set_visible<'gc>(
// Because this property dates to the era of Flash 4, this is actually coerced to an integer.
// `_visible = "false";` coerces to NaN and has no effect.
if let Some(n) = property_coerce_to_number(activation, val)? {
this.set_visible(activation.context.gc_context, n != 0.0);
this.set_visible(&mut activation.context, n != 0.0);
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm2/globals/flash/display/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ pub fn set_visible<'gc>(
if let Some(dobj) = this.as_display_object() {
let new_visible = args.get_bool(0);

dobj.set_visible(activation.context.gc_context, new_visible);
dobj.set_visible(&mut activation.context, new_visible);
}

Ok(Value::Undefined)
Expand Down
2 changes: 1 addition & 1 deletion core/src/debug_ui/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ impl DisplayObjectWindow {
ui.checkbox(&mut is_visible, "Visible");
ui.end_row();
if is_visible != was_visible {
object.set_visible(context.gc_context, is_visible);
object.set_visible(context, is_visible);
}

ui.label("Blend mode");
Expand Down
15 changes: 11 additions & 4 deletions core/src/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,11 +1738,18 @@ pub trait TDisplayObject<'gc>:
/// Sets whether this display object will be visible.
/// Invisible objects are not rendered, but otherwise continue to exist normally.
/// Returned by the `_visible`/`visible` ActionScript properties.
fn set_visible(&self, gc_context: &Mutation<'gc>, value: bool) {
if self.base_mut(gc_context).set_visible(value) {
fn set_visible(&self, context: &mut UpdateContext<'_, 'gc>, value: bool) {
if self.base_mut(context.gc()).set_visible(value) {
if let Some(parent) = self.parent() {
// We don't need to invalidate ourselves, we're just toggling if the bitmap is rendered.
parent.invalidate_cached_bitmap(gc_context);
parent.invalidate_cached_bitmap(context.gc());
}
}

if !value {
if let Some(int) = self.as_interactive() {
// The object's focus is dropped when it's made invisible.
int.drop_focus(context);
}
}
}
Expand Down Expand Up @@ -2209,7 +2216,7 @@ pub trait TDisplayObject<'gc>:
}
if self.swf_version() >= 11 {
if let Some(visible) = place_object.is_visible {
self.set_visible(context.gc_context, visible);
self.set_visible(context, visible);
}
if let Some(mut color) = place_object.background_color {
let color = if color.a > 0 {
Expand Down
4 changes: 2 additions & 2 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,14 +1292,14 @@ impl Player {
// Turn the dragged object invisible so that we don't pick it.
// TODO: This could be handled via adding a `HitTestOptions::SKIP_DRAGGED`.
let was_visible = display_object.visible();
display_object.set_visible(context.gc_context, false);
display_object.set_visible(context, false);
// Set `_droptarget` to the object the mouse is hovering over.
let drop_target_object = run_mouse_pick(context, false);
movie_clip.set_drop_target(
context.gc_context,
drop_target_object.map(|d| d.as_displayobject()),
);
display_object.set_visible(context.gc_context, was_visible);
display_object.set_visible(context, was_visible);
}
}
}
Expand Down

0 comments on commit 10150f2

Please sign in to comment.